From d3deb238aee2fca44a099ec45c08dc265223ca52 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Tue, 8 Sep 2020 09:53:02 -0700 Subject: openPMD: Generalize Mesh Position (#1296) This adds a small utility that returns the relative in-cell position of values on each cell depending on an `amrex::MultiFab`'s `Box`'s `IndexType`. This does not change the output of openPMD yet, since we spatially and temporally center fields before output, but makes the routines more general overall for future use. --- Source/Utils/RelativeCellPosition.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Source/Utils/RelativeCellPosition.cpp (limited to 'Source/Utils/RelativeCellPosition.cpp') diff --git a/Source/Utils/RelativeCellPosition.cpp b/Source/Utils/RelativeCellPosition.cpp new file mode 100644 index 000000000..58c35fa52 --- /dev/null +++ b/Source/Utils/RelativeCellPosition.cpp @@ -0,0 +1,29 @@ +/* Copyright 2020 Axel Huebl + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ +#include "RelativeCellPosition.H" + +#include + + +std::vector< double > +utils::getRelativeCellPosition(amrex::MultiFab const& mf) +{ + amrex::IndexType const idx_type = mf.ixType(); + + std::vector< double > relative_position(AMREX_SPACEDIM, 0.0); + + // amrex::CellIndex::CELL means: 0.5 from lower corner for that index/direction + // amrex::CellIndex::NODE means: at corner for that index/direction + // WarpX::do_nodal means: all indices/directions on CellIndex::NODE + for (int d = 0; d < AMREX_SPACEDIM; d++) + { + if (idx_type.cellCentered(d)) + relative_position.at(d) = 0.5; + } + + return relative_position; +} -- cgit v1.2.3