Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61082670
aqueous_equation.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, May 4, 10:29
Size
10 KB
Mime Type
text/x-c
Expires
Mon, May 6, 10:29 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17418262
Attached To
rSPECMICP SpecMiCP / ReactMiCP
aqueous_equation.cpp
View Options
/* =============================================================================
Copyright (c) 2014 - 2016
F. 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:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. 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.
3. Neither the name of the copyright holder 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 HOLDER 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 "aqueous_equation.hpp"
#include "variables_box.hpp"
#include "transport_constraints.hpp"
#include "../../../dfpm/meshes/mesh1d.hpp"
#include "../../../utils/compat.hpp"
#include "../../../physics/constants.hpp"
#include "../../../physics/maths.hpp"
#include "../../../dfpmsolver/parabolic_driver.hpp"
namespace
specmicp
{
namespace
dfpmsolver
{
// explicit template instanciation
template
class
ParabolicDriver
<
reactmicp
::
systems
::
unsaturated
::
AqueousTransportEquation
>
;
}
//end namespace dfpmsolver
namespace
reactmicp
{
namespace
systems
{
namespace
unsaturated
{
static
constexpr
index_t
no_equation
{
-
1
};
static
constexpr
index_t
no_eq_no_var
{
-
2
};
static
constexpr
index_t
not_initialized
{
-
5
};
struct
SPECMICP_DLL_LOCAL
AqueousTransportEquation
::
AqueousTransportEquationImpl
{
mesh
::
Mesh1DPtr
m_mesh
;
LiquidAqueousComponentVariableBox
m_vars
;
std
::
vector
<
index_t
>
m_ideq
;
mesh
::
Mesh1D
*
mesh
()
{
return
m_mesh
.
get
();}
LiquidAqueousComponentVariableBox
&
vars
()
{
return
m_vars
;}
bool
node_has_equation
(
index_t
node
)
{
return
m_ideq
[
node
]
>
no_equation
;
}
bool
node_can_flux
(
index_t
node
)
{
return
m_ideq
[
node
]
>
no_eq_no_var
;
}
index_t
id_equation
(
index_t
node
)
{
return
m_ideq
[
node
];
}
void
fix_node
(
index_t
node
)
{
m_ideq
[
node
]
=
no_equation
;
}
void
gas_node
(
index_t
node
)
{
m_ideq
[
node
]
=
no_eq_no_var
;
}
AqueousTransportEquationImpl
(
mesh
::
Mesh1DPtr
the_mesh
,
LiquidAqueousComponentVariableBox
the_vars
)
:
m_mesh
(
the_mesh
),
m_vars
(
the_vars
),
m_ideq
(
the_mesh
->
nb_nodes
(),
not_initialized
)
{}
void
compute_transport_rate
(
scalar_t
dt
,
const
Vector
&
displacment
);
};
AqueousTransportEquation
::
AqueousTransportEquation
(
mesh
::
Mesh1DPtr
the_mesh
,
LiquidAqueousComponentVariableBox
&
variables
,
const
TransportConstraints
&
constraints
)
:
base
(
the_mesh
->
nb_nodes
()),
m_impl
(
make_unique
<
AqueousTransportEquationImpl
>
(
the_mesh
,
variables
))
{
number_equations
(
constraints
);
}
AqueousTransportEquation
::~
AqueousTransportEquation
()
=
default
;
index_t
AqueousTransportEquation
::
id_equation_impl
(
index_t
id_dof
)
{
const
auto
id_eq
=
m_impl
->
id_equation
(
id_dof
);
return
(
id_eq
>
no_equation
)
?
id_eq:
no_equation
;
}
mesh
::
Mesh1D
*
AqueousTransportEquation
::
get_mesh_impl
()
{
return
m_impl
->
mesh
();
}
void
AqueousTransportEquation
::
pre_nodal_residual_hook_impl
(
index_t
node
,
const
Vector
&
displacement
)
{}
void
AqueousTransportEquation
::
pre_residual_hook_impl
(
const
Vector
&
displacement
)
{}
void
AqueousTransportEquation
::
post_residual_hook_impl
(
const
Vector
&
displacement
)
{}
//! \brief Compute the residuals inside 'element'
void
AqueousTransportEquation
::
residuals_element_impl
(
index_t
element
,
const
Vector
&
displacement
,
const
Vector
&
velocity
,
Eigen
::
Vector2d
&
element_residual
,
bool
use_chemistry_rate
)
{
element_residual
.
setZero
();
mesh
::
Mesh1D
*
m_mesh
=
m_impl
->
mesh
();
LiquidAqueousComponentVariableBox
&
vars
=
m_impl
->
m_vars
;
const
scalar_t
mass_coeff_0
=
m_mesh
->
get_volume_cell_element
(
element
,
0
);
const
scalar_t
mass_coeff_1
=
m_mesh
->
get_volume_cell_element
(
element
,
1
);
const
index_t
node_0
=
m_mesh
->
get_node
(
element
,
0
);
const
index_t
node_1
=
m_mesh
->
get_node
(
element
,
1
);
scalar_t
flux_0
=
0.0
;
scalar_t
flux_1
=
0.0
;
if
(
m_impl
->
node_can_flux
(
node_0
)
and
m_impl
->
node_can_flux
(
node_1
))
{
// Diffusion Cw
const
scalar_t
coeff_diff_0
=
vars
.
liquid_diffusivity
(
node_0
)
*
vars
.
relative_liquid_diffusivity
(
node_0
);
const
scalar_t
coeff_diff_1
=
vars
.
liquid_diffusivity
(
node_1
)
*
vars
.
relative_liquid_diffusivity
(
node_1
);
const
scalar_t
coeff_diff
=
average
<
Average
::
harmonic
>
(
coeff_diff_0
,
coeff_diff_1
);
const
scalar_t
diff_aq
=
(
displacement
(
node_1
)
-
displacement
(
node_0
)
);
const
scalar_t
diff_flux
=
coeff_diff
*
diff_aq
/
m_mesh
->
get_dx
(
element
);
// advection
if
(
vars
.
advection_flux
(
element
)
<
0
)
{
flux_0
=
-
vars
.
advection_flux
(
element
)
*
diff_aq
;
}
else
if
(
vars
.
advection_flux
(
element
)
>
0
)
{
flux_1
=
-
vars
.
advection_flux
(
element
)
*
diff_aq
;
}
flux_0
+=
diff_flux
;
flux_0
*=
m_mesh
->
get_face_area
(
element
);
flux_1
-=
diff_flux
;
flux_1
*=
m_mesh
->
get_face_area
(
element
);
}
// transient
if
(
m_impl
->
node_has_equation
(
node_0
))
{
const
scalar_t
porosity_0
=
vars
.
porosity
(
node_0
);
const
scalar_t
aq_tot_conc_0
=
displacement
(
node_0
);
const
scalar_t
saturation_0
=
vars
.
saturation
(
node_0
);
const
scalar_t
transient_0
=
porosity_0
*
aq_tot_conc_0
*
vars
.
saturation
.
velocity
(
node_0
)
+
saturation_0
*
aq_tot_conc_0
*
vars
.
porosity
.
velocity
(
node_0
)
+
porosity_0
*
saturation_0
*
velocity
(
node_0
);
scalar_t
res
=
mass_coeff_0
*
transient_0
-
flux_0
;
if
(
use_chemistry_rate
)
{
const
scalar_t
chemistry_0
=
vars
.
aqueous_concentration
.
chemistry_rate
(
node_0
)
+
vars
.
solid_concentration
.
chemistry_rate
(
node_0
)
+
vars
.
partial_pressure
.
chemistry_rate
(
node_0
);
res
-=
mass_coeff_0
*
chemistry_0
;
}
element_residual
(
0
)
=
res
/
get_scaling
();
}
if
(
m_impl
->
node_has_equation
(
node_1
))
{
const
scalar_t
porosity_1
=
vars
.
porosity
(
node_1
);
const
scalar_t
aq_tot_conc_1
=
displacement
(
node_1
);
const
scalar_t
saturation_1
=
vars
.
saturation
(
node_1
);
const
scalar_t
transient_1
=
porosity_1
*
aq_tot_conc_1
*
vars
.
saturation
.
velocity
(
node_1
)
+
saturation_1
*
aq_tot_conc_1
*
vars
.
porosity
.
velocity
(
node_1
)
+
porosity_1
*
saturation_1
*
velocity
(
node_1
);
scalar_t
res
=
mass_coeff_1
*
transient_1
-
flux_1
;
if
(
use_chemistry_rate
)
{
const
scalar_t
chemistry_1
=
vars
.
aqueous_concentration
.
chemistry_rate
(
node_1
)
+
vars
.
solid_concentration
.
chemistry_rate
(
node_1
)
+
vars
.
partial_pressure
.
chemistry_rate
(
node_1
);
res
-=
mass_coeff_1
*
chemistry_1
;
}
element_residual
(
1
)
=
res
/
get_scaling
();
}
}
void
AqueousTransportEquation
::
number_equations
(
const
TransportConstraints
&
constraints
)
{
for
(
int
fixed_node:
constraints
.
fixed_nodes
())
{
m_impl
->
fix_node
(
fixed_node
);
}
for
(
int
gas_node:
constraints
.
gas_nodes
())
{
m_impl
->
gas_node
(
gas_node
);
}
index_t
neq
=
0
;
for
(
index_t
node:
m_impl
->
mesh
()
->
range_nodes
())
{
if
(
m_impl
->
m_ideq
[
node
]
==
not_initialized
)
{
m_impl
->
m_ideq
[
node
]
=
neq
;
++
neq
;
}
}
register_number_equations
(
neq
);
}
void
AqueousTransportEquation
::
compute_transport_rate
(
scalar_t
dt
,
const
Vector
&
displacement
)
{
m_impl
->
compute_transport_rate
(
dt
,
displacement
);
}
void
AqueousTransportEquation
::
AqueousTransportEquationImpl
::
compute_transport_rate
(
scalar_t
dt
,
const
Vector
&
displacement
)
{
MainVariable
&
aqueous_concentration
=
m_vars
.
aqueous_concentration
;
const
MainVariable
&
saturation
=
m_vars
.
saturation
;
const
MainVariable
&
solid_conc
=
m_vars
.
solid_concentration
;
const
MainVariable
&
pressure
=
m_vars
.
partial_pressure
;
const
SecondaryTransientVariable
&
porosity
=
m_vars
.
porosity
;
for
(
index_t
node:
m_mesh
->
range_nodes
())
{
if
(
!
node_has_equation
(
node
))
continue
;
const
scalar_t
transient
=
(
(
porosity
(
node
)
*
saturation
(
node
)
*
displacement
(
node
))
-
(
porosity
.
predictor
(
node
)
*
aqueous_concentration
.
predictor
(
node
)
*
saturation
.
predictor
(
node
))
)
/
dt
;
const
scalar_t
chem_rates
=
(
saturation
.
chemistry_rate
(
node
)
+
solid_conc
.
chemistry_rate
(
node
)
+
pressure
.
chemistry_rate
(
node
)
);
aqueous_concentration
.
transport_fluxes
(
node
)
=
transient
-
chem_rates
;
}
}
}
//end namespace unsaturated
}
//end namespace systems
}
//end namespace reactmicp
}
//end namespace specmicp
Event Timeline
Log In to Comment