Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91961620
switch_basis.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Nov 16, 04:14
Size
2 KB
Mime Type
text/x-c
Expires
Mon, Nov 18, 04:14 (2 d)
Engine
blob
Format
Raw Data
Handle
22354909
Attached To
rSPECMICP SpecMiCP / ReactMiCP
switch_basis.cpp
View Options
/*-------------------------------------------------------
- Module : database
- File : switch_basis.cpp
- Author : Fabien Georget
Copyright (c) 2014, Fabien Georget, Princeton University
---------------------------------------------------------*/
#include "switch_basis.hpp"
#include <Eigen/Eigen>
#include "canonicalizer.hpp"
namespace specmicp {
namespace database {
void BasisSwitcher::change_basis(std::vector<int>& new_basis)
{
if (not is_database_canonical())
{
canonicalize_database(data);
}
Eigen::MatrixXd beta = Eigen::MatrixXd::Zero(data->nb_component, data->nb_component);
Eigen::VectorXd kswap(data->nb_component);
// swap coefficients, build beta matrix and kswap
for (int i=0; i<data->nb_component; ++i)
{
if (new_basis[i] >= data->nb_component)
{
int j = new_basis[i] - data->nb_component;
beta.row(i) = data->nu_aqueous.row(j);
data->nu_aqueous.row(j) = Eigen::VectorXd::Zero(data->nb_component);
data->nu_aqueous(j, i) = 1.0;
kswap(i) = data->logk_aqueous(j);
data->logk_aqueous(j) = 0.0;
}
else
{
beta(i, i) = 1.0;
kswap(i) = 0.0;
}
}
Eigen::MatrixXd betainv = beta.inverse();
data->molar_mass_basis = beta*data->molar_mass_basis;
data->nu_aqueous = data->nu_aqueous * betainv;
data->logk_aqueous -= data->nu_aqueous * kswap;
swap_aq_param(new_basis);
swap_labels(new_basis);
// now do the minerals
data->nu_mineral = data->nu_mineral*betainv;
data->logk_mineral -= data->nu_mineral * kswap;
data->nu_mineral_kinetic = data->nu_mineral_kinetic*betainv;
data->logk_mineral_kinetic -= data->nu_mineral_kinetic * kswap;
// and the gases
if (data->nb_gas != 0)
{
data->nu_gas = data->nu_gas*betainv;
data->logk_gas -= data->nu_gas * kswap;
}
}
void BasisSwitcher::swap_aq_param(std::vector<int> new_basis)
{
for (int i=0; i< data->nb_component; ++i)
{
if(new_basis[i] >= data->nb_component)
{
const int j = new_basis[i];
data->param_aq.row(i).swap(data->param_aq.row(j));
}
}
}
void BasisSwitcher::swap_labels(std::vector<int> new_basis)
{
for (int i=0; i<data->nb_component; ++i)
{
if (new_basis[i] >= data->nb_component)
{
std::swap(data->labels_basis[i], data->labels_aqueous[new_basis[i]-data->nb_component]);
}
}
}
} // end namespace database
} // end namespace specmicp
Event Timeline
Log In to Comment