Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EGlib correction to vanishing molar concentrations #132

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/diffusion/include/antioch/molecular_binary_diffusion_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
#ifndef ANTIOCH_MOLECULAR_BINARY_DIFFUSION_UTILS_H
#define ANTIOCH_MOLECULAR_BINARY_DIFFUSION_UTILS_H

// Antioch
#include "antioch/transport_species.h"
#include "antioch/molecular_binary_diffusion_utils_decl.h"
#include "antioch/molecular_binary_diffusion_building.h"

// C++
#include <limits>

namespace Antioch
{
// getting tag
Expand Down Expand Up @@ -188,13 +192,39 @@ namespace Antioch
antioch_assert_equal_to(ds.size(),mixture.n_species());
antioch_assert_equal_to(ds.size(),mass_fractions.size());

// convenient
typedef typename value_type<VectorStateType>::type StateType;

VectorStateType molar_fractions = zero_clone(mass_fractions);
mixture.X(mixture.M(mass_fractions),mass_fractions,molar_fractions);

// EGlib traces management, see doc: http://blanche.polytechnique.fr/www.eglib/manual.ps
// page 5
// EGlib uses eps = 1e-16
typename raw_value_type<StateType>::type eps(std::numeric_limits<StateType>::epsilon() * 10);
StateType mol_frac_sum = zero_clone(mass_fractions[0]);
for(unsigned int s = 0; s < molar_fractions.size(); s++)
{
mol_frac_sum += molar_fractions[s];
}
mol_frac_sum /= (typename rebind< unsigned int, StateType >::type)(molar_fractions.size());

// (i) evaluate perturbed mole fractions
// (ii) evaluate the perturbed mean molar weight ...
StateType M_tr = zero_clone(mass_fractions[0]);
for(unsigned int s = 0; s < molar_fractions.size(); s++)
{
molar_fractions[s] += eps * (mol_frac_sum - molar_fractions[s]); // add perturbation
M_tr += molar_fractions[s] * mixture.M(s);
}


// (ii) .. evaluate perturbed mass_fraction [= molar_fraction * molar_mass / perturbed_molar_mass]
// (iii) use perturbed values to evaluate the transport properties [ (1 - y_s) / sum_i x_i / D_{is} ]
for(unsigned int s = 0; s < ds.size(); s++)
{
ds[s] = constant_clone(mass_fractions[s],1) - mass_fractions[s];
typename value_type<VectorStateType>::type denom = zero_clone(mass_fractions[0]);
ds[s] = constant_clone(mass_fractions[0],1) - mixture.M(s) / M_tr * molar_fractions[s];
StateType denom = zero_clone(mass_fractions[0]);
for(unsigned int j = 0; j < ds.size(); j++)
{
if(j == s)continue;
Expand Down