Page MenuHomec4science

saturated_react.hpp
No OneTemporary

File Metadata

Created
Sun, Aug 25, 11:18

saturated_react.hpp

/*-------------------------------------------------------------------------------
Copyright (c) 2014,2015 F. Georget <fabieng@princeton.edu>, Princeton University
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-----------------------------------------------------------------------------*/
#ifndef SPECMICP_IO_SATURATEDREACT_HPP
#define SPECMICP_IO_SATURATEDREACT_HPP
//! \file saturated_react.hpp
//! \brief Print information about the saturated reactive transport module
#include <iostream>
#include <fstream>
#include <chrono>
#include <ctime>
#include "../../utils/io/units.hpp"
#include "../../reactmicp/systems/saturated_react/variables.hpp"
using namespace specmicp::reactmicp::systems::satdiff;
namespace specmicp {
namespace io {
static constexpr char field_sep = '\t';
static constexpr char comment = '#';
//! \brief Print the time as a comment
void print_csv_header(std::ostream* ofile)
{
std::time_t time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
(*ofile) << comment << " - ReactMiCP - " << std::ctime(&time);
}
//! \brief Print the total aqueous concentrations in the CSV format in 'ofile'
void print_components_total_aqueous_concentration(
RawDatabasePtr the_database,
SaturatedVariablesPtr variables,
mesh::Mesh1DPtr the_mesh,
const units::UnitsSet& units_set,
std::ostream* ofile
)
{
print_csv_header(ofile);
(*ofile) << comment << "units : mol/" << io::volume_unit_to_string(units_set.length) << std::endl;
(*ofile) << "Position";
for (index_t component: the_database->range_aqueous_component())
{
(*ofile) << field_sep << the_database->get_label_component(component);
}
(*ofile) << std::endl;
for (index_t node: the_mesh->range_nodes())
{
(*ofile) << the_mesh->get_position(node);
for (index_t component: the_database->range_aqueous_component())
{
(*ofile) << field_sep << variables->aqueous_concentration(node, component);
}
(*ofile) << std::endl;
}
}
//! \brief Print the total aqueous concentrations in the CSV format in the file 'filepath'
void print_components_total_aqueous_concentration(
RawDatabasePtr the_database,
SaturatedVariablesPtr variables,
mesh::Mesh1DPtr the_mesh,
const units::UnitsSet& units_set,
const std::string& filepath
)
{
std::ofstream ofile(filepath);
print_components_total_aqueous_concentration(the_database, variables, the_mesh, units_set, &ofile);
ofile.close();
}
//! \brief Print the total solid concentrations in the CSV format in 'ofile'
void print_components_total_solid_concentration(
RawDatabasePtr the_database,
SaturatedVariablesPtr variables,
mesh::Mesh1DPtr the_mesh,
const units::UnitsSet& units_set,
std::ostream* ofile
)
{
print_csv_header(ofile);
(*ofile) << comment << "units : mol/" << io::volume_unit_to_string(units_set.length) << std::endl;
(*ofile) << "Position";
for (index_t component: the_database->range_aqueous_component())
{
(*ofile) << field_sep << the_database->get_label_component(component);
}
(*ofile) << std::endl;
for (index_t node: the_mesh->range_nodes())
{
(*ofile) << the_mesh->get_position(node);
for (index_t component: the_database->range_aqueous_component())
{
(*ofile) << field_sep << variables->solid_concentration(node, component);
}
(*ofile) << std::endl;
}
}
//! \brief Print the total solid concentrations in the CSV format in the file 'filepath'
void print_components_total_solid_concentration(
RawDatabasePtr the_database,
SaturatedVariablesPtr variables,
mesh::Mesh1DPtr the_mesh,
const units::UnitsSet& units_set,
const std::string& filepath
)
{
std::ofstream ofile(filepath);
print_components_total_solid_concentration(the_database, variables, the_mesh, units_set, &ofile);
ofile.close();
}
//! \brief Print the solid phases profiles in 'ofile'
void print_minerals_profile(
RawDatabasePtr the_database,
SaturatedVariablesPtr variables,
mesh::Mesh1DPtr the_mesh,
std::ostream* ofile
)
{
print_csv_header(ofile);
(*ofile) << "Position";
for (index_t mineral: the_database->range_mineral())
{
(*ofile) << field_sep << the_database->get_label_mineral(mineral);
}
(*ofile) << field_sep << "Porosity";
(*ofile) << field_sep << "pH";
(*ofile) << std::endl;
for (index_t node: the_mesh->range_nodes())
{
(*ofile) << the_mesh->get_position(node);
AdimensionalSystemSolutionExtractor extractor(variables->equilibrium_solution(node), the_database, units::UnitsSet());
for (index_t mineral: the_database->range_mineral())
{
(*ofile) << field_sep << extractor.volume_fraction_mineral(mineral);
}
(*ofile) << field_sep << variables->porosity(node);
(*ofile) << field_sep << extractor.pH();
(*ofile) << std::endl;
}
}
//! \brief Print the solid phases profiles in 'filepath'
void print_minerals_profile(
RawDatabasePtr the_database,
SaturatedVariablesPtr variables,
mesh::Mesh1DPtr the_mesh,
const std::string& filepath
)
{
std::ofstream ofile(filepath);
print_minerals_profile(
the_database,
variables,
the_mesh,
&ofile
);
ofile.close();
}
} // end namespace io
} // end namespace specmicp
#endif // SPECMICP_IO_SATURATEDREACT_HPP

Event Timeline