Loading...
Searching...
No Matches
PABLO_example_00008.cpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#if BITPIT_ENABLE_MPI==1
26#include <mpi.h>
27#endif
28
29#include "bitpit_PABLO.hpp"
30
31#if BITPIT_ENABLE_MPI==1
32#include "PABLO_userDataComm.hpp"
33#include "PABLO_userDataLB.hpp"
34#endif
35
36using namespace std;
37using namespace bitpit;
38
39// =================================================================================== //
59// =================================================================================== //
60
64void run()
65{
66 int iter = 0;
67
69 PabloUniform pablo8(2);
70
72 int idx = 0;
73 pablo8.setBalance(idx,false);
74
76 for (iter=1; iter<6; iter++){
77 pablo8.adaptGlobalRefine();
78 }
79
81 double xc, yc;
82 xc = yc = 0.5;
83 double radius = 0.25;
84
86 uint32_t nocts = pablo8.getNumOctants();
87 uint32_t nghosts = pablo8.getNumGhosts();
88 vector<double> oct_data(nocts, 0.0), ghost_data(nghosts, 0.0);
89
91 for (unsigned int i=0; i<nocts; i++){
93 vector<array<double,3> > nodes = pablo8.getNodes(i);
95 array<double,3> center = pablo8.getCenter(i);
96 for (int j=0; j<4; j++){
97 double x = nodes[j][0];
98 double y = nodes[j][1];
99 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
100 oct_data[i] = (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0));
101 }
102 }
103 }
104
106 iter = 0;
107 pablo8.updateConnectivity();
108 pablo8.writeTest("pablo00008_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
109
111 int start = 1;
112 for (iter=start; iter<start+2; iter++){
113 for (unsigned int i=0; i<nocts; i++){
115 vector<array<double,3> > nodes = pablo8.getNodes(i);
117 array<double,3> center = pablo8.getCenter(i);
118 for (int j=0; j<4; j++){
119 double x = nodes[j][0];
120 double y = nodes[j][1];
121 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
122 if (center[0]<=xc){
123
125 pablo8.setMarker(i,1);
126 }
127 else{
128
130 pablo8.setMarker(i,-1);
131 }
132 }
133 }
134 }
135
137 vector<double> oct_data_new;
138 vector<uint32_t> mapper;
139 vector<bool> isghost;
140 pablo8.adapt(true);
141 nocts = pablo8.getNumOctants();
142 oct_data_new.resize(nocts, 0.0);
143
147 for (uint32_t i=0; i<nocts; i++){
148 pablo8.getMapping(i, mapper, isghost);
149 if (pablo8.getIsNewC(i)){
150 for (int j=0; j<4; j++){
151 if (isghost[j]){
152 oct_data_new[i] += ghost_data[mapper[j]]/4;
153 }
154 else{
155 oct_data_new[i] += oct_data[mapper[j]]/4;
156 }
157 }
158 }
159 else{
160 oct_data_new[i] += oct_data[mapper[0]];
161 }
162 }
163
165 pablo8.updateConnectivity();
166 pablo8.writeTest("pablo00008_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data_new);
167
168 oct_data = oct_data_new;
169 }
170
171#if BITPIT_ENABLE_MPI==1
174 uint8_t levels = 4;
175 UserDataLB<vector<double> > data_lb(oct_data,ghost_data);
176 pablo8.loadBalance(data_lb, levels);
177#endif
178
180 pablo8.updateConnectivity();
181 pablo8.writeTest("pablo00008_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
182}
183
187int main(int argc, char *argv[])
188{
189#if BITPIT_ENABLE_MPI==1
190 MPI_Init(&argc,&argv);
191#else
192 BITPIT_UNUSED(argc);
193 BITPIT_UNUSED(argv);
194#endif
195
196 int nProcs;
197 int rank;
198#if BITPIT_ENABLE_MPI==1
199 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
200 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
201#else
202 nProcs = 1;
203 rank = 0;
204#endif
205
206 // Initialize the logger
207 log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
208 log::cout() << log::fileVerbosity(log::LEVEL_INFO);
210
211 // Run the example
212 try {
213 run();
214 } catch (const std::exception &exception) {
215 log::cout() << exception.what();
216 exit(1);
217 }
218
219#if BITPIT_ENABLE_MPI==1
220 MPI_Finalize();
221#endif
222}
void initialize(log::Mode mode, bool reset, int nProcesses, int rank)
Definition logger.cpp:1268
PABLO Uniform is an example of user class derived from ParaTree to map ParaTree in a uniform (square/...
std::array< T, d > pow(std::array< T, d > &x, double p)
#define BITPIT_UNUSED(variable)
Definition compiler.hpp:63
Logger & cout(log::Level defaultSeverity, log::Visibility defaultVisibility)
Definition logger.cpp:1705
LoggerManipulator< log::Level > fileVerbosity(const log::Level &threshold)
Definition logger.cpp:2120
Logger & disableConsole(Logger &logger, const log::Level &level)
Definition logger.cpp:2165
LoggerManager & manager()
Definition logger.cpp:1685
--- layout: doxygen_footer ---