IBAMR  IBAMR version 0.19.
Public Member Functions | Private Member Functions | Private Attributes | List of all members
IBTK::HierarchyAveragedDataManager Class Reference

Class HierarchyAveragedDataManager provides a method of tracking and determining periodic steady states of fields. In particular, this class can be used to determine the average of a field over several instances, for example determining the mean flow of a turbulent flow field. More...

#include <ibtk/HierarchyAveragedDataManager.h>

Inheritance diagram for IBTK::HierarchyAveragedDataManager:
Inheritance graph
[legend]

Public Member Functions

 HierarchyAveragedDataManager (std::string object_name, SAMRAI::tbox::Pointer< SAMRAI::hier::Variable< NDIM > > var, SAMRAI::tbox::Pointer< SAMRAI::tbox::Database > input_db, SAMRAI::tbox::Pointer< SAMRAI::hier::GridGeometry< NDIM > > grid_geom, bool register_for_restart=true)
 
 HierarchyAveragedDataManager (std::string object_name, SAMRAI::tbox::Pointer< SAMRAI::hier::Variable< NDIM > > var, SAMRAI::tbox::Pointer< SAMRAI::tbox::Database > input_db, std::set< double > snapshot_time_points, double period_start_time, double period_end_time, double threshold, SAMRAI::tbox::Pointer< SAMRAI::hier::GridGeometry< NDIM > > grid_geom, bool register_for_restart=true)
 
 ~HierarchyAveragedDataManager ()=default
 The destructor for class HierarchyAveragedDataManager deallocates patch data as needed. More...
 
void clearSnapshots ()
 
bool updateTimeAveragedSnapshot (int u_idx, double time, SAMRAI::tbox::Pointer< SAMRAI::hier::PatchHierarchy< NDIM > > hierarchy, const int wgt_idx=IBTK::invalid_index, double tol=1.0e-8)
 
bool updateTimeAveragedSnapshot (int u_idx, double time, SAMRAI::tbox::Pointer< SAMRAI::hier::PatchHierarchy< NDIM > > hierarchy, const std::string &mean_refine_type, const int wgt_idx=IBTK::invalid_index, double tol=1.0e-8)
 
bool isAtPeriodicSteadyState ()
 
bool isAtPeriodicSteadyState (double time, const double tol)
 
const std::set< double > & getSnapshotTimePoints ()
 
double getTimePoint (double time, double tol)
 
SnapshotCachegetSnapshotCache ()
 
void putToDatabase (SAMRAI::tbox::Pointer< SAMRAI::tbox::Database > db) override
 

Private Member Functions

void getFromRestart ()
 
void commonConstructor (SAMRAI::tbox::Pointer< SAMRAI::tbox::Database > input_db)
 Registers a scratch variable with the variable database. This data is allocated and deallocated as needed. More...
 

Private Attributes

std::string d_object_name
 
SAMRAI::tbox::Pointer< SAMRAI::hier::Variable< NDIM > > d_var
 
int d_scratch_idx = IBTK::invalid_index
 
std::string d_mean_refine_type = "CONSERVATIVE_LINEAR_REFINE"
 
double d_period_start = std::numeric_limits<double>::quiet_NaN()
 
double d_period_end = std::numeric_limits<double>::quiet_NaN()
 
double d_period_length = std::numeric_limits<double>::quiet_NaN()
 
double d_periodic_thresh = std::numeric_limits<double>::quiet_NaN()
 
std::map< double, unsigned intd_idx_num_updates_map
 
std::map< double, boold_idx_steady_state_map
 
std::set< doubled_snapshot_time_pts
 
SnapshotCache d_snapshot_cache
 
std::unique_ptr< SAMRAI::appu::VisItDataWriter< NDIM > > d_visit_data_writer
 
SAMRAI::tbox::Pointer< SAMRAI::pdat::CellVariable< NDIM, double > > d_mean_var
 
int d_mean_idx = IBTK::invalid_index
 
