KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
simple_mortar_mapper_wrapper_process.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Vicente Mataix Ferrandiz
11 //
12 
13 #pragma once
14 
15 // System includes
16 
17 // External includes
18 
19 // Project includes
21 
22 namespace Kratos
23 {
26 
30 
32  using SizeType = std::size_t;
33 
37 
41 
45 
53  : public Process
54 {
55 public:
58 
61 
64 
67 
70 
73 
76 
78  using IndexType = std::size_t;
79 
83 
93  ModelPart& rOriginModelPart,
94  ModelPart& rDestinationModelPart,
95  Parameters ThisParameters = Parameters(R"({})" ),
96  LinearSolverType::Pointer pThisLinearSolver = nullptr
97  )
98  {
99  // The default parameters
100  const Parameters default_parameters = GetDefaultParameters();
101  const bool origin_are_conditions_is_defined = ThisParameters.Has("origin_are_conditions");
102  const bool destination_are_conditions_is_defined = ThisParameters.Has("destination_are_conditions");
103  ThisParameters.ValidateAndAssignDefaults(default_parameters);
104 
105  // Automatic detect the entities
106  if (!origin_are_conditions_is_defined) {
107  if (rOriginModelPart.NumberOfElements() > 0) {
108  ThisParameters["origin_are_conditions"].SetBool(false);
109  KRATOS_WARNING("SimpleMortarMapperProcessWrapper") << "\'origin_are_conditions\' changed to \'False\'. Mapping from elements." << std::endl;
110  } else if (rOriginModelPart.NumberOfConditions() == 0) {
111  KRATOS_ERROR << "No conditions defined on origin model part" << std::endl;
112  }
113  }
114  if (!destination_are_conditions_is_defined) {
115  if (rDestinationModelPart.NumberOfElements() > 0) {
116  ThisParameters["destination_are_conditions"].SetBool(false);
117  KRATOS_WARNING("SimpleMortarMapperProcessWrapper") << "\'destination_are_conditions\' changed to \'False\'. Mapping from elements." << std::endl;
118  } else if (rDestinationModelPart.NumberOfConditions() == 0) {
119  KRATOS_ERROR << "No conditions defined on destination model part" << std::endl;
120  }
121  }
122 
123  // The condition iterators
124  auto& r_geometry_origin = ThisParameters["origin_are_conditions"].GetBool() ? rOriginModelPart.Conditions().begin()->GetGeometry() : rOriginModelPart.Elements().begin()->GetGeometry();
125  auto& r_geometry_destination = ThisParameters["destination_are_conditions"].GetBool() ? rDestinationModelPart.Conditions().begin()->GetGeometry() : rDestinationModelPart.Elements().begin()->GetGeometry();
126 
127  // The dimensions
128  const SizeType dimension = r_geometry_origin.WorkingSpaceDimension();
129  const SizeType size_1 = r_geometry_origin.size();
130  const SizeType size_2 = r_geometry_destination.size();
131 
132  // The variable names
133  const std::string& r_origin_variable_name = ThisParameters["origin_variable"].GetString();
134  const std::string& r_destination_variable_name = ThisParameters["destination_variable"].GetString();
135 
136  bool double_variable = true;
137  if(KratosComponents<Variable<double>>::Has(r_origin_variable_name)) {
138  if (r_destination_variable_name != "" && !(KratosComponents<Variable<double>>::Has(r_destination_variable_name))) {
139  KRATOS_ERROR << "The destination variable is not the same type (double) as the origin" << std::endl;
140  }
141  } else if (KratosComponents< Variable< array_1d< double, 3> > >::Has(r_origin_variable_name)) {
142  double_variable = false;
143  if (r_destination_variable_name != "" && !(KratosComponents<Variable<array_1d< double, 3>>>::Has(r_destination_variable_name)))
144  KRATOS_ERROR << "The destination variable is not the same type (array_1d< double, 3>) as the origin" << std::endl;
145  } else {
146  KRATOS_ERROR << "The types of the variables are not supported array_1d< double, 3> or double" << std::endl;
147  }
148 
149  // Creating the mapper
150  if (dimension == 2) {
151  // 2D
152  if (double_variable) {
153  mpMapperProcess = Kratos::make_shared<SimpleMortarMapperProcess<2, 2, Variable<double>>>(rOriginModelPart, rDestinationModelPart, ThisParameters, pThisLinearSolver);
154  } else {
155  mpMapperProcess = Kratos::make_shared<SimpleMortarMapperProcess<2, 2, Variable<array_1d< double, 3>>>>(rOriginModelPart, rDestinationModelPart, ThisParameters, pThisLinearSolver);
156  }
157  } else {
158  // 3D
159  if (size_1 == 3 && size_2 == 3) {
160  if (double_variable) {
161  mpMapperProcess = Kratos::make_shared<SimpleMortarMapperProcess<3, 3, Variable<double>>>(rOriginModelPart, rDestinationModelPart, ThisParameters, pThisLinearSolver);
162  } else {
163  mpMapperProcess = Kratos::make_shared<SimpleMortarMapperProcess<3, 3, Variable<array_1d< double, 3>>>>(rOriginModelPart, rDestinationModelPart, ThisParameters, pThisLinearSolver);
164  }
165  } else if (size_1 == 4 && size_2 == 4) {
166  if (double_variable) {
167  mpMapperProcess = Kratos::make_shared<SimpleMortarMapperProcess<3, 4, Variable<double>>>(rOriginModelPart, rDestinationModelPart, ThisParameters, pThisLinearSolver);
168  } else {
169  mpMapperProcess = Kratos::make_shared<SimpleMortarMapperProcess<3, 4, Variable<array_1d< double, 3>>>>(rOriginModelPart, rDestinationModelPart, ThisParameters, pThisLinearSolver);
170  }
171  } else if (size_1 == 4 && size_2 == 3) {
172  if (double_variable) {
173  mpMapperProcess = Kratos::make_shared<SimpleMortarMapperProcess<3, 3, Variable<double>, 4>>(rOriginModelPart, rDestinationModelPart, ThisParameters, pThisLinearSolver);
174  } else {
175  mpMapperProcess = Kratos::make_shared<SimpleMortarMapperProcess<3, 3, Variable<array_1d< double, 3>>, 4>>(rOriginModelPart, rDestinationModelPart, ThisParameters, pThisLinearSolver);
176  }
177  } else if (size_1 == 3 && size_2 == 4) {
178  if (double_variable) {
179  mpMapperProcess = Kratos::make_shared<SimpleMortarMapperProcess<3, 4, Variable<double>, 3>>(rOriginModelPart, rDestinationModelPart, ThisParameters, pThisLinearSolver);
180  } else {
181  mpMapperProcess = Kratos::make_shared<SimpleMortarMapperProcess<3, 4, Variable<array_1d< double, 3>>, 3>>(rOriginModelPart, rDestinationModelPart, ThisParameters, pThisLinearSolver);
182  }
183  } else {
184  KRATOS_ERROR << "Combination of dimensions and sizes not compatible. Dimension: " << dimension << " Size Origin: " << size_1 << " Size Destination: " << size_2 << std::endl;
185  }
186  }
187  }
188 
190  ~SimpleMortarMapperProcessWrapper() override = default;
191 
195 
199 
203 
207 
211 
212  void operator()()
213  {
214  Execute();
215  }
216 
220 
224  void Execute() override
225  {
226  mpMapperProcess->Execute();
227  }
228 
233  {
234  mpMapperProcess->ExecuteInitializeSolutionStep();
235  }
236 
240  const Parameters GetDefaultParameters() const override
241  {
242  const Parameters default_parameters = Parameters(R"(
243  {
244  "echo_level" : 0,
245  "consider_tessellation" : false,
246  "using_average_nodal_normal" : true,
247  "discontinuous_interface" : false,
248  "discontinous_interface_factor" : 1.0e-4,
249  "absolute_convergence_tolerance" : 1.0e-9,
250  "relative_convergence_tolerance" : 1.0e-4,
251  "max_number_iterations" : 10,
252  "integration_order" : 2,
253  "distance_threshold" : 1.0e24,
254  "zero_tolerance_factor" : 1.0e0,
255  "remove_isolated_conditions" : false,
256  "mapping_coefficient" : 1.0e0,
257  "origin_variable" : "TEMPERATURE",
258  "destination_variable" : "",
259  "origin_variable_historical" : true,
260  "origin_are_conditions" : true,
261  "destination_variable_historical" : true,
262  "destination_are_conditions" : true,
263  "update_interface" : true,
264  "search_parameters" : {
265  "allocation_size" : 1000,
266  "bucket_size" : 4,
267  "search_factor" : 3.5
268  }
269  })" );
270 
271  return default_parameters;
272  }
273 
277 
281 
285 
287  std::string Info() const override
288  {
289  return "SimpleMortarMapperProcessWrapper";
290  }
291 
293  void PrintInfo(std::ostream& rOStream) const override
294  {
295  rOStream << "SimpleMortarMapperProcessWrapper";
296  }
297 
299  void PrintData(std::ostream& rOStream) const override
300  {
301  }
302 
306 
308 private:
314 
315  Process::Pointer mpMapperProcess = nullptr;
316 
320 
324 
328 
332 
336 
339 
341 };// class SimpleMortarMapperProcessWrapper
345 
349 
351 
352 } // namespace Kratos.
std::size_t IndexType
Definition: flags.h:74
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
Base class for all the linear solvers in Kratos.
Definition: linear_solver.h:65
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
SizeType NumberOfConditions(IndexType ThisIndex=0) const
Definition: model_part.h:1218
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
The base class for all processes in Kratos.
Definition: process.h:49
This class wraps automatically the different types mof mappers.
Definition: simple_mortar_mapper_wrapper_process.h:54
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: simple_mortar_mapper_wrapper_process.h:224
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: simple_mortar_mapper_wrapper_process.h:293
typename SparseSpaceType::MatrixType MatrixType
Type definition for matrix.
Definition: simple_mortar_mapper_wrapper_process.h:69
typename SparseSpaceType::VectorType VectorType
Type definition for vector.
Definition: simple_mortar_mapper_wrapper_process.h:72
std::string Info() const override
Turn back information as a string.
Definition: simple_mortar_mapper_wrapper_process.h:287
KRATOS_CLASS_POINTER_DEFINITION(SimpleMortarMapperProcessWrapper)
Pointer definition of SimpleMortarMapperProcessWrapper.
void operator()()
Definition: simple_mortar_mapper_wrapper_process.h:212
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: simple_mortar_mapper_wrapper_process.h:299
void ExecuteInitializeSolutionStep() override
Definition: simple_mortar_mapper_wrapper_process.h:232
~SimpleMortarMapperProcessWrapper() override=default
Destructor.
const Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: simple_mortar_mapper_wrapper_process.h:240
SimpleMortarMapperProcessWrapper(ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, Parameters ThisParameters=Parameters(R"({})"), LinearSolverType::Pointer pThisLinearSolver=nullptr)
Default constructor.
Definition: simple_mortar_mapper_wrapper_process.h:92
A class template for handling data types, matrices, and vectors in a Ublas space.
Definition: ublas_space.h:121
TMatrixType MatrixType
The matrix type considered.
Definition: ublas_space.h:133
TVectorType VectorType
The vector type considered.
Definition: ublas_space.h:136
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_WARNING(label)
Definition: logger.h:265
bool Has(const std::string &ModelerName)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:24
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123