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.
morton_partitioning_process.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3 KratosPFEMApplication
4 A library based on:
5 Kratos
6 A General Purpose Software for Multi-Physics Finite Element Analysis
7 Version 1.0 (Released on march 05, 2007).
8 
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 
16 
17 Permission is hereby granted, free of charge, to any person obtaining
18 a copy of this software and associated documentation files (the
19 "Software"), to deal in the Software without restriction, including
20 without limitation the rights to use, copy, modify, merge, publish,
21 distribute, sublicense and/or sell copies of the Software, and to
22 permit persons to whom the Software is furnished to do so, subject to
23 the following condition:
24 
25 Distribution of this code for any commercial purpose is permissible
26 ONLY BY DIRECT ARRANGEMENT WITH THE COPYRIGHT OWNERS.
27 
28 The above copyright notice and this permission notice shall be
29 included in all copies or substantial portions of the Software.
30 
31 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
34 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
35 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
36 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
37 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 
39 ==============================================================================
40 */
41 
42 //
43 // Project Name: Kratos
44 // Last Modified by: $Author: rrossi $
45 // Date: $Date: 2009-01-15 11:11:35 $
46 // Revision: $Revision: 1.6 $
47 //
48 //
49 
50 
51 #pragma once
52 
53 // System includes
54 
55 // Project includes
56 #include "includes/io.h"
57 #include "processes/process.h"
58 
59 namespace Kratos
60 {
61 
64 
68 
69 
73 
77 
81 
83 
87  : public Process
88 {
89 public:
92 
93  typedef idx_t idxtype;
94 
97 
98  typedef std::size_t SizeType;
99  typedef std::size_t IndexType;
100  typedef std::vector<idxtype> PartitionIndicesType;
101 
105 
108  IO::NodesContainerType& rNodesContainer,
109  PartitionIndicesType& rNodesPartitions,
110  PartitionIndicesType& rElementsPartitions,
111  SizeType NumberOfPartitions, int Dimension = 3)
112  : mrElementsConnectivities(rElementsConnectivities),
113  mrNodesContainer(rNodesContainer),
114  mrNodesPartitions(rNodesPartitions),
115  mrElementsPartitions(rElementsPartitions),
116  mNumberOfPartitions(NumberOfPartitions),
117  mDimension(Dimension)
118  {
119  }
120 
128  mDimension(rOther.mDimension)
129  {
130  }
131 
134  {
135  }
136 
137 
141 
142  void operator()()
143  {
144  Execute();
145  }
146 
147 
151 
152  void Execute() override
153  {
154  KRATOS_TRY;
155 
156  if(mNumberOfPartitions < 2) // There is no need to partition it and just reading the input
157  {
158  return;
159  }
160 
161  int number_of_elements = mrElementsConnectivities.size();
162 
163  int number_of_nodes = 0;
164  int real_r_of_nodes = 0;
165  // calculating number of nodes considering sequencial numbering!! We can get it from input for no sequencial one. Pooyan.
166  for(IO::ConnectivitiesContainerType::iterator i_element = mrElementsConnectivities.begin() ; i_element != mrElementsConnectivities.end() ; i_element++)
167  for(IO::ConnectivitiesContainerType::value_type::iterator i_node_id = i_element->begin() ; i_node_id != i_element->end() ; i_node_id++)
168  {
169  if(static_cast<int>(*i_node_id) > number_of_nodes)
170  number_of_nodes = *i_node_id;
171 
172  real_r_of_nodes++;
173  }
174 
175  //verify that all of the nodes exist
176  std::vector< bool > aux(number_of_nodes,false);
177  // calculating number of nodes considering sequencial numbering!! We can get it from input for no sequencial one. Pooyan.
178  for(IO::ConnectivitiesContainerType::iterator i_element = mrElementsConnectivities.begin() ; i_element != mrElementsConnectivities.end() ; i_element++)
179  for(IO::ConnectivitiesContainerType::value_type::iterator i_node_id = i_element->begin() ; i_node_id != i_element->end() ; i_node_id++)
180  {
181  aux[static_cast<int>(*i_node_id)-1] = true;
182  }
183 
184  mrElementsPartitions.resize(number_of_elements);
185  mrNodesPartitions.resize(number_of_nodes);
186 
187  idxtype* epart = &(*(mrElementsPartitions.begin()));
188  idxtype* npart = &(*(mrNodesPartitions.begin()));
189 
190  AssignPartition(number_of_nodes, real_r_of_nodes, npart, epart);
191 
192  KRATOS_CATCH("")
193  }
194 
195 
199 
200 
204 
205 
209 
211  std::string Info() const override
212  {
213  return "MortonPartitioningProcess";
214  }
215 
217  void PrintInfo(std::ostream& rOStream) const override
218  {
219  rOStream << "MortonPartitioningProcess";
220  }
221 
223  void PrintData(std::ostream& rOStream) const override
224  {
225  }
226 
227 
231 
232 
234 
235 protected:
238 
239 
243 
250 
251 
255 
256 
260 
261  void AssignPartition(SizeType NumberOfNodes, SizeType NumberOfElements, idxtype* NPart, idxtype* EPart)
262  {
263  for(SizeType i_element = 0 ; i_element < NumberOfElements ; i_element++)
264  {
265  for(IO::ConnectivitiesContainerType::value_type::iterator i_node = mrElementsConnectivities[i_element].begin() ;
266  i_node != mrElementsConnectivities[i_element].end() ; i_node++)
267  {
268  //IO::NodesContainerType::iterator i_nod = mrNodesContainer.begin() + (*i_node-1);
269 
270  NPart[(*i_node-1)] = i_element%mNumberOfPartitions;
271  EPart[i_element] = i_element%mNumberOfPartitions;
272  }
273  }
274  }
275 
279 
280 
284 
285 
289 
290 
292 
293 private:
296 
297 
301 
305 
309 
310 
314 
315 
319 
320 
324 
326  MortonPartitioningProcess& operator=(MortonPartitioningProcess const& rOther);
327 
329  //MortonGraphPartitioningProcess(MortonPartitioningProcess const& rOther);
330 
331 
333 
334 }; // Class MortonGraphPartitioningProcess
335 
337 
340 
341 
345 
346 
348 inline std::istream& operator >> (std::istream& rIStream,
350 
352 inline std::ostream& operator << (std::ostream& rOStream,
353  const MortonPartitioningProcess& rThis)
354 {
355  rThis.PrintInfo(rOStream);
356  rOStream << std::endl;
357  rThis.PrintData(rOStream);
358 
359  return rOStream;
360 }
362 
363 } // namespace Kratos.
std::vector< std::vector< std::size_t > > ConnectivitiesContainerType
Definition: io.h:91
Short class definition.
Definition: morton_partitioning_process.h:88
std::string Info() const override
Turn back information as a string.
Definition: morton_partitioning_process.h:211
IO::NodesContainerType & mrNodesContainer
Definition: morton_partitioning_process.h:245
SizeType mDimension
Definition: morton_partitioning_process.h:249
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: morton_partitioning_process.h:217
KRATOS_CLASS_POINTER_DEFINITION(MortonPartitioningProcess)
Pointer definition of MortonPartitioningProcess.
MortonPartitioningProcess(MortonPartitioningProcess const &rOther)
Copy constructor.
Definition: morton_partitioning_process.h:122
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: morton_partitioning_process.h:223
std::vector< idxtype > PartitionIndicesType
Definition: morton_partitioning_process.h:100
IO::ConnectivitiesContainerType & mrElementsConnectivities
Definition: morton_partitioning_process.h:244
idx_t idxtype
Definition: morton_partitioning_process.h:93
MortonPartitioningProcess(IO::ConnectivitiesContainerType &rElementsConnectivities, IO::NodesContainerType &rNodesContainer, PartitionIndicesType &rNodesPartitions, PartitionIndicesType &rElementsPartitions, SizeType NumberOfPartitions, int Dimension=3)
Default constructor.
Definition: morton_partitioning_process.h:107
std::size_t IndexType
Definition: morton_partitioning_process.h:99
PartitionIndicesType & mrElementsPartitions
Definition: morton_partitioning_process.h:247
SizeType mNumberOfPartitions
Definition: morton_partitioning_process.h:248
void AssignPartition(SizeType NumberOfNodes, SizeType NumberOfElements, idxtype *NPart, idxtype *EPart)
Definition: morton_partitioning_process.h:261
std::size_t SizeType
Definition: morton_partitioning_process.h:98
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: morton_partitioning_process.h:152
virtual ~MortonPartitioningProcess()
Destructor.
Definition: morton_partitioning_process.h:133
void operator()()
Definition: morton_partitioning_process.h:142
PartitionIndicesType & mrNodesPartitions
Definition: morton_partitioning_process.h:246
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
The base class for all processes in Kratos.
Definition: process.h:49
#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
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