Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F84813945
variables_sub.hpp
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
Wed, Sep 25, 01:04
Size
6 KB
Mime Type
text/x-c
Expires
Fri, Sep 27, 01:04 (2 d)
Engine
blob
Format
Raw Data
Handle
21090686
Attached To
rSPECMICP SpecMiCP / ReactMiCP
variables_sub.hpp
View Options
/*-------------------------------------------------------------------------------
Copyright (c) 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.
-----------------------------------------------------------------------------*/
//! \file variables_sub.hpp
//! \brief Substruct for the variables
#ifndef SPECMICP_REACTMICP_UNSATURATED_VARIABLESSUB_HPP
#define SPECMICP_REACTMICP_UNSATURATED_VARIABLESSUB_HPP
#include "../../../types.hpp"
#include "../../../specmicp/adimensional/adimensional_system_solution.hpp"
#include <vector>
#include <memory>
#include "../../../utils/compat.hpp"
namespace
specmicp
{
namespace
reactmicp
{
namespace
systems
{
namespace
unsaturated
{
struct
SPECMICP_DLL_LOCAL
BaseVariable
{
Vector
variable
;
//!< The variables
//! \brief Return value of the variable
scalar_t
&
operator
()
(
index_t
node
)
{
return
variable
(
node
);
}
//! \brief Return value of the variable
scalar_t
operator
()
(
index_t
node
)
const
{
return
variable
(
node
);
}
index_t
size
()
const
{
return
variable
.
rows
();
}
void
set_constant
(
scalar_t
value
)
{
variable
.
setConstant
(
value
);
}
void
set_zero
()
{
variable
.
setZero
();
}
BaseVariable
(
index_t
size
)
:
variable
(
Vector
::
Zero
(
size
))
{}
};
struct
SPECMICP_DLL_LOCAL
BaseTransientVariable:
public
BaseVariable
{
Vector
velocity
;
//!< Rate of change of the variable
Vector
predictor
;
//!< Predictor, value before first iteration
BaseTransientVariable
(
index_t
size
)
:
BaseVariable
(
size
),
velocity
(
Vector
::
Zero
(
size
)),
predictor
(
Vector
::
Zero
(
size
))
{}
};
//! \brief A main variable, used to solve the governing equations
struct
SPECMICP_DLL_LOCAL
MainVariable:
public
BaseTransientVariable
{
Vector
transport_fluxes
;
//!< Transport fluxes of the corresponding governing equations
Vector
chemistry_rate
;
//!< Chemical exchange rate
MainVariable
(
index_t
size
)
:
BaseTransientVariable
(
size
),
transport_fluxes
(
Vector
::
Zero
(
size
)),
chemistry_rate
(
Vector
::
Zero
(
size
))
{}
//! \brief Reset the variables
//!
//! This function is called if the solver failed and must be restarted
void
reset
()
{
transport_fluxes
.
setZero
();
chemistry_rate
.
setZero
();
velocity
.
setZero
();
variable
=
predictor
;
}
};
//! \brief List of main variables
struct
SPECMICP_DLL_LOCAL
ListMainVariable
{
// Variables are stored as pointer so we can skip components
// that do not exist
// But still access their variables through their index
using
value_type
=
std
::
unique_ptr
<
MainVariable
>
;
using
vector_type
=
std
::
vector
<
value_type
>
;
using
iterator
=
vector_type
::
iterator
;
using
const_iterator
=
vector_type
::
const_iterator
;
vector_type
variables
;
MainVariable
&
water
()
{
return
*
variables
[
0
];
}
MainVariable
&
aqueous_component
(
index_t
aq_component
)
{
specmicp_assert
(
variables
[
aq_component
]
!=
nullptr
);
return
*
variables
[
aq_component
];
}
MainVariable
&
component
(
index_t
component
)
{
specmicp_assert
(
variables
[
component
]
!=
nullptr
);
return
*
variables
[
component
];
}
MainVariable
*
operator
()
(
index_t
component
)
{
return
variables
[
component
].
get
();
}
// Implementations of the following methods
// is in variables.cpp
//! \brief Initialize the variables
ListMainVariable
(
index_t
nb_vars
,
index_t
nb_nodes
);
//! \brief Initialize some variables
//!
//! Only initialize values given by 'to_init'
ListMainVariable
(
index_t
nb_vars
,
index_t
nb_nodes
,
std
::
vector
<
bool
>
to_init
);
//! \brief Reset the variables
void
reset
();
//! \brief Hard reset, erase all info for a component;
void
hard_reset
(
index_t
component
,
index_t
nb_nodes
);
};
//! \brief A secondary variable
struct
SPECMICP_DLL_LOCAL
SecondaryVariable:
public
BaseVariable
{
SecondaryVariable
(
index_t
size
)
:
BaseVariable
(
size
)
{}
};
//! \brief A secondary transient variable
//!
//! e.g. the porosity
struct
SPECMICP_DLL_LOCAL
SecondaryTransientVariable:
public
BaseTransientVariable
{
SecondaryTransientVariable
(
index_t
size
)
:
BaseTransientVariable
(
size
)
{}
};
//! \brief The chemistry solutions
struct
SPECMICP_DLL_LOCAL
ChemistrySolutions
{
std
::
vector
<
AdimensionalSystemSolution
>
solutions
;
ChemistrySolutions
(
index_t
size
)
:
solutions
(
size
)
{}
//! \brief Return a solution
AdimensionalSystemSolution
&
solution
(
index_t
node
)
{
return
solutions
[
node
];
}
//! \brief Return a const solution
const
AdimensionalSystemSolution
&
solution
(
index_t
node
)
const
{
return
solutions
[
node
];
}
//! \brief Set a solution
void
update_solution
(
index_t
node
,
const
AdimensionalSystemSolution
&
new_solution
)
{
solutions
[
node
]
=
new_solution
;
}
};
}
//end namespace unsaturated
}
//end namespace systems
}
//end namespace reactmicp
}
//end namespace specmicp
#endif
// SPECMICP_REACTMICP_UNSATURATED_VARIABLESSUB_HPP
Event Timeline
Log In to Comment