Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom coords #1039

Merged
merged 41 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
be24c3d
Add CoordinatesVec flag
jonahm-LANL Mar 29, 2024
dbf28b4
clean details a bit
jonahm-LANL Mar 29, 2024
4610d02
start special casing coordinate fields
jonahm-LANL Mar 29, 2024
071d305
clean up some of this insane C++ string processing
jonahm-LANL Mar 29, 2024
0e082bd
Merge branch 'jmm/output-nodes-2' into jmm/custom-coords
jonahm-LANL Mar 29, 2024
0ee7442
lets try this
jonahm-LANL Mar 29, 2024
7656598
working
jonahm-LANL Mar 29, 2024
da3727e
Merge branch 'jmm/output-nodes-2' into jmm/custom-coords
jonahm-LANL Apr 1, 2024
ac12de0
intermediate commit dealing with issues with 2D and 1D
jonahm-LANL Apr 1, 2024
a7c621c
gotcha
jonahm-LANL Apr 1, 2024
19379e4
am I insane
jonahm-LANL Apr 1, 2024
c652ebe
Merge branch 'jmm/output-nodes-2' into jmm/custom-coords
jonahm-LANL Apr 3, 2024
b198055
fix typos, enable particle output (optimistically)
jonahm-LANL Apr 3, 2024
0f8a018
oops, too much data to stringprintf from incomplete fix
jonahm-LANL Apr 3, 2024
0d6deb5
need c_str()
jonahm-LANL Apr 3, 2024
dc768e2
don't need it here
jonahm-LANL Apr 3, 2024
7f111a1
nope particles still don't work. I tried.
jonahm-LANL Apr 3, 2024
d958618
Merge branch 'develop' into jmm/custom-coords
jonahm-LANL Apr 3, 2024
525b80a
try to fix 2D and 1D meshes
jonahm-LANL Apr 3, 2024
f1ccda1
remove extraneous vector dimension
jonahm-LANL Apr 3, 2024
5acd3ac
make documentation explain
jonahm-LANL Apr 3, 2024
115cccd
fix issue with n321 in lower dims
jonahm-LANL Apr 3, 2024
bee7d4d
changelog
jonahm-LANL Apr 3, 2024
015b349
debug
jonahm-LANL Apr 3, 2024
ebbe5c6
debugging
jonahm-LANL Apr 3, 2024
738fe53
why wasnt mesh_ndim being passed correctly whatever try this
jonahm-LANL Apr 3, 2024
cb6eddb
remove warning since I tested polyline
jonahm-LANL Apr 3, 2024
610c324
oh my god what a mistake
jonahm-LANL Apr 4, 2024
53b140e
number of elements
jonahm-LANL Apr 4, 2024
4130974
try this polyline
jonahm-LANL Apr 4, 2024
7057ffe
shape
jonahm-LANL Apr 4, 2024
f982fd8
flat baby
jonahm-LANL Apr 4, 2024
5be9c99
topology
jonahm-LANL Apr 4, 2024
94cff20
I can't get 1D to work. Removed the insanity
jonahm-LANL Apr 4, 2024
7e29c1b
cant write ndim_mesh
jonahm-LANL Apr 4, 2024
55a99b4
globals my rank
jonahm-LANL Apr 4, 2024
ac75270
disable vector output
jonahm-LANL Apr 9, 2024
53bd349
Merge branch 'develop' into jmm/custom-coords
Yurlungur Apr 10, 2024
0b0599f
Merge branch 'develop' into jmm/custom-coords
Yurlungur Apr 10, 2024
ae4cffd
Switch to new gold file for sparse advection
jonahm-LANL Apr 10, 2024
80b39ae
Merge branch 'jmm/custom-coords' of github.com:lanl/parthenon into jm…
jonahm-LANL Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Current develop

### Added (new features/APIs/variables/...)

