Loading...
Searching...
No Matches
PABLO_example_00001.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// =================================================================================== //
67// =================================================================================== //
68
72void run()
73{
75 PabloUniform pablo1(2);
76
78 pablo1.computeConnectivity();
79 pablo1.write("pablo00001_iter0");
80
82 pablo1.adaptGlobalRefine();
83 pablo1.updateConnectivity();
84 pablo1.write("pablo00001_iter1");
85
87 double xc, yc;
88 xc = yc = 0.5;
89
91 pablo1.setBalanceCodimension(1);
92
94 uint32_t nocts = pablo1.getNumOctants();
95 for (unsigned int i=0; i<nocts; i++){
96 array<double,3> center = pablo1.getCenter(i);
97 double x = center[0];
98 if (x>xc)
99 pablo1.setBalance(i,false);
100 }
101
103 double radius = 0.4;
104
106 int nref1 = 6;
107 for (int iter=0; iter<nref1; iter++){
108 nocts = pablo1.getNumOctants();
109 for (unsigned int i=0; i<nocts; i++){
111 Octant *oct = pablo1.getOctant(i);
113 array<double,3> center = pablo1.getCenter(oct);
114 double x = center[0];
115 double y = center[1];
116
118 if ((pow((x-xc),2.0)+pow((y-yc),2.0) < pow(radius,2.0)) &&
119 (y<yc)){
120 pablo1.setMarker(oct, 1);
121 }
122 }
124 pablo1.adapt();
125 pablo1.updateConnectivity();
126 pablo1.write("pablo00001_iter"+to_string(static_cast<unsigned long long>(iter+2)));
127 }
128
131 int nref2 = 5;
132 int iter = 0;
133 bool done = true;
134 while(iter<=nref2){
135 done = true;
136 while(done)
137 {
138 nocts = pablo1.getNumOctants();
139 for (unsigned int i=0; i<nocts; i++){
141 array<double,3> center = pablo1.getCenter(i);
142 double x = center[0];
143 double y = center[1];
144 if ((pow((x-xc),2.0)+pow((y-yc),2.0) < pow(radius,2.0)) &&
145 (y>yc) && iter<=nref2 && pablo1.getLevel(i)<=iter+1){
146
148 pablo1.setMarker(i, 1);
149 }
150 }
151 done = pablo1.adapt();
152 pablo1.updateConnectivity();
153 pablo1.write("pablo00001_iter"+to_string(static_cast<unsigned long long>(iter+nref1+2)));
154 }
155 iter++;
156 }
158 pablo1.adaptGlobalRefine();
159 pablo1.updateConnectivity();
160 pablo1.write("pablo00001_iter"+to_string(static_cast<unsigned long long>(iter+nref1+3)));
161}
162
166int main(int argc, char *argv[])
167{
168#if BITPIT_ENABLE_MPI==1
169 MPI_Init(&argc,&argv);
170#else
171 BITPIT_UNUSED(argc);
172 BITPIT_UNUSED(argv);
173#endif
174
175 int nProcs;
176 int rank;
177#if BITPIT_ENABLE_MPI==1
178 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
179 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
180#else
181 nProcs = 1;
182 rank = 0;
183#endif
184
185 // Initialize the logger
186 log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
187 log::cout() << log::fileVerbosity(log::LEVEL_INFO);
189
190 // Run the example
191 try {
192 run();
193 } catch (const std::exception &exception) {
194 log::cout() << exception.what();
195 exit(1);
196 }
197
198#if BITPIT_ENABLE_MPI==1
199 MPI_Finalize();
200#endif
201}
void initialize(log::Mode mode, bool reset, int nProcesses, int rank)
Definition logger.cpp:1268
Octant class definition.
Definition Octant.hpp:89
void setMarker(int8_t marker)
Definition Octant.cpp:385
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 ---