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.
L2_error_calculator_utility.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: Joaquin Gonzalez-Usua
11 //
12 
13 #if !defined(KRATOS_L2_ERROR_CALCULATOR_UTILITY)
14 #define KRATOS_L2_ERROR_CALCULATOR_UTILITY
15 
16 // External includes
17 #include <omp.h>
18 #include <vector>
19 
20 // Project includes
21 #include "includes/model_part.h"
24 #include "includes/process_info.h"
25 
26 namespace Kratos
27 {
29 {
30 
31 public:
32 
33  typedef Node NodeType;
37  typedef Vector VectorType;
38  typedef Matrix MatrixType;
39  typedef ModelPart::ElementsContainerType::iterator ElementIterator;
40  typedef ModelPart::NodesContainerType::iterator NodeIterator;
42 
44 
46 {}
47 
49 
50 void ComputeDofsErrors(ModelPart& r_model_part)
51 {
52  block_for_each(r_model_part.Nodes(), [&](Node& r_node)
53  {
54  auto& r_vectorial_error = r_node.FastGetSolutionStepValue(VECTORIAL_ERROR);
55  r_vectorial_error = r_node.FastGetSolutionStepValue(VELOCITY) - r_node.FastGetSolutionStepValue(EXACT_VELOCITY);
56 
57  auto& r_scalar_error = r_node.FastGetSolutionStepValue(SCALAR_ERROR);
58  r_scalar_error = r_node.FastGetSolutionStepValue(PRESSURE) - r_node.FastGetSolutionStepValue(EXACT_PRESSURE);
59  });
60 }
61 
62 double GetL2VectorErrorNorm(ModelPart& r_model_part)
63 {
64  double total_area = 0.0, result = 0.0;
65  const unsigned int dim = r_model_part.GetProcessInfo()[DOMAIN_SIZE];
66 
67  for (const auto& r_node : r_model_part.Nodes())
68  {
69  double local_area = r_node.FastGetSolutionStepValue(NODAL_AREA);
70  total_area += local_area;
71  double error_x = r_node.FastGetSolutionStepValue(VECTORIAL_ERROR_X);
72  double error_y = r_node.FastGetSolutionStepValue(VECTORIAL_ERROR_Y);
73  double error_z = 0.0;
74  if (dim == 3) error_z += r_node.FastGetSolutionStepValue(VECTORIAL_ERROR_Z);
75  double squared_modulus = std::pow(error_x,2)+std::pow(error_y,2)+std::pow(error_z,2);
76  result += squared_modulus * local_area;
77  }
78 
79  return std::sqrt(result/total_area);
80 }
81 
82 
83 double GetL2ScalarErrorNorm(ModelPart& r_model_part)
84 {
85  double total_area = 0.0, result = 0.0;
86 
87  for (const auto& r_node : r_model_part.Nodes())
88  {
89  double local_area = r_node.FastGetSolutionStepValue(NODAL_AREA);
90  total_area += local_area;
91  double error_p = r_node.FastGetSolutionStepValue(SCALAR_ERROR);
92  result += std::pow(error_p,2) * local_area;
93  }
94 
95  return std::sqrt(result/total_area);
96 }
97 //**************************************************************************************************************************************************
98 //**************************************************************************************************************************************************
99 
100 }; // Class L2ErrorNormCalculator
101 
102 } // namespace Kratos.
103 
104 #endif // KRATOS_L2_ERROR_CALCULATOR_UTILITY defined
Geometry base class.
Definition: geometry.h:71
Definition: L2_error_calculator_utility.h:29
ModelPart::NodesContainerType::iterator NodeIterator
Definition: L2_error_calculator_utility.h:40
Geometry< NodeType > GeometryType
Definition: L2_error_calculator_utility.h:35
double GetL2VectorErrorNorm(ModelPart &r_model_part)
Definition: L2_error_calculator_utility.h:62
ModelPart::ElementsContainerType::iterator ElementIterator
Definition: L2_error_calculator_utility.h:39
Matrix MatrixType
Definition: L2_error_calculator_utility.h:38
Kratos::Vector ShapeFunctionsType
Definition: L2_error_calculator_utility.h:41
KRATOS_CLASS_POINTER_DEFINITION(L2ErrorNormCalculator)
L2ErrorNormCalculator()
Definition: L2_error_calculator_utility.h:45
double GetL2ScalarErrorNorm(ModelPart &r_model_part)
Definition: L2_error_calculator_utility.h:83
Node NodeType
Definition: L2_error_calculator_utility.h:33
Geometry< NodeType >::PointsArrayType NodesArrayType
Definition: L2_error_calculator_utility.h:36
Vector VectorType
Definition: L2_error_calculator_utility.h:37
virtual ~L2ErrorNormCalculator()
Definition: L2_error_calculator_utility.h:48
void ComputeDofsErrors(ModelPart &r_model_part)
Definition: L2_error_calculator_utility.h:50
Properties PropertiesType
Definition: L2_error_calculator_utility.h:34
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
Properties encapsulates data shared by different Elements or Conditions. It can store any type of dat...
Definition: properties.h:69
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
int dim
Definition: sensitivityMatrix.py:25