- [[PR1039]](https://github.com/parthenon-hpc-lab/parthenon/pull/1039) Add ability to output custom coordinate positions for Visit/Paraview
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ended up in the changelog for the previous release by accident.

- [[PR1019](https://github.com/parthenon-hpc-lab/parthenon/pull/1019) Enable output for non-cell-centered variables

### Changed (changing behavior/API/variables/...)
- [[PR 1024]](https://github.com/parthenon-hpc-lab/parthenon/pull/1024) Add .outN. to history output filenames
Expand All @@ -21,6 +22,7 @@


### Incompatibilities (i.e. breaking changes)
- [[PR1019](https://github.com/parthenon-hpc-lab/parthenon/pull/1019) Remove support for file formats < 3


## Release 24.03
Expand All @@ -39,7 +41,6 @@ Date: 2024-03-21
- [[PR 996]](https://github.com/parthenon-hpc-lab/parthenon/pull/996) Remove dynamic allocations from swarm particle creation

### Changed (changing behavior/API/variables/...)
- [[PR1019](https://github.com/parthenon-hpc-lab/parthenon/pull/1019) Enable output for non-cell-centered variables
- [[PR 973]](https://github.com/parthenon-hpc-lab/parthenon/pull/973) Multigrid performance upgrades

### Fixed (not changing behavior/API/variables/...)
Expand All @@ -58,7 +59,6 @@ Date: 2024-03-21
- [[PR 982]](https://github.com/parthenon-hpc-lab/parthenon/pull/982) add some gut check testing for parthenon-VIBE

### Incompatibilities (i.e. breaking changes)
- [[PR1019](https://github.com/parthenon-hpc-lab/parthenon/pull/1019) Remove support for file formats < 3
- [[PR 987]](https://github.com/parthenon-hpc-lab/parthenon/pull/987) Change the API for what was IterativeTasks
- [[PR 974]](https://github.com/parthenon-hpc-lab/parthenon/pull/974) Change GetParentPointer to always return T*
- [[PR 996]](https://github.com/parthenon-hpc-lab/parthenon/pull/996) Remove dynamic allocations from swarm particle creation
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ include(cmake/Format.cmake)
include(cmake/Lint.cmake)

# regression test reference data
set(REGRESSION_GOLD_STANDARD_VER 21 CACHE STRING "Version of gold standard to download and use")
set(REGRESSION_GOLD_STANDARD_VER 22 CACHE STRING "Version of gold standard to download and use")
set(REGRESSION_GOLD_STANDARD_HASH
"SHA512=e16b14272915b4607965e5900961402f6da96dc13da8ea3c3d213d61f82d3a1dded08c40a9ab644aa3409d93a045bba360a90a43dc289b24f525878f9ba50890"
"SHA512=c64f34b6841569c74c3918aa33d5c1fe6795b6ba124e25be7184c48f589ebe634062955e97969e68d252e59d8d0fce5d65e32b4252e2c2537f9f49ebfdf37ee0"
CACHE STRING "Hash of default gold standard file to download")
option(REGRESSION_GOLD_STANDARD_SYNC "Automatically sync gold standard files." ON)

Expand Down
3 changes: 3 additions & 0 deletions doc/sphinx/src/interface/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ These flags specify how a variable interacts with I/O. Enable them to
enable output properties.

- ``Metadata::Restart`` implies a variable is required in restart files
- ``Metadata::CoordinatesVec`` implies a variable should be used to
describe coordinate positions of nodes. Must be a node-centered
variable with 3 components.

Tensor properties and boundaries
--------------------------------
Expand Down
59 changes: 59 additions & 0 deletions doc/sphinx/src/outputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,65 @@ cases, the ``.xdmf`` files should be opened. In ParaView, select the
for ParaView and VisIt. However, our python tooling does support
all mesh locations.

Tying non-standard coordinates to visualization tools
------------------------------------------------------

By default, Parthenon outputs the positions of faces on each block in
``X1``, ``X2`` and ``X3`` and assumes these correspond to the ``x``,
``y``, and ``z`` components of the nodes on the mesh. However, some
applications may apply cooridnate transformations or use moving
meshes. In these cases, the above strategy will not provide intuitive
plots.

For these applications we provide a special ``Metadata`` flag. If you
mark a node-centered 3-vector variable with the the flag
``Metadata::CoordinatesVec``, and fill it with the ``x``, ``y``, and
``z`` values of your node positions, Parthenon will specify these
values should be used by visualization software such as Visit or
Paraview.

For example, in your package ``Initialize`` function, you might
declare something like:

.. code:: cpp

pkg->AddField("locations",
Metadata({Metadata::Node, Metadata::CoordinatesVec, Metadata::Derived, Metadata::OneCopy},
std::vector<int>{3}));

and then (trivially) if you set

.. code:: cpp

pman.app_input->InitMeshBlockUserData = SetGeometryBlock;

for

.. code:: cpp

void SetGeometryBlock(MeshBlock *pmb, ParameterInput *pin) {
/* boiler plate to build a pack object */
parthenon::par_for(DEFAULT_LOOP_PATTERN, "positions", DevExecSpace(), 0, pack.GetNBlocks() - 1,
kb.s, kb.e, jb.s, jb.e, ib.s, ib.e,
KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) {
const auto &coords = pack.GetCoordinates(b);
pack(b, 0, k, j, i) = coords.X<X1DIR, parthenon::TopologicalElement::NN>(k, j, i);
pack(b, 1, k, j, i) = coords.X<X2DIR, parthenon::TopologicalElement::NN>(k, j, i);
pack(b, 2, k, j, i) = coords.X<X3DIR, parthenon::TopologicalElement::NN>(k, j, i);
});
return;
}

then the code will set the nodal values to their trivial coordinate
values and these will be used for visualization. In a more non-trivial
example, ``SetGeometryBlock`` might apply a coordinate
transformation. Or actually evolve ``"locations"``.

.. warning::

Non-standard coordinates are not supported in XDMF for 1D meshes
and Parthenon will revert to the traditional output in 1D.

Preparing outputs for ``yt``
----------------------------

Expand Down
3 changes: 1 addition & 2 deletions example/sparse_advection/sparse_advection_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
// add sparse field
{
Metadata m({Metadata::Cell, Metadata::Independent, Metadata::WithFluxes,
Metadata::FillGhost, Metadata::Sparse},
std::vector<int>({1}));
Metadata::FillGhost, Metadata::Sparse});
lroberts36 marked this conversation as resolved.
Show resolved Hide resolved
SparsePool pool("sparse", m);

for (int sid = 0; sid < NUM_FIELDS; ++sid) {
Expand Down
82 changes: 82 additions & 0 deletions src/interface/metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,88 @@ std::ostream &operator<<(std::ostream &os, const parthenon::Metadata &m) {
return os;
}

// Return true if the flags constraints are satisfied, false otherwise. If throw_on_fail
// is true, throw a descriptive exception when invalid
bool Metadata::IsValid(bool throw_on_fail) const {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from hpp to cpp

bool valid = true;

// Topology
if (CountSet({None, Node, Edge, Face, Cell}) != 1) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW("Exactly one topology flag must be set");
}
}

// Role
if (CountSet({Private, Provides, Requires, Overridable}) != 1) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW("Exactly one role flag must be set");
}
}

// Shape
if (CountSet({Vector, Tensor}) > 1) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW("At most one shape flag can be set");
}
}

// Coordinates
if (IsSet(CoordinatesVec)) {
if (Where() != Node) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW("Coordinate field must be node-centered");
}
}
if (shape_.size() != 1) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW("Coordinate field must be tensor rank 1");
}
}
if (shape_[0] != 3) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW(
"Coordinate field must be 3-vector. (Does not need Vector metadata flag).");
Yurlungur marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

// Datatype
if (CountSet({Boolean, Integer, Real}) != 1) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW("Exactly one data type flag must be set");
}
}

// Independent
if (CountSet({Independent, Derived}) != 1) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW("Either the Independent or Derived flag must be set");
}
}

// Prolongation/restriction
if (IsRefined()) {
if (refinement_funcs_.label().size() == 0) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW(
"Registered for refinment but no prolongation/restriction ops found");
}
}
}

return valid;
}

