@@ -63,8 +63,7 @@ bool NCP::CrystallineTexture::isApplicable( const NC::Info& info )
6363 return info.countCustomSections (pluginNameUpperCase ()) > 0 ;
6464}
6565
66- NCP::CrystallineTexture NCP::CrystallineTexture::createFromInfo ( const NC::SCOrientation& sco,
67- const NC::Info& info,
66+ NCP::CrystallineTexture NCP::CrystallineTexture::createFromInfo ( const NC::Info& info,
6867 NC::PlaneProvider * std_pp)
6968{
7069 // Parse the content of our custom section. In case of syntax errors, we should
@@ -114,11 +113,10 @@ NCP::CrystallineTexture NCP::CrystallineTexture::createFromInfo( const NC::SCOri
114113 const NCrystal::StructureInfo& struct_info = info.getStructureInfo ();
115114
116115 // Parsing done! Create and return our model:
117- return CrystallineTexture (sco, preferred_orientation1,R1,f1,preferred_orientation2,R2,f2,struct_info,std_pp);
116+ return CrystallineTexture (preferred_orientation1,R1,f1,preferred_orientation2,R2,f2,struct_info,std_pp);
118117}
119118
120- NCP::CrystallineTexture::CrystallineTexture ( const NC::SCOrientation& sco,
121- const NCrystal::Vector& preferred_orientation1, double R1, double f1,
119+ NCP::CrystallineTexture::CrystallineTexture ( const NCrystal::Vector& preferred_orientation1, double R1, double f1,
122120 const NCrystal::Vector& preferred_orientation2, double R2, double f2,
123121 const NCrystal::StructureInfo& struct_info,
124122 NCrystal::PlaneProvider * plane_provider )
@@ -129,13 +127,6 @@ NCP::CrystallineTexture::CrystallineTexture( const NC::SCOrientation& sco,
129127 m_R2(R2),
130128 m_f2(f2)
131129{
132- // Important note to developers who are using the infrastructure in the
133- // testcode/ subdirectory: If you change the number or types of the arguments
134- // for the constructor here, you should make sure to perform a corresponding
135- // change in three files in the testcode/ directory: _cbindings.py,
136- // __init__.py, and NCForPython.cc - that way you can still instantiate your
137- // model directly from your python test code).
138-
139130 nc_assert ( preferred_orientation1.mag () > 0.0 );
140131 nc_assert ( m_R1 > 0.0 );
141132 nc_assert ( m_f1 > 0.0 );
@@ -144,12 +135,10 @@ NCP::CrystallineTexture::CrystallineTexture( const NC::SCOrientation& sco,
144135 nc_assert ( m_f2 > 0.0 );
145136 nc_assert ( plane_provider->canProvide () );
146137
147- m_reclat = getReciprocalLatticeRot ( struct_info );
148138 NCrystal::RotMatrix lattice_rot = NC::getLatticeRot ( struct_info.lattice_a , struct_info.lattice_b , struct_info.lattice_c ,
149139 struct_info.alpha *NC::kDeg , struct_info.beta *NC::kDeg , struct_info.gamma *NC::kDeg );
150- m_lab2cry = getCrystal2LabRot ( sco, m_reclat ).getInv ();
151140
152- // RotMatrix cry2lab = getCrystal2LabRot( sco, m_reclat );
141+
153142 double V0numAtom = struct_info.n_atoms * struct_info.volume ;
154143 const double xsectfact = 0.5 / V0numAtom;
155144
@@ -171,15 +160,9 @@ NCP::CrystallineTexture::CrystallineTexture( const NC::SCOrientation& sco,
171160 }
172161}
173162
174- double NCP::CrystallineTexture::calcCrossSection ( NC::NeutronEnergy neutron_ekin, const NC::NeutronDirection& ndirlab ) const
163+ double NCP::CrystallineTexture::calcCrossSection ( NC::NeutronEnergy neutron_ekin ) const
175164{
176- (void )ndirlab;// FIXME: Actually use this!!
177- // auto ndir = ( m_lab2cry * ndirlab.as<NC::Vector>() ).unit();
178- // ndir[0],ndir[1],ndir[2]
179- // auto neutron_HKL = m_reclat * ndir;
180-
181165 double xs_in_barns = 0.0 ;
182-
183166 const double wl = neutron_ekin.wavelength ().dbl ();
184167 const double wlsq = NC::ncsquare (wl);
185168 for ( auto & e: m_hklPlanes ) {
@@ -190,20 +173,14 @@ double NCP::CrystallineTexture::calcCrossSection( NC::NeutronEnergy neutron_ekin
190173 xs_in_barns += e.strength * (P1 * m_f1 + P2 * m_f2);
191174 }
192175 xs_in_barns *= 2 .*wlsq; // consideration of the negative hkl
193-
194176 return xs_in_barns;
195177}
196178
197- NC::ScatterOutcome NCP::CrystallineTexture::sampleScatteringEvent ( NC::RNG& rng, NC::NeutronEnergy neutron_ekin, const NC::NeutronDirection& ndirlab ) const
179+ NC::ScatterOutcomeIsotropic NCP::CrystallineTexture::sampleScatteringEvent ( NC::RNG& rng, NC::NeutronEnergy neutron_ekin ) const
198180{
199- // Don't do anything:
200- // return { neutron_ekin, ndirlab };
201- // return { neutron_ekin, NC::randIsotropicDirection(rng).as<NeutronDirection>() };
202-
203- NC::NeutronDirection outndirlab = ndirlab; // outgoing neutron direction
204181 const double wl = neutron_ekin.wavelength ().dbl ();
205182 const double wlsq = NC::ncsquare (wl);
206- const double xs = calcCrossSection ( neutron_ekin, ndirlab ) / (2 .*wlsq); // calculate xs
183+ const double xs = calcCrossSection ( neutron_ekin ) / (2 .*wlsq);
207184 const double rnd = rng.generate (); // random number on [0;1]
208185
209186 double left_bound = 0 .;
@@ -220,38 +197,11 @@ NC::ScatterOutcome NCP::CrystallineTexture::sampleScatteringEvent( NC::RNG& rng,
220197 const double E_hkl = 0.5 * NC::kPiSq * NC::const_hhm / NC::ncsquare (e.d_hkl );
221198 const double mu = 1 . - 2 * E_hkl / neutron_ekin.dbl ();
222199 nc_assert ( NC::ncabs (mu) <= 1.0 );
223- outndirlab.as <NC::Vector>() = NC::randDirectionGivenScatterMu ( rng, mu, ndirlab.as <NC::Vector>() );
224- break ;
200+ return { neutron_ekin, NC::CosineScatAngle{ mu } };
225201 }
226202 else {
227203 left_bound = right_bound;
228204 }
229205 }
230-
231- return { neutron_ekin, outndirlab };
232-
233- // if ( ! (neutron_ekin > m_cutoffekin) ) {
234- // Special case: We are asked to sample a scattering event for a neutron
235- // energy where we have zero cross section! Although in a real simulation we
236- // would usually not expect this to happen, users with custom code might
237- // still generate such calls. The only consistent thing to do when the cross
238- // section is zero is to not change the neutron state parameters, which means:
239- // result.ekin_final = neutron_ekin;
240- // result.mu = 1.0;
241- // return result;
242- // }
243-
244- // Implement our actual model here. Of course it is trivial for the example
245- // model. For a more realistic or complicated model, it might be that
246- // additional helper classes or functions should be created and used, in order
247- // to keep the code here manageable:
248-
249- // result.ekin_final = neutron_ekin;//Elastic
250- // result.mu = randIsotropicScatterMu(rng).dbl();
251-
252- // Same as coherent elastic scattering
253- // result.ekin_final = neutron_ekin.dbl();
254- // result.mu = randIsotropicScatterMu(rng).dbl(); // Take isotropic first for test
255-
256- // return result;
206+ return { neutron_ekin, NC::CosineScatAngle{1.0 } };// state unchanged
257207}
0 commit comments