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.
old_cable_net_mpc_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 // this process does not work at the moment
16 // base class was moved to the core
17 
18 
19 #ifndef CABLE_NET_MPC_PROCESS_H
20 #define CABLE_NET_MPC_PROCESS_H
21 
22 // System includes
23 #include <string>
24 #include <iostream>
25 
26 // External includes
27 
28 // Project includes
29 #include "includes/node.h"
30 #include "includes/define.h"
31 #include "processes/process.h"
32 #include "utilities/math_utils.h"
35 
36 namespace Kratos
37 {
38 
39 class CableNetMpcProcess : public ApplyMultipointConstraintsProcess
40 {
41  public:
42 
43  typedef Node NodeType;
44  typedef Node ::Pointer NodeTypePointer;
45  typedef std::vector<NodeTypePointer> NodeVector;
47  typedef std::vector<NodeTypePointer>::iterator NodeIterator;
48  typedef std::vector<double> DoubleVector;
49  typedef DoubleVector::iterator DoubleVectorIterator;
50  typedef std::size_t SizeType;
54 
55  // Type definitions for tree-search
58 
59 
62 
65  Parameters rParameters) : ApplyMultipointConstraintsProcess(model_part,rParameters)
66  {}
67 
68 
74  {
75  ModelPart &master_model_part = mrModelPart.GetSubModelPart(mParameters["master_sub_model_part_name"].GetString());
76  ModelPart &slave_model_part = mrModelPart.GetSubModelPart(mParameters["slave_sub_model_part_name"].GetString());
77  double neighbor_search_radius = mParameters["neighbor_search_radius"].GetDouble();
78  const int bucket_size = mParameters["bucket_size"].GetInt();
79  NodesArrayType &r_nodes_master = master_model_part.Nodes();
80  NodesArrayType &r_nodes_slave = slave_model_part.Nodes();
81 
82  NodeVector master_node_list(r_nodes_master.size());
83  this->CreateListOfNodesOfMasterSubModelPart(master_node_list);
84 
85  KDTree::Pointer search_tree =
86  Kratos::shared_ptr<KDTree>(new KDTree(master_node_list.begin(), master_node_list.end(), bucket_size));
87 
88 
89  //this->CreateSpringElements(master_model_part,slave_model_part);
90 
91  const int max_number_of_neighbors = 2;
92  for(NodeType& node_i : r_nodes_slave)
93  {
94  neighbor_search_radius = mParameters["neighbor_search_radius"].GetDouble();
95  SizeType number_of_neighbors = 0;
96  NodeVector neighbor_nodes( max_number_of_neighbors );
97  DoubleVector resulting_squared_distances( max_number_of_neighbors );
98 
99 /* number_of_neighbors = search_tree->SearchInRadius( node_i,
100  neighbor_search_radius,
101  neighbor_nodes.begin(),
102  resulting_squared_distances.begin(),
103  max_number_of_neighbors ); */
104 
105  int nr_searches(0);
106  while (number_of_neighbors<1)
107  {
108  nr_searches++;
109  neighbor_nodes.clear();
110  resulting_squared_distances.clear();
111  //1.) find nodal neighbors
112  number_of_neighbors = search_tree->SearchInRadius( node_i,
113  neighbor_search_radius,
114  neighbor_nodes.begin(),
115  resulting_squared_distances.begin(),
116  max_number_of_neighbors );
117 
118  (nr_searches>1000.0)?(KRATOS_ERROR << "found no neighbor for slave node "
119  << node_i.Id() << " " << node_i.Coordinates() << std::endl):neighbor_search_radius*=2.0;
120  }
121 
122  if(mParameters["debug_info"].GetBool()) std::cout << "nr.ne.: " << number_of_neighbors << std::endl;
123  DoubleVector list_of_weights( number_of_neighbors, 0.0 );
124 
125  this->CalculateNodalWeights(resulting_squared_distances,list_of_weights,number_of_neighbors);
126  this->CoupleSlaveToNeighborMasterNodes(node_i,neighbor_nodes,list_of_weights,number_of_neighbors);
127  this->SetmIsInitialized(true);
128 
129  //DoubleVector list_of_weights2( number_of_neighbors, 0.0 );
130  //test new function to calculate weight
131  //this->ComputeWeightForAllNeighbors( node_i, neighbor_nodes, number_of_neighbors, list_of_weights2);
132 
133 
134  //if(mParameters["debug_info"].GetBool()) KRATOS_WATCH(list_of_weights);
135 
136  //std::cout << "slave: " << node_i.Id() << " has " << number_of_neighbors << " masters " << std::endl;
137  //std::cout << "###################################################" << std::endl;
138  }
139  }
140 
141 
145  void CoupleSlaveToNeighborMasterNodes(const NodeType& rCurrentSlaveNode,
146  const NodeVector& rNeighborNodes, const DoubleVector& rNodalNeighborWeights,
147  const SizeType& rNumberOfNeighbors)
148  {
149  ModelPart &master_model_part = mrModelPart.GetSubModelPart(mParameters["master_sub_model_part_name"].GetString());
150  ModelPart &slave_model_part = mrModelPart.GetSubModelPart(mParameters["slave_sub_model_part_name"].GetString());
151  NodesArrayType &r_nodes_master = master_model_part.Nodes();
152  NodesArrayType &r_nodes_slave = slave_model_part.Nodes();
153 
154 
155  for(SizeType dof_iterator=0;dof_iterator<mParameters["variable_names"].size();++dof_iterator)
156  {
157  VariableComponentType current_dof = KratosComponents<VariableComponentType>::Get(mParameters["variable_names"][dof_iterator].GetString());
158 
159  for(SizeType master_iterator =0;master_iterator<rNumberOfNeighbors;++master_iterator)
160  {
161 
162 
163  ApplyMultipointConstraintsProcess::AddMasterSlaveRelationWithNodesAndVariableComponents(
164  r_nodes_master[rNeighborNodes[master_iterator]->Id()],current_dof,
165  r_nodes_slave[rCurrentSlaveNode.Id()],current_dof,rNodalNeighborWeights[master_iterator],0);
166 
167  if(mParameters["debug_info"].GetBool()){
168  std::cout << rNeighborNodes[master_iterator]->Id() << "-----" << rCurrentSlaveNode.Id() << "-----" << rNodalNeighborWeights[master_iterator] << std::endl;
169  }
170 
171  } // each master node
172  } // each dof
173 
174  }
175 
176 
177 
182  {
183  ModelPart &master_model_part = mrModelPart.GetSubModelPart(mParameters["master_sub_model_part_name"].GetString());
184  NodesArrayType &r_nodes = master_model_part.Nodes();
185 
186  MasterNodeList.resize(r_nodes.size());
187  auto i_begin = master_model_part.NodesBegin();
188 
189  for (SizeType i(0);i<r_nodes.size();++i)
190  {
191  NodeTypePointer pnode = *((i_begin+i).base());
192  MasterNodeList[i] = pnode;
193  }
194  }
195 
196 
200  void CalculateNodalWeights(const DoubleVector& rResultingSquaredDistances, DoubleVector& rNodalNeighborWeights, const SizeType& rNumberOfNeighbors)
201  {
202  const double numerical_limit = std::numeric_limits<double>::epsilon();
203  double total_nodal_distance = 0.00;
204 
205  if((rNumberOfNeighbors==1)&&(std::abs(rResultingSquaredDistances[0])<numerical_limit))
206  {rNodalNeighborWeights[0] = 1.00;}
207  else
208  {
209  for (SizeType i=0;i<rNumberOfNeighbors;++i) total_nodal_distance+=std::sqrt(rResultingSquaredDistances[i]);
210  for (SizeType i=0;i<rNumberOfNeighbors;++i)
211  {
212  double current_weight = std::sqrt(rResultingSquaredDistances[rNumberOfNeighbors-(i+1)])/total_nodal_distance;
213  (current_weight>numerical_limit) ? (rNodalNeighborWeights[i]=current_weight) : (rNodalNeighborWeights[i]=0.00);
214  //rNodalNeighborWeights[i] = std::sqrt(rResultingSquaredDistances[rNumberOfNeighbors-(i+1)])/total_nodal_distance;
215  }
216  }
217  }
218 
219 
220 
222  {
223  if (this->GetmIsInitialized())
224  {if (mParameters["reform_every_step"].GetBool())
225  {this->CoupleModelParts();}
226  }
227  else this->CoupleModelParts();
228  }
229 
230 
231 
232  void CreateSpringElements(ModelPart &rMasterModelPart,ModelPart &rSlaveModelPart)
233  {
234  //idea: calculate internal force from each slave truss ->
235  // use this force to couple node to beam with K = f_int_slave_truss * nu_friction
236  auto slave_element_begin = rSlaveModelPart.ElementsBegin();
237  const ElementsArrayType& r_slave_elements = rSlaveModelPart.Elements();
238  const NodesArrayType& r_slave_nodes = rSlaveModelPart.Nodes();
239 
240  auto master_element_begin = rMasterModelPart.ElementsBegin();
241  const ElementsArrayType& r_master_elements = rMasterModelPart.Elements();
242  const NodesArrayType& r_master_nodes = rMasterModelPart.Nodes();
243 
244 
245  for (SizeType slave_element_counter(0);slave_element_counter<r_slave_elements.size();slave_element_counter++)
246  {
247  auto slave_current_element = slave_element_begin+slave_element_counter;
248  const GeometryType& r_element_geometry = slave_current_element->GetGeometry();
249  const NodeType& r_node_a = r_element_geometry[0];
250  const NodeType& r_node_b = r_element_geometry[1];
251 
252  VectorType right_hand_side = ZeroVector(6);
253  ProcessInfo &r_current_process_info = rSlaveModelPart.GetProcessInfo();
254  slave_current_element->CalculateRightHandSide(right_hand_side,r_current_process_info);
255  const double internal_truss_force = std::sqrt(std::pow(right_hand_side[3],2)+
256  std::pow(right_hand_side[4],2)+std::pow(right_hand_side[5],2));
257 
258  const double friction_coeff = 10.0;
259  const double friction_stiff = friction_coeff*internal_truss_force;
260 
261  for (SizeType master_element_counter(0);master_element_counter<r_master_elements.size();master_element_counter++)
262  {
263  }
264  }
265  }
266 
267 
270 
272  NodeVector& neighbor_nodes,
273  SizeType number_of_neighbors,
274  DoubleVector& list_of_weights)
275  {
276 
277 
278  double total_length(0.0);
279  DoubleVector temp_vector(number_of_neighbors,0.00);
280  KRATOS_WATCH(number_of_neighbors);
281  KRATOS_WATCH(temp_vector);
282  for(SizeType neighbor_itr = 0 ; neighbor_itr<number_of_neighbors ; neighbor_itr++)
283  {
284  ModelPart::NodeType& neighbor_node = *neighbor_nodes[neighbor_itr];
285  double current_length(this->CalculateCurrentLength(design_node,neighbor_node));
286 
287  temp_vector[neighbor_itr] = current_length;
288  total_length += current_length;
289  }
290 
291  for(SizeType i=0;i<number_of_neighbors;++i) temp_vector[i] /= total_length;
292  for(SizeType i=0;i<number_of_neighbors;++i) list_of_weights[i] = temp_vector[number_of_neighbors-(i+1)];
293  }
294 
296  const double du =
297  rNodeJ.FastGetSolutionStepValue(DISPLACEMENT_X) -
298  rNodeI.FastGetSolutionStepValue(DISPLACEMENT_X);
299  const double dv =
300  rNodeJ.FastGetSolutionStepValue(DISPLACEMENT_Y) -
301  rNodeI.FastGetSolutionStepValue(DISPLACEMENT_Y);
302  const double dw =
303  rNodeJ.FastGetSolutionStepValue(DISPLACEMENT_Z) -
304  rNodeI.FastGetSolutionStepValue(DISPLACEMENT_Z);
305  const double dx = rNodeJ.X0() - rNodeI.X0();
306  const double dy = rNodeJ.Y0() - rNodeI.Y0();
307  const double dz = rNodeJ.Z0() - rNodeI.Z0();
308  const double l = std::sqrt((du + dx) * (du + dx) + (dv + dy) * (dv + dy) +
309  (dw + dz) * (dw + dz));
310  return l;
311  }
312  //<------- ////////////////
314 
315 
316 
317 
318  void SetmIsInitialized(const bool& check) {this->mIsInitialized = check;}
319  bool GetmIsInitialized() const {return this->mIsInitialized;}
320 
321 
322 
323  protected:
324 
325  private:
326 
327  bool mIsInitialized = false;
328 
329 }; // Class
330 
331 }; // namespace
332 
333 #endif
Short class definition.
Definition: bucket.h:57
Definition: old_cable_net_mpc_process.h:40
void CalculateNodalWeights(const DoubleVector &rResultingSquaredDistances, DoubleVector &rNodalNeighborWeights, const SizeType &rNumberOfNeighbors)
This function re-calculates the weights used in mpc.
Definition: old_cable_net_mpc_process.h:200
double CalculateCurrentLength(ModelPart::NodeType &rNodeI, ModelPart::NodeType &rNodeJ)
Definition: old_cable_net_mpc_process.h:295
std::vector< NodeTypePointer > NodeVector
Definition: old_cable_net_mpc_process.h:45
Element::VectorType VectorType
Definition: old_cable_net_mpc_process.h:52
Node NodeType
Definition: old_cable_net_mpc_process.h:43
void ComputeWeightForAllNeighbors(ModelPart::NodeType &design_node, NodeVector &neighbor_nodes, SizeType number_of_neighbors, DoubleVector &list_of_weights)
Definition: old_cable_net_mpc_process.h:271
Node ::Pointer NodeTypePointer
Definition: old_cable_net_mpc_process.h:44
Element::GeometryType GeometryType
Definition: old_cable_net_mpc_process.h:51
void CoupleSlaveToNeighborMasterNodes(const NodeType &rCurrentSlaveNode, const NodeVector &rNeighborNodes, const DoubleVector &rNodalNeighborWeights, const SizeType &rNumberOfNeighbors)
This function couples nodes by calling the parent class functions.
Definition: old_cable_net_mpc_process.h:145
KRATOS_CLASS_POINTER_DEFINITION(CableNetMpcProcess)
Pointer definition of ApplyMultipointConstraintsProcess.
std::vector< NodeTypePointer >::iterator NodeIterator
Definition: old_cable_net_mpc_process.h:47
ModelPart::ElementsContainerType ElementsArrayType
Definition: old_cable_net_mpc_process.h:53
std::size_t SizeType
Definition: old_cable_net_mpc_process.h:50
bool GetmIsInitialized() const
Definition: old_cable_net_mpc_process.h:319
void ExecuteInitializeSolutionStep() override
Definition: old_cable_net_mpc_process.h:221
Bucket< 3, NodeType, NodeVector, NodeTypePointer, NodeIterator, DoubleVectorIterator > BucketType
Definition: old_cable_net_mpc_process.h:56
void CreateListOfNodesOfMasterSubModelPart(NodeVector &MasterNodeList)
This function creates a NodeVector of the master nodes to be used for the Kd tree.
Definition: old_cable_net_mpc_process.h:181
ModelPart::NodesContainerType NodesArrayType
Definition: old_cable_net_mpc_process.h:46
void SetmIsInitialized(const bool &check)
Definition: old_cable_net_mpc_process.h:318
std::vector< double > DoubleVector
Definition: old_cable_net_mpc_process.h:48
CableNetMpcProcess(ModelPart &model_part, Parameters rParameters)
Constructor.
Definition: old_cable_net_mpc_process.h:64
Tree< KDTreePartition< BucketType > > KDTree
Definition: old_cable_net_mpc_process.h:57
void CreateSpringElements(ModelPart &rMasterModelPart, ModelPart &rSlaveModelPart)
Definition: old_cable_net_mpc_process.h:232
DoubleVector::iterator DoubleVectorIterator
Definition: old_cable_net_mpc_process.h:49
void CoupleModelParts()
This function finds neighbor nodes for each slave node and couples the nodes this is the main functio...
Definition: old_cable_net_mpc_process.h:73
Geometry base class.
Definition: geometry.h:71
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
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
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
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
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
double & Z0()
Definition: node.h:576
double & X0()
Definition: node.h:568
double & Y0()
Definition: node.h:572
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
A generic tree data structure for spatial partitioning.
Definition: tree.h:190
#define KRATOS_WATCH(variable)
Definition: define.h:806
#define KRATOS_ERROR
Definition: exception.h:161
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
std::shared_ptr< T > shared_ptr
Definition: smart_pointers.h:27
model_part
Definition: face_heat.py:14
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17