Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F68738780
equilibrium_data.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
Fri, Jun 28, 17:42
Size
6 KB
Mime Type
text/x-c
Expires
Sun, Jun 30, 17:42 (2 d)
Engine
blob
Format
Raw Data
Handle
18591578
Attached To
rSPECMICP SpecMiCP / ReactMiCP
equilibrium_data.cpp
View Options
/*-------------------------------------------------------
- Module : specmicp
- File : equilibrium_data.cpp
- Author : Fabien Georget
Copyright (c) 2014, Fabien Georget <fabieng@princeton.edu>, Princeton University
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Princeton University nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------*/
#include "equilibrium_data.hpp"
#include "database/module.hpp"
#include "physics/constants.hpp"
#define POW10(m) std::pow(10.0, m)
namespace
specmicp
{
scalar_t
EquilibriumState
::
logIAP
(
index_t
m
)
const
{
scalar_t
logiap
=
0.0
;
for
(
index_t
i
=
1
;
i
<
m_data
->
nb_component
;
++
i
)
logiap
+=
m_main_variables
(
i
)
*
m_data
->
nu_mineral
(
m
,
i
);
return
logiap
;
}
scalar_t
EquilibriumState
::
logIAP
(
const
std
::
string
&
label_mineral
)
const
{
database
::
DatabaseModule
namer
(
m_data
);
index_t
idm
=
namer
.
safe_label_to_id
(
label_mineral
,
m_data
->
labels_minerals
);
return
logIAP
(
idm
);
}
scalar_t
EquilibriumState
::
saturation_index
(
const
std
::
string
&
label_mineral
)
const
{
database
::
DatabaseModule
namer
(
m_data
);
index_t
idm
=
namer
.
safe_label_to_id
(
label_mineral
,
m_data
->
labels_minerals
);
return
logIAP
(
idm
)
-
m_data
->
logk_mineral
(
idm
);
}
scalar_t
EquilibriumState
::
logIAP_kinetic
(
index_t
m
)
const
{
scalar_t
logiap
=
0.0
;
for
(
index_t
i
=
1
;
i
<
m_data
->
nb_component
;
++
i
)
logiap
+=
m_main_variables
(
i
)
*
m_data
->
nu_mineral_kinetic
(
m
,
i
);
return
logiap
;
}
scalar_t
EquilibriumState
::
logIAP_kinetic
(
const
std
::
string
&
label_mineral
)
const
{
database
::
DatabaseModule
namer
(
m_data
);
int
idm
=
namer
.
safe_label_to_id
(
label_mineral
,
m_data
->
labels_minerals_kinetic
);
return
logIAP_kinetic
(
idm
);
}
scalar_t
EquilibriumState
::
saturation_index_kinetic
(
const
std
::
string
&
label_mineral
)
const
{
database
::
DatabaseModule
namer
(
m_data
);
index_t
idm
=
namer
.
safe_label_to_id
(
label_mineral
,
m_data
->
labels_minerals
);
return
logIAP_kinetic
(
idm
)
-
m_data
->
logk_mineral_kinetic
(
idm
);
}
scalar_t
EquilibriumState
::
total_aqueous_concentration_component
(
index_t
i
)
const
{
scalar_t
totconc
;
if
(
i
>
0
)
totconc
=
molality_component
(
i
);
// aqueous component
else
totconc
=
1.0
/
m_data
->
molar_mass_basis_si
(
0
);
// water
totconc
+=
m_data
->
nu_aqueous
.
col
(
i
).
dot
(
m_concentration_secondary
);
return
totconc
;
}
void
EquilibriumState
::
total_aqueous_concentrations
(
Eigen
::
VectorXd
&
totconc
)
const
{
assert
(
totconc
.
rows
()
==
m_data
->
nb_component
);
for
(
index_t
i:
m_data
->
range_component
())
totconc
(
i
)
=
total_aqueous_concentration_component
(
i
);
}
void
EquilibriumState
::
total_concentrations
(
Vector
&
total_conc
)
const
{
total_conc
.
resize
(
m_data
->
nb_component
);
total_conc
.
setZero
();
// Aqueous concentration : m_w * B_i
total_aqueous_concentrations
(
total_conc
);
total_conc
=
mass_water
()
*
total_conc
;
// Minerals : nu_{mi} n_m
for
(
index_t
mineral:
m_data
->
range_mineral
())
{
if
(
moles_mineral
(
mineral
)
==
0.0
)
continue
;
for
(
index_t
component:
m_data
->
range_component
())
{
total_conc
(
component
)
+=
m_data
->
nu_mineral
(
mineral
,
component
)
*
moles_mineral
(
mineral
);
}
}
}
scalar_t
EquilibriumState
::
pH
()
const
{
// search where the information about "H[+]" is stored
// (i.e. was the component H[+] or HO[-] ?)
database
::
DatabaseModule
namer
(
m_data
);
scalar_t
id
=
namer
.
component_label_to_id
(
"H[+]"
);
if
(
id
!=
no_species
)
return
-
std
::
log10
(
activity_component
(
id
));
else
{
id
=
namer
.
aqueous_label_to_id
(
"H[+]"
);
assert
(
id
!=
no_species
);
return
-
std
::
log10
(
activity_secondary
(
id
));
}
}
scalar_t
EquilibriumState
::
mass_mineral
(
index_t
m
)
const
{
return
m_data
->
molar_mass_mineral
(
m
)
*
m_main_variables
(
m_data
->
nb_component
+
m
);
}
scalar_t
EquilibriumState
::
condensed_phase_volume
()
const
{
scalar_t
volume
=
mass_water
()
/
constants
::
water_density_25
;
for
(
index_t
m
=
0
;
m
<
m_data
->
nb_mineral
;
++
m
)
{
volume
+=
moles_mineral
(
m
)
*
m_data
->
molar_volume_mineral
(
m
);
}
return
volume
;
}
scalar_t
EquilibriumState
::
gas_phase_volume
()
const
{
assert
(
is_fixed_volume
());
return
(
get_volume
()
-
condensed_phase_volume
());
}
//! \brief Return the volume of all minerals
scalar_t
EquilibriumState
::
moles_minerals
()
const
{
return
m_main_variables
.
segment
(
m_data
->
nb_component
,
m_data
->
nb_mineral
).
sum
();
}
scalar_t
EquilibriumState
::
volume_minerals
()
const
{
scalar_t
volume
=
0
;
for
(
index_t
m
=
0
;
m
<
m_data
->
nb_mineral
;
++
m
)
{
volume
+=
moles_mineral
(
m
)
*
m_data
->
molar_volume_mineral
(
m
);
}
return
volume
;
}
void
EquilibriumState
::
scale_condensed
(
scalar_t
scale
)
{
m_main_variables
(
0
)
*=
scale
;
m_main_variables
.
segment
(
m_data
->
nb_component
,
m_data
->
nb_mineral
)
*=
scale
;
}
}
// end namespace specmicp
Event Timeline
Log In to Comment