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.
embedded_mesh_locator_process.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3 KratosULFApplication
4 A library based on:
5 Kratos
6 A General Purpose Software for Multi-Physics Finite Element Analysis
7 Version 1.0 (Released on march 05, 2007).
8 
9 Copyright 2007
10 Pooyan Dadvand, Riccardo Rossi, Pawel Ryzhakov
11 pooyan@cimne.upc.edu
12 rrossi@cimne.upc.edu
13 - CIMNE (International Center for Numerical Methods in Engineering),
14 Gran Capita' s/n, 08034 Barcelona, Spain
15 
16 
17 Permission is hereby granted, free of charge, to any person obtaining
18 a copy of this software and associated documentation files (the
19 "Software"), to deal in the Software without restriction, including
20 without limitation the rights to use, copy, modify, merge, publish,
21 distribute, sublicense and/or sell copies of the Software, and to
22 permit persons to whom the Software is furnished to do so, subject to
23 the following condition:
24 
25 Distribution of this code for any commercial purpose is permissible
26 ONLY BY DIRECT ARRANGEMENT WITH THE COPYRIGHT OWNERS.
27 
28 The above copyright notice and this permission notice shall be
29 included in all copies or substantial portions of the Software.
30 
31 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
34 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
35 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
36 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
37 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 
39 ==============================================================================
40 */
41 
42 
43 //
44 // Project Name: Kratos
45 // Last Modified by: $Author: anonymous $
46 // Date: $Date: 2009-01-15 14:50:34 $
47 // Revision: $Revision: 1.3 $
48 //
49 //
50 
51 
52 #if !defined(KRATOS_EMBEDDED_LOCATOR_PROCESS_INCLUDED )
53 #define KRATOS_EMBEDDED_LOCATOR_PROCESS_INCLUDED
54 
55 
56 
57 // System includes
58 #include <string>
59 #include <iostream>
60 #include <algorithm>
61 #include <boost/timer.hpp>
62 
63 // External includes
64 
65 
66 // Project includes
68 #include "includes/define.h"
69 #include "processes/process.h"
70 #include "includes/node.h"
71 #include "includes/element.h"
72 #include "includes/model_part.h"
74 
75 
76 namespace Kratos
77 {
78 
81 
85 
86 
90 
94 
98 
100 
108  : public Process
109 {
110 public:
113 
116 
120 
123  : mr_model_part(model_part)
124  {
125  }
126 
129  {
130  }
131 
132 
136 
137  void operator()()
138  {
139  Execute();
140  }
141 
142 
146 
147  //this function calculates distances of the nodes of the given model part mr_model_part from the surface mesh (embedded_model_part) and stores it nodally
148  //this permits to identify the intersected elements
149  void Locate(ModelPart& embedded_model_part)
150  {
151  KRATOS_TRY
152 
153  ModelPart::NodesContainerType& embeddedNodes = embedded_model_part.Nodes();
154  ModelPart::NodesContainerType& volumeNodes = mr_model_part.Nodes();
155  //reset the COUNTER
156  for(ModelPart::NodesContainerType::iterator in = embeddedNodes.begin(); in!=embeddedNodes.end(); in++)
157  {
158  in->FastGetSolutionStepValue(COUNTER)=0;
159  }
160 
161  for(ModelPart::NodesContainerType::iterator in = volumeNodes.begin(); in!=volumeNodes.end(); in++)
162  {
163  in->FastGetSolutionStepValue(COUNTER)=0;
164  }
165 
166 
167  //the variable COUNTER stores for the skin nodes adn volume nodes store their positions in the Gid lists of surface and volume nodes respectively.
168 
170  //count the nummber of the "skin" nodes
171  unsigned int n_skin_nodes=embedded_model_part.Nodes().size();
172 
173  //each node is represented by its three coordinates
174  double* skin_nodes = NULL;
175  skin_nodes = new double[n_skin_nodes*3];
176 
177  unsigned int count=0;
178  unsigned int base=0;
179 
180  for(ModelPart::NodesContainerType::iterator in = embeddedNodes.begin(); in!=embeddedNodes.end(); in++)
181  {
182  //each node has three coords
183  base=count*3;
184  skin_nodes[base]=in->X();
185  skin_nodes[base+1]=in->Y();
186  skin_nodes[base+2]=in->Z();
187  in->FastGetSolutionStepValue(COUNTER)=count;
188  count++;
189  }
190 
191 
193 
194  //count the number of the "skin" faces (must be triangles)
195  //check if these are called CONDITIONS in kratos!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
196  unsigned int n_skin_faces=embedded_model_part.Conditions().size();
197  //KRATOS_WATCH(embedded_model_part.Conditions().size())
198  //each face is represented by "numbers" of its three nodes (vertices)
199  int* skin_faces = NULL;
200  skin_faces = new int[n_skin_faces*3];
201  //we reuse the counter
202  count=0;
203  ModelPart::ConditionsContainerType& embeddedConds = embedded_model_part.Conditions();
204 
205 
206  for(ModelPart::ConditionsContainerType::iterator ic = embeddedConds.begin() ;
207  ic != embeddedConds.end() ; ++ic)
208  {
209  //each face has three nodes
210  base=count*3;
211  //connectivities - according to their position in the skin_nodes list
212  //(three consecutive coords are corresponding to one node, i.e. one entry in the skin_faces list)
213  unsigned int position_0=ic->GetGeometry()[0].FastGetSolutionStepValue(COUNTER);
214  unsigned int position_1=ic->GetGeometry()[1].FastGetSolutionStepValue(COUNTER);
215  unsigned int position_2=ic->GetGeometry()[2].FastGetSolutionStepValue(COUNTER);
216  skin_faces[base]=position_0;
217  skin_faces[base+1]=position_1;
218  skin_faces[base+2]=position_2;
219  count++;
220  }
221 
222 
223 
225 
226  //count the nummber of the volume nodes
227  unsigned int n_vol_nodes=mr_model_part.Nodes().size();
228 
229  double* vol_nodes = NULL;
230  vol_nodes = new double[n_vol_nodes*3];
231 
232  count=0;
233 
234  double search_radius=0.0;
235  double temp=0.0;
236  //and fill in the list of the volume nodes
237  for(ModelPart::NodesContainerType::iterator in = volumeNodes.begin(); in!=volumeNodes.end(); in++)
238  {
239  //each node has three coords
240  base=count*3;
241  vol_nodes[base]=in->X();
242  vol_nodes[base+1]=in->Y();
243  vol_nodes[base+2]=in->Z();
244  in->FastGetSolutionStepValue(COUNTER)=count;
245  count++;
246  }
247  //compute the largest edge of an element in the volume mesh
248  double h_max=0.0;
249  double h_real;
250  for(ModelPart::NodesContainerType::iterator in = volumeNodes.begin(); in!=volumeNodes.end(); in++)
251  {
252  if((in->GetValue(NEIGHBOUR_NODES)).size() != 0)
253  {
254  double xc = in->X();
255  double yc = in->Y();
256  double zc = in->Z();
257 
258  double h = 10000000.0;
259  for( GlobalPointersVector< Node >::iterator i = in->GetValue(NEIGHBOUR_NODES).begin();
260  i != in->GetValue(NEIGHBOUR_NODES).end(); i++)
261  {
262  double x = i->X();
263  double y = i->Y();
264  double z = i->Z();
265  double l = (x-xc)*(x-xc);
266  l += (y-yc)*(y-yc);
267  l += (z-zc)*(z-zc);
268 
269  //if(l>h) h = l;
270  if(l<h) h = l;
271  }
272 
273  h = sqrt(h);
274 
275  if (h>h_max)
276  h_max=h;
277 
278  }
279 
280  }
281 
282  KRATOS_WATCH(h_max)
283  //the search radius should be at least 4 times the element size
284  search_radius=4.0*h_max;
285  KRATOS_WATCH("=========================EMBEDDED=INPUT=INFO================================================================")
286  KRATOS_WATCH(n_skin_faces)
287  KRATOS_WATCH(n_skin_nodes)
288  KRATOS_WATCH(n_vol_nodes)
289  KRATOS_WATCH(search_radius)
290 
291  if (search_radius<=0.0)
292  KRATOS_THROW_ERROR(std::logic_error,"error: YOUR SEARCH RADIUS FOR FINDING INTERSECTIONS IS ZERO OR NEGATIVE!!!!!! CHECK IF NODAL H WAS COMPUTED","");
293  unsigned int TDim=3;
294  void* hinput=GetGidInputHandleWithBoundaryMesh(TDim, n_skin_nodes, skin_nodes,n_skin_faces,skin_faces, 3);
295  //void* hinput=GetGidInputHandleWithBoundaryMesh(3,8,coord,12,conec,3);
296  AddNodesInMesh(hinput, n_vol_nodes, vol_nodes);
297 
299  boost::timer distance_calc_time;
300 
301  void* hout=GetGidOutputHandle();
302 
303 
304 
305  //GiDML_GetNodesDistanceInTetrahedraMesh(hinput, hout); 1 - cuadrado, 0 - con signo
306  GiDML_GetNodesDistanceRadiusInTetrahedraMesh(hinput, hout, search_radius, 0);
307  std::cout << "Distance from embedded object: calculation time = " << distance_calc_time.elapsed() << std::endl;
308  KRATOS_WATCH("============================================================================================================")
309 
310  double* distances=NULL;
311  //compute the distances using GiD library
312  distances=new double[n_vol_nodes];
313  distances=GetAttributesOfNodes(hout);
314 
315  //store the distances in the nodes of KRATOS
316  //count=0;
317  for(ModelPart::NodesContainerType::iterator in = volumeNodes.begin(); in!=volumeNodes.end(); in++)
318  {
319  //each node has three coords
320  count=in->FastGetSolutionStepValue(COUNTER);
321  in->FastGetSolutionStepValue(DISTANCE)=distances[count];
322  }
323 
324  //clearing memory
325  delete [] vol_nodes; // When done, free memory pointed to by a.
326  delete [] skin_nodes;
327  delete [] skin_faces;
328  delete [] distances;
329  vol_nodes=NULL;
330  skin_nodes=NULL;
331  skin_faces=NULL;
332  distances=NULL;
333 
334  //now we assign to the nodes that lie outside of the search radius the correct sign.
335  temp=0;
336  double max_dist=0;
337  for(ModelPart::NodesContainerType::iterator in = volumeNodes.begin(); in!=volumeNodes.end(); in++)
338  {
339  temp=in->FastGetSolutionStepValue(DISTANCE);
340  if (temp>max_dist)
341  max_dist=temp;
342  }
343  KRATOS_WATCH(max_dist)
344  const double default_distance=max_dist;//search_radius+1.0;
345 
346 
347  for(ModelPart::NodesContainerType::iterator in = volumeNodes.begin(); in!=volumeNodes.end(); in++)
348  {
349  double distance;
350  double distance_temp;
351  distance=in->FastGetSolutionStepValue(DISTANCE);
352  if (distance==default_distance)
353  {
354  //KRATOS_WATCH(distance)
355  GlobalPointersVector< Node >& neighb = in->GetValue(NEIGHBOUR_NODES);
356  bool inner_elem=false;
357  //int i=0;
358  //while (neighb[i]>0 && i<neighb.size())
359  //{
360  //i++;
361  //}
362  //if (i<neighb.size()) //if there was a node with a negative distance in the patch, set this distance to all the nodes (except for it
363  for (unsigned int i=0; i<neighb.size(); i++)
364  {
365  distance_temp=neighb[i].FastGetSolutionStepValue(DISTANCE);
366  if (distance_temp<0.0)
367  {
368  inner_elem=true;
369  }
370  }
371  if (inner_elem==true)
372  {
373  for (unsigned int i=0; i<neighb.size(); i++)
374  {
375  if (neighb[i].FastGetSolutionStepValue(DISTANCE)==default_distance)
376  neighb[i].FastGetSolutionStepValue(DISTANCE)=-default_distance;
377  }
378  }
379 
380 
381  }
382  }
383  bool uncertain=true;
384  while (uncertain==true)
385  {
386  uncertain=false;
387  for(ModelPart::NodesContainerType::iterator in = volumeNodes.begin(); in!=volumeNodes.end(); in++)
388  {
389  double distance;
390  double distance_temp;
391  distance=in->FastGetSolutionStepValue(DISTANCE);
392  if (distance==-default_distance)
393  {
394  GlobalPointersVector< Node >& neighb= in->GetValue(NEIGHBOUR_NODES);
395  for (unsigned int i=0; i<neighb.size(); i++)
396  {
397  distance_temp=neighb[i].FastGetSolutionStepValue(DISTANCE);
398  if (distance_temp==default_distance)
399  {
400  neighb[i].FastGetSolutionStepValue(DISTANCE)=-default_distance;
401  KRATOS_WATCH("Second round of negative nodes")
402  uncertain=true;
403  }
404 
405  }
406 
407  }
408 
409  }
410  }
411 
412 
413  KRATOS_CATCH("")
414  }
415 
416 
420 
421 
425 
426 
430 
432  virtual std::string Info() const
433  {
434  return "EmbeddedMeshLocatorProcess";
435  }
436 
438  virtual void PrintInfo(std::ostream& rOStream) const
439  {
440  rOStream << "EmbeddedMeshLocatorProcess";
441  }
442 
444  virtual void PrintData(std::ostream& rOStream) const
445  {
446  }
447 
448 
452 
453 
455 
456 protected:
459 
460 
464 
465 
469 
470 
474 
475 
479 
480 
484 
485 
489 
490 
492 
493 private:
496 
497 
501  ModelPart& mr_model_part;
502 
503 
504 
508 
512 
513 
517 
518 
522 
523 
527 
529  EmbeddedMeshLocatorProcess& operator=(EmbeddedMeshLocatorProcess const& rOther) {};
530 
532  //EmbeddedMeshLocatorProcess(EmbeddedMeshLocatorProcess const& rOther);
533 
534 
536 
537 }; // Class EmbeddedMeshLocatorProcess
538 
540 
543 
544 
548 
549 
551 inline std::istream& operator >> (std::istream& rIStream,
553 
555 inline std::ostream& operator << (std::ostream& rOStream,
556  const EmbeddedMeshLocatorProcess& rThis)
557 {
558  rThis.PrintInfo(rOStream);
559  rOStream << std::endl;
560  rThis.PrintData(rOStream);
561 
562  return rOStream;
563 }
565 
566 
567 } // namespace Kratos.
568 
569 #endif // KRATOS_EMBEDDED_LOCATOR_PROCESS_INCLUDED defined
570 
571 
Short class definition.
Definition: embedded_mesh_locator_process.h:109
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: embedded_mesh_locator_process.h:444
KRATOS_CLASS_POINTER_DEFINITION(EmbeddedMeshLocatorProcess)
Pointer definition of EmbeddedMeshLocatorProcess.
virtual std::string Info() const
Turn back information as a string.
Definition: embedded_mesh_locator_process.h:432
EmbeddedMeshLocatorProcess(ModelPart &model_part)
Default constructor.
Definition: embedded_mesh_locator_process.h:122
virtual ~EmbeddedMeshLocatorProcess()
Destructor.
Definition: embedded_mesh_locator_process.h:128
void operator()()
Definition: embedded_mesh_locator_process.h:137
void Locate(ModelPart &embedded_model_part)
Definition: embedded_mesh_locator_process.h:149
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: embedded_mesh_locator_process.h:438
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: global_pointers_vector.h:79
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
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
The base class for all processes in Kratos.
Definition: process.h:49
virtual void Execute()
Execute method is used to execute the Process algorithms.
Definition: process.h:101
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_WATCH(variable)
Definition: define.h:806
#define KRATOS_TRY
Definition: define.h:109
double * GetAttributesOfNodes(GiDOutput_Handle hdl_gout)
void * GetGidOutputHandle()
GiDInput_Handle GetGidInputHandleWithBoundaryMesh(int ndime, int nlen, double *coords, int flen, int *faces, int type_faces_mesh)
void AddNodesInMesh(GiDInput_Handle hdl_gin, int nlen, double *coord)
void GiDML_GetNodesDistanceRadiusInTetrahedraMesh(GiDInput_Handle hdl_gin, GiDOutput_Handle hdl_gout, double Radius, int cuadratic_distances)
z
Definition: GenerateWind.py:163
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
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
model_part
Definition: face_heat.py:14
y
Other simbols definition.
Definition: generate_axisymmetric_navier_stokes_element.py:54
h
Definition: generate_droplet_dynamics.py:91
int count
Definition: generate_frictional_mortar_condition.py:212
float temp
Definition: rotating_cone.py:85
float xc
Definition: rotating_cone.py:77
float yc
Definition: rotating_cone.py:78
x
Definition: sensitivityMatrix.py:49
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17