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.
calculate_nodal_length.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 author: Alex Jarauta
11 // Co-author : Elaf Mahrous
12 
13 
14 
15 #if !defined(CALCULATE_NODAL_LENGTH_INCLUDED )
16 #define CALCULATE_NODAL_LENGTH_INCLUDED
17 
18 
19 
20 // System includes
21 #include <string>
22 #include <iostream>
23 #include <algorithm>
24 
25 // External includes
26 
27 
28 // Project includes
29 #include <pybind11/pybind11.h>
30 #include "includes/define.h"
31 #include "includes/define_python.h"
32 
33 #include "includes/model_part.h"
34 #include "includes/node.h"
35 #include "utilities/math_utils.h"
36 #include "utilities/geometry_utilities.h"
37 #include "processes/process.h"
38 #include "includes/condition.h"
39 #include "includes/element.h"
40 #include "ULF_application.h"
41 
42 
43 
44 namespace Kratos
45 {
46 
49 
53 
54 
58 
62 
66 
68 
76  : public Process
77  {
78  public:
79 
82 
85 
89 
92  {
93  }
94 
97  {
98  }
99 
100 
104 
105  // void operator()()
106  // {
107  // MergeParts();
108  // }
109 
110 
114 
115  void CalculateNodalLength2D(ModelPart& ThisModelPart)
116  {
117  KRATOS_TRY
118 
119  double x0,y0,x1,y1,x2,y2,norm10,norm20;
120  int neighnum = 0;
123 
124  for(ModelPart::NodesContainerType::iterator im = ThisModelPart.NodesBegin() ; im != ThisModelPart.NodesEnd() ; ++im)
125  {
126  //Find the neighbours of TRIPLE_POINT at the boundary
127  if ((im->FastGetSolutionStepValue(TRIPLE_POINT))*1000 != 0.0)
128  {
129  GlobalPointersVector< Node >& neighb = im->GetValue(NEIGHBOUR_NODES);
130  x0 = im->X();
131  y0 = im->Y();
132  x1 = 0.0;
133  y1 = 0.0;
134  x2 = 0.0;
135  y2 = 0.0;
136  neighnum = 0;
137  for (unsigned int i = 0; i < neighb.size(); i++)
138  {
139  if (neighb[i].FastGetSolutionStepValue(IS_BOUNDARY) != 0.0)
140  {
141  if (neighnum == 0)
142  {
143  x1 = neighb[i].X();
144  y1 = neighb[i].Y();
145  }
146  if (neighnum == 1)
147  {
148  x2 = neighb[i].X();
149  y2 = neighb[i].Y();
150  }
151  neighnum++;
152  }
153  }
154 
155  //Obtain the vectors pointing from node 0 to node 1 (r10) and from 0 to 2 (r20)
156  Vector2D(x0,y0,x1,y1,r10);
157  Vector2D(x0,y0,x2,y2,r20);
158  norm10 = Norm2D(r10);
159  norm20 = Norm2D(r20);
160  im->FastGetSolutionStepValue(NODAL_LENGTH) = 0.5*(norm10+norm20);
161  }
162 
163  //Repeat for IS_FREE_SURFACE nodes
164  //Find the neighbours of IS_FREE_SURFACE at the boundary
165  if (im->FastGetSolutionStepValue(IS_FREE_SURFACE) != 0.0)
166  {
167  GlobalPointersVector< Node >& neighb = im->GetValue(NEIGHBOUR_NODES);
168  x0 = im->X();
169  y0 = im->Y();
170  x1 = 0.0;
171  y1 = 0.0;
172  x2 = 0.0;
173  y2 = 0.0;
174  neighnum = 0;
175  for (unsigned int i = 0; i < neighb.size(); i++)
176  {
177  if ((neighb[i].FastGetSolutionStepValue(IS_FREE_SURFACE) != 0.0) || ((im->FastGetSolutionStepValue(TRIPLE_POINT))*1000 != 0.0 ))
178  {
179  if (neighnum == 0)
180  {
181  x1 = neighb[i].X();
182  y1 = neighb[i].Y();
183  }
184  if (neighnum == 1)
185  {
186  x2 = neighb[i].X();
187  y2 = neighb[i].Y();
188  }
189  neighnum++;
190  }
191  }
192 
193  //Obtain the vectors pointing from node 0 to node 1 (r10) and from 0 to 2 (r20)
194  Vector2D(x0,y0,x1,y1,r10);
195  Vector2D(x0,y0,x2,y2,r20);
196  norm10 = Norm2D(r10);
197  norm20 = Norm2D(r20);
198  im->FastGetSolutionStepValue(NODAL_LENGTH) = 0.5*(norm10+norm20);
199  }
200 
201 
202  }
203 
204 
205  KRATOS_CATCH("")
206  }
207 
208  void CalculateNodalLength3D(ModelPart& ThisModelPart)
209  {
210  KRATOS_TRY
211 
212 
213 
214  for(ModelPart::NodesContainerType::iterator im = ThisModelPart.NodesBegin() ;
215  im != ThisModelPart.NodesEnd() ; ++im)
216  {
217  //Find the neighbours of TRIPLE_POINT at the boundary
218  if ((im->FastGetSolutionStepValue(TRIPLE_POINT))*1000 != 0.0)
219  {
220  GlobalPointersVector< Node >& neighb = im->GetValue(NEIGHBOUR_NODES);
221  double x0 = im->X();
222  double y0 = im->Y();
223  double z0 = im->Z();
224  double x1 = 0.0;
225  double y1 = 0.0;
226  double z1 = 0.0;
227  double x2 = 0.0;
228  double y2 = 0.0;
229  double z2 = 0.0;
230  int neighnum = 0;
231  for (unsigned int i = 0; i < neighb.size(); i++)
232  {
233  if ((neighb[i].FastGetSolutionStepValue(TRIPLE_POINT))*1000.0 != 0.0)
234  {
235  if (neighb[i].X() != x0 || neighb[i].Y() != y0 || neighb[i].Z() != z0)
236  {
237  if (neighnum == 0)
238  {
239  x1 = neighb[i].X();
240  y1 = neighb[i].Y();
241  z1 = neighb[i].Z();
242  }
243  else
244  {
245  x2 = neighb[i].X();
246  y2 = neighb[i].Y();
247  z2 = neighb[i].Z();
248  }
249  neighnum++;
250  }
251  }
252  }
253 
254  //Obtain the vectors pointing from node 0 to node 1 (r10) and from 0 to 2 (r20)
257  Vector3D(x0,y0,z0,x1,y1,z1,r10);
258  Vector3D(x0,y0,z0,x2,y2,z2,r20);
259  double norm10 = Norm3D(r10);
260  double norm20 = Norm3D(r20);
261 
262  im->FastGetSolutionStepValue(NODAL_LENGTH) = 0.5*(norm10+norm20);
263 // KRATOS_WATCH(im->FastGetSolutionStepValue(NODAL_LENGTH))
264  }
265  }
266  KRATOS_CATCH("")
267  }
268 
269  void Vector2D(const double x0, const double y0, const double x1, const double y1, array_1d<double,2>& r01)
270  {
271  r01[0] = x1 - x0;
272  r01[1] = y1 - y0;
273  }
274 
275  void Vector3D(const double x0, const double y0, const double z0,
276  const double x1, const double y1, const double z1, array_1d<double,3>& r01)
277  {
278  r01[0] = x1 - x0;
279  r01[1] = y1 - y0;
280  r01[2] = z1 - z0;
281  }
282 
283  double Norm2D(const array_1d<double,2>& a)
284  {
285  return sqrt(a[0]*a[0] + a[1]*a[1]);
286  }
287 
288  double Norm3D(const array_1d<double,3>& a)
289  {
290  return sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
291  }
292 
296 
297 
301 
302 
306 
308  std::string Info() const override
309  {
310  return "CalculateNodalLength";
311  }
312 
314  void PrintInfo(std::ostream& rOStream) const override
315  {
316  rOStream << "CalculateNodalLength";
317  }
318 
320  void PrintData(std::ostream& rOStream) const override
321  {
322  }
323 
324 
328 
329 
331 
332 protected:
335 
336 
340 
341 
345 
346 
350 
351 
355 
356 
360 
361 
365 
366 
368 
369 private:
372 
373 
377 
378 
382 
383 
387 
388 
392 
393 
397 
398 
402 
404 // CalculateNodalLength& operator=(CalculateNodalLength const& rOther);
405 
407 // CalculateNodalLength(CalculateNodalLength const& rOther);
408 
409 
411 
412 }; // Class CalculateNodalLength
413 
415 
418 
419 
423 
424 
426 inline std::istream& operator >> (std::istream& rIStream,
427  CalculateNodalLength& rThis);
428 
430 inline std::ostream& operator << (std::ostream& rOStream,
431  const CalculateNodalLength& rThis)
432 {
433  rThis.PrintInfo(rOStream);
434  rOStream << std::endl;
435  rThis.PrintData(rOStream);
436 
437  return rOStream;
438 }
440 
441 
442 
443 } // namespace Kratos.
444 
445 
446 #endif // KRATOS_CREATE_INTERFACE_CONDITIONS_PROCESS_INCLUDED defined
447 
448 
Short class definition.
Definition: calculate_nodal_length.h:77
double Norm3D(const array_1d< double, 3 > &a)
Definition: calculate_nodal_length.h:288
void CalculateNodalLength2D(ModelPart &ThisModelPart)
Definition: calculate_nodal_length.h:115
~CalculateNodalLength() override
Destructor.
Definition: calculate_nodal_length.h:96
void Vector2D(const double x0, const double y0, const double x1, const double y1, array_1d< double, 2 > &r01)
Definition: calculate_nodal_length.h:269
KRATOS_CLASS_POINTER_DEFINITION(CalculateNodalLength)
Pointer definition of PushStructureProcess.
void CalculateNodalLength3D(ModelPart &ThisModelPart)
Definition: calculate_nodal_length.h:208
void Vector3D(const double x0, const double y0, const double z0, const double x1, const double y1, const double z1, array_1d< double, 3 > &r01)
Definition: calculate_nodal_length.h:275
double Norm2D(const array_1d< double, 2 > &a)
Definition: calculate_nodal_length.h:283
CalculateNodalLength()
Default constructor.
Definition: calculate_nodal_length.h:91
std::string Info() const override
Turn back information as a string.
Definition: calculate_nodal_length.h:308
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: calculate_nodal_length.h:314
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: calculate_nodal_length.h:320
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
size_type size() const
Definition: global_pointers_vector.h:307
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
The base class for all processes in Kratos.
Definition: process.h:49
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
im
Definition: GenerateCN.py:100
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
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
x2
Definition: generate_frictional_mortar_condition.py:122
x1
Definition: generate_frictional_mortar_condition.py:121
a
Definition: generate_stokes_twofluid_element.py:77
integer i
Definition: TensorModule.f:17