Skip to content

Commit c032c66

Browse files
committed
Plugin no longer pretends to describe an anisotropic material
1 parent b4c1318 commit c032c66

4 files changed

Lines changed: 25 additions & 84 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
name = "ncrystal-plugin-CrysText"
2424
version = "0.0.1"
2525
license = {file = "LICENSE"}
26-
dependencies = [ "ncrystal-core>=3.9.85", "ncrystal-pypluginmgr>=0.0.3" ]
26+
dependencies = [ "ncrystal-core>=4.1.4", "ncrystal-pypluginmgr>=0.0.3" ]
2727
classifiers = [
2828
"Programming Language :: Python :: 3",
2929
"License :: OSI Approved :: Apache Software License",
3030
]
3131

3232
[build-system]
33-
requires = ["scikit-build-core>=0.10", "ncrystal-core>=3.9.85" ]
33+
requires = ["scikit-build-core>=0.10", "ncrystal-core>=4.1.4" ]
3434
build-backend = "scikit_build_core.build"
3535

3636
[tool.scikit-build]

src/NCCrystallineTexture.cc

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/NCCrystallineTexture.hh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include "NCrystal/NCPluginBoilerplate.hh"//Common stuff (includes NCrystal
55
//public API headers, sets up
66
//namespaces and aliases)
7-
#include "NCrystal/interfaces/NCSCOrientation.hh"
8-
#include "NCrystal/internal/utils/NCRotMatrix.hh"
97
#include "NCrystal/internal/utils/NCVector.hh"
108
#include "NCrystal/internal/extd_utils/NCPlaneProvider.hh"
119

@@ -27,9 +25,10 @@ namespace NCPluginNamespace {
2725
//case of syntax errors in the @CUSTOM_ section data):
2826

2927
static bool isApplicable( const NC::Info& );
30-
static CrystallineTexture createFromInfo( const NC::SCOrientation&, const NC::Info&, NC::PlaneProvider * = nullptr );//will raise BadInput in case of syntax errors
28+
static CrystallineTexture createFromInfo( const NC::Info&,
29+
NC::PlaneProvider * = nullptr );//will raise BadInput in case of syntax errors
3130

32-
//The crystalline texuture or preferred orientation correction is taken into account by introducing
31+
//The crystalline texuture or preferred orientation correction is taken into account by introducing
3332
//the cylindrically symmetric Pole-Density Distribution Function (PDDF) or preferred orientation
3433
//distribution function P_hkl(lambda, theta_hkl) which depends on the orientation angle theta_hkl,
3534
//i.e., angle between the preferred orientation and the plan vectors hkl.
@@ -38,19 +37,18 @@ namespace NCPluginNamespace {
3837

3938
//Constructor gets constant cross section value, and the neutron wavelength
4039
//cutoff:
41-
CrystallineTexture( const NC::SCOrientation&,
42-
const NCrystal::Vector& preferred_orientation1, double R1, double f1,
40+
CrystallineTexture( const NCrystal::Vector& preferred_orientation1, double R1, double f1,
4341
const NCrystal::Vector& preferred_orientation2, double R2, double f2,
4442
const NCrystal::StructureInfo& struct_info,
4543
NC::PlaneProvider * std_pp = nullptr );
4644

4745
//Provide cross sections for a given neutron:
48-
double calcCrossSection( NC::NeutronEnergy, const NC::NeutronDirection&) const;
46+
double calcCrossSection( NC::NeutronEnergy ) const;
4947

5048
//Sample scattering event (rng is random number stream). Results are given
5149
//as the final ekin of the neutron and scat_mu which is cos(scattering_angle).
5250

53-
NC::ScatterOutcome sampleScatteringEvent( NC::RNG&, NC::NeutronEnergy, const NC::NeutronDirection& ) const;
51+
NC::ScatterOutcomeIsotropic sampleScatteringEvent( NC::RNG&, NC::NeutronEnergy ) const;
5452

5553
private:
5654
//Data members:
@@ -66,9 +64,6 @@ namespace NCPluginNamespace {
6664
double strength; //dspacing*fsq*xsectfact
6765
};
6866
std::vector<HKLPlane> m_hklPlanes;
69-
NCrystal::RotMatrix m_lab2cry;
70-
NCrystal::RotMatrix m_reclat;
71-
7267
};
7368

7469
}

src/NCPluginFactory.cc

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace NCPluginNamespace {
2626

2727
using PhysicsModel = CrystallineTexture;
2828

29-
class PluginScatter final : public NC::ProcImpl::ScatterAnisotropicMat {
29+
class PluginScatter final : public NC::ProcImpl::ScatterIsotropicMat {
3030
public:
3131

3232
//The factory wraps our custom PhysicsModel helper class in an NCrystal API
@@ -40,20 +40,18 @@ namespace NCPluginNamespace {
4040
PluginScatter( PhysicsModel && pm ) : m_pm(std::move(pm)) {}
4141

4242

43-
NC::CrossSect crossSection(NC::CachePtr&,
44-
NC::NeutronEnergy neutron_ekin,
45-
const NC::NeutronDirection& ndirlab ) const override
43+
NC::CrossSect crossSectionIsotropic(NC::CachePtr&,
44+
NC::NeutronEnergy neutron_ekin) const override
4645
{
47-
return NC::CrossSect{ m_pm.calcCrossSection(neutron_ekin, ndirlab) };
46+
return NC::CrossSect{ m_pm.calcCrossSection(neutron_ekin) };
4847
}
4948

5049

51-
NC::ScatterOutcome sampleScatter(NC::CachePtr&,
50+
NC::ScatterOutcomeIsotropic sampleScatterIsotropic(NC::CachePtr&,
5251
NC::RNG& rng,
53-
NC::NeutronEnergy neutron_ekin,
54-
const NC::NeutronDirection& ndirlab) const override
52+
NC::NeutronEnergy neutron_ekin) const override
5553
{
56-
return m_pm.sampleScatteringEvent( rng, neutron_ekin, ndirlab );
54+
return m_pm.sampleScatteringEvent( rng, neutron_ekin );
5755
}
5856

5957
private:
@@ -100,10 +98,8 @@ NCP::PluginFactory::produce( const NC::FactImpl::ScatterRequest& cfg ) const
10098
//Ok, we are selected as the provider! First create our own scatter model:
10199

102100
auto sc_pp = createStdPlaneProvider( cfg.infoPtr() );
103-
auto sco = cfg.createSCOrientation();
104101
auto sc_ourmodel
105-
= NC::makeSO<PluginScatter>( CrystallineTexture::createFromInfo( sco,
106-
cfg.info(),
102+
= NC::makeSO<PluginScatter>( CrystallineTexture::createFromInfo( cfg.info(),
107103
sc_pp.get() ) );
108104

109105
//Now we just need to combine this with all the other physics. So ask the

0 commit comments

Comments
 (0)