Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77635279
saturation_pressure_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
Thu, Aug 15, 14:53
Size
13 KB
Mime Type
text/x-c
Expires
Sat, Aug 17, 14:53 (2 d)
Engine
blob
Format
Raw Data
Handle
19901170
Attached To
rSPECMICP SpecMiCP / ReactMiCP
saturation_pressure_equation.cpp
View Options
/*-------------------------------------------------------------------------------
Copyright (c) 2014,2015 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 "saturation_pressure_equation.hpp"
#include "variables_box.hpp"
#include "transport_constraints.hpp"
#include "../../../dfpm/meshes/mesh1d.hpp"
#include "../../../dfpmsolver/parabolic_driver.hpp"
#include "../../../utils/compat.hpp"
#include "../../../physics/maths.hpp"
#include <vector>
#include <iostream>
namespace
specmicp
{
namespace
dfpmsolver
{
// explicit template instanciation
template
class
ParabolicDriver
<
reactmicp
::
systems
::
unsaturated
::
SaturationPressureEquation
>
;
}
//end namespace dfpmsolver
}
//end namespace specmicp
namespace
specmicp
{
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
SaturationPressureEquation
::
SaturationPressureEquationImpl
{
mesh
::
Mesh1DPtr
m_mesh
;
SaturationPressureVariableBox
m_vars
;
std
::
vector
<
index_t
>
m_ideq
;
bool
m_store_residual_info
;
SaturationPressureEquationImpl
(
mesh
::
Mesh1DPtr
the_mesh
,
SaturationPressureVariableBox
vars
)
:
m_mesh
(
the_mesh
),
m_vars
(
vars
),
m_ideq
(
the_mesh
->
nb_nodes
(),
not_initialized
)
{}
index_t
&
id_equation
(
index_t
node
)
{
return
m_ideq
[
node
];}
bool
node_can_flux
(
index_t
node
)
{
return
m_ideq
[
node
]
!=
no_eq_no_var
;}
bool
node_has_eq
(
index_t
node
)
{
return
m_ideq
[
node
]
>
no_equation
;}
void
set_store_residual_info
()
{
m_store_residual_info
=
true
;
}
void
reset_store_residual_info
()
{
m_store_residual_info
=
false
;
}
bool
store_residual_info
()
{
return
m_store_residual_info
;
}
//! \brief Return a pointer to the mesh
mesh
::
Mesh1D
*
mesh
()
{
return
m_mesh
.
get
();}
range_t
range_nodes
()
{
return
m_mesh
->
range_nodes
();}
void
set_relative_variables
(
const
Vector
&
displacement
);
void
set_relative_variables
(
index_t
node
,
const
Vector
&
displacement
);
void
compute_transport_rate
(
scalar_t
dt
,
const
Vector
&
displacement
);
};
SaturationPressureEquation
::~
SaturationPressureEquation
()
=
default
;
SaturationPressureEquation
::
SaturationPressureEquation
(
mesh
::
Mesh1DPtr
the_mesh
,
SaturationPressureVariableBox
&
variables
,
const
TransportConstraints
&
constraints
)
:
base
(
the_mesh
->
nb_nodes
()),
m_impl
(
make_unique
<
SaturationPressureEquationImpl
>
(
the_mesh
,
variables
))
{
number_equations
(
constraints
);
}
void
SaturationPressureEquation
::
number_equations
(
const
TransportConstraints
&
constraints
)
{
for
(
index_t
node:
constraints
.
fixed_nodes
())
{
m_impl
->
id_equation
(
node
)
=
no_equation
;
}
for
(
index_t
node:
constraints
.
gas_nodes
())
{
m_impl
->
id_equation
(
node
)
=
no_eq_no_var
;
}
index_t
neq
=
0
;
for
(
index_t
node:
m_impl
->
range_nodes
())
{
if
(
m_impl
->
id_equation
(
node
)
==
not_initialized
)
{
m_impl
->
id_equation
(
node
)
=
neq
;
++
neq
;
}
}
register_number_equations
(
neq
);
}
mesh
::
Mesh1D
*
SaturationPressureEquation
::
get_mesh_impl
()
{
return
m_impl
->
mesh
();
}
index_t
SaturationPressureEquation
::
id_equation_impl
(
index_t
id_dof
)
{
return
m_impl
->
id_equation
(
id_dof
)
<
0
?
no_equation:
m_impl
->
id_equation
(
id_dof
);
}
void
SaturationPressureEquation
::
pre_nodal_residual_hook_impl
(
index_t
node
,
const
Vector
&
displacement
)
{
m_impl
->
set_relative_variables
(
node
,
displacement
);
}
void
SaturationPressureEquation
::
pre_residual_hook_impl
(
const
Vector
&
displacement
)
{
m_impl
->
set_relative_variables
(
displacement
);
m_impl
->
set_store_residual_info
();
}
void
SaturationPressureEquation
::
post_residual_hook_impl
(
const
Vector
&
displacement
)
{
m_impl
->
reset_store_residual_info
();
}
// Residuals
// =========
void
SaturationPressureEquation
::
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
();
SaturationPressureVariableBox
&
vars
=
m_impl
->
m_vars
;
const
scalar_t
&
rt
=
vars
.
constants
.
rt
;
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
;
scalar_t
tot_flux
=
0.0
;
scalar_t
advection_flux
=
0.0
;
if
(
m_impl
->
node_can_flux
(
node_0
)
and
m_impl
->
node_can_flux
(
node_1
))
{
// Cap pressure gradient
const
scalar_t
perm_0
=
vars
.
liquid_permeability
(
node_0
)
*
vars
.
relative_liquid_permeability
(
node_0
);
const
scalar_t
perm_1
=
vars
.
liquid_permeability
(
node_1
)
*
vars
.
relative_liquid_permeability
(
node_1
);
const
scalar_t
perm
=
average
<
Average
::
harmonic
>
(
perm_0
,
perm_1
);
const
scalar_t
aq_coefficient
=
average
<
Average
::
arithmetic
>
(
vars
.
aqueous_concentration
(
node_0
),
vars
.
aqueous_concentration
(
node_1
)
);
const
scalar_t
cap_pressure_gradient
=
(
vars
.
capillary_pressure
(
node_1
)
-
vars
.
capillary_pressure
(
node_0
)
)
/
m_mesh
->
get_dx
(
element
);
advection_flux
=
(
perm
/
vars
.
constants
.
viscosity_liquid_water
)
*
cap_pressure_gradient
;
const
scalar_t
cappres_flux
=
-
aq_coefficient
*
advection_flux
;
// 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
aq_flux
=
coeff_diff
*
(
vars
.
aqueous_concentration
(
node_1
)
-
vars
.
aqueous_concentration
(
node_0
)
)
/
m_mesh
->
get_dx
(
element
);
tot_flux
=
(
cappres_flux
+
aq_flux
);
}
// Diffusion pressure pv
const
scalar_t
coeff_diff_gas_0
=
vars
.
resistance_gas_diffusivity
(
node_0
)
*
vars
.
relative_gas_diffusivity
(
node_0
);
const
scalar_t
coeff_diff_gas_1
=
vars
.
resistance_gas_diffusivity
(
node_1
)
*
vars
.
relative_gas_diffusivity
(
node_1
);
const
scalar_t
coeff_diff_gas
=
vars
.
binary_diffusion_coefficient
*
average
<
Average
::
harmonic
>
(
coeff_diff_gas_0
,
coeff_diff_gas_1
);
const
scalar_t
diff_flux_gas
=
coeff_diff_gas
*
(
vars
.
partial_pressure
(
node_1
)
-
vars
.
partial_pressure
(
node_0
))
/
m_mesh
->
get_dx
(
element
)
/
rt
;
// Tot flux
tot_flux
+=
diff_flux_gas
;
tot_flux
*=
m_mesh
->
get_face_area
(
element
);
flux_0
=
tot_flux
;
flux_1
=
-
tot_flux
;
// Storage
if
(
m_impl
->
store_residual_info
())
{
// advective flux stored by element
vars
.
advection_flux
(
element
)
=
advection_flux
;
// fluxes to compute exchange term
vars
.
liquid_saturation
.
transport_fluxes
(
node_0
)
+=
flux_0
;
vars
.
liquid_saturation
.
transport_fluxes
(
node_1
)
+=
flux_1
;
}
// transient
if
(
m_impl
->
node_has_eq
(
node_0
))
{
const
scalar_t
porosity_0
=
vars
.
porosity
(
node_0
);
const
scalar_t
aq_tot_conc_0
=
vars
.
aqueous_concentration
(
node_0
);
const
scalar_t
saturation_0
=
displacement
(
node_0
);
scalar_t
transient_0
=
(
porosity_0
*
aq_tot_conc_0
*
velocity
(
node_0
)
+
saturation_0
*
aq_tot_conc_0
*
vars
.
porosity
.
velocity
(
node_0
)
+
porosity_0
*
saturation_0
*
vars
.
aqueous_concentration
.
velocity
(
node_0
)
);
auto
res
=
mass_coeff_0
*
transient_0
-
flux_0
;
if
(
use_chemistry_rate
)
{
const
scalar_t
chemistry_0
=
vars
.
liquid_saturation
.
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_eq
(
node_1
))
{
const
scalar_t
porosity_1
=
vars
.
porosity
(
node_1
);
const
scalar_t
aq_tot_conc_1
=
vars
.
aqueous_concentration
(
node_1
);
const
scalar_t
saturation_1
=
displacement
(
node_1
);
scalar_t
transient_1
=
(
porosity_1
*
aq_tot_conc_1
*
velocity
(
node_1
)
+
saturation_1
*
aq_tot_conc_1
*
vars
.
porosity
.
velocity
(
node_1
)
+
porosity_1
*
saturation_1
*
vars
.
aqueous_concentration
.
velocity
(
node_1
)
);
auto
res
=
mass_coeff_1
*
transient_1
-
flux_1
;
if
(
use_chemistry_rate
)
{
const
scalar_t
chemistry_1
=
vars
.
liquid_saturation
.
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
SaturationPressureEquation
::
set_relative_variables
(
const
Vector
&
displacement
)
{
return
m_impl
->
set_relative_variables
(
displacement
);
}
void
SaturationPressureEquation
::
SaturationPressureEquationImpl
::
set_relative_variables
(
index_t
node
,
const
Vector
&
displacement
)
{
if
(
not
node_can_flux
(
node
))
return
;
const
scalar_t
saturation
=
displacement
(
node
);
m_vars
.
relative_liquid_diffusivity
(
node
)
=
m_vars
.
relative_liquid_diffusivity_f
(
node
,
saturation
);
m_vars
.
relative_liquid_permeability
(
node
)
=
m_vars
.
relative_liquid_permeability_f
(
node
,
saturation
);
m_vars
.
capillary_pressure
(
node
)
=
m_vars
.
capillary_pressure_f
(
node
,
saturation
);
//m_vars.partial_pressure(node) = m_vars.partial_pressure_f(node, saturation);
}
void
SaturationPressureEquation
::
SaturationPressureEquationImpl
::
set_relative_variables
(
const
Vector
&
displacement
)
{
for
(
index_t
node:
m_mesh
->
range_nodes
())
{
set_relative_variables
(
node
,
displacement
);
}
}
void
SaturationPressureEquation
::
compute_transport_rate
(
scalar_t
dt
,
const
Vector
&
displacement
)
{
m_impl
->
compute_transport_rate
(
dt
,
displacement
);
}
void
SaturationPressureEquation
::
SaturationPressureEquationImpl
::
compute_transport_rate
(
scalar_t
dt
,
const
Vector
&
displacement
)
{
MainVariable
&
saturation
=
m_vars
.
liquid_saturation
;
const
MainVariable
&
solid_conc
=
m_vars
.
solid_concentration
;
const
MainVariable
&
pressure
=
m_vars
.
partial_pressure
;
const
SecondaryTransientVariable
&
porosity
=
m_vars
.
porosity
;
const
SecondaryTransientVariable
&
aqueous_concentration
=
m_vars
.
aqueous_concentration
;
for
(
index_t
node:
m_mesh
->
range_nodes
())
{
if
(
!
node_has_eq
(
node
))
continue
;
const
scalar_t
transient
=
(
(
porosity
(
node
)
*
aqueous_concentration
(
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
)
);
saturation
.
transport_fluxes
(
node
)
=
transient
-
chem_rates
;
}
}
}
//end namespace unsaturated
}
//end namespace systems
}
//end namespace reactmicp
}
//end namespace specmicp
Event Timeline
Log In to Comment