Loading...
Searching...
No Matches
PABLO_example_00004.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// =================================================================================== //
62// =================================================================================== //
63
67void run()
68{
69 int iter = 0;
70
72 PabloUniform pablo4(2);
73
75 int idx = 0;
76 pablo4.setBalance(idx,false);
77
79 for (iter=1; iter<6; iter++){
80 pablo4.adaptGlobalRefine();
81 }
82
84 double xc, yc;
85 xc = yc = 0.5;
86 double radius = 0.25;
87
89 uint32_t nocts = pablo4.getNumOctants();
90 vector<double> oct_data(nocts, 0.0);
91
93 for (unsigned int i=0; i<nocts; i++){
95 vector<array<double,3> > nodes = pablo4.getNodes(i);
96 array<double,3> center = pablo4.getCenter(i);
97 for (int j=0; j<4; j++){
98 double x = nodes[j][0];
99 double y = nodes[j][1];
100 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
101 oct_data[i] = (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0));
102 }
103 }
104 }
105
107 iter = 0;
108 pablo4.updateConnectivity();
109 pablo4.writeTest("pablo00004_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
110
112 int start = 1;
113 for (iter=start; iter<start+2; iter++){
114 for (unsigned int i=0; i<nocts; i++){
116 vector<array<double,3> > nodes = pablo4.getNodes(i);
117 array<double,3> center = pablo4.getCenter(i);
118 for (int j=0; j<4; j++){
119 double x = nodes[j][0];
120 double y = nodes[j][1];
121 if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
122 if (center[0]<=xc){
123
125 pablo4.setMarker(i,1);
126 }
127 else{
128
130 pablo4.setMarker(i,-1);
131 }
132 }
133 }
134 }
135
137 vector<double> oct_data_new;
138 vector<uint32_t> mapper;
139 vector<bool> isghost;
140 pablo4.adapt(true);
141 nocts = pablo4.getNumOctants();
142 oct_data_new.resize(nocts, 0.0);
143
147 for (uint32_t i=0; i<nocts; i++){
148 pablo4.getMapping(i, mapper, isghost);
149 if (pablo4.getIsNewC(i)){
150 for (int j=0; j<4; j++){
151 oct_data_new[i] += oct_data[mapper[j]]/4;
152 }
153 }
154 else if (pablo4.getIsNewR(i)){
155 oct_data_new[i] += oct_data[mapper[0]];
156 }
157 else{
158 oct_data_new[i] += oct_data[mapper[0]];
159 }
160 }
161
163 pablo4.updateConnectivity();
164 pablo4.writeTest("pablo00004_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data_new);
165
166 oct_data = oct_data_new;
167 }
168}
169
173int main(int argc, char *argv[])
174{
175#if BITPIT_ENABLE_MPI==1
176 MPI_Init(&argc,&argv);
177#else
178 BITPIT_UNUSED(argc);
179 BITPIT_UNUSED(argv);
180#endif
181
182 int nProcs;
183 int rank;
184#if BITPIT_ENABLE_MPI==1
185 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
186 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
187#else
188 nProcs = 1;
189 rank = 0;
190#endif
191
192 // Initialize the logger
193 log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
194 log::cout() << log::fileVerbosity(log::LEVEL_INFO);
196
197 // Run the example
198 try {
199 run();
200 } catch (const std::exception &exception) {
201 log::cout() << exception.what();
202 exit(1);
203 }
204
205#if BITPIT_ENABLE_MPI==1
206 MPI_Finalize();
207#endif
208}
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 ---