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.
find_conditions_neighbours_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 
14 #if !defined(KRATOS_FIND_CONDITIONS_NEIGHBOURS_PROCESS_H_INCLUDED )
15 #define KRATOS_FIND_CONDITIONS_NEIGHBOURS_PROCESS_H_INCLUDED
16 
17 
18 
19 // System includes
20 #include <string>
21 #include <iostream>
22 
23 
24 // External includes
25 
26 
27 // Project includes
28 #include "includes/define.h"
29 #include "processes/process.h"
30 #include "includes/node.h"
31 #include "includes/condition.h"
32 #include "includes/model_part.h"
33 
34 
35 namespace Kratos
36 {
37 
40 
46 
47 
51 
55 
59 
61 
64  : public Process
65 {
66 public:
69 
72 
76 
81  FindConditionsNeighboursProcess(ModelPart& model_part, int TDim, unsigned int avg_conds = 10)
82  : mr_model_part(model_part)
83  {
84  mavg_conds = avg_conds;
85  mTDim=TDim;
86 // mavg_nodes = avg_nodes;
87  }
88 
91  {
92  }
93 
94 
98 
99  void operator()()
100  {
101  Execute();
102  }
103 
104 
108 
109  void Execute() override
110  {
111  NodesContainerType& rNodes = mr_model_part.Nodes();
112  ConditionsContainerType& rConds = mr_model_part.Conditions();
113 
114  //first of all the neighbour nodes and conditions array are initialized to the guessed size
115  //and empties the old entries
116  for(NodesContainerType::iterator in = rNodes.begin(); in!=rNodes.end(); in++)
117  {
118  (in->GetValue(NEIGHBOUR_CONDITIONS)).reserve(mavg_conds);
119  GlobalPointersVector<Condition >& rC = in->GetValue(NEIGHBOUR_CONDITIONS);
120  rC.erase(rC.begin(),rC.end() );
121  }
122  for(ConditionsContainerType::iterator ic = rConds.begin(); ic!=rConds.end(); ic++)
123  {
124  (ic->GetValue(NEIGHBOUR_CONDITIONS)).reserve(3);
125  GlobalPointersVector<Condition >& rC = ic->GetValue(NEIGHBOUR_CONDITIONS);
126  rC.erase(rC.begin(),rC.end() );
127  }
128 
129  //add the neighbour conditions to all the nodes in the mesh
130  for(ConditionsContainerType::iterator ic = rConds.begin(); ic!=rConds.end(); ic++)
131  {
132  Condition::GeometryType& pGeom = ic->GetGeometry();
133  for(unsigned int i = 0; i < pGeom.size(); i++)
134  {
135  //KRATOS_WATCH( pGeom[i] );
136  (pGeom[i].GetValue(NEIGHBOUR_CONDITIONS)).push_back( Condition::WeakPointer( *(ic.base()) ) );
137  //KRATOS_WATCH( (pGeom[i].GetValue(NEIGHBOUR_CONDITIONS)).size() );
138  }
139  }
140 
141  //adding the neighbouring conditions to the condition
142  //loop over faces
143  if (mTDim==3)
144  {
145  for(ConditionsContainerType::iterator ic = rConds.begin(); ic!=rConds.end(); ic++)
146  {
147  //face nodes
148  Geometry<Node >& geom = (ic)->GetGeometry();
149  //vector of the 3 faces around the given face
150  (ic->GetValue(NEIGHBOUR_CONDITIONS)).resize(3);
151  GlobalPointersVector< Condition >& neighb_faces = ic->GetValue(NEIGHBOUR_CONDITIONS);
152  //neighb_face is the vector containing pointers to the three faces around ic
153  //neighb_face[0] = neighbour face over edge 1-2 of element ic;
154  //neighb_face[1] = neighbour face over edge 2-0 of element ic;
155  //neighb_face[2] = neighbour face over edge 0-1 of element ic;
156  neighb_faces(0) = CheckForNeighbourFaces(geom[1].Id(), geom[2].Id(), geom[1].GetValue(NEIGHBOUR_CONDITIONS), ic->Id());
157  neighb_faces(1) = CheckForNeighbourFaces(geom[2].Id(), geom[0].Id(), geom[2].GetValue(NEIGHBOUR_CONDITIONS), ic->Id());
158  neighb_faces(2) = CheckForNeighbourFaces(geom[0].Id(), geom[1].Id(), geom[0].GetValue(NEIGHBOUR_CONDITIONS), ic->Id());
159  }
160  }
161  }
162 
163 
165  {
166  NodesContainerType& rNodes = mr_model_part.Nodes();
167  for(NodesContainerType::iterator in = rNodes.begin(); in!=rNodes.end(); in++)
168  {
169  GlobalPointersVector<Condition >& rC = in->GetValue(NEIGHBOUR_CONDITIONS);
170  rC.erase(rC.begin(),rC.end());
171  }
172  ConditionsContainerType& rConds = mr_model_part.Conditions();
173  for(ConditionsContainerType::iterator ic = rConds.begin(); ic!=rConds.end(); ic++)
174  {
175  GlobalPointersVector<Condition >& rC = ic->GetValue(NEIGHBOUR_CONDITIONS);
176  rC.erase(rC.begin(),rC.end());
177  }
178 
179  }
180 
184 
185 
189 
190 
194 
196  std::string Info() const override
197  {
198  return "FindConditionsNeighboursProcess";
199  }
200 
202  void PrintInfo(std::ostream& rOStream) const override
203  {
204  rOStream << "FindConditionsNeighboursProcess";
205  }
206 
208  void PrintData(std::ostream& rOStream) const override
209  {
210  }
211 
212 
216 
217 
219 
220 protected:
223 
224 
228 
229 
233 
234 
238 
239 
243 
244 
248 
249 
253 
254 
256 
257 private:
260 
261 
265  ModelPart& mr_model_part;
266  unsigned int mavg_conds;
267  int mTDim;
268 // unsigned int mavg_nodes;
269 
270 
274 
275  //******************************************************************************************
276  //******************************************************************************************
277  template< class TDataType > void AddUniqueWeakPointer
278  (GlobalPointersVector< TDataType >& v, const typename TDataType::WeakPointer candidate)
279  {
281  typename GlobalPointersVector< TDataType >::iterator endit = v.end();
282  while ( i != endit && (i)->Id() != (candidate.lock())->Id())
283  {
284  i++;
285  }
286  if( i == endit )
287  {
288  v.push_back(candidate);
289  }
290 
291  }
292 
293  Condition::WeakPointer CheckForNeighbourFaces (unsigned int Id_1, unsigned int Id_2, GlobalPointersVector< Condition >& neighbour_face, unsigned int face)
294  {
295  //look for the faces around node Id_1
296  for( GlobalPointersVector< Condition >::iterator i =neighbour_face.begin(); i != neighbour_face.end(); i++)
297  {
298  //look for the nodes of the neighbour faces
299  Geometry<Node >& neigh_face_geometry = (i)->GetGeometry();
300  for( unsigned int node_i = 0 ; node_i < neigh_face_geometry.size(); node_i++)
301  {
302  if (neigh_face_geometry[node_i].Id() == Id_2)
303  {
304  if(i->Id() != face)
305  {
306  return *(i.base());
307  }
308  }
309  }
310  }
311  return Condition::WeakPointer();
312  }
316 
317 
321 
322 
326 
327 
331 
334 
336  //FindConditionsNeighboursProcess(FindConditionsNeighboursProcess const& rOther);
337 
338 
340 
341 }; // Class FindConditionsNeighboursProcess
342 
344 
347 
348 
352 
353 
355 inline std::istream& operator >> (std::istream& rIStream,
357 
359 inline std::ostream& operator << (std::ostream& rOStream,
360  const FindConditionsNeighboursProcess& rThis)
361 {
362  rThis.PrintInfo(rOStream);
363  rOStream << std::endl;
364  rThis.PrintData(rOStream);
365 
366  return rOStream;
367 }
369 
370 
371 } // namespace Kratos.
372 
373 #endif // KRATOS_FIND_CONDITIONS_NEIGHBOURS_PROCESS_H_INCLUDED defined
374 
375 
Short class definition.
Definition: find_conditions_neighbours_process.h:65
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: find_conditions_neighbours_process.h:208
void operator()()
Definition: find_conditions_neighbours_process.h:99
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: find_conditions_neighbours_process.h:202
~FindConditionsNeighboursProcess() override
Destructor.
Definition: find_conditions_neighbours_process.h:90
void ClearNeighbours()
Definition: find_conditions_neighbours_process.h:164
KRATOS_CLASS_POINTER_DEFINITION(FindConditionsNeighboursProcess)
Pointer definition of FindConditionsNeighboursProcess.
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: find_conditions_neighbours_process.h:109
FindConditionsNeighboursProcess(ModelPart &model_part, int TDim, unsigned int avg_conds=10)
Definition: find_conditions_neighbours_process.h:81
std::string Info() const override
Turn back information as a string.
Definition: find_conditions_neighbours_process.h:196
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: geometry.h:627
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
iterator erase(iterator pos)
Definition: global_pointers_vector.h:351
iterator begin()
Definition: global_pointers_vector.h:221
iterator end()
Definition: global_pointers_vector.h:229
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
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
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
The base class for all processes in Kratos.
Definition: process.h:49
Parameters GetValue(Parameters &rParameters, const std::string &rEntry)
Definition: add_kratos_parameters_to_python.cpp:53
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
ModelPart::NodesContainerType NodesContainerType
Definition: find_conditions_neighbours_process.h:44
ModelPart::ConditionsContainerType ConditionsContainerType
Definition: find_conditions_neighbours_process.h:45
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
v
Definition: generate_convection_diffusion_explicit_element.py:114
integer i
Definition: TensorModule.f:17