Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91315321
equilibrium_constraints.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 9, 22:33
Size
6 KB
Mime Type
text/x-c
Expires
Mon, Nov 11, 22:33 (2 d)
Engine
blob
Format
Raw Data
Handle
22241578
Attached To
rSPECMICP SpecMiCP / ReactMiCP
equilibrium_constraints.cpp
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.
------------------------------------------------------------------------------*/
#include "equilibrium_constraints.hpp"
#include "../../../specmicp/adimensional/adimensional_system_solver_structs.hpp"
#include "../../../utils/compat.hpp"
#include "../../../utils/log.hpp"
#include "../../../dfpm/meshes/mesh1d.hpp"
namespace
specmicp
{
namespace
reactmicp
{
namespace
systems
{
namespace
unsaturated
{
struct
EquilibriumConstraints
::
EquilibriumConstraintsImpl
{
EquilibriumConstraintsImpl
(
index_t
nb_nodes
)
:
m_node_constraints
(
nb_nodes
,
no_equation
),
m_is_fixed_node
(
nb_nodes
,
false
)
{
m_constraints
.
reserve
(
3
);
}
EquilibriumConstraintsImpl
(
index_t
nb_nodes
,
const
AdimensionalSystemSolverOptions
&
opts
)
:
m_node_constraints
(
nb_nodes
,
no_equation
),
m_is_fixed_node
(
nb_nodes
,
false
),
m_options
(
opts
)
{
m_constraints
.
reserve
(
3
);
}
size_t
last
()
{
return
m_constraints
.
size
()
-
1
;}
AdimensionalSystemSolverOptions
&
get_options
()
{
return
m_options
;}
std
::
vector
<
AdimensionalSystemConstraints
>
m_constraints
;
std
::
vector
<
index_t
>
m_node_constraints
;
std
::
vector
<
bool
>
m_is_fixed_node
;
void
set_fixed_node
(
index_t
node
)
{
m_is_fixed_node
[
node
]
=
true
;
}
bool
is_fixed_node
(
index_t
node
)
{
return
m_is_fixed_node
[
node
];
}
index_t
nb_nodes
()
{
return
m_is_fixed_node
.
size
();}
AdimensionalSystemSolverOptions
m_options
;
};
EquilibriumConstraints
::
EquilibriumConstraints
(
index_t
nb_nodes
)
:
m_impl
(
make_unique
<
EquilibriumConstraintsImpl
>
(
nb_nodes
))
{}
EquilibriumConstraints
::
EquilibriumConstraints
(
index_t
nb_nodes
,
const
AdimensionalSystemSolverOptions
&
opts
)
:
m_impl
(
make_unique
<
EquilibriumConstraintsImpl
>
(
nb_nodes
,
opts
))
{}
EquilibriumConstraints
::~
EquilibriumConstraints
()
=
default
;
std
::
size_t
EquilibriumConstraints
::
add_constraints
(
const
AdimensionalSystemConstraints
&
constraints
)
{
m_impl
->
m_constraints
.
push_back
(
constraints
);
return
m_impl
->
last
();
}
std
::
size_t
EquilibriumConstraints
::
new_constraints
()
{
m_impl
->
m_constraints
.
emplace_back
();
return
m_impl
->
last
();
}
AdimensionalSystemConstraints
&
EquilibriumConstraints
::
operator
[]
(
std
::
size_t
index_constraint
)
{
return
m_impl
->
m_constraints
[
index_constraint
];
}
void
EquilibriumConstraints
::
set_constraints
(
std
::
size_t
id_constraint
,
const
std
::
vector
<
index_t
>&
nodes
)
{
specmicp_assert
(
id_constraint
<=
m_impl
->
last
());
for
(
auto
node:
nodes
)
{
m_impl
->
m_node_constraints
[
node
]
=
id_constraint
;
}
}
void
EquilibriumConstraints
::
set_constraints
(
const
std
::
vector
<
size_t
>&
constraints_for_each_node
)
{
index_t
nb_nodes
=
m_impl
->
m_node_constraints
.
size
();
specmicp_assert
(
constraints_for_each_node
.
size
()
==
nb_nodes
);
for
(
index_t
node
=
0
;
node
<
nb_nodes
;
++
node
)
{
index_t
id
=
constraints_for_each_node
[
node
];
if
(
id
>
m_impl
->
last
())
{
ERROR
<<
"Node "
<<
node
<<
" : "
<<
"constraints #"
<<
id
<<
" does not exist."
;
throw
std
::
runtime_error
(
"Invalid constraint request"
);
}
m_impl
->
m_node_constraints
[
node
]
=
constraints_for_each_node
[
node
];
}
}
void
EquilibriumConstraints
::
set_constraint_for_all
(
std
::
size_t
id_constraint
)
{
if
(
id_constraint
<
0
or
id_constraint
>
m_impl
->
last
())
{
ERROR
<<
"Constraints #"
<<
id_constraint
<<
" does not exist."
;
throw
std
::
runtime_error
(
"Invalid constraint request"
);
}
for
(
index_t
node
=
0
;
node
<
m_impl
->
m_node_constraints
.
size
();
++
node
)
{
m_impl
->
m_node_constraints
[
node
]
=
id_constraint
;
}
}
AdimensionalSystemConstraints
&
EquilibriumConstraints
::
get_constraints
(
index_t
node
)
{
auto
id
=
m_impl
->
m_node_constraints
[
node
];
if
(
id
==
no_equation
)
{
// check that the node has been initialized before doing anything
ERROR
<<
"Node "
<<
node
<<
" : "
<<
"request for a non initialized constraints !"
;
throw
std
::
runtime_error
(
"Invalid constraint request."
);
}
return
m_impl
->
m_constraints
[
id
];
}
//! \brief Set the options
AdimensionalSystemSolverOptions
&
EquilibriumConstraints
::
get_options
()
{
return
m_impl
->
get_options
();
}
//! \brief Add a fixed node
void
EquilibriumConstraints
::
add_fixed_node
(
index_t
node
)
{
specmicp_assert
(
node
<
m_impl
->
nb_nodes
());
m_impl
->
set_fixed_node
(
node
);
}
//! \brief Add a list of fixed nodes
void
EquilibriumConstraints
::
add_fixed_nodes
(
std
::
vector
<
index_t
>
fixed_nodes
)
{
for
(
auto
node:
fixed_nodes
)
{
specmicp_assert
(
node
<
m_impl
->
nb_nodes
());
m_impl
->
set_fixed_node
(
node
);
}
}
//! \brief Return true if the node is fixed
bool
EquilibriumConstraints
::
is_fixed_node
(
index_t
node
)
{
return
m_impl
->
is_fixed_node
(
node
);
}
std
::
shared_ptr
<
EquilibriumConstraints
>
equilibrium_constraints
(
mesh
::
Mesh1DPtr
the_mesh
)
{
index_t
nb_nodes
=
the_mesh
->
nb_nodes
();
return
std
::
make_shared
<
EquilibriumConstraints
>
(
nb_nodes
);
}
}
//end namespace unsaturated
}
//end namespace systems
}
//end namespace reactmicp
}
//end namespace specmicp
Event Timeline
Log In to Comment