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.
graph_coloring_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: Pooyan Dadvand
11 //
12 
13 #if !defined(KRATOS_GRAPH_COLORING_PROCESS_H_INCLUDED )
14 #define KRATOS_GRAPH_COLORING_PROCESS_H_INCLUDED
15 
16 // System includes
17 #include <string>
18 #include <iostream>
19 
20 // External includes
21 
22 // Project includes
23 #include "includes/define.h"
24 #include "processes/process.h"
26 
27 namespace Kratos
28 {
31 
33 
43 {
44 public:
47 
50  typedef std::size_t SizeType;
51  typedef std::size_t IndexType;
52 
56 
60 
62 
77  GraphColoringProcess(int NumberOfPartitions, const GraphType& rDomainsGraph, GraphType& rDomainsColoredGraph, int& rMaxColor):
78  mNumberOfPartitions(NumberOfPartitions), mrMaxColor(rMaxColor), mrDomainsGraph(rDomainsGraph), mrDomainsColoredGraph(rDomainsColoredGraph)
79  {}
80 
82  virtual ~GraphColoringProcess() {}
83 
84 
88 
89  void operator()()
90  {
91  Execute();
92  }
93 
94 
98 
99  void Execute() override
100  {
102  // // Start coloring...
103  // for(SizeType i = 0 ; i < mrDomainsGraph.size1() ; i++) // for each domain
104  // for(SizeType j = i + 1 ; j < mrDomainsGraph.size2() ; j++) // finding neighbor domains
105  // if(mrDomainsGraph(i,j) != 0.00) // domain i has interface with domain j
106  // I should continue the implementation. Pooyan.
107 
108  mrMaxColor = 0;
109  // Initializing the coloered graph. -1 means no connection
110  // TODO: I have to change this part and create this matrix using max color number
111  mrDomainsColoredGraph.resize(mNumberOfPartitions, 2*mNumberOfPartitions,false);
112  mrDomainsColoredGraph = ScalarMatrix(mNumberOfPartitions, 2*mNumberOfPartitions, -1.00);
113 
114  // Start coloring...
115  for(SizeType i = 0 ; i < mrDomainsGraph.size1() ; i++) // for each domain
116  for(SizeType j = i + 1 ; j < mrDomainsGraph.size2() ; j++) // finding neighbor domains
117  if(mrDomainsGraph(i,j) != 0.00) // domain i has interface with domain j
118  for(SizeType color = 0 ; color < mrDomainsColoredGraph.size2() ; color++) // finding color
119  if((mrDomainsColoredGraph(i,color) == -1.00) && (mrDomainsColoredGraph(j,color) == -1.00)) // the first unused color
120  {
121  mrDomainsColoredGraph(i,color) = j;
122  mrDomainsColoredGraph(j,color) = i;
123  if(mrMaxColor < static_cast<int>(color + 1))
124  mrMaxColor = color + 1;
125  break;
126  }
127  }
128 
129 
130 
134 
136  std::string Info() const override
137  {
138  return "GraphColoringProcess";
139  }
140 
142  void PrintInfo(std::ostream& rOStream) const override
143  {
144  rOStream << "GraphColoringProcess";
145  }
146 
148  void PrintData(std::ostream& rOStream) const override
149  {
150  }
151 
152 
156 
157 
159 
160 
161 private:
164 
165 
169 
170  int mNumberOfPartitions;
171  int& mrMaxColor;
172  const GraphType& mrDomainsGraph;
173  GraphType& mrDomainsColoredGraph;
174 
175 
177  GraphColoringProcess& operator=(GraphColoringProcess const& rOther);
178 
180  //GraphColoringProcess(GraphColoringProcess const& rOther);
181 
182 
184 
185 }; // Class GraphColoringProcess
186 
188 
191 
192 
196 
197 
199 inline std::istream& operator >> (std::istream& rIStream,
200  GraphColoringProcess& rThis);
201 
203 inline std::ostream& operator << (std::ostream& rOStream,
204  const GraphColoringProcess& rThis)
205 {
206  rThis.PrintInfo(rOStream);
207  rOStream << std::endl;
208  rThis.PrintData(rOStream);
209 
210  return rOStream;
211 }
213 
214 
215 } // namespace Kratos.
216 
217 #endif // KRATOS_GRAPH_COLORING_PROCESS_H_INCLUDED defined
Getting a graph of connectivities (of domains) and performs a coloring procedure.
Definition: graph_coloring_process.h:43
KRATOS_CLASS_POINTER_DEFINITION(GraphColoringProcess)
Pointer definition of GraphColoringProcess.
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: graph_coloring_process.h:99
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: graph_coloring_process.h:148
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: graph_coloring_process.h:142
std::size_t IndexType
Definition: graph_coloring_process.h:51
std::size_t SizeType
Definition: graph_coloring_process.h:50
virtual ~GraphColoringProcess()
Destructor.
Definition: graph_coloring_process.h:82
DenseMatrix< int > GraphType
Definition: graph_coloring_process.h:55
void operator()()
Definition: graph_coloring_process.h:89
GraphColoringProcess(int NumberOfPartitions, const GraphType &rDomainsGraph, GraphType &rDomainsColoredGraph, int &rMaxColor)
Constructor.
Definition: graph_coloring_process.h:77
std::string Info() const override
Turn back information as a string.
Definition: graph_coloring_process.h:136
Definition: amatrix_interface.h:41
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
The base class for all processes in Kratos.
Definition: process.h:49
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
scalar_matrix< double > ScalarMatrix
Definition: amatrix_interface.h:728
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
color
Definition: all_t_win_vs_m_fixed_error.py:230
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17