Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify parameter interface for solid solver #51

Merged
merged 11 commits into from
Mar 22, 2021
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
29 changes: 16 additions & 13 deletions dealii-precice.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <adapter/parameters.h>

#include "source/linear_elasticity/include/linear_elasticity.h"
#include "source/nonlinear_elasticity/include/nonlinear_elasticity.h"

Expand Down Expand Up @@ -40,32 +42,33 @@ main(int argc, char **argv)
<< std::endl
<< std::endl;


std::string parameter_file;
if (argc > 1)
parameter_file = argv[2];
else
parameter_file = "nonlinear_elasticity.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(parameter_file, "", true);

if (solver.model == "neo-Hook") // nonlinear
{
Nonlinear_Elasticity::Solid<DIM> solid(case_path);
Nonlinear_Elasticity::Solid<DIM> solid(case_path, parameter_file);
solid.run();
}
else if (solver_type == "-linear") // linear
else if (solver.model == "linear") // linear
{
Linear_Elasticity::ElastoDynamics<DIM> elastic_solver(case_path);
Linear_Elasticity::ElastoDynamics<DIM> elastic_solver(case_path,
parameter_file);
elastic_solver.run();
}
else
AssertThrow(false, ExcMessage("Unknown solver specified. "))
AssertThrow(false, ExcNotImplemented())
}
catch (std::exception &exc)
{
Expand Down
198 changes: 198 additions & 0 deletions include/adapter/parameters.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
#include <adapter/parameters.h>

namespace Parameters
{
void
Time::add_output_parameters(ParameterHandler &prm)
{
prm.enter_subsection("Time");
{
prm.add_parameter("End time", end_time, "End time", Patterns::Double());

prm.add_parameter("Time step size",
delta_t,
"Time step size",
Patterns::Double());

prm.add_parameter("Output interval",
output_interval,
"Write results every x timesteps",
Patterns::Integer(0));
}
prm.leave_subsection();
}


void
System::add_output_parameters(ParameterHandler &prm)
{
prm.enter_subsection("System properties");
{
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();

lambda = 2 * mu * nu / (1 - 2 * nu);
}


void
Solver::add_output_parameters(ParameterHandler &prm)
{
prm.enter_subsection("Solver");
{
prm.add_parameter("Model",
model,
"Structural model to be used: linear or neo-Hook",
Patterns::Selection("linear|neo-Hook"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I added now an option here, where the user can select between the linear model and the neo-Hookean model. I hope this is intuitive enough, otherwise let me know.


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(
"Max iteration multiplier",
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::add_output_parameters(ParameterHandler &prm)
{
prm.enter_subsection("Discretization");
{
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::add_output_parameters(ParameterHandler &prm)
{
prm.enter_subsection("precice configuration");
{
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",
participant_name,
"Name of the participant in the precice-config.xml file",
Patterns::Anything());

prm.add_parameter(
"Mesh name",
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();

// 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;

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);

// Optional, if we want to print all parameters in the beginning of the
// simulation
// prm.print_parameters(std::cout,ParameterHandler::Text);
}
} // namespace Parameters
112 changes: 112 additions & 0 deletions include/adapter/parameters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#ifndef PARAMETERS_H
#define PARAMETERS_H

#include <deal.II/base/parameter_handler.h>

/**
* 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 = 1;
double delta_t = 0.1;
int output_interval = 1;

void
add_output_parameters(ParameterHandler &prm);
};

/**
* @brief The System struct keeps material properties and body force contributions
*/
struct System
{
double nu = 0.3;
double mu = 1538462;
double lambda = 2307692;
double rho = 1000;
Tensor<1, 3, double> body_force;

void
add_output_parameters(ParameterHandler &prm);
};


/**
* @brief LinearSolver: Specifies linear solver properties
*/
struct Solver
{
std::string model = "linear";
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
add_output_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 = 3;
// For the linear elastic model (theta-scheme)
double theta = 0.5;
// For the nonlinear elastic model (Newmark)
double beta = 0.25;
double gamma = 0.5;

void
add_output_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 = "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
add_output_parameters(ParameterHandler &prm);
};


struct AllParameters : public Solver,
public Discretization,
public System,
public Time,
public PreciceAdapterConfiguration

{
AllParameters(const std::string &input_file);
};
} // namespace Parameters

#endif // PARAMETERS_H
Loading