SAMRAI::tbox::Pointer< SAMRAI::pdat::CellVariable< NDIM, double > > d_dev_var
 
int d_dev_idx = IBTK::invalid_index
 
int d_visit_ts = 0
 
bool d_output_data = true
 
bool d_enable_logging = true
 

Detailed Description

The average field is defined as \( \bar{u} = \lim_{N\rightarrow\infty}\frac{1}{N} \sum_{i = 0}^{N-1} u(x,t + i*P) \) in which \( P \) is the period. This class computes the average \( \bar{u}_N = \frac{1}{N} \sum_{i = 0}^{N-1} u(x,t + i*P) \) via the relation \( \bar{u}_N = \frac{N - 1}{N} \bar{u}_{N-1} + \frac{1}{N} u(x, t + (N-1)*P) \). The average is considered converged when the L2 norm of \( \frac{1}{N} (\bar{u}_N - u(x, t + (N-1)*P)) \) is less than some specified threshold.

Note when the period is equal to 0.0, the average field reduces to \( \bar{u} = \lim_{T\rightarrow\infty} \frac{1}{T} \int_0^T u(x, t_0 + \tau)d\tau \). In this case, it is important that snapshots be taken at consistent time intervals to ensure the above recurrence relation still holds.

If requested, this class can output visualization files corresponding to the tracked average and convergence criteria (called 'deviation'). Visualization files are written after every call to updateTimeAveragedSnapshot. Side and face centered variables are assumed to represent d-dimensional vector fields, while all other fields output a depth consistent with the provided variable in the constructor.

A common use of this class is to determine an average flow field over the course of a simulation. For example, the below code will take snapshots of a flow field at specified intervals.

while (t < T_final)
{
// Advance flow field
ins_integrator->advanceHierarchy(dt);
t += dt;
// Take a snapshot if at the correct time.
if (t >= next_snap_time)
{
auto var_db = VariableDatabase<NDIM>::getDatabase();
const int u_idx = var_db->mapVariableAndContextToIndex(ins_hierarchy->getVelocityVariable(),
ins_hierarchy->getCurrentContext());
HierarchyMathOps hier_math_ops("HierarchyMathOps", patch_hierarchy);
hier_math_ops.resetLevels(0, patch_hierarchy->getFinestLevelNumber());
const int wgt_sc_idx = hier_math_ops.getSideWeightPatchDescriptorIndex();
bool at_steady_state = hier_avg_data_manager.updateTimeAveragedSnapshot(
u_idx, t, patch_hierarchy, "CONSERVATIVE_LINEAR_REFINE", wgt_sc_idx, 1.0e-8);
if (at_steady_state)
pout << "Determined steady state!\n";
}
}

Constructor & Destructor Documentation

◆ HierarchyAveragedDataManager() [1/2]

IBTK::HierarchyAveragedDataManager::HierarchyAveragedDataManager ( std::string  object_name,
SAMRAI::tbox::Pointer< SAMRAI::hier::Variable< NDIM > >  var,
SAMRAI::tbox::Pointer< SAMRAI::tbox::Database input_db,
SAMRAI::tbox::Pointer< SAMRAI::hier::GridGeometry< NDIM > >  grid_geom,
bool  register_for_restart = true 
)

The constructor for class HierarchyAveragedDataManager sets some default values and determines data centering. The expected period and number of snapshots must be set in the input database. This class assumes the snapshots will be taken at equidistant points along the periodic interval.

The input database is searched for the following keys:

  • 'period_start_time' : Double that represents the beginning of the period
  • 'period_end_time' : Double that represents the end of the period. For cases where the period is zero, period_end_time should be set to period_start_time.
  • 'threshold' : Double to determine whether a given time point is at a periodic steady state.
  • 'num_snapshots' : Integer to determine the number of snapshots taken, equally sampled between t_start and t_end.
  • 'enable_logging' : Bool used to determine whether to print convergence information to the log file.
  • 'output_data' : Bool used to determine whether to write visualization files for the mean and deviations.
  • 'dir_dump_name' : String used to determine which folder to write visualization files to. Defaults to "./".
  • 'refine_type' : String to determine which refine operator will be used by default. Defaults to "CONSERVATIVE_LINEAR_REFINE".

