tstState.cpp

./Core/dc/tests/tstState.cpp

#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include "Nemesis/gtest/nemesis_gtest.hh"
#include "Nemesis/harness/DBC.hh"
#include "Origen/Core/config.h"
using namespace Origen;
TEST( State, Accumulate )
{
// get a state
State state1 = f.states_at( 0 );
double volume = state1.concs().volume();
double power = state1.definition().power();
double flux = state1.definition().flux();
EXPECT_FLOAT_EQ( 1.0, state1.concs().vals_at( 0 ) );
// get a second state that looks like the first but is empty
State state;
StateInfo def = state1.definition();
def.set_power( 10 );
def.set_flux( 1e14 );
state.set_definition( def );
EXPECT_FLOAT_EQ( 0.0, state.concs().volume() );
// accumulate the full state into the empty
state.accumulate( state1 );
EXPECT_FLOAT_EQ( 1.0, state.concs().vals_at( 0 ) );
EXPECT_FLOAT_EQ( volume, state.concs().volume() );
EXPECT_FLOAT_EQ( 10 + power, state.definition().power() ); // add them
EXPECT_FLOAT_EQ( flux, state.definition().flux() ); // weighted average
// them
// accmulate again
state.accumulate( state1 );
EXPECT_FLOAT_EQ( 2.0, state.concs().vals_at( 0 ) );
EXPECT_FLOAT_EQ( 2 * volume, state.concs().volume() );
EXPECT_FLOAT_EQ( 10 + 2 * power, state.definition().power() ); // add them
EXPECT_FLOAT_EQ( flux, state.definition().flux() ); // weighted average
// them
// again with volumes not the same
Concentrations concs = state1.concs();
concs.set_volume( 3.0 );
state1.set_concs( concs );
def.set_power( power );
state1.set_definition( def );
state.accumulate( state1 );
EXPECT_FLOAT_EQ( 3.0, state.concs().vals_at( 0 ) );
double new_volume = 2 * volume + 3.0;
EXPECT_FLOAT_EQ( new_volume, state.concs().volume() );
EXPECT_FLOAT_EQ( 10 + 3 * power, state.definition().power() ); // add them
EXPECT_FLOAT_EQ( ( flux * 2. * volume + 3.0 * 1e14 ) / new_volume,
state.definition().flux() ); // weighted average them
}