Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91961523
canonicalizer.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:11
Size
4 KB
Mime Type
text/x-c
Expires
Mon, Nov 18, 04:11 (2 d)
Engine
blob
Format
Raw Data
Handle
22354880
Attached To
rSPECMICP SpecMiCP / ReactMiCP
canonicalizer.cpp
View Options
/*-------------------------------------------------------
- Module : database
- File : canonicalizer.cpp
- Author : Fabien Georget
Copyright (c) 2014, Fabien Georget, Princeton University
---------------------------------------------------------*/
#include "canonicalizer.hpp"
#include "utils/log.hpp"
namespace specmicp {
namespace database {
void DatabaseCanonicalizer::make_canonical() {
if (data->is_canonical == true)
{
WARNING << "Database already in canonical form, aborting";
return;
}
make_aqueous_canonical();
make_mineral_canonical();
make_mineral_kinetic_canonical();
if (data->nb_gas != 0) make_gas_canonical();
data->is_canonical = true;
}
void DatabaseCanonicalizer::make_aqueous_canonical()
{
if (data->nu_aqueous.cols() == data->nb_component)
{
INFO << "Database already in canonical form";
return;
}
if (data->nu_aqueous.cols() != data->nb_component + data->nb_aqueous)
{
CRITICAL << "Canonicalization : invalid size for stoichiometric coefficients of aqueous species - abort";
throw invalid_database("Invalid size for stoichiometric coefficients of aqueous species");
}
for (int i=1; i<data->nb_aqueous; ++i)
{
for (int j=0; j<i; ++j)
{
const double stoech = data->nu_aqueous(i, data->nb_component+j);
if (stoech != 0)
{
data->nu_aqueous.row(i) += stoech*data->nu_aqueous.row(j);
data->logk_aqueous(i) += stoech*data->logk_aqueous(j);
data->nu_aqueous(i, data->nb_component+j) = 0;
}
}
}
data->nu_aqueous.conservativeResize(Eigen::NoChange_t(), data->nb_component);
}
void DatabaseCanonicalizer::make_mineral_canonical()
{
if (data->nu_mineral.cols() == data->nb_component)
{
INFO << "Database already in canonical form";
return;
}
if (data->nu_mineral.cols() != data->nb_component + data->nb_aqueous)
{
CRITICAL << "Canonicalization : invalid size for stoichiometric coefficients of mineral species - abort";
throw invalid_database("Invalid size for stoichiometric coefficients of mineral species");
}
for (int i=1; i<data->nb_mineral; ++i)
{
for (int j=0; j<data->nb_aqueous; ++j)
{
const double stoech = data->nu_mineral(i, data->nb_component+j);
if (stoech != 0)
{
data->nu_mineral.block(i, 0, 1, data->nb_component) +=
stoech*data->nu_aqueous.row(j);
data->logk_mineral(i) += stoech*data->logk_aqueous(j);
data->nu_mineral(i, data->nb_component+j) = 0;
}
}
}
data->nu_mineral.conservativeResize(Eigen::NoChange_t(), data->nb_component);
}
void DatabaseCanonicalizer::make_mineral_kinetic_canonical()
{
if (data->nu_mineral_kinetic.cols() == data->nb_component)
{
INFO << "Database already in canonical form";
return;
}
if (data->nu_mineral_kinetic.cols() != data->nb_component + data->nb_aqueous)
{
CRITICAL << "Canonicalization : invalid size for stoichiometric coefficients of mineral species - abort";
throw invalid_database("Invalid size for stoichiometric coefficients of mineral species");
}
for (int i=1; i<data->nb_mineral_kinetic; ++i)
{
for (int j=0; j<data->nb_aqueous; ++j)
{
const double stoech = data->nu_mineral_kinetic(i, data->nb_component+j);
if (stoech != 0)
{
data->nu_mineral_kinetic.block(i, 0, 1, data->nb_component) +=
stoech*data->nu_aqueous.row(j);
data->logk_mineral_kinetic(i) += stoech*data->logk_aqueous(j);
data->nu_mineral_kinetic(i, data->nb_component+j) = 0;
}
}
}
data->nu_mineral_kinetic.conservativeResize(Eigen::NoChange_t(), data->nb_component);
}
void DatabaseCanonicalizer::make_gas_canonical()
{
if (data->nu_gas.cols() == data->nb_component)
{
INFO << "Database already in canonical form";
return;
}
if (data->nu_gas.cols() != data->nb_component + data->nb_aqueous)
{
CRITICAL << "Canonicalization : invalid size for stoichiometric coefficients of gas species - abort";
throw invalid_database("Invalid size for stoichiometric coefficients of gas species");
}
for (int i=1; i<data->nb_gas; ++i)
{
for (int j=0; j<i; ++j)
{
const double stoech = data->nu_gas(i, data->nb_component+j);
if (stoech != 0)
{
data->nu_gas.row(i) += stoech*data->nu_gas.row(j);
data->logk_gas(i) += stoech*data->logk_gas(j);
data->nu_gas(i, data->nb_component+j) = 0;
}
}
}
data->nu_gas.conservativeResize(Eigen::NoChange_t(), data->nb_component);
}
} // end namespace database
} // end namespace specmicp
Event Timeline
Log In to Comment