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.
from_json_check_result_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: Vicente Mataix Ferrandiz
11 //
12 
13 #if !defined(KRATOS_FROM_JSON_CHECK_RESULT_PROCESS_H_INCLUDED )
14 #define KRATOS_FROM_JSON_CHECK_RESULT_PROCESS_H_INCLUDED
15 
16 // System includes
17 
18 // External includes
19 
20 // Project includes
21 #include "processes/process.h"
22 #include "includes/model_part.h"
25 
26 namespace Kratos
27 {
28 
31 
35 
39 
43 
47 
55 class KRATOS_API(KRATOS_CORE) FromJSONCheckResultProcess
56  : public Process
57 {
58 public:
61 
64 
66  KRATOS_DEFINE_LOCAL_FLAG( CORRECT_RESULT );
67  KRATOS_DEFINE_LOCAL_FLAG( HISTORICAL_VALUE );
68  KRATOS_DEFINE_LOCAL_FLAG( CHECK_ONLY_LOCAL_ENTITIES );
69  KRATOS_DEFINE_LOCAL_FLAG( NODES_CONTAINER_INITIALIZED );
70  KRATOS_DEFINE_LOCAL_FLAG( ELEMENTS_CONTAINER_INITIALIZED );
71  KRATOS_DEFINE_LOCAL_FLAG( NODES_DATABASE_INITIALIZED );
72  KRATOS_DEFINE_LOCAL_FLAG( ELEMENTS_DATABASE_INITIALIZED );
73 
77 
79  typedef Node NodeType;
80 
82  typedef std::size_t IndexType;
83 
85  typedef std::size_t SizeType;
86 
90 
97  Model& rModel,
98  Parameters ThisParameters = Parameters(R"({})")
99  );
100 
107  ModelPart& rModelPart,
108  Parameters ThisParameters = Parameters(R"({})")
109  );
110 
113 
117 
118  void operator()()
119  {
120  Execute();
121  }
122 
126 
130  void ExecuteInitialize() override;
131 
135  void ExecuteFinalizeSolutionStep() override;
136 
140  void ExecuteFinalize() override;
141 
145  int Check() override;
146 
152  {
153  return this->Is(CORRECT_RESULT);
154  }
155 
160  std::string GetErrorMessage()
161  {
162  return mErrorMessage;
163  }
164 
168 
170  std::string Info() const override
171  {
172  return "FromJSONCheckResultProcess";
173  }
174 
176  void PrintInfo(std::ostream& rOStream) const override
177  {
178  rOStream << "FromJSONCheckResultProcess";
179  }
180 
182  void PrintData(std::ostream& rOStream) const override
183  {
184  }
185 
187 protected:
190 
194  void InitializeDatabases();
195 
201  void FillVariablesList(
202  const std::vector<std::string>& rNodalVariablesNames,
203  const std::vector<std::string>& rGPVariablesNames
204  );
205 
211  template<class TEntity>
212  bool CheckFlag(
213  const TEntity& rEntity,
214  const Flags* pFlag
215  )
216  {
217  if (pFlag != nullptr) {
218  if (rEntity.IsNot(*pFlag)) {
219  return false;
220  }
221  }
222  return true;
223  }
224 
230  bool CheckValues(
231  const double ValueEntity,
232  const double ValueJSON
233  );
234 
245  void FailMessage(
246  const IndexType EntityId,
247  const std::string& rEntityType,
248  const double ValueEntity,
249  const double ValueJSON,
250  const std::string& rVariableName,
251  const int ComponentIndex = -1,
252  const int GPIndex = -1
253  );
254 
259  void CheckNodeValues(IndexType& rCheckCounter);
260 
265  void CheckNodeHistoricalValues(IndexType& rCheckCounter);
266 
271  void CheckGPValues(IndexType& rCheckCounter);
272 
276  SizeType SizeDatabase(
277  const Parameters& rResults,
278  const NodesArrayType& rNodesArray,
279  const ElementsArrayType& rElementsArray
280  );
281 
285  void FillDatabase(
286  const Parameters& rResults,
287  const NodesArrayType& rNodesArray,
288  const ElementsArrayType& rElementsArray,
289  const SizeType NumberOfGP
290  );
291 
297  std::string GetNodeIdentifier(NodeType& rNode);
298 
303  NodesArrayType& GetNodes(const Flags* pFlag = nullptr);
304 
309  ElementsArrayType& GetElements(const Flags* pFlag = nullptr);
310 
314  std::size_t ComputeRelevantDigits(const double Value);
315 
319  const Parameters GetDefaultParameters() const override;
320 
324 
329  const ModelPart& GetModelPart() const;
330 
335  const Parameters GetSettings() const;
336 
341  const ResultDatabase& GetNodeDatabase();
342 
347  const ResultDatabase& GetGPDatabase();
348 
352 
354  FromJSONCheckResultProcess(ModelPart& rModelPart, Parameters Settings, Parameters DefaultSettings);
355 
357 
358 private:
361 
362  /* Model part and different settings */
363  ModelPart& mrModelPart;
364  Parameters mThisParameters;
365 
366  /* Additional values */
367  double mFrequency;
368  double mRelativeTolerance;
369  double mAbsoluteTolerance;
370  SizeType mRelevantDigits;
371 
372  /* Counters */
373  double mTimeCounter = 0.0;
374 
375  /* The entities of the containers */
376  NodesArrayType mNodesArray;
377  ElementsArrayType mElementsArray;
378 
379  /* The vectors storing the variables of study */
380  std::vector<const Variable<double>*> mpNodalVariableDoubleList;
381  std::vector<const Variable<array_1d<double,3>>*> mpNodalVariableArrayList;
382  std::vector<const Variable<Vector>*> mpNodalVariableVectorList;
383 
384  std::vector<const Variable<double>*> mpGPVariableDoubleList;
385  std::vector<const Variable<array_1d<double,3>>*> mpGPVariableArrayList;
386  std::vector<const Variable<Vector>*> mpGPVariableVectorList;
387 
388  /* The databases which store the values */
389  ResultDatabase mDatabaseNodes;
390  ResultDatabase mDatabaseGP;
391 
392  /* Error message */
393  std::string mErrorMessage = "";
394 
397 
401 
404 
406 
407 }; // Class FromJSONCheckResultProcess
408 
410 
413 
414 
418 
420 inline std::istream& operator >> (std::istream& rIStream,
422 
424 inline std::ostream& operator << (std::ostream& rOStream,
425  const FromJSONCheckResultProcess& rThis)
426 {
427  rThis.PrintInfo(rOStream);
428  rOStream << std::endl;
429  rThis.PrintData(rOStream);
430 
431  return rOStream;
432 }
434 
435 
436 } // namespace Kratos.
437 
438 #endif // KRATOS_FROM_JSON_CHECK_RESULT_PROCESS_H_INCLUDED defined
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
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
Definition: flags.h:58
This class is used in order to check results using a json file containing the solution a given model ...
Definition: from_json_check_result_process.h:57
KRATOS_DEFINE_LOCAL_FLAG(ELEMENTS_CONTAINER_INITIALIZED)
This flag is used in order to check that nodes container are initialized.
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: from_json_check_result_process.h:176
KRATOS_DEFINE_LOCAL_FLAG(NODES_CONTAINER_INITIALIZED)
This flag is used in order to check only local entities.
virtual ~FromJSONCheckResultProcess()
Destructor.
Definition: from_json_check_result_process.h:112
KRATOS_DEFINE_LOCAL_FLAG(CHECK_ONLY_LOCAL_ENTITIES)
This flag is used in order to check if the values are historical.
KRATOS_DEFINE_LOCAL_FLAG(ELEMENTS_DATABASE_INITIALIZED)
This flag is used in order to check that nodes database are initialized.
KRATOS_DEFINE_LOCAL_FLAG(NODES_DATABASE_INITIALIZED)
This flag is used in order to check that elements container are initialized.
KRATOS_DEFINE_LOCAL_FLAG(HISTORICAL_VALUE)
This flag is used in order to check that the result is correct.
bool CheckFlag(const TEntity &rEntity, const Flags *pFlag)
This method checks if a flag is active in a given entity.
Definition: from_json_check_result_process.h:212
KRATOS_CLASS_POINTER_DEFINITION(FromJSONCheckResultProcess)
Pointer definition of FromJSONCheckResultProcess.
std::size_t IndexType
The definition of the index type.
Definition: from_json_check_result_process.h:82
KRATOS_DEFINE_LOCAL_FLAG(CORRECT_RESULT)
Local Flags.
void operator()()
Definition: from_json_check_result_process.h:118
std::string Info() const override
Turn back information as a string.
Definition: from_json_check_result_process.h:170
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: from_json_check_result_process.h:182
FromJSONCheckResultProcess(ModelPart &rModelPart, Parameters Settings, Parameters DefaultSettings)
Protected constructor with modified default settings to be defined by derived class.
std::size_t SizeType
The definition of the sizetype.
Definition: from_json_check_result_process.h:85
Node NodeType
The node type definiton.
Definition: from_json_check_result_process.h:79
std::string GetErrorMessage()
This function returns the error message.
Definition: from_json_check_result_process.h:160
ModelPart::NodesContainerType NodesArrayType
This flag is used in order to check that elements database are initialized.
Definition: from_json_check_result_process.h:75
ModelPart::ElementsContainerType ElementsArrayType
Definition: from_json_check_result_process.h:76
bool IsCorrectResult()
This function returns if the result is correct.
Definition: from_json_check_result_process.h:151
This class aims to manage different model parts across multi-physics simulations.
Definition: model.h:60
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
This class defines the node.
Definition: node.h:65
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
The base class for all processes in Kratos.
Definition: process.h:49
This class stores the results of a simulation for a later comparison.
Definition: result_dabatase.h:403
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
ModelPart::NodesContainerType NodesArrayType
Definition: gid_gauss_point_container.h:42
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
def ComputeRelevantDigits(number)
Computes the relevant digits.
Definition: particle_from_json_check_result_process.py:308
def CheckValues(test_unit, value_a, value_b, tolerance)
Definition: test_utilities.py:46