27#if BITPIT_ENABLE_MPI==1
31#include "bitpit_common.hpp"
32#include "bitpit_voloctree.hpp"
34using namespace bitpit;
55 : m_patch(patch), m_scalarField(scalarField), m_vectorField(vectorField)
61 if (name ==
"scalarField") {
63 long id = cell.getId();
66 }
else if (name ==
"vectorField") {
68 long id = cell.getId();
82int main(
int argc,
char *argv[])
88#if BITPIT_ENABLE_MPI == 1
90 MPI_Init(&argc, &argv);
98 log::cout() <<
" Initializing mesh..." << std::endl;
101 std::array<double, 3> center = {{0.0,0.0,0.0}};
102 std::array<double, 3> minimum = center - length / 2.;
103 double dh = length / 16.;
106 VolOctree mesh(3, minimum, length, dh, MPI_COMM_NULL);
110 mesh.initializeAdjacencies();
114 log::cout() <<
"Initializing fields..." << std::endl;
120 for (
const Cell &cell : mesh.getCells()) {
121 const long cellId = cell.getId();
122 std::array<double, 3> cellCentroid = mesh.evalCellCentroid(cellId);
123 double r = std::sqrt(cellCentroid[0] * cellCentroid[0] + cellCentroid[1] * cellCentroid[1] + cellCentroid[2] * cellCentroid[2]);
125 scalarField.
set(cellId, r);
126 vectorField.
set(cellId, {{cellCentroid[0] / r, cellCentroid[1] / r, cellCentroid[2] / r}});
132 mesh.getVTK().setName(
"voloctree_adaptation_example_00001");
133 mesh.getVTK().setCounter();
134 mesh.getVTK().addData<
double>(
"scalarField", VTKFieldType::SCALAR, VTKLocation::CELL, &dataStreamer);
135 mesh.getVTK().addData<std::array<double, 3>>(
"vectorField", VTKFieldType::VECTOR, VTKLocation::CELL, &dataStreamer);
143 bool trackAdaptation =
true;
144 bool squeeshPatchStorage =
false;
145 std::vector<adaption::Info> adaptionData;
148 log::cout() <<
"Performing refinement..." << std::endl;
150 int nRefinements = 2;
151 for (
int i = 0; i < nRefinements; ++i) {
156 log::cout() <<
" Marking cells that need refinement..." << std::endl;
158 for (
const Cell &cell : mesh.getCells()) {
159 long cellId = cell.getId();
160 std::array<double, 3> cellCentroid = mesh.evalCellCentroid(cellId);
162 double r = std::sqrt(cellCentroid[0] * cellCentroid[0] + cellCentroid[1] * cellCentroid[1] + cellCentroid[2] * cellCentroid[2]);
164 mesh.markCellForRefinement(cellId);
172 adaptionData = mesh.adaptionPrepare(trackAdaptation);
182 if (adaptionInfo.entity != adaption::Entity::ENTITY_CELL) {
184 }
else if (adaptionInfo.type != adaption::TYPE_REFINEMENT) {
189 for (
long previousId : adaptionInfo.previous) {
190 previousScalarField.
insert(previousId, std::move(scalarField.
at(previousId)));
191 previousVectorField.
insert(previousId, std::move(vectorField.
at(previousId)));
196 adaptionData = mesh.adaptionAlter(trackAdaptation, squeeshPatchStorage);
205 if (adaptionInfo.entity != adaption::Entity::ENTITY_CELL) {
207 }
else if (adaptionInfo.type != adaption::TYPE_REFINEMENT) {
212 long parentId = adaptionInfo.previous.front();
213 for (
long currentId : adaptionInfo.current) {
214 scalarField.
set(currentId, previousScalarField.
at(parentId));
215 vectorField.
set(currentId, previousVectorField.
at(parentId));
219 mesh.adaptionCleanup();
226 int nofCoarsening = 1;
227 for (
int i = 0; i < nofCoarsening; ++i) {
232 for (
const Cell &cell : mesh.getCells()) {
233 long cellId = cell.getId();
234 std::array<double, 3> cellCentroid = mesh.evalCellCentroid(cellId);
236 double r = std::sqrt(cellCentroid[0] * cellCentroid[0] + cellCentroid[1] * cellCentroid[1] + cellCentroid[2] * cellCentroid[2]);
238 mesh.markCellForCoarsening(cellId);
242 adaptionData = mesh.adaptionPrepare(trackAdaptation);
252 if (adaptionInfo.entity != adaption::Entity::ENTITY_CELL) {
254 }
else if (adaptionInfo.type != adaption::TYPE_COARSENING) {
259 for (
long previousId : adaptionInfo.previous) {
260 previousScalarField.
insert(previousId, std::move(scalarField.
at(previousId)));
261 previousVectorField.
insert(previousId, std::move(vectorField.
at(previousId)));
269 adaptionData = mesh.adaptionAlter(trackAdaptation, squeeshPatchStorage);
278 if (adaptionInfo.entity != adaption::Entity::ENTITY_CELL) {
280 }
else if (adaptionInfo.type != adaption::TYPE_COARSENING) {
285 int nParents = adaptionInfo.previous.size();
286 double scalarParentAverage = 0.;
287 std::array<double, 3> vectorParentAverage = {{0., 0., 0.}};
288 for (
long parentId : adaptionInfo.previous) {
289 scalarParentAverage += previousScalarField.
at(parentId);
290 vectorParentAverage += previousVectorField.
at(parentId);
292 scalarParentAverage /= nParents;
293 vectorParentAverage /= (double) nParents;
296 long childId = adaptionInfo.current.front();
297 scalarField.
set(childId, scalarParentAverage);
298 vectorField.
set(childId, vectorParentAverage);
301 mesh.adaptionCleanup();
307#if BITPIT_ENABLE_MPI == 1
void flushData(std::fstream &stream, const std::string &name, VTKFormat format) override
The Cell class defines the cells.
The PatchKernel class provides an interface for defining patches.
const CellConstRange getVTKCellWriteRange() const
void setDynamicKernel(const PiercedKernel< id_t > *kernel, PiercedSyncMaster::SyncMode syncMode)
Metafunction for generating a pierced storage.
void set(id_t id, const value_t &value)
__PS_REFERENCE__ at(id_t id, std::size_t k=0)
__PVS_REFERENCE__ at(id_t id)
Metafunction for generating a pierced vector.
iterator insert(id_t id, const value_t &value)
The base class to be used to derive VTK streamers form.
void flushValue(std::fstream &, VTKFormat, const T &value) const
The VolOctree defines a Octree patch.
#define BITPIT_UNUSED(variable)
Logger & cout(log::Level defaultSeverity, log::Visibility defaultVisibility)
The Info struct defines the information associated to an adaption.