Skip to content

Commit effc4d5

Browse files
committed
Merge branch 'feature/tsl-part3' into 'develop'
Feature/tsl part3 See merge request njoy/dryad!119
2 parents cbc678d + 8712a20 commit effc4d5

File tree

11 files changed

+148165
-0
lines changed

11 files changed

+148165
-0
lines changed

cmake/unit_testing.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,12 @@ add_cpp_test( dryad.format.endf.createEndfInterpolants
222222
add_cpp_test( dryad.format.endf.createEndfSublibraryType dryad/format/endf/createEndfSublibraryType.test.cpp )
223223
add_cpp_test( dryad.format.endf.atomic.createEndfSubshellDesignator dryad/format/endf/atomic/createEndfSubshellDesignator.test.cpp )
224224
add_cpp_test( dryad.format.endf.atomic.createEndfSubshellData dryad/format/endf/atomic/createEndfSubshellData.test.cpp )
225+
add_cpp_test( dryad.format.endf.thermal.createEndfIncoherentElastic dryad/format/endf/thermal/createEndfIncoherentElastic.test.cpp )
225226
add_cpp_test( dryad.format.endf.createEndfFile3Section dryad/format/endf/createEndfFile3Section.test.cpp )
226227
add_cpp_test( dryad.format.endf.createEndfFile23Section dryad/format/endf/createEndfFile23Section.test.cpp )
227228
add_cpp_test( dryad.format.endf.createAtomicRelaxationEndfFile dryad/format/endf/createAtomicRelaxationEndfFile.test.cpp )
228229
add_cpp_test( dryad.format.endf.createProjectileTargetEndfFile dryad/format/endf/createProjectileTargetEndfFile.test.cpp )
230+
add_cpp_test( dryad.format.endf.createThermalScatteringEndfFile dryad/format/endf/createThermalScatteringEndfFile.test.cpp )
229231

230232
add_cpp_test( dryad.format.gnds.convertEnergy dryad/format/gnds/convertEnergy.test.cpp )
231233
add_cpp_test( dryad.format.gnds.convertEnergies dryad/format/gnds/convertEnergies.test.cpp )

docs/src/dryad/ThermalScattering.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ Read from File
2020
~ThermalScattering.from_endf_file
2121
~ThermalScattering.from_gnds_file
2222

23+
Write to File
24+
~~~~~~~~~~~~~
25+
.. autosummary::
26+
:toctree: generated/
27+
28+
~ThermalScattering.to_endf_file
29+
2330
Modifiable Attributes
2431
~~~~~~~~~~~~~~~~~~~~~
2532
.. autosummary::

python/src/dryad/ThermalScattering.python.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "dryad/definitions.hpp"
77
#include "njoy/dryad/ThermalScattering.hpp"
88
#include "njoy/dryad/format/endf/createThermalScatteringFromFile.hpp"
9+
#include "njoy/dryad/format/endf/createThermalScatteringEndfFile.hpp"
910
#include "njoy/dryad/format/gnds/createThermalScatteringFromFile.hpp"
1011

1112
// namespace aliases
@@ -121,6 +122,24 @@ void wrapThermalScattering( python::module& module ) {
121122
" the GNDS file name\n"
122123
" style : string\n"
123124
" the GNDS style to process (default is eval)"
125+
)
126+
.def(
127+
128+
"to_endf_file",
129+
[] ( const Component& self, int za, int mat, const std::string& filename ) {
130+
131+
njoy::dryad::format::endf::createThermalScatteringEndfFile( self, za, mat, filename );
132+
},
133+
python::arg( "za" ), python::arg( "mat" ), python::arg( "filename" ),
134+
"Write the ThermalScattering data to an ENDF file\n\n"
135+
"Parameters\n"
136+
"----------\n"
137+
" za : int\n"
138+
" the ENDF za number to be used\n"
139+
" mat : int\n"
140+
" the ENDF mat number to be used\n"
141+
" filename : string\n"
142+
" the ENDF file name\n"
124143
);
125144

126145
// add standard equality comparison definitions
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#ifndef NJOY_DRYAD_FORMAT_ENDF_CREATETHERMALSCATTERINGENDFFILE
2+
#define NJOY_DRYAD_FORMAT_ENDF_CREATETHERMALSCATTERINGENDFFILE
3+
4+
// system includes
5+
#include <fstream>
6+
#include <vector>
7+
8+
// other includes
9+
#include "tools/Log.hpp"
10+
#include "njoy/dryad/format/endf/thermal/createEndfIncoherentElastic.hpp"
11+
#include "njoy/dryad/format/endf/createDocumentation.hpp"
12+
#include "njoy/dryad/ThermalScattering.hpp"
13+
#include "ENDFtk/Material.hpp"
14+
#include "ENDFtk/tree/Material.hpp"
15+
#include "ENDFtk/tree/updateDirectory.hpp"
16+
17+
namespace njoy {
18+
namespace dryad {
19+
namespace format {
20+
namespace endf {
21+
22+
/**
23+
* @brief Create an ENDF thermal scattering file
24+
*
25+
* @param[in] tsl the thermal scattering data
26+
* @param[in] za the za number
27+
* @param[in] mat the ENDF mat number
28+
* @param[in] filename the file name for the ENDF file
29+
*/
30+
inline void createThermalScatteringEndfFile( const ThermalScattering& tsl,
31+
int za,
32+
int mat,
33+
const std::string& filename ) {
34+
35+
int zaid = za;
36+
double awr = tsl.documentation().awr().has_value()
37+
? tsl.documentation().awr().value()
38+
: 0.;
39+
int lrp = -1;
40+
int lfi = 0;
41+
int nlib = tsl.documentation().library().has_value()
42+
? tsl.documentation().library().value()
43+
: 0;
44+
int nmod = 0;
45+
double elis = 0;
46+
double sta = 0;
47+
int lis = 0;
48+
int liso = 0;
49+
int nfor = 6;
50+
double awi = 1; // neutrons
51+
double emax = 0;
52+
int lrel = tsl.documentation().version().has_value()
53+
? tsl.documentation().version()->second
54+
: 0;
55+
int nsub = 12;
56+
int nver = tsl.documentation().version().has_value()
57+
? tsl.documentation().version()->first
58+
: 0;
59+
double temp = 0;
60+
int ldrv = 0;
61+
std::string description = tsl.documentation().description().has_value()
62+
? tsl.documentation().description().value()
63+
: "";
64+
65+
// create MF1 MT451 section for this data
66+
ENDFtk::section::Type< 1, 451 >
67+
information( zaid, awr, lrp, lfi, nlib, nmod,
68+
elis, sta, lis, liso, nfor,
69+
awi, emax, lrel, nsub, nver,
70+
temp, ldrv, std::move( description ),
71+
{ ENDFtk::DirectoryRecord( 1, 451, 1, 0 ) } );
72+
73+
// create material
74+
ENDFtk::tree::Material material( mat );
75+
material.insert( information );
76+
77+
// inser elastic if there is data
78+
if ( tsl.hasElasticScattering() ) {
79+
80+
if ( tsl.hasCoherentElasticScattering() &&
81+
tsl.hasIncoherentElasticScattering() ) {
82+
83+
// unreachable for now
84+
}
85+
else if ( tsl.hasCoherentElasticScattering() ) {
86+
87+
// unreachable for now
88+
}
89+
else {
90+
91+
ENDFtk::section::Type< 7, 2 >
92+
elastic( zaid, awr,
93+
thermal::createEndfIncoherentElastic( tsl.incoherentElasticScattering().value() ) );
94+
material.insert( elastic );
95+
}
96+
}
97+
98+
// insert inelastic if there is data
99+
if ( tsl.hasInelasticScattering() ) {
100+
101+
// unreachable for now
102+
}
103+
104+
// update index
105+
ENDFtk::tree::updateDirectory( material );
106+
107+
// add create tape
108+
ENDFtk::TapeIdentification id( "Thermal scattering data" );
109+
ENDFtk::tree::Tape tape( std::move( id ) );
110+
tape.insert( std::move( material ) );
111+
112+
// print to file
113+
std::ofstream out( filename, std::ios::binary );
114+
out << tape.content();
115+
out.close();
116+
}
117+
118+
} // endf namespace
119+
} // format namespace
120+
} // dryad namespace
121+
} // njoy namespace
122+
123+
#endif
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef NJOY_DRYAD_FORMAT_ENDF_THERMAL_CREATEENDFINCOHERENTELASTIC
2+
#define NJOY_DRYAD_FORMAT_ENDF_THERMAL_CREATEENDFINCOHERENTELASTIC
3+
4+
// system includes
5+
#include <vector>
6+
7+
// other includes
8+
#include "njoy/dryad/thermal/IncoherentElasticScattering.hpp"
9+
#include "njoy/dryad/format/endf/createEndfInterpolants.hpp"
10+
#include "njoy/dryad/format/endf/createEndfBoundaries.hpp"
11+
#include "ENDFtk/section/7/2.hpp"
12+
13+
namespace njoy {
14+
namespace dryad {
15+
namespace format {
16+
namespace endf {
17+
namespace thermal {
18+
19+
/**
20+
* @brief Create an ENDF MF7 MT2 IncoherentElastic object from an
21+
* IncoherentElasticScattering object
22+
*
23+
* @param[in] incoherent the incoherent elastic data
24+
*/
25+
inline ENDFtk::section::Type< 7, 2 >::IncoherentElastic
26+
createEndfIncoherentElastic( const dryad::thermal::IncoherentElasticScattering& incoherent ) {
27+
28+
double sb = incoherent.boundCrossSection();
29+
std::vector< long > boundaries = createEndfBoundaries( incoherent.debyeWallerIntegral().boundaries() );
30+
std::vector< long > interpolants = createEndfInterpolants( incoherent.debyeWallerIntegral().interpolants() );
31+
std::vector< double > temperatures = incoherent.debyeWallerIntegral().temperatures();
32+
std::vector< double > integrals = incoherent.debyeWallerIntegral().values();
33+
34+
return ENDFtk::section::Type< 7, 2 >::IncoherentElastic(
35+
sb,
36+
std::move( boundaries ),
37+
std::move( interpolants ),
38+
std::move( temperatures ),
39+
std::move( integrals ) );
40+
}
41+
42+
} // atomic namespace
43+
} // endf namespace
44+
} // format namespace
45+
} // dryad namespace
46+
} // njoy namespace
47+
48+
#endif

0 commit comments

Comments
 (0)