Loading...
Searching...
No Matches
PABLO_example_00006.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#endif
34
35using namespace std;
36using namespace bitpit;
37
38// =================================================================================== //
121// =================================================================================== //
122
123class Data{
124public:
125 vector<double> doubleData;
126 vector<float> floatData;
127 Data(uint32_t nocts): doubleData(nocts,0.0), floatData(nocts,0.0){};
128 Data(Data& rhs){
129 this->doubleData = rhs.doubleData;
130 this->floatData = rhs.floatData;
131 }
132};
133
137void run()
138{
139 int iter = 0;
140 int dim = 2;
141
143 PabloUniform pablo6(2);
144
146 for (iter=1; iter<5; iter++){
147 pablo6.adaptGlobalRefine();
148 }
149
150#if BITPIT_ENABLE_MPI==1
152 pablo6.loadBalance();
153#endif
154
156 double xc, yc;
157 xc = yc = 0.5;
158 double radius = 0.25;
159
161 uint32_t nocts = pablo6.getNumOctants();
162 uint32_t nghosts = pablo6.getNumGhosts();
163 //vector<double> oct_data(nocts, 0.0), ghost_data(nghosts, 0.0);
164 Data octdata(nocts), ghostdata(nghosts);
165
166
168 for (unsigned int i=0; i<nocts; i++){
169 vector<array<double,3> > nodes = pablo6.getNodes(i);
170 for (int j=0; j<4; j++){
171 double x = nodes[j][0];
172 double y = nodes[j][1];
173 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
174 //oct_data[i] = 1.0;
175 octdata.doubleData[i] = 1.0;
176 octdata.floatData[i] = 1.0;
177 }
178 }
179 }
180
182 for (unsigned int i=0; i<nghosts; i++){
184 Octant *oct = pablo6.getGhostOctant(i);
185 vector<array<double,3> > nodes = pablo6.getNodes(oct);
186 for (int j=0; j<4; j++){
187 double x = nodes[j][0];
188 double y = nodes[j][1];
189 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
190 //ghost_data[i] = 1.0;
191 ghostdata.doubleData[i] = 1.0;
192 ghostdata.floatData[i] = 1.0;
193 }
194 }
195 }
196
198 iter = 0;
199 pablo6.updateConnectivity();
200 pablo6.writeTest("pablo00006_double_iter"+to_string(static_cast<unsigned long long>(iter)), octdata.doubleData);
201
203 int start = iter + 1;
204 for (iter=start; iter<start+25; iter++){
205 //vector<double> oct_data_smooth(nocts, 0.0);
206 Data octdatasmooth(nocts);
207 vector<uint32_t> neigh, neigh_t;
208 vector<bool> isghost, isghost_t;
209 uint8_t iface, nfaces, codim;
210 for (unsigned int i=0; i<nocts; i++){
211 neigh.clear();
212 isghost.clear();
213
215 for (codim=1; codim<dim+1; codim++){
216 if (codim == 1){
217 nfaces = 4;
218 }
219 else if (codim == 2){
220 nfaces = 4;
221 }
222 for (iface=0; iface<nfaces; iface++){
223 pablo6.findNeighbours(i,iface,codim,neigh_t,isghost_t);
224 neigh.insert(neigh.end(), neigh_t.begin(), neigh_t.end());
225 isghost.insert(isghost.end(), isghost_t.begin(), isghost_t.end());
226 }
227 }
228
230 //oct_data_smooth[i] = oct_data[i]/(neigh.size()+1);
231 octdatasmooth.doubleData[i] = octdata.doubleData[i]/(neigh.size()+1);
232 octdatasmooth.floatData[i] = octdata.floatData[i]/(neigh.size()+1);
233 for (unsigned int j=0; j<neigh.size(); j++){
234 if (isghost[j]){
235 //oct_data_smooth[i] += ghost_data[neigh[j]]/(neigh.size()+1);
236 octdatasmooth.doubleData[i] += ghostdata.doubleData[neigh[j]]/(neigh.size()+1);
237 octdatasmooth.floatData[i] += ghostdata.floatData[neigh[j]]/(neigh.size()+1);
238 }
239 else{
240 //oct_data_smooth[i] += oct_data[neigh[j]]/(neigh.size()+1);
241 octdatasmooth.doubleData[i] += octdata.doubleData[neigh[j]]/(neigh.size()+1);
242 octdatasmooth.floatData[i] += octdata.floatData[neigh[j]]/(neigh.size()+1);
243 }
244 }
245 }
246
248 pablo6.updateConnectivity();
249 pablo6.writeTest("pablo00006_iter"+to_string(static_cast<unsigned long long>(iter)), octdatasmooth.doubleData);
250
251#if BITPIT_ENABLE_MPI==1
253 UserDataComm<Data> data_comm(octdatasmooth, ghostdata);
254 pablo6.communicate(data_comm);
255
256#endif
257 octdata.doubleData = octdatasmooth.doubleData;
258 octdata.floatData = octdatasmooth.floatData;
259 }
260}
261
265int main(int argc, char *argv[])
266{
267#if BITPIT_ENABLE_MPI==1
268 MPI_Init(&argc,&argv);
269#else
270 BITPIT_UNUSED(argc);
271 BITPIT_UNUSED(argv);
272#endif
273
274 int nProcs;
275 int rank;
276#if BITPIT_ENABLE_MPI==1
277 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
278 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
279#else
280 nProcs = 1;
281 rank = 0;
282#endif
283
284 // Initialize the logger
285 log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
286 log::cout() << log::fileVerbosity(log::LEVEL_INFO);
288
289 // Run the example
290 try {
291 run();
292 } catch (const std::exception &exception) {
293 log::cout() << exception.what();
294 exit(1);
295 }
296
297#if BITPIT_ENABLE_MPI==1
298 MPI_Finalize();
299#endif
300}
void initialize(log::Mode mode, bool reset, int nProcesses, int rank)
Definition logger.cpp:1268
Octant class definition.
Definition Octant.hpp:89
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 ---