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.
dam_bofang_condition_temperature_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: Lorenzo Gracia
11 //
12 //
13 
14 #if !defined(KRATOS_DAM_BOFANG_CONDITION_TEMPERATURE_PROCESS)
15 #define KRATOS_DAM_BOFANG_CONDITION_TEMPERATURE_PROCESS
16 
17 #include <cmath>
18 
19 // Project includes
20 #include "includes/kratos_flags.h"
22 #include "processes/process.h"
23 
24 // Application includes
26 
27 namespace Kratos
28 {
29 
31 {
32 
33  public:
35 
37 
38  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
39 
42  Parameters &rParameters) : Process(Flags()), mrModelPart(rModelPart)
43  {
45 
46  //only include validation with c++11 since raw_literals do not exist in c++03
47  Parameters default_parameters(R"(
48  {
49  "model_part_name":"PLEASE_CHOOSE_MODEL_PART_NAME",
50  "variable_name": "PLEASE_PRESCRIBE_VARIABLE_NAME",
51  "is_fixed" : false,
52  "Gravity_Direction" : "Y",
53  "Reservoir_Bottom_Coordinate_in_Gravity_Direction" : 0.0,
54  "Surface_Temp" : 0.0,
55  "Bottom_Temp" : 0.0,
56  "Height_Dam" : 0.0,
57  "Temperature_Amplitude" : 0.0,
58  "Day_Ambient_Temp" : 1,
59  "Water_level" : 0.0,
60  "Water_level_Table" : 0,
61  "Month" : 1.0,
62  "Month_Table" : 0,
63  "interval":[
64  0.0,
65  0.0
66  ]
67  } )");
68 
69  // Some values need to be mandatorily prescribed since no meaningful default value exist. For this reason try accessing to them
70  // So that an error is thrown if they don't exist
71  rParameters["Reservoir_Bottom_Coordinate_in_Gravity_Direction"];
72  rParameters["variable_name"];
73  rParameters["model_part_name"];
74 
75  // Now validate agains defaults -- this also ensures no type mismatch
76  rParameters.ValidateAndAssignDefaults(default_parameters);
77 
78  mVariableName = rParameters["variable_name"].GetString();
79  mIsFixed = rParameters["is_fixed"].GetBool();
80  mGravityDirection = rParameters["Gravity_Direction"].GetString();
81  mReferenceCoordinate = rParameters["Reservoir_Bottom_Coordinate_in_Gravity_Direction"].GetDouble();
82  mSurfaceTemp = rParameters["Surface_Temp"].GetDouble();
83  mBottomTemp = rParameters["Bottom_Temp"].GetDouble();
84  mHeight = rParameters["Height_Dam"].GetDouble();
85  mAmplitude = rParameters["Temperature_Amplitude"].GetDouble();
86  mDay = rParameters["Day_Ambient_Temp"].GetInt();
87  mWaterLevel = rParameters["Water_level"].GetDouble();
88  mMonth = rParameters["Month"].GetDouble();
89  mFreq = 0.52323;
90 
91  mTimeUnitConverter = mrModelPart.GetProcessInfo()[TIME_UNIT_CONVERTER];
92  mTableIdWater = rParameters["Water_level_Table"].GetInt();
93  mTableIdMonth = rParameters["Month_Table"].GetInt();
94 
95  if (mTableIdWater != 0)
97 
98  if (mTableIdMonth != 0)
100 
101  KRATOS_CATCH("");
102  }
103 
105 
108 
109  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
110 
111  void Execute() override
112  {
113  }
114 
115  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
116 
117  void ExecuteInitialize() override
118  {
119 
120  KRATOS_TRY;
121 
123  const int nnodes = mrModelPart.GetMesh(0).Nodes().size();
124  int direction;
125 
126  if (mGravityDirection == "X")
127  direction = 0;
128  else if (mGravityDirection == "Y")
129  direction = 1;
130  else
131  direction = 2;
132 
133  if (nnodes != 0)
134  {
135  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.GetMesh(0).NodesBegin();
136 
137  #pragma omp parallel for
138  for (int i = 0; i < nnodes; i++)
139  {
140  ModelPart::NodesContainerType::iterator it = it_begin + i;
141 
142  double aux = mWaterLevel - it->Coordinates()[direction];
143  if (aux >= 0.0)
144  {
145  if (mIsFixed)
146  {
147  it->Fix(var);
148  }
149  double aux1 = ((mBottomTemp - (mSurfaceTemp * exp(-0.04 * mHeight))) / (1 - (exp(-0.04 * mHeight))));
150  double Temperature = (aux1 + ((mSurfaceTemp - aux1) * (exp(-0.04 * aux))) + (mAmplitude * (exp(-0.018 * aux)) * (cos(mFreq * (mMonth - (mDay / 30.0) - 2.15 + (1.30 * exp(-0.085 * aux)))))));
151 
152  it->FastGetSolutionStepValue(var) = Temperature;
153  }
154  }
155  }
156 
157  KRATOS_CATCH("");
158  }
159 
160  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
161 
163  {
164 
165  KRATOS_TRY;
166 
168 
169  // Getting the values of table in case that it exist
170  if (mTableIdWater != 0)
171  {
172  double time = mrModelPart.GetProcessInfo()[TIME];
174  mWaterLevel = mpTableWater->GetValue(time);
175  }
176 
177  if (mTableIdMonth != 0)
178  {
179  double time = mrModelPart.GetProcessInfo()[TIME];
181  mMonth = mpTableMonth->GetValue(time);
182  }
183 
184  const int nnodes = mrModelPart.GetMesh(0).Nodes().size();
185  int direction;
186 
187  if (mGravityDirection == "X")
188  direction = 0;
189  else if (mGravityDirection == "Y")
190  direction = 1;
191  else
192  direction = 2;
193 
194  if (nnodes != 0)
195  {
196  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.GetMesh(0).NodesBegin();
197 
198  #pragma omp parallel for
199  for (int i = 0; i < nnodes; i++)
200  {
201  ModelPart::NodesContainerType::iterator it = it_begin + i;
202 
203  double aux = mWaterLevel - it->Coordinates()[direction];
204  if (aux >= 0.0)
205  {
206  if (mIsFixed)
207  {
208  it->Fix(var);
209  }
210  double aux1 = ((mBottomTemp - (mSurfaceTemp * exp(-0.04 * mHeight))) / (1 - (exp(-0.04 * mHeight))));
211  double Temperature = (aux1 + ((mSurfaceTemp - aux1) * (exp(-0.04 * aux))) + (mAmplitude * (exp(-0.018 * aux)) * (cos(mFreq * (mMonth - (mDay / 30.0) - 2.15 + (1.30 * exp(-0.085 * aux)))))));
212 
213  it->FastGetSolutionStepValue(var) = Temperature;
214  }
215  }
216  }
217 
218  KRATOS_CATCH("");
219  }
220 
221  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
222 
224  {
225 
226  KRATOS_TRY;
227 
229 
230  const int nnodes = mrModelPart.GetMesh(0).Nodes().size();
231 
232  if (nnodes != 0)
233  {
234 
235  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.GetMesh(0).NodesBegin();
236 
237  #pragma omp parallel for
238  for (int i = 0; i < nnodes; i++)
239  {
240  ModelPart::NodesContainerType::iterator it = it_begin + i;
241  it->Free(var);
242  }
243  }
244 
245  KRATOS_CATCH("");
246  }
247 
249  std::string Info() const override
250  {
251  return "DamBofangConditionTemperatureProcess";
252  }
253 
255  void PrintInfo(std::ostream &rOStream) const override
256  {
257  rOStream << "DamBofangConditionTemperatureProcess";
258  }
259 
261  void PrintData(std::ostream &rOStream) const override
262  {
263  }
264 
266 
267  protected:
269 
271  std::string mVariableName;
272  std::string mGravityDirection;
273  bool mIsFixed;
275  double mSurfaceTemp;
276  double mBottomTemp;
277  double mHeight;
278  double mAmplitude;
279  int mDay;
280  double mMonth;
281  double mWaterLevel;
282  double mFreq;
284  TableType::Pointer mpTableWater;
285  TableType::Pointer mpTableMonth;
288 
289  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
290 
291  private:
294 
295 }; //Class
296 
298 inline std::istream &operator>>(std::istream &rIStream,
300 
302 inline std::ostream &operator<<(std::ostream &rOStream,
304 {
305  rThis.PrintInfo(rOStream);
306  rOStream << std::endl;
307  rThis.PrintData(rOStream);
308 
309  return rOStream;
310 }
311 
312 } /* namespace Kratos.*/
313 
314 #endif /* KRATOS_DAM_BOFANG_CONDITION_TEMPERATURE_PROCESS defined */
Definition: dam_bofang_condition_temperature_process.hpp:31
std::string Info() const override
Turn back information as a string.
Definition: dam_bofang_condition_temperature_process.hpp:249
virtual ~DamBofangConditionTemperatureProcess()
Destructor.
Definition: dam_bofang_condition_temperature_process.hpp:107
KRATOS_CLASS_POINTER_DEFINITION(DamBofangConditionTemperatureProcess)
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: dam_bofang_condition_temperature_process.hpp:261
double mWaterLevel
Definition: dam_bofang_condition_temperature_process.hpp:281
std::string mGravityDirection
Definition: dam_bofang_condition_temperature_process.hpp:272
double mSurfaceTemp
Definition: dam_bofang_condition_temperature_process.hpp:275
int mTableIdWater
Definition: dam_bofang_condition_temperature_process.hpp:286
DamBofangConditionTemperatureProcess(ModelPart &rModelPart, Parameters &rParameters)
Constructor.
Definition: dam_bofang_condition_temperature_process.hpp:41
TableType::Pointer mpTableMonth
Definition: dam_bofang_condition_temperature_process.hpp:285
void ExecuteInitializeSolutionStep() override
This function will be executed at every time step BEFORE performing the solve phase.
Definition: dam_bofang_condition_temperature_process.hpp:162
std::string mVariableName
Definition: dam_bofang_condition_temperature_process.hpp:271
int mDay
Definition: dam_bofang_condition_temperature_process.hpp:279
int mTableIdMonth
Definition: dam_bofang_condition_temperature_process.hpp:287
double mTimeUnitConverter
Definition: dam_bofang_condition_temperature_process.hpp:283
bool mIsFixed
Definition: dam_bofang_condition_temperature_process.hpp:273
double mAmplitude
Definition: dam_bofang_condition_temperature_process.hpp:278
void ExecuteInitialize() override
This function is designed for being called at the beginning of the computations right after reading t...
Definition: dam_bofang_condition_temperature_process.hpp:117
double mFreq
Definition: dam_bofang_condition_temperature_process.hpp:282
ModelPart & mrModelPart
Member Variables.
Definition: dam_bofang_condition_temperature_process.hpp:270
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: dam_bofang_condition_temperature_process.hpp:255
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: dam_bofang_condition_temperature_process.hpp:111
void ExecuteFinalizeSolutionStep() override
This function will be executed at every time step AFTER performing the solve phase.
Definition: dam_bofang_condition_temperature_process.hpp:223
double mHeight
Definition: dam_bofang_condition_temperature_process.hpp:277
double mReferenceCoordinate
Definition: dam_bofang_condition_temperature_process.hpp:274
TableType::Pointer mpTableWater
Definition: dam_bofang_condition_temperature_process.hpp:284
double mMonth
Definition: dam_bofang_condition_temperature_process.hpp:280
Table< double, double > TableType
Definition: dam_bofang_condition_temperature_process.hpp:36
double mBottomTemp
Definition: dam_bofang_condition_temperature_process.hpp:276
Definition: flags.h:58
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
NodesContainerType & Nodes()
Definition: mesh.h:346
NodeIterator NodesBegin()
Definition: mesh.h:326
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
TableType::Pointer pGetTable(IndexType TableId)
Definition: model_part.h:595
MeshType & GetMesh(IndexType ThisIndex=0)
Definition: model_part.h:1791
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
The base class for all processes in Kratos.
Definition: process.h:49
Definition: table.h:435
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
time
Definition: face_heat.py:85
float aux1
Definition: isotropic_damage_automatic_differentiation.py:239
int nnodes
Definition: sensitivityMatrix.py:24
integer i
Definition: TensorModule.f:17