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.
kutta_condition_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: Riccardo Rossi
11 //
12 
13 #ifndef KRATOS_KUTTA_CONDITION_PROCESS_H
14 #define KRATOS_KUTTA_CONDITION_PROCESS_H
15 
16 
17 #include "includes/define.h"
18 #include "includes/model_part.h"
19 #include "includes/kratos_flags.h"
20 #include "processes/process.h"
21 #include "geometries/geometry.h"
22 #include "utilities/geometry_utilities.h"
23 #include "utilities/math_utils.h"
25 
26 #include <string>
27 #include <iostream>
28 #include <sstream>
29 
30 #include <boost/functional/hash.hpp> //TODO: remove this dependence when Kratos has en internal one
31 #include <unordered_map> //TODO: remove this dependence when Kratos has en internal one
32 #include <utility>
33 
34 namespace Kratos
35 {
36 
38 {
39 public:
42 
45 
48 
52 
54 // KuttaConditionProcess(ModelPart& rModelPart,
55 // KratosParameters& parameters
56 // ):
57 // Process(),
58 // mrModelPart(rModelPart),
59 // mrOptions(Flags()),
60 // mrParameters(parameters)
61 // {
62 // }
65  ):
66  Process(),
67  mrModelPart(rModelPart)
68  {
69  }
70 
72  ~KuttaConditionProcess() override {}
73 
74 
78 
80  void operator()()
81  {
82  Execute();
83  }
84 
85 
89 
90 
92  void Execute() override
93  {
94  KRATOS_TRY;
95 
96  if(mrModelPart.Elements().size() == 0)
97  KRATOS_THROW_ERROR(std::invalid_argument, "the number of elements in the domain is zero. kutta condition can not be applied","")
98 
99  using normal_map_type = std::unordered_map<std::size_t, array_1d<double,3> >;
100 
101  for(auto it=mrModelPart.NodesBegin(); it!=mrModelPart.NodesEnd(); ++it)
102  if(it->Is(STRUCTURE)) it->Set(VISITED,false);
103 
104  PointerVector<Element> kutta_elements;
105  for(auto it=mrModelPart.ElementsBegin(); it!=mrModelPart.ElementsEnd(); ++it)
106  {
107  auto geom = it->GetGeometry();
108 
109  for(unsigned int i=0; i<geom.size(); ++i)
110  {
111  if(geom[i].Is(STRUCTURE))
112  {
113  kutta_elements.push_back(*(it.base()));
114  break;
115  }
116  }
117  }
118 
119  //compute one normal per each kutta node
120  normal_map_type normal_map;
121  for(auto it=kutta_elements.begin(); it!=kutta_elements.end(); ++it)
122  {
123  if(it->Is(MARKER))
124  {
125  //compute normal
126  const Vector& elemental_distances = it->GetValue(ELEMENTAL_DISTANCES);
127 
128  double vol;
130  bounded_matrix<double,4,3> DN_DX;
131  GeometryUtils::CalculateGeometryData(it->GetGeometry(), DN_DX, N, vol);
132 
133  //get a relevant norm
134  array_1d<double,3> n = prod(trans(DN_DX),elemental_distances);
135  n/=(norm_2(n)+1e-30);
136 
137  //
138  auto geom = it->GetGeometry();
139  for(unsigned int i=0; i<geom.size(); ++i)
140  {
141  if(geom[i].Is(STRUCTURE))
142  {
143  geom[i].Set(VISITED,true);
144  normal_map[geom[i].Id()] = n;;
145  }
146  }
147  }
148  }
149 
150  //now compute one elemntal distance per each element in the kutta list
151  for(auto it=kutta_elements.begin(); it!=kutta_elements.end(); ++it)
152  {
153  it->Set(MARKER,false);
154  Vector& elemental_distances = it->GetValue(ELEMENTAL_DISTANCES);
155 
157  auto geom = it->GetGeometry();
158  int kutta_id = -1;
159  for(unsigned int i=0; i<geom.size(); ++i)
160  {
161  if(geom[i].Is(STRUCTURE) && geom[i].Is(VISITED))
162  {
163  kutta_id = i;
164  n = normal_map[geom[i].Id()];
165  break;
166  }
167  }
168 
169  if(kutta_id == -1) //no node was found with the normal correctly calculated
170  {
171  it->Set(ACTIVE,false);
172  }
173  else
174  {
175 
176 
177  array_1d<double,3> x0 = geom[kutta_id].Coordinates();
178  double dkutta = -1e-3;
179  for(int i=0; i<static_cast<int>(geom.size()); ++i)
180  {
181  if(kutta_id != i)
182  {
183 
184  array_1d<double,3> v = geom[i].Coordinates() - x0;
185  elemental_distances[i] = inner_prod(n,v);
186  }
187  else
188  elemental_distances[i] = dkutta;
189  }
190 
191 
192  unsigned int npos = 0;
193  unsigned int nneg = 0;
194  for(unsigned int i=0; i<geom.size(); ++i)
195  if(elemental_distances[i] >= 0)
196  npos++;
197  else
198  nneg++;
199 
200  if(nneg > 0 && npos >0)
201  it->Set(MARKER,true);
202  }
203 
204  }
205 
206  KRATOS_CATCH("");
207  }
208 
209 
210 
214 
215 
219 
220 
224 
226  std::string Info() const override
227  {
228  return "KuttaConditionProcess";
229  }
230 
232  void PrintInfo(std::ostream& rOStream) const override
233  {
234  rOStream << "KuttaConditionProcess";
235  }
236 
238  void PrintData(std::ostream& rOStream) const override
239  {
240  this->PrintInfo(rOStream);
241  }
242 
243 
247 
248 
250 
251 
252 private:
255 
256 
260 
261  ModelPart& mrModelPart;
262  Flags mrOptions;
263 
264 
268 
269 
273 
275  KuttaConditionProcess& operator=(KuttaConditionProcess const& rOther);
276 
279 
280 
282 
283 }; // Class Process
284 
286 
289 
290 
294 
295 
297 inline std::istream& operator >> (std::istream& rIStream,
298  KuttaConditionProcess& rThis);
299 
301 inline std::ostream& operator << (std::ostream& rOStream,
302  const KuttaConditionProcess& rThis)
303 {
304  rThis.PrintInfo(rOStream);
305  rOStream << std::endl;
306  rThis.PrintData(rOStream);
307 
308  return rOStream;
309 }
311 
312 
313 
314 } // namespace Kratos
315 
316 
317 #endif // KRATOS_KUTTA_CONDITION_PROCESS_H
Base class for all Conditions.
Definition: condition.h:59
Base class for all Elements.
Definition: element.h:60
Definition: flags.h:58
bool Is(Flags const &rOther) const
Definition: flags.h:274
static void CalculateGeometryData(const GeometryType &rGeometry, BoundedMatrix< double, 4, 3 > &rDN_DX, array_1d< double, 4 > &rN, double &rVolume)
This function is designed to compute the shape function derivatives, shape functions and volume in 3D...
Definition: geometry_utilities.h:176
Definition: kutta_condition_process.h:38
std::string Info() const override
Turn back information as a string.
Definition: kutta_condition_process.h:226
void operator()()
This operator is provided to call the process as a function and simply calls the Execute method.
Definition: kutta_condition_process.h:80
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: kutta_condition_process.h:238
ModelPart::ConditionType ConditionType
Definition: kutta_condition_process.h:47
void Execute() override
Check elements to make sure that their jacobian is positive and conditions to ensure that their face ...
Definition: kutta_condition_process.h:92
~KuttaConditionProcess() override
Destructor.
Definition: kutta_condition_process.h:72
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: kutta_condition_process.h:232
KRATOS_CLASS_POINTER_DEFINITION(KuttaConditionProcess)
Pointer definition of Process.
KuttaConditionProcess(ModelPart &rModelPart)
Constructor for KuttaConditionProcess Process.
Definition: kutta_condition_process.h:64
ModelPart::ElementType ElementType
Definition: kutta_condition_process.h:46
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
iterator end()
Definition: pointer_vector.h:177
iterator begin()
Definition: pointer_vector.h:169
void push_back(const TPointerType &x)
Definition: pointer_vector.h:270
The base class for all processes in Kratos.
Definition: process.h:49
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#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
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
v
Definition: generate_convection_diffusion_explicit_element.py:114
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
N
Definition: sensitivityMatrix.py:29
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31