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.
apply_weak_sliding_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: Klaus B. Sautter
11 //
12 //
13 
14 
15 
16 #ifndef APPLY_WEAK_SLIDING_PROCESS_H
17 #define APPLY_WEAK_SLIDING_PROCESS_H
18 
19 // System includes
20 #include <string>
21 #include <iostream>
22 
23 // External includes
24 
25 // Project includes
26 #include "includes/node.h"
27 #include "includes/define.h"
28 #include "processes/process.h"
29 #include "utilities/math_utils.h"
33 #include "includes/model_part.h"
34 
35 namespace Kratos
36 {
37 
38 
40  : public Process
41 {
42  public:
43 
44  typedef Node NodeType;
45  typedef Node ::Pointer NodeTypePointer;
46  typedef std::vector<NodeTypePointer> NodeVector;
48  typedef std::vector<NodeTypePointer>::iterator NodeIterator;
49  typedef std::vector<double> DoubleVector;
50  typedef DoubleVector::iterator DoubleVectorIterator;
51  typedef std::size_t SizeType;
52 
53  // Type definitions for tree-search
56 
57 
60 
63  Parameters InputParameters):mrModelPart(rModelPart),mParameters(InputParameters)
64  {
65  KRATOS_TRY;
66  Parameters default_parameters = Parameters(R"(
67  {
68  "model_part_name_slave" : "example_part_slave",
69  "model_part_name_master" : "example_part_master",
70  "computing_model_part_name" : "Structure",
71  "element_id" : 1,
72  "property_id" : 1,
73  "debug_info" : false
74  })" );
75  default_parameters.ValidateAndAssignDefaults(InputParameters);
76 
77  KRATOS_CATCH("")
78  }
79 
82  void ExecuteInitialize() override
83  {
84  KRATOS_TRY;
85  KRATOS_CATCH("");
86  }
87 
90  {
91  KRATOS_TRY;
92  // create elements
93  mCurrentElementId = mParameters["element_id"].GetInt();
94  this->CreateElements();
95  KRATOS_CATCH("");
96  }
97 
100  {
101  KRATOS_TRY;
102  // delete elements and decrease mCurrentElementId
103  for (IndexType element_id=mParameters["element_id"].GetInt();element_id<mCurrentElementId;element_id++)
104  {
105  mrModelPart.RemoveElementFromAllLevels(element_id);
106  }
107  KRATOS_CATCH("");
108  }
109 
110 
111 
113  {
114  KRATOS_TRY;
115  ModelPart &master_model_part = mrModelPart.GetSubModelPart(mParameters["model_part_name_master"].GetString());
116  ModelPart &slave_model_part = mrModelPart.GetSubModelPart(mParameters["model_part_name_slave"].GetString());
117  //ModelPart &computing_model_part = mrModelPart.GetSubModelPart(mParameters["computing_model_part_name"].GetString());
118  NodesArrayType &r_nodes_slave = slave_model_part.Nodes();
119 
120  for(NodeType& node_i : r_nodes_slave)
121  {
122  std::vector<std::size_t> neighbour_nodes = FindNearestNeighbours(node_i);
123 
124  const SizeType number_nodes = 3;
125  std::vector<NodeType::Pointer> element_nodes (number_nodes);
126 
127  element_nodes[0] = master_model_part.pGetNode(neighbour_nodes[0]);
128  element_nodes[1] = master_model_part.pGetNode(neighbour_nodes[1]);
129  element_nodes[2] = slave_model_part.pGetNode(node_i.Id());
130 
131  Triangle3D3 <NodeType> triangle_t ( PointerVector<NodeType>{element_nodes} );
132 
133  const Element& rElem = KratosComponents<Element>::Get("WeakSlidingElement3D3N");
134  Properties::Pointer p_elem_prop = slave_model_part.pGetProperties(mParameters["property_id"].GetInt());
135  Element::Pointer pElem = rElem.Create(mCurrentElementId++, triangle_t, p_elem_prop);
136  mrModelPart.AddElement(pElem);
137  }
138 
139  KRATOS_CATCH("");
140  }
141 
142  std::vector<std::size_t> FindNearestNeighbours(const NodeType& node_i)
143  {
144  KRATOS_TRY;
145  ModelPart &master_model_part = mrModelPart.GetSubModelPart(mParameters["model_part_name_master"].GetString());
146  NodesArrayType &r_nodes_master = master_model_part.Nodes();
147 
148  double distance = 1e12; // better: std::numeric_limits<double>::max()
149  double distance_i = 0.0;
150  std::vector<std::size_t> neighbour_ids = {0,0};
151 
152 
153  for(NodeType& node_j : r_nodes_master)
154  {
155  distance_i = GetNodalDistance(node_i,node_j);
156  if (distance_i<distance)
157  {
158  distance=distance_i;
159  neighbour_ids[0] = node_j.Id();
160  }
161  }
162 
163  distance = 1e12; // better: std::numeric_limits<double>::max()
164 
165  for(NodeType& node_j : r_nodes_master)
166  {
167  if (node_j.Id()==neighbour_ids[0]) continue;
168 
169  distance_i = GetNodalDistance(node_i,node_j);
170  if (distance_i<distance)
171  {
172  distance=distance_i;
173  neighbour_ids[1] = node_j.Id();
174  }
175  }
176 
177  if (mParameters["debug_info"].GetBool())
178  {
179  KRATOS_WATCH(node_i.Id())
180  KRATOS_WATCH(neighbour_ids)
181  std::cout << "_________________________" << std::endl;
182  }
183  return neighbour_ids;
184  KRATOS_CATCH("")
185  }
186 
187  double GetNodalDistance(const NodeType& node_i, const NodeType& node_j)
188  {
189  const array_1d<double, 3> delta_pos =
190  node_j.GetInitialPosition().Coordinates() -
191  node_i.GetInitialPosition().Coordinates() +
192  node_j.FastGetSolutionStepValue(DISPLACEMENT) -
193  node_i.FastGetSolutionStepValue(DISPLACEMENT);
194 
195  const double l = MathUtils<double>::Norm3(delta_pos);
196  return l;
197  }
198 
199  protected:
200 
201  private:
202 
203  ModelPart& mrModelPart;
204  Parameters mParameters;
205  SizeType mCurrentElementId;
206 
207 }; // Class
208 
209 }; // namespace
210 
211 #endif
Definition: apply_weak_sliding_process.h:41
Tree< KDTreePartition< BucketType > > KDTree
Definition: apply_weak_sliding_process.h:55
std::vector< NodeTypePointer > NodeVector
Definition: apply_weak_sliding_process.h:46
void ExecuteFinalizeSolutionStep() override
this function will be executed at every time step AFTER performing the solve phase
Definition: apply_weak_sliding_process.h:99
double GetNodalDistance(const NodeType &node_i, const NodeType &node_j)
Definition: apply_weak_sliding_process.h:187
ModelPart::NodesContainerType NodesArrayType
Definition: apply_weak_sliding_process.h:47
Node ::Pointer NodeTypePointer
Definition: apply_weak_sliding_process.h:45
ApplyWeakSlidingProcess(ModelPart &rModelPart, Parameters InputParameters)
Constructor.
Definition: apply_weak_sliding_process.h:62
std::size_t SizeType
Definition: apply_weak_sliding_process.h:51
std::vector< std::size_t > FindNearestNeighbours(const NodeType &node_i)
Definition: apply_weak_sliding_process.h:142
void ExecuteInitializeSolutionStep() override
this function will be executed at every time step BEFORE performing the solve phase
Definition: apply_weak_sliding_process.h:89
Bucket< 3, NodeType, NodeVector, NodeTypePointer, NodeIterator, DoubleVectorIterator > BucketType
Definition: apply_weak_sliding_process.h:54
DoubleVector::iterator DoubleVectorIterator
Definition: apply_weak_sliding_process.h:50
std::vector< NodeTypePointer >::iterator NodeIterator
Definition: apply_weak_sliding_process.h:48
void ExecuteInitialize() override
Definition: apply_weak_sliding_process.h:82
void CreateElements()
Definition: apply_weak_sliding_process.h:112
std::vector< double > DoubleVector
Definition: apply_weak_sliding_process.h:49
KRATOS_CLASS_POINTER_DEFINITION(ApplyWeakSlidingProcess)
Pointer definition of ApplyMultipointConstraintsProcess.
Node NodeType
Definition: apply_weak_sliding_process.h:44
Short class definition.
Definition: bucket.h:57
Base class for all Elements.
Definition: element.h:60
std::size_t IndexType
Definition: flags.h:74
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
static double Norm3(const TVectorType &a)
Calculates the norm of vector "a" which is assumed to be of size 3.
Definition: math_utils.h:691
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
PropertiesType::Pointer pGetProperties(IndexType PropertiesId, IndexType MeshIndex=0)
Returns the Properties::Pointer corresponding to it's identifier.
Definition: model_part.cpp:664
NodeType::Pointer pGetNode(IndexType NodeId, IndexType ThisIndex=0)
Definition: model_part.h:421
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
void RemoveElementFromAllLevels(IndexType ElementId, IndexType ThisIndex=0)
Definition: model_part.cpp:1090
void AddElement(ElementType::Pointer pNewElement, IndexType ThisIndex=0)
Definition: model_part.cpp:917
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
IndexType Id() const
Definition: node.h:262
const PointType & GetInitialPosition() const
Definition: node.h:559
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
CoordinatesArrayType const & Coordinates() const
Definition: point.h:215
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
The base class for all processes in Kratos.
Definition: process.h:49
A generic tree data structure for spatial partitioning.
Definition: tree.h:190
A three node 3D triangle geometry with linear shape functions.
Definition: triangle_3d_3.h:77
BaseType::Pointer Create(PointsArrayType const &rThisPoints) const override
Creates a new geometry pointer.
Definition: triangle_3d_3.h:358
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_WATCH(variable)
Definition: define.h:806
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
integer l
Definition: TensorModule.f:17