AMR-Wind
v0.1.0
CFD solver for wind plant simulations
|
#include <FieldRepo.H>
Public Member Functions | |
FieldRepo (const amrex::AmrCore &mesh) | |
FieldRepo (const FieldRepo &)=delete | |
FieldRepo & | operator= (const FieldRepo &)=delete |
~FieldRepo ()=default | |
void | make_new_level_from_scratch (int lev, amrex::Real time, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm) |
Perform field data management tasks when amrex::AmrCore::MakeNewLevelFromScratch is called. More... | |
void | make_new_level_from_coarse (int lev, amrex::Real time, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm) |
Allocate and initialize data on a finer level from the next coarser level. More... | |
void | remake_level (int lev, amrex::Real time, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm) |
Allocate and initialize data on an existing level during regrid. More... | |
void | clear_level (int lev) |
Remove a level during regrid. More... | |
Field & | declare_field (const std::string &name, const int ncomp=1, const int ngrow=0, const int nstates=1, const FieldLoc floc=FieldLoc::CELL) |
Create a new field instance. More... | |
Field & | declare_cc_field (const std::string &name, const int ncomp=1, const int ngrow=0, const int nstates=1) |
Declare a cell-centered field. More... | |
Field & | declare_nd_field (const std::string &name, const int ncomp=1, const int ngrow=0, const int nstates=1) |
Declare a node-centered field. More... | |
Field & | declare_xf_field (const std::string &name, const int ncomp=1, const int ngrow=0, const int nstates=1) |
Declare a face field on the faces with normal in x-direction. More... | |
Field & | declare_yf_field (const std::string &name, const int ncomp=1, const int ngrow=0, const int nstates=1) |
Declare a face field on the faces with normal in y-direction. More... | |
Field & | declare_zf_field (const std::string &name, const int ncomp=1, const int ngrow=0, const int nstates=1) |
Declare a face field on the faces with normal in z-direction. More... | |
amrex::Vector< Field * > | declare_face_normal_field (const amrex::Vector< std::string > &names, const int ncomp=1, const int ngrow=0, const int nstates=1) |
Declare a vector field with components in the x,y,z faces. More... | |
Field & | get_field (const std::string &name, const FieldState fstate=FieldState::New) const |
Return a previously created field identified by name and time state. More... | |
Field & | get_field (const int field_id) const |
Return a previously created field using a unique identifier. More... | |
Field & | get_mesh_mapping_field (FieldLoc floc) const |
Return a previously created mesh mapping field using field location. More... | |
Field & | get_mesh_mapping_detJ (FieldLoc floc) const |
Return a previously created mesh mapping detJ using field location. More... | |
bool | field_exists (const std::string &name, const FieldState fstate=FieldState::New) const |
Query if field uniquely identified by name and time state exists in repository. More... | |
IntField & | declare_int_field (const std::string &name, const int ncomp=1, const int ngrow=0, const int nstates=1, const FieldLoc floc=FieldLoc::CELL) |
Declare an integer field. More... | |
IntField & | get_int_field (const std::string &name, const FieldState fstate=FieldState::New) const |
Return a reference to an integer field. More... | |
IntField & | get_int_field (const int field_id) const |
Return a reference to a previously created integer field using unique identifier. More... | |
bool | int_field_exists (const std::string &name, const FieldState fstate=FieldState::New) const |
Query if an integer field exists. More... | |
std::unique_ptr< ScratchField > | create_scratch_field (const std::string &name, const int ncomp=1, const int nghost=0, const FieldLoc floc=FieldLoc::CELL) const |
Create a scratch field. More... | |
std::unique_ptr< ScratchField > | create_scratch_field (const int ncomp=1, const int nghost=0, const FieldLoc floc=FieldLoc::CELL) const |
Create a scratch field. More... | |
std::unique_ptr< ScratchField > | create_scratch_field_on_host (const std::string &name, const int ncomp=1, const int nghost=0, const FieldLoc floc=FieldLoc::CELL) const |
std::unique_ptr< ScratchField > | create_scratch_field_on_host (const int ncomp=1, const int nghost=0, const FieldLoc floc=FieldLoc::CELL) const |
std::unique_ptr< IntScratchField > | create_int_scratch_field_on_host (const std::string &name, const int ncomp=1, const int nghost=0, const FieldLoc floc=FieldLoc::CELL) const |
std::unique_ptr< IntScratchField > | create_int_scratch_field_on_host (const int ncomp=1, const int nghost=0, const FieldLoc floc=FieldLoc::CELL) const |
void | advance_states () noexcept |
Advance all fields with more than one timestate to the new timestep. More... | |
const amrex::AmrCore & | mesh () const |
Return a reference to the underlying AMR mesh instance. More... | |
int | num_active_levels () const noexcept |
Total number of levels currently active in the AMR mesh. More... | |
int | num_fields () const noexcept |
Number of fields registered in the database. More... | |
const amrex::Vector< std::unique_ptr< Field > > & | fields () const |
Return list of fields registered (for unit-test purposes only) More... | |
const amrex::FabFactory< amrex::FArrayBox > & | factory (int lev) const noexcept |
Return factory instance at a given level. More... | |
Protected Member Functions | |
amrex::MultiFab & | get_multifab (const unsigned fid, const int lev) noexcept |
Return the amrex::MultiFab instance for a field at a given level. More... | |
amrex::iMultiFab & | get_int_fab (const unsigned fid, const int lev) noexcept |
Return the integer fab instance for a field at a given level. More... | |
Field & | create_state (Field &field, const FieldState fstate) |
Create a new state for a field. More... | |
void | allocate_field_data (int lev, const Field &field, LevelDataHolder &level_data, const amrex::FabFactory< amrex::FArrayBox > &factory) |
Allocate field data for a single level outside of regrid. More... | |
void | allocate_field_data (Field &field) |
Allocate field data at all levels. More... | |
void | allocate_field_data (const amrex::BoxArray &ba, const amrex::DistributionMapping &dm, LevelDataHolder &level_data, const amrex::FabFactory< amrex::FArrayBox > &factory) |
Allocate data at a level during regrid. More... | |
void | allocate_field_data (int lev, const IntField &field, LevelDataHolder &level_data) |
void | allocate_field_data (const IntField &field) |
void | allocate_field_data (const amrex::BoxArray &ba, const amrex::DistributionMapping &dm, LevelDataHolder &level_data, const amrex::FabFactory< amrex::IArrayBox > &factory) |
Protected Attributes | |
const amrex::AmrCore & | m_mesh |
Reference to the mesh instance. More... | |
amrex::Vector< std::unique_ptr< LevelDataHolder > > | m_leveldata |
Array (size: nlevels) of data holder that contains another array of MultiFabs for all fields at that level. More... | |
amrex::Vector< std::unique_ptr< Field > > | m_field_vec |
References to field instances identified by unique integer. More... | |
amrex::Vector< std::unique_ptr< IntField > > | m_int_field_vec |
Reference to integer field instances identified by unique integer. More... | |
std::unordered_map< std::string, size_t > | m_fid_map |
Map of field name to unique integer ID for lookups. More... | |
std::unordered_map< std::string, size_t > | m_int_fid_map |
Map of integer field name to unique integer ID for lookups. More... | |
bool | m_is_initialized {false} |
Flag indicating if mesh is available to allocate field data. More... | |
Friends | |
class | Field |
class | IntField |
Field Repository.
FieldRepo is a database that manages handling of fields used during a simulation. It provides an interface to automatically handle the creation/destruction of lower-level data structures (amrex::MultiFab) during regrids and handles the interface between the actual data and the amr_wind::Field interface which doesn't hold any actual data.
FieldRepo allows the user to declare instances of fields and their types (e.g., cell or node cenrered), and allows querying and accessing these fields at different places in the code and ensures the same data is accessed everywhere.
Fields can be declared at any time, even before the actual mesh instance is created, and it is recommended that they be created before mesh is initialized so that initialization happens automatically. When fields are declared before a mesh is available, data allocation is deferred until the mesh is generated (MakeNewLevelFromScratch
). However, if a mesh is available, data is allocated and ready for use immediately upon declaration.
Field declarations use a unique string name to differentiate different fields. If amr_wind::FieldRepo::declare_field is called multiple times with the same field name, the previously created instance is returned on subsequent calls. However, an error is raised if the subsequent calls do not have the same field parameters (e.g., number of components, states, or ghost cells).
Fields can be accessed using amr_wind::FieldRepo::get_field method. Unlike the declaration method, this method will raise an error if no field exists. amr_wind::FieldRepo::field_exists can be used to determine if a field exists in the repository.
FieldRepo also manages integer fields (IntField) as well as creation of ScratchField instances.
|
inlineexplicit |
|
delete |
|
default |
|
noexcept |
Advance all fields with more than one timestate to the new timestep.
|
protected |
Allocate data at a level during regrid.
|
protected |
|
protected |
|
protected |
Allocate field data at all levels.
|
protected |
Allocate field data for a single level outside of regrid.
|
protected |
void amr_wind::FieldRepo::clear_level | ( | int | lev | ) |
Remove a level during regrid.
std::unique_ptr< IntScratchField > amr_wind::FieldRepo::create_int_scratch_field_on_host | ( | const int | ncomp = 1 , |
const int | nghost = 0 , |
||
const FieldLoc | floc = FieldLoc::CELL |
||
) | const |
std::unique_ptr< IntScratchField > amr_wind::FieldRepo::create_int_scratch_field_on_host | ( | const std::string & | name, |
const int | ncomp = 1 , |
||
const int | nghost = 0 , |
||
const FieldLoc | floc = FieldLoc::CELL |
||
) | const |
std::unique_ptr< ScratchField > amr_wind::FieldRepo::create_scratch_field | ( | const int | ncomp = 1 , |
const int | nghost = 0 , |
||
const FieldLoc | floc = FieldLoc::CELL |
||
) | const |
Create a scratch field.
ScratchField is a temporary field used to compute and store intermediate quantities that are needed within a timestep. Scratch fields provide an API similar to Field, but do not contain multiple states. The underlying MultiFab data is not managed by FieldRepo and, therefore, ScratchField do not survive a regrid. This method returns a unique_ptr instance that is only valid within a timestep. It is not safe to hold a reference to the ScratchField object across timesteps.
std::unique_ptr< ScratchField > amr_wind::FieldRepo::create_scratch_field | ( | const std::string & | name, |
const int | ncomp = 1 , |
||
const int | nghost = 0 , |
||
const FieldLoc | floc = FieldLoc::CELL |
||
) | const |
Create a scratch field.
ScratchField is a temporary field used to compute and store intermediate quantities that are needed within a timestep. Scratch fields provide an API similar to Field, but do not contain multiple states. The underlying MultiFab data is not managed by FieldRepo and, therefore, ScratchField do not survive a regrid. This method returns a unique_ptr instance that is only valid within a timestep. It is not safe to hold a reference to the ScratchField object across timesteps.
std::unique_ptr< ScratchField > amr_wind::FieldRepo::create_scratch_field_on_host | ( | const int | ncomp = 1 , |
const int | nghost = 0 , |
||
const FieldLoc | floc = FieldLoc::CELL |
||
) | const |
std::unique_ptr< ScratchField > amr_wind::FieldRepo::create_scratch_field_on_host | ( | const std::string & | name, |
const int | ncomp = 1 , |
||
const int | nghost = 0 , |
||
const FieldLoc | floc = FieldLoc::CELL |
||
) | const |
|
protected |
Create a new state for a field.
|
inline |
Declare a cell-centered field.
This is a convenience wrapper around declare_field
|
inline |
Declare a vector field with components in the x,y,z faces.
This is a convenience function around declare_field
Field & amr_wind::FieldRepo::declare_field | ( | const std::string & | name, |
const int | ncomp = 1 , |
||
const int | ngrow = 0 , |
||
const int | nstates = 1 , |
||
const FieldLoc | floc = FieldLoc::CELL |
||
) |
Create a new field instance.
name | Unique identifier for this field |
ncomp | Number of components in this field (default: 1) |
ngrow | Number of ghost cells/nodes for this field (default: 1) |
nstates | Number of time states for this field (default: 1) |
floc | Field location (default: cell-centered) |
IntField & amr_wind::FieldRepo::declare_int_field | ( | const std::string & | name, |
const int | ncomp = 1 , |
||
const int | ngrow = 0 , |
||
const int | nstates = 1 , |
||
const FieldLoc | floc = FieldLoc::CELL |
||
) |
Declare an integer field.
Integer fields are used for masks and iblanking with overset meshes
name | [in] Unique identifier for the field |
|
inline |
Declare a node-centered field.
This is a convenience wrapper around declare_field
|
inline |
Declare a face field on the faces with normal in x-direction.
This is a convenience wrapper around declare_field
|
inline |
Declare a face field on the faces with normal in y-direction.
This is a convenience wrapper around declare_field
|
inline |
Declare a face field on the faces with normal in z-direction.
This is a convenience wrapper around declare_field
|
inlinenoexcept |
Return factory instance at a given level.
bool amr_wind::FieldRepo::field_exists | ( | const std::string & | name, |
const FieldState | fstate = FieldState::New |
||
) | const |
Query if field uniquely identified by name and time state exists in repository.
|
inline |
Return list of fields registered (for unit-test purposes only)
|
inline |
Return a previously created field using a unique identifier.
Field & amr_wind::FieldRepo::get_field | ( | const std::string & | name, |
const FieldState | fstate = FieldState::New |
||
) | const |
Return a previously created field identified by name and time state.
|
inlineprotectednoexcept |
Return the integer fab instance for a field at a given level.
fid | Unique integer field identifier for this field |
lev | AMR level |
|
inline |
Return a reference to a previously created integer field using unique identifier.
IntField & amr_wind::FieldRepo::get_int_field | ( | const std::string & | name, |
const FieldState | fstate = FieldState::New |
||
) | const |
Return a reference to an integer field.
Return a previously created mesh mapping detJ using field location.
Return a previously created mesh mapping field using field location.
|
inlineprotectednoexcept |
Return the amrex::MultiFab instance for a field at a given level.
fid | Unique integer field identifier for this field |
lev | AMR level |
bool amr_wind::FieldRepo::int_field_exists | ( | const std::string & | name, |
const FieldState | fstate = FieldState::New |
||
) | const |
Query if an integer field exists.
void amr_wind::FieldRepo::make_new_level_from_coarse | ( | int | lev, |
amrex::Real | time, | ||
const amrex::BoxArray & | ba, | ||
const amrex::DistributionMapping & | dm | ||
) |
Allocate and initialize data on a finer level from the next coarser level.
This is called by the AmrCore automatically during regrid process
void amr_wind::FieldRepo::make_new_level_from_scratch | ( | int | lev, |
amrex::Real | time, | ||
const amrex::BoxArray & | ba, | ||
const amrex::DistributionMapping & | dm | ||
) |
Perform field data management tasks when amrex::AmrCore::MakeNewLevelFromScratch is called.
|
inline |
Return a reference to the underlying AMR mesh instance.
|
inlinenoexcept |
Total number of levels currently active in the AMR mesh.
|
inlinenoexcept |
Number of fields registered in the database.
void amr_wind::FieldRepo::remake_level | ( | int | lev, |
amrex::Real | time, | ||
const amrex::BoxArray & | ba, | ||
const amrex::DistributionMapping & | dm | ||
) |
Allocate and initialize data on an existing level during regrid.
This is called by the AmrCore automatically during regrid process
|
friend |
|
friend |
|
protected |
Map of field name to unique integer ID for lookups.
|
mutableprotected |
References to field instances identified by unique integer.
|
protected |
Map of integer field name to unique integer ID for lookups.
|
mutableprotected |
Reference to integer field instances identified by unique integer.
|
protected |
Flag indicating if mesh is available to allocate field data.
|
protected |
Array (size: nlevels) of data holder that contains another array of MultiFabs for all fields at that level.
|
protected |
Reference to the mesh instance.