diff --git a/src/dfpm/io/configuration.cpp b/src/dfpm/io/configuration.cpp index 94a13de..a530e12 100644 --- a/src/dfpm/io/configuration.cpp +++ b/src/dfpm/io/configuration.cpp @@ -1,371 +1,272 @@ /* ============================================================================= Copyright (c) 2014 - 2016 F. Georget 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 "specmicp_common/io/yaml.hpp" #include "specmicp_common/io/safe_config.hpp" #include "dfpm/meshes/mesh1d.hpp" #include "dfpm/solver/parabolic_structs.hpp" #include "specmicp_common/io/config_yaml_sections.h" #include "specmicp_common/log.hpp" #include 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(SPC_CF_S_MESH_A_TYPE); mesh::Mesh1DPtr the_mesh {nullptr}; if (type == SPC_CF_S_MESH_SS_UNIFMESH) { SPC_CONF_LOG << "Uniform mesh"; the_mesh = configure_uniform_mesh1D( mesh_section.get_section(SPC_CF_S_MESH_SS_UNIFMESH)); } else if (type == SPC_CF_S_MESH_SS_RAMPMESH) { SPC_CONF_LOG << "Ramp mesh"; the_mesh = configure_ramp_mesh1D( mesh_section.get_section(SPC_CF_S_MESH_SS_RAMPMESH)); } else if (type == SPC_CF_S_MESH_SS_UNIFAXISYMESH) { SPC_CONF_LOG << "Uniform axisymmetric mesh"; the_mesh = configure_uniform_axisymmetric_mesh1D( mesh_section.get_section(SPC_CF_S_MESH_SS_UNIFAXISYMESH)); } else mesh_section.report_error(YAMLConfigError::InvalidArgument, "'"+type+"' is not a valid type of mesh."); uindex_t nb_nodes = the_mesh->nb_nodes(); SPC_CONF_LOG << "Coordinates : " << "\n - 0 : " << the_mesh->get_position(0) << "\n - 1 : " << the_mesh->get_position(1) << "\n - 2 : " << the_mesh->get_position(2) << "\n - ---- " << "\n - " << nb_nodes-3 << " : " << the_mesh->get_position(nb_nodes - 3) << "\n - " << nb_nodes-2 << " : " << the_mesh->get_position(nb_nodes - 2) << "\n - " << nb_nodes-1 << " : " << the_mesh->get_position(nb_nodes - 1) ; 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( SPC_CF_S_MESH_SS_UNIFMESH_A_DX, 0.0); geometry.nb_nodes = uniform_section.get_required_attribute( SPC_CF_S_MESH_SS_UNIFMESH_A_NBNODES, 0); geometry.section = uniform_section.get_required_attribute( SPC_CF_S_MESH_SS_UNIFMESH_A_SECTION, 0.0); 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( SPC_CF_S_MESH_SS_RAMPMESH_A_MIN_DX, 0.0); geometry.dx_max = ramp_section.get_required_attribute( SPC_CF_S_MESH_SS_RAMPMESH_A_MAX_DX, 0.0); geometry.length_ramp = ramp_section.get_required_attribute( SPC_CF_S_MESH_SS_RAMPMESH_A_RAMP_LENGTH, 0.0); geometry.length_plateau = ramp_section.get_required_attribute( SPC_CF_S_MESH_SS_RAMPMESH_A_PLATEAU_LENGTH, 0.0); geometry.section = ramp_section.get_required_attribute( SPC_CF_S_MESH_SS_RAMPMESH_A_SECTION, 0.0); 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( SPC_CF_S_MESH_SS_UNIFAXISYMESH_A_DX, -1.0); geometry.nb_nodes = axisymmetric_section.get_optional_attribute( SPC_CF_S_MESH_SS_UNIFAXISYMESH_A_NBNODES, -1.0); geometry.height = axisymmetric_section.get_required_attribute( SPC_CF_S_MESH_SS_UNIFAXISYMESH_A_HEIGHT, 0.0); geometry.radius = axisymmetric_section.get_required_attribute( SPC_CF_S_MESH_SS_UNIFAXISYMESH_A_RADIUS, 0.0); return mesh::uniform_axisymmetric_mesh1d(geometry); } -// old interface -// ------------- - -mesh::Mesh1DPtr configure_mesh(const YAML::Node& conf) -{ - check_mandatory_yaml_node(conf, SPC_CF_S_MESH, "__main__"); - const YAML::Node& subconf = conf[SPC_CF_S_MESH]; - - std::string type = subconf[SPC_CF_S_MESH_A_TYPE].as(); - if (type == SPC_CF_S_MESH_SS_UNIFMESH) - return configure_uniform_mesh1D(subconf); - else if (type == SPC_CF_S_MESH_SS_RAMPMESH) - return configure_ramp_mesh1D(subconf); - else if (type == SPC_CF_S_MESH_SS_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, SPC_CF_S_MESH_SS_UNIFMESH, SPC_CF_S_MESH); - const YAML::Node& subconf = conf[SPC_CF_S_MESH_SS_UNIFMESH]; - - mesh::Uniform1DMeshGeometry geometry; - geometry.dx = get_yaml_mandatory( - subconf, - SPC_CF_S_MESH_SS_UNIFMESH_A_DX, - SPC_CF_S_MESH_SS_UNIFMESH); - geometry.nb_nodes = get_yaml_mandatory( - subconf, - SPC_CF_S_MESH_SS_UNIFMESH_A_NBNODES, - SPC_CF_S_MESH_SS_UNIFMESH); - geometry.section = get_yaml_mandatory( - subconf, - SPC_CF_S_MESH_SS_UNIFMESH_A_SECTION, - SPC_CF_S_MESH_SS_UNIFMESH); - return mesh::uniform_mesh1d(geometry); -} - - - -mesh::Mesh1DPtr configure_ramp_mesh1D(const YAML::Node& conf) -{ - check_mandatory_yaml_node(conf, SPC_CF_S_MESH_SS_RAMPMESH, SPC_CF_S_MESH); - const YAML::Node& subconf = conf[SPC_CF_S_MESH_SS_RAMPMESH]; - - mesh::Ramp1DMeshGeometry geometry; - geometry.dx_min = get_yaml_mandatory( - subconf, - SPC_CF_S_MESH_SS_RAMPMESH_A_MIN_DX, - SPC_CF_S_MESH_SS_RAMPMESH); - geometry.dx_max = get_yaml_mandatory( - subconf, - SPC_CF_S_MESH_SS_RAMPMESH_A_MAX_DX, - SPC_CF_S_MESH_SS_RAMPMESH); - geometry.length_ramp = get_yaml_mandatory( - subconf, - SPC_CF_S_MESH_SS_RAMPMESH_A_RAMP_LENGTH, - SPC_CF_S_MESH_SS_RAMPMESH); - geometry.length_plateau = get_yaml_mandatory( - subconf, - SPC_CF_S_MESH_SS_RAMPMESH_A_PLATEAU_LENGTH, - SPC_CF_S_MESH_SS_RAMPMESH); - geometry.section = get_yaml_mandatory( - subconf, - SPC_CF_S_MESH_SS_RAMPMESH_A_SECTION, - SPC_CF_S_MESH_SS_RAMPMESH); - - return mesh::ramp_mesh1d(geometry); -} - -mesh::Mesh1DPtr configure_uniform_axisymmetric_mesh1D(const YAML::Node& conf) -{ - const YAML::Node& subconf = conf[SPC_CF_S_MESH_SS_UNIFAXISYMESH]; - - mesh::UniformAxisymmetricMesh1DGeometry geometry; - geometry.dx = get_yaml_optional( - subconf, - SPC_CF_S_MESH_SS_UNIFAXISYMESH_A_DX, - SPC_CF_S_MESH_SS_UNIFAXISYMESH, - -1.0); - geometry.nb_nodes = get_yaml_optional( - subconf, - SPC_CF_S_MESH_SS_UNIFAXISYMESH_A_NBNODES, - SPC_CF_S_MESH_SS_UNIFAXISYMESH, - -1); - geometry.height = get_yaml_mandatory( - subconf, - SPC_CF_S_MESH_SS_UNIFAXISYMESH_A_HEIGHT, - SPC_CF_S_MESH_SS_UNIFAXISYMESH); - geometry.radius = get_yaml_mandatory( - subconf, - SPC_CF_S_MESH_SS_UNIFAXISYMESH_A_RADIUS, - SPC_CF_S_MESH_SS_UNIFAXISYMESH); - - return mesh::uniform_axisymmetric_mesh1d(geometry); -} // transport options // ================= void configure_transport_options( dfpmsolver::ParabolicDriverOptions& options, const YAML::Node& configuration ) { check_mandatory_yaml_node(configuration, SPC_CF_S_DFPM, "__main__"); const YAML::Node& conf = configuration[SPC_CF_S_DFPM]; options.absolute_tolerance = get_yaml_optional( conf, SPC_CF_S_DFPM_A_ABS_TOL, SPC_CF_S_DFPM, DFPM_DEFAULT_ABS_TOL); options.residuals_tolerance = get_yaml_optional( conf, SPC_CF_S_DFPM_A_RES_TOL, SPC_CF_S_DFPM, DFPM_DEFAULT_RES_TOL); options.step_tolerance = get_yaml_optional( conf, SPC_CF_S_DFPM_A_STEP_TOL, SPC_CF_S_DFPM, DFPM_DEFAULT_STEP_TOL); options.maximum_iterations = get_yaml_optional( conf, SPC_CF_S_DFPM_A_MAX_ITER, SPC_CF_S_DFPM, DFPM_DEFAULT_MAX_ITER); options.maximum_step_length = get_yaml_optional( conf, SPC_CF_S_DFPM_A_MAX_STEP_LENGTH, SPC_CF_S_DFPM, DFPM_DEFAULT_MAX_STEP_LENGTH); options.max_iterations_at_max_length = get_yaml_optional(conf, SPC_CF_S_DFPM_A_MAX_STEP_MAX_ITER, SPC_CF_S_DFPM, DFPM_DEFAULT_MAX_ITER_MAX_LENGTH); options.threshold_stationary_point = get_yaml_optional(conf, SPC_CF_S_DFPM_A_TRSHOLD_STATIONARY, SPC_CF_S_DFPM, DFPM_DEFAULT_TRSHOLD_STATIONARY); options.quasi_newton = get_yaml_optional(conf, SPC_CF_S_DFPM_A_QUASI_NEWTON, SPC_CF_S_DFPM, DFPM_PARABOLIC_DEFAULT_QUASI_NEWTON); if (conf[SPC_CF_S_DFPM_A_SPARSE_SOLVER]) { std::string sparse_solver = conf[SPC_CF_S_DFPM_A_SPARSE_SOLVER].as(); if (sparse_solver == "LU") options.sparse_solver = sparse_solvers::SparseSolver::SparseLU; else if (sparse_solver == "QR") options.sparse_solver = sparse_solvers::SparseSolver::SparseQR; else if (sparse_solver == "GMRES") options.sparse_solver = sparse_solvers::SparseSolver::GMRES; else if (sparse_solver == "BiCGSTAB") options.sparse_solver = sparse_solvers::SparseSolver::BiCGSTAB; else throw std::runtime_error("Invalid argument for the sparse solver : '"+sparse_solver+"'.\n" +"Available solvers : 'LU' / 'QR' / 'GMRES' / 'BiCGSTAB'."); } if (conf[SPC_CF_S_DFPM_A_LINESEARCH]) { std::string linesearch = conf[SPC_CF_S_DFPM_A_LINESEARCH].as(); if (linesearch == "backtracking") options.linesearch = dfpmsolver::ParabolicLinesearch::Backtracking; else if (linesearch == "strang") options.linesearch = dfpmsolver::ParabolicLinesearch::Strang; else throw std::runtime_error("Invalid argument for the linesearch : '"+linesearch+"'.\n" +"Available options : 'backtracking' / 'strang'."); } } void configure_transport_options( dfpmsolver::ParabolicDriverOptions& options, io::YAMLConfigHandle&& conf ) { conf.set_if_attribute_exists( options.absolute_tolerance, SPC_CF_S_DFPM_A_ABS_TOL, 0.0); conf.set_if_attribute_exists( options.residuals_tolerance, SPC_CF_S_DFPM_A_RES_TOL, 0.0, 1.0); conf.set_if_attribute_exists( options.step_tolerance, SPC_CF_S_DFPM_A_STEP_TOL, 0.0, 1.0); conf.set_if_attribute_exists( options.maximum_iterations, SPC_CF_S_DFPM_A_MAX_ITER, 0); conf.set_if_attribute_exists( options.maximum_step_length, SPC_CF_S_DFPM_A_MAX_STEP_LENGTH, 0.0); conf.set_if_attribute_exists( options.max_iterations_at_max_length, SPC_CF_S_DFPM_A_MAX_STEP_MAX_ITER, 0); conf.set_if_attribute_exists( options.threshold_stationary_point, SPC_CF_S_DFPM_A_TRSHOLD_STATIONARY, 0.0, 1.0); conf.set_if_attribute_exists( options.quasi_newton, SPC_CF_S_DFPM_A_QUASI_NEWTON); if (conf.has_attribute(SPC_CF_S_DFPM_A_SPARSE_SOLVER)) { std::string sparse_solver = conf.get_attribute( SPC_CF_S_DFPM_A_SPARSE_SOLVER); if (sparse_solver == "LU") options.sparse_solver = sparse_solvers::SparseSolver::SparseLU; else if (sparse_solver == "QR") options.sparse_solver = sparse_solvers::SparseSolver::SparseQR; #ifdef EIGEN3_UNSUPPORTED_FOUND else if (sparse_solver == "GMRES") options.sparse_solver = sparse_solvers::SparseSolver::GMRES; #endif else if (sparse_solver == "BiCGSTAB") options.sparse_solver = sparse_solvers::SparseSolver::BiCGSTAB; else conf.report_error( YAMLConfigError::InvalidArgument, "Invalid argument for the sparse solver : '" + sparse_solver + "'.\n" "Available solvers :" "'LU' / 'QR' / 'GMRES' / 'BiCGSTAB'." ); } if (conf.has_attribute(SPC_CF_S_DFPM_A_LINESEARCH)) { std::string linesearch = conf.get_attribute(SPC_CF_S_DFPM_A_LINESEARCH); if (linesearch == "backtracking") options.linesearch = dfpmsolver::ParabolicLinesearch::Backtracking; else if (linesearch == "strang") options.linesearch = dfpmsolver::ParabolicLinesearch::Strang; else conf.report_error( YAMLConfigError::InvalidArgument, "Invalid argument for the linesearch : '" + linesearch + "'.\n" "Available options : 'backtracking' / 'strang'." ); } } } //end namespace io } //end namespace specmicp diff --git a/src/dfpm/io/configuration.hpp b/src/dfpm/io/configuration.hpp index 42c1fa0..7dd2447 100644 --- a/src/dfpm/io/configuration.hpp +++ b/src/dfpm/io/configuration.hpp @@ -1,122 +1,87 @@ /* ============================================================================= Copyright (c) 2014 - 2016 F. Georget 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. * ============================================================================= */ #ifndef SPECMICP_DFPM_IO_CONFIGURATION_HPP #define SPECMICP_DFPM_IO_CONFIGURATION_HPP #include "specmicp_common/macros.hpp" #include "dfpm/meshes/mesh1dfwd.hpp" namespace YAML { class Node; } //end namespace YAML namespace specmicp { namespace dfpmsolver { struct ParabolicDriverOptions; } //end namespace dfpmsolver namespace io { class YAMLConfigHandle; -//! \brief Configure the mesh -//! -//! \deprecated -mesh::Mesh1DPtr SPECMICP_DLL_PUBLIC -configure_mesh(const YAML::Node& conf) -SPECMICP_DEPRECATED("Unsafe YAML interface"); - -//! \brief Configure an uniform mesh -//! -//! \deprecated -mesh::Mesh1DPtr SPECMICP_DLL_PUBLIC -configure_uniform_mesh1D(const YAML::Node& conf) -SPECMICP_DEPRECATED("Unsafe YAML interface"); - -//! \brief Configure a 'ramp' mesh -//! -//! \deprecated -mesh::Mesh1DPtr SPECMICP_DLL_PUBLIC -configure_ramp_mesh1D(const YAML::Node& conf) -SPECMICP_DEPRECATED("Unsafe YAML interface"); - -//! \brief Configure an uniform axisymmetric mesh -//! -//! \deprecated -mesh::Mesh1DPtr SPECMICP_DLL_PUBLIC -configure_uniform_axisymmetric_mesh1D(const YAML::Node& conf) -SPECMICP_DEPRECATED("Unsafe YAML interface"); - - //! \brief Configure the mesh mesh::Mesh1DPtr SPECMICP_DLL_PUBLIC configure_mesh(YAMLConfigHandle&& mesh_section); //! \brief Configure an uniform mesh mesh::Mesh1DPtr SPECMICP_DLL_PUBLIC configure_uniform_mesh1D(YAMLConfigHandle&& uniform_section); //! \brief Configure a 'ramp' mesh mesh::Mesh1DPtr SPECMICP_DLL_PUBLIC configure_ramp_mesh1D(YAMLConfigHandle&& ramp_section); //! \brief Configure an uniform axisymmetric mesh mesh::Mesh1DPtr SPECMICP_DLL_PUBLIC configure_uniform_axisymmetric_mesh1D(YAMLConfigHandle&& axisymmetric_section); // parabolic driver // ---------------- -//! \brief Configure parabolic driver options -void SPECMICP_DLL_PUBLIC configure_transport_options( - dfpmsolver::ParabolicDriverOptions& options, - const YAML::Node& configuration - ) SPECMICP_DEPRECATED("Use new, safer config interface"); - //! \brief Configure parabolic driver options void SPECMICP_DLL_PUBLIC configure_transport_options( dfpmsolver::ParabolicDriverOptions& options, io::YAMLConfigHandle&& configuration ); } //end namespace io } //end namespace specmicp #endif // SPECMICP_DFPM_IO_CONFIGURATION_HPP