39 #ifndef SORPTION_IMPL_HH_
40 #define SORPTION_IMPL_HH_
44 #include <boost/math/tools/roots.hpp>
61 eps = T(ldexp(1.0F, 1-bits));
66 return fabs(a - b) <= (
eps * (std::max)(fabs(a), fabs(b)));
150 "The Boost solver of nonlinear equation did not converge in sorption model.\n"
151 <<
"Check input at the following address for possible user error: \t" << Input::EI_Address::val <<
"\n"
152 "Solver message: \n" << EI_BoostMessage::val);
156 "The total mass in sorption model became negative during the computation (value: "
157 << EI_TotalMass::val <<
").\n"
158 <<
"Check input at the following address for possible user error: \t" << Input::EI_Address::val <<
"\n");
190 double aqua_density,
double scale_aqua,
double scale_sorbed,
191 double c_aqua_limit,
double mult_coef,
double second_coef);
204 inline void compute(
double &c_aqua,
double &c_sorbed);
211 inline void interpolate(
double &c_aqua,
double &c_sorbed);
226 void make_table(
const Func &isotherm,
int n_points);
233 inline ConcPair
solve_conc(ConcPair c_pair,
const Func &isotherm);
301 template <
class Func>
305 CrossFunction(
const Func &func_,
double total_mass,
double scale_aqua,
double scale_sorbed,
double rho_aqua)
327 double rho_aqua,
double scale_aqua,
double scale_sorbed,
328 double c_aqua_limit,
double mult_coef,
double second_coef)
354 c_sorbed=result.
solid;
365 c_sorbed=result.
solid;
373 THROW( Isotherm::ExcNegativeTotalMass()
374 << EI_TotalMass(total_mass)
378 unsigned int total_mass_idx = static_cast <
unsigned int>(std::floor(total_mass_steps));
406 boost::uintmax_t max_iter = 20;
410 double upper_solution_bound;
412 if(total_mass >= mass_limit)
414 mass_limit = total_mass;
418 pair<double,double> solution;
422 solution = boost::math::tools::toms748_solve(eq_func, 0.0, upper_solution_bound, toler, max_iter);
424 catch(boost::exception
const & e)
426 THROW( Isotherm::ExcBoostSolver()
427 << EI_BoostMessage(boost::diagnostic_information(e))
432 difference = (solution.second - solution.first)/2;
433 double c_aqua = solution.first + difference;
435 (total_mass -
scale_aqua_ * c_aqua)/scale_sorbed_);
478 THROW( Isotherm::ExcNegativeTotalMass()
479 << EI_TotalMass(mass_limit)
483 for(
int i=0; i<= n_steps; i++) {
double operator()(double x)
Isotherm definition.
double mult_coef_
Multiplication parameter of the isotherm.
CrossFunction(const Func &func_, double total_mass, double scale_aqua, double scale_sorbed, double rho_aqua)
void compute(double &c_aqua, double &c_sorbed)
double second_coef_
Optional secod parameter of the isotherm.
ConcPair(double x, double y)
double operator()(double x)
Isotherm definition.
ConcPair solve_conc(ConcPair c_pair, const Func &isotherm)
Langmuir(double mult_coef, double alpha)
Constructor to set parameters.
double operator()(double x)
Isotherm definition.
double mult_coef_
Parameters of the isotherm.
void reinit(enum SorptionType sorption_type, bool limited_solubility_on, double aqua_density, double scale_aqua, double scale_sorbed, double c_aqua_limit, double mult_coef, double second_coef)
Freundlich(double mult_coef, double exponent)
Constructor to set parameters.
double mult_coef_
Parameters of the isotherm.
vector< double > interpolation_table
double scale_sorbed_
coefficient that convert adsorbed molar concentration to mass; molar_weight * rho_rock * (1 - porosit...
ConcPair precipitate(ConcPair conc)
Linear(double mult_coef)
Constructor to set parameters.
bool limited_solubility_on_
Solubility limit flag.
Pair of soluted and adsorbed concentration.
double operator()(double conc_aqua)
double mult_coef_
Parameters of the isotherm.
SorptionType
Type of adsorption isotherm.
TYPEDEF_ERR_INFO(EI_BoostMessage, std::string)
bool operator()(const T &a, const T &b)
void make_table(int n_points)
None()
Constructor to set parameters.
void interpolate(double &c_aqua, double &c_sorbed)
double inv_scale_aqua_
reciprocal values
ConcPair compute_projection(ConcPair conc)
double scale_aqua_
coefficient that convert soluted concentration to mass; porosity = k_W, originally rho_aqua*porosity ...
enum SorptionType adsorption_type_
Type of isotherm.
bool is_precomputed(void)
double operator()(double x)
Isotherm definition.
double rho_aqua_
density of the solvent
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
DECLARE_EXCEPTION(ExcBoostSolver,<< "The Boost solver of nonlinear equation did not converge in sorption model.\n"<< "Check input at the following address for possible user error: \t"<< Input::EI_Address::val<< "\n""Solver message: \n"<< EI_BoostMessage::val)