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.
#if BITPIT_ENABLE_MPI==1
#include <mpi.h>
#endif
#include "bitpit_PABLO.hpp"
using namespace std;
using namespace bitpit;
void run()
{
int iter = 0;
for (iter=1; iter<5; iter++){
}
double xc, yc;
xc = yc = 0.5;
double radius = 0.25;
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++){
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
log::manager().initialize(log::MODE_SEPARATE, false, nProcs, rank);
log::cout() << log::fileVerbosity(log::LEVEL_INFO);
log::cout() << log::disableConsole();
try {
run();
} catch (const std::exception &exception) {
log::cout() << exception.what();
exit(1);
}
#if BITPIT_ENABLE_MPI==1
MPI_Finalize();
#endif
}
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)