Loading...
Searching...
No Matches
PABLO_example_00007.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#include "bitpit_PABLO.hpp"
26
27#if BITPIT_ENABLE_MPI==1
28#include "PABLO_userDataComm.hpp"
29#include "PABLO_userDataLB.hpp"
30#endif
31
32using namespace std;
33using namespace bitpit;
34
35// =================================================================================== //
187// =================================================================================== //
188
189#if BITPIT_ENABLE_MPI==1
190#include <mpi.h>
191#endif
192
193#include "bitpit_PABLO.hpp"
194
198void run()
199{
200 int iter = 0;
201
203 PabloUniform pablo7(2);
204
206 int idx = 0;
207 pablo7.setBalance(idx,false);
208
210 for (iter=1; iter<6; iter++){
211 pablo7.adaptGlobalRefine();
212 }
213
215 double xc, yc;
216 xc = yc = 0.5;
217 double radius = 0.25;
218
220 uint32_t nocts = pablo7.getNumOctants();
221 uint32_t nghosts = pablo7.getNumGhosts();
222 vector<double> oct_data(nocts, 0.0), ghost_data(nghosts, 0.0);
223
225 for (unsigned int i=0; i<nocts; i++){
227 vector<array<double,3> > nodes = pablo7.getNodes(i);
229 array<double,3> center = pablo7.getCenter(i);
230 for (int j=0; j<4; j++){
231 double x = nodes[j][0];
232 double y = nodes[j][1];
233 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
234 oct_data[i] = (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0));
235 }
236 }
237 }
238
240 iter = 0;
241 pablo7.updateConnectivity();
242 pablo7.writeTest("pablo00007_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
243
245 int start = 1;
247 vector<double> weight(nocts, 1.0),weightGhost;
248 for (iter=start; iter<start+2; iter++){
249 for (unsigned int i=0; i<nocts; i++){
251 vector<array<double,3> > nodes = pablo7.getNodes(i);
253 array<double,3> center = pablo7.getCenter(i);
254 for (int j=0; j<4; j++){
255 weight[i] = 2.0;
256 double x = nodes[j][0];
257 double y = nodes[j][1];
258 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
259 if (center[0]<=xc){
260
262 pablo7.setMarker(i,1);
263 weight[i] = 1.0;
264 }
265 else{
266
268 pablo7.setMarker(i,-1);
269 weight[i] = 1.0;
270 }
271 }
272 }
273 }
274
276 vector<double> oct_data_new;
277 vector<double> weight_new;
278 vector<uint32_t> mapper;
279 vector<bool> isghost;
280 pablo7.adapt(true);
281 nocts = pablo7.getNumOctants();
282 oct_data_new.resize(nocts, 0.0);
283 weight_new.resize(nocts,0.0);
284
288 for (uint32_t i=0; i<nocts; i++){
289 pablo7.getMapping(i, mapper, isghost);
290 if (pablo7.getIsNewC(i)){
291 for (int j=0; j<4; j++){
292 oct_data_new[i] += oct_data[mapper[j]]/4;
293 weight_new[i] += weight[mapper[j]];
294 }
295 }
296 else if (pablo7.getIsNewR(i)){
297 oct_data_new[i] += oct_data[mapper[0]];
298 weight_new[i] += weight[mapper[0]];
299 }
300 else{
301 oct_data_new[i] += oct_data[mapper[0]];
302 weight_new[i] += weight[mapper[0]];
303 }
304 }
305
307 pablo7.updateConnectivity();
308 pablo7.writeTest("pablo00007_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data_new);
309
310 oct_data = oct_data_new;
311 weight = weight_new;
312 }
313
314#if BITPIT_ENABLE_MPI==1
316 UserDataLB<vector<double> > data_lb(weight,weightGhost);
317 pablo7.loadBalance(data_lb, &weight);
318#endif
319
320 double tot = 0.0;
321 for (unsigned int i=0; i<weight.size(); i++){
322 tot += weight[i];
323 }
324
326 pablo7.updateConnectivity();
327 pablo7.writeTest("pablo00007_iter"+to_string(static_cast<unsigned long long>(iter)), weight);
328}
329
333int main(int argc, char *argv[])
334{
335#if BITPIT_ENABLE_MPI==1
336 MPI_Init(&argc,&argv);
337#else
338 BITPIT_UNUSED(argc);
339 BITPIT_UNUSED(argv);
340#endif
341
342 int nProcs;
343 int rank;
344#if BITPIT_ENABLE_MPI==1
345 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
346 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
347#else
348 nProcs = 1;
349 rank = 0;
350#endif
351
352 // Initialize the logger
353 log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
354 log::cout() << log::fileVerbosity(log::LEVEL_INFO);
356
357 // Run the example
358 try {
359 run();
360 } catch (const std::exception &exception) {
361 log::cout() << exception.what();
362 exit(1);
363 }
364
365#if BITPIT_ENABLE_MPI==1
366 MPI_Finalize();
367#endif
368}
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 ---