Pulse adds COVID-19 Simulation Support
×
SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE > Class Template Reference

#include <SECircuitCalculator.h>

Inherits Loggable.

Public Member Functions

 SECircuitCalculator (const CapacitanceUnit &c, const FluxUnit &f, const InductanceUnit &i, const PotentialUnit &p, const QuantityUnit &q, const ResistanceUnit &r, Logger *logger)
 
virtual ~SECircuitCalculator ()
 
virtual void SetEigenSolver (EigenCircuitSolver s)
 
virtual void SetEigenSolver (EigenCircuitSolver::Type t)
 
virtual void Process (CircuitType &circuit, double timeStep_s)
 Calculates the Next circuit values. More...
 
virtual void PostProcess (CircuitType &circuit)
 Advances time. More...
 
- Public Member Functions inherited from Loggable
 Loggable (Logger *logger=nullptr)
 
 Loggable (std::string const &logfile)
 
virtual ~Loggable ()
 
virtual LoggerGetLogger () const
 
virtual void SetLogger (Logger &logger)
 
virtual void Debug (std::string const &msg, std::string const &origin=empty) const
 
virtual void Debug (std::stringstream &msg, std::string const &origin=empty) const
 
virtual void Debug (std::ostream &msg, std::string const &origin=empty) const
 
virtual void Info (std::string const &msg, std::string const &origin=empty) const
 
virtual void Info (std::stringstream &msg, std::string const &origin=empty) const
 
virtual void Info (const std::stringstream &msg, std::string const &origin=empty) const
 
virtual void Info (std::ostream &msg, std::string const &origin=empty) const
 
virtual void Warning (std::string const &msg, std::string const &origin=empty) const
 
virtual void Warning (std::stringstream &msg, std::string const &origin=empty) const
 
virtual void Warning (std::ostream &msg, std::string const &origin=empty) const
 
virtual void Error (std::string const &msg, std::string const &origin=empty) const
 
virtual void Error (std::stringstream &msg, std::string const &origin=empty) const
 
virtual void Error (std::ostream &msg, std::string const &origin=empty) const
 
virtual void Fatal (std::string const &msg, std::string const &origin=empty) const
 
virtual void Fatal (std::stringstream &msg, std::string const &origin=empty) const
 
virtual void Fatal (std::ostream &msg, std::string const &origin=empty) const
 
std::string to_string (int i)
 
std::string to_string (unsigned int i)
 
std::string to_string (size_t t)
 
std::string to_string (float f)
 
std::string to_string (double d)
 

Protected Member Functions

virtual void ParseIn ()
 Set up the equations to solve the circuit. More...
 
virtual void Solve ()
 Solve for unknowns. More...
 
virtual void ParseOut ()
 Assign the Solver solution vector values to the appropriate places. More...
 
virtual void CalculateFluxes ()
 Calculate and set all Path Flow values. More...
 
virtual void CalculateQuantities ()
 Calculate and set all Path Volumes. More...
 
virtual bool CheckAndModifyValves ()
 Check if the solutions meets all Valve criteria, and modify a Valve state if not. More...
 
virtual bool IsCurrentValveStateUnique ()
 Check if the current Valve state combination has already been analyzed. More...
 
virtual void PopulateAMatrix (NodeType &nKCL, PathType &p, double dMultiplier, bool hasPotentialSource=false)
 Add a value to the appropriate location in the Jacobian matrix. More...
 

Protected Attributes

std::stringstream m_ss
 
double m_dT_s
 
double m_currentTime_s
 
double m_refPotential
 
CircuitType * m_circuit
 
EigenCircuitSolver m_solver
 
std::set< uint64_t > m_valveStates
 
std::map< PathType *, size_t > m_potentialSources
 
const CapacitanceUnit & m_CapacitanceUnit
 
const FluxUnit & m_FluxUnit
 
const InductanceUnit & m_InductanceUnit
 
const PotentialUnit & m_PotentialUnit
 
const QuantityUnit & m_QuantityUnit
 
const ResistanceUnit & m_ResistanceUnit
 
- Protected Attributes inherited from Loggable
bool myLogger
 
Loggerm_Logger
 

Private Attributes

eigen_eigen
 

Additional Inherited Members

- Static Public Attributes inherited from Loggable
static const std::string empty
 

Constructor & Destructor Documentation

◆ SECircuitCalculator()

template<CIRCUIT_CALCULATOR_TEMPLATE >
SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::SECircuitCalculator ( const CapacitanceUnit &  c,
const FluxUnit &  f,
const InductanceUnit &  i,
const PotentialUnit &  p,
const QuantityUnit &  q,
const ResistanceUnit &  r,
Logger logger 
)

