-
Notifications
You must be signed in to change notification settings - Fork 2
FieldMap Class
Jacob Fields edited this page Jun 16, 2020
·
1 revision
The FieldMap class stores information about every field and its corresponding ODEData data structure for a specific Grid. In its most basic form, FieldMap is just a wrapper around std::map with some additional convenience functionality to make it easy to work with fields in OOPS-2D.
| Method | Description |
|---|---|
FieldMap(const Grid* grid) |
A constructor that creates a FieldMap for a specific Grid and no fields. |
FieldMap(const Grid* grid, std::map<std::string, FieldInfo>& fields) |
A constructor that creates a FieldMap for a specific Grid and automatically populates it with fields according to the std::map passed in through the fields argument. |
~FieldMap() |
A destructor for FieldMap. It simply clears all the fields. |
const std::map<std::string, std::shared_ptr<ODEData>>& getFields() |
Get all the fields stored in the FieldMap, including SolverData fields. |
const std::map<std::string, std::shared_ptr<SolverData>>& getSolverFields() |
Get all the SolverData fields stored in FieldMap, or the fields that should be evolved by a Solver object. |
void addField(std::string name, unsigned int nEqs, unsigned int stages=0) |
Add a new field to FieldMap. The name argument specifies the name for the new field and nEqs the number of equations. If stages == 0, then the field is initialized as an ODEData object and assumed to be an ordinary field. If stages > 0, the field is initialized as a SolverData object and assumed to be an evolved field. Therefore, stages should match the number of stages in the Solver used for this field. If a field matching name already exists, it does nothing (an exception will be thrown in a future release). |
void removeField(std::string name) |
Remove a field indexed by name. If no field matching name exists, then an std::out_of_range exception is thrown. |
bool hasField(std::string name) |
Check if a field matching name exists. |
unsigned int getNumFields() |
Get the total number of fields stored in the FieldMap. |
isSolverField(std::string name) |
Check if a field indexed by name is a a solver field (SolverData object) or an ordinary unevolved field (an ODEData object). Throws an std::out_of_range exception if name doesn't exist. |
const Grid& getGrid() const |
Get the Grid object associated with this FieldMap. |
std::shared_ptr<SolverData>& getSolverField(std::string name) |
Get a smart pointer to a solver field in FieldMap. An std::out_of_range exception is thrown if the field does not exist or is not a solver field. |
std::shared_ptr<ODEData>& operator[](std::string name) |
Get a smart pointer to an ordinary field using the [] operator. Throws std::out_of_range if the field does not exist. |
- Particularly when using a large number of fields, try to avoid retrieving fields via
[]andgetSolverFieldmore than necessary. Thestd::mapclass sorts data via a comparison operator, not hashing. Therefore, random access is, not
. Where possible, a better practice is only calling
getSolverFieldand[]to create a new reference and then manipulating the field through that reference. - The
ODEclass maintains a set ofFieldInfoobjects and acts as a factory forFieldMap. In order to keep all data consistent inside theODEclass, it's good practice to add and remove fields throughODE, notFieldMap.
- The
addFieldmethod should throw an exception when a field already exists. - For consistency, there should be a
getFieldmethod to parallelgetSolverField. BecauseODEtypically frequently only has access to aFieldMapas a pointer, this also allows for a more natural syntax using the->operator than is possible with the[]operator.