From bf653bd2d8cb77f918b244374be8d27856d118f7 Mon Sep 17 00:00:00 2001 From: DavidSCN Date: Wed, 3 Mar 2021 08:49:54 +0100 Subject: [PATCH 01/11] Move and unify parameter header file into include path --- include/adapter/parameters.h | 133 ++++++++++++++++ .../include/parameter_handling.h | 120 --------------- .../include/parameter_handling.h | 145 ------------------ 3 files changed, 133 insertions(+), 265 deletions(-) create mode 100644 include/adapter/parameters.h delete mode 100644 source/linear_elasticity/include/parameter_handling.h delete mode 100644 source/nonlinear_elasticity/include/parameter_handling.h diff --git a/include/adapter/parameters.h b/include/adapter/parameters.h new file mode 100644 index 0000000..bdad65d --- /dev/null +++ b/include/adapter/parameters.h @@ -0,0 +1,133 @@ +#ifndef PARAMETERS_H +#define PARAMETERS_H + +#include + +/** + * This class declares all parameters, which can be specified in the parameter + * file. The subsection abut preCICE configurations is directly interlinked + * to the Adapter class. + */ +namespace Parameters +{ + using namespace dealii; + /** + * @brief Time: Specifies simulation time properties + */ + struct Time + { + double end_time; + double delta_t; + int output_interval; + + static void + declare_parameters(ParameterHandler &prm); + + void + parse_parameters(ParameterHandler &prm); + }; + + /** + * @brief The System struct keeps material properties and body force contributions + */ + struct System + { + double nu; + double mu; + double lambda; + double rho; + Tensor<1, 3, double> body_force; + + + static void + declare_parameters(ParameterHandler &prm); + + void + parse_parameters(ParameterHandler &prm); + }; + + + /** + * @brief LinearSolver: Specifies linear solver properties + */ + struct Solver + { + std::string type_lin; + double tol_lin; + double max_iterations_lin; + unsigned int max_iterations_NR; + double tol_f; + double tol_u; + + static void + declare_parameters(ParameterHandler &prm); + + void + parse_parameters(ParameterHandler &prm); + }; + + + + /** + * @brief Discretization: Specifies parameters for time integration by a + * theta scheme and polynomial degree of the FE system + */ + struct Discretization + { + unsigned int poly_degree; + // For the linear elastic model (theta-scheme) + double theta; + // For the nonlinear elastic model (Newmark) + double beta; + double gamma ; + + static void + declare_parameters(ParameterHandler &prm); + + void + parse_parameters(ParameterHandler &prm); + }; + + + /** + * @brief PreciceAdapterConfiguration: Specifies preCICE related information. + * A lot of these information need to be consistent with the + * precice-config.xml file. + */ + struct PreciceAdapterConfiguration + { + std::string scenario; + std::string config_file; + std::string participant_name; + std::string mesh_name; + std::string read_data_name; + std::string write_data_name; + double flap_location; + bool data_consistent; + + static void + declare_parameters(ParameterHandler &prm); + + void + parse_parameters(ParameterHandler &prm); + }; + + + struct AllParameters : public Solver, + public Discretization, + public System, + public Time, + public PreciceAdapterConfiguration + + { + AllParameters(const std::string &input_file); + + static void + declare_parameters(ParameterHandler &prm); + + void + parse_parameters(ParameterHandler &prm); + }; +} // namespace Parameters + +#endif // PARAMETERS_H diff --git a/source/linear_elasticity/include/parameter_handling.h b/source/linear_elasticity/include/parameter_handling.h deleted file mode 100644 index 3a22274..0000000 --- a/source/linear_elasticity/include/parameter_handling.h +++ /dev/null @@ -1,120 +0,0 @@ -#pragma once - -#include - -namespace Linear_Elasticity -{ - using namespace dealii; - - /** - * This class declares all parameters, which can be specified in the parameter - * file. The subsection abut preCICE configurations is directly interlinked - * to the Adapter class. - */ - namespace Parameters - { - // TODO: Add more parameters - struct Time - { - double delta_t; - double end_time; - int output_interval; - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - - /** - * @brief Discretization: Specifies parameters for time integration by a - * theta scheme and polynomial degree of the FE system - */ - struct Discretization - { - double theta; - unsigned int poly_degree; - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - - /** - * @brief The System struct keeps material properties and body force contributions - */ - struct System - { - double mu; - double lambda; - double rho; - Tensor<1, 3, double> body_force; - - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - - /** - * @brief LinearSolver: Specifies linear solver properties - */ - struct LinearSolver - { - std::string type_lin; - double tol_lin; - double max_iterations_lin; - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - - /** - * @brief PreciceAdapterConfiguration: Specifies preCICE related information. - * A lot of these information need to be consistent with the - * precice-config.xml file. - */ - struct PreciceAdapterConfiguration - { - std::string scenario; - std::string config_file; - std::string participant_name; - std::string mesh_name; - std::string read_data_name; - std::string write_data_name; - double flap_location; - bool data_consistent; - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - - - struct AllParameters : public LinearSolver, - public Discretization, - public System, - public Time, - public PreciceAdapterConfiguration - - { - AllParameters(const std::string &input_file); - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - } // namespace Parameters -} // namespace Linear_Elasticity diff --git a/source/nonlinear_elasticity/include/parameter_handling.h b/source/nonlinear_elasticity/include/parameter_handling.h deleted file mode 100644 index 7c62131..0000000 --- a/source/nonlinear_elasticity/include/parameter_handling.h +++ /dev/null @@ -1,145 +0,0 @@ -#pragma once - -#include - -namespace Nonlinear_Elasticity -{ - using namespace dealii; - - /** - * This class declares all parameters, which can be specified in the parameter - * file. The subsection abut preCICE configurations is directly interlinked - * to the Adapter class. - */ - namespace Parameters - { - /** - * @brief System: Specifies system properties - */ - struct System - { - double nu; - double mu; - double rho; - Tensor<1, 3, double> body_force; - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - - - /** - * @brief LinearSolver: Specifies linear solver properties - */ - struct LinearSolver - { - std::string type_lin; - double tol_lin; - double max_iterations_lin; - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - - - /** - * @brief NonlinearSolver: Specifies nonlinear solver properties - */ - struct NonlinearSolver - { - unsigned int max_iterations_NR; - double tol_f; - double tol_u; - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - - - /** - * @brief Time: Specifies simulation time properties - */ - struct Time - { - double delta_t; - double end_time; - int output_interval; - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - - /** - * @brief Discretization: Specifies parameters for time integration by an - * implicit Newmark scheme and polynomial degree of the FE system - */ - struct Discretization - { - double beta; - double gamma; - unsigned int poly_degree; - - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - - - /** - * @brief PreciceAdapterConfiguration: Specifies preCICE related information. - * A lot of these information need to be consistent with the - * precice-config.xml file. - */ - struct PreciceAdapterConfiguration - { - std::string scenario; - std::string config_file; - std::string participant_name; - std::string mesh_name; - std::string read_data_name; - std::string write_data_name; - double flap_location; - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - - - struct AllParameters : public System, - public LinearSolver, - public NonlinearSolver, - public Time, - public Discretization, - public PreciceAdapterConfiguration - - { - AllParameters(const std::string &input_file); - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); - }; - - - } // namespace Parameters -} // namespace Nonlinear_Elasticity From c3fe0064ddfbfaa4ee6cbd57ca409892044f7414 Mon Sep 17 00:00:00 2001 From: DavidSCN Date: Wed, 3 Mar 2021 08:51:56 +0100 Subject: [PATCH 02/11] Move and unify parameter sources into include path --- include/adapter/parameters.cc | 277 ++++++++++++++++++ source/linear_elasticity/linear_elasticity.cc | 237 --------------- .../nonlinear_elasticity.cc | 272 ----------------- 3 files changed, 277 insertions(+), 509 deletions(-) create mode 100644 include/adapter/parameters.cc diff --git a/include/adapter/parameters.cc b/include/adapter/parameters.cc new file mode 100644 index 0000000..7a6a4aa --- /dev/null +++ b/include/adapter/parameters.cc @@ -0,0 +1,277 @@ +#include + +namespace Parameters +{ + void + Time::declare_parameters(ParameterHandler &prm) + { + prm.enter_subsection("Time"); + { + prm.declare_entry("End time", "1", Patterns::Double(), "End time"); + + prm.declare_entry("Time step size", + "0.1", + Patterns::Double(), + "Time step size"); + + prm.declare_entry("Output interval", + "1", + Patterns::Integer(0), + "Write results every x timesteps"); + } + prm.leave_subsection(); + } + + void + Time::parse_parameters(ParameterHandler &prm) + { + prm.enter_subsection("Time"); + { + end_time = prm.get_double("End time"); + delta_t = prm.get_double("Time step size"); + output_interval = prm.get_integer("Output interval"); + } + prm.leave_subsection(); + } + + void + System::declare_parameters(ParameterHandler &prm) + { + prm.enter_subsection("System properties"); + { + prm.declare_entry("Shear modulus", + "0.4225e6", + Patterns::Double(), + "Shear modulus"); + + prm.declare_entry("Poisson's ratio", + "0.3", + Patterns::Double(-1.0, 0.5), + "Poisson's ratio"); + + prm.declare_entry("rho", "1000", Patterns::Double(0.0), "density"); + + prm.declare_entry("body forces", + "0,0,0", + Patterns::List(Patterns::Double()), + "body forces x,y,z"); + } + prm.leave_subsection(); + } + + void + System::parse_parameters(ParameterHandler &prm) + { + prm.enter_subsection("System properties"); + { + mu = prm.get_double("Shear modulus"); + nu = prm.get_double("Poisson's ratio"); + rho = prm.get_double("rho"); + const std::vector body_forces_input = + Utilities::split_string_list(prm.get("body forces")); + for (uint d = 0; d < 3; ++d) + body_force[d] = Utilities::string_to_double(body_forces_input[d]); + } + prm.leave_subsection(); + + lambda = 2 * mu * nu / (1 - 2 * nu); + } + + + void + Solver::declare_parameters(ParameterHandler &prm) + { + prm.enter_subsection("Linear solver"); + { + prm.declare_entry("Solver type", + "Direct", + Patterns::Selection("CG|Direct"), + "Linear solver: CG or Direct"); + + prm.declare_entry("Residual", + "1e-6", + Patterns::Double(0.0), + "Linear solver residual (scaled by residual norm)"); + + prm.declare_entry( + "Max iteration multiplier", + "1", + Patterns::Double(0.0), + "Linear solver iterations (multiples of the system matrix size)"); + + prm.declare_entry("Max iterations Newton-Raphson", + "10", + Patterns::Integer(0), + "Number of Newton-Raphson iterations allowed"); + + prm.declare_entry("Tolerance force", + "1.0e-9", + Patterns::Double(0.0), + "Force residual tolerance"); + + prm.declare_entry("Tolerance displacement", + "1.0e-6", + Patterns::Double(0.0), + "Displacement error tolerance"); + } + prm.leave_subsection(); + } + + + void + Solver::parse_parameters(ParameterHandler &prm) + { + prm.enter_subsection("Solver"); + { + type_lin = prm.get("Solver type"); + tol_lin = prm.get_double("Residual"); + max_iterations_lin = prm.get_double("Max iteration multiplier"); + + max_iterations_NR = prm.get_integer("Max iterations Newton-Raphson"); + tol_f = prm.get_double("Tolerance force"); + tol_u = prm.get_double("Tolerance displacement"); + } + prm.leave_subsection(); + } + + + void + Discretization::declare_parameters(ParameterHandler &prm) + { + prm.enter_subsection("Discretization"); + { + prm.declare_entry("Polynomial degree", + "3", + Patterns::Integer(0), + "Polynomial degree of the FE system"); + + prm.declare_entry("theta", + "0.5", + Patterns::Double(0, 1), + "Time integration scheme"); + + prm.declare_entry("beta", + "0.25", + Patterns::Double(0, 0.5), + "Newmark beta"); + + prm.declare_entry("gamma", + "0.5", + Patterns::Double(0, 1), + "Newmark gamma"); + } + prm.leave_subsection(); + } + + void + Discretization::parse_parameters(ParameterHandler &prm) + { + prm.enter_subsection("Discretization"); + { + poly_degree = prm.get_integer("Polynomial degree"); + theta = prm.get_double("theta"); + beta = prm.get_double("beta"); + gamma = prm.get_double("gamma"); + } + prm.leave_subsection(); + } + + + void + PreciceAdapterConfiguration::declare_parameters(ParameterHandler &prm) + { + prm.enter_subsection("precice configuration"); + { + prm.declare_entry("Scenario", + "FSI3", + Patterns::Selection("FSI3|PF"), + "Cases: FSI3 or PF for perpendicular flap"); + prm.declare_entry("precice config-file", + "precice-config.xml", + Patterns::Anything(), + "Name of the precice configuration file"); + prm.declare_entry( + "Participant name", + "dealiisolver", + Patterns::Anything(), + "Name of the participant in the precice-config.xml file"); + prm.declare_entry( + "Mesh name", + "dealii-mesh", + Patterns::Anything(), + "Name of the coupling mesh in the precice-config.xml file"); + prm.declare_entry("Read data name", + "received-data", + Patterns::Anything(), + "Name of the read data in the precice-config.xml file"); + prm.declare_entry( + "Write data name", + "calculated-data", + Patterns::Anything(), + "Name of the write data in the precice-config.xml file"); + prm.declare_entry("Flap location", + "0.0", + Patterns::Double(-3, 3), + "PF x-location"); + } + prm.leave_subsection(); + } + + void + PreciceAdapterConfiguration::parse_parameters(ParameterHandler &prm) + { + prm.enter_subsection("precice configuration"); + { + scenario = prm.get("Scenario"); + config_file = prm.get("precice config-file"); + participant_name = prm.get("Participant name"); + mesh_name = prm.get("Mesh name"); + read_data_name = prm.get("Read data name"); + write_data_name = prm.get("Write data name"); + flap_location = prm.get_double("Flap location"); + } + prm.leave_subsection(); + // Look at the specific type of read data + if ((read_data_name.find("Stress") == 0)) + data_consistent = true; + else if ((read_data_name.find("Force") == 0)) + data_consistent = false; + else + AssertThrow( + false, + ExcMessage( + "Unknown read data type. Please use 'Force' or 'Stress' in the read data naming.")); + } + + AllParameters::AllParameters(const std::string &input_file) + { + ParameterHandler prm; + declare_parameters(prm); + prm.parse_input(input_file); + parse_parameters(prm); + + // Optional, if we want to print all parameters in the beginning of the + // simulation + // prm.print_parameters(std::cout,ParameterHandler::Text); + } + + void + AllParameters::declare_parameters(ParameterHandler &prm) + { + Solver::declare_parameters(prm); + Discretization::declare_parameters(prm); + System::declare_parameters(prm); + Time::declare_parameters(prm); + PreciceAdapterConfiguration::declare_parameters(prm); + } + + void + AllParameters::parse_parameters(ParameterHandler &prm) + { + Solver::parse_parameters(prm); + Discretization::parse_parameters(prm); + System::parse_parameters(prm); + Time::parse_parameters(prm); + PreciceAdapterConfiguration::parse_parameters(prm); + } +} // namespace Parameters diff --git a/source/linear_elasticity/linear_elasticity.cc b/source/linear_elasticity/linear_elasticity.cc index 6dc0ef3..a69584d 100644 --- a/source/linear_elasticity/linear_elasticity.cc +++ b/source/linear_elasticity/linear_elasticity.cc @@ -50,243 +50,6 @@ namespace Linear_Elasticity { using namespace dealii; - namespace Parameters - { - void - Time::declare_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Time"); - { - prm.declare_entry("End time", "1", Patterns::Double(), "End time"); - - prm.declare_entry("Time step size", - "0.1", - Patterns::Double(), - "Time step size"); - - prm.declare_entry("Output interval", - "1", - Patterns::Integer(0), - "Write results every x timesteps"); - } - prm.leave_subsection(); - } - - void - Time::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Time"); - { - end_time = prm.get_double("End time"); - delta_t = prm.get_double("Time step size"); - output_interval = prm.get_integer("Output interval"); - } - prm.leave_subsection(); - } - - void - Discretization::declare_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Discretization"); - { - prm.declare_entry("theta", - "0.5", - Patterns::Double(0, 1), - "Time integration scheme"); - - prm.declare_entry("Polynomial degree", - "3", - Patterns::Integer(0), - "Polynomial degree of the FE system"); - } - prm.leave_subsection(); - } - - void - Discretization::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Discretization"); - { - theta = prm.get_double("theta"); - poly_degree = prm.get_integer("Polynomial degree"); - } - prm.leave_subsection(); - } - - void - System::declare_parameters(ParameterHandler &prm) - { - prm.enter_subsection("System properties"); - { - prm.declare_entry("mu", "0.5e6", Patterns::Double(), "mu"); - - prm.declare_entry("lambda", "2e6", Patterns::Double(), "lambda"); - - prm.declare_entry("rho", "1000", Patterns::Double(0.0), "density"); - - prm.declare_entry("body forces", - "0,0,0", - Patterns::List(Patterns::Double()), - "body forces x,y,z"); - } - prm.leave_subsection(); - } - - void - System::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("System properties"); - { - mu = prm.get_double("mu"); - lambda = prm.get_double("lambda"); - rho = prm.get_double("rho"); - const std::vector body_forces_input = - Utilities::split_string_list(prm.get("body forces")); - for (uint d = 0; d < 3; ++d) - body_force[d] = Utilities::string_to_double(body_forces_input[d]); - } - prm.leave_subsection(); - } - - - void - LinearSolver::declare_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Linear solver"); - { - prm.declare_entry("Solver type", - "Direct", - Patterns::Selection("CG|Direct"), - "Linear solver: CG or Direct"); - - prm.declare_entry("Residual", - "1e-6", - Patterns::Double(0.0), - "Linear solver residual (scaled by residual norm)"); - - prm.declare_entry( - "Max iteration multiplier", - "1", - Patterns::Double(0.0), - "Linear solver iterations (multiples of the system matrix size)"); - } - prm.leave_subsection(); - } - - void - LinearSolver::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Linear solver"); - { - type_lin = prm.get("Solver type"); - tol_lin = prm.get_double("Residual"); - max_iterations_lin = prm.get_double("Max iteration multiplier"); - } - prm.leave_subsection(); - } - - void - PreciceAdapterConfiguration::declare_parameters(ParameterHandler &prm) - { - prm.enter_subsection("precice configuration"); - { - prm.declare_entry("Scenario", - "FSI3", - Patterns::Selection("FSI3|PF"), - "Cases: FSI3 or PF for perpendicular flap"); - prm.declare_entry("precice config-file", - "precice-config.xml", - Patterns::Anything(), - "Name of the precice configuration file"); - prm.declare_entry( - "Participant name", - "dealiisolver", - Patterns::Anything(), - "Name of the participant in the precice-config.xml file"); - prm.declare_entry( - "Mesh name", - "dealii-mesh", - Patterns::Anything(), - "Name of the coupling mesh in the precice-config.xml file"); - prm.declare_entry( - "Read data name", - "received-data", - Patterns::Anything(), - "Name of the read data in the precice-config.xml file"); - prm.declare_entry( - "Write data name", - "calculated-data", - Patterns::Anything(), - "Name of the write data in the precice-config.xml file"); - prm.declare_entry("Flap location", - "0.0", - Patterns::Double(-3, 3), - "PF x-location"); - } - prm.leave_subsection(); - } - - void - PreciceAdapterConfiguration::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("precice configuration"); - { - scenario = prm.get("Scenario"); - config_file = prm.get("precice config-file"); - participant_name = prm.get("Participant name"); - mesh_name = prm.get("Mesh name"); - read_data_name = prm.get("Read data name"); - write_data_name = prm.get("Write data name"); - flap_location = prm.get_double("Flap location"); - } - prm.leave_subsection(); - // Look at the specific type of read data - if ((read_data_name.find("Stress") == 0)) - data_consistent = true; - else if ((read_data_name.find("Force") == 0)) - data_consistent = false; - else - AssertThrow( - false, - ExcMessage( - "Unknown read data type. Please use 'Force' or 'Stress' in the read data naming.")); - } - - AllParameters::AllParameters(const std::string &input_file) - { - ParameterHandler prm; - declare_parameters(prm); - prm.parse_input(input_file); - parse_parameters(prm); - - // Optional, if we want to print all parameters in the beginning of the - // simulation - // prm.print_parameters(std::cout,ParameterHandler::Text); - } - - void - AllParameters::declare_parameters(ParameterHandler &prm) - { - LinearSolver::declare_parameters(prm); - Discretization::declare_parameters(prm); - System::declare_parameters(prm); - Time::declare_parameters(prm); - PreciceAdapterConfiguration::declare_parameters(prm); - } - - void - AllParameters::parse_parameters(ParameterHandler &prm) - { - LinearSolver::parse_parameters(prm); - Discretization::parse_parameters(prm); - System::parse_parameters(prm); - Time::parse_parameters(prm); - PreciceAdapterConfiguration::parse_parameters(prm); - } - - } // namespace Parameters - - // Constructor template ElastoDynamics::ElastoDynamics(const std::string &case_path) diff --git a/source/nonlinear_elasticity/nonlinear_elasticity.cc b/source/nonlinear_elasticity/nonlinear_elasticity.cc index bc85aa3..2425d3b 100644 --- a/source/nonlinear_elasticity/nonlinear_elasticity.cc +++ b/source/nonlinear_elasticity/nonlinear_elasticity.cc @@ -57,278 +57,6 @@ namespace Nonlinear_Elasticity { using namespace dealii; - namespace Parameters - { - AllParameters::AllParameters(const std::string &input_file) - { - ParameterHandler prm; - declare_parameters(prm); - prm.parse_input(input_file); - parse_parameters(prm); - - // Optional, if we want to print all parameters in the beginning of the - // simulation - // prm.print_parameters(std::cout,ParameterHandler::Text); - } - - void - Discretization::declare_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Discretization"); - { - prm.declare_entry("beta", - "0.25", - Patterns::Double(0, 0.5), - "Newmark beta"); - - prm.declare_entry("gamma", - "0.5", - Patterns::Double(0, 1), - "Newmark gamma"); - - prm.declare_entry("Polynomial degree", - "3", - Patterns::Integer(0), - "Polynomial degree of the FE system"); - } - prm.leave_subsection(); - } - - void - Discretization::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Discretization"); - { - beta = prm.get_double("beta"); - gamma = prm.get_double("gamma"); - poly_degree = prm.get_integer("Polynomial degree"); - } - prm.leave_subsection(); - } - - void - PreciceAdapterConfiguration::declare_parameters(ParameterHandler &prm) - { - prm.enter_subsection("precice configuration"); - { - prm.declare_entry("Scenario", - "FSI3", - Patterns::Selection("FSI3|PF"), - "Cases: FSI3 or PF for perpendicular flap"); - prm.declare_entry("precice config-file", - "precice-config.xml", - Patterns::Anything(), - "Name of the precice configuration file"); - prm.declare_entry( - "Participant name", - "dealiisolver", - Patterns::Anything(), - "Name of the participant in the precice-config.xml file"); - prm.declare_entry( - "Mesh name", - "dealii-mesh", - Patterns::Anything(), - "Name of the coupling mesh in the precice-config.xml file"); - prm.declare_entry( - "Read data name", - "received-data", - Patterns::Anything(), - "Name of the read data in the precice-config.xml file"); - prm.declare_entry( - "Write data name", - "calculated-data", - Patterns::Anything(), - "Name of the write data in the precice-config.xml file"); - prm.declare_entry("Flap location", - "0.0", - Patterns::Double(-3, 3), - "PF x-location"); - } - prm.leave_subsection(); - } - - void - PreciceAdapterConfiguration::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("precice configuration"); - { - scenario = prm.get("Scenario"); - config_file = prm.get("precice config-file"); - participant_name = prm.get("Participant name"); - mesh_name = prm.get("Mesh name"); - read_data_name = prm.get("Read data name"); - write_data_name = prm.get("Write data name"); - flap_location = prm.get_double("Flap location"); - } - prm.leave_subsection(); - } - - void - Time::declare_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Time"); - { - prm.declare_entry("End time", "1", Patterns::Double(), "End time"); - - prm.declare_entry("Time step size", - "0.1", - Patterns::Double(), - "Time step size"); - - prm.declare_entry("Output interval", - "1", - Patterns::Integer(), - "Output interval"); - } - prm.leave_subsection(); - } - - void - Time::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Time"); - { - end_time = prm.get_double("End time"); - delta_t = prm.get_double("Time step size"); - output_interval = prm.get_integer("Output interval"); - } - prm.leave_subsection(); - } - - void - NonlinearSolver::declare_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Nonlinear solver"); - { - prm.declare_entry("Max iterations Newton-Raphson", - "10", - Patterns::Integer(0), - "Number of Newton-Raphson iterations allowed"); - - prm.declare_entry("Tolerance force", - "1.0e-9", - Patterns::Double(0.0), - "Force residual tolerance"); - - prm.declare_entry("Tolerance displacement", - "1.0e-6", - Patterns::Double(0.0), - "Displacement error tolerance"); - } - prm.leave_subsection(); - } - - void - NonlinearSolver::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Nonlinear solver"); - { - max_iterations_NR = prm.get_integer("Max iterations Newton-Raphson"); - tol_f = prm.get_double("Tolerance force"); - tol_u = prm.get_double("Tolerance displacement"); - } - prm.leave_subsection(); - } - - void - LinearSolver::declare_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Linear solver"); - { - prm.declare_entry("Solver type", - "CG", - Patterns::Selection("CG|Direct"), - "Linear solver: CG or Direct"); - - prm.declare_entry("Residual", - "1e-6", - Patterns::Double(0.0), - "Linear solver residual (scaled by residual norm)"); - - prm.declare_entry( - "Max iteration multiplier", - "1", - Patterns::Double(0.0), - "Linear solver iterations (multiples of the system matrix size)"); - } - prm.leave_subsection(); - } - void - System::declare_parameters(ParameterHandler &prm) - { - prm.enter_subsection("System properties"); - { - prm.declare_entry("Poisson's ratio", - "0.3", - Patterns::Double(-1.0, 0.5), - "Poisson's ratio"); - - prm.declare_entry("Shear modulus", - "0.4225e6", - Patterns::Double(), - "Shear modulus"); - - prm.declare_entry("rho", "1000", Patterns::Double(), "rho"); - - prm.declare_entry("body forces", - "0,0,0", - Patterns::List(Patterns::Double()), - "body forces x,y,z"); - } - prm.leave_subsection(); - } - - void - System::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("System properties"); - { - nu = prm.get_double("Poisson's ratio"); - mu = prm.get_double("Shear modulus"); - rho = prm.get_double("rho"); - const std::vector body_forces_input = - Utilities::split_string_list(prm.get("body forces")); - for (uint d = 0; d < 3; ++d) - body_force[d] = Utilities::string_to_double(body_forces_input[d]); - } - prm.leave_subsection(); - } - - void - LinearSolver::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Linear solver"); - { - type_lin = prm.get("Solver type"); - tol_lin = prm.get_double("Residual"); - max_iterations_lin = prm.get_double("Max iteration multiplier"); - } - prm.leave_subsection(); - } - } // namespace Parameters - - void - Parameters::AllParameters::declare_parameters(ParameterHandler &prm) - { - System::declare_parameters(prm); - LinearSolver::declare_parameters(prm); - NonlinearSolver::declare_parameters(prm); - Time::declare_parameters(prm); - Discretization::declare_parameters(prm); - PreciceAdapterConfiguration::declare_parameters(prm); - } - - void - Parameters::AllParameters::parse_parameters(ParameterHandler &prm) - { - System::parse_parameters(prm); - LinearSolver::parse_parameters(prm); - NonlinearSolver::parse_parameters(prm); - Time::parse_parameters(prm); - Discretization::parse_parameters(prm); - PreciceAdapterConfiguration::parse_parameters(prm); - } - // Constructor initializes member variables and reads the parameter file template Solid::Solid(const std::string &case_path) From 4057bbe34218b69caeef9302383f5f67fb711be1 Mon Sep 17 00:00:00 2001 From: DavidSCN Date: Wed, 3 Mar 2021 08:52:40 +0100 Subject: [PATCH 03/11] Configure CMake for new source file and adjust includes --- CMakeLists.txt | 2 +- source/linear_elasticity/include/linear_elasticity.h | 2 +- source/linear_elasticity/linear_elasticity.cc | 2 +- source/nonlinear_elasticity/include/nonlinear_elasticity.h | 2 +- source/nonlinear_elasticity/nonlinear_elasticity.cc | 3 ++- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97e278a..fd8f940 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ ADD_DEFINITIONS(-DDIM=${DIM}) # Set the target and the target source SET( TARGET "dealii-precice" ) -SET( TARGET_SRC ${TARGET}.cc ) +SET( TARGET_SRC ${TARGET}.cc include/adapter/parameters.cc) DEAL_II_INITIALIZE_CACHED_VARIABLES() diff --git a/source/linear_elasticity/include/linear_elasticity.h b/source/linear_elasticity/include/linear_elasticity.h index 18c2c2e..78ac2b0 100644 --- a/source/linear_elasticity/include/linear_elasticity.h +++ b/source/linear_elasticity/include/linear_elasticity.h @@ -37,12 +37,12 @@ #include #include +#include #include #include #include -#include "parameter_handling.h" #include "postprocessor.h" // The Linear_Elasticity case includes a linear elastic material with a one-step diff --git a/source/linear_elasticity/linear_elasticity.cc b/source/linear_elasticity/linear_elasticity.cc index a69584d..0120e1d 100644 --- a/source/linear_elasticity/linear_elasticity.cc +++ b/source/linear_elasticity/linear_elasticity.cc @@ -36,12 +36,12 @@ #include #include +#include #include #include #include -#include "include/parameter_handling.h" #include "include/postprocessor.h" // The Linear_Elasticity case includes a linear elastic material with a one-step diff --git a/source/nonlinear_elasticity/include/nonlinear_elasticity.h b/source/nonlinear_elasticity/include/nonlinear_elasticity.h index e68f240..a4a1270 100644 --- a/source/nonlinear_elasticity/include/nonlinear_elasticity.h +++ b/source/nonlinear_elasticity/include/nonlinear_elasticity.h @@ -49,13 +49,13 @@ #include #include +#include #include #include #include #include "compressible_neo_hook_material.h" -#include "parameter_handling.h" #include "postprocessor.h" namespace Nonlinear_Elasticity diff --git a/source/nonlinear_elasticity/nonlinear_elasticity.cc b/source/nonlinear_elasticity/nonlinear_elasticity.cc index 2425d3b..19ea161 100644 --- a/source/nonlinear_elasticity/nonlinear_elasticity.cc +++ b/source/nonlinear_elasticity/nonlinear_elasticity.cc @@ -47,10 +47,11 @@ #include #include +#include + #include #include -#include "include/parameter_handling.h" #include "include/postprocessor.h" namespace Nonlinear_Elasticity From 8f8369c7caf3a5dfe28ac56a4290e9180e392a13 Mon Sep 17 00:00:00 2001 From: DavidSCN Date: Wed, 3 Mar 2021 09:57:43 +0100 Subject: [PATCH 04/11] Simplify parameter handling using add_parameter --- include/adapter/parameters.cc | 316 +++++++++++++--------------------- include/adapter/parameters.h | 82 ++++----- 2 files changed, 146 insertions(+), 252 deletions(-) diff --git a/include/adapter/parameters.cc b/include/adapter/parameters.cc index 7a6a4aa..97b24fa 100644 --- a/include/adapter/parameters.cc +++ b/include/adapter/parameters.cc @@ -3,74 +3,47 @@ namespace Parameters { void - Time::declare_parameters(ParameterHandler &prm) + Time::add_output_parameters(ParameterHandler &prm) { prm.enter_subsection("Time"); { - prm.declare_entry("End time", "1", Patterns::Double(), "End time"); + prm.add_parameter("End time", end_time, "End time", Patterns::Double()); - prm.declare_entry("Time step size", - "0.1", - Patterns::Double(), - "Time step size"); + prm.add_parameter("Time step size", + delta_t, + "Time step size", + Patterns::Double()); - prm.declare_entry("Output interval", - "1", - Patterns::Integer(0), - "Write results every x timesteps"); + prm.add_parameter("Output interval", + output_interval, + "Write results every x timesteps", + Patterns::Integer(0)); } prm.leave_subsection(); } - void - Time::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Time"); - { - end_time = prm.get_double("End time"); - delta_t = prm.get_double("Time step size"); - output_interval = prm.get_integer("Output interval"); - } - prm.leave_subsection(); - } - - void - System::declare_parameters(ParameterHandler &prm) - { - prm.enter_subsection("System properties"); - { - prm.declare_entry("Shear modulus", - "0.4225e6", - Patterns::Double(), - "Shear modulus"); - - prm.declare_entry("Poisson's ratio", - "0.3", - Patterns::Double(-1.0, 0.5), - "Poisson's ratio"); - - prm.declare_entry("rho", "1000", Patterns::Double(0.0), "density"); - - prm.declare_entry("body forces", - "0,0,0", - Patterns::List(Patterns::Double()), - "body forces x,y,z"); - } - prm.leave_subsection(); - } void - System::parse_parameters(ParameterHandler &prm) + System::add_output_parameters(ParameterHandler &prm) { prm.enter_subsection("System properties"); { - mu = prm.get_double("Shear modulus"); - nu = prm.get_double("Poisson's ratio"); - rho = prm.get_double("rho"); - const std::vector body_forces_input = - Utilities::split_string_list(prm.get("body forces")); - for (uint d = 0; d < 3; ++d) - body_force[d] = Utilities::string_to_double(body_forces_input[d]); + prm.add_parameter("Shear modulus", + mu, + "Shear modulus", + Patterns::Double()); + + prm.add_parameter("Poisson's ratio", + nu, + "Poisson's ratio", + Patterns::Double(-1.0, 0.5)); + + prm.add_parameter("rho", rho, "density", Patterns::Double(0.0)); + + prm.add_parameter("body forces", + body_force, + "body forces x,y,z", + Patterns::List(Patterns::Double())); } prm.leave_subsection(); @@ -79,158 +52,115 @@ namespace Parameters void - Solver::declare_parameters(ParameterHandler &prm) + Solver::add_output_parameters(ParameterHandler &prm) { - prm.enter_subsection("Linear solver"); + prm.enter_subsection("Solver"); { - prm.declare_entry("Solver type", - "Direct", - Patterns::Selection("CG|Direct"), - "Linear solver: CG or Direct"); + prm.add_parameter("Solver type", + type_lin, + "Linear solver: CG or Direct", + Patterns::Selection("CG|Direct")); - prm.declare_entry("Residual", - "1e-6", - Patterns::Double(0.0), - "Linear solver residual (scaled by residual norm)"); + prm.add_parameter("Residual", + tol_lin, + "Linear solver residual (scaled by residual norm)", + Patterns::Double(0.0)); - prm.declare_entry( + prm.add_parameter( "Max iteration multiplier", - "1", - Patterns::Double(0.0), - "Linear solver iterations (multiples of the system matrix size)"); - - prm.declare_entry("Max iterations Newton-Raphson", - "10", - Patterns::Integer(0), - "Number of Newton-Raphson iterations allowed"); - - prm.declare_entry("Tolerance force", - "1.0e-9", - Patterns::Double(0.0), - "Force residual tolerance"); - - prm.declare_entry("Tolerance displacement", - "1.0e-6", - Patterns::Double(0.0), - "Displacement error tolerance"); - } - prm.leave_subsection(); - } - - - void - Solver::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Solver"); - { - type_lin = prm.get("Solver type"); - tol_lin = prm.get_double("Residual"); - max_iterations_lin = prm.get_double("Max iteration multiplier"); - - max_iterations_NR = prm.get_integer("Max iterations Newton-Raphson"); - tol_f = prm.get_double("Tolerance force"); - tol_u = prm.get_double("Tolerance displacement"); + max_iterations_lin, + "Linear solver iterations (multiples of the system matrix size)", + Patterns::Double(0.0)); + + prm.add_parameter("Max iterations Newton-Raphson", + max_iterations_NR, + "Number of Newton-Raphson iterations allowed", + Patterns::Integer(0)); + + prm.add_parameter("Tolerance force", + tol_f, + "Force residual tolerance", + Patterns::Double(0.0)); + + prm.add_parameter("Tolerance displacement", + tol_u, + "Displacement error tolerance", + Patterns::Double(0.0)); } prm.leave_subsection(); } void - Discretization::declare_parameters(ParameterHandler &prm) + Discretization::add_output_parameters(ParameterHandler &prm) { prm.enter_subsection("Discretization"); { - prm.declare_entry("Polynomial degree", - "3", - Patterns::Integer(0), - "Polynomial degree of the FE system"); - - prm.declare_entry("theta", - "0.5", - Patterns::Double(0, 1), - "Time integration scheme"); - - prm.declare_entry("beta", - "0.25", - Patterns::Double(0, 0.5), - "Newmark beta"); - - prm.declare_entry("gamma", - "0.5", - Patterns::Double(0, 1), - "Newmark gamma"); - } - prm.leave_subsection(); - } - - void - Discretization::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("Discretization"); - { - poly_degree = prm.get_integer("Polynomial degree"); - theta = prm.get_double("theta"); - beta = prm.get_double("beta"); - gamma = prm.get_double("gamma"); + prm.add_parameter("Polynomial degree", + poly_degree, + "Polynomial degree of the FE system", + Patterns::Integer(0)); + + prm.add_parameter("theta", + theta, + "Time integration scheme", + Patterns::Double(0, 1)); + + prm.add_parameter("beta", beta, "Newmark beta", Patterns::Double(0, 0.5)); + + prm.add_parameter("gamma", + gamma, + "Newmark gamma", + Patterns::Double(0, 1)); } prm.leave_subsection(); } void - PreciceAdapterConfiguration::declare_parameters(ParameterHandler &prm) + PreciceAdapterConfiguration::add_output_parameters(ParameterHandler &prm) { prm.enter_subsection("precice configuration"); { - prm.declare_entry("Scenario", - "FSI3", - Patterns::Selection("FSI3|PF"), - "Cases: FSI3 or PF for perpendicular flap"); - prm.declare_entry("precice config-file", - "precice-config.xml", - Patterns::Anything(), - "Name of the precice configuration file"); - prm.declare_entry( + prm.add_parameter("Scenario", + scenario, + "Cases: FSI3 or PF for perpendicular flap", + Patterns::Selection("FSI3|PF")); + + prm.add_parameter("precice config-file", + config_file, + "Name of the precice configuration file", + Patterns::Anything()); + + prm.add_parameter( "Participant name", - "dealiisolver", - Patterns::Anything(), - "Name of the participant in the precice-config.xml file"); - prm.declare_entry( + participant_name, + "Name of the participant in the precice-config.xml file", + Patterns::Anything()); + + prm.add_parameter( "Mesh name", - "dealii-mesh", - Patterns::Anything(), - "Name of the coupling mesh in the precice-config.xml file"); - prm.declare_entry("Read data name", - "received-data", - Patterns::Anything(), - "Name of the read data in the precice-config.xml file"); - prm.declare_entry( - "Write data name", - "calculated-data", - Patterns::Anything(), - "Name of the write data in the precice-config.xml file"); - prm.declare_entry("Flap location", - "0.0", - Patterns::Double(-3, 3), - "PF x-location"); + mesh_name, + "Name of the coupling mesh in the precice-config.xml file", + Patterns::Anything()); + + prm.add_parameter("Read data name", + read_data_name, + "Name of the read data in the precice-config.xml file", + Patterns::Anything()); + + prm.add_parameter("Write data name", + write_data_name, + "Name of the write data in the precice-config.xml file", + Patterns::Anything()); + + prm.add_parameter("Flap location", + flap_location, + "PF x-location", + Patterns::Double(-3, 3)); } prm.leave_subsection(); - } - void - PreciceAdapterConfiguration::parse_parameters(ParameterHandler &prm) - { - prm.enter_subsection("precice configuration"); - { - scenario = prm.get("Scenario"); - config_file = prm.get("precice config-file"); - participant_name = prm.get("Participant name"); - mesh_name = prm.get("Mesh name"); - read_data_name = prm.get("Read data name"); - write_data_name = prm.get("Write data name"); - flap_location = prm.get_double("Flap location"); - } - prm.leave_subsection(); // Look at the specific type of read data if ((read_data_name.find("Stress") == 0)) data_consistent = true; @@ -243,35 +173,21 @@ namespace Parameters "Unknown read data type. Please use 'Force' or 'Stress' in the read data naming.")); } + AllParameters::AllParameters(const std::string &input_file) { ParameterHandler prm; - declare_parameters(prm); + + Solver::add_output_parameters(prm); + Discretization::add_output_parameters(prm); + System::add_output_parameters(prm); + Time::add_output_parameters(prm); + PreciceAdapterConfiguration::add_output_parameters(prm); + prm.parse_input(input_file); - parse_parameters(prm); // Optional, if we want to print all parameters in the beginning of the // simulation // prm.print_parameters(std::cout,ParameterHandler::Text); } - - void - AllParameters::declare_parameters(ParameterHandler &prm) - { - Solver::declare_parameters(prm); - Discretization::declare_parameters(prm); - System::declare_parameters(prm); - Time::declare_parameters(prm); - PreciceAdapterConfiguration::declare_parameters(prm); - } - - void - AllParameters::parse_parameters(ParameterHandler &prm) - { - Solver::parse_parameters(prm); - Discretization::parse_parameters(prm); - System::parse_parameters(prm); - Time::parse_parameters(prm); - PreciceAdapterConfiguration::parse_parameters(prm); - } } // namespace Parameters diff --git a/include/adapter/parameters.h b/include/adapter/parameters.h index bdad65d..862c148 100644 --- a/include/adapter/parameters.h +++ b/include/adapter/parameters.h @@ -16,15 +16,12 @@ namespace Parameters */ struct Time { - double end_time; - double delta_t; - int output_interval; - - static void - declare_parameters(ParameterHandler &prm); + double end_time = 1; + double delta_t = 0.1; + int output_interval = 1; void - parse_parameters(ParameterHandler &prm); + add_output_parameters(ParameterHandler &prm); }; /** @@ -32,18 +29,14 @@ namespace Parameters */ struct System { - double nu; - double mu; - double lambda; - double rho; + double nu = 0.3; + double mu = 1538462; + double lambda = 2307692; + double rho = 1000; Tensor<1, 3, double> body_force; - - static void - declare_parameters(ParameterHandler &prm); - void - parse_parameters(ParameterHandler &prm); + add_output_parameters(ParameterHandler &prm); }; @@ -52,18 +45,15 @@ namespace Parameters */ struct Solver { - std::string type_lin; - double tol_lin; - double max_iterations_lin; - unsigned int max_iterations_NR; - double tol_f; - double tol_u; - - static void - declare_parameters(ParameterHandler &prm); + std::string type_lin = "Direct"; + double tol_lin = 1e-6; + double max_iterations_lin = 1; + unsigned int max_iterations_NR = 10; + double tol_f = 1e-9; + double tol_u = 1e-6; void - parse_parameters(ParameterHandler &prm); + add_output_parameters(ParameterHandler &prm); }; @@ -74,18 +64,15 @@ namespace Parameters */ struct Discretization { - unsigned int poly_degree; + unsigned int poly_degree = 3; // For the linear elastic model (theta-scheme) - double theta; + double theta = 0.5; // For the nonlinear elastic model (Newmark) - double beta; - double gamma ; - - static void - declare_parameters(ParameterHandler &prm); + double beta = 0.25; + double gamma = 0.5; void - parse_parameters(ParameterHandler &prm); + add_output_parameters(ParameterHandler &prm); }; @@ -96,20 +83,17 @@ namespace Parameters */ struct PreciceAdapterConfiguration { - std::string scenario; - std::string config_file; - std::string participant_name; - std::string mesh_name; - std::string read_data_name; - std::string write_data_name; - double flap_location; - bool data_consistent; - - static void - declare_parameters(ParameterHandler &prm); + std::string scenario = "FSI3"; + std::string config_file = "precice-config.xml"; + std::string participant_name = "dealiisolver"; + std::string mesh_name = "dealii-mesh"; + std::string read_data_name = "Stress"; + std::string write_data_name = "Displacement"; + double flap_location = 0.0; + bool data_consistent = true; void - parse_parameters(ParameterHandler &prm); + add_output_parameters(ParameterHandler &prm); }; @@ -121,12 +105,6 @@ namespace Parameters { AllParameters(const std::string &input_file); - - static void - declare_parameters(ParameterHandler &prm); - - void - parse_parameters(ParameterHandler &prm); }; } // namespace Parameters From bb7ed54b5101508d011338168aad05a3b7952f9c Mon Sep 17 00:00:00 2001 From: DavidSCN Date: Wed, 3 Mar 2021 10:52:49 +0100 Subject: [PATCH 05/11] Remove specific parameter files and add unified one --- dealii-precice.cc | 2 +- .../linear_elasticity.prm => parameters.prm | 29 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) rename source/linear_elasticity/linear_elasticity.prm => parameters.prm (76%) diff --git a/dealii-precice.cc b/dealii-precice.cc index e9ae8a4..fb45460 100644 --- a/dealii-precice.cc +++ b/dealii-precice.cc @@ -45,7 +45,7 @@ main(int argc, char **argv) if (argc > 1) parameter_file = argv[2]; else - parameter_file = "nonlinear_elasticity.prm"; + parameter_file = "parameters.prm"; // Extract case path for the output directory size_t pos = parameter_file.find_last_of("/"); diff --git a/source/linear_elasticity/linear_elasticity.prm b/parameters.prm similarity index 76% rename from source/linear_elasticity/linear_elasticity.prm rename to parameters.prm index 62edcbe..9cf3410 100644 --- a/source/linear_elasticity/linear_elasticity.prm +++ b/parameters.prm @@ -14,29 +14,25 @@ subsection Time end subsection Discretization - # Time integration scheme - # 0 = forward, 1 = backward - set theta = 0.5 - # Polynomial degree of the FE system set Polynomial degree = 3 end subsection System properties - # mu (shear modulus) - set mu = 0.5e6 + # Poisson's ratio + set Poisson's ratio = 0.4 - # lambda - set lambda = 2e6 + # Shear modulus + set Shear modulus = 0.5e6 - # density - set rho = 1000 + # Density + set rho = 1000 - # body forces x,y,z + # Body forces x,y,z set body forces = 0.0,0.0,0.0 end -subsection Linear solver +subsection Solver # Linear solver iterations (multiples of the system matrix size) set Max iteration multiplier = 1 @@ -45,6 +41,15 @@ subsection Linear solver # Linear solver: CG or Direct set Solver type = Direct + + # Number of Newton-Raphson iterations allowed + set Max iterations Newton-Raphson = 10 + + # Displacement error tolerance + set Tolerance displacement = 1.0e-6 + + # Force residual tolerance + set Tolerance force = 1.0e-9 end subsection precice configuration From d691fa22a5efa6c4812733d1e3308fdf9fb045c1 Mon Sep 17 00:00:00 2001 From: DavidSCN Date: Wed, 3 Mar 2021 12:02:47 +0100 Subject: [PATCH 06/11] Add parameter option for model selection --- dealii-precice.cc | 24 +++++++++++++----------- include/adapter/parameters.cc | 5 +++++ include/adapter/parameters.h | 1 + parameters.prm | 3 +++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/dealii-precice.cc b/dealii-precice.cc index fb45460..7749303 100644 --- a/dealii-precice.cc +++ b/dealii-precice.cc @@ -1,3 +1,5 @@ +#include + #include "source/linear_elasticity/include/linear_elasticity.h" #include "source/nonlinear_elasticity/include/nonlinear_elasticity.h" @@ -40,32 +42,32 @@ main(int argc, char **argv) << std::endl << std::endl; - - std::string parameter_file; - if (argc > 1) - parameter_file = argv[2]; - else - parameter_file = "parameters.prm"; + // Store the name of the parameter file + const std::string parameter_file = argc > 1 ? argv[1] : "parameters.prm"; // Extract case path for the output directory size_t pos = parameter_file.find_last_of("/"); std::string case_path = std::string::npos == pos ? "" : parameter_file.substr(0, pos + 1); - std::string solver_type = argv[1]; - // Dimension is determinded via cmake -DDIM - if (solver_type == "-nonlinear") // nonlinear + // Query solver type from the parameter file + ParameterHandler prm; + Parameters::Solver solver; + solver.add_output_parameters(prm); + prm.parse_input(case_path + parameter_file, "", true); + + if (solver.model == "neo-Hook") // nonlinear { Nonlinear_Elasticity::Solid solid(case_path); solid.run(); } - else if (solver_type == "-linear") // linear + else if (solver.model == "linear") // linear { Linear_Elasticity::ElastoDynamics elastic_solver(case_path); elastic_solver.run(); } else - AssertThrow(false, ExcMessage("Unknown solver specified. ")) + AssertThrow(false, ExcNotImplemented()) } catch (std::exception &exc) { diff --git a/include/adapter/parameters.cc b/include/adapter/parameters.cc index 97b24fa..088591d 100644 --- a/include/adapter/parameters.cc +++ b/include/adapter/parameters.cc @@ -56,6 +56,11 @@ namespace Parameters { prm.enter_subsection("Solver"); { + prm.add_parameter("Model", + model, + "Solid model to be used: linear or neo-Hook", + Patterns::Selection("linear|neo-Hook")); + prm.add_parameter("Solver type", type_lin, "Linear solver: CG or Direct", diff --git a/include/adapter/parameters.h b/include/adapter/parameters.h index 862c148..fc6c6f8 100644 --- a/include/adapter/parameters.h +++ b/include/adapter/parameters.h @@ -45,6 +45,7 @@ namespace Parameters */ struct Solver { + std::string model = "linear"; std::string type_lin = "Direct"; double tol_lin = 1e-6; double max_iterations_lin = 1; diff --git a/parameters.prm b/parameters.prm index 9cf3410..bcaf5e6 100644 --- a/parameters.prm +++ b/parameters.prm @@ -33,6 +33,9 @@ subsection System properties end subsection Solver + # Structural model to be used: linear or neo-Hook + set Model = linear + # Linear solver iterations (multiples of the system matrix size) set Max iteration multiplier = 1 From 8997e9fbca474d9b1740a278b62290947310d13f Mon Sep 17 00:00:00 2001 From: DavidSCN Date: Wed, 3 Mar 2021 12:11:33 +0100 Subject: [PATCH 07/11] Add an entry for the parameter file location --- dealii-precice.cc | 7 ++++--- include/adapter/parameters.cc | 2 +- source/linear_elasticity/include/linear_elasticity.h | 3 ++- source/linear_elasticity/linear_elasticity.cc | 5 +++-- source/nonlinear_elasticity/include/nonlinear_elasticity.h | 2 +- source/nonlinear_elasticity/nonlinear_elasticity.cc | 6 +++--- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/dealii-precice.cc b/dealii-precice.cc index 7749303..d646f7e 100644 --- a/dealii-precice.cc +++ b/dealii-precice.cc @@ -54,16 +54,17 @@ main(int argc, char **argv) ParameterHandler prm; Parameters::Solver solver; solver.add_output_parameters(prm); - prm.parse_input(case_path + parameter_file, "", true); + prm.parse_input(parameter_file, "", true); if (solver.model == "neo-Hook") // nonlinear { - Nonlinear_Elasticity::Solid solid(case_path); + Nonlinear_Elasticity::Solid solid(case_path, parameter_file); solid.run(); } else if (solver.model == "linear") // linear { - Linear_Elasticity::ElastoDynamics elastic_solver(case_path); + Linear_Elasticity::ElastoDynamics elastic_solver(case_path, + parameter_file); elastic_solver.run(); } else diff --git a/include/adapter/parameters.cc b/include/adapter/parameters.cc index 088591d..37b52f3 100644 --- a/include/adapter/parameters.cc +++ b/include/adapter/parameters.cc @@ -58,7 +58,7 @@ namespace Parameters { prm.add_parameter("Model", model, - "Solid model to be used: linear or neo-Hook", + "Structural model to be used: linear or neo-Hook", Patterns::Selection("linear|neo-Hook")); prm.add_parameter("Solver type", diff --git a/source/linear_elasticity/include/linear_elasticity.h b/source/linear_elasticity/include/linear_elasticity.h index 78ac2b0..ae270fa 100644 --- a/source/linear_elasticity/include/linear_elasticity.h +++ b/source/linear_elasticity/include/linear_elasticity.h @@ -55,7 +55,8 @@ namespace Linear_Elasticity class ElastoDynamics { public: - ElastoDynamics(const std::string &case_path); + ElastoDynamics(const std::string &case_path, + const std::string ¶meter_file); ~ElastoDynamics(); // As usual in dealii, the run function covers the main time loop of the diff --git a/source/linear_elasticity/linear_elasticity.cc b/source/linear_elasticity/linear_elasticity.cc index 0120e1d..cca4a1a 100644 --- a/source/linear_elasticity/linear_elasticity.cc +++ b/source/linear_elasticity/linear_elasticity.cc @@ -52,8 +52,9 @@ namespace Linear_Elasticity // Constructor template - ElastoDynamics::ElastoDynamics(const std::string &case_path) - : parameters(case_path + "linear_elasticity.prm") + ElastoDynamics::ElastoDynamics(const std::string &case_path, + const std::string ¶meter_file) + : parameters(parameter_file) , interface_boundary_id(6) , dof_handler(triangulation) , fe(FE_Q(parameters.poly_degree), dim) diff --git a/source/nonlinear_elasticity/include/nonlinear_elasticity.h b/source/nonlinear_elasticity/include/nonlinear_elasticity.h index a4a1270..b354c8f 100644 --- a/source/nonlinear_elasticity/include/nonlinear_elasticity.h +++ b/source/nonlinear_elasticity/include/nonlinear_elasticity.h @@ -132,7 +132,7 @@ namespace Nonlinear_Elasticity class Solid { public: - Solid(const std::string &case_path); + Solid(const std::string &case_path, const std::string ¶meter_file); virtual ~Solid(); diff --git a/source/nonlinear_elasticity/nonlinear_elasticity.cc b/source/nonlinear_elasticity/nonlinear_elasticity.cc index 19ea161..46abc3b 100644 --- a/source/nonlinear_elasticity/nonlinear_elasticity.cc +++ b/source/nonlinear_elasticity/nonlinear_elasticity.cc @@ -60,9 +60,9 @@ namespace Nonlinear_Elasticity // Constructor initializes member variables and reads the parameter file template - Solid::Solid(const std::string &case_path) - : parameters( - Parameters::AllParameters(case_path + "nonlinear_elasticity.prm")) + Solid::Solid(const std::string &case_path, + const std::string ¶meter_file) + : parameters(Parameters::AllParameters(parameter_file)) , vol_reference(0.0) , vol_current(0.0) , triangulation(Triangulation::maximum_smoothing) From 5476c4925dcc1cff28ff5ca389ffa05951018f32 Mon Sep 17 00:00:00 2001 From: DavidSCN Date: Wed, 3 Mar 2021 12:15:56 +0100 Subject: [PATCH 08/11] Fix Hook Hooke typo --- dealii-precice.cc | 2 +- include/adapter/parameters.cc | 4 ++-- parameters.prm | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dealii-precice.cc b/dealii-precice.cc index d646f7e..5cf6e63 100644 --- a/dealii-precice.cc +++ b/dealii-precice.cc @@ -56,7 +56,7 @@ main(int argc, char **argv) solver.add_output_parameters(prm); prm.parse_input(parameter_file, "", true); - if (solver.model == "neo-Hook") // nonlinear + if (solver.model == "neo-Hooke") // nonlinear { Nonlinear_Elasticity::Solid solid(case_path, parameter_file); solid.run(); diff --git a/include/adapter/parameters.cc b/include/adapter/parameters.cc index 37b52f3..6a1c06e 100644 --- a/include/adapter/parameters.cc +++ b/include/adapter/parameters.cc @@ -58,8 +58,8 @@ namespace Parameters { prm.add_parameter("Model", model, - "Structural model to be used: linear or neo-Hook", - Patterns::Selection("linear|neo-Hook")); + "Structural model to be used: linear or neo-Hooke", + Patterns::Selection("linear|neo-Hooke")); prm.add_parameter("Solver type", type_lin, diff --git a/parameters.prm b/parameters.prm index bcaf5e6..1396b38 100644 --- a/parameters.prm +++ b/parameters.prm @@ -33,7 +33,7 @@ subsection System properties end subsection Solver - # Structural model to be used: linear or neo-Hook + # Structural model to be used: linear or neo-Hooke set Model = linear # Linear solver iterations (multiples of the system matrix size) From 81363a6649c1f8fb95c5a093725c14497ce58d91 Mon Sep 17 00:00:00 2001 From: DavidSCN Date: Sun, 21 Mar 2021 14:16:30 +0100 Subject: [PATCH 09/11] Apply suggestions from code review --- CMakeLists.txt | 2 +- README.md | 6 +-- dealii-precice.cc => elasticity.cc | 2 +- include/adapter/parameters.cc | 46 +++++++++++-------- parameters.prm | 21 +++++---- source/linear_elasticity/linear_elasticity.cc | 2 +- 6 files changed, 44 insertions(+), 35 deletions(-) rename dealii-precice.cc => elasticity.cc (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd8f940..0cbbdbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ ENDIF() ADD_DEFINITIONS(-DDIM=${DIM}) # Set the target and the target source -SET( TARGET "dealii-precice" ) +SET( TARGET "elasticity" ) SET( TARGET_SRC ${TARGET}.cc include/adapter/parameters.cc) DEAL_II_INITIALIZE_CACHED_VARIABLES() diff --git a/README.md b/README.md index a559ae7..64c320b 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ Coupled structural solvers written with the C++ finite element library deal.II: -- `linear_elasticity` contains a linear-elastic solver based on the [step-8 tutorial program](https://www.dealii.org/9.2.0/doxygen/deal.II/step_8.html) of deal.II -- `nonlinear_elasticity` contains a nonlinear elastic solver, which builds on previous work of Jean-Paul Pelteret and Andrew McBride in their deal.II code gallery program '[Quasi-Static Finite-Strain Compressible Elasticity](https://www.dealii.org/9.0.0/doxygen/deal.II/code_gallery_Quasi_static_Finite_strain_Compressible_Elasticity.html).' This solver supports shared-memory parallelization. +- `source/linear_elasticity` contains a linear-elastic solver based on the [step-8 tutorial program](https://www.dealii.org/9.2.0/doxygen/deal.II/step_8.html) of deal.II +- `source/nonlinear_elasticity` contains a nonlinear elastic solver, which builds on previous work of Jean-Paul Pelteret and Andrew McBride in their deal.II code gallery program '[Quasi-Static Finite-Strain Compressible Elasticity](https://www.dealii.org/9.0.0/doxygen/deal.II/code_gallery_Quasi_static_Finite_strain_Compressible_Elasticity.html).' This solver supports shared-memory parallelization. -Applied coupling functionalities have been separated and can be found in the `adapter` directory. +Applied coupling functionalities have been separated and can be found in the `include/adapter` directory. ## Start here Our [wiki](https://github.com/precice/dealii-adapter/wiki) will help you start. If you are missing something, [let us know](https://www.precice.org/resources/#contact). diff --git a/dealii-precice.cc b/elasticity.cc similarity index 98% rename from dealii-precice.cc rename to elasticity.cc index 5cf6e63..006cdef 100644 --- a/dealii-precice.cc +++ b/elasticity.cc @@ -56,7 +56,7 @@ main(int argc, char **argv) solver.add_output_parameters(prm); prm.parse_input(parameter_file, "", true); - if (solver.model == "neo-Hooke") // nonlinear + if (solver.model == "neo-Hookean") // nonlinear { Nonlinear_Elasticity::Solid solid(case_path, parameter_file); solid.run(); diff --git a/include/adapter/parameters.cc b/include/adapter/parameters.cc index 6a1c06e..bea72b0 100644 --- a/include/adapter/parameters.cc +++ b/include/adapter/parameters.cc @@ -58,39 +58,43 @@ namespace Parameters { prm.add_parameter("Model", model, - "Structural model to be used: linear or neo-Hooke", - Patterns::Selection("linear|neo-Hooke")); + "Structural model to be used: linear or neo-Hookean", + Patterns::Selection("linear|neo-Hookean")); prm.add_parameter("Solver type", type_lin, "Linear solver: CG or Direct", Patterns::Selection("CG|Direct")); - prm.add_parameter("Residual", - tol_lin, - "Linear solver residual (scaled by residual norm)", - Patterns::Double(0.0)); + prm.add_parameter( + "Residual", + tol_lin, + "CG solver residual (multiplied by residual norm, ignored if Model == linear)", + Patterns::Double(0.0)); prm.add_parameter( "Max iteration multiplier", max_iterations_lin, - "Linear solver iterations (multiples of the system matrix size)", + "Max CG solver iterations (multiples of the system matrix size)", Patterns::Double(0.0)); - prm.add_parameter("Max iterations Newton-Raphson", - max_iterations_NR, - "Number of Newton-Raphson iterations allowed", - Patterns::Integer(0)); + prm.add_parameter( + "Max iterations Newton-Raphson", + max_iterations_NR, + "Number of Newton-Raphson iterations allowed (ignored if Model == linear)", + Patterns::Integer(0)); - prm.add_parameter("Tolerance force", - tol_f, - "Force residual tolerance", - Patterns::Double(0.0)); + prm.add_parameter( + "Tolerance force", + tol_f, + "Force residual tolerance for non-linear iteration (ignored if Model == linear)", + Patterns::Double(0.0)); - prm.add_parameter("Tolerance displacement", - tol_u, - "Displacement error tolerance", - Patterns::Double(0.0)); + prm.add_parameter( + "Tolerance displacement", + tol_u, + "Displacement error tolerance for non-linear iteration (ignored if Model == linear)", + Patterns::Double(0.0)); } prm.leave_subsection(); } @@ -191,6 +195,10 @@ namespace Parameters prm.parse_input(input_file); + AssertThrow((data_consistent && model == "neo-Hookean") || + model == "linear", + ExcNotImplemented()); + // Optional, if we want to print all parameters in the beginning of the // simulation // prm.print_parameters(std::cout,ParameterHandler::Text); diff --git a/parameters.prm b/parameters.prm index 1396b38..3485920 100644 --- a/parameters.prm +++ b/parameters.prm @@ -33,25 +33,26 @@ subsection System properties end subsection Solver - # Structural model to be used: linear or neo-Hooke + # Structural model to be used: linear or neo-Hookean set Model = linear - # Linear solver iterations (multiples of the system matrix size) + # Linear solver: CG or Direct + set Solver type = Direct + + # Max CG solver iterations (multiples of the system matrix size) + # In 2-d, this value is best set at 2. In 3-d, a value of 1 work fine. set Max iteration multiplier = 1 - # Linear solver residual (scaled by residual norm) + # Absolute CG solver residual (multiplied by residual norm, ignored if Model == linear) set Residual = 1e-6 - # Linear solver: CG or Direct - set Solver type = Direct - - # Number of Newton-Raphson iterations allowed + # Number of Newton-Raphson iterations allowed (ignored if Model == linear) set Max iterations Newton-Raphson = 10 - # Displacement error tolerance + # Relative displacement error tolerance for non-linear iteration (ignored if Model == linear) set Tolerance displacement = 1.0e-6 - # Force residual tolerance + # Relative force residual tolerance for non-linear iteration (ignored if Model == linear) set Tolerance force = 1.0e-9 end @@ -66,7 +67,7 @@ subsection precice configuration set Participant name = Solid # Name of the coupling mesh in the precice-config.xml file - set Mesh name = Solid_mesh + set Mesh name = Solid-Mesh # Name of the read data in the precice-config.xml file set Read data name = Stress diff --git a/source/linear_elasticity/linear_elasticity.cc b/source/linear_elasticity/linear_elasticity.cc index cca4a1a..1c7dfc8 100644 --- a/source/linear_elasticity/linear_elasticity.cc +++ b/source/linear_elasticity/linear_elasticity.cc @@ -541,7 +541,7 @@ namespace Linear_Elasticity const int solver_its = system_matrix.m() * parameters.max_iterations_lin; - const double tol_sol = parameters.tol_lin * system_rhs.l2_norm(); + const double tol_sol = 1.e-10; SolverControl solver_control(solver_its, tol_sol); GrowingVectorMemory<> GVM; From 005535ac7962c8352ff61e5ab81cb310ba08bd85 Mon Sep 17 00:00:00 2001 From: DavidSCN Date: Sun, 21 Mar 2021 14:47:22 +0100 Subject: [PATCH 10/11] Fix 'Force' data check for non-linear model --- include/adapter/parameters.cc | 24 ++++++++----------- .../nonlinear_elasticity.cc | 8 ++++++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/adapter/parameters.cc b/include/adapter/parameters.cc index bea72b0..dc73797 100644 --- a/include/adapter/parameters.cc +++ b/include/adapter/parameters.cc @@ -169,17 +169,6 @@ namespace Parameters Patterns::Double(-3, 3)); } prm.leave_subsection(); - - // Look at the specific type of read data - if ((read_data_name.find("Stress") == 0)) - data_consistent = true; - else if ((read_data_name.find("Force") == 0)) - data_consistent = false; - else - AssertThrow( - false, - ExcMessage( - "Unknown read data type. Please use 'Force' or 'Stress' in the read data naming.")); } @@ -195,9 +184,16 @@ namespace Parameters prm.parse_input(input_file); - AssertThrow((data_consistent && model == "neo-Hookean") || - model == "linear", - ExcNotImplemented()); + // Look at the specific type of read data + if ((read_data_name.find("Stress") == 0)) + data_consistent = true; + else if ((read_data_name.find("Force") == 0)) + data_consistent = false; + else + AssertThrow( + false, + ExcMessage( + "Unknown read data type. Please use 'Force' or 'Stress' in the read data naming.")); // Optional, if we want to print all parameters in the beginning of the // simulation diff --git a/source/nonlinear_elasticity/nonlinear_elasticity.cc b/source/nonlinear_elasticity/nonlinear_elasticity.cc index 46abc3b..5821989 100644 --- a/source/nonlinear_elasticity/nonlinear_elasticity.cc +++ b/source/nonlinear_elasticity/nonlinear_elasticity.cc @@ -82,7 +82,13 @@ namespace Nonlinear_Elasticity , timer(std::cout, TimerOutput::summary, TimerOutput::wall_times) , time(parameters.end_time, parameters.delta_t) , adapter(parameters, boundary_interface_id) - {} + { + AssertThrow( + parameters.data_consistent, + ExcMessage( + "The neo-Hookean solid doesn't support 'Force' data reading. Please switch to 'Stress' " + "data on the Fluid side or use the linear model of the solid solver")); + } // Destructor clears the DoFHandler template From 54893cc98a1a9528a9b83077db1140426ebeaaa8 Mon Sep 17 00:00:00 2001 From: DavidSCN Date: Mon, 22 Mar 2021 08:30:39 +0100 Subject: [PATCH 11/11] Enfore compatibility to tutorial parameter file --- parameters.prm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parameters.prm b/parameters.prm index 3485920..c10c444 100644 --- a/parameters.prm +++ b/parameters.prm @@ -40,7 +40,7 @@ subsection Solver set Solver type = Direct # Max CG solver iterations (multiples of the system matrix size) - # In 2-d, this value is best set at 2. In 3-d, a value of 1 work fine. + # In 2D, this value is best set at 2. In 3D, a value of 1 works fine. set Max iteration multiplier = 1 # Absolute CG solver residual (multiplied by residual norm, ignored if Model == linear)