◆ ~SECircuitCalculator()

template<CIRCUIT_CALCULATOR_TEMPLATE >
SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::~SECircuitCalculator ( )
virtual

Member Function Documentation

◆ CalculateFluxes()

template<CIRCUIT_CALCULATOR_TEMPLATE >
void SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::CalculateFluxes ( )
protectedvirtual

Calculate and set all Path Flow values.

Set flows that were given for Flow Sources. Set flows that were directly solved for Pressure Sources. Calculate and set Flows for Paths with other Elements.

◆ CalculateQuantities()

template<CIRCUIT_CALCULATOR_TEMPLATE >
void SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::CalculateQuantities ( )
protectedvirtual

Calculate and set all Path Volumes.

Calculate and set the Volumes for all Paths with Compliance Elements. You need a compliance because volume can't change in a rigid pipe.

◆ CheckAndModifyValves()

template<CIRCUIT_CALCULATOR_TEMPLATE >
bool SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::CheckAndModifyValves ( )
protectedvirtual

Check if the solutions meets all Valve criteria, and modify a Valve state if not.

Returns
true if the solution meets all Valve criteria, false if not

The solution passes if: 1) There is a path with a valve and flow in the wrong direction. 2) Check reverse bias (i.e. voltage must be positive at the cathode). Look at the pressures to ensure flow would be going against the diode if the "switch" (ideal diode is modeled as a switch) was closed. Since flow goes from low to high pressure, the pressure at the Target must be higher or equal to the Source for negative flow (against valve).

If it does not pass, change the state (Open/Close) of the first Valve that fails. The circuit will be re-solved with the new Valve state, and will iterate until a solution is found.

Error:
Fatal: The combination of valves precludes the circuit from being solved.

◆ IsCurrentValveStateUnique()

template<CIRCUIT_CALCULATOR_TEMPLATE >
bool SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::IsCurrentValveStateUnique ( )
protectedvirtual

Check if the current Valve state combination has already been analyzed.

Returns
true if the Valve combination is unique, false if it is not.

Loop through all of the previously analyzed Valve combinations this time-step and check if the current combination is the same. If this combination is unique, store it in a vector for the next go-round to check. Valve combinations are stored as integers that use their index and state (Open = 0, Closed = 1) to calculate a unique value for every combination. The total number of possible combinations (i.e. highest value possible) is 2^(# of Valves in the Circuit). For example, if all open will be 0, no matter how many Valves are in the circuit

The lower bits are used to represent the states of the non-polarized valves. In the lexicographic ordering of all state representations, all non-polarized valve combinations are enumerated first before the polarized element combinations. This is the order in which we want to evaluate the states so this bit order is important.

◆ ParseIn()

template<CIRCUIT_CALCULATOR_TEMPLATE >
void SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::ParseIn ( )
protectedvirtual

Set up the equations to solve the circuit.

Define the state-space system, by creating the A Jacobian matrix and b solution vector (Ax=b). We do all of the Modified Nodal Analysis setup steps all at once below. There are (using electrical terminology): 1) Select a reference node 2) Assign a name to the current through each voltage source. We will use the convention that the current flows from the positive node to the negative node of the source. 3) Apply Kirchoff's current law to each node. We will take currents out of the node to be positive. 4) Write an equation for the voltage each voltage source. 5) Solve the system of n-1 unknowns.

Error:
Fatal: Circuit must have at least 1 reference node
Error:
Warning: Reference pressure is not defined - setting it to 0.
Error:
Fatal: Multiple Reference Potentials must be equal
Error:
Fatal: Resistance cannot be negative
Error:
Warning: Initial compliance source pressure is not defined, assuming it is the reference pressure.
Error:
Warning: Initial compliance target pressure is not defined, assuming it is the reference pressure.
Error:
Fatal: Capacitance cannot be negative
Error:
Warning: Initial inductance is not defined, assuming it is 0.
Error:
Warning: Initial inductance source pressure is not defined, assuming it is the reference pressure.
Error:
Warning: Initial inductance target pressure is not defined, assuming it is the reference pressure.
Error:
Fatal: Inductance cannot be negative

◆ ParseOut()

template<CIRCUIT_CALCULATOR_TEMPLATE >
void SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::ParseOut ( )
protectedvirtual

Assign the Solver solution vector values to the appropriate places.

Set all Node Pressures. Set Pressure Source Flows.

