Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98113461
configuration.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, Jan 9, 22:25
Size
7 KB
Mime Type
text/x-c
Expires
Sat, Jan 11, 22:25 (2 d)
Engine
blob
Format
Raw Data
Handle
23507886
Attached To
rSPECMICP SpecMiCP / ReactMiCP
configuration.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 "configuration.hpp"
#include "utils/io/yaml.hpp"
#include "utils/io/safe_config.hpp"
#include "dfpm/meshes/generic_mesh1d.hpp"
#include "dfpm/meshes/axisymmetric_mesh1d.hpp"
#include <stdexcept>
#define S_MESH "mesh"
#define S_MESH_A_TYPE "type"
#define S_UNIFMESH "uniform_mesh"
#define S_UNIFMESH_A_DX "dx"
#define S_UNIFMESH_A_NBNODES "nb_nodes"
#define S_UNIFMESH_A_SECTION "section"
#define S_RAMPMESH "ramp_mesh"
#define S_RAMPMESH_A_MIN_DX "min_dx"
#define S_RAMPMESH_A_MAX_DX "max_dx"
#define S_RAMPMESH_A_RAMP_LENGTH "length_ramp"
#define S_RAMPMESH_A_PLATEAU_LENGTH "length_plateau"
#define S_RAMPMESH_A_SECTION "section"
#define S_UNIFAXISYMESH "uniform_axisymmetric"
#define S_UNIFAXISYMESH_A_RADIUS "radius"
#define S_UNIFAXISYMESH_A_NBNODES "nb_nodes"
#define S_UNIFAXISYMESH_A_HEIGHT "height"
#define S_UNIFAXISYMESH_A_DX "dx"
namespace
specmicp
{
namespace
io
{
// new interface
// -------------
//! \brief Configure the mesh
mesh
::
Mesh1DPtr
SPECMICP_DLL_PUBLIC
configure_mesh
(
YAMLConfigHandle
&&
mesh_section
)
{
auto
type
=
mesh_section
.
get_required_attribute
<
std
::
string
>
(
S_MESH_A_TYPE
);
mesh
::
Mesh1DPtr
the_mesh
{
nullptr
};
if
(
type
==
S_UNIFMESH
)
the_mesh
=
configure_uniform_mesh1D
(
mesh_section
.
get_section
(
S_UNIFMESH
));
else
if
(
type
==
S_RAMPMESH
)
the_mesh
=
configure_ramp_mesh1D
(
mesh_section
.
get_section
(
S_RAMPMESH
));
else
if
(
type
==
S_UNIFAXISYMESH
)
the_mesh
=
configure_uniform_axisymmetric_mesh1D
(
mesh_section
.
get_section
(
S_UNIFAXISYMESH
));
else
mesh_section
.
report_error
(
YAMLConfigError
::
InvalidArgument
,
"'"
+
type
+
"' is not a valid type of mesh."
);
return
the_mesh
;
}
//! \brief Configure an uniform mesh
mesh
::
Mesh1DPtr
configure_uniform_mesh1D
(
YAMLConfigHandle
&&
uniform_section
)
{
mesh
::
Uniform1DMeshGeometry
geometry
;
geometry
.
dx
=
uniform_section
.
get_required_attribute
<
scalar_t
>
(
S_UNIFMESH_A_DX
);
geometry
.
nb_nodes
=
uniform_section
.
get_required_attribute
<
index_t
>
(
S_UNIFMESH_A_NBNODES
);
geometry
.
section
=
uniform_section
.
get_required_attribute
<
scalar_t
>
(
S_UNIFMESH_A_SECTION
);
return
mesh
::
uniform_mesh1d
(
geometry
);
}
//! \brief Configure a 'ramp' mesh
mesh
::
Mesh1DPtr
configure_ramp_mesh1D
(
YAMLConfigHandle
&&
ramp_section
)
{
mesh
::
Ramp1DMeshGeometry
geometry
;
geometry
.
dx_min
=
ramp_section
.
get_required_attribute
<
scalar_t
>
(
S_RAMPMESH_A_MIN_DX
);
geometry
.
dx_max
=
ramp_section
.
get_required_attribute
<
scalar_t
>
(
S_RAMPMESH_A_MAX_DX
);
geometry
.
length_ramp
=
ramp_section
.
get_required_attribute
<
scalar_t
>
(
S_RAMPMESH_A_RAMP_LENGTH
);
geometry
.
length_plateau
=
ramp_section
.
get_required_attribute
<
scalar_t
>
(
S_RAMPMESH_A_PLATEAU_LENGTH
);
geometry
.
section
=
ramp_section
.
get_required_attribute
<
scalar_t
>
(
S_RAMPMESH_A_SECTION
);
return
mesh
::
ramp_mesh1d
(
geometry
);
}
//! \brief Configure an uniform axisymmetric mesh
mesh
::
Mesh1DPtr
configure_uniform_axisymmetric_mesh1D
(
YAMLConfigHandle
&&
axisymmetric_section
)
{
mesh
::
UniformAxisymmetricMesh1DGeometry
geometry
;
geometry
.
dx
=
axisymmetric_section
.
get_optional_attribute
<
scalar_t
>
(
S_UNIFAXISYMESH_A_DX
,
-
1.0
);
geometry
.
nb_nodes
=
axisymmetric_section
.
get_optional_attribute
<
index_t
>
(
S_UNIFAXISYMESH_A_NBNODES
,
-
1.0
);
geometry
.
height
=
axisymmetric_section
.
get_required_attribute
<
scalar_t
>
(
S_UNIFAXISYMESH_A_HEIGHT
);
geometry
.
radius
=
axisymmetric_section
.
get_required_attribute
<
scalar_t
>
(
S_UNIFAXISYMESH_A_RADIUS
);
return
mesh
::
uniform_axisymmetric_mesh1d
(
geometry
);
}
// old interface
// -------------
mesh
::
Mesh1DPtr
configure_mesh
(
const
YAML
::
Node
&
conf
)
{
check_mandatory_yaml_node
(
conf
,
S_MESH
,
"__main__"
);
const
YAML
::
Node
&
subconf
=
conf
[
S_MESH
];
std
::
string
type
=
subconf
[
S_MESH_A_TYPE
].
as
<
std
::
string
>
();
if
(
type
==
S_UNIFMESH
)
return
configure_uniform_mesh1D
(
subconf
);
else
if
(
type
==
S_RAMPMESH
)
return
configure_ramp_mesh1D
(
subconf
);
else
if
(
type
==
S_UNIFAXISYMESH
)
return
configure_uniform_axisymmetric_mesh1D
(
subconf
);
else
throw
std
::
invalid_argument
(
"Not a valid type of mesh : '"
+
type
+
"'."
);
}
mesh
::
Mesh1DPtr
configure_uniform_mesh1D
(
const
YAML
::
Node
&
conf
)
{
check_mandatory_yaml_node
(
conf
,
S_UNIFMESH
,
S_MESH
);
const
YAML
::
Node
&
subconf
=
conf
[
S_UNIFMESH
];
mesh
::
Uniform1DMeshGeometry
geometry
;
geometry
.
dx
=
get_yaml_mandatory
<
scalar_t
>
(
subconf
,
S_UNIFMESH_A_DX
,
S_UNIFMESH
);
geometry
.
nb_nodes
=
get_yaml_mandatory
<
index_t
>
(
subconf
,
S_UNIFMESH_A_NBNODES
,
S_UNIFMESH
);
geometry
.
section
=
get_yaml_mandatory
<
scalar_t
>
(
subconf
,
S_UNIFMESH_A_SECTION
,
S_UNIFMESH
);
return
mesh
::
uniform_mesh1d
(
geometry
);
}
mesh
::
Mesh1DPtr
configure_ramp_mesh1D
(
const
YAML
::
Node
&
conf
)
{
check_mandatory_yaml_node
(
conf
,
S_RAMPMESH
,
S_MESH
);
const
YAML
::
Node
&
subconf
=
conf
[
S_RAMPMESH
];
mesh
::
Ramp1DMeshGeometry
geometry
;
geometry
.
dx_min
=
get_yaml_mandatory
<
scalar_t
>
(
subconf
,
S_RAMPMESH_A_MIN_DX
,
S_RAMPMESH
);
geometry
.
dx_max
=
get_yaml_mandatory
<
scalar_t
>
(
subconf
,
S_RAMPMESH_A_MAX_DX
,
S_RAMPMESH
);
geometry
.
length_ramp
=
get_yaml_mandatory
<
scalar_t
>
(
subconf
,
S_RAMPMESH_A_RAMP_LENGTH
,
S_RAMPMESH
);
geometry
.
length_plateau
=
get_yaml_mandatory
<
scalar_t
>
(
subconf
,
S_RAMPMESH_A_PLATEAU_LENGTH
,
S_RAMPMESH
);
geometry
.
section
=
get_yaml_mandatory
<
scalar_t
>
(
subconf
,
S_RAMPMESH_A_SECTION
,
S_RAMPMESH
);
return
mesh
::
ramp_mesh1d
(
geometry
);
}
mesh
::
Mesh1DPtr
configure_uniform_axisymmetric_mesh1D
(
const
YAML
::
Node
&
conf
)
{
const
YAML
::
Node
&
subconf
=
conf
[
S_UNIFAXISYMESH
];
mesh
::
UniformAxisymmetricMesh1DGeometry
geometry
;
geometry
.
dx
=
get_yaml_optional
<
scalar_t
>
(
subconf
,
S_UNIFAXISYMESH_A_DX
,
S_UNIFAXISYMESH
,
-
1.0
);
geometry
.
nb_nodes
=
get_yaml_optional
<
index_t
>
(
subconf
,
S_UNIFAXISYMESH_A_NBNODES
,
S_UNIFAXISYMESH
,
-
1
);
geometry
.
height
=
get_yaml_mandatory
<
scalar_t
>
(
subconf
,
S_UNIFAXISYMESH_A_HEIGHT
,
S_UNIFAXISYMESH
);
geometry
.
radius
=
get_yaml_mandatory
<
scalar_t
>
(
subconf
,
S_UNIFAXISYMESH_A_RADIUS
,
S_UNIFAXISYMESH
);
return
mesh
::
uniform_axisymmetric_mesh1d
(
geometry
);
}
}
//end namespace io
}
//end namespace specmicp
Event Timeline
Log In to Comment