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) const
 
virtual void Debug (std::stringstream &msg) const
 
virtual void Debug (std::ostream &msg) const
 
virtual void Info (std::string const &msg) const
 
virtual void Info (std::stringstream &msg) const
 
virtual void Info (const std::stringstream &msg) const
 
virtual void Info (std::ostream &msg) const
 
virtual void Warning (std::string const &msg) const
 
virtual void Warning (std::stringstream &msg) const
 
virtual void Warning (std::ostream &msg) const
 
virtual void Error (std::string const &msg) const
 
virtual void Error (std::stringstream &msg) const
 
virtual void Error (std::ostream &msg) const
 
virtual void Fatal (std::string const &msg) const
 
virtual void Fatal (std::stringstream &msg) const
 
virtual void Fatal (std::ostream &msg) const
 

Protected Member Functions

virtual void ParseIn ()
 Set up the equations to solve the circuit. More...
 
virtual bool 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 Flux values. More...
 
virtual void CalculateQuantities ()
 Calculate and set all Path Quantities. More...
 
virtual void ParseInPotentialSources ()
 
virtual void Verbose (std::string location)
 
virtual bool CheckAndModifyValves (bool solverPassed)
 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 A 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
 
std::map< NodeType *, size_t > m_blackBoxPotentialSources
 
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
 

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 Flux values.

Set fluxes that were given for Flux Sources. Set fluxes that were directly solved for Potential Sources. Calculate and set Fluxes for Paths with other Elements.

◆ CalculateQuantities()

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

Calculate and set all Path Quantities.

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

◆ CheckAndModifyValves()

template<CIRCUIT_CALCULATOR_TEMPLATE >
bool SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::CheckAndModifyValves ( bool  solverPassed)
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 flux in the wrong direction. 2) Check reverse bias (i.e. voltage must be positive at the cathode). Look at the potentials to ensure flux would be going against the diode if the "switch" (ideal diode is modeled as a switch) was closed. Since flux goes from low to high potential, the potential at the Target must be higher or equal to the Source for negative flux (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.

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

◆ ParseInPotentialSources()

template<CIRCUIT_CALCULATOR_TEMPLATE >
void SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::ParseInPotentialSources
protectedvirtual

◆ 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 Potentials. Set Potential Source Fluxes.

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

Parameters
nThe Node that is currently being analyzed.
pThe Path that is currently being analyzed.
dMultiplierThe value to insert in the A matrix.
hasPotentialSourceTrue if the path has a Potential 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 >
bool SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::Solve
protectedvirtual

Solve for unknowns.

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

◆ Verbose()

template<CIRCUIT_CALCULATOR_TEMPLATE >
void SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::Verbose ( std::string  location)
protectedvirtual

Member Data Documentation

◆ _eigen

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

◆ m_blackBoxPotentialSources

template<CIRCUIT_CALCULATOR_TEMPLATE >
std::map<NodeType*, size_t> SECircuitCalculator< CIRCUIT_CALCULATOR_TEMPLATE >::m_blackBoxPotentialSources
protected

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