Loading...
Searching...
No Matches
PABLO_bubbles_2D.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// =================================================================================== //
55class bubble{
56public:
57 double c[2];
58 double r;
59};
60
66void run()
67{
68 int iter = 0;
69
71 PabloUniform pabloBB(2);
72
74 pabloBB.setBalanceCodimension(1);
75 uint32_t idx = 0;
76 pabloBB.setBalance(idx,true);
77
79 for (iter=1; iter<4; iter++){
80 pabloBB.adaptGlobalRefine();
81 }
82
83#if BITPIT_ENABLE_MPI==1
85 pabloBB.loadBalance();
86#endif
87
89 srand(0);
90
91#if BITPIT_ENABLE_MPI==1
92 int nb = 50;
93#else
94 int nb = 10;
95#endif
96 vector<bubble> BB;
97 vector<bubble> BB0;
98 vector<double> DY;
99 vector<double> OM;
100 vector<double> AA;
101
102 for (int i=0; i<nb; i++){
103 double randc[2];
104 randc[0] = 0.8 * double(rand()) / RAND_MAX + 0.1;
105 randc[1] = double(rand()) / RAND_MAX - 0.5;
106 double randr = 0.1 * double(rand()) / RAND_MAX + 0.02;
107 double dy = 0.005 + 0.05 * double(rand()) / RAND_MAX;
108 double omega = 0.5 * double(rand()) / RAND_MAX;
109 double aa = 0.15 * double(rand()) / RAND_MAX;
110 bubble bb;
111 bb.c[0] = randc[0];
112 bb.c[1] = randc[1];
113 bb.r = randr;
114 BB.push_back(bb);
115 BB0.push_back(bb);
116 DY.push_back(dy);
117 OM.push_back(omega);
118 AA.push_back(aa);
119 }
121 double t0 = 0;
122 double t = t0;
123 double Dt = 0.5;
124
126 int itstart = 1;
127 int iterend = 200;
128
130 for (iter=itstart; iter<iterend; iter++){
131 if(pabloBB.getRank()==0) cout << "iter " << iter << endl;
132 t += Dt;
133
135 for (int i=0; i<nb; i++){
136 BB[i].c[0] = BB0[i].c[0] + AA[i]*cos(OM[i]*t);
137 BB[i].c[1] = BB[i].c[1]+ Dt*DY[i];
138 }
139
141 bool adapt = true;
142 while (adapt){
143 octantIterator it, itend = pabloBB.getInternalOctantsEnd();
144 for (it=pabloBB.getInternalOctantsBegin(); it!=itend; ++it){
145 bool inside = false;
147 vector<array<double,3> > nodes = pabloBB.getNodes((*it));
149 array<double,3> center = pabloBB.getCenter((*it));
150 int ib = 0;
151 while (!inside && ib<nb){
152 double xc = BB[ib].c[0];
153 double yc = BB[ib].c[1];
154 double radius = BB[ib].r;
156 for (int j=0; j<4; j++){
157 double x = nodes[j][0];
158 double y = nodes[j][1];
159 if ( ((!inside) &&
160 (pow((x-xc),2.0)+pow((y-yc),2.0) <= 1.25*pow(radius,2.0) &&
161 pow((x-xc),2.0)+pow((y-yc),2.0) >= 0.75*pow(radius,2.0)))
162 || ((!inside) && (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0) <= 1.25*pow(radius,2.0) &&
163 pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0) >= 0.75*pow(radius,2.0)))){
164 if (int(pabloBB.getLevel((*it))) < 9){
166 pabloBB.setMarker((*it),1);
167 }
168 else{
169 pabloBB.setMarker((*it),0);
170 }
171 inside = true;
172 }
173 }
174 ib++;
175 }
176 if (int(pabloBB.getLevel((*it))) > 0 && !inside){
178 pabloBB.setMarker((*it),5-pabloBB.getLevel((*it)));
179 }
180 }
181
182 itend = pabloBB.getPboundOctantsEnd();
183 for (it=pabloBB.getPboundOctantsBegin(); it!=itend; ++it){
184 bool inside = false;
186 vector<array<double,3> > nodes = pabloBB.getNodes((*it));
188 array<double,3> center = pabloBB.getCenter((*it));
189 int ib = 0;
190 while (!inside && ib<nb){
191 double xc = BB[ib].c[0];
192 double yc = BB[ib].c[1];
193 double radius = BB[ib].r;
195 for (int j=0; j<4; j++){
196 double x = nodes[j][0];
197 double y = nodes[j][1];
198 if ( ((!inside) &&
199 (pow((x-xc),2.0)+pow((y-yc),2.0) <= 1.25*pow(radius,2.0) &&
200 pow((x-xc),2.0)+pow((y-yc),2.0) >= 0.75*pow(radius,2.0)))
201 || ((!inside) && (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0) <= 1.25*pow(radius,2.0) &&
202 pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0) >= 0.75*pow(radius,2.0)))){
203 if (pabloBB.getLevel((*it)) < 9){
205 pabloBB.setMarker((*it),1);
206 }
207 else{
208 pabloBB.setMarker((*it),0);
209 }
210 inside = true;
211 }
212 }
213 ib++;
214 }
215 if (pabloBB.getLevel((*it)) > 0 && !inside){
217 pabloBB.setMarker((*it),5-pabloBB.getLevel((*it)));
218 }
219 }
220
222 adapt = pabloBB.adapt();
223
224 }
225
226#if BITPIT_ENABLE_MPI==1
228 pabloBB.loadBalance();
229#endif
230
232 pabloBB.updateConnectivity();
233 pabloBB.write("PabloBubble_iter"+to_string(static_cast<unsigned long long>(iter)));
234
235 }
236}
237
241int main(int argc, char *argv[])
242{
243#if BITPIT_ENABLE_MPI==1
244 MPI_Init(&argc,&argv);
245#else
246 BITPIT_UNUSED(argc);
247 BITPIT_UNUSED(argv);
248#endif
249
250 int nProcs;
251 int rank;
252#if BITPIT_ENABLE_MPI==1
253 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
254 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
255#else
256 nProcs = 1;
257 rank = 0;
258#endif
259
260 // Initialize the logger
261 log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
262 log::cout() << log::fileVerbosity(log::LEVEL_INFO);
264
265 // Run the example
266 try {
267 run();
268 } catch (const std::exception &exception) {
269 log::cout() << exception.what();
270 exit(1);
271 }
272
273#if BITPIT_ENABLE_MPI==1
274 MPI_Finalize();
275#endif
276}
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 ---