Skip to content

Commit

Permalink
Making the NE case a little more robust and clean.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Blondel committed Jan 14, 2025
1 parent f36302e commit f2994eb
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 18 deletions.
37 changes: 37 additions & 0 deletions test/core/flux/FuelFitFluxHandlerTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,44 @@ BOOST_AUTO_TEST_CASE(checkComputeIncidentFlux)
{
// Create the option to create a network
xolotl::options::ConfOptions opts;

// Create a file with reaction data.
std::ofstream reactionFile("reaction.dat");
reactionFile
<< "0 0 1 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "0 1 0 -0.160789024638881 -12.7387253625273 4.2488E+11 4.23317"
<< std::endl
<< "0 2 0 2.87060634573234 -8.37649260139129 9.9337E+11 3.43830674"
<< std::endl
<< "1 0 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 1 0 3.14296517286615 -1.4324963007117 0 0" << std::endl
<< "1 2 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 3 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 4 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 5 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 6 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 7 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 8 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "Reactions" << std::endl
<< "0 0 1 0.00596" << std::endl
<< "0 1 0 0.00596" << std::endl
<< "0 2 0 0.00596" << std::endl;
reactionFile.close();

// Create a good parameter file
std::string parameterFile = "param.txt";
std::ofstream paramFile(parameterFile);
paramFile << "netParam=5 0 0 5 1" << std::endl
<< "reactionFilePath=reaction.dat" << std::endl
<< "tempParam=1500" << std::endl;
paramFile.close();

Expand Down Expand Up @@ -61,6 +95,9 @@ BOOST_AUTO_TEST_CASE(checkComputeIncidentFlux)
std::vector<NetworkType::SubdivisionRatio> subdivRatios = {
{maxXe + 1, maxV + 1, maxI + 1}};
NetworkType network(maxSpeciesAmounts, subdivRatios, 1, opts);

std::remove("reaction.dat");

// Get its size
const int dof = network.getDOF();

Expand Down
2 changes: 1 addition & 1 deletion test/core/network/AlloyNetworkTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ BOOST_AUTO_TEST_CASE(traits)
BOOST_REQUIRE_EQUAL(toNameString(Spec::Frank), "Frank");

// parseSpeciesId / getSpeciesLabel / getSpeciesName
auto network = NetworkType();
auto network = NetworkType();
auto sid = network.parseSpeciesId("V");
BOOST_REQUIRE(sid.cast<Spec>() == Spec::V);
BOOST_REQUIRE_EQUAL(network.getSpeciesLabel(sid), "V");
Expand Down
35 changes: 35 additions & 0 deletions test/core/network/NetworkTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,38 @@ using network_types =

BOOST_AUTO_TEST_CASE_TEMPLATE(defaut_constructor, T, network_types)
{
// Create a file with reaction data for NE.
std::ofstream reactionFile("reaction.dat");
reactionFile
<< "0 0 1 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "0 1 0 -0.160789024638881 -12.7387253625273 4.2488E+11 4.23317"
<< std::endl
<< "0 2 0 2.87060634573234 -8.37649260139129 9.9337E+11 3.43830674"
<< std::endl
<< "1 0 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 1 0 3.14296517286615 -1.4324963007117 0 0" << std::endl
<< "1 2 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 3 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 4 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 5 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 6 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 7 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 8 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "Reactions" << std::endl
<< "0 0 1 0.00596" << std::endl
<< "0 1 0 0.00596" << std::endl
<< "0 2 0 0.00596" << std::endl;
reactionFile.close();

using NetworkType = T;
constexpr auto speciesRange = NetworkType::getSpeciesRange();
std::vector<typename NetworkType::AmountType> maxSpeciesAmounts;
Expand All @@ -43,6 +75,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(defaut_constructor, T, network_types)
NetworkType network =
NetworkType(maxSpeciesAmounts, 1, xolotl::options::ConfOptions{});

// Remove the file because it is not needed anymore
std::remove("reaction.dat");

BOOST_REQUIRE(network.getNumClusters() > 0);
BOOST_REQUIRE(network.getDOF() > 0);
BOOST_REQUIRE(network.getDeviceMemorySize() > 0);
Expand Down
39 changes: 37 additions & 2 deletions test/interface/InterfaceTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,38 @@ BOOST_AUTO_TEST_SUITE(Interface_testSuite)

BOOST_AUTO_TEST_CASE(simple0D)
{
// Create a file with reaction data.
std::ofstream reactionFile("reaction.dat");
reactionFile
<< "0 0 1 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "0 1 0 -0.160789024638881 -12.7387253625273 4.2488E+11 4.23317"
<< std::endl
<< "0 2 0 2.87060634573234 -8.37649260139129 9.9337E+11 3.43830674"
<< std::endl
<< "1 0 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 1 0 3.14296517286615 -1.4324963007117 0 0" << std::endl
<< "1 2 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 3 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 4 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 5 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 6 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 7 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "1 8 0 11.2375337876032 22.3998792567472 4.0767E+11 4.08453089"
<< std::endl
<< "Reactions" << std::endl
<< "0 0 1 0.00596" << std::endl
<< "0 1 0 0.00596" << std::endl
<< "0 2 0 0.00596" << std::endl;
reactionFile.close();

// Create the parameter file
std::string parameterFile = "param.txt";
std::ofstream paramFile(parameterFile);
Expand All @@ -42,6 +74,7 @@ BOOST_AUTO_TEST_CASE(simple0D)
<< "material=Fuel" << std::endl
<< "dimensions=0" << std::endl
<< "process=reaction" << std::endl
<< "reactionFilePath=reaction.dat" << std::endl
<< "netParam=5 0 0 5 1" << std::endl;
paramFile.close();

Expand All @@ -55,11 +88,13 @@ BOOST_AUTO_TEST_CASE(simple0D)
// Get data to check
auto concVector = interface.getConcVector();
BOOST_REQUIRE_EQUAL(concVector[0][0][0][0].first, 0);
BOOST_REQUIRE_CLOSE(concVector[0][0][0][0].second, 400000000, 0.01);
BOOST_REQUIRE_CLOSE(concVector[0][0][0][0].second, 220899.426, 0.01);
BOOST_REQUIRE_EQUAL(concVector[0][0][0][10].first, 10);
BOOST_REQUIRE_EQUAL(concVector[0][0][0][10].second, 0);
BOOST_REQUIRE_CLOSE(
concVector[0][0][0][10].second, -1.1602146071246332e-23, 0.01);

std::remove(parameterFile.c_str());
std::remove("reaction.dat");
}

BOOST_AUTO_TEST_SUITE_END()
3 changes: 0 additions & 3 deletions xolotl/core/include/xolotl/core/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ constexpr double alphaZrCSinkStrength = 2.25e-8; // Single crystal
// constexpr double alphaZrASinkStrength = 2e-5; //cold-worked Zr
// constexpr double alphaZrCSinkStrength = 5e-6; //cold-worked Zr

constexpr double uConcentration = 24.44;
// constexpr double uConcentration = 1.0;

constexpr double zFactor = 100.0;

// Tungsten density in nm^-3
Expand Down
7 changes: 6 additions & 1 deletion xolotl/core/include/xolotl/core/flux/FuelFitFluxHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class FuelFitFluxHandler : public FluxHandler
// The temperature
double temperature;

// The uranium concentration
double uConc;

// The list of pure vacancy indices
std::vector<IdType> pureDefectIds;
std::vector<double> pureDefectFactors;
Expand Down Expand Up @@ -75,6 +78,9 @@ class FuelFitFluxHandler : public FluxHandler
initializeFluxHandler(network::IReactionNetwork& network, int surfacePos,
std::vector<double> grid) override
{
// Get the uranium concentration
uConc = 1.0 / network.getAtomicVolume();

// Set the grid
xGrid = grid;

Expand Down Expand Up @@ -220,7 +226,6 @@ class FuelFitFluxHandler : public FluxHandler
auto yield = defectYield;
auto xenonYield = xeYield;
auto ids = this->fluxIds;
auto uConc = core::uConcentration;

Kokkos::parallel_for(
1, KOKKOS_LAMBDA(std::size_t) {
Expand Down
4 changes: 2 additions & 2 deletions xolotl/core/include/xolotl/core/network/NEReactionNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class NEReactionNetwork : public ReactionNetwork<NEReactionNetwork>
getReactionGenerator() const noexcept;

void
readClusters(const std::string filename = "reactionRates.txt");
readClusters(const std::string filename = "reaction.dat");

void
readReactions(
double temperature, const std::string filename = "reactionRates.txt");
double temperature, const std::string filename = "reaction.dat");
};

namespace detail
Expand Down
4 changes: 2 additions & 2 deletions xolotl/core/include/xolotl/core/network/ReactionNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,11 @@ class ReactionNetwork : public ReactionNetworkInterface<TImpl>::Type
generateClusterData(const ClusterGenerator& generator);

void
readClusters(const std::string filename = "reactionRates.txt");
readClusters(const std::string filename = "reaction.dat");

void
readReactions(
double temperature, const std::string filename = "reactionRates.txt");
double temperature, const std::string filename = "reaction.dat");

void
defineReactions(Connectivity& connectivity);
Expand Down
4 changes: 3 additions & 1 deletion xolotl/core/src/network/NEReactionNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ NEReactionNetwork::readClusters(const std::string filename)
std::ifstream reactionFile;
reactionFile.open(filename);
if (!reactionFile.good()) {
return;
throw std::string("\nIncorrect filename for reading reactions! \n"
"Either provide reaction.dat or set the file path "
"with the reactionFilePath option.");
}

// First find how big of an object we need to create
Expand Down
8 changes: 4 additions & 4 deletions xolotl/options/src/ConfOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ ConfOptions::readParams(int argc, const char* argv[])
bpo::value<fs::path>(&fluxDepthProfileFilePath),
"The path to the custom flux profile file; the default is an empty "
"string that will use the default material associated flux handler.")(
"reactionFilePath", bpo::value<fs::path>(&reactionFilePath),
"The path to the reaction rates file; the default is an empty "
"string.")("basalPortion",
bpo::value<double>(&basalPortion)->default_value(0.1),
"reactionFilePath",
bpo::value<fs::path>(&reactionFilePath)->default_value("reaction.dat"),
"The path to the reaction rates file; the default is reaction.dat .")(
"basalPortion", bpo::value<double>(&basalPortion)->default_value(0.1),
"The value of the basal portion generated for each V (0.1 by "
"default).")("transitionSize",
bpo::value<int>(&transitionSize)->default_value(325),
Expand Down
2 changes: 1 addition & 1 deletion xolotl/options/src/JSONOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ JSONOptions::defineHandlers()
.add(
"reactionFilePath", ElemType::string,
"The path to the reaction rates file.\n"
"(default = \"\")",
"(default = \"reaction.dat\")",
JSON_ELEM_HANDLER { checkSetParam(tree, name, reactionFilePath); })
.add(
"basalPortion", ElemType::real,
Expand Down
3 changes: 2 additions & 1 deletion xolotl/options/src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ Options::Options() :
basalPortion(0.1),
transitionSize(325),
cascadeDose(-1.0),
cascadeEfficiency(0.0)
cascadeEfficiency(0.0),
reactionFilePath("reaction.dat")
{
}

Expand Down

0 comments on commit f2994eb

Please sign in to comment.