5#include <unordered_map>
27 class Element :
public std::enable_shared_from_this<Element>
31 std::unordered_map<std::string, std::vector<double>>
components;
32 std::unordered_map<std::shared_ptr<Element>, std::string>
inputs;
33 std::unordered_map<std::shared_ptr<Element>, std::string>
outputs;
35 struct CachedInput {
const double* src; std::size_t size; };
36 std::vector<CachedInput> cachedInputs;
37 double* inputPtr =
nullptr;
38 std::size_t inputSize = 0;
56 virtual void step(
double t,
double deltaT) = 0;
58 virtual std::shared_ptr<Element>
clone()
const = 0;
70 virtual void addInput(
const std::shared_ptr<Element>& inputElement,
71 const std::string& inputComponent =
"output");
73 void removeInput(
const std::string& inputElementId);
76 bool hasInput(
const std::string& inputElementName,
const std::string& inputComponent);
77 bool hasInput(
int inputElementId,
const std::string& inputComponent);
92 bool hasOutput(
const std::string& outputElementName,
const std::string& outputComponent);
93 bool hasOutput(
int outputElementId,
const std::string& outputComponent);
113 std::vector<double>
getComponent(
const std::string& componentName);
115 std::vector<double>*
getComponentPtr(
const std::string& componentName);
119 const std::unordered_map<std::string, std::vector<double>>*
getComponents()
const;
121 std::vector<std::shared_ptr<Element>>
getInputs();
126 std::vector<std::shared_ptr<Element>>
getOutputs();
Abstract base class for all simulation elements.
Definition element.h:28
void print() const
Definition element.cpp:38
std::string getUniqueName() const
Definition element.cpp:245
std::vector< double > getComponent(const std::string &componentName)
Return a copy of the named component vector.
Definition element.cpp:265
void setUniqueName(const std::string &name)
Definition element.cpp:250
void close()
Definition element.cpp:29
double getStepSize() const
Return the spatial resolution (d_x).
Definition element.cpp:171
int getMaxSpatialDimension() const
Definition element.cpp:166
virtual void step(double t, double deltaT)=0
Advance the element by one time step.
std::vector< std::shared_ptr< Element > > getInputs()
Definition element.cpp:299
void buildInputCache()
Cache raw pointers to input component data. Call after all element init()s complete.
Definition element.cpp:141
std::unordered_map< std::string, std::vector< double > > components
Named data arrays (e.g. "output").
Definition element.h:31
bool hasOutput() const
Definition element.cpp:315
void removeOutput(const std::string &outputElementId)
Deregister this element as an input of outputElementId.
Definition element.cpp:232
bool hasInput() const
Definition element.cpp:320
const std::unordered_map< std::string, std::vector< double > > * getComponents() const
Return a read-only pointer to the full components map.
Definition element.cpp:294
void removeInput(const std::string &inputElementId)
Definition element.cpp:79
void removeOutputs()
Definition element.cpp:203
void updateInput()
Pull data from all registered input elements into this element's components.
Definition element.cpp:156
std::vector< std::string > getComponentList() const
Definition element.cpp:279
std::unordered_map< std::shared_ptr< Element >, std::string > getInputsAndComponents()
Return all inputs mapped to the component name they expose.
Definition element.cpp:310
std::vector< std::shared_ptr< Element > > getOutputs()
Definition element.cpp:325
virtual void changeDimensions(const ElementDimensions &newDimensions)
Resize all components to newDimensions and re-initialize.
Definition element.cpp:20
virtual ~Element()=default
ElementCommonParameters commonParameters
Name, label, and spatial dimensions.
Definition element.h:30
ElementLabel getLabel() const
Definition element.cpp:260
std::unordered_map< std::shared_ptr< Element >, std::string > inputs
Upstream elements and the component they expose.
Definition element.h:32
int getUniqueIdentifier() const
Definition element.cpp:255
virtual std::shared_ptr< Element > clone() const =0
void removeInputs()
Definition element.cpp:129
int getSize() const
Return the number of spatial samples (size = round(x_max / d_x)).
Definition element.cpp:214
virtual void addInput(const std::shared_ptr< Element > &inputElement, const std::string &inputComponent="output")
Register inputElement as an upstream source for this element.
Definition element.cpp:43
std::vector< double > * getComponentPtr(const std::string &componentName)
Definition element.cpp:272
virtual void init()=0
Initialize the element (called once before the simulation loop).
ElementCommonParameters getElementCommonParameters() const
Definition element.cpp:187
virtual std::string toString() const =0
std::unordered_map< std::shared_ptr< Element >, std::string > outputs
Downstream elements that read this element's output.
Definition element.h:33
Definition element_parameters.h:10
ElementLabel
Definition element_parameters.h:12
Definition element_parameters.h:188
Definition element_parameters.h:159