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.
interpolate_sw_to_pfem_utility.hpp
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|w
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Andrea Montanino
11 //
12 
13 #pragma once
14 
15 // System includes
16 #include <fstream>
17 #include <iostream>
18 #include <cmath>
19 
20 // Project includes
21 #include "geometries/geometry.h"
22 #include "includes/define.h"
23 #include "includes/model_part.h"
25 #include "utilities/openmp_utils.h"
27 #include "utilities/math_utils.h"
28 
29 // Application includes
31 
32 namespace Kratos
33 {
34 
36 {
37 
38 protected:
39 
41 
43  {
47  };
48 
49 public:
50 
52 
55 
57 
60 
62 
63  void InterpolateVariables (ModelPart& rPfemModelPart, ModelPart& rSWModelPart)
64  {
65 
66  const std::size_t NNodesSW = static_cast<int>(rSWModelPart.Nodes().size());
67  ModelPart::NodesContainerType::iterator node_beginSW = rSWModelPart.NodesBegin();
68 
69  const std::size_t NNodesPfem = static_cast<int>(rPfemModelPart.Nodes().size());
70  ModelPart::NodesContainerType::iterator node_beginPfem = rPfemModelPart.NodesBegin();
71 
72  double distance, distance_to_first_neigh_node, distance_to_second_neigh_node;
73  double ratio, ratio1,ratio2;
74  double tol = 1e-4;
75  double Tol = 5.0;
76  double Tol2 = Tol*Tol;
77 
78  int first_neigh_node, second_neigh_node;
79 
80  double height, vertical_velocity, topography;
82 
83  for(std::size_t i = 0; i < NNodesPfem; i++) {
84  ModelPart::NodesContainerType::iterator it_node = node_beginPfem + i;
85 
86  distance_to_first_neigh_node = 1e32;
87  distance_to_second_neigh_node = 1e32;
88 
89  for (std::size_t j = 0; j < NNodesSW; j++){
90  ModelPart::NodesContainerType::iterator jt_node = node_beginSW + j;
91 
92  distance = (it_node->X() - jt_node->X())*(it_node->X() - jt_node->X()) + (it_node->Y() - jt_node->Y())*(it_node->Y() - jt_node->Y());
93  if (distance < distance_to_first_neigh_node){
94  distance_to_first_neigh_node = distance;
95  first_neigh_node = j;
96  }
97  }
98 
99  for (std::size_t j = 0; j < NNodesSW; j++){
100  ModelPart::NodesContainerType::iterator jt_node = node_beginSW + j;
101 
102  distance = (it_node->X() - jt_node->X())*(it_node->X() - jt_node->X()) + (it_node->Y() - jt_node->Y())*(it_node->Y() - jt_node->Y());
103  if ((distance < distance_to_second_neigh_node) & (distance > distance_to_first_neigh_node)){
104  distance_to_second_neigh_node = distance;
105  second_neigh_node = j;
106  }
107  }
108 
109  ModelPart::NodesContainerType::iterator jt_node1 = node_beginSW + first_neigh_node;
110  ModelPart::NodesContainerType::iterator jt_node2 = node_beginSW + second_neigh_node;
111 
112  double dx = std::abs(jt_node1->X() - jt_node2->X());
113  double dy = std::abs(jt_node1->Y() - jt_node2->Y());
114 
115  if (distance_to_first_neigh_node*distance_to_first_neigh_node > Tol2*(dx*dx + dy*dy)){
116  KRATOS_WARNING("Interpolate_sw_to_pfem") << "PFEM node quite far from SW output interface " << std::endl;
117  }
118 
119  if (((dx > tol) & (dy < tol)) | ((dx < tol) & (dy > tol))){
120  if ((dx > tol) & (dy < tol)){
121  ratio = (it_node->X() - jt_node2->X())/(jt_node1->X() - jt_node2->X());
122  } else if ((dx < tol) & (dy > tol)){
123  ratio = (it_node->Y() - jt_node2->Y())/(jt_node1->Y() - jt_node2->Y());
124  }
125 
126  velocity = ratio*(jt_node1->GetValue(VELOCITY) - jt_node2->GetValue(VELOCITY)) + jt_node2->GetValue(VELOCITY);
127  height = ratio*(jt_node1->GetValue(HEIGHT) - jt_node2->GetValue(HEIGHT)) + jt_node2->GetValue(HEIGHT);
128  vertical_velocity = ratio*(jt_node1->GetValue(VERTICAL_VELOCITY) - jt_node2->GetValue(VERTICAL_VELOCITY)) + jt_node2->GetValue(VERTICAL_VELOCITY);
129  topography = ratio*(jt_node1->GetValue(TOPOGRAPHY) - jt_node2->GetValue(TOPOGRAPHY)) + jt_node2->GetValue(TOPOGRAPHY);
130  } else {
131  ratio1 = (it_node->X() - jt_node2->X())/(jt_node1->X() - jt_node2->X());
132  ratio2 = (it_node->Y() - jt_node2->Y())/(jt_node1->Y() - jt_node2->Y());
133 
134  velocity = ratio1*(jt_node1->GetValue(VELOCITY) - jt_node2->GetValue(VELOCITY)) + jt_node2->GetValue(VELOCITY);
135  height = ratio1*(jt_node1->GetValue(HEIGHT) - jt_node2->GetValue(HEIGHT)) + jt_node2->GetValue(HEIGHT);
136  vertical_velocity = ratio1*(jt_node1->GetValue(VERTICAL_VELOCITY) - jt_node2->GetValue(VERTICAL_VELOCITY)) + jt_node2->GetValue(VERTICAL_VELOCITY);
137  topography = ratio1*(jt_node1->GetValue(TOPOGRAPHY) - jt_node2->GetValue(TOPOGRAPHY)) + jt_node2->GetValue(TOPOGRAPHY);
138 
139  velocity += ratio2*(jt_node1->GetValue(VELOCITY) - jt_node2->GetValue(VELOCITY)) + jt_node2->GetValue(VELOCITY);
140  height += ratio2*(jt_node1->GetValue(HEIGHT) - jt_node2->GetValue(HEIGHT)) + jt_node2->GetValue(HEIGHT);
141  vertical_velocity += ratio2*(jt_node1->GetValue(VERTICAL_VELOCITY) - jt_node2->GetValue(VERTICAL_VELOCITY)) + jt_node2->GetValue(VERTICAL_VELOCITY);
142  topography += ratio2*(jt_node1->GetValue(TOPOGRAPHY) - jt_node2->GetValue(TOPOGRAPHY)) + jt_node2->GetValue(TOPOGRAPHY);
143 
144  velocity = 0.5*velocity;
145  height = 0.5*height;
146  vertical_velocity = 0.5*vertical_velocity;
147  topography = 0.5*topography;
148  }
149 
150  it_node->GetValue(HEIGHT) = height;
151  it_node->GetValue(VELOCITY) = velocity;
152  it_node->GetValue(VERTICAL_VELOCITY) = vertical_velocity;
153  it_node->GetValue(TOPOGRAPHY) = topography;
154 
155  }
156  };
157 
158 protected:
159 
161 
162 
163 
165 
166 private:
168 
169 
170 
171 }; // Class InterpolateSwToPfemUtility
172 
173 } // namespace Kratos.
174 
175 
Definition: interpolate_sw_to_pfem_utility.hpp:36
KRATOS_CLASS_POINTER_DEFINITION(InterpolateSwToPfemUtility)
virtual ~InterpolateSwToPfemUtility()
Destructor.
Definition: interpolate_sw_to_pfem_utility.hpp:59
void InterpolateVariables(ModelPart &rPfemModelPart, ModelPart &rSWModelPart)
Definition: interpolate_sw_to_pfem_utility.hpp:63
InterpolateSwToPfemUtility()
Constructor.
Definition: interpolate_sw_to_pfem_utility.hpp:54
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
#define KRATOS_WARNING(label)
Definition: logger.h:265
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
float velocity
Definition: PecletTest.py:54
int tol
Definition: hinsberg_optimization.py:138
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31
Basic Structs for the utility -----------------------------------------------------------------------...
Definition: interpolate_sw_to_pfem_utility.hpp:43
double ColumnSize
Definition: interpolate_sw_to_pfem_utility.hpp:46
int NRows
Definition: interpolate_sw_to_pfem_utility.hpp:45
int NColumns
Definition: interpolate_sw_to_pfem_utility.hpp:45
double SectionSize
Definition: interpolate_sw_to_pfem_utility.hpp:46
double X_max
Definition: interpolate_sw_to_pfem_utility.hpp:44
double RowSize
Definition: interpolate_sw_to_pfem_utility.hpp:46
double Y_max
Definition: interpolate_sw_to_pfem_utility.hpp:44
double Y_min
Definition: interpolate_sw_to_pfem_utility.hpp:44
double Z_min
Definition: interpolate_sw_to_pfem_utility.hpp:44
double Z_max
Definition: interpolate_sw_to_pfem_utility.hpp:44
int NSections
Definition: interpolate_sw_to_pfem_utility.hpp:45
double X_min
Definition: interpolate_sw_to_pfem_utility.hpp:44