SECompartmentNodes.h
1 /**************************************************************************************
2 Copyright 2015 Applied Research Associates, Inc.
3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 this file except in compliance with the License. You may obtain a copy of the License
5 at:
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software distributed under
8 the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9 CONDITIONS OF ANY KIND, either express or implied. See the License for the
10 specific language governing permissions and limitations under the License.
11 **************************************************************************************/
12 
13 #pragma once
14 #include <biogears/cdm/circuit/SECircuit.h>
15 #include <biogears/cdm/compartment/SECompartment.h>
16 
17 #define COMPARTMENT_NODE_TEMPLATE typename NodeType, typename PotentialScalar, typename PotentialUnit, typename QuantityScalar, typename QuantityUnit
18 #define COMPARTMENT_NODE_TYPES NodeType, PotentialScalar, PotentialUnit, QuantityScalar, QuantityUnit
19 #define ELECTRICAL_COMPARTMENT_NODE SEElectricalCircuitNode, SEScalarElectricPotential, ElectricPotentialUnit, SEScalarElectricCharge, ElectricChargeUnit
20 #define FLUID_COMPARTMENT_NODE SEFluidCircuitNode, SEScalarPressure, PressureUnit, SEScalarVolume, VolumeUnit
21 #define THERMAL_COMPARTMENT_NODE SEThermalCircuitNode, SEScalarTemperature, TemperatureUnit, SEScalarEnergy, EnergyUnit
22 
23 namespace biogears {
24 template <COMPARTMENT_NODE_TEMPLATE>
25 class SECompartmentNodes : public Loggable {
26 public:
27  SECompartmentNodes(Logger* logger);
28  virtual ~SECompartmentNodes();
29 
30  virtual void Clear();
31  virtual void StateChange(); //analyze and cache for optimization
32 
33  virtual bool HasMapping() const { return !m_AllNodes.empty(); }
34  virtual std::vector<NodeType*>& GetNodes() { return m_AllNodes; }
35  virtual void RemoveNode(NodeType& node);
36  virtual void MapNode(NodeType& node);
37 
38  virtual bool HasQuantity() const { return !m_QuantityNodes.empty(); }
39  virtual QuantityScalar& GetQuantity();
40  virtual double GetQuantity(const QuantityUnit& unit) const;
41 
42  virtual bool HasPotential() const;
43  virtual PotentialScalar& GetPotential();
44  virtual double GetPotential(const PotentialUnit& unit) const;
45 
46 protected:
47  void SortNode(NodeType& node);
48  virtual const std::vector<NodeType*>& GetAllNodes() const { return m_AllNodes; }
49  virtual const std::vector<NodeType*>& GetQuantityNodes() const { return m_QuantityNodes; }
50 
51  // I assume all nodes will have a pressure
52  std::vector<NodeType*> m_QuantityNodes;
53  std::vector<NodeType*> m_AllNodes; //Even nodes without quantity (ex. volume)
54 
55  QuantityScalar* m_Quantity;
56  PotentialScalar* m_Potential;
57 };
58 }
59 #include <biogears/cdm/compartment/SECompartmentNodes.inl>
virtual bool HasMapping() const
Definition: SECompartmentNodes.h:33
PotentialScalar * m_Potential
Definition: SECompartmentNodes.h:56
virtual void MapNode(NodeType &node)
void SortNode(NodeType &node)
virtual bool HasQuantity() const
Definition: SECompartmentNodes.h:38
virtual const std::vector< NodeType * > & GetAllNodes() const
Definition: SECompartmentNodes.h:48
virtual PotentialScalar & GetPotential()
QuantityScalar * m_Quantity
Definition: SECompartmentNodes.h:55
Definition: Logger.h:27
Definition: Logger.h:75
virtual const std::vector< NodeType * > & GetQuantityNodes() const
Definition: SECompartmentNodes.h:49
std::vector< NodeType * > m_QuantityNodes
Definition: SECompartmentNodes.h:52
virtual std::vector< NodeType * > & GetNodes()
Definition: SECompartmentNodes.h:34
virtual QuantityScalar & GetQuantity()
SECompartmentNodes(Logger *logger)
virtual bool HasPotential() const
std::vector< NodeType * > m_AllNodes
Definition: SECompartmentNodes.h:53
Definition: SECompartmentNodes.h:25
virtual void RemoveNode(NodeType &node)
Definition: SEElectricalCircuit.h:18