std::vector<MetadataFlag> Metadata::Flags() const {
std::vector<MetadataFlag> set_flags;
const auto &flags = metadata_state.AllFlags();
Expand Down
66 changes: 9 additions & 57 deletions src/interface/metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@
/** the variable participate in GMG calculations */ \
PARTHENON_INTERNAL_FOR_FLAG(GMGRestrict) \
/** the variable must always be allocated for new blocks **/ \
PARTHENON_INTERNAL_FOR_FLAG(ForceAllocOnNewBlocks)
PARTHENON_INTERNAL_FOR_FLAG(ForceAllocOnNewBlocks) \
/************************************************/ \
/** Vars specifying coordinates for visualization purposes **/ \
/** You can specify a single 3D var **/ \
PARTHENON_INTERNAL_FOR_FLAG(CoordinatesVec)
namespace parthenon {

namespace internal {
Expand Down Expand Up @@ -383,62 +387,7 @@ class Metadata {

// Return true if the flags constraints are satisfied, false otherwise. If throw_on_fail
// is true, throw a descriptive exception when invalid
bool IsValid(bool throw_on_fail = false) const {
bool valid = true;

// Topology
if (CountSet({None, Node, Edge, Face, Cell}) != 1) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW("Exactly one topology flag must be set");
}
}

// Role
if (CountSet({Private, Provides, Requires, Overridable}) != 1) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW("Exactly one role flag must be set");
}
}

// Shape
if (CountSet({Vector, Tensor}) > 1) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW("At most one shape flag can be set");
}
}

