Loading...
Searching...
No Matches
PABLO_example_00003.cpp

2D smoothing data using PABLO

2D smoothing data using PABLOThis example shows how to use PABLO's methods to find neighboring quadrants of a specified element. Neighbors search can be performed through faces, edges and nodes (in 2D case, only faces and nodes).

In this example a 2D octree is refined four times and then a set of data is assigned to the mesh using STL vectors. More specifically, an integer equal to 1 is assigned uniformly to all quadrants within a circle, and 0 to the remaining quadrants. In this example neighbor-search is used to perform a simple moving-average-smoothing procedure of the data.

The obtained results show the time-evolution of data over 25 smoothing iterations.

To run: ./PABLO_example_00003
To see the result visit: PABLO website

/*---------------------------------------------------------------------------*\
*
* bitpit
*
* Copyright (C) 2015-2021 OPTIMAD engineering Srl
*
* -------------------------------------------------------------------------
* License
* This file is part of bitpit.
*
* bitpit is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License v3 (LGPL)
* as published by the Free Software Foundation.
*
* bitpit is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with bitpit. If not, see <http://www.gnu.org/licenses/>.
*
\*---------------------------------------------------------------------------*/
#if BITPIT_ENABLE_MPI==1
#include <mpi.h>
#endif
#include "bitpit_PABLO.hpp"
using namespace std;
using namespace bitpit;
// =================================================================================== //
// =================================================================================== //
void run()
{
int iter = 0;
PabloUniform pablo3(2);
for (iter=1; iter<5; iter++){
}
double xc, yc;
xc = yc = 0.5;
double radius = 0.25;
uint32_t nocts = pablo3.getNumOctants();
vector<double> oct_data(nocts, 0.0);
for (unsigned int i=0; i<nocts; i++){
vector<array<double,3> > nodes = pablo3.getNodes(i);
for (int j=0; j<4; j++){
double x = nodes[j][0];
double y = nodes[j][1];
if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
oct_data[i] = 1.0;
}
}
}
iter = 0;
pablo3.writeTest("pablo00003_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
int start = 1;
for (iter=start; iter<start+25; iter++){
vector<double> oct_data_smooth(nocts, 0.0);
vector<uint32_t> neigh, neigh_t;
vector<bool> isghost, isghost_t;
uint8_t iface, nfaces;
int codim;
for (unsigned int i=0; i<nocts; i++){
neigh.clear();
isghost.clear();
for (codim=1; codim<3; codim++){
if (codim == 1){
nfaces = 4;
}
else if (codim == 2){
nfaces = 4;
}
for (iface=0; iface<nfaces; iface++){
pablo3.findNeighbours(i,iface,codim,neigh_t,isghost_t);
neigh.insert(neigh.end(), neigh_t.begin(), neigh_t.end());
isghost.insert(isghost.end(), isghost_t.begin(), isghost_t.end());
}
}
oct_data_smooth[i] = oct_data[i]/(neigh.size()+1);
for (unsigned int j=0; j<neigh.size(); j++){
if (isghost[j]){
}
else{
oct_data_smooth[i] += oct_data[neigh[j]]/(neigh.size()+1);
}
}
}
pablo3.writeTest("pablo00003_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data_smooth);
oct_data = oct_data_smooth;
}
}
int main(int argc, char *argv[])
{
#if BITPIT_ENABLE_MPI==1
MPI_Init(&argc,&argv);
#else
#endif
int nProcs;
int rank;
#if BITPIT_ENABLE_MPI==1
MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#else
nProcs = 1;
rank = 0;
#endif
// Initialize the logger
log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
log::cout() << log::fileVerbosity(log::LEVEL_INFO);
log::cout() << log::disableConsole();
// Run the example
try {
run();
} catch (const std::exception &exception) {
log::cout() << exception.what();
exit(1);
}
#if BITPIT_ENABLE_MPI==1
MPI_Finalize();
#endif
}
PABLO Uniform is an example of user class derived from ParaTree to map ParaTree in a uniform (square/...
void getNodes(uint32_t idx, darr3vector &nodes) const
void writeTest(const std::string &filename, dvector data)
uint32_t getNumOctants() const
bool adaptGlobalRefine(bool mapper_flag=false)
void findNeighbours(uint32_t idx, uint8_t face, uint8_t codim, u32vector &neighbours, bvector &isghost) const
void updateConnectivity()
std::array< T, d > pow(std::array< T, d > &x, double p)
#define BITPIT_UNUSED(variable)
Definition compiler.hpp:63
--- layout: doxygen_footer ---