Skip to content

Commit

Permalink
Enable viz of native boundary files (Exawind#1356)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchdf authored Nov 25, 2024
1 parent e12ec7b commit 68753c2
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 30 deletions.
40 changes: 40 additions & 0 deletions amr-wind/utilities/constants.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H

#include "AMReX_REAL.H"
#include "AMReX_Math.H"
#include "AMReX_GpuQualifiers.H"

namespace amr_wind::constants {

//! A number close to zero
static constexpr amrex::Real SMALL_NUM = static_cast<amrex::Real>(
std::numeric_limits<amrex::Real>::epsilon() * 1e10);

//! A number very close to zero
static constexpr amrex::Real EPS =
static_cast<amrex::Real>(std::numeric_limits<amrex::Real>::epsilon());

//! A tight tolerance
static constexpr amrex::Real TIGHT_TOL = 1e-12;

//! A loose tolerance
static constexpr amrex::Real LOOSE_TOL = 1e-8;

//! A large negative number
static constexpr amrex::Real LOW_NUM = static_cast<amrex::Real>(
std::numeric_limits<amrex::Real>::lowest() * 1e-10);

//! A large positive number
static constexpr amrex::Real LARGE_NUM =
static_cast<amrex::Real>(std::numeric_limits<amrex::Real>::max() * 1e-10);

//! Closeness comparison
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE bool
is_close(const amrex::Real a, const amrex::Real b)
{
return amrex::Math::abs(a - b) < EPS;
}

} // namespace amr_wind::constants
#endif
21 changes: 8 additions & 13 deletions amr-wind/utilities/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <AMReX_PlotFileUtil.H>
#include "amr-wind/incflo.H"
#include "amr-wind/core/Physics.H"
#include "amr-wind/utilities/io_utils.H"
#include "amr-wind/utilities/console_io.H"
#include "amr-wind/utilities/IOManager.H"

Expand All @@ -11,12 +12,6 @@ namespace {
const std::string level_prefix{"Level_"};
}

void goto_next_line(std::istream& is)
{
constexpr std::streamsize bl_ignore_max{100000};
is.ignore(bl_ignore_max, '\n');
}

void incflo::ReadCheckpointFile()
{
BL_PROFILE("amr-wind::incflo::ReadCheckpointFile()");
Expand Down Expand Up @@ -52,29 +47,29 @@ void incflo::ReadCheckpointFile()

// Finest level
is >> finest_level;
goto_next_line(is);
amr_wind::ioutils::goto_next_line(is);

int nstep;
amrex::Real cur_time, dt_restart;
// Step count
is >> nstep;
goto_next_line(is);
amr_wind::ioutils::goto_next_line(is);

// Current time
is >> cur_time;
goto_next_line(is);
amr_wind::ioutils::goto_next_line(is);

m_time.set_restart_time(nstep, cur_time);

// Time step size
is >> dt_restart;
goto_next_line(is);
amr_wind::ioutils::goto_next_line(is);

is >> m_time.delta_t_nm1();
goto_next_line(is);
amr_wind::ioutils::goto_next_line(is);

is >> m_time.delta_t_nm2();
goto_next_line(is);
amr_wind::ioutils::goto_next_line(is);

// Low coordinates of domain bounding box
std::getline(is, line);
Expand Down Expand Up @@ -153,7 +148,7 @@ void incflo::ReadCheckpointFile()
for (int lev = 0; lev <= finest_level; ++lev) {
// read in level 'lev' BoxArray from Header
ba_inp[lev].readFrom(is);
goto_next_line(is);
amr_wind::ioutils::goto_next_line(is);
}

// always use level 0 to check domain size
Expand Down
2 changes: 2 additions & 0 deletions amr-wind/utilities/io_utils.H
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const char* buildInfoGetGitHash(int i);

namespace amr_wind::ioutils {

void goto_next_line(std::istream& is);

inline std::string amr_wind_version()
{
return {amrex::buildInfoGetGitHash(1)};
Expand Down
6 changes: 6 additions & 0 deletions amr-wind/utilities/io_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

namespace amr_wind::ioutils {

void goto_next_line(std::istream& is)
{
constexpr std::streamsize bl_ignore_max{100000};
is.ignore(bl_ignore_max, '\n');
}

void read_flat_grid_file(
const std::string& fname,
amrex::Vector<amrex::Real>& xs,
Expand Down
8 changes: 7 additions & 1 deletion amr-wind/wind_energy/ABLBoundaryPlane.H
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "amr-wind/CFDSim.H"
#include "AMReX_Gpu.H"
#include "amr-wind/utilities/ncutils/nc_interface.H"
#include "amr-wind/utilities/io_utils.H"
#include <AMReX_BndryRegister.H>

namespace amr_wind {
Expand Down Expand Up @@ -126,10 +127,15 @@ public:

void write_header();

void write_bndry_native_header(const std::string& chkname);

void write_file();

void read_header();

amrex::Vector<amrex::BoxArray> read_bndry_native_boxarrays(
const std::string& chkname, const Field& field) const;

void read_file(const bool /* nph_target_time*/);

void populate_data(
Expand Down Expand Up @@ -177,7 +183,7 @@ private:
const int /*lev*/,
const Field* /*fld*/);
#endif
int boundary_native_file_levels();
int boundary_native_file_levels() const;

std::string m_title{"ABL boundary planes"};

Expand Down
Loading

0 comments on commit 68753c2

Please sign in to comment.