◆ HierarchyAveragedDataManager() [2/2]

IBTK::HierarchyAveragedDataManager::HierarchyAveragedDataManager ( std::string  object_name,
SAMRAI::tbox::Pointer< SAMRAI::hier::Variable< NDIM > >  var,
SAMRAI::tbox::Pointer< SAMRAI::tbox::Database input_db,
std::set< double snapshot_time_points,
double  period_start_time,
double  period_end_time,
double  threshold,
SAMRAI::tbox::Pointer< SAMRAI::hier::GridGeometry< NDIM > >  grid_geom,
bool  register_for_restart = true 
)

The constructor for class HierarchyAveragedDataManager sets some default values and determines data centering. In this constructor, the times at which snapshots are taken are set by arguments.

The input database is searched for the following keys:

  • 'enable_logging' : Bool used to determine whether to print convergence information to the log file.
  • 'output_data' : Bool used to determine whether to write visualization files for the mean and deviations.
  • 'dir_dump_name' : String used to determine which folder to write visualization files to. Defaults to "./". Note that dir_dump_name should be unique from other directories where visualization files are written to prevent conflicts in summary files.
  • 'refine_type' : String to determine which refine operator will be used by default. Defaults to "CONSERVATIVE_LINEAR_REFINE".

◆ ~HierarchyAveragedDataManager()

IBTK::HierarchyAveragedDataManager::~HierarchyAveragedDataManager ( )
default

Member Function Documentation

◆ clearSnapshots()

void IBTK::HierarchyAveragedDataManager::clearSnapshots ( )

Clear the snapshots taken with this class.

◆ updateTimeAveragedSnapshot() [1/2]

bool IBTK::HierarchyAveragedDataManager::updateTimeAveragedSnapshot ( int  u_idx,
double  time,
SAMRAI::tbox::Pointer< SAMRAI::hier::PatchHierarchy< NDIM > >  hierarchy,
const int  wgt_idx = IBTK::invalid_index,
double  tol = 1.0e-8 
)
inline

Update the time averaged snapshot. The update is computed through the relation \( u_avg = u_avg + 1/N * (u - u_avg) \) in which N is the number of updates to the snapshot. If this the first update after clearSnapshots() is called, we simply copy data.

This function returns true if the snapshot is at a steady state, or that 1/N*||u - u_avg|| < threshold. Note that a weight patch index should be supplied to accurately compute the norm.

If specified in the constructor, this function also writes visualization files for both the mean field and the deviation.

◆ updateTimeAveragedSnapshot() [2/2]

bool IBTK::HierarchyAveragedDataManager::updateTimeAveragedSnapshot ( int  u_idx,
double  time,
SAMRAI::tbox::Pointer< SAMRAI::hier::PatchHierarchy< NDIM > >  hierarchy,
const std::string &  mean_refine_type,
const int  wgt_idx = IBTK::invalid_index,
double  tol = 1.0e-8 
)

◆ isAtPeriodicSteadyState() [1/2]

bool IBTK::HierarchyAveragedDataManager::isAtPeriodicSteadyState ( )
inline

Return true if all the tracked mean fields are at a steady state.

◆ isAtPeriodicSteadyState() [2/2]

bool IBTK::HierarchyAveragedDataManager::isAtPeriodicSteadyState ( double  time,
const double  tol 
)
inline

Return whether the point at the specified time is at a periodic steady state. If multiple time points are found within the provided tolerance, this function returns the closest time that is less than the requested time.

◆ getSnapshotTimePoints()

const std::set<double>& IBTK::HierarchyAveragedDataManager::getSnapshotTimePoints ( )
inline

Return the time points this class is storing.

◆ getTimePoint()

double IBTK::HierarchyAveragedDataManager::getTimePoint ( double  time,
double  tol 
)