// Datatype
if (CountSet({Boolean, Integer, Real}) != 1) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW("Exactly one data type flag must be set");
}
}

// Independent
if (CountSet({Independent, Derived}) != 1) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW("Either the Independent or Derived flag must be set");
}
}

// Prolongation/restriction
if (IsRefined()) {
if (refinement_funcs_.label().size() == 0) {
valid = false;
if (throw_on_fail) {
PARTHENON_THROW(
"Registered for refinment but no prolongation/restriction ops found");
}
}
}

return valid;
}
bool IsValid(bool throw_on_fail = false) const;

/*--------------------------------------------------------*/
// Getters for attributes
Expand Down Expand Up @@ -500,6 +449,9 @@ class Metadata {
IsSet(GMGProlongate) || IsSet(GMGRestrict));
}

// Returns true if this variable is a coords var
bool IsCoordinateField() const { return IsSet(CoordinatesVec); }

const std::vector<int> &Shape() const { return shape_; }

/*--------------------------------------------------------*/
Expand Down
4 changes: 3 additions & 1 deletion src/outputs/output_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct VarInfo {
MetadataFlag where;
bool is_sparse;
bool is_vector;
bool is_coordinate_field;
IndexShape cellbounds;
std::vector<std::string> component_labels;
// list of topological elements in variable... e.g., Face1, Face2, etc
Expand Down Expand Up @@ -132,7 +133,8 @@ struct VarInfo {
tensor_rank(metadata.Shape().size()), where(metadata.Where()),
topological_elements(topological_elements), is_sparse(is_sparse),
is_vector(is_vector), cellbounds(cellbounds), rnx_(nx_.rbegin(), nx_.rend()),
ntop_elems(topological_elements.size()), element_matters(ntop_elems > 1) {
ntop_elems(topological_elements.size()), element_matters(ntop_elems > 1),
is_coordinate_field(metadata.IsCoordinateField()) {
if (num_components <= 0) {
std::stringstream msg;
msg << "### ERROR: Got variable " << label << " with " << num_components
Expand Down
18 changes: 15 additions & 3 deletions src/outputs/parthenon_hdf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,27 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
// simulation, but not all variables may be allocated on all blocks

auto get_vars = [=](const std::shared_ptr<MeshBlock> pmb) {
auto &var_vec = pmb->meshblock_data.Get()->GetVariableVector();
const VariableVector<Real> &var_vec = pmb->meshblock_data.Get()->GetVariableVector();
VariableVector<Real> coords_vars =
GetAnyVariables(var_vec, {parthenon::Metadata::CoordinatesVec});
VariableVector<Real> out;
if (restart_) {
// get all vars with flag Independent OR restart
return GetAnyVariables(
out = GetAnyVariables(
var_vec, {parthenon::Metadata::Independent, parthenon::Metadata::Restart});
} else {
return GetAnyVariables(var_vec, output_params.variables);
out = GetAnyVariables(var_vec, output_params.variables);
}
auto coords_loc = std::find_if(out.begin(), out.end(), [](const auto &v) {
return v->metadata().IsCoordinateField();
});
// if we need to add the coords var to the list of output variables, do so.
if ((coords_vars.size() == 1) && (coords_loc == out.end())) {
out.push_back(coords_vars[0]); // there can be only one
}
Yurlungur marked this conversation as resolved.
Show resolved Hide resolved
return out;
};

// get list of all vars, just use the first block since the list is
// the same for all blocks
auto all_vars_info = VarInfo::GetAll(get_vars(pm->block_list.front()), cellbounds);
Expand Down
Loading
Loading