Skip to content

Commit d3deb23

Browse files
authored
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.
1 parent b452f85 commit d3deb23

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

Source/Diagnostics/WarpXOpenPMD.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
#include "WarpXOpenPMD.H"
88
#include "FieldIO.H" // for getReversedVec
9+
#include "Utils/RelativeCellPosition.H"
910
#include "Utils/WarpXAlgorithmSelection.H"
1011
#include "Utils/WarpXUtil.H"
1112

@@ -792,9 +793,10 @@ WarpXOpenPMDPlot::WriteOpenPMDFields( //const std::string& filename,
792793
// Create a new mesh record component, and store the associated metadata
793794
auto mesh_comp = mesh[comp_name];
794795
mesh_comp.resetDataset( dataset );
795-
// Cell-centered data: position is at 0.5 of a cell size.
796-
// TODO: honor nodal/cell centered data per component; reverse order to axisLabel order
797-
mesh_comp.setPosition( std::vector<double>{AMREX_D_DECL(0.5, 0.5, 0.5)} );
796+
797+
auto relative_cell_pos = utils::getRelativeCellPosition( mf ); // AMReX Fortran index order
798+
std::reverse( relative_cell_pos.begin(), relative_cell_pos.end() ); // now in C order
799+
mesh_comp.setPosition( relative_cell_pos );
798800

799801
// Loop through the multifab, and store each box as a chunk,
800802
// in the openPMD file.

Source/Utils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ target_sources(WarpX
44
CoarsenMR.cpp
55
Interpolate.cpp
66
IntervalsParser.cpp
7+
RelativeCellPosition.cpp
78
WarpXAlgorithmSelection.cpp
89
WarpXMovingWindow.cpp
910
WarpXTagging.cpp

Source/Utils/Make.package

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ CEXE_sources += CoarsenIO.cpp
66
CEXE_sources += CoarsenMR.cpp
77
CEXE_sources += Interpolate.cpp
88
CEXE_sources += IntervalsParser.cpp
9+
CEXE_sources += RelativeCellPosition.cpp
910

1011
VPATH_LOCATIONS += $(WARPX_HOME)/Source/Utils
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* Copyright 2020 Axel Huebl
2+
*
3+
* This file is part of WarpX.
4+
*
5+
* License: BSD-3-Clause-LBNL
6+
*/
7+
#ifndef WARPX_RELATIVE_CELL_POSITION_H_
8+
#define WARPX_RELATIVE_CELL_POSITION_H_
9+
10+
#include "WarpX.H"
11+
12+
#include <AMReX_MultiFab.H>
13+
14+
#include <vector>
15+
16+
17+
namespace utils
18+
{
19+
/** Get the Relative Cell Position of Values in an MultiFab
20+
*
21+
* Translate the IndexType of a given MultiFab into a position relative to
22+
* the lower corner of a cell.
23+
*
24+
* @param[in] mf the amrex::MultiFab to get relative cell positions for
25+
* @return relative position to the lower corner, scaled to cell size [0.0:1.0)
26+
*/
27+
std::vector< double >
28+
getRelativeCellPosition (amrex::MultiFab const& mf);
29+
}
30+
31+
#endif // WARPX_RELATIVE_CELL_POSITION_H_
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Copyright 2020 Axel Huebl
2+
*
3+
* This file is part of WarpX.
4+
*
5+
* License: BSD-3-Clause-LBNL
6+
*/
7+
#include "RelativeCellPosition.H"
8+
9+
#include <AMReX_IndexType.H>
10+
11+
12+
std::vector< double >
13+
utils::getRelativeCellPosition(amrex::MultiFab const& mf)
14+
{
15+
amrex::IndexType const idx_type = mf.ixType();
16+
17+
std::vector< double > relative_position(AMREX_SPACEDIM, 0.0);
18+
19+
// amrex::CellIndex::CELL means: 0.5 from lower corner for that index/direction
20+
// amrex::CellIndex::NODE means: at corner for that index/direction
21+
// WarpX::do_nodal means: all indices/directions on CellIndex::NODE
22+
for (int d = 0; d < AMREX_SPACEDIM; d++)
23+
{
24+
if (idx_type.cellCentered(d))
25+
relative_position.at(d) = 0.5;
26+
}
27+
28+
return relative_position;
29+
}

0 commit comments

Comments
 (0)