Page MenuHomec4science

configuration.cpp
No OneTemporary

File Metadata

Created
Sat, Apr 27, 13:35

configuration.cpp

/* =============================================================================
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 "../meshes/generic_mesh1d.hpp"
#include "../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 {
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