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.
unv_output.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: Carlos Roig
11 //
12 //
13 
14 #ifndef KRATOS_UNV_OUTPUT_H_INCLUDED
15 #define KRATOS_UNV_OUTPUT_H_INCLUDED
16 
17 /* System includes */
18 #include <iostream>
19 #include <fstream>
20 #include <string>
21 
22 /* External includes */
23 
24 /* Project includes */
25 #include "includes/model_part.h"
26 #include "includes/exception.h"
27 
28 namespace Kratos {
29 
30 
40 class KRATOS_API(KRATOS_CORE) UnvOutput {
41 public:
42 
43  enum class DatasetID {
44  NODES_DATASET = 2411,
45  ELEMENTS_DATASET = 2412,
46  RESULTS_DATASET = 2414
47  };
48 
49  enum class DatasetLocation {
50  DATA_AT_NODES = 1,
51  DATA_AT_ELEMENTS = 2,
52  DATA_AT_NODES_ON_ELEMENTS = 3,
53  DATA_AT_POINTS = 5,
54  DATA_ON_ELEMENTS_AT_NODES = 6
55  };
56 
57  enum class ModelType {
58  UNKNOWN = 0,
59  STRUCTURAL = 1,
60  HEAT_TRANSFER = 2,
61  FLUID_FLOW = 3
62  };
63 
64  enum class AnalysisType {
65  UNKNOWN = 0,
66  STATIC = 1,
67  NORMAL_MODE = 2,
68  COMPLEX_EIGENVALUE_FIRST_ORDER = 3,
69  TRANSIENT = 4,
70  FREQUENCY_RESPONSE = 5,
71  BUCKLING = 6,
72  COMPLEX_EIGENVALUE_SECOND_ORDER = 7,
73  STATIC_NON_LINEAR = 9,
74  CRAIG_BAMPTON_CONSTRAINT_MODES = 10,
75  EQUIVALENT_ATTACHMENT_MODES = 11,
76  EFFECTIVE_MASS_MODES = 12,
77  EFFECTIVE_MASS_MATRIX = 13,
78  EFFECTIVE_MASS_MATRIX_COPY = 14, // This record is duplicared intentionally
79  DISTRIBUTED_LOAD_LOAD_DISTRIBUTION = 15,
80  DISTRIBUTED_LOAD_ATTACHMENT_MODES = 16
81  };
82 
83  // 3_DOF_* Records have their name changed to D3_DOF to avoid conflicts.
84  enum class DataCharacteristics {
85  UNKNOWN = 0,
86  SCALAR = 1,
87  D3_DOF_GLOBAL_TRANSLATION_VECTOR = 2,
88  D3_DOF_GLOBAL_TRANSLATION_ROTATION_VECTOR = 3,
89  SYMMETRIC_GLOBAL_TENSOR = 4,
90  STRESS_RESULTANTS = 6
91  };
92 
93  // This record is to big, I will consider moving these enums to another file.
94  // enum class ResultType {
95 
96  // };
97 
98  enum class DataType {
99  INTEGER = 1,
100  SINGLE_PRECISION_FLOATING_POINT = 2,
101  DOUBLE_PRECISION_FLOATING_POINT = 4,
102  SINGLE_PRECISION_COMPLEX = 5,
103  DOUBLE_PRECISION_COMPLEX = 6
104  };
105 
107 
108  template <typename Enumeration>
109  auto as_integer(Enumeration const value)
111  {
112  return static_cast<typename std::underlying_type<Enumeration>::type>(value);
113  }
114 
115  UnvOutput(Kratos::ModelPart &modelPart, const std::string &outFileWithoutExtension);
116 
117 
118  void InitializeOutputFile();
119 
124  void WriteMesh();
125 
130  void WriteNodes();
131 
136  void WriteElements();
137 
144  void WriteNodalResults(const Variable<bool>& rVariable, const double timeStep);
145  void WriteNodalResults(const Variable<int>& rVariable, const double timeStep);
146  void WriteNodalResults(const Variable<double>& rVariable, const double timeStep);
147  void WriteNodalResults(const Variable<array_1d<double,3>>& rVariable, const double timeStep);
148  void WriteNodalResults(const Variable<Vector>& rVariable, const double timeStep);
149  void WriteNodalResults(const Variable<Matrix>& rVariable, const double timeStep);
150 
159  UnvOutput::DataCharacteristics GetDataType(const Variable<int>&);
164 
174  void WriteNodalResultValues(std::ofstream &outputFile, const Node& node, const Variable<bool>& rVariable);
175  void WriteNodalResultValues(std::ofstream &outputFile, const Node& node, const Variable<int>& rVariable);
176  void WriteNodalResultValues(std::ofstream &outputFile, const Node& node, const Variable<double>& rVariable);
177  void WriteNodalResultValues(std::ofstream &outputFile, const Node& node, const Variable<array_1d<double,3>>& rVariable);
178  void WriteNodalResultValues(std::ofstream &outputFile, const Node& node, const Variable<Vector>& rVariable);
179  void WriteNodalResultValues(std::ofstream &outputFile, const Node& node, const Variable<Matrix>& rVariable);
180 
187  template<class TVariablebleType>
188  int GetUnvVariableName(const TVariablebleType& rVariable) {
189  if(rVariable == VELOCITY) return 11;
190  if(rVariable == TEMPERATURE) return 5;
191  if(rVariable == PRESSURE) return 117;
192 
193  return 1000;
194  }
195 
224  template<class TVariablebleType>
225  void WriteNodalResultRecords(const TVariablebleType& rVariable, const int numComponents, const double timeStep) {
226  std::ofstream outputFile;
227  outputFile.open(mOutputFileName, std::ios::out | std::ios::app);
228 
229  std::string dataSetName = "NodalResults";
230  const std::string& dataSetLabel = rVariable.Name();
231 
232  outputFile << std::setw(6) << "-1" << "\n"; // Begin block
233  outputFile << std::setw(6) << as_integer(DatasetID::RESULTS_DATASET) << "\n"; // DatasetID
234 
235  outputFile << std::setw(10) << dataSetLabel << "\n"; // Record 1 - Label
236  outputFile << std::setw(6) << dataSetName << "\n"; // Record 2 - Name
237  outputFile << std::setw(10) << as_integer(DatasetLocation::DATA_AT_NODES) << "\n"; // Record 3
238 
239  // String records, seems like you can put anything you want.
240  outputFile << "" << "\n"; // Record 4
241  outputFile << "" << "\n"; // Record 5
242  outputFile << "" << "\n"; // Record 6
243  outputFile << "" << "\n"; // Record 7
244  outputFile << "" << "\n"; // Record 8
245 
246  // ModelType, AnalysisType, DataCharacteristic, ResultType, DataType, NumberOfDataValues // Record 9
247  outputFile << std::setw(10) << as_integer(ModelType::STRUCTURAL);
248  outputFile << std::setw(10) << as_integer(AnalysisType::TRANSIENT);
249  outputFile << std::setw(10) << as_integer(GetDataType(rVariable));
250  outputFile << std::setw(10) << GetUnvVariableName(rVariable);
251  outputFile << std::setw(10) << as_integer(DataType::SINGLE_PRECISION_FLOATING_POINT);
252  outputFile << std::setw(10) << numComponents;
253  outputFile << "\n";
254 
255  // DesignSetId, IterationNumber, SolutionSetId, BoundaryCondition, LoadSet, ModeNumber, TimeStampNumber, FrequencyNumber
256  outputFile << std::setw(10) << 0; // Record 10
257  outputFile << std::setw(10) << timeStep;
258  outputFile << std::setw(10) << 0;
259  outputFile << std::setw(10) << 0;
260  outputFile << std::setw(10) << 0;
261  outputFile << std::setw(10) << 1;
262  outputFile << std::setw(10) << timeStep;
263  outputFile << std::setw(10) << 0;
264  outputFile << "\n";
265 
266  // CreationOption, (Unknown)*7
267  outputFile << std::setw(10) << 0; // Record 11
268  outputFile << std::setw(10) << 0;
269  outputFile << "\n";
270 
271  // Time, Frequency Eigenvalue NodalMass ViscousDampingRatio, HystereticDampingRatio
272  outputFile << std::setw(13) << timeStep * 0.1; // Record 12
273  outputFile << std::setw(13) << "0.00000E+00";
274  outputFile << std::setw(13) << "0.00000E+00";
275  outputFile << std::setw(13) << "0.00000E+00";
276  outputFile << std::setw(13) << "0.00000E+00";
277  outputFile << std::setw(13) << "0.00000E+00";
278  outputFile << "\n";
279 
280  // Eigenvalue_re, Eigenvalue_im, ModalA_re, ModalA_im, ModalB_re, ModalB_im
281  outputFile << std::setw(13) << "0.00000E+00"; // Record 13
282  outputFile << std::setw(13) << "0.00000E+00";
283  outputFile << std::setw(13) << "0.00000E+00";
284  outputFile << std::setw(13) << "0.00000E+00";
285  outputFile << std::setw(13) << "0.00000E+00";
286  outputFile << std::setw(13) << "0.00000E+00";
287  outputFile << "\n";
288 
289  // Data at nodes:
290  for (auto &node_i : mrOutputModelPart.Nodes()) {
291  int node_label = node_i.Id();
292  outputFile << std::setw(6) << node_label << "\n"; // Record 14 - Node Number
293  WriteNodalResultValues(outputFile, node_i, rVariable); // Record 15 - NumberOfDataValues' data of the node
294  }
295 
296  outputFile << std::setw(6) << "-1" << "\n";
297  outputFile.close();
298  }
299 
300 private:
301 
302  Kratos::ModelPart &mrOutputModelPart;
303  std::string mOutputFileName;
304 
305 };
306 }
307 
308 #endif //KRATOS_UNV_OUTPUT_H_INCLUDED
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
This class defines the node.
Definition: node.h:65
Provides a tool to write UNV files.
Definition: unv_output.h:40
AnalysisType
Definition: unv_output.h:64
void WriteNodalResultRecords(const TVariablebleType &rVariable, const int numComponents, const double timeStep)
Writes a result dataset using the results in node mode.
Definition: unv_output.h:225
KRATOS_CLASS_POINTER_DEFINITION(UnvOutput)
DataCharacteristics
Definition: unv_output.h:84
DataType
Definition: unv_output.h:98
int GetUnvVariableName(const TVariablebleType &rVariable)
Get the id of the UNV variable name corresponding to rVariable. 1000+ if none found.
Definition: unv_output.h:188
DatasetID
Definition: unv_output.h:43
DatasetLocation
Definition: unv_output.h:49
auto as_integer(Enumeration const value) -> typename std::underlying_type< Enumeration >::type
Definition: unv_output.h:109
ModelType
Definition: unv_output.h:57
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
void WriteMesh(GidIOType &dummy, GidIOType::MeshType &rThisMesh)
Definition: add_custom_io_to_python.cpp:74
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
type
Definition: generate_gid_list_file.py:35
out
Definition: isotropic_damage_automatic_differentiation.py:200
Definition: mesh_converter.cpp:38