Returns the exact data point at which points are being stored in the internal map. Note that if a time point is not found within the specified tolerance, an unrecoverable error occurs.

◆ getSnapshotCache()

SnapshotCache& IBTK::HierarchyAveragedDataManager::getSnapshotCache ( )
inline

Get the SnapshotCache object.

◆ putToDatabase()

void IBTK::HierarchyAveragedDataManager::putToDatabase ( SAMRAI::tbox::Pointer< SAMRAI::tbox::Database db)
overridevirtual

Write the averaged data manager to a database

Implements SAMRAI::tbox::Serializable.

◆ getFromRestart()

void IBTK::HierarchyAveragedDataManager::getFromRestart ( )
private

◆ commonConstructor()

void IBTK::HierarchyAveragedDataManager::commonConstructor ( SAMRAI::tbox::Pointer< SAMRAI::tbox::Database input_db)
private

Member Data Documentation

◆ d_object_name

std::string IBTK::HierarchyAveragedDataManager::d_object_name
private

◆ d_var

SAMRAI::tbox::Pointer<SAMRAI::hier::Variable<NDIM> > IBTK::HierarchyAveragedDataManager::d_var
private

◆ d_scratch_idx

int IBTK::HierarchyAveragedDataManager::d_scratch_idx = IBTK::invalid_index
private

◆ d_mean_refine_type

std::string IBTK::HierarchyAveragedDataManager::d_mean_refine_type = "CONSERVATIVE_LINEAR_REFINE"
private

◆ d_period_start

double IBTK::HierarchyAveragedDataManager::d_period_start = std::numeric_limits<double>::quiet_NaN()
private

◆ d_period_end

double IBTK::HierarchyAveragedDataManager::d_period_end = std::numeric_limits<double>::quiet_NaN()
private

◆ d_period_length

double IBTK::HierarchyAveragedDataManager::d_period_length = std::numeric_limits<double>::quiet_NaN()
private

◆ d_periodic_thresh

double IBTK::HierarchyAveragedDataManager::d_periodic_thresh = std::numeric_limits<double>::quiet_NaN()
private

◆ d_idx_num_updates_map

std::map<double, unsigned int> IBTK::HierarchyAveragedDataManager::d_idx_num_updates_map
private

◆ d_idx_steady_state_map

std::map<double, bool> IBTK::HierarchyAveragedDataManager::d_idx_steady_state_map
private

◆ d_snapshot_time_pts

std::set<double> IBTK::HierarchyAveragedDataManager::d_snapshot_time_pts
private

◆ d_snapshot_cache

SnapshotCache IBTK::HierarchyAveragedDataManager::d_snapshot_cache
private

◆ d_visit_data_writer

std::unique_ptr<SAMRAI::appu::VisItDataWriter<NDIM> > IBTK::HierarchyAveragedDataManager::d_visit_data_writer
private

◆ d_mean_var

SAMRAI::tbox::Pointer<SAMRAI::pdat::CellVariable<NDIM, double> > IBTK::HierarchyAveragedDataManager::d_mean_var
private

◆ d_mean_idx

int IBTK::HierarchyAveragedDataManager::d_mean_idx = IBTK::invalid_index
private

◆ d_dev_var

SAMRAI::tbox::Pointer<SAMRAI::pdat::CellVariable<NDIM, double> > IBTK::HierarchyAveragedDataManager::d_dev_var
private

◆ d_dev_idx

int IBTK::HierarchyAveragedDataManager::d_dev_idx = IBTK::invalid_index
private

◆ d_visit_ts

int IBTK::HierarchyAveragedDataManager::d_visit_ts = 0
private

◆ d_output_data

bool IBTK::HierarchyAveragedDataManager::d_output_data = true
private

◆ d_enable_logging

bool IBTK::HierarchyAveragedDataManager::d_enable_logging = true
private

The documentation for this class was generated from the following file:
SAMRAI::tbox::pout
std::ostream pout