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.
rans_line_output_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: Suneth Warnakulasuriya
11 //
12 
13 #if !defined(KRATOS_RANS_LINE_OUTPUT_PROCESS_H_INCLUDED)
14 #define KRATOS_RANS_LINE_OUTPUT_PROCESS_H_INCLUDED
15 
16 // System includes
17 #include <string>
18 
19 // External includes
20 
21 // Project includes
22 #include "containers/model.h"
23 #include "processes/process.h"
24 
25 namespace Kratos
26 {
29 
30 namespace LineOutputProcessUtilities
31 {
34 
37 using SizeType = std::size_t;
38 using IndicesVector = std::vector<int>;
39 
41 
44 
50 template <class TDataType>
52 {
53 public:
61  static void inline AddToValuesVector(
62  std::vector<double>& rValuesVector,
63  const TDataType& rValue,
64  const SizeType StartIndex)
65  {
67 
68  KRATOS_DEBUG_ERROR_IF(StartIndex >= rValuesVector.size() + rValue.size())
69  << "rValuesVector size is not enough to allocate values. "
70  "rValuesVector vector should have atleast "
71  << rValue.size()
72  << " elements from(including) StartIndex value. [ StartIndex = " << StartIndex
73  << ", rValuesVector.size() = " << rValuesVector.size() << " ].\n";
74 
75  for (SizeType i = 0; i < rValue.size(); ++i) {
76  rValuesVector[StartIndex + i] += rValue[i];
77  }
78 
79  KRATOS_CATCH("");
80  }
81 
90  static void inline AddNamesToVector(
91  std::vector<std::string>& rNamesVector,
92  const Variable<TDataType>& rVariable,
93  const TDataType& rValue,
94  const SizeType StartIndex)
95  {
97 
98  KRATOS_DEBUG_ERROR_IF(StartIndex >= rNamesVector.size() + rValue.size())
99  << "rNamesVector size is not enough to allocate values. "
100  "rNamesVector vector should have atleast "
101  << rValue.size()
102  << " elements from(including) StartIndex value. [ StartIndex = " << StartIndex
103  << ", rNamesVector.size() = " << rNamesVector.size() << " ].\n";
104 
105  for (SizeType i = 0; i < rValue.size(); ++i) {
106  rNamesVector[StartIndex + i] =
107  rVariable.Name() + "_" + std::to_string(i + 1);
108  }
109 
110  KRATOS_CATCH("");
111  }
112 
120  const TDataType& rValue)
121  {
122  return rValue.size();
123  }
124 };
125 
129 
143 template <class TDataType, class TValueGetterFunction>
145  std::vector<std::string>& rNamesList,
146  const NodeType& rNode,
147  const std::vector<const Variable<TDataType>*>& rVariablesList,
148  const IndicesVector& rVariableValuesStartIndex,
149  TValueGetterFunction* pValueGetterFunction)
150 {
151  for (std::size_t i = 0; i < rVariablesList.size(); ++i) {
152  const auto& r_variable = *(rVariablesList[i]);
154  rNamesList, r_variable, (*pValueGetterFunction)(rNode, r_variable),
155  rVariableValuesStartIndex[i]);
156  }
157 }
158 
169 template <class TDataType>
170 TDataType inline GetHistoricalValue(
171  const NodeType& rNode,
172  const Variable<TDataType>& rVariable)
173 {
174  return rNode.FastGetSolutionStepValue(rVariable);
175 }
176 
187 template <class TDataType>
188 TDataType inline GetNonHistoricalValue(
189  const NodeType& rNode,
190  const Variable<TDataType>& rVariable)
191 {
192  return rNode.GetValue(rVariable);
193 }
194 
206 template <class TDataType, class TValueGetterFunction>
208  const NodeType& rNode,
209  const std::vector<const Variable<TDataType>*>& rVariablesList,
210  TValueGetterFunction* pValueGetterFunction,
211  SizeType& Offset)
212 {
213  const auto number_of_variables = rVariablesList.size();
214  IndicesVector start_indices(number_of_variables + 1);
215 
216  for (SizeType i = 0; i < number_of_variables; ++i) {
217  start_indices[i] = Offset;
219  (*pValueGetterFunction)(rNode, *(rVariablesList[i])));
220  }
221 
222  start_indices[number_of_variables] = Offset;
223 
224  return start_indices;
225 }
226 
251 template <class TDataType, class TValueGetterFunction>
253  std::vector<double>& rValuesList,
254  const ModelPart::NodeType& rNode,
255  const double ShapeFunctionValue,
256  TValueGetterFunction* pValueGetterFunction,
257  const IndicesVector& rVariableValuesStartIndex,
258  const std::vector<const Variable<TDataType>*>& rVariablesList,
259  const SizeType StartIndexOffset)
260 {
261  using variable_data_collector =
263 
264  for (SizeType i = 0; i < rVariablesList.size(); ++i) {
265  variable_data_collector::AddToValuesVector(
266  rValuesList, (*pValueGetterFunction)(rNode, *(rVariablesList[i])) * ShapeFunctionValue,
267  StartIndexOffset + rVariableValuesStartIndex[i]);
268  }
269 }
270 
289 template <class... TVariableInfoTuplesList>
291  std::vector<double>& rValuesList,
292  const GeometryType& rGeometry,
293  const Vector& rSamplingPointShapeFunctions,
294  const SizeType LocalSamplePointValuesOffset,
295  const TVariableInfoTuplesList&... rVariableInfoTuplesList)
296 {
297  KRATOS_TRY
298 
299  const SizeType number_of_nodes = rGeometry.PointsNumber();
300 
301  KRATOS_DEBUG_ERROR_IF(number_of_nodes != rSamplingPointShapeFunctions.size())
302  << "number_of_nodes != rSamplingPointShapeFunctions.size().";
303 
304  for (SizeType i_node = 0; i_node < number_of_nodes; ++i_node) {
305  const auto& r_node = rGeometry[i_node];
306  const double shape_function_value = rSamplingPointShapeFunctions[i_node];
307 
308  int dummy[sizeof...(rVariableInfoTuplesList)] = {(
309  AddInterpolationContributions(rValuesList, r_node, shape_function_value,
310  std::get<2>(rVariableInfoTuplesList),
311  std::get<0>(rVariableInfoTuplesList),
312  std::get<1>(rVariableInfoTuplesList), LocalSamplePointValuesOffset),
313  0)...};
314 
315  *dummy = 0;
316  }
317 
318  KRATOS_CATCH("");
319 }
320 
322 
323 } // namespace LineOutputProcessUtilities
324 
327 
341 class KRATOS_API(RANS_APPLICATION) RansLineOutputProcess
342 : public Process
343 {
344 public:
347 
350 
352  using SizeType = std::size_t;
353  using IndicesVector = std::vector<int>;
354 
358 
360 
361  RansLineOutputProcess(Model& rModel, Parameters rParameters);
362 
364  ~RansLineOutputProcess() override = default;
365 
368 
371 
375 
376  int Check() override;
377 
378  void ExecuteInitialize() override;
379 
380  void ExecuteInitializeSolutionStep() override;
381 
382  void ExecuteFinalizeSolutionStep() override;
383 
384  const Parameters GetDefaultParameters() const override;
385 
389 
391  std::string Info() const override;
392 
394  void PrintInfo(std::ostream& rOStream) const override;
395 
397  void PrintData(std::ostream& rOStream) const override;
398 
400 
401 private:
404 
405  Model& mrModel;
406 
407  std::string mModelPartName;
408  std::vector<std::string> mVariableNames;
409  bool mWriteHeader;
410  array_1d<double, 3> mStartPoint;
411  array_1d<double, 3> mEndPoint;
412 
413  double mOutputStepInterval;
414  double mCurrentStepCount = 0.0;
415  double mPreviousStepValue;
416  std::string mOutputFileName;
417  std::string mOutputStepControlVariableName;
418 
419  bool mIsHistoricalValue;
420  bool mUpdatePointsEachStep;
421 
422  SizeType mNumberOfSamplingPoints;
423  std::vector<double> mSamplingPoints;
424  std::vector<int> mSamplingPointElementIds;
425  std::vector<Vector> mSamplingPointElementShapeFunctions;
426 
427  IndicesVector mSamplePointLocalIndexList;
428  std::vector<IndicesVector> mSamplePointLocalIndexListMaster;
429 
430  template <class TDataType>
431  using variables_vector_type = std::vector<const Variable<TDataType>*>;
432 
433  variables_vector_type<double> mDoubleVariablesList;
434  variables_vector_type<array_1d<double, 3>> mArray3VariablesList;
435  variables_vector_type<array_1d<double, 4>> mArray4VariablesList;
436  variables_vector_type<array_1d<double, 6>> mArray6VariablesList;
437  variables_vector_type<array_1d<double, 9>> mArray9VariablesList;
438  variables_vector_type<Vector> mVectorVariablesList;
439  variables_vector_type<Matrix> mMatrixVariablesList;
440 
444 
451  void UpdateSamplePoints();
452 
466  template <class TDataType>
467  bool CheckAndAddVariableToList(
468  variables_vector_type<TDataType>& rVariablesList,
469  const ModelPart& rModelPart,
470  const std::string& rVariableName)
471  {
472  KRATOS_TRY
473 
474  if (KratosComponents<Variable<TDataType>>::Has(rVariableName)) {
475  const auto& r_variable =
476  KratosComponents<Variable<TDataType>>::Get(rVariableName);
477  KRATOS_ERROR_IF(mIsHistoricalValue && !rModelPart.HasNodalSolutionStepVariable(r_variable))
478  << rVariableName << " is not found in nodal solution step variables list of "
479  << rModelPart.Name() << ".";
480 
481  rVariablesList.push_back(&r_variable);
482 
483  return true;
484  }
485 
486  return false;
487 
488  KRATOS_CATCH("");
489  }
490 
504  template <class TOutputDataType, class TDataType>
505  void GetVariableValueFromProcessInfo(
506  bool& rIsValueObtained,
507  TOutputDataType& rOutputValue,
508  const std::string& rVariableName) const
509  {
510  KRATOS_TRY
511 
512  if (KratosComponents<Variable<TDataType>>::Has(rVariableName)) {
513  const auto& r_process_info =
514  mrModel.GetModelPart(mModelPartName).GetProcessInfo();
515  const auto& r_variable =
516  KratosComponents<Variable<TDataType>>::Get(rVariableName);
517 
518  if (r_process_info.Has(r_variable)) {
519  rOutputValue = static_cast<TOutputDataType>(r_process_info[r_variable]);
520  rIsValueObtained = true;
521  }
522  }
523 
524  KRATOS_CATCH("");
525  }
526 
537  template <class... TDataTypes>
538  double CheckAndGetOutputVariableValue(
539  const std::string& rVariableName) const
540  {
541  KRATOS_TRY
542 
543  bool is_variable_found = false;
544  double value = 0.0;
545 
546  int dummy[sizeof...(TDataTypes)] = {(
547  GetVariableValueFromProcessInfo<double, TDataTypes>(is_variable_found, value, rVariableName),
548  0)...};
549 
550  *dummy = 0;
551 
552  KRATOS_ERROR_IF(!is_variable_found)
553  << "Output step control variable name not found in variables list. "
554  "[ "
555  "output_step_control_variable_name = "
556  << rVariableName << " ].\n";
557 
558  return value;
559 
560  KRATOS_CATCH("");
561  }
562 
569  bool IsOutputStep();
570 
575  void WriteOutputFile() const;
576 
582  void WriteOutputFileHeader(
583  std::ofstream& rOutputFileStream) const;
584 
590  std::string GetOutputFileName() const;
591 
593 
594 }; // Class RansLineOutputProcess
595 
599 
601 inline std::ostream& operator<<(
602  std::ostream& rOStream,
603  const RansLineOutputProcess& rThis);
604 
606 
608 
609 } // namespace Kratos.
610 
611 #endif // KRATOS_RANS_LINE_OUTPUT_PROCESS_H_INCLUDED defined
void ExecuteFinalizeSolutionStep() override
this function will be executed at every time step AFTER performing the solve phase
Definition: periodic_interface_process.hpp:55
void ExecuteInitialize() override
Definition: periodic_interface_process.hpp:37
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
Geometry< NodeType > GeometryType
definition of the geometry type with given NodeType
Definition: element.h:83
Geometry base class.
Definition: geometry.h:71
SizeType PointsNumber() const
Definition: geometry.h:528
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
Class to get variable information.
Definition: rans_line_output_process.h:52
static SizeType GetVariableDataLength(const TDataType &rValue)
Get the Variable Data Length.
Definition: rans_line_output_process.h:119
static void AddNamesToVector(std::vector< std::string > &rNamesVector, const Variable< TDataType > &rVariable, const TDataType &rValue, const SizeType StartIndex)
Updates variable names from given variable.
Definition: rans_line_output_process.h:90
static void AddToValuesVector(std::vector< double > &rValuesVector, const TDataType &rValue, const SizeType StartIndex)
Updates TDataType values starting from StartIndex.
Definition: rans_line_output_process.h:61
This class aims to manage different model parts across multi-physics simulations.
Definition: model.h:60
ModelPart & GetModelPart(const std::string &rFullModelPartName)
This method returns a model part given a certain name.
Definition: model.cpp:107
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
std::string & Name()
Definition: model_part.h:1811
bool HasNodalSolutionStepVariable(VariableData const &ThisVariable) const
Definition: model_part.h:544
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
Node NodeType
Definition: model_part.h:117
This class defines the node.
Definition: node.h:65
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: node.h:466
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
Line output process.
Definition: rans_line_output_process.h:343
std::vector< int > IndicesVector
Definition: rans_line_output_process.h:353
RansLineOutputProcess & operator=(RansLineOutputProcess const &rOther)=delete
Assignment operator.
~RansLineOutputProcess() override=default
Destructor.
RansLineOutputProcess(RansLineOutputProcess const &rOther)=delete
Copy constructor.
KRATOS_CLASS_POINTER_DEFINITION(RansLineOutputProcess)
Pointer definition of RansLineOutputProcess.
std::size_t SizeType
Definition: rans_line_output_process.h:352
const std::string & Name() const
Definition: variable_data.h:201
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
TDataType GetNonHistoricalValue(const NodeType &rNode, const Variable< TDataType > &rVariable)
Get the Historical Value.
Definition: rans_line_output_process.h:188
void InterpolateVariables(std::vector< double > &rValuesList, const GeometryType &rGeometry, const Vector &rSamplingPointShapeFunctions, const SizeType LocalSamplePointValuesOffset, const TVariableInfoTuplesList &... rVariableInfoTuplesList)
Interpolates variables for given variable list tuples.
Definition: rans_line_output_process.h:290
std::size_t SizeType
Definition: rans_line_output_process.h:37
std::vector< int > IndicesVector
Definition: rans_line_output_process.h:38
void AddInterpolationContributions(std::vector< double > &rValuesList, const ModelPart::NodeType &rNode, const double ShapeFunctionValue, TValueGetterFunction *pValueGetterFunction, const IndicesVector &rVariableValuesStartIndex, const std::vector< const Variable< TDataType > * > &rVariablesList, const SizeType StartIndexOffset)
Adds interpolation contributions for given variables list.
Definition: rans_line_output_process.h:252
IndicesVector GetVariableDataStartIndices(const NodeType &rNode, const std::vector< const Variable< TDataType > * > &rVariablesList, TValueGetterFunction *pValueGetterFunction, SizeType &Offset)
Calculates variable start indices.
Definition: rans_line_output_process.h:207
TDataType GetHistoricalValue(const NodeType &rNode, const Variable< TDataType > &rVariable)
Get the Historical Value.
Definition: rans_line_output_process.h:170
void AddVariablesListNamesToVector(std::vector< std::string > &rNamesList, const NodeType &rNode, const std::vector< const Variable< TDataType > * > &rVariablesList, const IndicesVector &rVariableValuesStartIndex, TValueGetterFunction *pValueGetterFunction)
Modifies names from list of variables.
Definition: rans_line_output_process.h:144
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::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
dummy
Definition: script.py:194
integer i
Definition: TensorModule.f:17