@@ -67,13 +67,56 @@ use Photonic::Types -all;
6767use Moo;
6868use MooX::StrictConstructor;
6969
70+ # Temporary:
71+ has ' rawfield' => (is => ' lazy' , isa => PDLComplex,
72+ documentation => ' Calculated real space field, unnormalized' );
73+
7074with ' Photonic::Roles::Field' ;
7175
7276sub BUILD {
7377 my $self =shift ;
7478 $self -> haydock-> run unless $self -> haydock-> iteration;
7579}
7680
81+ # Temporary. Almost copy of _build_field
82+ sub _build_rawfield {
83+ my $self =shift ;
84+ my $as =$self -> haydock-> as ;
85+ my $bs =$self -> haydock-> bs;
86+ my $cs =$self -> haydock-> cs;
87+ my $nh =$self -> nh; # desired number of Haydock terms
88+ # don't go beyond available values.
89+ $nh =$self -> haydock-> iteration if $nh >$self -> haydock-> iteration;
90+ # calculate using lapack for tridiag system
91+ my $diag = 1-$as -> (0:$nh -1);
92+ # rotate complex zero from first to last element.
93+ my $subdiag = -$bs -> (0:$nh -1)-> rotate(-1);
94+ my $supradiag =-$cs -> (0:$nh -1)-> rotate(-1);
95+ my $rhs =PDL-> zeroes($nh ); # build a nh pdl
96+ $rhs -> slice((0)).=1;
97+ $rhs =$rhs -> r2C;
98+ # coefficients of g^{-1}E
99+ my $giEs = cgtsv($subdiag , $diag , $supradiag , $rhs );
100+ # states are xy,pm,nx,ny...
101+ my $stateit =$self -> haydock-> states;
102+ my $ndims =$self -> haydock-> B-> ndims; # num. of dims of space
103+ # field is xy,pm,nx,ny...
104+ my $field_G =linearCombineIt($giEs , $stateit ); # En ^G|psi_n>
105+ my $Es =$self -> haydock-> applyMetric($field_G );
106+ # Comment as unnormalized
107+ # $Es*=$bs->((0))/$self->haydock->metric->epsilon;
108+ my $Esp =$Es (:,(0)); # choose +k spinor component.
109+ $Esp *= $self -> filter-> (*1) if $self -> has_filter;
110+ # #get cartesian out of the way, fourier transform, put cartesian.
111+ my $field_R =GtoR($Esp , $ndims , 1);
112+ $field_R *=$self -> haydock-> B-> nelem; # scale??
113+ my $b0 =$self -> haydock-> bs-> slice(' (0)' ); # #First state normalization factor
114+ $field_R *=$b0 ; # scale??
115+ $field_R /=$self -> haydock-> B-> nelem; # normalize FT?
116+ return $field_R ; # result is xy,nx,ny...
117+ }
118+
119+
77120sub _build_field {
78121 my $self =shift ;
79122 my $as =$self -> haydock-> as ;
@@ -101,6 +144,7 @@ sub _build_field {
101144 # Comment as normalization below makes it useless
102145 # $Es*=$bs->((0))/$self->haydock->metric->epsilon;
103146 my $Esp =$Es (:,(0)); # choose +k spinor component.
147+ # project unto polarization?
104148 my $e_0 =1/($Esp -> slice(" :" . " ,(0)" x $ndims )
105149 *$self -> haydock-> polarization-> conj)-> sumover;
106150 # Normalize result so macroscopic field is 1.
0 commit comments