Loading...
Searching...
No Matches
PABLO_bubbles_3D.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#include <mpi.h>
31#endif
32
33using namespace std;
34using namespace bitpit;
35
36// =================================================================================== //
54class bubble{
55public:
56 double c[3];
57 double r;
58};
59
65void run()
66{
67 int iter = 0;
68
70 PabloUniform pabloBB(3);
71
73 pabloBB.setBalanceCodimension(1);
74 int idx = 0;
75 pabloBB.setBalance(idx,true);
76
78 for (iter=1; iter<4; iter++){
79 pabloBB.adaptGlobalRefine();
80 }
81
82#if BITPIT_ENABLE_MPI==1
84 pabloBB.loadBalance();
85#endif
86
88 uint32_t nocts = pabloBB.getNumOctants();
89
91 srand(0);
92
93#if BITPIT_ENABLE_MPI==1
94 int nb = 50;
95#else
96 int nb = 10;
97#endif
98 vector<bubble> BB;
99 vector<bubble> BB0;
100 vector<double> DZ;
101 vector<double> OM;
102 vector<double> AA;
103
104 for (int i=0; i<nb; i++){
105 double randc[3];
106 randc[0] = 0.8 * (double) (rand()) / RAND_MAX + 0.1;
107 randc[1] = 0.8 * (double) (rand()) / RAND_MAX + 0.1;
108 randc[2] = (double) (rand()) / RAND_MAX - 0.5;
109 double randr = (0.05 * (double) (rand()) / RAND_MAX + 0.04);
110 double dz = 0.005 + 0.05 * (double) (rand()) / RAND_MAX;
111 double omega = 0.5 * (double) (rand()) / RAND_MAX;
112 double aa = 0.15 * (double) (rand()) / RAND_MAX;
113 bubble bb;
114 bb.c[0] = randc[0];
115 bb.c[1] = randc[1];
116 bb.c[2] = randc[2];
117 bb.r = randr;
118 BB.push_back(bb);
119 BB0.push_back(bb);
120 DZ.push_back(dz);
121 OM.push_back(omega);
122 AA.push_back(aa);
123 }
125 double t0 = 0;
126 double t = t0;
127 double Dt = 0.5;
128
130 vector<double> oct_data(nocts, 0.0),oct_data_ghost;
131 vector<double> oct_data_new(nocts, 0.0);
132
134 int itstart = 1;
135 int itend = 200;
136
138 for (iter=itstart; iter<itend; iter++){
139 if(pabloBB.getRank()==0) cout << "iter " << iter << endl;
140 t += Dt;
141
143 for (int i=0; i<nb; i++){
144 BB[i].c[0] = BB0[i].c[0];// + AA[i]*cos(OM[i]*t);
145 BB[i].c[1] = BB0[i].c[1];// + AA[i]*cos(OM[i]*t);
146 BB[i].c[2] = BB[i].c[2]+ Dt*DZ[i];
147 }
148
150 bool adapt = true;
151 while (adapt){
152
153 for (unsigned int i=0; i<nocts; i++){
154 bool inside = false;
156 vector<array<double,3> > nodes = pabloBB.getNodes(i);
158 array<double,3> center = pabloBB.getCenter(i);
159 int ib = 0;
160 while (!inside && ib<nb){
161 double xc = BB[ib].c[0];
162 double yc = BB[ib].c[1];
163 double zc = BB[ib].c[2];
164 double radius = BB[ib].r;
166 if (((!inside))){
167 if (((pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0)+pow((center[2]-zc),2.0) <= 1.25*pow(radius,2.0) &&
168 pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0)+pow((center[2]-zc),2.0) >= 0.75*pow(radius,2.0)))){
169 if (pabloBB.getLevel(i) < 7){
171 pabloBB.setMarker(i,1);
172 oct_data[i] = 1.0;
173 }
174 else{
175 pabloBB.setMarker(i,0);
176 oct_data[i] = 1.0;
177 }
178 inside = true;
179 }
180 }
181 for (int j=0; j<8; j++){
182 double x = nodes[j][0];
183 double y = nodes[j][1];
184 double z = nodes[j][2];
185 if (((!inside))){
186 if (((pow((x-xc),2.0)+pow((y-yc),2.0)+pow((z-zc),2.0) <= 1.25*pow(radius,2.0) &&
187 pow((x-xc),2.0)+pow((y-yc),2.0)+pow((z-zc),2.0) >= 0.75*pow(radius,2.0)))){
188 if (pabloBB.getLevel(i) < 7){
190 pabloBB.setMarker(i,1);
191 oct_data[i] = 1.0;
192 }
193 else{
194 pabloBB.setMarker(i,0);
195 oct_data[i] = 1.0;
196 }
197 inside = true;
198 }
199 }
200 }
201 ib++;
202 }
203 if (!inside){
204 oct_data[i] = 0.0;
205 if (pabloBB.getLevel(i) > 3){
207 pabloBB.setMarker(i,3-pabloBB.getLevel(i));
208 }
209 }
210 }
211
213 vector<uint32_t> mapidx;
214 vector<bool> isghost;
215 adapt = pabloBB.adapt(true);
216
218 nocts = pabloBB.getNumOctants();
219
221 oct_data_new.resize(nocts, 0);
222 for (uint32_t i=0; i<nocts; i++){
223 pabloBB.getMapping(i, mapidx, isghost);
224 oct_data_new[i] = oct_data[mapidx[0]];
225 }
226 oct_data = oct_data_new;
227 vector<double>().swap(oct_data_new);
228
229 }
230
231#if BITPIT_ENABLE_MPI==1
234 UserDataLB<vector<double> > data_lb(oct_data,oct_data_ghost);
235 pabloBB.loadBalance(data_lb);
237 nocts = pabloBB.getNumOctants();
238#endif
239
241 pabloBB.updateConnectivity();
242 pabloBB.writeTest("PabloBubble3D_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
243 }
244}
245
249int main(int argc, char *argv[])
250{
251#if BITPIT_ENABLE_MPI==1
252 MPI_Init(&argc,&argv);
253#else
254 BITPIT_UNUSED(argc);
255 BITPIT_UNUSED(argv);
256#endif
257
258 int nProcs;
259 int rank;
260#if BITPIT_ENABLE_MPI==1
261 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
262 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
263#else
264 nProcs = 1;
265 rank = 0;
266#endif
267
268 // Initialize the logger
269 log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
270 log::cout() << log::fileVerbosity(log::LEVEL_INFO);
272
273 // Run the example
274 try {
275 run();
276 } catch (const std::exception &exception) {
277 log::cout() << exception.what();
278 exit(1);
279 }
280
281#if BITPIT_ENABLE_MPI==1
282 MPI_Finalize();
283#endif
284}
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 ---