AMR-Wind  v0.1.0
CFD solver for wind plant simulations
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
amr_wind::FieldRepo Class Reference

Field Repository. More...

#include <FieldRepo.H>

Collaboration diagram for amr_wind::FieldRepo:
[legend]

Public Member Functions

 FieldRepo (const amrex::AmrCore &mesh)
 
 FieldRepo (const FieldRepo &)=delete
 
FieldRepooperator= (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...
 
Fielddeclare_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...
 
Fielddeclare_cc_field (const std::string &name, const int ncomp=1, const int ngrow=0, const int nstates=1)
 Declare a cell-centered field. More...
 
Fielddeclare_nd_field (const std::string &name, const int ncomp=1, const int ngrow=0, const int nstates=1)
 Declare a node-centered field. More...
 
Fielddeclare_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...
 
Fielddeclare_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...
 
Fielddeclare_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...
 
Fieldget_field (const std::string &name, const FieldState fstate=FieldState::New) const
 Return a previously created field identified by name and time state. More...
 
Fieldget_field (const int field_id) const
 Return a previously created field using a unique identifier. More...
 
Fieldget_mesh_mapping_field (FieldLoc floc) const
 Return a previously created mesh mapping field using field location. More...
 
Fieldget_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...
 
IntFielddeclare_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...
 
IntFieldget_int_field (const std::string &name, const FieldState fstate=FieldState::New) const
 Return a reference to an integer field. More...
 
IntFieldget_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< ScratchFieldcreate_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< ScratchFieldcreate_scratch_field (const int ncomp=1, const int nghost=0, const FieldLoc floc=FieldLoc::CELL) const
 Create a scratch field. More...
 
std::unique_ptr< ScratchFieldcreate_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< ScratchFieldcreate_scratch_field_on_host (const int ncomp=1, const int nghost=0, const FieldLoc floc=FieldLoc::CELL) const
 
std::unique_ptr< IntScratchFieldcreate_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< IntScratchFieldcreate_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...
 
Fieldcreate_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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ FieldRepo() [1/2]

amr_wind::FieldRepo::FieldRepo ( const amrex::AmrCore &  mesh)
inlineexplicit

◆ FieldRepo() [2/2]

amr_wind::FieldRepo::FieldRepo ( const FieldRepo )
delete

◆ ~FieldRepo()

amr_wind::FieldRepo::~FieldRepo ( )
default

Member Function Documentation

◆ advance_states()

void amr_wind::FieldRepo::advance_states ( )
noexcept

Advance all fields with more than one timestate to the new timestep.

◆ allocate_field_data() [1/6]

void amr_wind::FieldRepo::allocate_field_data ( const amrex::BoxArray &  ba,
const amrex::DistributionMapping &  dm,
LevelDataHolder level_data,
const amrex::FabFactory< amrex::FArrayBox > &  factory 
)
protected

Allocate data at a level during regrid.

◆ allocate_field_data() [2/6]

void amr_wind::FieldRepo::allocate_field_data ( const amrex::BoxArray &  ba,
const amrex::DistributionMapping &  dm,
LevelDataHolder level_data,
const amrex::FabFactory< amrex::IArrayBox > &  factory 
)
protected

◆ allocate_field_data() [3/6]

void amr_wind::FieldRepo::allocate_field_data ( const IntField field)
protected

◆ allocate_field_data() [4/6]

void amr_wind::FieldRepo::allocate_field_data ( Field field)
protected

Allocate field data at all levels.

◆ allocate_field_data() [5/6]

void amr_wind::FieldRepo::allocate_field_data ( int  lev,
const Field field,
LevelDataHolder level_data,
const amrex::FabFactory< amrex::FArrayBox > &  factory 
)
protected

Allocate field data for a single level outside of regrid.

◆ allocate_field_data() [6/6]

void amr_wind::FieldRepo::allocate_field_data ( int  lev,
const IntField field,
LevelDataHolder level_data 
)
protected

◆ clear_level()

void amr_wind::FieldRepo::clear_level ( int  lev)

Remove a level during regrid.

◆ create_int_scratch_field_on_host() [1/2]

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

◆ create_int_scratch_field_on_host() [2/2]

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

◆ create_scratch_field() [1/2]

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.

◆ create_scratch_field() [2/2]

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.

◆ create_scratch_field_on_host() [1/2]

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

◆ create_scratch_field_on_host() [2/2]

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

◆ create_state()

Field & amr_wind::FieldRepo::create_state ( Field field,
const FieldState  fstate 
)
protected

Create a new state for a field.

◆ declare_cc_field()

Field& amr_wind::FieldRepo::declare_cc_field ( const std::string &  name,
const int  ncomp = 1,
const int  ngrow = 0,
const int  nstates = 1 
)
inline

Declare a cell-centered field.

This is a convenience wrapper around declare_field

See also
amr_wind::FieldRepo::declare_field

◆ declare_face_normal_field()

amrex::Vector<Field*> amr_wind::FieldRepo::declare_face_normal_field ( const amrex::Vector< std::string > &  names,
const int  ncomp = 1,
const int  ngrow = 0,
const int  nstates = 1 
)
inline

Declare a vector field with components in the x,y,z faces.

This is a convenience function around declare_field

◆ 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.

Parameters
nameUnique identifier for this field
ncompNumber of components in this field (default: 1)
ngrowNumber of ghost cells/nodes for this field (default: 1)
nstatesNumber of time states for this field (default: 1)
flocField location (default: cell-centered)

◆ declare_int_field()

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

Parameters
name[in] Unique identifier for the field

◆ declare_nd_field()

Field& amr_wind::FieldRepo::declare_nd_field ( const std::string &  name,
const int  ncomp = 1,
const int  ngrow = 0,
const int  nstates = 1 
)
inline

Declare a node-centered field.

This is a convenience wrapper around declare_field

See also
amr_wind::FieldRepo::declare_field

◆ declare_xf_field()

Field& amr_wind::FieldRepo::declare_xf_field ( const std::string &  name,
const int  ncomp = 1,
const int  ngrow = 0,
const int  nstates = 1 
)
inline

Declare a face field on the faces with normal in x-direction.

This is a convenience wrapper around declare_field

See also
amr_wind::FieldRepo::declare_field

◆ declare_yf_field()

Field& amr_wind::FieldRepo::declare_yf_field ( const std::string &  name,
const int  ncomp = 1,
const int  ngrow = 0,
const int  nstates = 1 
)
inline

Declare a face field on the faces with normal in y-direction.

This is a convenience wrapper around declare_field

See also
amr_wind::FieldRepo::declare_field

◆ declare_zf_field()

Field& amr_wind::FieldRepo::declare_zf_field ( const std::string &  name,
const int  ncomp = 1,
const int  ngrow = 0,
const int  nstates = 1 
)
inline

Declare a face field on the faces with normal in z-direction.

This is a convenience wrapper around declare_field

See also
amr_wind::FieldRepo::declare_field

◆ factory()

const amrex::FabFactory<amrex::FArrayBox>& amr_wind::FieldRepo::factory ( int  lev) const
inlinenoexcept

Return factory instance at a given level.

◆ field_exists()

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.

◆ fields()

const amrex::Vector<std::unique_ptr<Field> >& amr_wind::FieldRepo::fields ( ) const
inline

Return list of fields registered (for unit-test purposes only)

◆ get_field() [1/2]

Field& amr_wind::FieldRepo::get_field ( const int  field_id) const
inline

Return a previously created field using a unique identifier.

◆ get_field() [2/2]

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.

◆ get_int_fab()

amrex::iMultiFab& amr_wind::FieldRepo::get_int_fab ( const unsigned  fid,
const int  lev 
)
inlineprotectednoexcept

Return the integer fab instance for a field at a given level.

Parameters
fidUnique integer field identifier for this field
levAMR level

◆ get_int_field() [1/2]

IntField& amr_wind::FieldRepo::get_int_field ( const int  field_id) const
inline

Return a reference to a previously created integer field using unique identifier.

◆ get_int_field() [2/2]

IntField & amr_wind::FieldRepo::get_int_field ( const std::string &  name,
const FieldState  fstate = FieldState::New 
) const

Return a reference to an integer field.

◆ get_mesh_mapping_detJ()

Field & amr_wind::FieldRepo::get_mesh_mapping_detJ ( FieldLoc  floc) const

Return a previously created mesh mapping detJ using field location.

◆ get_mesh_mapping_field()

Field & amr_wind::FieldRepo::get_mesh_mapping_field ( FieldLoc  floc) const

Return a previously created mesh mapping field using field location.

◆ get_multifab()

amrex::MultiFab& amr_wind::FieldRepo::get_multifab ( const unsigned  fid,
const int  lev 
)
inlineprotectednoexcept

Return the amrex::MultiFab instance for a field at a given level.

Parameters
fidUnique integer field identifier for this field
levAMR level

◆ int_field_exists()

bool amr_wind::FieldRepo::int_field_exists ( const std::string &  name,
const FieldState  fstate = FieldState::New 
) const

Query if an integer field exists.

◆ make_new_level_from_coarse()

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

◆ make_new_level_from_scratch()

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.

◆ mesh()

const amrex::AmrCore& amr_wind::FieldRepo::mesh ( ) const
inline

Return a reference to the underlying AMR mesh instance.

◆ num_active_levels()

int amr_wind::FieldRepo::num_active_levels ( ) const
inlinenoexcept

Total number of levels currently active in the AMR mesh.

◆ num_fields()

int amr_wind::FieldRepo::num_fields ( ) const
inlinenoexcept

Number of fields registered in the database.

◆ operator=()

FieldRepo& amr_wind::FieldRepo::operator= ( const FieldRepo )
delete

◆ remake_level()

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

Friends And Related Function Documentation

◆ Field

friend class Field
friend

◆ IntField

friend class IntField
friend

Member Data Documentation

◆ m_fid_map

std::unordered_map<std::string, size_t> amr_wind::FieldRepo::m_fid_map
protected

Map of field name to unique integer ID for lookups.

◆ m_field_vec

amrex::Vector<std::unique_ptr<Field> > amr_wind::FieldRepo::m_field_vec
mutableprotected

References to field instances identified by unique integer.

◆ m_int_fid_map

std::unordered_map<std::string, size_t> amr_wind::FieldRepo::m_int_fid_map
protected

Map of integer field name to unique integer ID for lookups.

◆ m_int_field_vec

amrex::Vector<std::unique_ptr<IntField> > amr_wind::FieldRepo::m_int_field_vec
mutableprotected

Reference to integer field instances identified by unique integer.

◆ m_is_initialized

bool amr_wind::FieldRepo::m_is_initialized {false}
protected

Flag indicating if mesh is available to allocate field data.

◆ m_leveldata

amrex::Vector<std::unique_ptr<LevelDataHolder> > amr_wind::FieldRepo::m_leveldata
protected

Array (size: nlevels) of data holder that contains another array of MultiFabs for all fields at that level.

◆ m_mesh

const amrex::AmrCore& amr_wind::FieldRepo::m_mesh
protected

Reference to the mesh instance.


The documentation for this class was generated from the following files: