Loading...
Searching...
No Matches
PABLO_example_00009.cpp
Parallel 3D adaptive mesh refinement (AMR) with data using PABLO.
Parallel 3D adaptive mesh refinement (AMR) with data using PABLOThe load-balance example with data and "compact families" in example 00008 is here rerun for a three-dimensional octree mesh.
To run: ./PABLO_example_00009
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"
#if BITPIT_ENABLE_MPI==1
#include "PABLO_userDataComm.hpp"
#include "PABLO_userDataLB.hpp"
#endif
using namespace std;
using namespace bitpit;
// =================================================================================== //
// =================================================================================== //
void run()
{
int iter = 0;
PabloUniform pablo9(0,0,0,1,3);
int idx = 0;
for (iter=1; iter<6; iter++){
pablo9.adaptGlobalRefine();
}
#if BITPIT_ENABLE_MPI==1
pablo9.loadBalance();
#endif
double xc, yc;
xc = yc = 0.5;
double radius = 0.25;
uint32_t nocts = pablo9.getNumOctants();
uint32_t nghosts = pablo9.getNumGhosts();
vector<double> oct_data(nocts, 0.0), ghost_data(nghosts, 0.0);
for (unsigned int i=0; i<nocts; i++){
vector<array<double,3> > nodes = pablo9.getNodes(i);
array<double,3> center = pablo9.getCenter(i);
for (int j=0; j<8; j++){
double x = nodes[j][0];
double y = nodes[j][1];
}
}
}
iter = 0;
pablo9.updateConnectivity();
int start = 1;
for (iter=start; iter<start+2; iter++){
for (unsigned int i=0; i<nocts; i++){
vector<array<double,3> > nodes = pablo9.getNodes(i);
array<double,3> center = pablo9.getCenter(i);
for (int j=0; j<8; j++){
double x = nodes[j][0];
double y = nodes[j][1];
if (center[0]<=xc){
pablo9.setMarker(i,1);
}
else{
pablo9.setMarker(i,-1);
}
}
}
}
vector<double> oct_data_new;
vector<uint32_t> mapper;
vector<bool> isghost;
nocts = pablo9.getNumOctants();
oct_data_new.resize(nocts, 0.0);
for (uint32_t i=0; i<nocts; i++){
pablo9.getMapping(i, mapper, isghost);
for (int j=0; j<8; j++){
if (isghost[j]){
oct_data_new[i] += ghost_data[mapper[j]]/8;
}
else{
oct_data_new[i] += oct_data[mapper[j]]/8;
}
}
}
oct_data_new[i] += oct_data[mapper[0]];
}
else{
oct_data_new[i] += oct_data[mapper[0]];
}
}
oct_data = oct_data_new;
vector<double>().swap(oct_data_new);
pablo9.updateConnectivity();
}
#if BITPIT_ENABLE_MPI==1
uint8_t levels = 4;
UserDataLB<vector<double> > data_lb(oct_data,ghost_data);
pablo9.loadBalance(data_lb, levels);
#endif
pablo9.updateConnectivity();
}
int main(int argc, char *argv[])
{
#if BITPIT_ENABLE_MPI==1
MPI_Init(&argc,&argv);
#else
BITPIT_UNUSED(argc);
BITPIT_UNUSED(argv);
#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/...
Definition PabloUniform.hpp:62
void getNodes(uint32_t idx, darr3vector &nodes) const
Definition PabloUniform.cpp:405
void writeTest(const std::string &filename, dvector data)
Definition PabloUniform.cpp:1035
void getCenter(uint32_t idx, darray3 ¢er) const
Definition PabloUniform.cpp:323
void getMapping(uint32_t idx, u32vector &mapper, bvector &isghost) const
Definition ParaTree.cpp:3215
void loadBalance(const dvector *weight=NULL)
Definition ParaTree.cpp:3997
bool adaptGlobalRefine(bool mapper_flag=false)
Definition ParaTree.cpp:3573
Logger & cout(log::Level defaultSeverity, log::Visibility defaultVisibility)
Definition logger.cpp:1714
LoggerManipulator< log::Level > fileVerbosity(const log::Level &threshold)
Definition logger.cpp:2129
Logger & disableConsole(Logger &logger, const log::Level &level)
Definition logger.cpp:2174
