forked from AMReX-Codes/amrex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EB checkpoint files (AMReX-Codes#2897)
* support for loading EB from checkpoint file * add support for writing chkpt file as well Co-authored-by: Weiqun Zhang <[email protected]>
- Loading branch information
1 parent
35ed6b4
commit 539427a
Showing
15 changed files
with
823 additions
and
0 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef AMREX_EB2_INDEXSPACE_CHKPTFILE_H_ | ||
#define AMREX_EB2_INDEXSPACE_CHKPTFILE_H_ | ||
#include <AMReX_Config.H> | ||
|
||
#include <AMReX_EB2.H> | ||
#include <AMReX_EB2_Level_chkpt_file.H> | ||
|
||
#include <string> | ||
|
||
namespace amrex { namespace EB2 { | ||
|
||
class IndexSpaceChkptFile | ||
: public IndexSpace | ||
{ | ||
public: | ||
|
||
IndexSpaceChkptFile (const ChkptFile& chkptfile, | ||
const Geometry& geom, int required_coarsening_level, | ||
int max_coarsening_level, int ngrow, | ||
bool build_coarse_level_by_coarsening, | ||
bool extend_domain_face); | ||
|
||
IndexSpaceChkptFile (IndexSpaceChkptFile const&) = delete; | ||
IndexSpaceChkptFile (IndexSpaceChkptFile &&) = delete; | ||
void operator= (IndexSpaceChkptFile const&) = delete; | ||
void operator= (IndexSpaceChkptFile &&) = delete; | ||
|
||
virtual ~IndexSpaceChkptFile () {} | ||
|
||
virtual const Level& getLevel (const Geometry& geom) const final; | ||
virtual const Geometry& getGeometry (const Box& dom) const final; | ||
virtual const Box& coarsestDomain () const final { | ||
return m_geom.back().Domain(); | ||
} | ||
virtual void addFineLevels (int num_new_fine_levels) final; | ||
|
||
private: | ||
|
||
Vector<ChkptFileLevel> m_chkpt_file_level; | ||
Vector<Geometry> m_geom; | ||
Vector<Box> m_domain; | ||
Vector<int> 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,86 @@ | ||
#include <AMReX_EB2_IndexSpace_chkpt_file.H> | ||
|
||
namespace amrex { namespace EB2 { | ||
|
||
IndexSpaceChkptFile::IndexSpaceChkptFile (const ChkptFile& chkpt_file, | ||
const Geometry& geom, int required_coarsening_level, | ||
int max_coarsening_level, int ngrow, | ||
bool build_coarse_level_by_coarsening, | ||
bool extend_domain_face) | ||
{ | ||
Gpu::LaunchSafeGuard lsg(true); // Always use GPU | ||
|
||
// build finest level (i.e., level 0) first | ||
AMREX_ALWAYS_ASSERT(required_coarsening_level >= 0 && required_coarsening_level <= 30); | ||
max_coarsening_level = std::max(required_coarsening_level,max_coarsening_level); | ||
max_coarsening_level = std::min(30,max_coarsening_level); | ||
|
||
int ngrow_finest = std::max(ngrow,0); | ||
for (int i = 1; i <= required_coarsening_level; ++i) { | ||
ngrow_finest *= 2; | ||
} | ||
|
||
m_geom.push_back(geom); | ||
m_domain.push_back(geom.Domain()); | ||
m_ngrow.push_back(ngrow_finest); | ||
m_chkpt_file_level.reserve(max_coarsening_level+1); | ||
m_chkpt_file_level.emplace_back(this, chkpt_file, geom, EB2::max_grid_size, ngrow_finest, | ||
extend_domain_face); | ||
|
||
for (int ilev = 1; ilev <= max_coarsening_level; ++ilev) | ||
{ | ||
bool coarsenable = m_geom.back().Domain().coarsenable(2,2); | ||
if (!coarsenable) { | ||
if (ilev <= required_coarsening_level) { | ||
amrex::Abort("IndexSpaceImp: domain is not coarsenable at level "+std::to_string(ilev)); | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
int ng = (ilev > required_coarsening_level) ? 0 : m_ngrow.back()/2; | ||
|
||
Box cdomain = amrex::coarsen(m_geom.back().Domain(),2); | ||
Geometry cgeom = amrex::coarsen(m_geom.back(),2); | ||
m_chkpt_file_level.emplace_back(this, ilev, EB2::max_grid_size, ng, cgeom, m_chkpt_file_level[ilev-1]); | ||
if (!m_chkpt_file_level.back().isOK()) { | ||
m_chkpt_file_level.pop_back(); | ||
if (ilev <= required_coarsening_level) { | ||
if (build_coarse_level_by_coarsening) { | ||
amrex::Abort("Failed to build required coarse EB level "+std::to_string(ilev)); | ||
} else { | ||
amrex::Abort("Chkptfile only stored for finest level. Failed to build "+std::to_string(ilev)); | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
m_geom.push_back(cgeom); | ||
m_domain.push_back(cdomain); | ||
m_ngrow.push_back(ng); | ||
} | ||
} | ||
|
||
const Level& | ||
IndexSpaceChkptFile::getLevel (const Geometry& geom) const | ||
{ | ||
auto it = std::find(std::begin(m_domain), std::end(m_domain), geom.Domain()); | ||
int i = std::distance(m_domain.begin(), it); | ||
return m_chkpt_file_level[i]; | ||
} | ||
|
||
const Geometry& | ||
IndexSpaceChkptFile::getGeometry (const Box& dom) const | ||
{ | ||
auto it = std::find(std::begin(m_domain), std::end(m_domain), dom); | ||
int i = std::distance(m_domain.begin(), it); | ||
return m_geom[i]; | ||
} | ||
|
||
void | ||
IndexSpaceChkptFile::addFineLevels (int /*num_new_fine_levels*/) | ||
{ | ||
amrex::Abort("IndexSpaceChkptFile::addFineLevels: not supported"); | ||
} | ||
|
||
}} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef AMREX_EB2_LEVEL_CHKPT_FILE_H_ | ||
#define AMREX_EB2_LEVEL_CHKPT_FILE_H_ | ||
#include <AMReX_Config.H> | ||
|
||
#include <AMReX_EB2_Level.H> | ||
#include <AMReX_EB_chkpt_file.H> | ||
|
||
namespace amrex { namespace EB2 { | ||
|
||
class ChkptFileLevel | ||
: public GShopLevel<ChkptFile> | ||
{ | ||
public: | ||
|
||
ChkptFileLevel (IndexSpace const* is, ChkptFile const& chkpt_file, const Geometry& geom, | ||
int max_grid_size, int ngrow, bool extend_domain_face); | ||
|
||
ChkptFileLevel (IndexSpace const* is, int ilev, int max_grid_size, int ngrow, | ||
const Geometry& geom, ChkptFileLevel& fineLevel); | ||
|
||
// for cuda support | ||
void define_fine_chkpt_file (ChkptFile const& chkpt_file, | ||
Geometry const& geom, int max_grid_size, int ngrow, | ||
bool extend_domain_face); | ||
|
||
void finalize_cell_flags (); //sets the connection flags and adjustments to cellflags | ||
}; | ||
|
||
}} | ||
|
||
#endif |
Oops, something went wrong.