Skip to content

Commit

Permalink
switch OO system to Moo
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Oct 3, 2021
1 parent 959466b commit 98152ce
Show file tree
Hide file tree
Showing 40 changed files with 187 additions and 238 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Haydock states stored in memory-mapped files rather than using Storable
- remove the state_iterator capability which is replaced by memory-mapping, allowing large threaded calculations
- switch type system to Type::Tiny
- switch OO system to Moo

0.021 2021-10-01
- Add example of honeycomb lattice for LE::NR2
Expand Down
6 changes: 3 additions & 3 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ WriteMakefile(
'IO::File' => '0',
'List::Util' => '0',
'Machine::Epsilon' => '0',
'Moose' => '0',
'Moose::Role' => '0',
'Moo' => '0',
'namespace::autoclean' => '0',
'Type::Tiny' => '0',
'MooseX::StrictConstructor' => '0',
'MooX::StrictConstructor' => '0',
'PDL' => '2.049', # PDL::Complex->from_native
'PDL::Constants' => '0',
'PDL::Core' => '0',
Expand Down
2 changes: 1 addition & 1 deletion lib/Photonic/Geometry/FromB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA


use namespace::autoclean;
use Moose;
use Moo;
use Photonic::Types -all;

has 'B' =>(is=>'ro', isa=>PDLObj, required=>1,
Expand Down
6 changes: 3 additions & 3 deletions lib/Photonic/Geometry/FromEpsilon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA

use namespace::autoclean;
use Carp;
use Moose;
use Moo;
use Photonic::Types -all;

has 'epsilon'=>(is=>'ro', isa=>PDLComplex, required=>1,
documentation=>'Dielectric function as function of position');

has 'B' =>(is=>'ro', isa=>PDLObj, init_arg=>undef, builder=>'_B', lazy=>1,
has 'B' =>(is=>'lazy', isa=>PDLObj, init_arg=>undef,
documentation=>'Characteristic function');

with 'Photonic::Roles::Geometry';
Expand All @@ -55,7 +55,7 @@ before 'f' => sub {
. "Photonic::Geometry::FromEpsilon";
};

sub _B {
sub _build_B {
my $self=shift;
return $self->epsilon->re; #value is irrelevant. Only
#shape of pdl counts.
Expand Down
6 changes: 3 additions & 3 deletions lib/Photonic/Geometry/FromImage2D.pm
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ L<Photonic::Roles::Geometry>
=cut

use namespace::autoclean;
use Moose;
use MooseX::StrictConstructor;
use Moo;
use MooX::StrictConstructor;

BEGIN {
# Put inoffensive path. Or else, PDL::IO::Pic fails in taint mode.
Expand All @@ -109,7 +109,7 @@ use Carp;

has 'path' => ( is => 'ro', required => 1,
documentation => 'File name of 2D monochrome image' );
has 'B' => (is=>'ro', init_arg=>undef, lazy=>1, builder=>'_build_B' );
has 'B' => (is=>'lazy', init_arg=>undef);
has 'inverted' => (is=>'ro', default=> 0,
documentation=>'Flag to invert black/white');

Expand Down
4 changes: 2 additions & 2 deletions lib/Photonic/LE/NP/EpsL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ Consumes L<Photonic::Roles::EpsL>
use namespace::autoclean;
use Photonic::Utils qw(lentzCF);
use List::Util qw(min);
use Moose;
use MooseX::StrictConstructor;
use Moo;
use MooX::StrictConstructor;

with 'Photonic::Roles::EpsL';

Expand Down
4 changes: 2 additions & 2 deletions lib/Photonic/LE/NP/EpsTensor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ use namespace::autoclean;
use Photonic::LE::NP::Haydock;
use Photonic::LE::NP::EpsL;
use Photonic::Types -all;
use Moose;
use MooseX::StrictConstructor;
use Moo;
use MooX::StrictConstructor;

has allh_class=>(is=>'ro', default=>'Photonic::LE::NP::Haydock');
has allh_attrs=>(is=>'ro', default=>sub{[qw(reorthogonalize epsilon)]});
Expand Down
6 changes: 3 additions & 3 deletions lib/Photonic/LE/NP/Haydock.pm
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ use PDL::Lite;
use Carp;
use Photonic::Types -all;
use Photonic::Utils qw(EProd any_complex apply_longitudinal_projection);
use Moose;
use MooseX::StrictConstructor;
use Moo;
use MooX::StrictConstructor;

has 'geometry'=>(is=>'ro', isa => GeometryG0,
handles=>[qw(B ndims dims r G GNorm L scale f)],required=>1
Expand All @@ -121,7 +121,7 @@ has 'complexCoeffs'=>(is=>'ro', init_arg=>undef, default=>1,
documentation=>'Haydock coefficients are complex');
with 'Photonic::Roles::Haydock', 'Photonic::Roles::EpsFromGeometry';

sub _firstState { #\delta_{G0}
sub _build_firstState { #\delta_{G0}
my $self=shift;
my $v=PDL->zeroes(@{$self->dims})->r2C; #nx, ny...
my $arg=join ',', ("(0)") x ($self->B->ndims); #(0),(0),... ndims+1 times
Expand Down
6 changes: 3 additions & 3 deletions lib/Photonic/LE/NR2/EpsL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ use Photonic::Utils qw(lentzCF);

use List::Util qw(min);

use Moose;
use MooseX::StrictConstructor;
use Moo;
use MooX::StrictConstructor;

with 'Photonic::Roles::EpsL';

has 'epsA'=>(is=>'ro', isa=>PDLComplex, required => 1,
documentation=>'Dielectric function of host');
has 'epsB'=>(is=>'ro', isa=>PDLComplex, required => 1,
documentation=>'Dielectric function of inclusions');
has 'u'=>(is=>'ro', isa=>PDLComplex, lazy => 1, builder => '_build_u',
has 'u'=>(is=>'lazy', isa=>PDLComplex,
documentation=>'Spectral variable');

sub _build_u {
Expand Down
4 changes: 2 additions & 2 deletions lib/Photonic/LE/NR2/EpsTensor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ use namespace::autoclean;
use Photonic::LE::NR2::Haydock;
use Photonic::LE::NR2::EpsL;
use Photonic::Types -all;
use Moose;
use MooseX::StrictConstructor;
use Moo;
use MooX::StrictConstructor;

has allh_class=>(is=>'ro', default=>'Photonic::LE::NR2::Haydock');
has allh_attrs=>(is=>'ro', default=>sub{[qw(reorthogonalize use_mask mask)]});
Expand Down
4 changes: 2 additions & 2 deletions lib/Photonic/LE/NR2/Field.pm
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ use PDL::NiceSlice;
use Photonic::LE::NR2::Haydock;
use Photonic::Utils qw(cgtsv GtoR linearCombineIt);
use Photonic::Types -all;
use Moose;
use MooseX::StrictConstructor;
use Moo;
use MooX::StrictConstructor;

has 'haydock'=>(is=>'ro', isa=>HaydockSave, required=>1,
documentation=>'Haydock recursion calculator');
Expand Down
6 changes: 3 additions & 3 deletions lib/Photonic/LE/NR2/Haydock.pm
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ use PDL::Lite;
use Carp;
use Photonic::Types -all;
use Photonic::Utils qw(HProd apply_longitudinal_projection);
use Moose;
use MooseX::StrictConstructor;
use Moo;
use MooX::StrictConstructor;

has 'geometry'=>(is=>'ro', isa => GeometryG0,
handles=>[qw(B dims ndims r G GNorm L scale f)],required=>1);
has 'complexCoeffs'=>(is=>'ro', init_arg=>undef, default=>0,
documentation=>'Haydock coefficients are real');
with 'Photonic::Roles::Haydock', 'Photonic::Roles::UseMask';

sub _firstState { #\delta_{G0}
sub _build_firstState { #\delta_{G0}
my $self=shift;
my $v=PDL->zeroes(@{$self->dims})->r2C; #nx, ny...
my $arg=join ',', ("(0)") x ($self->ndims); #(0),(0),... ndims times
Expand Down
79 changes: 29 additions & 50 deletions lib/Photonic/LE/NR2/SH.pm
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ use Photonic::LE::NR2::Haydock;
use Photonic::Utils qw(RtoG GtoR HProd linearCombineIt any_complex cgtsv top_slice mvN);
use Photonic::Types -all;
use PDL::Constants qw(PI);
use Moose;
use MooseX::StrictConstructor;
use Moo;
use MooX::StrictConstructor;

has 'shp'=>(is=>'ro', isa=>InstanceOf['Photonic::LE::NR2::SHP'], required=>1,
handles=>[qw(ndims nrf densityA densityB density haydock)],
Expand All @@ -205,94 +205,73 @@ has 'epsA2'=>(is=>'ro', isa=>PDLComplex, required=>1,
documentation=>'SH Dielectric function of host');
has 'epsB2'=>(is=>'ro', isa=>PDLComplex, required=>1,
documentation=>'SH Dielectric function of inclusions');
has 'alpha1'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_alpha1',
has 'alpha1'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>'Linear "atomic" polarizability');
has 'alpha2'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_alpha2',
has 'alpha2'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>'SH linear "atomic" polarizability');
has 'u1'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_u1',
has 'u1'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>'Spectral variable at fundamental');
has 'u2'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_u2',
has 'u2'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>'Spectral variable at SH');
has 'field1'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_field1',
has 'field1'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>'longitudinal field at fundamental');
has 'field2'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_field2',
has 'field2'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>'longitudinal field at second harmonic');
has 'epsL2'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
writer=>'_epsL2', predicate=>'has_epsL2',
documentation=>'longitudinal dielectric function at 2w');
has 'dipolar'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_dipolar',
has 'dipolar'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>'SH dipolar contribution to SH polarization');
has 'quadrupolar'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_quadrupolar',
has 'quadrupolar'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>'SH quadrupolar contribution to SH polarization');
has 'external'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_external',
has 'external'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>'SH external contribution to SH polarization');
has 'external_G'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_external_G',
has 'external_G'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>'SH ext. polarization in reciprocal space');
has 'externalL_G'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_externalL_G',
has 'externalL_G'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>
'SH ext. longitudinal polarization comp. in reciprocal space');
has 'externalVecL_G'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_externalVecL_G',
has 'externalVecL_G'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>
'SH ext. longitudinal polarization proj. in recip. space');
has 'externalVecL'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_externalVecL',
has 'externalVecL'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>
'SH ext. longitudinal polarization proj. in real space');
has 'HP' =>(is=>'ro', isa=>InstanceOf['Photonic::LE::NR2::Haydock'], init_arg=>undef,
lazy=>1, builder=>'_build_HP',
has 'HP' =>(is=>'lazy', isa=>InstanceOf['Photonic::LE::NR2::Haydock'], init_arg=>undef,
documentation=>
'Structure to calculate Haydock basis for non linear polarization');
has 'externalL_n'=>(is=>'ro', isa=>PDLComplex, init_arg=>undef,
lazy=>1, builder=>'_build_externalL_n',
has 'externalL_n'=>(is=>'lazy', isa=>PDLComplex, init_arg=>undef,
documentation=>
'SH ext. longitudinal polarization in Haydock
representation');
has 'selfConsistentL_n'=>(is=>'ro', isa=>PDLComplex,
init_arg=>undef, lazy=>1,
builder=>'_build_selfConsistentL_n',
has 'selfConsistentL_n'=>(is=>'lazy', isa=>PDLComplex,
init_arg=>undef,
documentation=>
'SH self consistent longitudinal polarization
in Haydock representation');
has 'selfConsistentL_G'=>(is=>'ro', isa=>PDLComplex,
init_arg=>undef, lazy=>1,
builder=>'_build_selfConsistentL_G',
has 'selfConsistentL_G'=>(is=>'lazy', isa=>PDLComplex,
init_arg=>undef,
documentation=>
'SH self consistent longitudinal polarization components in
reciprocal space');
has 'selfConsistentVecL_G'=>(is=>'ro', isa=>PDLComplex,
init_arg=>undef, lazy=>1,
builder=>'_build_selfConsistentVecL_G',
has 'selfConsistentVecL_G'=>(is=>'lazy', isa=>PDLComplex,
init_arg=>undef,
documentation=>
'SH self consistent longitudinal polarization vector
field in reciprocal space');
has 'selfConsistentVecL'=>(is=>'ro', isa=>PDLComplex,
init_arg=>undef, lazy=>1,
builder=>'_build_selfConsistentVecL',
has 'selfConsistentVecL'=>(is=>'lazy', isa=>PDLComplex,
init_arg=>undef,
documentation=>
'SH self consistent longitudinal polarization vector
field in real space');
has 'P2'=>(is=>'ro', isa=>PDLComplex,
init_arg=>undef, lazy=>1,
builder=>'_build_P2',
has 'P2'=>(is=>'lazy', isa=>PDLComplex,
init_arg=>undef,
documentation=>
'SH self consistent total polarization vector
field in real space');

has 'P2LMCalt'=>(is=>'ro', isa=>PDLComplex,
init_arg=>undef, lazy=>1,
builder=>'_build_P2LMCalt',
has 'P2LMCalt'=>(is=>'lazy', isa=>PDLComplex,
init_arg=>undef,
documentation=>
'SH self consistent total macroscopic polarization
in real space. Alternative');
Expand Down
9 changes: 4 additions & 5 deletions lib/Photonic/LE/NR2/SHChiTensor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ use PDL::IO::Storable;
use Photonic::Utils qw(make_haydock tensor incarnate_as);
use Photonic::Types -all;
use Photonic::LE::NR2::EpsTensor;
use Moose;
use Moo;

has 'nh' =>(is=>'ro', isa=>Num, required=>1,
documentation=>'Desired no. of Haydock coefficients');
Expand Down Expand Up @@ -211,12 +211,11 @@ has 'epsA2'=>(is=>'ro', isa=>PDLComplex, required=>1,
documentation=>'Dielectric function of host at SH');
has 'epsB2'=>(is=>'ro', isa=>PDLComplex, required=>1,
documentation=>'Dielectric function of inclusions');
has 'nrshp' =>(is=>'ro', isa=>ArrayRef[InstanceOf['Photonic::LE::NR2::SHP']],
init_arg=>undef, lazy=>1, builder=>'_build_nrshp',
has 'nrshp' =>(is=>'lazy', isa=>ArrayRef[InstanceOf['Photonic::LE::NR2::SHP']],
init_arg=>undef,
documentation=>'Array of Haydock SH polarization calculators');
has 'epsTensor'=>(is=>'ro', isa=>InstanceOf['Photonic::LE::NR2::EpsTensor'],
has 'epsTensor'=>(is=>'lazy', isa=>InstanceOf['Photonic::LE::NR2::EpsTensor'],
init_arg=>undef,
lazy=>1, builder=>'_build_epsTensor',
documentation=>'diel. tensor at 2w');
has 'chiTensor'=>(is=>'ro', isa=>PDLObj, init_arg=>undef, writer=>'_chiTensor',
documentation=>'SH Susceptibility from last evaluation');
Expand Down
9 changes: 4 additions & 5 deletions lib/Photonic/LE/NR2/SHP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ Number of dimensions of the system
use namespace::autoclean;
use PDL::Lite;
use PDL::NiceSlice;
use Moose;
use Moo;
use Photonic::Types -all;
use MooseX::StrictConstructor;
use MooX::StrictConstructor;

has 'nrf'=>(is=>'ro', isa=>InstanceOf['Photonic::LE::NR2::Field'], required=>1,
documentation=>'Haydock field calculator');
Expand All @@ -116,8 +116,7 @@ has 'densityB'=>(is=>'ro', isa=>Num, required=>1,
documentation=>'Normalized dipole entities density in medium B');
has 'density'=>(is=>'ro', isa=>PDLObj, writer=>'_density', init_arg=>undef,
documentation=>'Normalized dipole entities density over unit cell');
has 'ndims' =>(is=>'ro', isa=>Int, init_arg=>undef, lazy=>1,
builder=>'_ndims',
has 'ndims' =>(is=>'lazy', isa=>Int, init_arg=>undef,
documentation=>'Number of dimensions of system');

sub BUILD {
Expand All @@ -126,7 +125,7 @@ sub BUILD {
$self->_density($self->densityA*(1-$B)+$self->densityB*$B);
}

sub _ndims {
sub _build_ndims {
my $self=shift;
return $self->nrf->haydock->B->ndims;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Photonic/LE/S/EpsL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ Consumes L<Photonic::Roles::EpsL>
use namespace::autoclean;
use Photonic::Utils qw(lentzCF);
use List::Util qw(min);
use Moose;
use MooseX::StrictConstructor;
use Moo;
use MooX::StrictConstructor;

with 'Photonic::Roles::EpsL';

Expand Down
4 changes: 2 additions & 2 deletions lib/Photonic/LE/S/EpsTensor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ L<Photonic::Roles::UseMask>, L<Photonic::Roles::EpsFromGeometry>
use namespace::autoclean;
use Photonic::LE::S::Haydock;
use Photonic::LE::S::EpsL;
use Moose;
use MooseX::StrictConstructor;
use Moo;
use MooX::StrictConstructor;

has allh_class=>(is=>'ro', default=>'Photonic::LE::S::Haydock');
has allh_attrs=>(is=>'ro', default=>sub{[qw(reorthogonalize use_mask mask)]});
Expand Down

0 comments on commit 98152ce

Please sign in to comment.