◆ PopulateAMatrix()

template<CIRCUIT_CALCULATOR_TEMPLATE >
void SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::PopulateAMatrix ( NodeType &  n,
PathType &  p,
double  dMultiplier,
bool  hasPotentialSource = false 
)
protectedvirtual

Add a value to the appropriate location in the Jacobian matrix.

Parameters
nKCLThe Node that is currently being analyzed.
pThe Path that is currently being analyzed.
dMultiplierThe value to insert in the Jacobian matrix.
hasPressureSourceTrue if the path has a Pressure Source.

Each row in the square A matrix is for the KCL analysis of a single Node. Each column is for the variables (i.e. other Nodes) in that KCL equation, and is in the same order as the rows. These should include all of the multipliers on the left side of the KCL equations.

◆ PostProcess()

template<CIRCUIT_CALCULATOR_TEMPLATE >
void SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::PostProcess ( CircuitType &  circuit)
virtual

Advances time.

Parameters
CircuitThe circuit in question.
vSubstancesList with the substances that are currently present in the circuit

Move the Next circuit values to Current, and sets the Next values to the Baselines. This effectively advances time for the circuit

◆ Process()

template<CIRCUIT_CALCULATOR_TEMPLATE >
void SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::Process ( CircuitType &  circuit,
double  timeStep_s 
)
virtual

Calculates the Next circuit values.

Parameters
CircuitThe circuit in question.

Take the Element values and calculate the Node and Path variables for the Next time-step.

◆ SetEigenSolver() [1/2]

template<CIRCUIT_CALCULATOR_TEMPLATE >
virtual void SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::SetEigenSolver ( EigenCircuitSolver  s)
inlinevirtual

◆ SetEigenSolver() [2/2]

template<CIRCUIT_CALCULATOR_TEMPLATE >
virtual void SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::SetEigenSolver ( EigenCircuitSolver::Type  t)
inlinevirtual

◆ Solve()

template<CIRCUIT_CALCULATOR_TEMPLATE >
void SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::Solve ( )
protectedvirtual

Solve for unknowns.

Use the Eigen solver to find the unknowns. Make sure the solution is correct.

Error:
Fatal: The solver was unable to determine a solution for the circuit.
Warning
Warning: Circuit solution from secondary solver with maximum relative error greater than 1.0e-12 but less than 1.0e-8

Member Data Documentation

◆ _eigen

template<CIRCUIT_CALCULATOR_TEMPLATE >
eigen* SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::_eigen
private

◆ m_CapacitanceUnit

template<CIRCUIT_CALCULATOR_TEMPLATE >
const CapacitanceUnit& SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_CapacitanceUnit
protected

◆ m_circuit

template<CIRCUIT_CALCULATOR_TEMPLATE >
CircuitType* SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_circuit
protected

◆ m_currentTime_s

template<CIRCUIT_CALCULATOR_TEMPLATE >
double SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_currentTime_s
protected

◆ m_dT_s

template<CIRCUIT_CALCULATOR_TEMPLATE >
double SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_dT_s
protected

◆ m_FluxUnit

template<CIRCUIT_CALCULATOR_TEMPLATE >
const FluxUnit& SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_FluxUnit
protected

◆ m_InductanceUnit

template<CIRCUIT_CALCULATOR_TEMPLATE >
const InductanceUnit& SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_InductanceUnit
protected

◆ m_potentialSources

template<CIRCUIT_CALCULATOR_TEMPLATE >
std::map<PathType*, size_t> SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_potentialSources
protected

◆ m_PotentialUnit

template<CIRCUIT_CALCULATOR_TEMPLATE >
const PotentialUnit& SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_PotentialUnit
protected

◆ m_QuantityUnit

template<CIRCUIT_CALCULATOR_TEMPLATE >
const QuantityUnit& SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_QuantityUnit
protected

◆ m_refPotential

template<CIRCUIT_CALCULATOR_TEMPLATE >
double SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_refPotential
protected

◆ m_ResistanceUnit

template<CIRCUIT_CALCULATOR_TEMPLATE >
const ResistanceUnit& SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_ResistanceUnit
protected

◆ m_solver

template<CIRCUIT_CALCULATOR_TEMPLATE >
EigenCircuitSolver SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_solver
protected

◆ m_ss

template<CIRCUIT_CALCULATOR_TEMPLATE >
std::stringstream SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_ss
protected

◆ m_valveStates

template<CIRCUIT_CALCULATOR_TEMPLATE >
std::set<uint64_t> SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_valveStates
protected

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.