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.
lagrangian_inlet_process.h
Go to the documentation of this file.
1 
2 /*
3 ==============================================================================
4 KratosPFEMApplication
5 A library based on:
6 Kratos
7 A General Purpose Software for Multi-Physics Finite Element Analysis
8 Version 1.0 (Released on march 05, 2007).
9 Copyright 2007
10 Pooyan Dadvand, Riccardo Rossi
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 Permission is hereby granted, free of charge, to any person obtaining
16 a copy of this software and associated documentation files (the
17 "Software"), to deal in the Software without restriction, including
18 without limitation the rights to use, copy, modify, merge, publish,
19 distribute, sublicense and/or sell copies of the Software, and to
20 permit persons to whom the Software is furnished to do so, subject to
21 the following condition:
22 Distribution of this code for any commercial purpose is permissible
23 ONLY BY DIRECT ARRANGEMENT WITH THE COPYRIGHT OWNERS.
24 The above copyright notice and this permission notice shall be
25 included in all copies or substantial portions of the Software.
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
29 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
30 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 ==============================================================================
34 */
35 
36 //
37 // Project Name: Kratos
38 // Last Modified by: $Author: rrossi $
39 // Date: $Date: 2007-03-06 10:30:31 $
40 // Revision: $Revision: 1.2 $
41 //
42 //
43 
44 
45 #if !defined(KRATOS_LAGRANGIAN_INLET_PROCESS_INCLUDED )
46 #define KRATOS_LAGRANGIAN_INLET_PROCESS_INCLUDED
47 
48 
49 
50 // System includes
51 #include <string>
52 #include <iostream>
53 #include <algorithm>
54 
55 // External includes
56 
57 
58 // Project includes
59 #include "includes/define.h"
60 #include "processes/process.h"
61 #include "includes/node.h"
62 #include "includes/element.h"
63 #include "includes/model_part.h"
64 
65 namespace Kratos
66 {
67 
70 
74 
75 
79 
83 
87 
89 //adds nodes to the inlet boundary ... every "insertion_time_step" time
94  : public Process
95 {
96 public:
99 
102 
106 
109  : mr_model_part(model_part)
110  {
111  KRATOS_TRY
112  minsertion_time = 0.00;
113  minsertion_time_step = insertion_time_step;
114  //by default we set the inlet vel to 0
115  this->minlet_vel=inlet_vel;
116  KRATOS_CATCH("")
117  }
118 
121  {
122  }
123 
124 
128 
129  void operator()()
130  {
131  Execute();
132  }
133 
134 
138 
139  void Execute() override
140  {
141  KRATOS_TRY;
142  double dt = mr_model_part.GetProcessInfo()[DELTA_TIME];
143 
144  double time = mr_model_part.GetProcessInfo()[TIME];
145 
146  if(minsertion_time == 0.00)
147  {
148  minsertion_time_step = EstimateInsertionTime();
149  minsertion_time = time + minsertion_time_step;
150  }
152  KRATOS_WATCH(minsertion_time)
153  if(time >= minsertion_time)
154  {
155 
156  //detecting number of new nodes
157  int new_nodes_number = 0;
158  for(ModelPart::NodesContainerType::iterator in = mr_model_part.NodesBegin(); in!=mr_model_part.NodesEnd(); in++)
159  {
160  if(in->FastGetSolutionStepValue(IS_LAGRANGIAN_INLET) == 1)
161  new_nodes_number += 1;
162  }
163  KRATOS_WATCH("SHOULD ADD NODES")
164  if(new_nodes_number != 0)
165  {
166  //allocating the memory needed
167  int old_size = mr_model_part.Nodes().size();
168  (mr_model_part.Nodes()).reserve(old_size + new_nodes_number);
169 
170  for(int i = 0; i<old_size; i++)
171  {
172  ModelPart::NodesContainerType::iterator in = mr_model_part.NodesBegin() + i;
173 
174  if(in->FastGetSolutionStepValue(IS_LAGRANGIAN_INLET) == 1)
175  {
176  //first of all set the node as normal fluid (not structure)
177  in->FastGetSolutionStepValue(IS_STRUCTURE) = 0;
178  in->FastGetSolutionStepValue(IS_BOUNDARY) = 0;
179  in->FastGetSolutionStepValue(IS_LAGRANGIAN_INLET) = 0;
180  in->FastGetSolutionStepValue(IS_FREE_SURFACE) = 0;
181  in->Free(DISPLACEMENT_X);
182  in->Free(DISPLACEMENT_Y);
183  in->Free(DISPLACEMENT_Z);
184 
185  //make a copy of the
186  //Node::Pointer new_node = AdaptivityUtils::AddNode(in->X(),in->Y(),in->Z(),mr_model_part);
187  Node::DofsContainerType& reference_dofs = (mr_model_part.NodesBegin())->GetDofs();
188 
189  int id = mr_model_part.Nodes().size();
190  id++;
191  //KRATOS_WATCH(id)
192  double init_pos_x=in->X()-in->FastGetSolutionStepValue(DISPLACEMENT_X);
193  double init_pos_y=in->Y()-in->FastGetSolutionStepValue(DISPLACEMENT_Y);
194  double init_pos_z=in->Z()-in->FastGetSolutionStepValue(DISPLACEMENT_Z);
195 
196  //KRATOS_WATCH(init_pos_x)
197  //KRATOS_WATCH(init_pos_y)
198  //KRATOS_WATCH(init_pos_z)
199 
200  Node::Pointer new_node = mr_model_part.CreateNewNode(id, init_pos_x, init_pos_y, init_pos_z);//in->X(), in->Y(), in->Z());
201 
202  new_node->SetBufferSize(mr_model_part.NodesBegin()->GetBufferSize() );
203  //KRATOS_WATCH(new_node->GetBufferSize())
204 
205  for(Node::DofsContainerType::iterator iii = reference_dofs.begin(); iii != reference_dofs.end(); iii++)
206  {
207  Node::DofType& rDof = *iii;
208  Node::DofType::Pointer p_new_dof = new_node->pAddDof( rDof );
209 
210  (p_new_dof)->FreeDof();
211  //(p_new_dof)->FixDof();
212  // (p_new_dof)->EquationId() = -1;
213  KRATOS_WATCH(" ADDED NODES")
214 
215  }
216 
217 
218  //new_node->X0() = init_pos_x;
219  //new_node->Y0() = init_pos_y;
220  //new_node->Z0() = init_pos_z;
221 
222  //array_1d<double,3>& dnew = new_node->FastGetSolutionStepValue(DISPLACEMENT);
223  //const array_1d<double,3>& d = in->FastGetSolutionStepValue(DISPLACEMENT);
224 
225  //here we read the velocity of the Lagrangian inlet
226  const array_1d<double,3>& inlet_vel = in->FastGetSolutionStepValue(VELOCITY,1);
227 
228  //array_1d<double,3> d=this->minlet_vel*dt;
229  //KRATOS_WATCH(inlet_vel)
231 
232 // size_t sizee = 0;
233  new_node->FastGetSolutionStepValue(DISPLACEMENT)+=d;
234  //KRATOS_WATCH(new_node->FastGetSolutionStepValue(DISPLACEMENT))
235 
236  //new_node->FastGetSolutionStepValue(VELOCITY) = this->minlet_vel;//in->FastGetSolutionStepValue(VELOCITY);
237  //in->FastGetSolutionStepValue(VELOCITY) = this->minlet_vel;//in->FastGetSolutionStepValue(VELOCITY);
238  new_node->FastGetSolutionStepValue(VELOCITY) = inlet_vel;//in->FastGetSolutionStepValue(VELOCITY);
239  in->FastGetSolutionStepValue(VELOCITY) = inlet_vel;//in->FastGetSolutionStepValue(VELOCITY);
240 
241  new_node->FastGetSolutionStepValue(NODAL_AREA) = in->FastGetSolutionStepValue(NODAL_AREA);
242  new_node->FastGetSolutionStepValue(PRESSURE,1) = in->FastGetSolutionStepValue(PRESSURE,1);
243  new_node->FastGetSolutionStepValue(PRESSURE) = in->FastGetSolutionStepValue(PRESSURE);
244  new_node->FastGetSolutionStepValue(BULK_MODULUS) = in->FastGetSolutionStepValue(BULK_MODULUS);
245  new_node->FastGetSolutionStepValue(VISCOSITY) = in->FastGetSolutionStepValue(VISCOSITY);
246  new_node->FastGetSolutionStepValue(DENSITY) = in->FastGetSolutionStepValue(DENSITY);
247  new_node->FastGetSolutionStepValue(BODY_FORCE) = in->FastGetSolutionStepValue(BODY_FORCE);
248  new_node->FastGetSolutionStepValue(IS_FLUID)=1.0;
249  new_node->FastGetSolutionStepValue(IS_BOUNDARY)=1.0;
250  //new_node->FastGetSolutionStepValue(ACCELERATION) = in->FastGetSolutionStepValue(PRESS_PROJ);
251  new_node->Fix(DISPLACEMENT_X);
252  new_node->Fix(DISPLACEMENT_Y);
253  new_node->Fix(DISPLACEMENT_Z);
254 
255  //new_node->FastGetSolutionStepValue(IS_STRUCTURE) = 1;
256  new_node->FastGetSolutionStepValue(IS_LAGRANGIAN_INLET) = 1;
257  double nodal_h = in->FastGetSolutionStepValue(NODAL_H);
258  new_node->FastGetSolutionStepValue(NODAL_H) = nodal_h;
259 
260  }
261  }
262  minsertion_time_step = EstimateInsertionTime();
263  KRATOS_WATCH(minsertion_time_step);
264 
265  //update the time for the next insertion
266  minsertion_time = time + minsertion_time_step;
267 
268  }
269  }
270  //if we do not insert in this step - we simply have to move
271  else
272  {
273  for(ModelPart::NodesContainerType::iterator in = mr_model_part.NodesBegin(); in!=mr_model_part.NodesEnd(); in++)
274  {
275  if(in->FastGetSolutionStepValue(IS_LAGRANGIAN_INLET) == 1)
276  {
277  array_1d<double,3> old_disp=in->FastGetSolutionStepValue(DISPLACEMENT,1);
278  const array_1d<double,3>& inlet_vel = in->FastGetSolutionStepValue(VELOCITY,1);
279  //KRATOS_WATCH(inlet_vel)
280  //array_1d<double,3> inc_disp=this->minlet_vel*dt;
282  in->FastGetSolutionStepValue(DISPLACEMENT)=inc_disp+old_disp;
283  //in->FastGetSolutionStepValue(VELOCITY)=this->minlet_vel;
284  in->FastGetSolutionStepValue(VELOCITY)=inlet_vel;
285  in->Fix(DISPLACEMENT_X);
286  in->Fix(DISPLACEMENT_Y);
287  in->Fix(DISPLACEMENT_Z);
288  }
289 
290  }
291  }
292 
293  KRATOS_CATCH("")
294  }
295 
296 
300 
301 
305 
306 
310 
312  std::string Info() const override
313  {
314  return "LagrangianInletProcess";
315  }
316 
318  void PrintInfo(std::ostream& rOStream) const override
319  {
320  rOStream << "LagrangianInletProcess";
321  }
322 
324  void PrintData(std::ostream& rOStream) const override
325  {
326  }
327 
328 
332 
333 
335 
336 protected:
339 
340 
344 
345 
349 
350 
354 
355 
359 
360 
364 
365 
369 
370 
372 
373 private:
376 
377 
381  ModelPart& mr_model_part;
382  double minsertion_time_step;
383  double minsertion_time;
384  array_1d<double,3> minlet_vel;
385 
386 
390  double EstimateInsertionTime()
391  {
392  KRATOS_TRY
393 
394  double dt_estimate = 100.0;
395 
396  for(ModelPart::NodesContainerType::iterator in = mr_model_part.NodesBegin(); in!=mr_model_part.NodesEnd(); in++)
397  {
398  if(in->FastGetSolutionStepValue(IS_LAGRANGIAN_INLET) == 1)
399  {
400  const array_1d<double,3> v = this->minlet_vel;//in->FastGetSolutionStepValue(VELOCITY);
401  //KRATOS_WATCH("INLET VELOCITY")
402  //KRATOS_WATCH(v)
403  double nodal_h = in->FastGetSolutionStepValue(NODAL_H);
404 
405  //estimating the next time step
406  double normv = norm_2(v);
407  double dtcandidate = nodal_h / normv;
408  KRATOS_WATCH(dtcandidate)
409  if( dtcandidate < dt_estimate)
410  dt_estimate = dtcandidate;
411  dt_estimate*=1.1;
412  KRATOS_WATCH(dt_estimate)
413  }
414  }
415 
416  return dt_estimate;
417 
418  KRATOS_CATCH("");
419  }
420 
424 
425 
429 
430 
434 
435 
439 
441  LagrangianInletProcess& operator=(LagrangianInletProcess const& rOther);
442 
443 
445 
446 }; // Class LagrangianInletProcess
447 
449 
452 
453 
457 
458 
460 inline std::istream& operator >> (std::istream& rIStream,
461  LagrangianInletProcess& rThis);
462 
464 inline std::ostream& operator << (std::ostream& rOStream,
465  const LagrangianInletProcess& rThis)
466 {
467  rThis.PrintInfo(rOStream);
468  rOStream << std::endl;
469  rThis.PrintData(rOStream);
470 
471  return rOStream;
472 }
474 
475 
476 } // namespace Kratos.
477 
478 #endif // KRATOS_LAGRANGIAN_INLET_PROCESS_INCLUDED defined
479 
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
Short class definition.
Definition: lagrangian_inlet_process.h:95
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: lagrangian_inlet_process.h:139
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: lagrangian_inlet_process.h:318
KRATOS_CLASS_POINTER_DEFINITION(LagrangianInletProcess)
Pointer definition of LagrangianInletProcess.
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: lagrangian_inlet_process.h:324
~LagrangianInletProcess() override
Destructor.
Definition: lagrangian_inlet_process.h:120
void operator()()
Definition: lagrangian_inlet_process.h:129
std::string Info() const override
Turn back information as a string.
Definition: lagrangian_inlet_process.h:312
LagrangianInletProcess(ModelPart &model_part, double insertion_time_step, array_1d< double, 3 > inlet_vel)
Default constructor.
Definition: lagrangian_inlet_process.h:108
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
NodeType::Pointer CreateNewNode(int Id, double x, double y, double z, VariablesList::Pointer pNewVariablesList, IndexType ThisIndex=0)
Definition: model_part.cpp:270
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
std::vector< std::unique_ptr< Dof< double > >> DofsContainerType
The DoF container type definition.
Definition: node.h:92
The base class for all processes in Kratos.
Definition: process.h:49
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_WATCH(variable)
Definition: define.h:806
#define KRATOS_TRY
Definition: define.h:109
dt
Definition: DEM_benchmarks.py:173
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
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
time
Definition: face_heat.py:85
model_part
Definition: face_heat.py:14
v
Definition: generate_convection_diffusion_explicit_element.py:114
int d
Definition: ode_solve.py:397
inlet_vel
Definition: script.py:181
integer i
Definition: TensorModule.f:17