Skip to content
Snippets Groups Projects
Commit ffa81a05 authored by renchao.lu's avatar renchao.lu
Browse files

[CL] Set aqueous solution.

parent 7c0e62f3
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "BaseLib/Algorithm.h" #include "BaseLib/Algorithm.h"
#include "BaseLib/ConfigTreeUtil.h" #include "BaseLib/ConfigTreeUtil.h"
#include "MathLib/LinAlg/Eigen/EigenVector.h" #include "MathLib/LinAlg/Eigen/EigenVector.h"
#include "MathLib/LinAlg/LinAlg.h"
#include "MeshLib/Mesh.h" #include "MeshLib/Mesh.h"
#include "PhreeqcIOData/AqueousSolution.h" #include "PhreeqcIOData/AqueousSolution.h"
#include "PhreeqcIOData/ChemicalSystem.h" #include "PhreeqcIOData/ChemicalSystem.h"
...@@ -116,8 +117,7 @@ void PhreeqcIO::initialize() ...@@ -116,8 +117,7 @@ void PhreeqcIO::initialize()
void PhreeqcIO::executeInitialCalculation( void PhreeqcIO::executeInitialCalculation(
std::vector<GlobalVector> const& interpolated_process_solutions) std::vector<GlobalVector> const& interpolated_process_solutions)
{ {
setAqueousSolutionsOrUpdateProcessSolutions( setAqueousSolution(interpolated_process_solutions);
process_solutions, Status::SettingAqueousSolutions);
writeInputsToFile(); writeInputsToFile();
...@@ -132,8 +132,7 @@ void PhreeqcIO::executeInitialCalculation( ...@@ -132,8 +132,7 @@ void PhreeqcIO::executeInitialCalculation(
void PhreeqcIO::doWaterChemistryCalculation( void PhreeqcIO::doWaterChemistryCalculation(
std::vector<GlobalVector*>& process_solutions, double const dt) std::vector<GlobalVector*>& process_solutions, double const dt)
{ {
setAqueousSolutionsOrUpdateProcessSolutions( setAqueousSolution(interpolated_process_solutions);
process_solutions, Status::SettingAqueousSolutions);
setAqueousSolutionsPrevFromDumpFile(); setAqueousSolutionsPrevFromDumpFile();
...@@ -147,66 +146,23 @@ void PhreeqcIO::doWaterChemistryCalculation( ...@@ -147,66 +146,23 @@ void PhreeqcIO::doWaterChemistryCalculation(
process_solutions, Status::UpdatingProcessSolutions); process_solutions, Status::UpdatingProcessSolutions);
} }
void PhreeqcIO::setAqueousSolutionsOrUpdateProcessSolutions( void PhreeqcIO::setAqueousSolution(
std::vector<GlobalVector*> const& process_solutions, Status const status) std::vector<GlobalVector> const& interpolated_process_solutions)
{ {
std::size_t const num_chemical_systems = _mesh.getNumberOfBaseNodes();
auto const chemical_system_map =
*_mesh.getProperties().template getPropertyVector<std::size_t>(
"bulk_node_ids", MeshLib::MeshItemType::Node, 1);
// Loop over chemical systems
auto& aqueous_solution = _chemical_system->aqueous_solution; auto& aqueous_solution = _chemical_system->aqueous_solution;
// components
auto& components = aqueous_solution->components; auto& components = aqueous_solution->components;
for (std::size_t local_id = 0; local_id < num_chemical_systems; ++local_id) for (unsigned component_id = 0; component_id < components.size();
++component_id)
{ {
auto const global_id = chemical_system_map[local_id]; MathLib::LinAlg::copy(interpolated_process_solutions[component_id + 1],
// Loop over transport process id map to retrieve component *components[component_id].amount);
// concentrations from process solutions or to update process solutions
// after chemical calculation by Phreeqc
for (unsigned component_id = 0; component_id < components.size();
++component_id)
{
auto& component = components[component_id];
auto& transport_process_solution =
process_solutions[component_id + 1];
switch (status)
{
case Status::SettingAqueousSolutions:
// Set component concentrations.
component.amount->set(
local_id, (*transport_process_solution)[global_id]);
break;
case Status::UpdatingProcessSolutions:
// Update solutions of component transport processes.
transport_process_solution->set(
global_id, (*component.amount)[local_id]);
break;
}
}
switch (status)
{
case Status::SettingAqueousSolutions:
{
// Set pH value by hydrogen concentration.
aqueous_solution->pH->set(
local_id,
-std::log10((*process_solutions.back())[global_id]));
break;
}
case Status::UpdatingProcessSolutions:
{
// Update hydrogen concentration by pH value.
auto hydrogen_concentration =
std::pow(10, -(*aqueous_solution->pH)[local_id]);
process_solutions.back()->set(global_id,
hydrogen_concentration);
break;
}
}
} }
// pH
MathLib::LinAlg::copy(interpolated_process_solutions.back(),
*aqueous_solution->pH);
} }
void PhreeqcIO::setAqueousSolutionsPrevFromDumpFile() void PhreeqcIO::setAqueousSolutionsPrevFromDumpFile()
......
...@@ -31,12 +31,6 @@ struct SurfaceSite; ...@@ -31,12 +31,6 @@ struct SurfaceSite;
struct Dump; struct Dump;
struct UserPunch; struct UserPunch;
enum class Status
{
SettingAqueousSolutions,
UpdatingProcessSolutions
};
class PhreeqcIO final : public ChemicalSolverInterface class PhreeqcIO final : public ChemicalSolverInterface
{ {
public: public:
...@@ -60,9 +54,8 @@ public: ...@@ -60,9 +54,8 @@ public:
std::vector<GlobalVector*>& process_solutions, std::vector<GlobalVector*>& process_solutions,
double const dt) override; double const dt) override;
void setAqueousSolutionsOrUpdateProcessSolutions( void setAqueousSolution(
std::vector<GlobalVector*> const& process_solutions, std::vector<GlobalVector> const& interpolated_process_solutions);
Status const status);
void writeInputsToFile(double const dt = 0); void writeInputsToFile(double const dt = 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment