Loading...
Searching...
No Matches
PABLO_example_00003.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// =================================================================================== //
59// =================================================================================== //
60
64void run()
65{
66 int iter = 0;
67
69 PabloUniform pablo3(2);
70
72 for (iter=1; iter<5; iter++){
73 pablo3.adaptGlobalRefine();
74 }
75
77 double xc, yc;
78 xc = yc = 0.5;
79 double radius = 0.25;
80
82 uint32_t nocts = pablo3.getNumOctants();
83 vector<double> oct_data(nocts, 0.0);
84
86 for (unsigned int i=0; i<nocts; i++){
88 vector<array<double,3> > nodes = pablo3.getNodes(i);
89 for (int j=0; j<4; j++){
90 double x = nodes[j][0];
91 double y = nodes[j][1];
92 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
93 oct_data[i] = 1.0;
94 }
95 }
96 }
97
99 iter = 0;
100 pablo3.updateConnectivity();
101 pablo3.writeTest("pablo00003_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
102
104 int start = 1;
105 for (iter=start; iter<start+25; iter++){
106 vector<double> oct_data_smooth(nocts, 0.0);
107 vector<uint32_t> neigh, neigh_t;
108 vector<bool> isghost, isghost_t;
109 uint8_t iface, nfaces;
110 int codim;
111 for (unsigned int i=0; i<nocts; i++){
112 neigh.clear();
113 isghost.clear();
114
116 for (codim=1; codim<3; codim++){
117 if (codim == 1){
118 nfaces = 4;
119 }
120 else if (codim == 2){
121 nfaces = 4;
122 }
123 for (iface=0; iface<nfaces; iface++){
124 pablo3.findNeighbours(i,iface,codim,neigh_t,isghost_t);
125 neigh.insert(neigh.end(), neigh_t.begin(), neigh_t.end());
126 isghost.insert(isghost.end(), isghost_t.begin(), isghost_t.end());
127 }
128 }
129
131 oct_data_smooth[i] = oct_data[i]/(neigh.size()+1);
132 for (unsigned int j=0; j<neigh.size(); j++){
133 if (isghost[j]){
135 }
136 else{
137 oct_data_smooth[i] += oct_data[neigh[j]]/(neigh.size()+1);
138 }
139 }
140 }
141
143 pablo3.updateConnectivity();
144 pablo3.writeTest("pablo00003_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data_smooth);
145
146 oct_data = oct_data_smooth;
147 }
148}
149
153int main(int argc, char *argv[])
154{
155#if BITPIT_ENABLE_MPI==1
156 MPI_Init(&argc,&argv);
157#else
158 BITPIT_UNUSED(argc);
159 BITPIT_UNUSED(argv);
160#endif
161
162 int nProcs;
163 int rank;
164#if BITPIT_ENABLE_MPI==1
165 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
166 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
167#else
168 nProcs = 1;
169 rank = 0;
170#endif
171
172 // Initialize the logger
173 log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
174 log::cout() << log::fileVerbosity(log::LEVEL_INFO);
176
177 // Run the example
178 try {
179 run();
180 } catch (const std::exception &exception) {
181 log::cout() << exception.what();
182 exit(1);
183 }
184
185#if BITPIT_ENABLE_MPI==1
186 MPI_Finalize();
187#endif
188}
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 ---