Page MenuHomec4science

hdf5_unsaturated.cpp
No OneTemporary

File Metadata

Created
Fri, Dec 27, 07:23

hdf5_unsaturated.cpp

/*------------------------------------------------------------------------------
Copyright (c)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.
------------------------------------------------------------------------------*/
#include "hdf5_unsaturated.hpp"
#include "../systems/unsaturated/variables.hpp"
#include <H5Cpp.h>
#include "../../utils/io/specmicp_hdf5.hpp"
#include "../../utils/io/hdf5_eigen.hpp"
#include "../../specmicp/io/hdf5_adimensional.hpp"
#include "../../database/data_container.hpp"
#include "../../utils/compat.hpp"
#include <iostream>
using namespace specmicp::reactmicp::systems::unsaturated;
#define MAIN_VARIABLES_GRPNAME "main_variables"
#define CHEMISTRY_SOLUTION_GRPNAME "chemistry_solution"
#define TRANSPORT_PROPERTIES_GRPNAME "transport_properties"
#define LIQUID_SATURATION_DSET "liquid_saturation"
#define AQUEOUS_CONC_DSET "aqueous_concentration"
#define SOLID_CONC_DSET "solid_concentration"
#define PRESSURE_DSET "partial_pressure"
#define CAP_PRESSURE_DSET "capillary_pressure"
#define POROSITY_DSET "porosity"
#define LIQUID_DIFFUSIVITY_DSET "liquid_diffusivity"
#define REL_LIQUID_DIFFUSIVITY_DSET "relative_liquid_diffusivity"
#define LIQUID_PERMEABILITY_DSET "liquid_permeability"
#define REL_LIQUID_PERMEABILITY_DSET "relative_liquid_permeability"
#define RESISTANCE_GAS_DIFFUSIVITY_DSET "resistance_gas_diffusivity"
#define REL_GAS_DIFFUSIVITY_DSET "relative_gas_diffusivity"
namespace specmicp {
namespace io {
//! \brief Implementation of the UnsaturatedHDF5Saver
//!
//! \internal
struct SPECMICP_DLL_LOCAL UnsaturatedHDF5Saver::UnsaturatedHDF5SaverImpl
{
public:
std::shared_ptr<UnsaturatedVariables> m_vars; //!< the variables
database::RawDatabasePtr m_database; //!< the database
UnsaturatedHDF5SaverImpl(std::shared_ptr<UnsaturatedVariables> vars):
m_vars(vars),
m_database(vars->get_database())
{}
//! \brief Save the main variables
//!
//! \param file HDF5 file
//! \param section section where to save the main variables
void save_main_variables(
io::HDF5File& file,
const std::string& section
);
//! \brief Save the chemical solution
//!
//! \param file HDF5 file
//! \param section section where to save the chemical solutions
void save_chemical_solution(
io::HDF5File& file,
const std::string& section
);
//! \brief Save the transport properties
//!
//! \param file HDF5 file
//! \param section section where to save the transport properties
void save_transport_properties(
io::HDF5File& file,
const std::string& section
);
};
UnsaturatedHDF5Saver::UnsaturatedHDF5Saver(
std::shared_ptr<UnsaturatedVariables> vars):
m_impl(make_unique<UnsaturatedHDF5SaverImpl>(vars))
{}
UnsaturatedHDF5Saver::~UnsaturatedHDF5Saver() = default;
void UnsaturatedHDF5Saver::save_timepoint(HDF5File& file,
const std::string& name,
const std::string& section)
{
auto group_name = file.complete_name(name, section);
auto group = file.create_group(group_name);
m_impl->save_main_variables(file, group_name);
m_impl->save_chemical_solution(file, group_name);
m_impl->save_transport_properties(file, group_name);
}
// Implementation
// ==============
void UnsaturatedHDF5Saver::UnsaturatedHDF5SaverImpl::save_main_variables(
HDF5File& file,
const std::string& section
)
{
auto group_name = file.complete_name(MAIN_VARIABLES_GRPNAME, section);
auto group = file.create_group(group_name);
// water
{
auto water_grp_name = file.complete_name(
m_database->get_label_component(0), group_name);
auto water_group = file.create_group(water_grp_name);
save_eigen_matrix(file, LIQUID_SATURATION_DSET, water_grp_name,
m_vars->get_liquid_saturation().variable);
save_eigen_matrix(file, AQUEOUS_CONC_DSET, water_grp_name,
m_vars->get_water_aqueous_concentration().variable);
save_eigen_matrix(file, SOLID_CONC_DSET, water_grp_name,
m_vars->get_solid_concentration(0).variable);
if (m_vars->component_has_gas(0)) {
save_eigen_matrix(file, PRESSURE_DSET, water_grp_name,
m_vars->get_pressure_main_variables(0).variable);
}
save_eigen_matrix(file, CAP_PRESSURE_DSET, water_grp_name,
m_vars->get_capillary_pressure().variable);
}
for (index_t aq_component: m_database->range_aqueous_component())
{
auto aqcomp_grp_name = file.complete_name(
m_database->get_label_component(aq_component), group_name);
auto aqcomp_group = file.create_group(aqcomp_grp_name);
save_eigen_matrix(file, AQUEOUS_CONC_DSET, aqcomp_grp_name,
m_vars->get_aqueous_concentration(aq_component).variable);
save_eigen_matrix(file, SOLID_CONC_DSET, aqcomp_grp_name,
m_vars->get_solid_concentration(aq_component).variable);
if (m_vars->component_has_gas(aq_component)) {
save_eigen_matrix(file, PRESSURE_DSET, aqcomp_grp_name,
m_vars->get_pressure_main_variables(aq_component).variable);
}
}
}
void UnsaturatedHDF5Saver::UnsaturatedHDF5SaverImpl::save_chemical_solution(
HDF5File& file,
const std::string& section
)
{
auto group_name = file.complete_name(CHEMISTRY_SOLUTION_GRPNAME, section);
auto group = file.create_group(group_name);
for (auto node: m_vars->get_mesh()->range_nodes())
{
save_adimensional_system_solution(file, std::to_string(node), group_name,
m_vars->get_adim_solution(node));
}
}
// time to get ugly and use macro
// this is simply a quick wrapper that call the save_eigen matrix function
// It avoids all the boilerplate
#define save_transport_property(name, var) \
save_eigen_matrix(file, name, group_name, \
m_vars->get_##var ().variable)
void UnsaturatedHDF5Saver::UnsaturatedHDF5SaverImpl::save_transport_properties(
HDF5File& file,
const std::string& section
)
{
auto group_name = file.complete_name(TRANSPORT_PROPERTIES_GRPNAME, section);
auto group = file.create_group(group_name);
save_transport_property(POROSITY_DSET, porosity);
save_transport_property(LIQUID_DIFFUSIVITY_DSET,
liquid_diffusivity);
save_transport_property(REL_LIQUID_DIFFUSIVITY_DSET,
relative_liquid_diffusivity);
save_transport_property(LIQUID_PERMEABILITY_DSET,
liquid_permeability);
save_transport_property(REL_LIQUID_PERMEABILITY_DSET,
relative_liquid_permeability);
save_transport_property(RESISTANCE_GAS_DIFFUSIVITY_DSET,
resistance_gas_diffusivity);
save_transport_property(REL_GAS_DIFFUSIVITY_DSET,
relative_gas_diffusivity);
}
#undef save_transport_property // we remove the ugly macro, no one saws anything :)
} //end namespace io
} //end namespace specmicp

Event Timeline