Loading...
Searching...
No Matches
PABLO_example_00005.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
31using namespace std;
32using namespace bitpit;
33
34// =================================================================================== //
59// =================================================================================== //
60
64void run()
65{
66 int iter = 0;
67
69 PabloUniform pablo5(2);
70
72 uint32_t idx=0;
73 pablo5.setBalance(idx,false);
74
76 pablo5.computeConnectivity();
77 pablo5.write("pablo00005_iter"+to_string(static_cast<unsigned long long>(iter)));
78
80 for (iter=1; iter<3; iter++){
81 pablo5.adaptGlobalRefine();
82 pablo5.updateConnectivity();
83 pablo5.write("pablo00005_iter"+to_string(static_cast<unsigned long long>(iter)));
84 }
85
86#if BITPIT_ENABLE_MPI==1
88 pablo5.loadBalance();
89#endif
90
92 double xc, yc;
93 xc = yc = 0.5;
94 double radius = 0.4;
95
97 for (iter=3; iter<9; iter++){
98 uint32_t nocts = pablo5.getNumOctants();
99 for (unsigned int i=0; i<nocts; i++){
101 vector<array<double,3> > nodes = pablo5.getNodes(i);
102 for (int j=0; j<4; j++){
103 double x = nodes[j][0];
104 double y = nodes[j][1];
105 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
106 pablo5.setMarker(i, 1);
107 }
108 }
109 }
110
112 pablo5.adapt();
113
114#if BITPIT_ENABLE_MPI==1
116 pablo5.loadBalance();
117#endif
118
120 pablo5.updateConnectivity();
121 pablo5.write("pablo00005_iter"+to_string(static_cast<unsigned long long>(iter)));
122 }
123
125 pablo5.adaptGlobalCoarse();
126 pablo5.updateConnectivity();
127 pablo5.write("pablo00005_iter"+to_string(static_cast<unsigned long long>(iter)));
128
129
131 xc = yc = 0.35;
132 radius = 0.15;
133
135 for (iter=10; iter<15; iter++){
136 uint32_t nocts = pablo5.getNumOctants();
137 for (unsigned int i=0; i<nocts; i++){
139 vector<array<double,3> > nodes = pablo5.getNodes(i);
140 for (int j=0; j<4; j++){
141 double x = nodes[j][0];
142 double y = nodes[j][1];
144 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
145 pablo5.setMarker(i, -1);
146 }
147 }
148 }
150 pablo5.adapt();
151
152#if BITPIT_ENABLE_MPI==1
154 pablo5.loadBalance();
155#endif
156
158 pablo5.updateConnectivity();
159 pablo5.write("pablo00005_iter"+to_string(static_cast<unsigned long long>(iter)));
160 }
161
163 pablo5.adaptGlobalCoarse();
164 pablo5.updateConnectivity();
165 pablo5.write("pablo00005_iter"+to_string(static_cast<unsigned long long>(iter)));
166}
167
171int main(int argc, char *argv[])
172{
173#if BITPIT_ENABLE_MPI==1
174 MPI_Init(&argc,&argv);
175#else
176 BITPIT_UNUSED(argc);
177 BITPIT_UNUSED(argv);
178#endif
179
180 int nProcs;
181 int rank;
182#if BITPIT_ENABLE_MPI==1
183 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
184 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
185#else
186 nProcs = 1;
187 rank = 0;
188#endif
189
190 // Initialize the logger
191 log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
192 log::cout() << log::fileVerbosity(log::LEVEL_INFO);
194
195 // Run the example
196 try {
197 run();
198 } catch (const std::exception &exception) {
199 log::cout() << exception.what();
200 exit(1);
201 }
202
203#if BITPIT_ENABLE_MPI==1
204 MPI_Finalize();
205#endif
206}
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 ---