Page MenuHomec4science

secondary.cpp
No OneTemporary

File Metadata

Created
Tue, Nov 5, 01:04

secondary.cpp

#include "catch.hpp"
#include "utils.hpp"
#include "test_database.hpp"
#include "reactmicp/systems/diffusion/diffusion_secondary.hpp"
#include "database/database.hpp"
using namespace specmicp;
using namespace specmicp::reactmicp::systems::diffusion;
TEST_CASE("Secondary variables", "[Secondary, Diffusion]") {
DiffusionSecondaryVariables::Variables var;
std::shared_ptr<database::DataContainer> database = get_test_carbo_database();
EquilibriumState comp_bc;
comp_bc = blank_composition(database);
BoundaryCondition bc_node0;
bc_node0.node = 0;
bc_node0.composition = comp_bc;
bc_node0.fix_all();
ListBoundaryCondition bcs = {bc_node0,};
DiffusionNumbering numberer(5, database, bcs, var);
SECTION("Initialization") {
DiffusionSecondaryVariables secondary(5, database, numberer);
CHECK( secondary.secondary_concentration(2, 2) == 0 );
CHECK( secondary.secondary_concentration(2, 3) == 0 );
CHECK( secondary.secondary_concentration(2, 4) == 0 );
CHECK( secondary.loggamma_component(2, 3) == 0 );
CHECK( secondary.loggamma_secondary(2, 3) == 0 );
}
SECTION("Ionic strength computation") {
DiffusionSecondaryVariables secondary(5, database, numberer);
database::Database database_handler(database);
var.displacement(numberer.get_dof_massbalance(1, database_handler.component_label_to_id("Ca[2+]"))) = -3;
var.displacement(numberer.get_dof_massbalance(1, database_handler.component_label_to_id("HO[-]"))) = -3;
var.displacement(numberer.get_dof_massbalance(1, database_handler.component_label_to_id("HCO3[-]"))) = -3;
var.displacement(numberer.get_dof_massbalance(1, database_handler.component_label_to_id("SiO(OH)3[-]"))) = -3;
secondary.nodal_ionic_strength(1, var);
REQUIRE(secondary.ionic_strength(1) == (4*1e-3 +3*1e-3)*0.5);
secondary.secondary_concentration(1, database_handler.aqueous_label_to_id("CO3[2-]")) = 1e-2;
secondary.nodal_ionic_strength(1, var);
REQUIRE(secondary.ionic_strength(1) == (4*1e-3 +3*1e-3 + 4*1e-2)*0.5);
secondary.secondary_concentration(1, database_handler.aqueous_label_to_id("CO2")) = 1e-1;
secondary.nodal_ionic_strength(1, var);
REQUIRE(secondary.ionic_strength(1) == (4*1e-3 +3*1e-3 + 4*1e-2)*0.5);
}
SECTION("Aqueous concentration") {
DiffusionSecondaryVariables secondary(5, database, numberer);
secondary.ionic_strength(0) = comp_bc.ionic_strength();
secondary.nodal_loggamma(0);
secondary.nodal_secondary_concentrations(0, var);
for (int aq: database->range_aqueous())
{
REQUIRE(std::pow(10.0, secondary.loggamma_secondary(0, aq)) == comp_bc.activity_coefficient_secondary(aq));
REQUIRE(std::abs(secondary.secondary_concentration(0, aq) - comp_bc.molality_secondary()[aq]) < 1e-7);
}
}
}

Event Timeline