Loading...
Searching...
No Matches
PABLO_example_00009.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// =================================================================================== //
53// =================================================================================== //
54
58void run()
59{
60 int iter = 0;
61
63 PabloUniform pablo9(0,0,0,1,3);
64
66 int idx = 0;
67 pablo9.setBalance(idx,false);
68
70 for (iter=1; iter<6; iter++){
71 pablo9.adaptGlobalRefine();
72 }
73
74#if BITPIT_ENABLE_MPI==1
76 pablo9.loadBalance();
77#endif
78
80 double xc, yc;
81 xc = yc = 0.5;
82 double radius = 0.25;
83
85 uint32_t nocts = pablo9.getNumOctants();
86 uint32_t nghosts = pablo9.getNumGhosts();
87 vector<double> oct_data(nocts, 0.0), ghost_data(nghosts, 0.0);
88
90 for (unsigned int i=0; i<nocts; i++){
92 vector<array<double,3> > nodes = pablo9.getNodes(i);
94 array<double,3> center = pablo9.getCenter(i);
95 for (int j=0; j<8; j++){
96 double x = nodes[j][0];
97 double y = nodes[j][1];
98 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
99 oct_data[i] = (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0));
100 }
101 }
102 }
103
105 iter = 0;
106 pablo9.updateConnectivity();
107 pablo9.writeTest("pablo00009_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
108
110 int start = 1;
111 for (iter=start; iter<start+2; iter++){
112 for (unsigned int i=0; i<nocts; i++){
114 vector<array<double,3> > nodes = pablo9.getNodes(i);
116 array<double,3> center = pablo9.getCenter(i);
117 for (int j=0; j<8; j++){
118 double x = nodes[j][0];
119 double y = nodes[j][1];
120 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
121 if (center[0]<=xc){
122
124 pablo9.setMarker(i,1);
125 }
126 else{
127
129 pablo9.setMarker(i,-1);
130 }
131 }
132 }
133 }
134
136 vector<double> oct_data_new;
137 vector<uint32_t> mapper;
138 vector<bool> isghost;
139 pablo9.adapt(true);
140 nocts = pablo9.getNumOctants();
141 oct_data_new.resize(nocts, 0.0);
142
146 for (uint32_t i=0; i<nocts; i++){
147 pablo9.getMapping(i, mapper, isghost);
148 if (pablo9.getIsNewC(i)){
149 for (int j=0; j<8; j++){
150 if (isghost[j]){
151 oct_data_new[i] += ghost_data[mapper[j]]/8;
152 }
153 else{
154 oct_data_new[i] += oct_data[mapper[j]]/8;
155 }
156 }
157 }
158 else if (pablo9.getIsNewR(i)){
159 oct_data_new[i] += oct_data[mapper[0]];
160 }
161 else{
162 oct_data_new[i] += oct_data[mapper[0]];
163 }
164 }
165
166 oct_data = oct_data_new;
167 vector<double>().swap(oct_data_new);
168
170 pablo9.updateConnectivity();
171 pablo9.writeTest("pablo00009_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
172
173 }
174
175#if BITPIT_ENABLE_MPI==1
178 uint8_t levels = 4;
179 UserDataLB<vector<double> > data_lb(oct_data,ghost_data);
180 pablo9.loadBalance(data_lb, levels);
181#endif
182
184 pablo9.updateConnectivity();
185 pablo9.writeTest("pablo00009_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
186}
187
191int main(int argc, char *argv[])
192{
193#if BITPIT_ENABLE_MPI==1
194 MPI_Init(&argc,&argv);
195#else
196 BITPIT_UNUSED(argc);
197 BITPIT_UNUSED(argv);
198#endif
199
200 int nProcs;
201 int rank;
202#if BITPIT_ENABLE_MPI==1
203 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
204 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
205#else
206 nProcs = 1;
207 rank = 0;
208#endif
209
210 // Initialize the logger
211 log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
212 log::cout() << log::fileVerbosity(log::LEVEL_INFO);
214
215 // Run the example
216 try {
217 run();
218 } catch (const std::exception &exception) {
219 log::cout() << exception.what();
220 exit(1);
221 }
222
223#if BITPIT_ENABLE_MPI==1
224 MPI_Finalize();
225#endif
226}
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 ---