Skip to content

Commit 8202f45

Browse files
committedJan 24, 2024
Make the ZA on the HEAD record int
1 parent ad668b2 commit 8202f45

8 files changed

+52
-107
lines changed
 

‎src/ENDFtk/ControlRecord.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ namespace ENDFtk {
8686
/* methods */
8787

8888
#define DEFINE_GETTER( name, index ) \
89-
MutableReturnType< index > \
90-
name (){ return std::get< index >( this->fields ); } \
91-
\
9289
ImmutableReturnType< index > \
9390
name () const { return std::get< index >( this->fields ); }
9491

@@ -124,7 +121,7 @@ namespace ENDFtk {
124121
/**
125122
* @brief Return the number of lines in this record
126123
*/
127-
long NC() const { return 1; }
124+
static constexpr long NC() { return 1; }
128125

129126
#include "ENDFtk/ControlRecord/src/print.hpp"
130127
};

‎src/ENDFtk/DirectoryRecord.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ namespace ENDFtk {
8383
}
8484

8585
#define DEFINE_GETTER( name, index ) \
86-
MutableReturnType< index > \
87-
name (){ return std::get< index >( this->fields ); } \
88-
\
8986
ImmutableReturnType< index > \
9087
name () const { return std::get< index >( this->fields ); }
9188

‎src/ENDFtk/HeadRecord.hpp

+8-19
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,9 @@ namespace ENDFtk {
1616
HeadRecord&
1717
asHead( StructureDivision& record );
1818

19-
HeadRecord&
20-
asHead( double expectedZA,
21-
double expectedAtomicWeightRatio,
22-
StructureDivision& record );
23-
2419
const HeadRecord&
2520
asHead( const StructureDivision& record );
2621

27-
const HeadRecord&
28-
asHead( double expectedZA,
29-
double expectedAtomicWeightRatio,
30-
const StructureDivision& record );
31-
3222
class HeadRecord : protected StructureDivision {
3323
public:
3424

@@ -38,22 +28,24 @@ namespace ENDFtk {
3828
template< std::size_t index >
3929
using ImmutableReturnType = Base::ImmutableReturnType< index >;
4030

41-
HeadRecord( double C1, double C2, long L1, long L2, long N1, long N2,
31+
HeadRecord( int ZA, double C2, long L1, long L2, long N1, long N2,
4232
int MAT, int MF, int MT ) :
43-
StructureDivision( C1, C2, L1, L2, N1, N2, MAT, MF, MT ) {}
33+
StructureDivision( static_cast< double >( ZA ), C2,
34+
L1, L2, N1, N2, MAT, MF, MT ) {}
4435

4536
template< typename Iterator >
4637
HeadRecord( Iterator& it, const Iterator& end, long& lineNumber )
4738
: StructureDivision(it, end, lineNumber) { /* Do nothing */ }
4839

40+
int ZA() const {
41+
42+
return static_cast< int >( std::round( std::get< 0 >( this->base.fields ) ) );
43+
}
44+
4945
#define DEFINE_BASE_GETTER( name, position ) \
50-
MutableReturnType< position > \
51-
name(){ return std::get< position >( this->base.fields ); } \
52-
\
5346
ImmutableReturnType< position > \
5447
name() const { return std::get< position >( this->base.fields ); }
5548

56-
DEFINE_BASE_GETTER( ZA, 0 )
5749
DEFINE_BASE_GETTER( atomicWeightRatio, 1 )
5850
DEFINE_BASE_GETTER( AWR, 1 )
5951
DEFINE_BASE_GETTER( L1, 2 )
@@ -64,9 +56,6 @@ namespace ENDFtk {
6456
#undef DEFINE_BASE_GETTER
6557

6658
#define DEFINE_TAIL_GETTER( name ) \
67-
decltype( StructureDivision::tail.name() ) \
68-
name(){ return this->tail.name(); } \
69-
\
7059
decltype( std::declval \
7160
< typename std::add_const \
7261
< decltype( StructureDivision::tail ) >::type >().name() ) \

‎src/ENDFtk/HeadRecord/src/asHead.hpp

-57
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,7 @@ asHead( StructureDivision& record ){
33
return static_cast< HeadRecord& >( record );
44
}
55

6-
friend HeadRecord&
7-
asHead( double expectedZA,
8-
double expectedAtomicWeightRatio,
9-
StructureDivision& record ){
10-
auto& head = njoy::ENDFtk::asHead( record );
11-
if ( head.ZA() != expectedZA ){
12-
Log::warning(
13-
"Encountered ZA does not meet expectations for head record with:"
14-
"\n Material number (MAT) = {}"
15-
"\n File number (MF) = {}"
16-
"\n Section number (MT) = {}",
17-
head.MAT(), head.MF(), head.MT() );
18-
Log::info( "Expected ZA: {}", expectedZA );
19-
Log::info( "Encountered ZA: {}", head.ZA() );
20-
}
21-
if ( head.AWR() != expectedAtomicWeightRatio ){
22-
Log::warning(
23-
"Encountered atomic weight ratio does not meet expectations for head record with:"
24-
"\n Material number (MAT) = {}"
25-
"\n File number (MF) = {}"
26-
"\n Section number (MT) = {}",
27-
head.MAT() , head.MF(), head.MT() );
28-
Log::info( "Expected atomic weight ratio: {}", expectedAtomicWeightRatio );
29-
Log::info( "Encountered atomic weight ratio: {}", head.AWR() );
30-
}
31-
return head;
32-
}
33-
346
friend const HeadRecord&
357
asHead( const StructureDivision& record ){
368
return static_cast< const HeadRecord& >( record );
379
}
38-
39-
friend const HeadRecord&
40-
asHead( double expectedZA,
41-
double expectedAtomicWeightRatio,
42-
const StructureDivision& record ){
43-
auto& head = njoy::ENDFtk::asHead( record );
44-
if ( head.ZA() != expectedZA ){
45-
Log::warning(
46-
"Encountered ZA does not meet expectations for head record with:"
47-
"\n Material number (MAT) = {}"
48-
"\n File number (MF) = {}"
49-
"\n Section number (MT) = {}",
50-
head.MAT(), head.MF(), head.MT() );
51-
52-
Log::info( "Expected ZA: {}", expectedZA );
53-
Log::info( "Encountered ZA: {}", head.ZA() );
54-
}
55-
if ( head.AWR() != expectedAtomicWeightRatio ){
56-
Log::warning(
57-
"Encountered atomic weight ratio does not meet expectations for head record with:"
58-
"\n Material number (MAT) = {}"
59-
"\n File number (MF) = {}"
60-
"\n Section number (MT) = {}",
61-
head.MAT(), head.MF(), head.MT() );
62-
Log::info( "Expected atomic weight ratio: {}", expectedAtomicWeightRatio );
63-
Log::info( "Encountered atomic weight ratio: {}", head.AWR() );
64-
}
65-
return head;
66-
}

‎src/ENDFtk/HeadRecord/test/HeadRecord.test.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ SCENARIO( "HeadRecord" ) {
2323

2424
WHEN( "the data is given explicitly" ) {
2525

26-
double c1 = 1001;
26+
int zaid = 1001;
2727
double c2 = 0.9991673;
2828
int l1 = 1;
2929
int l2 = 2;
@@ -33,7 +33,7 @@ SCENARIO( "HeadRecord" ) {
3333
int mf = 1;
3434
int mt = 451;
3535

36-
HeadRecord chunk( c1, c2, l1, l2, n1, n2, mat, mf, mt );
36+
HeadRecord chunk( zaid, c2, l1, l2, n1, n2, mat, mf, mt );
3737

3838
THEN( "a HeadRecord can be constructed and members can be tested" ) {
3939

@@ -81,7 +81,7 @@ std::string chunk() {
8181

8282
void verifyChunk( const HeadRecord& chunk ) {
8383

84-
CHECK_THAT( 1001., WithinRel( chunk.ZA() ) );
84+
CHECK( 1001 == chunk.ZA() );
8585
CHECK_THAT( 0.9991673, WithinRel( chunk.AWR() ) );
8686
CHECK_THAT( 0.9991673, WithinRel( chunk.atomicWeightRatio() ) );
8787
CHECK( 1 == chunk.L1() );

‎src/ENDFtk/ListRecord.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ namespace ENDFtk {
9797
/* methods */
9898

9999
#define DEFINE_GETTER( name, index ) \
100-
Base::MutableReturnType< index > \
101-
name (){ return std::get< index >( this->metadata.fields ); } \
102-
\
103100
Base::ImmutableReturnType< index > \
104101
name () const { return std::get< index >( this->metadata.fields ); }
105102

‎src/ENDFtk/TextRecord.hpp

+40-15
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,69 @@ namespace njoy {
1010
namespace ENDFtk {
1111

1212
class TextRecord : protected record::Base< record::Character< 66 > > {
13-
/* convenience typedefs */
13+
1414
using base = record::Base< record::Character< 66 > >;
1515
using tail = record::TailVerifying< record::MAT, record::MF, record::MT >;
1616

1717
public:
18-
/* ctor */
19-
TextRecord( std::string&& text ) : base( std::move(text) ){}
18+
19+
/* constructor */
20+
21+
TextRecord( std::string&& text ) : base( std::move( text ) ) {}
2022

2123
template< typename Iterator >
2224
TextRecord( Iterator& it, const Iterator& end, long& lineNumber,
2325
int MAT, int MF, int MT )
24-
try: base( it, end ){
26+
try : base( it, end ) {
27+
2528
tail( MAT, MF, MT, it, end, lineNumber );
26-
} catch ( std::exception& e ) {
29+
}
30+
catch ( std::exception& e ) {
31+
2732
/* TODO error information here */
2833
throw e;
29-
} catch ( int fieldNo ){
34+
}
35+
catch ( int fieldNo ) {
36+
3037
--lineNumber;
3138
/* TODO error information here */
3239
throw std::exception();
3340
}
3441

3542
/* methods */
36-
MutableReturnType< 0 >
37-
text(){ return std::get< 0 >( this->fields ); }
3843

39-
ImmutableReturnType< 0 >
40-
text() const { return std::get< 0 >( this->fields ); }
44+
/**
45+
* @brief Return the text of the record
46+
*/
47+
const std::string& text() const {
48+
49+
return std::get< 0 >( this->fields );
50+
}
51+
52+
/**
53+
* @brief Equality operator
54+
*
55+
* @param[in] rhs the text record on the right
56+
*/
57+
bool operator==( const TextRecord& rhs ) const {
4158

42-
bool
43-
operator==( const TextRecord& rhs ) const {
4459
return static_cast< const base& >( *this ) == rhs;
4560
}
4661

47-
bool
48-
operator!=( const TextRecord& rhs ) const { return not( *this == rhs ); }
62+
/**
63+
* @brief Not equal operator
64+
*
65+
* @param[in] rhs the text record on the right
66+
*/
67+
bool operator!=( const TextRecord& rhs ) const {
68+
69+
return not( *this == rhs );
70+
}
4971

50-
long NC() const { return 1; }
72+
/**
73+
* @brief Return the number of lines in this record
74+
*/
75+
static constexpr long NC() { return 1; }
5176

5277
#include "ENDFtk/TextRecord/src/print.hpp"
5378
};

‎src/ENDFtk/record/InterpolationBase.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ namespace record {
5858
#include "ENDFtk/record/InterpolationBase/src/ctor.hpp"
5959

6060
#define DEFINE_GETTER( name, index ) \
61-
Base::MutableReturnType< index > \
62-
name (){ return std::get< index >( this->metadata.fields ); } \
63-
\
6461
Base::ImmutableReturnType< index > \
6562
name () const { return std::get< index >( this->metadata.fields ); }
6663

0 commit comments

Comments
 (0)
Please sign in to comment.