Page MenuHomec4science

diffusion_secondary.hpp
No OneTemporary

File Metadata

Created
Mon, Jul 29, 10:32

diffusion_secondary.hpp

/*-------------------------------------------------------
- Module : reactmicp/systems/diffusion
- File : diffusion_secondary.hpp
- Author : Fabien Georget
Copyright (c) 2014, Fabien 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:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
* Neither the name of the Princeton University 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 OWNER 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_REACTMICP_SYSTEMS_DIFFUSION_SECONDARY_HPP
#define SPECMICP_REACTMICP_SYSTEMS_DIFFUSION_SECONDARY_HPP
#include <memory>
#include "database/data_container.hpp"
#include "reactmicp/common.hpp"
#include "diffusion_numbering.hpp"
namespace specmicp {
namespace reactmicp {
namespace systems {
namespace diffusion {
//! \brief handle secondary variables for the diffusion system
class DiffusionSecondaryVariables
{
public:
using Variables = ParabolicVariables;
DiffusionSecondaryVariables(int nb_nodes,
std::shared_ptr<database::DataContainer> thedatabase,
DiffusionNumbering& numberer):
m_data(thedatabase), m_ideq(numberer),
m_secondary_variables(Eigen::MatrixXd(thedatabase->nb_component+thedatabase->nb_aqueous+1, nb_nodes)),
m_secondary_concentration(Eigen::MatrixXd(thedatabase->nb_aqueous, nb_nodes))
{
m_secondary_variables.setZero();
m_secondary_concentration.setZero();
}
// Secondary variables
// ===================
// Algorithms
// ----------
//! \brief Set secondary concentrations
void compute_secondary_concentrations(const Variables& variable);
//! \brief Set secondary concentrations for node 'node'
void nodal_secondary_concentrations(ind_t node, const Variables& variable);
//! \brief Solve for secondary variables
int solve_secondary_variables(const Variables& variable);
//! \brief Solve for secondary variables in one node
int nodal_solve_secondary_variables(ind_t node, const Variables& variable);
//! \brief Compute secondary variables
void compute_secondary_variables(const Variables& variable);
//! \brief Compute the secondary variables at node 'node'
void nodal_secondary_variables(ind_t node, const Variables& variable);
//! \brief compute the ionic strengths
void compute_ionic_strength(const Variables& variable);
//! \brief compute the ionic strength for node 'node'
void nodal_ionic_strength(ind_t node, const Variables& variable);
//! \brief compute the activity coefficients
void compute_loggamma();
//! \brief compute the logarithm of the activity coefficients for node 'node'
void nodal_loggamma(ind_t node);
//! \brief compute the activity coefficient for the components of node 'node'
void nodal_loggamma_component(ind_t node);
//! \brief compute the activity coefficient for the aqueous species of node 'node'
void nodal_loggamma_aqueous(ind_t node);
// Getters and setters
// -------------------
//! \brief Secondary species concentration
double& secondary_concentration(ind_t node, ind_t aqueous) {
assert(aqueous >= 0 and aqueous < m_data->nb_aqueous);
return m_secondary_concentration.coeffRef(aqueous, node);
}
//! \brief Secondary species concentration
double secondary_concentration(ind_t node, ind_t aqueous) const {
assert(aqueous >= 0 and aqueous < m_data->nb_aqueous);
return m_secondary_concentration.coeff(aqueous, node);
}
//! \brief Return the loggamma of a component
double& loggamma_component(ind_t node, ind_t component) {
assert(component >= 1 and component < m_data->nb_component);
return m_secondary_variables.coeffRef(component, node);
}
//! \brief Return the loggamma of a component
double loggamma_component(ind_t node, ind_t component) const {
assert(component >= 1 and component < m_data->nb_component);
return m_secondary_variables.coeff(component, node);
}
//! \brief Return the loggamma of a secondary species
double& loggamma_secondary(ind_t node, ind_t aqueous) {
assert(aqueous >= 0 and aqueous < m_data->nb_aqueous);
return m_secondary_variables.coeffRef(m_data->nb_component + aqueous, node);
}
//! \brief Return the loggamma of a secondary species
double loggamma_secondary(ind_t node, ind_t aqueous) const {
assert(aqueous >= 0 and aqueous < m_data->nb_aqueous);
return m_secondary_variables.coeff(m_data->nb_component + aqueous, node);
}
//! \brief Return ionic strength
double& ionic_strength(ind_t node) {
return m_secondary_variables.coeffRef(m_data->nb_component+m_data->nb_aqueous, node);
}
//! \brief Return ionic strength
double ionic_strength(ind_t node) const {
return m_secondary_variables.coeff(m_data->nb_component+m_data->nb_aqueous, node);
}
//! \brief Return norm of the loggamma
double loggamma_norm() const {
return m_secondary_variables.norm();
}
private:
// Return the norm used to check the convergence of the fixed-point iterations
double norm_secondary_variables();
double nodal_norm_secondary_variables(ind_t node);
std::shared_ptr<database::DataContainer> m_data;
DiffusionNumbering& m_ideq;
Eigen::MatrixXd m_secondary_variables;
Eigen::MatrixXd m_secondary_concentration;
};
} // end namespace diffusion
} // end namespace systems
} // end namespace reactmicp
} // end namespace specmicp
#endif // SPECMICP_REACTMICP_SYSTEMS_DIFFUSION_SECONDARY_HPP

Event Timeline