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)));
166 double aqua_density,
double scale_aqua,
double scale_sorbed,
167 double c_aqua_limit,
double mult_coef,
double second_coef);
179 inline void compute(
double &c_aqua,
double &c_sorbed);
186 inline void interpolate(
double &c_aqua,
double &c_sorbed);
200 void make_table(
const Func &isotherm,
int n_points);
206 inline ConcPair
solve_conc(ConcPair c_pair,
const Func &isotherm);
270 template <
class Func>
274 CrossFunction(
const Func &func_,
double total_mass,
double scale_aqua,
double scale_sorbed,
double rho_aqua)
296 double rho_aqua,
double scale_aqua,
double scale_sorbed,
297 double c_aqua_limit,
double mult_coef,
double second_coef)
324 c_sorbed=result.
solid;
335 c_sorbed=result.
solid;
343 int total_mass_idx = static_cast <
int>(std::floor(total_mass_steps));
345 if ( total_mass_idx < 0 ) {
xprintf(
UsrErr,
"total_mass %f seems to have negative value.\n", total_mass); }
372 boost::uintmax_t max_iter = 20;
376 double upper_solution_bound;
378 if(total_mass >= mass_limit)
380 mass_limit = total_mass;
384 pair<double,double> solution;
386 solution = boost::math::tools::toms748_solve(eq_func, 0.0, upper_solution_bound, toler, max_iter);
388 difference = (solution.second - solution.first)/2;
389 double c_aqua = solution.first + difference;
391 (total_mass -
scale_aqua_ * c_aqua)/scale_sorbed_);
438 for(
int i=0; i<= n_steps; i++) {
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.
bool operator()(const T &a, const T &b)
void make_table(int n_points)
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