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.
set_parameter_field_process.hpp
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: Aron Noordam
11 //
12 
13 #pragma once
14 
15 // System includes
16 
17 // External includes
18 
19 // Project includes
20 #include "includes/define.h"
21 #include "processes/process.h"
22 #include "includes/model_part.h"
24 
27 namespace Kratos {
28 
31 
34 
35 
44  class KRATOS_API(GEO_MECHANICS_APPLICATION) SetParameterFieldProcess : public Process
45  {
46  public:
49 
50  using SizeType = std::size_t;
51 
56 
60 
62  const Parameters & rParameters);
63 
67 
71  void ExecuteInitialize() override;
72 
73 
77 
79  std::string Info() const override {
80  return "SetParameterFieldProcess";
81  }
83 
84  private:
87 
88  ModelPart& mrModelPart;
89  Parameters mParameters;
90 
91 
95 
102  template <typename T>
103  static void SetValueAtElement(Element & rElement, const Variable<T>&rVar, const T & Value)
104  {
105  Properties& r_prop = rElement.GetProperties();
106 
107  // Copies properties
108  Properties::Pointer p_new_prop = Kratos::make_shared<Properties>(r_prop);
109 
110  // Adds new properties to the element
111  p_new_prop->SetValue(rVar, Value);
112  rElement.SetProperties(p_new_prop);
113  }
114 
119  void SetParameterFieldUsingInputFunction(const Variable<double>&rVar);
120  void SetParameterFieldUsingInputFunction(const Variable<Vector>&rVar);
121 
126  void SetParameterFieldUsingParametersClass(const Variable<double>&rVar, const Parameters & rParameters);
127  void SetParameterFieldUsingParametersClass(const Variable<Vector>&rVar, const Parameters & rParameters);
128 
133  template <typename T>
134  void SetParameterFieldUsingJsonFile(const Variable<T>&rVar)
135  {
136  // Read json string in field parameters file, create Parameters
137  const std::string& field_file_name = mParameters["dataset_file_name"].GetString();
139  << "The parameter field file specified with name \"" << field_file_name << "\" does not exist!" << std::endl;
140 
141  std::ifstream ifs(field_file_name);
142  this->SetParameterFieldUsingParametersClass(rVar, Parameters{ ifs });
143  }
144 
149  template <typename T>
150  void SetParameterFieldUsingJsonString(const Variable<T>&rVar)
151  {
152  // get new data from the data set
153  const std::string& r_dataset = mParameters["dataset"].GetString();
154  Parameters new_data{ r_dataset };
155  this->SetParameterFieldUsingParametersClass(rVar, new_data);
156  }
157 
162  template <typename T>
163  void SetParameterFieldForVariableType(const Variable<T>&r_var)
164  {
165  if (mParameters["func_type"].GetString() == "input") {
166  this->SetParameterFieldUsingInputFunction(r_var);
167  }
168  else if (mParameters["func_type"].GetString() == "json_string") {
169  this->SetParameterFieldUsingJsonString(r_var);
170  }
171  else if (mParameters["func_type"].GetString() == "json_file") {
172  this->SetParameterFieldUsingJsonFile(r_var);
173  }
174  }
175 
176  std::vector<IndexType> GetVectorIndices() const;
177 
181 
183 
184  }; // Class SetParameterFieldProcess
185 
187 
188 } // namespace Kratos.
void ExecuteInitialize() override
Definition: periodic_interface_process.hpp:37
Base class for all Elements.
Definition: element.h:60
PropertiesType & GetProperties()
Definition: element.h:1024
void SetProperties(PropertiesType::Pointer pProperties)
Definition: element.h:1040
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
The base class for all processes in Kratos.
Definition: process.h:49
Properties encapsulates data shared by different Elements or Conditions. It can store any type of dat...
Definition: properties.h:69
Process to set a parameter field.
Definition: set_parameter_field_process.hpp:45
KRATOS_CLASS_POINTER_DEFINITION(SetParameterFieldProcess)
std::string Info() const override
Turn back information as a string.
Definition: set_parameter_field_process.hpp:79
std::size_t SizeType
Definition: set_parameter_field_process.hpp:50
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
bool exists(const std::string &rPath)
Definition: kratos_filesystem.cpp:27
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21