SECircuitCalculator.h
1 /* Distributed under the Apache License, Version 2.0.
2  See accompanying NOTICE file for details.*/
3 
4 #pragma once
5 #include "Eigen/Core"
6 #include "utils/SmartEnum.h"
7 #include <set>
8 
9 #define CIRCUIT_CALCULATOR_TEMPLATE typename CircuitType, typename NodeType, typename PathType, typename CapacitanceUnit, typename FluxUnit, typename InductanceUnit, typename PotentialUnit, typename QuantityUnit, typename ResistanceUnit
10 #define CIRCUIT_CALCULATOR_TYPES CircuitType,NodeType,PathType,CapacitanceUnit,FluxUnit,InductanceUnit,PotentialUnit,QuantityUnit,ResistanceUnit
11 
12 // These are the Eigen Solvers we can use for solving our circuits
13 struct CDM_DECL EigenCircuitSolver
14 {
15  enum Type { Direct, PartialPivLu, FullPivLu, JacobiSvd, HouseholderQr, Ldlt, Llt, SparseLU, SparseQR, BiCGSTAB, ConjugateGradient };
16  SMART_ENUM(EigenCircuitSolver, Type, 11);
17  static char const* Value(size_t idx);
18 };
19 
20 template<CIRCUIT_CALCULATOR_TEMPLATE>
22 {
23 public:
24  SECircuitCalculator(const CapacitanceUnit& c, const FluxUnit& f, const InductanceUnit& i, const PotentialUnit& p, const QuantityUnit& q, const ResistanceUnit& r, Logger* logger);
25  virtual ~SECircuitCalculator();
26 
27  virtual void SetEigenSolver(EigenCircuitSolver s){ m_solver = s; };
28  virtual void SetEigenSolver(EigenCircuitSolver::Type t) { m_solver.set(t); };
29 
30  // Analysis of the Circuit dynamics
31  virtual void Process(CircuitType& circuit, double timeStep_s);
32  virtual void PostProcess(CircuitType& circuit);
33 
34 protected:
35  virtual void ParseIn();
36  virtual void Solve();
37  virtual void ParseOut();
38  virtual void CalculateFluxes();
39  virtual void CalculateQuantities();
40 
41  // Valve Support
42  virtual bool CheckAndModifyValves();
43  virtual bool IsCurrentValveStateUnique();
44  // Eigen Support
45  virtual void PopulateAMatrix(NodeType& nKCL, PathType& p, double dMultiplier, bool hasPotentialSource = false);
46  // These are all transient and cleared/set at the start of the process call
47 
48  std::stringstream m_ss;
49  //Ax=b
50  Eigen::MatrixXd m_AMatrix; //A
51  Eigen::VectorXd m_xVector; //x
52  Eigen::VectorXd m_bVector; //b
53 
54  double m_dT_s;
57  CircuitType* m_circuit;
59  std::set<uint64_t> m_valveStates;
60  std::map<PathType*, size_t> m_potentialSources;
61 
62  const CapacitanceUnit &m_CapacitanceUnit;
63  const FluxUnit &m_FluxUnit;
64  const InductanceUnit &m_InductanceUnit;
65  const PotentialUnit &m_PotentialUnit;
66  const QuantityUnit &m_QuantityUnit;
67  const ResistanceUnit &m_ResistanceUnit;
68 };
69 #include "circuit/SECircuitCalculator.inl"
const ResistanceUnit & m_ResistanceUnit
Definition: SECircuitCalculator.h:67
Definition: SECircuitCalculator.h:21
Eigen::VectorXd m_xVector
Definition: SECircuitCalculator.h:51
double m_dT_s
Definition: SECircuitCalculator.h:54
Definition: Logger.h:61
const CapacitanceUnit & m_CapacitanceUnit
Definition: SECircuitCalculator.h:62
CircuitType * m_circuit
Definition: SECircuitCalculator.h:57
Type
Definition: SECircuitCalculator.h:15
virtual void SetEigenSolver(EigenCircuitSolver::Type t)
Definition: SECircuitCalculator.h:28
Eigen::VectorXd m_bVector
Definition: SECircuitCalculator.h:52
const InductanceUnit & m_InductanceUnit
Definition: SECircuitCalculator.h:64
const QuantityUnit & m_QuantityUnit
Definition: SECircuitCalculator.h:66
Definition: Logger.h:11
std::map< PathType *, size_t > m_potentialSources
Definition: SECircuitCalculator.h:60
const FluxUnit & m_FluxUnit
Definition: SECircuitCalculator.h:63
double m_refPotential
Definition: SECircuitCalculator.h:56
Definition: SECircuitCalculator.h:13
virtual void SetEigenSolver(EigenCircuitSolver s)
Definition: SECircuitCalculator.h:27
std::set< uint64_t > m_valveStates
Definition: SECircuitCalculator.h:59
EigenCircuitSolver m_solver
Definition: SECircuitCalculator.h:58
const PotentialUnit & m_PotentialUnit
Definition: SECircuitCalculator.h:65
std::stringstream m_ss
Definition: SECircuitCalculator.h:48
double m_currentTime_s
Definition: SECircuitCalculator.h:55
Eigen::MatrixXd m_AMatrix
Definition: SECircuitCalculator.h:50