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.
manage_selected_elements_process.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosPfemApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: July 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_MANAGE_SELECTED_ELEMENTS_PROCESS_H_INCLUDED)
11 #define KRATOS_MANAGE_SELECTED_ELEMENTS_PROCESS_H_INCLUDED
12 
13 
14 // System includes
15 
16 // External includes
17 
18 // Project includes
19 #include "includes/model_part.h"
21 #include "processes/process.h"
23 
24 namespace Kratos
25 {
26 
29 
31 
37 {
38 public:
41 
43 
46 
50 
51  ManageSelectedElementsProcess(ModelPart& rModelPart) : Process(Flags()) , mrModelPart(rModelPart)
52  {
53  }
54 
57 
58 
62 
64  void operator()()
65  {
66  Execute();
67  }
68 
72 
73 
75  void Execute() override
76  {
77  }
78 
81  void ExecuteInitialize() override
82  {
83  }
84 
87  void ExecuteBeforeSolutionLoop() override
88  {
90 
91  double Radius = 0.0;
92  //BOUNDARY flag must be set in model part nodes
93  mBoundingBox = SpatialBoundingBox(mrModelPart,Radius,0.1);
94 
95  KRATOS_CATCH("")
96  }
97 
98 
101  {
102  KRATOS_TRY
103 
104  const int nelements = mrModelPart.NumberOfElements();
105 
106  if (nelements != 0)
107  {
108  ModelPart::ElementsContainerType::iterator it_begin = mrModelPart.ElementsBegin();
109 
110  #pragma omp parallel for
111  for (int i = 0; i < nelements; ++i)
112  {
113  ModelPart::ElementsContainerType::iterator it = it_begin + i;
114 
115  if( it->Is(FLUID) ){
116 
117  GeometryType& rGeometry = it->GetGeometry();
118  const unsigned int number_of_nodes = rGeometry.size();
119  unsigned int selected_nodes = 0;
120  for(unsigned int j=0; j<number_of_nodes; ++j)
121  {
122  if(rGeometry[j].Is(SELECTED))
123  ++selected_nodes;
124  }
125 
126  if(selected_nodes == number_of_nodes){
127  it->Set(SELECTED,true);
128  it->Set(ACTIVE,false);
129  }
130  }
131  }
132  }
133 
134  KRATOS_CATCH("")
135  }
136 
139  {
140  KRATOS_TRY
141 
142  const int nelements = mrModelPart.NumberOfElements();
143 
144  if (nelements != 0)
145  {
146  ModelPart::ElementsContainerType::iterator it_begin = mrModelPart.ElementsBegin();
147 
148  //(set on nodes, not in parallel)
149  for (int i = 0; i < nelements; ++i)
150  {
151  ModelPart::ElementsContainerType::iterator it = it_begin + i;
152 
153  if( it->Is(FLUID) && it->Is(SELECTED) ){
154 
155  GeometryType& rGeometry = it->GetGeometry();
156  const unsigned int number_of_nodes = rGeometry.size();
157 
158  for(unsigned int j=0; j<number_of_nodes; ++j)
159  {
160  rGeometry[j].Set(SELECTED,true);
161  }
162  it->Set(SELECTED,false);
163  it->Set(ACTIVE,true);
164  }
165  }
166  }
167 
168  const int nnodes = mrModelPart.NumberOfNodes();
169 
170  if (nnodes != 0)
171  {
172  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.NodesBegin();
173 
174  #pragma omp parallel for
175  for (int i = 0; i < nnodes; ++i)
176  {
177  ModelPart::NodesContainerType::iterator it = it_begin + i;
178 
179  if( it->Is(SELECTED) ){
180 
181  if( norm_2(it->FastGetSolutionStepValue(VELOCITY)) > 1.5 * norm_2(it->FastGetSolutionStepValue(VELOCITY,1)) ||
182  norm_2(it->FastGetSolutionStepValue(ACCELERATION)) > 1.5 * norm_2(it->FastGetSolutionStepValue(ACCELERATION,1)) ){
183 
184  // std::cout<<"PRE POSITION "<<it->Coordinates()<<" ACCELERATION "<<it->FastGetSolutionStepValue(ACCELERATION)<<std::endl;
185  // std::cout<<"DISPLACEMENT "<<it->FastGetSolutionStepValue(DISPLACEMENT)<<" VELOCITY "<<it->FastGetSolutionStepValue(VELOCITY)<<std::endl;
186 
187  noalias(it->FastGetSolutionStepValue(VELOCITY)) = it->FastGetSolutionStepValue(VELOCITY,1);
188  noalias(it->FastGetSolutionStepValue(ACCELERATION)) = it->FastGetSolutionStepValue(ACCELERATION,1);
189  noalias(it->Coordinates()) -= it->FastGetSolutionStepValue(DISPLACEMENT);
190  noalias(it->FastGetSolutionStepValue(DISPLACEMENT)) = it->FastGetSolutionStepValue(DISPLACEMENT,1);
191  noalias(it->Coordinates()) += it->FastGetSolutionStepValue(DISPLACEMENT);
192 
193  // std::cout<<"POST POSITION "<<it->Coordinates()<<" ACCELERATION "<<it->FastGetSolutionStepValue(ACCELERATION)<<std::endl;
194  // std::cout<<"DISPLACEMENT "<<it->FastGetSolutionStepValue(DISPLACEMENT)<<" VELOCITY "<<it->FastGetSolutionStepValue(VELOCITY)<<std::endl;
195 
196  //std::cout<<" SELECTED Node ["<<it->Id()<<"] Displacement"<<it->FastGetSolutionStepValue(DISPLACEMENT)<<std::endl;
197 
198  }
199 
200  //check if free surface nodes are outside the bounding box
201  if( it->Is(FREE_SURFACE) ){
202  if( !mBoundingBox.IsInside( it->Coordinates() ) ){
203  it->Set(TO_ERASE,true);
204  std::cout<<" SELECTED to erase "<<std::endl;
205  }
206  }
207 
208  it->Set(SELECTED,false);
209  }
210 
211 
212  }
213  }
214  KRATOS_CATCH("")
215  }
216 
217 
219  void ExecuteBeforeOutputStep() override
220  {
221  }
222 
223 
225  void ExecuteAfterOutputStep() override
226  {
227  }
228 
229 
232  void ExecuteFinalize() override
233  {
234  }
235 
236 
240 
241 
245 
246 
250 
252  std::string Info() const override
253  {
254  return "ManageSelectedElementsProcess";
255  }
256 
258  void PrintInfo(std::ostream& rOStream) const override
259  {
260  rOStream << "ManageSelectedElementsProcess";
261  }
262 
264  void PrintData(std::ostream& rOStream) const override
265  {
266  }
267 
268 
273 
274 protected:
275 
284 
287 
301 
302 private:
303 
309 
310  ModelPart& mrModelPart;
311 
312  SpatialBoundingBox mBoundingBox;
313 
323 
326 
327 
337 
338 }; // Class ManageSelectedElementsProcess
339 
340 
342 
345 
346 
350 
351 
353 inline std::istream& operator >> (std::istream& rIStream,
355 
357 inline std::ostream& operator << (std::ostream& rOStream,
358  const ManageSelectedElementsProcess& rThis)
359 {
360  rThis.PrintInfo(rOStream);
361  rOStream << std::endl;
362  rThis.PrintData(rOStream);
363 
364  return rOStream;
365 }
367 
368 
369 } // namespace Kratos.
370 
371 #endif // KRATOS_MANAGE_SELECTED_ELEMENTS_PROCESS_H_INCLUDED defined
Definition: flags.h:58
bool Is(Flags const &rOther) const
Definition: flags.h:274
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
Process for managing the time integration of variables for selected elements.
Definition: manage_selected_elements_process.hpp:37
void ExecuteFinalizeSolutionStep() override
this function will be executed at every time step AFTER performing the solve phase
Definition: manage_selected_elements_process.hpp:138
void ExecuteAfterOutputStep() override
this function will be executed at every time step AFTER writing the output
Definition: manage_selected_elements_process.hpp:225
void ExecuteBeforeOutputStep() override
this function will be executed at every time step BEFORE writing the output
Definition: manage_selected_elements_process.hpp:219
ManageSelectedElementsProcess(ModelPart &rModelPart)
Definition: manage_selected_elements_process.hpp:51
void ExecuteInitialize() override
Definition: manage_selected_elements_process.hpp:81
KRATOS_CLASS_POINTER_DEFINITION(ManageSelectedElementsProcess)
Pointer definition of ManageSelectedElementsProcess.
std::string Info() const override
Turn back information as a string.
Definition: manage_selected_elements_process.hpp:252
void operator()()
This operator is provided to call the process as a function and simply calls the Execute method.
Definition: manage_selected_elements_process.hpp:64
void ExecuteFinalize() override
Definition: manage_selected_elements_process.hpp:232
void ExecuteBeforeSolutionLoop() override
Definition: manage_selected_elements_process.hpp:87
void Execute() override
Execute method is used to execute the ManageSelectedElementsProcess algorithms.
Definition: manage_selected_elements_process.hpp:75
ModelPart::ElementType::GeometryType GeometryType
Definition: manage_selected_elements_process.hpp:42
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: manage_selected_elements_process.hpp:258
void ExecuteInitializeSolutionStep() override
this function will be executed at every time step BEFORE performing the solve phase
Definition: manage_selected_elements_process.hpp:100
ManageSelectedElementsProcess(ManageSelectedElementsProcess const &rOther)
Copy constructor.
virtual ~ManageSelectedElementsProcess()
Destructor.
Definition: manage_selected_elements_process.hpp:56
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: manage_selected_elements_process.hpp:264
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
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
SizeType NumberOfNodes(IndexType ThisIndex=0) const
Definition: model_part.h:341
The base class for all processes in Kratos.
Definition: process.h:49
Short class definition.
Definition: spatial_bounding_box.hpp:48
virtual bool IsInside(const PointType &rPoint, double &rCurrentTime, double Radius=0)
Definition: spatial_bounding_box.hpp:604
#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
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
int j
Definition: quadrature.py:648
int nnodes
Definition: sensitivityMatrix.py:24
integer i
Definition: TensorModule.f:17