Loading...
Searching...
No Matches
PABLO_example_00010.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
31#if BITPIT_ENABLE_MPI==1
32#include "PABLO_userDataComm.hpp"
33#include "PABLO_userDataLB.hpp"
34#endif
35
36using namespace std;
37using namespace bitpit;
38
39// =================================================================================== //
53// =================================================================================== //
54
58void run()
59{
60 int iter = 0;
61
63 PabloUniform pablo10(3);
64
66 int idx = 0;
67 pablo10.setBalance(idx,false);
68
70 for (iter=1; iter<6; iter++){
71 pablo10.adaptGlobalRefine();
72 }
73
74#if BITPIT_ENABLE_MPI==1
76 pablo10.loadBalance();
77#endif
78
80 double xc, yc, zc;
81 double radius = 0.15;
82 double Dt = 0.000025;
83 double omega = 2.0*3.14/0.001;
84
86 xc = 0.25*cos(omega* Dt) + 0.5 ;
87 yc = 0.25*sin(omega* Dt) + 0.5;
88 zc = 100*Dt;
89
91 uint32_t nocts = pablo10.getNumOctants();
92 vector<double> oct_data(nocts, 0.0);
93
95 int itstart = 1;
96 int itend = 460;
97
98 for (iter=itstart; iter<itend; iter++){
100 xc = 0.25*cos(omega* Dt* (double) iter) + 0.5 ;
101 yc = 0.25*sin(omega* Dt* (double) iter) + 0.5;
102 zc = 100*Dt*iter;
103
104 for (unsigned int i=0; i<nocts; i++){
105 bool inside = false;
107 vector<array<double,3> > nodes = pablo10.getNodes(i);
109 array<double,3> center = pablo10.getCenter(i);
110 oct_data[i] = sqrt((pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0)+pow((center[2]-zc),2.0)));
111 for (int j=0; j<8; j++){
112 double x = nodes[j][0];
113 double y = nodes[j][1];
114 double z = nodes[j][2];
115 if (pow((x-xc),2.0)+pow((y-yc),2.0)+pow((z-zc),2.0) <= pow(radius,2.0)){
116 if (pablo10.getLevel(i) < 6){
118 pablo10.setMarker(i,1);
119 }
120 else{
121 pablo10.setMarker(i,0);
122 }
123 inside = true;
124 }
125 }
126 if (pablo10.getLevel(i) > 5 && !inside){
128 pablo10.setMarker(i,-1);
129 }
130 }
131
133 pablo10.preadapt();
134 pablo10.adapt();
135
136#if BITPIT_ENABLE_MPI==1
138 pablo10.loadBalance();
139#endif
140
142 nocts = pablo10.getNumOctants();
143 vector<double> oct_data_new(nocts, 0.0);
144 for (unsigned int i=0; i<nocts; i++){
145 array<double,3> center = pablo10.getCenter(i);
146 oct_data_new[i] = sqrt((pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0)+pow((center[2]-zc),2.0)));
147 }
148
149 oct_data.resize(nocts);
150 oct_data = oct_data_new;
151 oct_data_new.clear();
152
154 pablo10.updateConnectivity();
155 pablo10.writeTest("pablo00010_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
156 }
157}
158
162int main(int argc, char *argv[])
163{
164#if BITPIT_ENABLE_MPI==1
165 MPI_Init(&argc,&argv);
166#else
167 BITPIT_UNUSED(argc);
168 BITPIT_UNUSED(argv);
169#endif
170
171 int nProcs;
172 int rank;
173#if BITPIT_ENABLE_MPI==1
174 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
175 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
176#else
177 nProcs = 1;
178 rank = 0;
179#endif
180
181 // Initialize the logger
182 log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
183 log::cout() << log::fileVerbosity(log::LEVEL_INFO);
185
186 // Run the example
187 try {
188 run();
189 } catch (const std::exception &exception) {
190 log::cout() << exception.what();
191 exit(1);
192 }
193
194#if BITPIT_ENABLE_MPI==1
195 MPI_Finalize();
196#endif
197}
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 ---