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_reservoir_monitoring_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_RESERVOIR_MONITORING_TEMPERATURE_PROCESS)
15 #define KRATOS_DAM_RESERVOIR_MONITORING_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  "Height_Dam" : 0.0,
55  "Ambient_temp" : 0.0,
56  "Ambient_temp_Table" : 0,
57  "Water_level" : 0.0,
58  "Water_level_Table" : 0,
59  "Z_Coord_1" : 0.0,
60  "Water_temp_1" : 0.0,
61  "Water_temp_Table_1" : 0,
62  "Z_Coord_2" : 0.0,
63  "Water_temp_2" : 0.0,
64  "Water_temp_Table_2" : 0,
65  "Z_Coord_3" : 0.0,
66  "Water_temp_3" : 0.0,
67  "Water_temp_Table_3" : 0,
68  "interval":[
69  0.0,
70  0.0
71  ]
72  } )");
73 
74  // Some values need to be mandatorily prescribed since no meaningful default value exist. For this reason try accessing to them
75  // So that an error is thrown if they don't exist
76  rParameters["Reservoir_Bottom_Coordinate_in_Gravity_Direction"];
77  rParameters["variable_name"];
78  rParameters["model_part_name"];
79 
80  // Now validate agains defaults -- this also ensures no type mismatch
81  rParameters.ValidateAndAssignDefaults(default_parameters);
82 
83  mVariableName = rParameters["variable_name"].GetString();
84  mIsFixed = rParameters["is_fixed"].GetBool();
85  mGravityDirection = rParameters["Gravity_Direction"].GetString();
86  mReferenceCoordinate = rParameters["Reservoir_Bottom_Coordinate_in_Gravity_Direction"].GetDouble();
87  mHeight = rParameters["Height_Dam"].GetDouble();
88  mAmbientTemp = rParameters["Ambient_temp"].GetDouble();
89  mWaterLevel = rParameters["Water_level"].GetDouble();
90  mZCoord1 = rParameters["Z_Coord_1"].GetDouble();
91  mWaterTemp1 = rParameters["Water_temp_1"].GetDouble();
92  mZCoord2 = rParameters["Z_Coord_2"].GetDouble();
93  mWaterTemp2 = rParameters["Water_temp_2"].GetDouble();
94  mZCoord3 = rParameters["Z_Coord_3"].GetDouble();
95  mWaterTemp3 = rParameters["Water_temp_3"].GetDouble();
96 
97  mTimeUnitConverter = mrModelPart.GetProcessInfo()[TIME_UNIT_CONVERTER];
98  mTableIdWater = rParameters["Water_level_Table"].GetInt();
99  mTableIdAmbientTemp = rParameters["Ambient_temp_Table"].GetInt();
100  mTableIdWaterTemp1 = rParameters["Water_temp_Table_1"].GetInt();
101  mTableIdWaterTemp2 = rParameters["Water_temp_Table_2"].GetInt();
102  mTableIdWaterTemp3 = rParameters["Water_temp_Table_3"].GetInt();
103 
104 // ELIMINAR mTableIdMonth = rParameters["Month_Table"].GetInt();
105 
106  if (mTableIdWater != 0)
108 
109  if (mTableIdAmbientTemp != 0)
111 
112  if (mTableIdWaterTemp1 != 0)
114 
115  if (mTableIdWaterTemp2 != 0)
117 
118  if (mTableIdWaterTemp3 != 0)
120 
121 
122 
123  KRATOS_CATCH("");
124  }
125 
127 
130 
131  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
132 
133  void Execute() override
134  {
135  }
136 
137  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
138 
139  void ExecuteInitialize() override
140  {
141 
142  KRATOS_TRY;
143 
145  const int nnodes = mrModelPart.GetMesh(0).Nodes().size();
146  int direction;
147 
148  if (mGravityDirection == "X")
149  direction = 0;
150  else if (mGravityDirection == "Y")
151  direction = 1;
152  else
153  direction = 2;
154 
155  if (nnodes != 0)
156  {
157  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.GetMesh(0).NodesBegin();
158 
159  #pragma omp parallel for
160  for (int i = 0; i < nnodes; i++)
161  {
162  ModelPart::NodesContainerType::iterator it = it_begin + i;
163 
164  double aux = it->Coordinates()[direction];
165  if (aux < mWaterLevel)
166  {
167  if (mIsFixed)
168  {
169  it->Fix(var);
170  }
171  if (aux > mZCoord1)
172  {
173  double Temperature = ((mAmbientTemp - mWaterTemp1)/(mWaterLevel - mZCoord1)) * (aux - mZCoord1) + mWaterTemp1;
174  it->FastGetSolutionStepValue(var) = Temperature;
175  }
176  else if ((aux <= mZCoord1) && (aux > mZCoord2))
177  {
178  double Temperature = ((mWaterTemp1 - mWaterTemp2)/(mZCoord1 - mZCoord2)) * (aux - mZCoord2) + mWaterTemp2;
179  it->FastGetSolutionStepValue(var) = Temperature;
180  }
181  else if ((aux <= mZCoord2) && (aux > mZCoord3))
182  {
183  double Temperature = ((mWaterTemp2 - mWaterTemp3)/(mZCoord2 - mZCoord3)) * (aux - mZCoord3) + mWaterTemp3;
184  it->FastGetSolutionStepValue(var) = Temperature;
185  }
186  else if (aux <= mZCoord3)
187  {
188  double Temperature = ((mWaterTemp3 - mWaterTemp2)/(mZCoord3 - mZCoord2)) * (aux - mZCoord3) + mWaterTemp3;
189  it->FastGetSolutionStepValue(var) = Temperature;
190  }
191  }
192  }
193  }
194 
195  KRATOS_CATCH("");
196  }
197 
198  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
199 
201  {
202 
203  KRATOS_TRY;
204 
206 
207  // Getting the values of table in case that it exist
208  if (mTableIdWater != 0)
209  {
210  double time = mrModelPart.GetProcessInfo()[TIME];
212  mWaterLevel = mpTableWater->GetValue(time);
213  }
214 
215  if (mTableIdAmbientTemp != 0)
216  {
217  double time = mrModelPart.GetProcessInfo()[TIME];
219  mAmbientTemp = mpTableAmbientTemp->GetValue(time);
220  }
221 
222  if (mTableIdWaterTemp1 != 0)
223  {
224  double time = mrModelPart.GetProcessInfo()[TIME];
226  mWaterTemp1 = mpTableWaterTemp1->GetValue(time);
227  }
228 
229  if (mTableIdWaterTemp2 != 0)
230  {
231  double time = mrModelPart.GetProcessInfo()[TIME];
233  mWaterTemp2 = mpTableWaterTemp2->GetValue(time);
234  }
235 
236  if (mTableIdWaterTemp3 != 0)
237  {
238  double time = mrModelPart.GetProcessInfo()[TIME];
240  mWaterTemp3 = mpTableWaterTemp3->GetValue(time);
241  }
242 
243  const int nnodes = mrModelPart.GetMesh(0).Nodes().size();
244  int direction;
245 
246  if (mGravityDirection == "X")
247  direction = 0;
248  else if (mGravityDirection == "Y")
249  direction = 1;
250  else
251  direction = 2;
252 
253  if (nnodes != 0)
254  {
255  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.GetMesh(0).NodesBegin();
256 
257  #pragma omp parallel for
258  for (int i = 0; i < nnodes; i++)
259  {
260  ModelPart::NodesContainerType::iterator it = it_begin + i;
261 
262  double aux = it->Coordinates()[direction];
263  if (aux < mWaterLevel)
264  {
265  if (mIsFixed)
266  {
267  it->Fix(var);
268  }
269  if (aux > mZCoord1)
270  {
271  double Temperature = ((mAmbientTemp - mWaterTemp1)/(mWaterLevel - mZCoord1)) * (aux - mZCoord1) + mWaterTemp1;
272  it->FastGetSolutionStepValue(var) = Temperature;
273  }
274  else if ((aux <= mZCoord1) && (aux > mZCoord2))
275  {
276  double Temperature = ((mWaterTemp1 - mWaterTemp2)/(mZCoord1 - mZCoord2)) * (aux - mZCoord2) + mWaterTemp2;
277  it->FastGetSolutionStepValue(var) = Temperature;
278  }
279  else if ((aux <= mZCoord2) && (aux > mZCoord3))
280  {
281  double Temperature = ((mWaterTemp2 - mWaterTemp3)/(mZCoord2 - mZCoord3)) * (aux - mZCoord3) + mWaterTemp3;
282  it->FastGetSolutionStepValue(var) = Temperature;
283  }
284  else if (aux <= mZCoord3)
285  {
286  double Temperature = ((mWaterTemp3 - mWaterTemp2)/(mZCoord3 - mZCoord2)) * (aux - mZCoord3) + mWaterTemp3;
287  it->FastGetSolutionStepValue(var) = Temperature;
288  }
289  }
290  }
291  }
292 
293  KRATOS_CATCH("");
294  }
295 
296  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
297 
299  {
300 
301  KRATOS_TRY;
302 
304 
305  const int nnodes = mrModelPart.GetMesh(0).Nodes().size();
306 
307  if (nnodes != 0)
308  {
309 
310  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.GetMesh(0).NodesBegin();
311 
312  #pragma omp parallel for
313  for (int i = 0; i < nnodes; i++)
314  {
315  ModelPart::NodesContainerType::iterator it = it_begin + i;
316  it->Free(var);
317  }
318  }
319 
320  KRATOS_CATCH("");
321  }
322 
324  std::string Info() const override
325  {
326  return "DamReservoirMonitoringTemperatureProcess";
327  }
328 
330  void PrintInfo(std::ostream &rOStream) const override
331  {
332  rOStream << "DamReservoirMonitoringTemperatureProcess";
333  }
334 
336  void PrintData(std::ostream &rOStream) const override
337  {
338  }
339 
341 
342  protected:
344 
346  std::string mVariableName;
347  std::string mGravityDirection;
348  bool mIsFixed;
350  double mHeight;
351  double mAmbientTemp;
352  double mWaterLevel;
353  double mZCoord1;
354  double mWaterTemp1;
355  double mZCoord2;
356  double mWaterTemp2;
357  double mZCoord3;
358  double mWaterTemp3;
360  TableType::Pointer mpTableWater;
361  TableType::Pointer mpTableAmbientTemp;
362  TableType::Pointer mpTableWaterTemp1;
363  TableType::Pointer mpTableWaterTemp2;
364  TableType::Pointer mpTableWaterTemp3;
370 
371  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
372 
373  private:
376 
377 }; //Class
378 
380 inline std::istream &operator>>(std::istream &rIStream,
382 
384 inline std::ostream &operator<<(std::ostream &rOStream,
386 {
387  rThis.PrintInfo(rOStream);
388  rOStream << std::endl;
389  rThis.PrintData(rOStream);
390 
391  return rOStream;
392 }
393 
394 } /* namespace Kratos.*/
395 
396 #endif /* KRATOS_DAM_RESERVOIR_MONITORING_TEMPERATURE_PROCESS defined */
Definition: dam_reservoir_monitoring_temperature_process.hpp:31
double mAmbientTemp
Definition: dam_reservoir_monitoring_temperature_process.hpp:351
TableType::Pointer mpTableWater
Definition: dam_reservoir_monitoring_temperature_process.hpp:360
double mReferenceCoordinate
Definition: dam_reservoir_monitoring_temperature_process.hpp:349
void ExecuteInitialize() override
This function is designed for being called at the beginning of the computations right after reading t...
Definition: dam_reservoir_monitoring_temperature_process.hpp:139
int mTableIdWaterTemp2
Definition: dam_reservoir_monitoring_temperature_process.hpp:368
std::string mGravityDirection
Definition: dam_reservoir_monitoring_temperature_process.hpp:347
DamReservoirMonitoringTemperatureProcess(ModelPart &rModelPart, Parameters &rParameters)
Constructor.
Definition: dam_reservoir_monitoring_temperature_process.hpp:41
TableType::Pointer mpTableAmbientTemp
Definition: dam_reservoir_monitoring_temperature_process.hpp:361
int mTableIdWater
Definition: dam_reservoir_monitoring_temperature_process.hpp:365
double mWaterTemp1
Definition: dam_reservoir_monitoring_temperature_process.hpp:354
TableType::Pointer mpTableWaterTemp3
Definition: dam_reservoir_monitoring_temperature_process.hpp:364
void ExecuteInitializeSolutionStep() override
This function will be executed at every time step BEFORE performing the solve phase.
Definition: dam_reservoir_monitoring_temperature_process.hpp:200
double mHeight
Definition: dam_reservoir_monitoring_temperature_process.hpp:350
TableType::Pointer mpTableWaterTemp2
Definition: dam_reservoir_monitoring_temperature_process.hpp:363
Table< double, double > TableType
Definition: dam_reservoir_monitoring_temperature_process.hpp:36
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: dam_reservoir_monitoring_temperature_process.hpp:133
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: dam_reservoir_monitoring_temperature_process.hpp:336
bool mIsFixed
Definition: dam_reservoir_monitoring_temperature_process.hpp:348
int mTableIdWaterTemp1
Definition: dam_reservoir_monitoring_temperature_process.hpp:367
double mZCoord3
Definition: dam_reservoir_monitoring_temperature_process.hpp:357
std::string mVariableName
Definition: dam_reservoir_monitoring_temperature_process.hpp:346
double mWaterLevel
Definition: dam_reservoir_monitoring_temperature_process.hpp:352
double mTimeUnitConverter
Definition: dam_reservoir_monitoring_temperature_process.hpp:359
std::string Info() const override
Turn back information as a string.
Definition: dam_reservoir_monitoring_temperature_process.hpp:324
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: dam_reservoir_monitoring_temperature_process.hpp:330
double mWaterTemp2
Definition: dam_reservoir_monitoring_temperature_process.hpp:356
double mWaterTemp3
Definition: dam_reservoir_monitoring_temperature_process.hpp:358
void ExecuteFinalizeSolutionStep() override
This function will be executed at every time step AFTER performing the solve phase.
Definition: dam_reservoir_monitoring_temperature_process.hpp:298
double mZCoord2
Definition: dam_reservoir_monitoring_temperature_process.hpp:355
TableType::Pointer mpTableWaterTemp1
Definition: dam_reservoir_monitoring_temperature_process.hpp:362
ModelPart & mrModelPart
Member Variables.
Definition: dam_reservoir_monitoring_temperature_process.hpp:345
virtual ~DamReservoirMonitoringTemperatureProcess()
Destructor.
Definition: dam_reservoir_monitoring_temperature_process.hpp:129
int mTableIdWaterTemp3
Definition: dam_reservoir_monitoring_temperature_process.hpp:369
KRATOS_CLASS_POINTER_DEFINITION(DamReservoirMonitoringTemperatureProcess)
int mTableIdAmbientTemp
Definition: dam_reservoir_monitoring_temperature_process.hpp:366
double mZCoord1
Definition: dam_reservoir_monitoring_temperature_process.hpp:353
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
int nnodes
Definition: sensitivityMatrix.py:24
integer i
Definition: TensorModule.f:17