-
Notifications
You must be signed in to change notification settings - Fork 82
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
Checkpoint tools #885
Merged
Merged
Checkpoint tools #885
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
09f3c5e
setting up files for desired implementation
mbkuhn efb6057
starting point for more changes
mbkuhn e63a720
compiling version with more of the pieces
mbkuhn 5747c0b
changes to writing, max level
mbkuhn 7d82078
getting rid of IOManager_Mod, accessing checkpoint fields
mbkuhn 058c6e1
running version of the code!
mbkuhn 5e91e94
removing print statements
mbkuhn d0ac9e0
checkpoint to CSV that compiles
mbkuhn fc7faf8
additional fields
mbkuhn 805a0ea
cell sizes, proper variable names, reading routine
mbkuhn 977fe05
cleanup
mbkuhn b0b81c6
clarify arguments and format
mbkuhn d5382ef
Tool to convert plotfile to CSV, by Jose
mbkuhn 75f88dd
comment about where code comes from
mbkuhn a2f75df
another comment
mbkuhn 097fdda
format
mbkuhn 5375407
remove unused vars, shadow vars, cpp check stuff
mbkuhn acbbb3d
explicit constructor
mbkuhn 1d25adc
plt CI
mbkuhn 2035f3c
shadow variables
mbkuhn f78e548
suppress cppcheck
mbkuhn 72429c0
codeQL
mbkuhn 31e3a42
cppcheck
mbkuhn a2ccb14
Merge branch 'main' into coarsen_checkpoint
mbkuhn 4adf0c9
get the number of components right
mbkuhn 6bf120d
new cppcheck
mbkuhn 0c85cbd
Merge branch 'main' into coarsen_checkpoint
mbkuhn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
add_subdirectory(refine-chkpt) | ||
add_subdirectory(coarsen-chkpt) | ||
add_subdirectory(CheckpointToCSV) | ||
add_subdirectory(PlotfileToCSV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
set(tool_exe_name CheckpointToCSV) | ||
|
||
add_executable(${tool_exe_name}) | ||
target_sources(${tool_exe_name} | ||
PRIVATE | ||
CheckpointToCSV.cpp | ||
CheckpointFileUtil.cpp) | ||
|
||
target_include_directories(${tool_exe_name} PRIVATE | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) | ||
target_link_libraries(${tool_exe_name} PUBLIC ${amr_wind_lib_name} AMReX-Hydro::amrex_hydro_api) | ||
set_cuda_build_properties(${tool_exe_name}) | ||
|
||
install(TARGETS ${tool_exe_name} | ||
RUNTIME DESTINATION bin | ||
ARCHIVE DESTINATION lib | ||
LIBRARY DESTINATION lib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#ifndef CHECKPOINTFILEUTIL_H_ | ||
#define CHECKPOINTFILEUTIL_H_ | ||
#include <AMReX_Config.H> | ||
|
||
#include <AMReX_Geometry.H> | ||
#include <AMReX_MultiFab.H> | ||
#include <AMReX_VisMF.H> | ||
#include <string> | ||
#include <memory> | ||
|
||
using namespace amrex; | ||
|
||
// Adapted from amrex/Src/Base/AMReX_PlotFileDataImpl.H | ||
// not inherited because constructor needed to be rewritten | ||
|
||
class CheckpointFileDataImpl | ||
{ | ||
public: | ||
explicit CheckpointFileDataImpl( | ||
std::string const& chkptfile_name, | ||
Vector<std::string> addl_field_names = {}); | ||
|
||
[[nodiscard]] int spaceDim() const noexcept { return m_spacedim; } | ||
|
||
[[nodiscard]] Real time() const noexcept { return m_time; } | ||
|
||
[[nodiscard]] int finestLevel() const noexcept { return m_finest_level; } | ||
|
||
[[nodiscard]] const BoxArray& boxArray(int level) const noexcept | ||
{ | ||
return m_ba[level]; | ||
} | ||
|
||
[[nodiscard]] const DistributionMapping& | ||
DistributionMap(int level) const noexcept | ||
{ | ||
return m_dmap[level]; | ||
} | ||
|
||
void syncDistributionMap(CheckpointFileDataImpl const& src) noexcept; | ||
|
||
void | ||
syncDistributionMap(int level, CheckpointFileDataImpl const& src) noexcept; | ||
|
||
[[nodiscard]] Box probDomain(int level) const noexcept | ||
{ | ||
return m_prob_domain[level]; | ||
} | ||
[[nodiscard]] Array<Real, AMREX_SPACEDIM> probLo() const noexcept | ||
{ | ||
return m_prob_lo; | ||
} | ||
[[nodiscard]] Array<Real, AMREX_SPACEDIM> probHi() const noexcept | ||
{ | ||
return m_prob_hi; | ||
} | ||
[[nodiscard]] Array<Real, AMREX_SPACEDIM> cellSize(int level) const noexcept | ||
{ | ||
return m_cell_size[level]; | ||
} | ||
|
||
[[nodiscard]] const Vector<std::string>& varNames() const noexcept | ||
{ | ||
return m_var_names; | ||
} | ||
|
||
[[nodiscard]] const Vector<std::string>& varNamesComponents() const noexcept | ||
{ | ||
return m_var_names_full; | ||
} | ||
|
||
[[nodiscard]] int nComp() const noexcept { return m_ncomp; } | ||
[[nodiscard]] IntVect nGrowVect(int level) const noexcept | ||
{ | ||
return m_ngrow[level]; | ||
} | ||
|
||
MultiFab get(int level) noexcept; | ||
|
||
private: | ||
std::string m_chkptfile_name; | ||
int m_ncomp{8}; | ||
int m_nfields{4}; | ||
Vector<std::string> m_var_names = {"density", "gp", "p", "velocity"}; | ||
Vector<std::string> m_var_names_full = { | ||
"density", "gpx", "gpy", "gpz", | ||
"p", "velocityx", "velocityy", "velocityz"}; | ||
Vector<int> m_var_ncomp = {1, 3, 1, 3}; | ||
const int m_spacedim{3}; | ||
Real m_time; | ||
Real m_dt_restart; | ||
Real m_dt_nm1; | ||
Real m_dt_nm2; | ||
int m_finest_level, m_nlevels; | ||
Array<Real, AMREX_SPACEDIM> m_prob_lo{{AMREX_D_DECL(0., 0., 0.)}}; | ||
Array<Real, AMREX_SPACEDIM> m_prob_hi{{AMREX_D_DECL(1., 1., 1.)}}; | ||
Vector<int> m_ref_ratio; | ||
Vector<Box> m_prob_domain; | ||
int m_nstep; | ||
Vector<Array<Real, AMREX_SPACEDIM>> m_cell_size; | ||
Vector<std::string> m_mf_name; | ||
Vector<std::unique_ptr<VisMF>> m_vismf; | ||
Vector<BoxArray> m_ba; | ||
Vector<DistributionMapping> m_dmap; | ||
Vector<IntVect> m_ngrow; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
#include "CheckpointFileUtil.H" | ||
#include <AMReX_AsyncOut.H> | ||
#include <AMReX_PlotFileUtil.H> | ||
#include <AMReX_FPC.H> | ||
#include <AMReX_FabArrayUtility.H> | ||
#include <AMReX_ParallelDescriptor.H> | ||
#include <algorithm> | ||
#include <fstream> | ||
#include <iomanip> | ||
|
||
using namespace amrex; | ||
|
||
namespace { | ||
void GotoNextLine(std::istream& is) | ||
{ | ||
constexpr std::streamsize bl_ignore_max{100000}; | ||
is.ignore(bl_ignore_max, '\n'); | ||
} | ||
} // namespace | ||
|
||
CheckpointFileDataImpl::CheckpointFileDataImpl( | ||
std::string const& chkptfile_name, Vector<std::string> addl_field_names) | ||
: m_chkptfile_name(chkptfile_name) | ||
{ | ||
// Add field names from input | ||
const int naf = addl_field_names.size(); | ||
for (int n = 0; n < naf; ++n) { | ||
m_var_names.push_back(addl_field_names[n]); | ||
m_var_names_full.push_back(addl_field_names[n]); | ||
m_var_ncomp.push_back(1); | ||
} | ||
// Total number of components, assume addl fields are one component | ||
m_ncomp += naf; | ||
// Total number of fields | ||
m_nfields += naf; | ||
|
||
// Header | ||
std::string File(chkptfile_name + "/Header"); | ||
Vector<char> fileCharPtr; | ||
ParallelDescriptor::ReadAndBcastFile(File, fileCharPtr); | ||
std::istringstream is( | ||
std::string(fileCharPtr.dataPtr()), std::istringstream::in); | ||
|
||
std::string line, word; | ||
|
||
// !! -- Start reading from checkpoint file -- !! | ||
// Title line | ||
std::getline(is, line); | ||
|
||
// Finest level | ||
is >> m_finest_level; | ||
GotoNextLine(is); | ||
|
||
// Step count | ||
is >> m_nstep; | ||
GotoNextLine(is); | ||
|
||
// Current time | ||
is >> m_time; | ||
GotoNextLine(is); | ||
|
||
// Time step size | ||
is >> m_dt_restart; | ||
GotoNextLine(is); | ||
|
||
is >> m_dt_nm1; | ||
GotoNextLine(is); | ||
|
||
is >> m_dt_nm2; | ||
GotoNextLine(is); | ||
|
||
// Low coordinates of domain bounding box | ||
std::getline(is, line); | ||
{ | ||
std::istringstream lis(line); | ||
int i = 0; | ||
while (lis >> word) { | ||
m_prob_lo[i++] = std::stod(word); | ||
} | ||
} | ||
|
||
// High coordinates of domain bounding box | ||
std::getline(is, line); | ||
{ | ||
std::istringstream lis(line); | ||
int i = 0; | ||
while (lis >> word) { | ||
m_prob_hi[i++] = std::stod(word); | ||
} | ||
} | ||
|
||
// Read in box array to get domain box | ||
m_nlevels = m_finest_level + 1; | ||
m_ba.resize(m_nlevels); | ||
m_dmap.resize(m_nlevels); | ||
m_ngrow.resize(m_nlevels); | ||
m_prob_domain.resize(m_nlevels); | ||
m_cell_size.resize( | ||
m_nlevels, Array<Real, AMREX_SPACEDIM>{{AMREX_D_DECL(1., 1., 1.)}}); | ||
for (int lev = 0; lev <= m_finest_level; ++lev) { | ||
// read in level 'lev' BoxArray from Header | ||
m_ba[lev].readFrom(is); | ||
GotoNextLine(is); | ||
// get minimal box from box array for prob domain | ||
m_prob_domain[lev] = m_ba[lev].minimalBox(); | ||
// make distribution map | ||
m_dmap[lev].define(m_ba[lev], ParallelDescriptor::NProcs()); | ||
// ngrow is set to 0, don't know how to find it properly | ||
m_ngrow[lev] = {0, 0, 0}; | ||
} | ||
|
||
// Calculate cell size for lowest level | ||
for (int idim = 0; idim < m_spacedim; ++idim) { | ||
m_cell_size[0][idim] = (m_prob_hi[idim] - m_prob_lo[idim]) / | ||
(m_prob_domain[0].bigEnd(idim) - | ||
m_prob_domain[0].smallEnd(idim) + 1); | ||
} | ||
// Do the higher levels using refratio, assume 2 | ||
for (int lev = 1; lev <= m_finest_level; ++lev) { | ||
for (int idim = 0; idim < m_spacedim; ++idim) { | ||
m_cell_size[lev][idim] = m_cell_size[lev - 1][idim]; | ||
} | ||
} | ||
|
||
AMREX_ASSERT(m_nlevels > 0 && m_nlevels <= 1000); | ||
} | ||
|
||
void CheckpointFileDataImpl::syncDistributionMap( | ||
CheckpointFileDataImpl const& src) noexcept | ||
{ | ||
int nlevs_min = std::min(m_nlevels, src.m_nlevels); | ||
for (int ilev = 0; ilev < nlevs_min; ++ilev) { | ||
syncDistributionMap(ilev, src); | ||
} | ||
} | ||
|
||
void CheckpointFileDataImpl::syncDistributionMap( | ||
int level, CheckpointFileDataImpl const& src) noexcept | ||
{ | ||
if (level <= src.finestLevel() && | ||
m_dmap[level].size() == src.DistributionMap(level).size()) { | ||
m_dmap[level] = src.DistributionMap(level); | ||
} | ||
} | ||
|
||
MultiFab CheckpointFileDataImpl::get(int level) noexcept | ||
{ | ||
const std::string level_prefix{"Level_"}; | ||
MultiFab mf(m_ba[level], m_dmap[level], m_ncomp, m_ngrow[level]); | ||
|
||
// Do checkpoint reading, which is a field at a time | ||
for (int lev = 0; lev < m_nlevels; ++lev) { | ||
int icomp = 0; | ||
for (int nf = 0; nf < m_nfields; ++nf) { | ||
MultiFab tmp_mfab( | ||
m_ba[level], m_dmap[level], m_var_ncomp[nf], m_ngrow[level]); | ||
|
||
// Read current field into temporary fab | ||
amrex::VisMF::Read( | ||
tmp_mfab, | ||
amrex::MultiFabFileFullPrefix( | ||
lev, m_chkptfile_name, level_prefix, m_var_names[nf])); | ||
|
||
// Copy from tmp fab to bigger fab | ||
amrex::MultiFab::Copy( | ||
mf, tmp_mfab, 0, icomp, m_var_ncomp[nf], m_ngrow[lev]); | ||
// Advance index among total components | ||
icomp += m_var_ncomp[nf]; | ||
} | ||
} | ||
return mf; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
totally minor: you seem to be following camelCase for all the other member functions but this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true! this is straight from "amrex/Src/Base/AMReX_PlotFileDataImpl.H" though