├── LICENSE ├── README.md ├── examples └── shipboard_system │ ├── shipboard_system.netlist │ └── shipboard_topology.PNG ├── exe └── codegen_cli_main.cpp ├── include ├── codegen │ ├── ArrayObject.hpp │ ├── CodeGenDataTypes.hpp │ ├── Cpp.hpp │ ├── CppObject.hpp │ ├── LabelValuePair.hpp │ ├── Object.hpp │ ├── ReferenceObject.hpp │ ├── ResistiveCompanionElements.hpp │ ├── SolverCodegen.hpp │ ├── SolverEngineGenerator.hpp │ ├── StringProcessor.hpp │ ├── SubsystemSolverEngineGenerator.hpp │ ├── System.hpp │ ├── SystemConductanceGenerator.hpp │ ├── SystemSolverGenerator.hpp │ ├── SystemSourceVectorGenerator.hpp │ ├── components │ │ ├── BridgeConverter3LegIdealSwitches.hpp │ │ ├── BridgeConverter_1LegIdealSwitchesAntiParallelDiodes.hpp │ │ ├── BridgeConverter_3LegIdealSwitchesAntiParallelDiodes.hpp │ │ ├── Capacitor.hpp │ │ ├── Component.hpp │ │ ├── CurrentSource.hpp │ │ ├── DualActiveBridgeConverter_IdealSwitches.hpp │ │ ├── FunctionalCurrentSource.hpp │ │ ├── FunctionalVoltageSource.hpp │ │ ├── IdealFunctionalVoltageSource.hpp │ │ ├── IdealVoltageSource.hpp │ │ ├── Inductor.hpp │ │ ├── ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodes.hpp │ │ ├── ModularMultilevelConverter_HalfBridgeModules.hpp │ │ ├── MutualInductance3.hpp │ │ ├── NonidealFunctionalCurrentSource.hpp │ │ ├── NortonPort.hpp │ │ ├── Resistor.hpp │ │ ├── SeriesRLIdealSwitch.hpp │ │ ├── VoltageControlledCurrentSource.hpp │ │ ├── VoltageSource.hpp │ │ ├── basic.hpp │ │ └── power_electronics.hpp │ ├── netlist │ │ ├── ComponentFactory.hpp │ │ ├── ComponentListing.hpp │ │ ├── Netlist.hpp │ │ ├── NetlistLoader.hpp │ │ └── producers │ │ │ ├── BridgeConverter3LegIdealSwitchesProducer.hpp │ │ │ ├── BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer.hpp │ │ │ ├── BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer.hpp │ │ │ ├── CapacitorProducer.hpp │ │ │ ├── ComponentProducer.hpp │ │ │ ├── CurrentSourceProducer.hpp │ │ │ ├── DualActiveBridgeConverter_IdealSwitchesProducer.hpp │ │ │ ├── FunctionalCurrentSourceProducer.hpp │ │ │ ├── FunctionalVoltageSourceProducer.hpp │ │ │ ├── IdealFunctionalVoltageSourceProducer.hpp │ │ │ ├── IdealVoltageSourceProducer.hpp │ │ │ ├── InductorProducer.hpp │ │ │ ├── ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer.hpp │ │ │ ├── ModularMultilevelConverter_HalfBridgeModulesProducer.hpp │ │ │ ├── MutualInductance3Producer.hpp │ │ │ ├── NortonPortProducer.hpp │ │ │ ├── ResistorProducer.hpp │ │ │ ├── SeriesRLIdealSwitchProducer.hpp │ │ │ ├── VoltageControlledCurrentSourceProducer.hpp │ │ │ └── VoltageSourceProducer.hpp │ └── udc │ │ ├── UserDefinedComponent.hpp │ │ ├── UserDefinedComponentGenerator.hpp │ │ ├── UserDefinedComponentLoader.hpp │ │ └── UserDefinedComponentSourceTokenizer.hpp ├── exprpar │ ├── Expression.hpp │ ├── ExpressionConstants.hpp │ ├── ExpressionNode.hpp │ ├── ExpressionParser.hpp │ ├── ExpressionSymbolTable.hpp │ ├── ExpressionToken.hpp │ ├── ExpressionTraverser.hpp │ └── exprpar.hpp └── scfg │ └── Configuration.hpp ├── ortis_logo_300dpi.png └── src ├── codegen ├── Cpp.cpp ├── SolverEngineGenerator.cpp ├── SubsystemSolverEngineGenerator.cpp ├── System.cpp ├── SystemConductanceGenerator.cpp ├── SystemSolverGenerator.cpp ├── SystemSourceVectorGenerator.cpp ├── components │ ├── BridgeConverter3LegIdealSwitches.cpp │ ├── BridgeConverter_1LegIdealSwitchesAntiParallelDiodes.cpp │ ├── BridgeConverter_3LegIdealSwitchesAntiParallelDiodes.cpp │ ├── Capacitor.cpp │ ├── Component.cpp │ ├── CurrentSource.cpp │ ├── DualActiveBridgeConverter_IdealSwitches.cpp │ ├── FunctionalCurrentSource.cpp │ ├── FunctionalVoltageSource.cpp │ ├── IdealFunctionalVoltageSource.cpp │ ├── IdealVoltageSource.cpp │ ├── Inductor.cpp │ ├── ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodes.cpp │ ├── ModularMultilevelConverter_HalfBridgeModules.cpp │ ├── MutualInductance3.cpp │ ├── NonidealFunctionalCurrentSource.cpp │ ├── NortonPort.cpp │ ├── Resistor.cpp │ ├── SeriesRLIdealSwitch.cpp │ ├── VoltageControlledCurrentSource.cpp │ └── VoltageSource.cpp ├── netlist │ ├── ComponentFactory.cpp │ ├── ComponentFactory_registerBuiltinComponentProducers.cpp │ ├── ComponentListing.cpp │ ├── NetlistLoader.cpp │ └── producers │ │ ├── BridgeConverter3LegIdealSwitchesProducer.cpp │ │ ├── BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer.cpp │ │ ├── BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer.cpp │ │ ├── CapacitorProducer.cpp │ │ ├── ComponentProducer.cpp │ │ ├── CurrentSourceProducer.cpp │ │ ├── DualActiveBridgeConverter_IdealSwitchesProducer.cpp │ │ ├── FunctionalCurrentSourceProducer.cpp │ │ ├── FunctionalVoltageSourceProducer.cpp │ │ ├── IdealFunctionalVoltageSourceProducer.cpp │ │ ├── IdealVoltageSourceProducer.cpp │ │ ├── InductorProducer.cpp │ │ ├── ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer.cpp │ │ ├── ModularMultilevelConverter_HalfBridgeModulesProducer.cpp │ │ ├── MutualInductance3Producer.cpp │ │ ├── NortonPortProducer.cpp │ │ ├── ResistorProducer.cpp │ │ ├── SeriesRLIdealSwitchProducer.cpp │ │ ├── VoltageControlledCurrentSourceProducer.cpp │ │ └── VoltageSourceProducer.cpp └── udc │ ├── UserDefinedComponent.cpp │ ├── UserDefinedComponentGenerator.cpp │ └── UserDefinedComponentSourceTokenizer.cpp └── exprpar ├── Expression.cpp ├── ExpressionConstants.cpp ├── ExpressionNode.cpp ├── ExpressionParser.cpp ├── ExpressionSymbolTable.cpp └── ExpressionToken.cpp /examples/shipboard_system/shipboard_topology.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenRealTimeSimulation/SolverCodegen/3b2dc4e2d9239ae167ec89895274da9c26578b8d/examples/shipboard_system/shipboard_topology.PNG -------------------------------------------------------------------------------- /include/codegen/CodeGenDataTypes.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2018-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | /** 24 | 25 | \file CodeGenDataTypes.hpp 26 | 27 | Provides data types to be used only in code generation for LB-LMC engine development 28 | 29 | Many of the data types here may not be FPGA/HDL synthesizable 30 | 31 | \author Matthew Milton 32 | \date Spring 2018 33 | 34 | **/ 35 | 36 | #ifndef LBLMC_CODEGENDATATYPES_HPP 37 | #define LBLMC_CODEGENDATATYPES_HPP 38 | 39 | #include 40 | 41 | namespace lblmc 42 | { 43 | 44 | /////////////////////////////////////////////////////////////////////////////////////////////////// 45 | // Eigen3 Linear Algebra Library Typedefs (http://eigen.tuxfamily.org) 46 | 47 | typedef Eigen::Matrix 50 | MatrixRMXd; ///< Dynamically-allocated row-major double Eigen3 matrix type 51 | 52 | typedef Eigen::Matrix 54 | VectorRMXd; ///< dynamically-allocated row-major double Eigen3 vector type 55 | 56 | /////////////////////////////////////////////////////////////////////////////////////////////////// 57 | 58 | } //namespace lblmc 59 | 60 | #endif // LBLMC_CODEGENDATATYPES_HPP 61 | -------------------------------------------------------------------------------- /include/codegen/LabelValuePair.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_LABELVALUEPAIR_HPP 24 | #define LBLMC_LABELVALUEPAIR_HPP 25 | 26 | #include 27 | 28 | /** 29 | \brief defines a general-purpose label and value pair 30 | \tparam TYPE the data type of the value 31 | 32 | This pair can be used to define new fields in open-ended definitions. 33 | **/ 34 | template 35 | struct LabelValuePair 36 | { 37 | std::string label; 38 | TYPE value; 39 | }; 40 | 41 | /** 42 | \brief defines a label and value pair where the value is a variant of 2 different types 43 | \tparam TYPE the data type of the value 44 | 45 | This pair can be used to define new fields in open-ended definitions. 46 | 47 | The value of the pair is assigned to either value1 or value2, depending on desired 48 | type for the value. Fields value1 and value2 share same memory space. 49 | **/ 50 | template 51 | struct LabelValuePair2 52 | { 53 | std::string label; 54 | union 55 | { 56 | TYPE1 value1; ///< value as type TYPE1 associated with label 57 | TYPE2 value2; ///< value as type TYPE2 associated with label 58 | }; 59 | 60 | }; 61 | 62 | /** 63 | \brief defines a label and value pair where the value is a variant of 3 different types 64 | \tparam TYPE the data type of the value 65 | 66 | This pair can be used to define new fields in open-ended definitions. 67 | 68 | The value of the pair is assigned to either value1, value2, or value3 depending on desired 69 | type for the value. Fields value1 through value3 share same memory space. 70 | **/ 71 | template 72 | struct LabelValuePair3 73 | { 74 | std::string label; 75 | union 76 | { 77 | TYPE1 value1; ///< value as type TYPE1 associated with label 78 | TYPE2 value2; ///< value as type TYPE2 associated with label 79 | TYPE3 value3; ///< value as type TYPE3 associated with label 80 | }; 81 | 82 | }; 83 | 84 | /** 85 | \brief defines a label and value pair where the value is a variant of 4 different types 86 | \tparam TYPE the data type of the value 87 | 88 | This pair can be used to define new fields in open-ended definitions. 89 | 90 | The value of the pair is assigned to either value1, value2, value3, or value4 depending on 91 | desired type for the value. Fields value1 through value4 share same memory space. 92 | **/ 93 | template 94 | struct LabelValuePair4 95 | { 96 | std::string label; 97 | union 98 | { 99 | TYPE1 value1; ///< value as type TYPE1 associated with label 100 | TYPE2 value2; ///< value as type TYPE2 associated with label 101 | TYPE3 value3; ///< value as type TYPE3 associated with label 102 | TYPE4 value4; ///< value as type TYPE4 associated with label 103 | }; 104 | 105 | }; 106 | 107 | #endif // LBLMC_LABELVALUEPAIR_HPP 108 | 109 | -------------------------------------------------------------------------------- /include/codegen/ReferenceObject.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef CODEGEN_REFERENCEOBJECT_HPP 24 | #define CODEGEN_REFERENCEOBJECT_HPP 25 | 26 | #include 27 | #include 28 | #include "codegen/Object.hpp" 29 | 30 | namespace lblmc 31 | { 32 | 33 | /** 34 | \brief describes C++ pointer, reference, and r-value reference objects and generate appropriate 35 | C++ code for the objects 36 | 37 | This class cannot describe arrays, containers, or smart pointers 38 | (std::unique_ptr, std::shared_ptr, etc.) 39 | 40 | \author Matthew Milton 41 | \date 2019 42 | **/ 43 | class ReferenceObject : public Object 44 | { 45 | 46 | public: 47 | 48 | enum class ReferenceType : int 49 | { 50 | NONE = 0, 51 | POINTER, 52 | CONSTANT_POINTER, 53 | REFERENCE, 54 | RVALUE_REFERENCE, 55 | POINTER_REFERENCE, 56 | CONSTANT_POINTER_REFERENCE 57 | }; 58 | 59 | 60 | }; 61 | 62 | } //namespace codegen 63 | 64 | #endif // CODEGEN_REFERENCEOBJECT_HPP 65 | -------------------------------------------------------------------------------- /include/codegen/SolverCodegen.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2021 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef ORTIS_SOLVERCODEGEN_HPP 24 | #define ORTIS_SOLVERCODEGEN_HPP 25 | 26 | #include 27 | #include 28 | 29 | #include "codegen/netlist/Netlist.hpp" 30 | #include "codegen/netlist/NetlistLoader.hpp" 31 | #include "codegen/netlist/ComponentFactory.hpp" 32 | #include "codegen/SolverEngineGenerator.hpp" 33 | #include "codegen/System.hpp" 34 | 35 | /** 36 | \brief spawns a solver engine code generator initialized for a given circuit defined by a netlist string 37 | 38 | \param netlist_str string containing the circuit netlist text 39 | 40 | \param seg_params default parameters used by generator to generate solver code 41 | 42 | \return unique pointer to the spawned solver engine generator 43 | **/ 44 | inline 45 | std::unique_ptr 46 | produceSolverEngineGeneratorFromNetlistString 47 | ( 48 | const std::string& netlist_str, 49 | const SolverEngineGeneratorParameters& seg_params 50 | ) 51 | { 52 | NetlistLoader netlist_loader; 53 | Netlist netlist = netlist_loader.loadFromString(netlist_str); 54 | 55 | System system(netlist.getModelName()); 56 | 57 | ComponentFactory factory; 58 | factory.registerBuiltinComponentProducers(); 59 | 60 | for(const auto& comp_listing : netlist.getComponents()) 61 | { 62 | system.addComponent( factory.produceComponent(comp_listing) ); 63 | } 64 | 65 | std::unique_ptr seg_ptr 66 | ( 67 | new SolverEngineGenerator(system.getName(), system.getNumberOfSolutions() ) 68 | ); 69 | 70 | seg_ptr->setParameters(seg_params); 71 | 72 | for(const auto& comp_gen_ptr : system.getComponents() ) 73 | { 74 | comp_gen_ptr->stampSystem(*seg_ptr); 75 | } 76 | 77 | return seg_ptr; 78 | 79 | } 80 | 81 | /** 82 | \brief spawns a solver engine code generator initialized for a given circuit defined by a netlist string 83 | 84 | \param netlist_str string containing the circuit netlist text 85 | 86 | \return unique pointer to the spawned solver engine generator 87 | 88 | Similar to other overload of this function, but uses default parameters where generated solver function 89 | is implemented as template with real type parameter. 90 | **/ 91 | inline 92 | std::unique_ptr 93 | produceSolverEngineGeneratorFromNetlistString(const std::string& netlist_str) 94 | { 95 | SolverEngineGeneratorParameters seg_params; 96 | seg_params.codegen_solver_templated_function_enable = true; 97 | seg_params.codegen_solver_templated_real_type_enable = true; 98 | 99 | return produceSolverEngineGeneratorFromNetlistString(netlist_str, seg_params); 100 | } 101 | 102 | /** 103 | \brief generates circuit solver code source file from given circuit netlist 104 | 105 | \param netlist_str string containing the circuit netlist text 106 | 107 | \param filename full filename (.hpp) of the generated source code file 108 | **/ 109 | inline 110 | void 111 | generateSolverSourceCodeFileFromNetlistString(const std::string& netlist_str, const std::string& filename) 112 | { 113 | auto seg = produceSolverEngineGenerator(netlist_str); 114 | 115 | seg->generateCFunctionAndExport(filename); 116 | } 117 | 118 | #endif // ORTIS_SOLVERCODEGEN_HPP 119 | 120 | -------------------------------------------------------------------------------- /include/codegen/components/Capacitor.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_CAPACITOR_HPP 24 | #define LBLMC_CAPACITOR_HPP 25 | 26 | #include 27 | #include 28 | #include "codegen/components/Component.hpp" 29 | 30 | namespace lblmc 31 | { 32 | 33 | class Capacitor : public Component 34 | { 35 | 36 | private: 37 | 38 | double DT; 39 | double CAP; 40 | double HOC2; 41 | unsigned int P, N; 42 | unsigned int source_id; 43 | 44 | public: 45 | 46 | Capacitor(std::string comp_name); 47 | Capacitor(std::string comp_name, double dt, double cap); 48 | Capacitor(const Capacitor& base); 49 | 50 | inline std::string getType() const { return std::string("Capacitor");} 51 | 52 | inline unsigned int getNumberOfTerminals() const { return 2; } 53 | inline unsigned int getNumberOfSources() const { return 1; } 54 | 55 | void getSourceIds(std::vector& ids) const; 56 | void getResistiveCompanionElements(std::vector& elements) const; 57 | 58 | void setTerminalConnections(unsigned int p, unsigned int n); 59 | inline void getTerminalConnections(std::vector& term_ids) const 60 | { 61 | term_ids = {P, N}; 62 | } 63 | 64 | inline void setParameters(double dt, double cap) { DT = dt; CAP = cap; } 65 | inline const double& getDT() const { return DT; } 66 | inline const double& getCapacitance() const { return CAP; } 67 | 68 | inline void setIntegrationMethod(std::string method) {} 69 | inline std::string getIntegrationMethod() const { return std::string("tustin"); } 70 | 71 | void stampConductance(SystemConductanceGenerator& gen); 72 | void stampSources(SystemSourceVectorGenerator& gen); 73 | std::string generateParameters(); 74 | std::string generateFields(); 75 | std::string generateInputs() { return std::string(""); } 76 | std::string generateOutputs(std::string output = "ALL") { return std::string(""); } 77 | std::string generateUpdateBody(); 78 | }; 79 | 80 | } //namespace lblmc 81 | 82 | #endif // LBLMC_CAPACITOR_HPP 83 | -------------------------------------------------------------------------------- /include/codegen/components/CurrentSource.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | 24 | #ifndef LBLMC_CURRENTSOURCE_HPP 25 | #define LBLMC_CURRENTSOURCE_HPP 26 | 27 | #include 28 | #include 29 | #include "codegen/components/Component.hpp" 30 | 31 | namespace lblmc 32 | { 33 | 34 | class CurrentSource : public Component 35 | { 36 | 37 | private: 38 | 39 | double CURRENT; 40 | unsigned int P, N; 41 | unsigned int source_id; 42 | 43 | public: 44 | 45 | CurrentSource(std::string comp_name); 46 | CurrentSource(std::string comp_name, double i); 47 | CurrentSource(const CurrentSource& base); 48 | 49 | inline std::string getType() const { return std::string("CurrentSource");} 50 | 51 | inline unsigned int getNumberOfTerminals() const { return 2; } 52 | inline unsigned int getNumberOfSources() const { return 1; } 53 | 54 | inline void setTerminalConnections(unsigned int p, unsigned int n) { P = p; N = n; } 55 | inline void getTerminalConnections(std::vector& term_ids) const 56 | { 57 | term_ids = {P, N}; 58 | } 59 | 60 | inline void setParameters(double i) { CURRENT=i; } 61 | inline const double& getCurrent() const { return CURRENT; } 62 | 63 | void getSourceIds(std::vector& ids) const; 64 | void getResistiveCompanionElements(std::vector& elements) const; 65 | 66 | void stampConductance(SystemConductanceGenerator& gen); 67 | void stampSources(SystemSourceVectorGenerator& gen); 68 | std::string generateParameters(); 69 | inline std::string generateFields() { return std::string(""); } 70 | inline std::string generateInputs() { return std::string(""); } 71 | inline std::string generateOutputs(std::string output = "ALL") { return std::string(""); } 72 | std::string generateUpdateBody(); 73 | }; 74 | 75 | } //namespace lblmc 76 | 77 | #endif // LBLMC_CURRENTSOURCE_HPP 78 | 79 | 80 | -------------------------------------------------------------------------------- /include/codegen/components/DualActiveBridgeConverter_IdealSwitches.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2020 Matthew Milton, Dhiman Chowdhury, Michele Difronzo 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_DUALACTIVEBRIDGECONVERTER_IDEALSWITCHES_HPP 24 | #define LBLMC_DUALACTIVEBRIDGECONVERTER_IDEALSWITCHES_HPP 25 | 26 | #include 27 | #include 28 | 29 | #include "codegen/components/Component.hpp" 30 | 31 | namespace lblmc 32 | { 33 | 34 | /** 35 | \brief component code generator for a Dual Active Bridge power electronic converter 36 | 37 | This currently a placeholder for the final component generator and as such, is not operational. 38 | **/ 39 | class DualActiveBridgeConverter_IdealSwitches : public Component 40 | { 41 | 42 | private: 43 | 44 | double DT; 45 | double R11; 46 | double R22; 47 | double R1; 48 | double R2; 49 | double RM; 50 | double LM; 51 | double C1; 52 | double C2; 53 | double L1; 54 | double L2; 55 | double N; 56 | 57 | unsigned int P1, N1, P2, N2; 58 | unsigned int source_id1, source_id2; 59 | 60 | public: 61 | 62 | 63 | DualActiveBridgeConverter_IdealSwitches(std::string comp_name); 64 | DualActiveBridgeConverter_IdealSwitches 65 | ( 66 | std::string comp_name, 67 | double dt, 68 | double r_input1, 69 | double r_input2, 70 | double r_transformer1, 71 | double r_transformer2, 72 | double r_magnetizing, 73 | double l_magnetizing, 74 | double c_filter1, 75 | double c_filter2, 76 | double l_transformer1, 77 | double l_transformer2, 78 | double turns_ratio 79 | ); 80 | DualActiveBridgeConverter_IdealSwitches(const DualActiveBridgeConverter_IdealSwitches& base); 81 | 82 | inline std::string getType() const { return std::string("DualActiveBridgeConverter_IdealSwitches");} 83 | 84 | inline unsigned int getNumberOfTerminals() const { return 4; } 85 | inline unsigned int getNumberOfSources() const { return 2; } 86 | 87 | void getSourceIds(std::vector& ids) const; 88 | std::vector getSourceIds() const; 89 | 90 | inline void setTerminalConnections 91 | ( 92 | unsigned int p1, 93 | unsigned int n1, 94 | unsigned int p2, 95 | unsigned int n2 96 | ) { P1 = p1; N1 = n1; P2 = p2; N2 = n2; } 97 | 98 | inline void getTerminalConnections(std::vector& term_ids) const 99 | { 100 | term_ids = {P1,N1,P2,N2}; 101 | } 102 | 103 | inline std::vector getTerminalConnections() const 104 | { 105 | return std::vector {P1,N1,P2,N2}; 106 | } 107 | 108 | void setParameters 109 | ( 110 | double dt, 111 | double r_input1, 112 | double r_input2, 113 | double r_transformer1, 114 | double r_transformer2, 115 | double r_magnetizing, 116 | double l_magnetizing, 117 | double c_filter1, 118 | double c_filter2, 119 | double l_transformer1, 120 | double l_transformer2, 121 | double turns_ratio 122 | ); 123 | 124 | inline void setIntegrationMethod(std::string method) {} 125 | inline std::string getIntegrationMethod() const { return std::string("euler_forward"); } 126 | 127 | std::vector getSupportedOutputs() const; 128 | 129 | void stampConductance(SystemConductanceGenerator& gen); 130 | void stampSources(SystemSourceVectorGenerator& gen); 131 | std::string generateParameters(); 132 | std::string generateFields(); 133 | std::string generateInputs(); 134 | std::string generateOutputs(std::string output = "ALL"); 135 | std::string generateOutputsUpdateBody(std::string output="ALL"); 136 | std::string generateUpdateBody(); 137 | 138 | }; 139 | 140 | } //namespace lblmc 141 | 142 | #endif // LBLMC_DUALACTIVEBRIDGECONVERTER_HPP 143 | 144 | -------------------------------------------------------------------------------- /include/codegen/components/FunctionalCurrentSource.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | 24 | #ifndef LBLMC_FUNCTIONALCURRENTSOURCE_HPP 25 | #define LBLMC_FUNCTIONALCURRENTSOURCE_HPP 26 | 27 | #include 28 | #include 29 | #include "codegen/components/Component.hpp" 30 | 31 | namespace lblmc 32 | { 33 | 34 | class FunctionalCurrentSource : public Component 35 | { 36 | 37 | private: 38 | 39 | unsigned int P, N; 40 | unsigned int source_id; 41 | 42 | public: 43 | 44 | FunctionalCurrentSource(std::string comp_name); 45 | FunctionalCurrentSource(const FunctionalCurrentSource& base); 46 | 47 | inline std::string getType() const { return std::string("FunctionalCurrentSource");} 48 | 49 | inline unsigned int getNumberOfTerminals() const { return 2; } 50 | inline unsigned int getNumberOfSources() const { return 1; } 51 | 52 | inline void setTerminalConnections(unsigned int p, unsigned int n) { P = p; N = n; } 53 | inline void getTerminalConnections(std::vector& term_ids) const 54 | { 55 | term_ids = {P, N}; 56 | } 57 | 58 | void getSourceIds(std::vector& ids) const; 59 | void getResistiveCompanionElements(std::vector& elements) const; 60 | 61 | void stampConductance(SystemConductanceGenerator& gen); 62 | void stampSources(SystemSourceVectorGenerator& gen); 63 | std::string generateParameters(); 64 | inline std::string generateFields() { return std::string(""); } 65 | inline std::string generateInputs(); 66 | inline std::string generateOutputs(std::string output = "ALL") { return std::string(""); } 67 | std::string generateUpdateBody(); 68 | }; 69 | 70 | } //namespace lblmc 71 | 72 | #endif // LBLMC_FUNCTIONALCURRENTSOURCE_HPP 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /include/codegen/components/FunctionalVoltageSource.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | 24 | #ifndef LBLMC_FUNCTIONALVOLTAGESOURCE_HPP 25 | #define LBLMC_FUNCTIONALVOLTAGESOURCE_HPP 26 | 27 | #include 28 | #include 29 | #include "codegen/components/Component.hpp" 30 | 31 | namespace lblmc 32 | { 33 | 34 | class FunctionalVoltageSource : public Component 35 | { 36 | 37 | private: 38 | 39 | double RES; 40 | unsigned int P, N; 41 | unsigned int source_id; 42 | 43 | public: 44 | 45 | FunctionalVoltageSource(std::string comp_name); 46 | FunctionalVoltageSource(std::string comp_name, double res); 47 | FunctionalVoltageSource(const FunctionalVoltageSource& base); 48 | 49 | inline std::string getType() const { return std::string("FunctionalVoltageSource");} 50 | 51 | inline unsigned int getNumberOfTerminals() const { return 2; } 52 | inline unsigned int getNumberOfSources() const { return 1; } 53 | 54 | inline void setTerminalConnections(unsigned int p, unsigned int n) { P = p; N = n; } 55 | inline void getTerminalConnections(std::vector& term_ids) const 56 | { 57 | term_ids = {P, N}; 58 | } 59 | 60 | inline void setParameters(double res) { RES = res; } 61 | inline const double& getResistance() const { return RES; } 62 | inline const double getConductance() const { return 1.0/RES; } 63 | 64 | void getSourceIds(std::vector& ids) const; 65 | void getResistiveCompanionElements(std::vector& elements) const; 66 | 67 | void stampConductance(SystemConductanceGenerator& gen); 68 | void stampSources(SystemSourceVectorGenerator& gen); 69 | std::string generateParameters(); 70 | inline std::string generateFields() { return std::string(""); } 71 | inline std::string generateInputs(); 72 | inline std::string generateOutputs(std::string output = "ALL") { return std::string(""); } 73 | std::string generateUpdateBody(); 74 | }; 75 | 76 | } //namespace lblmc 77 | 78 | #endif // LBLMC_FUNCTIONALVOLTAGESOURCE_HPP 79 | 80 | 81 | -------------------------------------------------------------------------------- /include/codegen/components/IdealFunctionalVoltageSource.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | 24 | #ifndef LBLMC_IDEALFUNCTIONALVOLTAGESOURCE_HPP 25 | #define LBLMC_IDEALFUNCTIONALVOLTAGESOURCE_HPP 26 | 27 | #include 28 | #include 29 | #include "codegen/components/Component.hpp" 30 | 31 | namespace lblmc 32 | { 33 | 34 | class IdealFunctionalVoltageSource : public Component 35 | { 36 | 37 | private: 38 | 39 | unsigned int P, N; 40 | unsigned int source_id; 41 | unsigned int solution_id; 42 | 43 | public: 44 | 45 | IdealFunctionalVoltageSource(std::string comp_name); 46 | IdealFunctionalVoltageSource(const IdealFunctionalVoltageSource& base); 47 | 48 | inline std::string getType() const { return std::string("IdealFunctionalVoltageSource");} 49 | 50 | inline unsigned int getNumberOfTerminals() const { return 2; } 51 | inline unsigned int getNumberOfSources() const { return 1; } 52 | inline unsigned int getNumberOfIdealVoltageSources() const { return 1; } 53 | 54 | inline void setTerminalConnections(unsigned int p, unsigned int n) { P = p; N = n; } 55 | inline void getTerminalConnections(std::vector& term_ids) const 56 | { 57 | term_ids = {P, N}; 58 | } 59 | 60 | inline void setSolutionIds(unsigned int s) { solution_id = s; } 61 | 62 | void getSourceIds(std::vector& ids) const; 63 | void getResistiveCompanionElements(std::vector& elements) const; 64 | void getSolutionIds(std::vector& ids) const; 65 | 66 | void stampConductance(SystemConductanceGenerator& gen); 67 | void stampSources(SystemSourceVectorGenerator& gen); 68 | std::string generateParameters(); 69 | inline std::string generateFields() { return std::string(""); } 70 | std::string generateInputs(); 71 | inline std::string generateOutputs(std::string output = "ALL") { return std::string(""); } 72 | std::string generateUpdateBody(); 73 | }; 74 | 75 | } //namespace lblmc 76 | 77 | #endif // LBLMC_IDEALFUNCTIONALVOLTAGESOURCE_HPP 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /include/codegen/components/IdealVoltageSource.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | 24 | #ifndef LBLMC_IDEALVOLTAGESOURCE_HPP 25 | #define LBLMC_IDEALVOLTAGESOURCE_HPP 26 | 27 | #include 28 | #include 29 | #include "codegen/components/Component.hpp" 30 | 31 | namespace lblmc 32 | { 33 | 34 | class IdealVoltageSource : public Component 35 | { 36 | 37 | private: 38 | 39 | double VOLTAGE; 40 | unsigned int P, N; 41 | unsigned int source_id; 42 | unsigned int solution_id; 43 | 44 | public: 45 | 46 | IdealVoltageSource(std::string comp_name); 47 | IdealVoltageSource(std::string comp_name, double v); 48 | IdealVoltageSource(const IdealVoltageSource& base); 49 | 50 | inline std::string getType() const { return std::string("IdealVoltageSource");} 51 | 52 | inline unsigned int getNumberOfTerminals() const { return 2; } 53 | inline unsigned int getNumberOfSources() const { return 1; } 54 | 55 | inline void setTerminalConnections(unsigned int p, unsigned int n) { P = p; N = n; } 56 | inline void getTerminalConnections(std::vector& term_ids) const 57 | { 58 | term_ids = {P, N}; 59 | } 60 | 61 | inline void setSolutionIds(unsigned int s) { solution_id = s; } 62 | 63 | inline void setParameters(double v) { VOLTAGE = v; } 64 | inline const double& getVoltage() const { return VOLTAGE; } 65 | 66 | inline unsigned int getNumberOfIdealVoltageSources() const { return 1; } 67 | 68 | void getSourceIds(std::vector& ids) const; 69 | void getResistiveCompanionElements(std::vector& elements) const; 70 | void getSolutionIds(std::vector& ids) const; 71 | 72 | void stampConductance(SystemConductanceGenerator& gen); 73 | void stampSources(SystemSourceVectorGenerator& gen); 74 | std::string generateParameters(); 75 | inline std::string generateFields() { return std::string(""); } 76 | inline std::string generateInputs() { return std::string(""); } 77 | inline std::string generateOutputs(std::string output = "ALL") { return std::string(""); } 78 | std::string generateUpdateBody(); 79 | }; 80 | 81 | } //namespace lblmc 82 | 83 | #endif // LBLMC_IDEALVOLTAGESOURCE_HPP 84 | 85 | 86 | -------------------------------------------------------------------------------- /include/codegen/components/Inductor.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | 24 | #ifndef LBLMC_INDUCTOR_HPP 25 | #define LBLMC_INDUCTOR_HPP 26 | 27 | #include 28 | #include 29 | #include "codegen/components/Component.hpp" 30 | 31 | namespace lblmc 32 | { 33 | 34 | class Inductor : public Component 35 | { 36 | 37 | private: 38 | 39 | double DT; 40 | double IND; 41 | double HOL2; 42 | unsigned int P, N; 43 | unsigned int source_id; 44 | 45 | public: 46 | 47 | Inductor(std::string comp_name); 48 | Inductor(std::string comp_name, double dt, double ind); 49 | Inductor(const Inductor& base); 50 | 51 | inline std::string getType() const { return std::string("Inductor");} 52 | 53 | inline unsigned int getNumberOfTerminals() const { return 2; } 54 | inline unsigned int getNumberOfSources() const { return 1; } 55 | void getSourceIds(std::vector& ids) const; 56 | void getResistiveCompanionElements(std::vector& elements) const; 57 | 58 | void setTerminalConnections(unsigned int p, unsigned int n); 59 | inline void getTerminalConnections(std::vector& term_ids) const 60 | { 61 | term_ids = {P, N}; 62 | } 63 | 64 | inline void setParameters(double dt, double ind) { DT = dt; IND = ind; } 65 | inline const double& getDT() const { return DT; } 66 | inline const double& getInductance() const { return IND; } 67 | 68 | inline void setIntegrationMethod(std::string method) {} 69 | inline std::string getIntegrationMethod() const { return std::string("tustin"); } 70 | 71 | inline std::vector getSupportedOutputs() const 72 | { 73 | std::vector ret 74 | { 75 | "l_current" 76 | }; 77 | 78 | return ret; 79 | } 80 | 81 | void stampConductance(SystemConductanceGenerator& gen); 82 | void stampSources(SystemSourceVectorGenerator& gen); 83 | std::string generateParameters(); 84 | std::string generateFields(); 85 | std::string generateInputs() { return std::string(""); } 86 | std::string generateOutputs(std::string output = "ALL"); 87 | std::string generateOutputsUpdateBody(std::string output = "ALL"); 88 | std::string generateUpdateBody(); 89 | }; 90 | 91 | } //namespace lblmc 92 | 93 | #endif // LBLMC_INDUCTOR_HPP 94 | -------------------------------------------------------------------------------- /include/codegen/components/NonidealFunctionalCurrentSource.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | 24 | #ifndef LBLMC_NONIDEALFUNCTIONALCURRENTSOURCE_HPP 25 | #define LBLMC_NONIDEALFUNCTIONALCURRENTSOURCE_HPP 26 | 27 | #include 28 | #include 29 | #include "codegen/components/Component.hpp" 30 | 31 | namespace lblmc 32 | { 33 | 34 | /** 35 | \brief generates code for a functional current source with parallel conductance 36 | 37 | This component can be used to recreate resistive companion elements (source+conductance) of 38 | components as components themselves. As such, this component generator has a constructor that 39 | takes as argument a ResistiveCompanionElement object that describes the element. 40 | **/ 41 | class NonidealFunctionalCurrentSource : public Component 42 | { 43 | 44 | private: 45 | 46 | double CONDUCTANCE; 47 | unsigned int P, N; 48 | unsigned int source_id; 49 | 50 | public: 51 | 52 | explicit NonidealFunctionalCurrentSource(std::string comp_name); 53 | NonidealFunctionalCurrentSource(std::string comp_name, double parallel_conductance); 54 | explicit NonidealFunctionalCurrentSource(const ResistiveCompanionElement& rce); 55 | NonidealFunctionalCurrentSource(const NonidealFunctionalCurrentSource& base); 56 | 57 | inline std::string getType() const { return std::string("NonidealFunctionalCurrentSource");} 58 | 59 | inline unsigned int getNumberOfTerminals() const { return 2; } 60 | inline unsigned int getNumberOfSources() const { return 1; } 61 | 62 | inline void setTerminalConnections(unsigned int p, unsigned int n) { P = p; N = n; } 63 | inline void getTerminalConnections(std::vector& term_ids) const 64 | { 65 | term_ids = {P, N}; 66 | } 67 | 68 | inline void setParameters(double para_cond) { CONDUCTANCE = para_cond; } 69 | inline const double getParallelResistance() const { return 1.0/CONDUCTANCE; } 70 | inline const double& getParallelConductance() const { return CONDUCTANCE; } 71 | 72 | 73 | void getSourceIds(std::vector& ids) const; 74 | void getResistiveCompanionElements(std::vector& elements) const; 75 | 76 | void stampConductance(SystemConductanceGenerator& gen); 77 | void stampSources(SystemSourceVectorGenerator& gen); 78 | std::string generateParameters(); 79 | inline std::string generateFields() { return std::string(""); } 80 | inline std::string generateInputs(); 81 | inline std::string generateOutputs(std::string output = "ALL") { return std::string(""); } 82 | std::string generateUpdateBody(); 83 | }; 84 | 85 | } //namespace lblmc 86 | 87 | #endif // LBLMC_NONIDEALFUNCTIONALCURRENTSOURCE_HPP 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /include/codegen/components/NortonPort.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | 24 | #ifndef LBLMC_NORTONPORT_HPP 25 | #define LBLMC_NORTONPORT_HPP 26 | 27 | #include 28 | #include 29 | #include "codegen/components/Component.hpp" 30 | 31 | namespace lblmc 32 | { 33 | 34 | /** 35 | \brief Code generator for a Norton Equivalent Port for a multiport system 36 | 37 | This port component is placed across two terminals and consists of a functional current source, 38 | 0 or more transconductance source, and 0 or 1 conductance across said terminals. 39 | 40 | The component can be used for Nodal decomposition 41 | 42 | \author Matthew Milton 43 | \date 2019 44 | **/ 45 | class NortonPort : public Component 46 | { 47 | 48 | private: 49 | 50 | double CONDUCTANCE; 51 | std::vector TRANSCONDUCTANCES; 52 | unsigned int P, N; 53 | std::vector OTHER_PORT_TERMINALS; 54 | unsigned int source_id; 55 | 56 | public: 57 | 58 | NortonPort(std::string comp_name); 59 | NortonPort(std::string comp_name, const std::vector& all_conductances); 60 | NortonPort(std::string comp_name, double conductance, const std::vector& transconductances); 61 | NortonPort(const NortonPort& base); 62 | 63 | inline std::string getType() const { return std::string("NortonPort");} 64 | 65 | inline unsigned int getNumberOfTerminals() const { return 2 + OTHER_PORT_TERMINALS.size(); } 66 | inline unsigned int getNumberOfSources() const { return 1; } 67 | 68 | void setTerminalConnections 69 | ( 70 | unsigned int p_this_port, 71 | unsigned int n_this_port, 72 | const std::vector& pn_other_ports 73 | ); 74 | 75 | void setTerminalConnections(const std::vector& all_terminals); 76 | 77 | void setParameters(double conduct, const std::vector& xconduct); 78 | 79 | inline const double& getConductance() const { return CONDUCTANCE; } 80 | inline const std::vector& getTransconductances() const { return TRANSCONDUCTANCES; } 81 | 82 | void getSourceIds(std::vector& ids) const; 83 | 84 | /** 85 | As NortonPort components have transconductance and as such do not fully follow normal 86 | resistive companion structure, this method only gives back an element that describes the 87 | functional source and parallel conductance only; transconductance elements are not 88 | described. 89 | **/ 90 | void getResistiveCompanionElements(std::vector& elements) const; 91 | 92 | void stampConductance(SystemConductanceGenerator& gen); 93 | void stampSources(SystemSourceVectorGenerator& gen); 94 | std::string generateParameters(); 95 | std::string generateFields(); 96 | std::string generateInputs(); 97 | std::string generateOutputs(std::string output = "ALL"); 98 | std::string generateUpdateBody(); 99 | }; 100 | 101 | } //namespace lblmc 102 | 103 | #endif // LBLMC_NORTONPORT_HPP 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /include/codegen/components/Resistor.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_RESISTOR_HPP 24 | #define LBLMC_RESISTOR_HPP 25 | 26 | #include 27 | #include 28 | #include "codegen/components/Component.hpp" 29 | 30 | namespace lblmc 31 | { 32 | 33 | class Resistor : public Component 34 | { 35 | 36 | private: 37 | 38 | double RES; 39 | unsigned int P, N; 40 | 41 | public: 42 | 43 | Resistor(std::string comp_name); 44 | Resistor(std::string comp_name, double res); 45 | Resistor(const Resistor& base); 46 | 47 | inline std::string getType() const { return std::string("Resistor");} 48 | 49 | inline unsigned int getNumberOfTerminals() const { return 2; } 50 | inline unsigned int getNumberOfSources() const { return 0; } 51 | 52 | void getResistiveCompanionElements(std::vector& elements) const; 53 | 54 | void setTerminalConnections(unsigned int p, unsigned int n); 55 | inline void getTerminalConnections(std::vector& term_ids) const 56 | { 57 | term_ids = {P, N}; 58 | } 59 | 60 | inline void setParameters(double res) { RES = res; } 61 | inline const double& getResistance() const { return RES; } 62 | inline const double getConductance() const { return 1.0/RES; } 63 | 64 | void stampConductance(SystemConductanceGenerator& gen); 65 | inline void stampSources(SystemSourceVectorGenerator& gen) {} 66 | inline std::string generateParameters() { return std::string(""); } 67 | inline std::string generateFields() { return std::string(""); } 68 | inline std::string generateInputs() { return std::string(""); } 69 | inline std::string generateOutputs(std::string output = "ALL") { return std::string(""); } 70 | inline std::string generateUpdateBody() { return std::string(""); } 71 | }; 72 | 73 | } //namespace lblmc 74 | 75 | #endif // LBLMC_RESISTOR_HPP 76 | 77 | -------------------------------------------------------------------------------- /include/codegen/components/SeriesRLIdealSwitch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_SERIESRLIDEALSWITCH_HPP 24 | #define LBLMC_SERIESRLIDEALSWITCH_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "codegen/components/Component.hpp" 32 | 33 | namespace lblmc 34 | { 35 | 36 | class SeriesRLIdealSwitch : public Component 37 | { 38 | 39 | private: 40 | 41 | double DT; 42 | double L; 43 | double R; 44 | 45 | unsigned int P, N; 46 | unsigned int source_id; 47 | 48 | std::string integration_method; 49 | 50 | public: 51 | 52 | SeriesRLIdealSwitch(std::string comp_name); 53 | SeriesRLIdealSwitch(std::string comp_name, double dt, double l, double r); 54 | SeriesRLIdealSwitch(const SeriesRLIdealSwitch& base); 55 | 56 | inline std::string getType() const { return std::string("SeriesRLIdealSwitch");} 57 | 58 | inline unsigned int getNumberOfTerminals() const { return 2; } 59 | inline unsigned int getNumberOfSources() const { return 1; } 60 | 61 | inline void getSourceIds(std::vector& ids) const { ids.clear(); ids.push_back(source_id); } 62 | void getResistiveCompanionElements(std::vector& elements) const; 63 | 64 | inline void setTerminalConnections 65 | ( 66 | unsigned int p, 67 | unsigned int n 68 | ) { P = p; N = n; } 69 | 70 | inline void getTerminalConnections(std::vector& term_ids) const 71 | { 72 | term_ids = {P,N}; 73 | } 74 | 75 | inline void setParameters 76 | ( 77 | double dt, 78 | double l, 79 | double r 80 | ) { DT = dt; L = l; R = r; } 81 | 82 | inline const double& getDT() const { return DT; } 83 | inline const double& getInductance() const { return L; } 84 | inline const double& getResistance() const { return R; } 85 | 86 | inline void setIntegrationMethod(std::string method) 87 | { 88 | if(method == INTEGRATION_EULER_FORWARD || method == INTEGRATION_RUNGE_KUTTA_4) 89 | integration_method = method; 90 | else throw std::invalid_argument("SeriesRLIdealSwitch::setIntegrationMethod(std::string) -- selected integration method is not supported"); 91 | } 92 | inline std::string getIntegrationMethod() const 93 | { 94 | return integration_method; 95 | } 96 | 97 | inline std::vector getSupportedInputs() const { return std::vector{"sw"}; } 98 | 99 | inline std::vector getSupportedOutputs() const 100 | { 101 | std::vector ret 102 | { 103 | "l_current" 104 | }; 105 | 106 | return ret; 107 | } 108 | 109 | void stampConductance(SystemConductanceGenerator& gen); 110 | void stampSources(SystemSourceVectorGenerator& gen); 111 | std::string generateParameters(); 112 | std::string generateFields(); 113 | std::string generateInputs(); 114 | std::string generateOutputs(std::string output = "ALL"); 115 | std::string generateOutputsUpdateBody(std::string output = "ALL"); 116 | std::string generateUpdateBody(); 117 | 118 | private: 119 | std::string generateUpdateBodyEulerForward(); 120 | std::string generateUpdateBodyRungeKutta4(); 121 | }; 122 | 123 | } //namespace lblmc 124 | 125 | #endif // LBLMC_SERIESRLIDEALSWITCH_HPP 126 | -------------------------------------------------------------------------------- /include/codegen/components/VoltageControlledCurrentSource.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | 24 | #ifndef LBLMC_VOLTAGECONTROLLEDCURRENTSOURCE_HPP 25 | #define LBLMC_VOLTAGECONTROLLEDCURRENTSOURCE_HPP 26 | 27 | #include 28 | #include 29 | #include "codegen/components/Component.hpp" 30 | 31 | namespace lblmc 32 | { 33 | 34 | /** 35 | \brief Code generator for Voltage Controlled Current Sources (VCCS) 36 | 37 | The VCCS is a source whose current is set by a measured voltage across two terminals times a 38 | transconductance gain. 39 | 40 | The VCCS can be used to model transconductance between two ports. 41 | 42 | \author Matthew Milton 43 | \date 2019 44 | **/ 45 | class VoltageControlledCurrentSource : public Component 46 | { 47 | 48 | private: 49 | 50 | double TRANSCONDUCTANCE; 51 | unsigned int M, N, P, Q; 52 | 53 | public: 54 | 55 | VoltageControlledCurrentSource(std::string comp_name); 56 | VoltageControlledCurrentSource(std::string comp_name, double transconductance); 57 | VoltageControlledCurrentSource(const VoltageControlledCurrentSource& base); 58 | 59 | inline std::string getType() const { return std::string("VoltageControlledCurrentSource");} 60 | 61 | inline unsigned int getNumberOfTerminals() const { return 4; } 62 | inline unsigned int getNumberOfSources() const { return 0; } 63 | 64 | inline void setTerminalConnections( 65 | unsigned int pv, 66 | unsigned int nv, 67 | unsigned int pi, 68 | unsigned int ni 69 | ) 70 | { M = pv; N = nv; P = pi; Q = ni; } 71 | 72 | inline void getTerminalConnections(std::vector& term_ids) const 73 | { 74 | term_ids = {M, N, P, Q}; 75 | } 76 | 77 | inline void setParameters(double tc) { TRANSCONDUCTANCE = tc; } 78 | inline const double& getTransconductance() const { return TRANSCONDUCTANCE; } 79 | 80 | void getSourceIds(std::vector& ids) const { ids.clear(); } 81 | 82 | /** 83 | As VoltageControlledCurrentSource components do not follow normal resistive companion 84 | structure, this method gives back an empty vector. 85 | **/ 86 | void getResistiveCompanionElements(std::vector& elements) const { elements.clear(); } 87 | void getResistiveCompanionControlledSourceElements 88 | (std::vector& elements) const; 89 | 90 | void stampConductance(SystemConductanceGenerator& gen); 91 | inline void stampSources(SystemSourceVectorGenerator& gen) {} 92 | inline std::string generateParameters() {return std::string(""); } 93 | inline std::string generateFields() { return std::string(""); } 94 | inline std::string generateInputs() { return std::string(""); } 95 | inline std::string generateOutputs(std::string output = "ALL") { return std::string(""); } 96 | inline std::string generateUpdateBody() {return std::string(""); } 97 | }; 98 | 99 | } //namespace lblmc 100 | 101 | #endif // LBLMC_VOLTAGECONTROLLEDCURRENTSOURCE_HPP 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /include/codegen/components/VoltageSource.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | 24 | #ifndef LBLMC_VOLTAGESOURCE_HPP 25 | #define LBLMC_VOLTAGESOURCE_HPP 26 | 27 | #include 28 | #include 29 | #include "codegen/components/Component.hpp" 30 | 31 | namespace lblmc 32 | { 33 | 34 | class VoltageSource : public Component 35 | { 36 | 37 | private: 38 | 39 | double VOLTAGE; 40 | double RES; 41 | unsigned int P, N; 42 | unsigned int source_id; 43 | 44 | public: 45 | 46 | VoltageSource(std::string comp_name); 47 | VoltageSource(std::string comp_name, double v, double res); 48 | VoltageSource(const VoltageSource& base); 49 | 50 | inline std::string getType() const { return std::string("VoltageSource");} 51 | 52 | inline unsigned int getNumberOfTerminals() const { return 2; } 53 | inline unsigned int getNumberOfSources() const { return 1; } 54 | 55 | inline void setTerminalConnections(unsigned int p, unsigned int n) { P = p; N = n; } 56 | inline void getTerminalConnections(std::vector& term_ids) const 57 | { 58 | term_ids = {P, N}; 59 | } 60 | 61 | inline void setParameters(double v, double res) { VOLTAGE = v; RES = res; } 62 | inline const double& getVoltage() const { return VOLTAGE; } 63 | inline const double& getResistance() const { return RES; } 64 | inline const double getConductance() const { return 1.0/RES; } 65 | 66 | void getSourceIds(std::vector& ids) const; 67 | void getResistiveCompanionElements(std::vector& elements) const; 68 | 69 | void stampConductance(SystemConductanceGenerator& gen); 70 | void stampSources(SystemSourceVectorGenerator& gen); 71 | std::string generateParameters(); 72 | inline std::string generateFields() { return std::string(""); } 73 | inline std::string generateInputs() { return std::string(""); } 74 | inline std::string generateOutputs(std::string output = "ALL") { return std::string(""); } 75 | std::string generateUpdateBody(); 76 | }; 77 | 78 | } //namespace lblmc 79 | 80 | #endif // LBLMC_VOLTAGESOURCE_HPP 81 | 82 | -------------------------------------------------------------------------------- /include/codegen/components/basic.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include "codegen/components/VoltageSource.hpp" 24 | #include "codegen/components/CurrentSource.hpp" 25 | #include "codegen/components/FunctionalCurrentSource.hpp" 26 | #include "codegen/components/FunctionalVoltageSource.hpp" 27 | #include "codegen/components/Resistor.hpp" 28 | #include "codegen/components/Capacitor.hpp" 29 | #include "codegen/components/Inductor.hpp" 30 | -------------------------------------------------------------------------------- /include/codegen/components/power_electronics.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include "codegen/components/BridgeConverter3LegIdealSwitches.hpp" 24 | #include "codegen/components/BridgeConverter3LegIdealSwitchesAntiParallelDiodes.hpp" 25 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/BridgeConverter3LegIdealSwitchesProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_BRIDGECONVERTER3LEGIDEALSWITCHESPRODUCER_HPP 24 | #define LBLMC_BRIDGECONVERTER3LEGIDEALSWITCHESPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class BridgeConverter3LegIdealSwitchesProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | BridgeConverter3LegIdealSwitchesProducer(); 43 | BridgeConverter3LegIdealSwitchesProducer(const BridgeConverter3LegIdealSwitchesProducer& base); 44 | BridgeConverter3LegIdealSwitchesProducer(BridgeConverter3LegIdealSwitchesProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_HALFBRIDGECONVERTER3PHASE2PRODUCER_HPP 52 | 53 | 54 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_BRIDGECONVERTER_1LEGIDEALSWITCHESANTIPARALLELDIODESPRODUCER_HPP 24 | #define LBLMC_BRIDGECONVERTER_1LEGIDEALSWITCHESANTIPARALLELDIODESPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer(); 43 | BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer(const BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer& base); 44 | BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer(BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_BRIDGECONVERTER_1LEGIDEALSWITCHESANTIPARALLELDIODESPRODUCER_HPP 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_BRIDGECONVERTER_3LEGIDEALSWITCHESANTIPARALLELDIODESPRODUCER_HPP 24 | #define LBLMC_BRIDGECONVERTER_3LEGIDEALSWITCHESANTIPARALLELDIODESPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer(); 43 | BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer(const BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer& base); 44 | BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer(BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_BRIDGECONVERTER_3LEGIDEALSWITCHESANTIPARALLELDIODESPRODUCER_HPP 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/CapacitorProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_CAPACITORPRODUCER_HPP 24 | #define LBLMC_CAPACITORPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class CapacitorProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | CapacitorProducer(); 43 | CapacitorProducer(const CapacitorProducer& base); 44 | CapacitorProducer(CapacitorProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_CAPACITORPRODUCER_HPP 52 | 53 | 54 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/ComponentProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_COMPONENTPRODUCER_HPP 24 | #define LBLMC_COMPONENTPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "codegen/components/Component.hpp" 33 | #include "codegen/netlist/ComponentListing.hpp" 34 | 35 | namespace lblmc 36 | { 37 | 38 | /** 39 | \brief pure abstract root class for objects that create code generators for LB-LMC components 40 | 41 | This class is unusable by itself. It must be inherited from to be used. 42 | 43 | \brief Matthew Milton 44 | \date 2019 45 | **/ 46 | class ComponentProducer 47 | { 48 | protected: 49 | 50 | std::string type; 51 | std::string producer_name; 52 | unsigned int num_parameters; 53 | unsigned int num_terminals; 54 | 55 | public: 56 | 57 | ComponentProducer(); 58 | 59 | ComponentProducer(const ComponentProducer& base); 60 | 61 | ComponentProducer(ComponentProducer&& base); 62 | 63 | const std::string& getType() const; 64 | 65 | virtual std::unique_ptr operator()(const ComponentListing& component_def) const = 0; 66 | 67 | protected: 68 | 69 | 70 | bool isTypeValid(const ComponentListing& component_def) const; 71 | 72 | bool isLabelValid(const ComponentListing& component_def) const; 73 | 74 | bool isNumberOfParametersValid(const ComponentListing& component_def) const; 75 | 76 | bool isNumberOfTerminalsValid(const ComponentListing& component_def) const; 77 | 78 | void assertTypeValid(const ComponentListing& component_def) const; 79 | 80 | void assertLabelValid(const ComponentListing& component_def) const; 81 | 82 | void assertNumberOfParametersValid(const ComponentListing& component_def) const; 83 | 84 | void assertNumberOfTerminalsValid(const ComponentListing& component_def) const; 85 | 86 | void assertNetlistComponentInstanceValid(const ComponentListing& component_def) const; 87 | 88 | 89 | 90 | }; 91 | 92 | } //namespace lblmc 93 | 94 | #endif // LBLMC_COMPONENTPRODUCER_HPP 95 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/CurrentSourceProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_CURRENTSOURCEPRODUCER_HPP 24 | #define LBLMC_CURRENTSOURCEPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class CurrentSourceProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | CurrentSourceProducer(); 43 | CurrentSourceProducer(const CurrentSourceProducer& base); 44 | CurrentSourceProducer(CurrentSourceProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_CURRENTSOURCEPRODUCER_HPP 52 | 53 | 54 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/DualActiveBridgeConverter_IdealSwitchesProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_DUALACTIVEBRIDGECONVERTER_IDEALSWITCHESPRODUCER_HPP 24 | #define LBLMC_DUALACTIVEBRIDGECONVERTER_IDEALSWITCHESPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class DualActiveBridgeConverter_IdealSwitchesProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | DualActiveBridgeConverter_IdealSwitchesProducer(); 43 | DualActiveBridgeConverter_IdealSwitchesProducer(const DualActiveBridgeConverter_IdealSwitchesProducer& base); 44 | DualActiveBridgeConverter_IdealSwitchesProducer(DualActiveBridgeConverter_IdealSwitchesProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_DUALACTIVEBRIDGECONVERTER_IDEALSWITCHESPRODUCER_HPP 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/FunctionalCurrentSourceProducer.hpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Copyright (C) 2019-2020 Matthew Milton 5 | 6 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 7 | Open Real-Time Simulation (ORTiS) Framework. 8 | 9 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 21 | 22 | */ 23 | 24 | #ifndef LBLMC_FUNCTIONALCURRENTSOURCEPRODUCER_HPP 25 | #define LBLMC_FUNCTIONALCURRENTSOURCEPRODUCER_HPP 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "codegen/components/Component.hpp" 32 | #include "codegen/netlist/ComponentListing.hpp" 33 | #include "codegen/netlist/producers/ComponentProducer.hpp" 34 | 35 | namespace lblmc 36 | { 37 | 38 | class FunctionalCurrentSourceProducer : public ComponentProducer 39 | { 40 | 41 | public: 42 | 43 | FunctionalCurrentSourceProducer(); 44 | FunctionalCurrentSourceProducer(const FunctionalCurrentSourceProducer& base); 45 | FunctionalCurrentSourceProducer(FunctionalCurrentSourceProducer&& base); 46 | 47 | std::unique_ptr operator()(const ComponentListing& component_def) const; 48 | }; 49 | 50 | } //namespace lblmc 51 | 52 | #endif // LBLMC_FUNCTIONALCURRENTSOURCEPRODUCER_HPP 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/FunctionalVoltageSourceProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_FUNCTIONALVOLTAGESOURCEPRODUCER_HPP 24 | #define LBLMC_FUNCTIONALVOLTAGESOURCEPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class FunctionalVoltageSourceProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | FunctionalVoltageSourceProducer(); 43 | FunctionalVoltageSourceProducer(const FunctionalVoltageSourceProducer& base); 44 | FunctionalVoltageSourceProducer(FunctionalVoltageSourceProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_FUNCTIONALVOLTAGESOURCEPRODUCER_HPP 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/IdealFunctionalVoltageSourceProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_IDEALFUNCTIONALVOLTAGESOURCEPRODUCER_HPP 24 | #define LBLMC_IDEALFUNCTIONALVOLTAGESOURCEPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class IdealFunctionalVoltageSourceProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | IdealFunctionalVoltageSourceProducer(); 43 | IdealFunctionalVoltageSourceProducer(const IdealFunctionalVoltageSourceProducer& base); 44 | IdealFunctionalVoltageSourceProducer(IdealFunctionalVoltageSourceProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_IDEALFUNCTIONALVOLTAGESOURCEPRODUCER_HPP 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/IdealVoltageSourceProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_IDEALVOLTAGESOURCEPRODUCER_HPP 24 | #define LBLMC_IDEALVOLTAGESOURCEPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class IdealVoltageSourceProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | IdealVoltageSourceProducer(); 43 | IdealVoltageSourceProducer(const IdealVoltageSourceProducer& base); 44 | IdealVoltageSourceProducer(IdealVoltageSourceProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_IDEALVOLTAGESOURCEPRODUCER_HPP 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/InductorProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_INDUCTORPRODUCER_HPP 24 | #define LBLMC_INDUCTORPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class InductorProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | InductorProducer(); 43 | InductorProducer(const InductorProducer& base); 44 | InductorProducer(InductorProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_INDUCTORPRODUCER_HPP 52 | 53 | 54 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2021 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef ORTIS_MODULARMULTILEVELCONVERTER_1LEGHALFBRIDGEANTIPARALLELDIODESPRODUCER_HPP 24 | #define ORTIS_MODULARMULTILEVELCONVERTER_1LEGHALFBRIDGEANTIPARALLELDIODESPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer : public ComponentProducer 38 | { 39 | public: 40 | 41 | ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer(); 42 | ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer(const ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer& base); 43 | ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer(ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer&& base); 44 | 45 | std::unique_ptr operator()(const ComponentListing& component_def) const; 46 | 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // ORTIS_MODULARMULTILEVELCONVERTER_1LEGHALFBRIDGEANTIPARALLELDIODESPRODUCER_HPP 52 | 53 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/ModularMultilevelConverter_HalfBridgeModulesProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2021 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_MODULARMULTILEVELCONVERTER_HALFBRIDGEMODULESPRODUCER_HPP 24 | #define LBLMC_MODULARMULTILEVELCONVERTER_HALFBRIDGEMODULESPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class ModularMultilevelConverter_HalfBridgeModulesProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | ModularMultilevelConverter_HalfBridgeModulesProducer(); 43 | ModularMultilevelConverter_HalfBridgeModulesProducer(const ModularMultilevelConverter_HalfBridgeModulesProducer& base); 44 | ModularMultilevelConverter_HalfBridgeModulesProducer(ModularMultilevelConverter_HalfBridgeModulesProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_MODULARMULTILEVELCONVERTER_HALFBRIDGEMODULESPRODUCER_HPP 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/MutualInductance3Producer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_MUTUALINDUCTANCE3PRODUCER_HPP 24 | #define LBLMC_MUTUALINDUCTANCE3PRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class MutualInductance3Producer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | MutualInductance3Producer(); 43 | MutualInductance3Producer(const MutualInductance3Producer& base); 44 | MutualInductance3Producer(MutualInductance3Producer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_MUTUALINDUCTANCE3PRODUCER_HPP 52 | 53 | 54 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/NortonPortProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_NORTONPORTPRODUCER_HPP 24 | #define LBLMC_NORTONPORTPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class NortonPortProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | NortonPortProducer(); 43 | NortonPortProducer(const NortonPortProducer& base); 44 | NortonPortProducer(NortonPortProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_NORTONPORTPRODUCER_HPP 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/ResistorProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_RESISTORPRODUCER_HPP 24 | #define LBLMC_RESISTORPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class ResistorProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | ResistorProducer(); 43 | ResistorProducer(const ResistorProducer& base); 44 | ResistorProducer(ResistorProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_RESISTORPRODUCER_HPP 52 | 53 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/SeriesRLIdealSwitchProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_SERIESRLIDEALSWITCHPRODUCER_HPP 24 | #define LBLMC_SERIESRLIDEALSWITCHPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class SeriesRLIdealSwitchProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | SeriesRLIdealSwitchProducer(); 43 | SeriesRLIdealSwitchProducer(const SeriesRLIdealSwitchProducer& base); 44 | SeriesRLIdealSwitchProducer(SeriesRLIdealSwitchProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_SERIESRLIDEALSWITCHPRODUCER_HPP 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/VoltageControlledCurrentSourceProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_VOLTAGECONTROLLEDCURRENTSOURCEPRODUCER_HPP 24 | #define LBLMC_VOLTAGECONTROLLEDCURRENTSOURCEPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class VoltageControlledCurrentSourceProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | VoltageControlledCurrentSourceProducer(); 43 | VoltageControlledCurrentSourceProducer(const VoltageControlledCurrentSourceProducer& base); 44 | VoltageControlledCurrentSourceProducer(VoltageControlledCurrentSourceProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_VOLTAGECONTROLLEDCURRENTSOURCEPRODUCER_HPP 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /include/codegen/netlist/producers/VoltageSourceProducer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef LBLMC_VOLTAGESOURCEPRODUCER_HPP 24 | #define LBLMC_VOLTAGESOURCEPRODUCER_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "codegen/components/Component.hpp" 31 | #include "codegen/netlist/ComponentListing.hpp" 32 | #include "codegen/netlist/producers/ComponentProducer.hpp" 33 | 34 | namespace lblmc 35 | { 36 | 37 | class VoltageSourceProducer : public ComponentProducer 38 | { 39 | 40 | public: 41 | 42 | VoltageSourceProducer(); 43 | VoltageSourceProducer(const VoltageSourceProducer& base); 44 | VoltageSourceProducer(VoltageSourceProducer&& base); 45 | 46 | std::unique_ptr operator()(const ComponentListing& component_def) const; 47 | }; 48 | 49 | } //namespace lblmc 50 | 51 | #endif // LBLMC_VOLTAGESOURCEPRODUCER_HPP 52 | 53 | 54 | -------------------------------------------------------------------------------- /include/codegen/udc/UserDefinedComponentLoader.hpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Copyright (C) 2020 Matthew Milton 5 | 6 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 7 | Open Real-Time Simulation (ORTiS) Framework. 8 | 9 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 21 | 22 | */ 23 | 24 | #ifndef LBLMC_USERDEFINEDCOMPONENTLOADER_HPP 25 | #define LBLMC_USERDEFINEDCOMPONENTLOADER_HPP 26 | 27 | #include 28 | #include 29 | 30 | #include "codegen/udc/UserDefinedComponent.hpp" 31 | 32 | 33 | namespace lblmc 34 | { 35 | 36 | /** 37 | \brief Loads a User Defined Component definition from streams, strings, and files 38 | 39 | \author Matthew Milton 40 | 41 | \date Created July 19, 2020 42 | 43 | **/ 44 | class UserDefinedComponentLoader 45 | { 46 | 47 | public: 48 | 49 | static 50 | UserDefinedComponent 51 | loadFromStream(std::istream& strm); 52 | 53 | static 54 | UserDefinedComponent 55 | loadFromString(const std::string& str); 56 | 57 | static 58 | UserDefinedComponent 59 | loadFromFile(const std::string& filename); 60 | 61 | private: 62 | 63 | const static std::vector SUPPORTED_MACROS; 64 | const static std::vector SUPPORTED_DATATYPES; 65 | 66 | }; 67 | 68 | } //namespace lblmc 69 | 70 | #endif // LBLMC_USERDEFINEDCOMPONENTLOADER_HPP 71 | -------------------------------------------------------------------------------- /include/exprpar/ExpressionConstants.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef EXPRPAR_EXPRESSIONCONSTANTS_HPP 24 | #define EXPRPAR_EXPRESSIONCONSTANTS_HPP 25 | 26 | #include 27 | 28 | namespace ortis 29 | { 30 | 31 | /** 32 | \brief namespace containing common constants for expression parsing 33 | 34 | \author Matthew Milton 35 | 36 | \date July 24, 2020 37 | **/ 38 | namespace ExpressionConstants 39 | { 40 | 41 | // operator symbol constants 42 | 43 | extern const std::string OPERATOR_UNARY_PLUS_SYMBOL; ///< unary plus (keep sign) operator u+ 44 | extern const std::string OPERATOR_BINARY_PLUS_SYMBOL; ///< binary plus (add) operator + 45 | extern const std::string OPERATOR_UNARY_MINUS_SYMBOL; ///< unary minus (negation) operator u- 46 | extern const std::string OPERATOR_BINARY_MINUS_SYMBOL; ///< binary minus (sub) operator - 47 | extern const std::string OPERATOR_MULTIPLY_SYMBOL; ///< binary multiply (mul) operator * 48 | extern const std::string OPERATOR_DIVIDE_SYMBOL; ///< binary divide (div) operator / 49 | extern const std::string OPERATOR_ASSIGNMENT_SYMBOL; ///< assignment operator = 50 | 51 | // bracket symbol constants 52 | 53 | extern const std::string BRACKET_LEFT_SYMBOL; ///< left bracket symbol ( 54 | extern const std::string BRACKET_RIGHT_SYMBOL; ///< right bracket symbol ) 55 | 56 | // misc. symbol constants 57 | 58 | extern const std::string STATEMENT_END_SYMBOL; ///< statement end symbol ; 59 | 60 | } //namespace ExpressionConstants 61 | 62 | } //namespace ortis 63 | 64 | #endif // EXPRPAR_EXPRESSIONCONSTANTS_HPP 65 | -------------------------------------------------------------------------------- /include/exprpar/ExpressionToken.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef EXPRPAR_EXPRESSIONTOKEN_HPP 24 | #define EXPRPAR_EXPRESSIONTOKEN_HPP 25 | 26 | #include 27 | 28 | namespace ortis 29 | { 30 | 31 | /** 32 | \brief Embodies an token within an expression 33 | 34 | \author Matthew Milton 35 | 36 | \date June 2020 37 | **/ 38 | class ExpressionToken 39 | { 40 | public: 41 | 42 | /** 43 | \brief Type of the tokens 44 | **/ 45 | enum Type 46 | { 47 | UNDEFINED = -1, ///< undefined token 48 | VALUE = 0, ///< variable/literal value token 49 | OPERATOR = 1, ///< operator token 50 | LEFT_BRACKET = 2, ///< left bracket ( token 51 | RIGHT_BRACKET = 3 ///< right bracket ) token 52 | }; 53 | 54 | private: 55 | 56 | ExpressionToken::Type type; ///< type of token 57 | std::string symbol; ///< symbol stored by the token 58 | unsigned char precedence; ///< precedence of token if operator; ignored otherwise 59 | unsigned char num_operands; ///< number of operands taken if operator; ignored otherwise 60 | 61 | public: 62 | 63 | ExpressionToken 64 | ( 65 | ExpressionToken::Type type = ExpressionToken::UNDEFINED, 66 | const std::string& symbol = std::string(""), 67 | unsigned char precedence = 0, 68 | unsigned char num_operands = 0 69 | ); 70 | 71 | ExpressionToken(const ExpressionToken& base); 72 | 73 | ExpressionToken(ExpressionToken&& base); 74 | 75 | ExpressionToken& 76 | operator=(const ExpressionToken& base); 77 | 78 | ExpressionToken& 79 | operator=(ExpressionToken&& base); 80 | 81 | void 82 | setType(ExpressionToken::Type type); 83 | 84 | const ExpressionToken::Type& 85 | getType() const; 86 | 87 | void 88 | setSymbol(const std::string& sym); 89 | 90 | void 91 | setSymbol(std::string&& sym); 92 | 93 | const std::string& 94 | getSymbol() const; 95 | 96 | void 97 | setPrecedence(unsigned char precedence); 98 | 99 | const unsigned char& 100 | getPrecedence() const; 101 | 102 | void 103 | setNumberOfOperands(unsigned char num_operands); 104 | 105 | const unsigned char& 106 | getNumberOfOperands() const; 107 | 108 | bool 109 | hasEqualPrecedence(const ExpressionToken& token); 110 | 111 | bool 112 | hasEqualPrecedence(unsigned char precedence); 113 | 114 | bool 115 | hasHigherPrecedence(const ExpressionToken& token); 116 | 117 | bool 118 | hasHigherPrecedence(unsigned char precedence); 119 | 120 | }; 121 | 122 | } //namespace ortis 123 | 124 | #endif // EXPRPAR_EXPRESSIONTOKEN_HPP 125 | -------------------------------------------------------------------------------- /include/exprpar/ExpressionTraverser.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef EXPRPAR_EXPRESSIONTRAVERSER_HPP 24 | #define EXPRPAR_EXPRESSIONTRAVERSER_HPP 25 | 26 | #include "exprpar/Expression.hpp" 27 | #include "exprpar/ExpressionNode.hpp" 28 | #include "exprpar/ExpressionSymbolTable.hpp" 29 | 30 | namespace ortis 31 | { 32 | 33 | /** 34 | \brief pure abstract base class template for traversers of Expression syntax trees 35 | 36 | \author Matthew Milton 37 | 38 | \date Created July 26, 2020 39 | 40 | Children of this abstract class can be implemented to traverse over Expression syntax trees to 41 | evaluate/analyze/interpret/etc. the trees and their inner nodes. 42 | 43 | \tparam T data type returned from traversing expression syntax trees 44 | **/ 45 | template 46 | class ExpressionTraverser 47 | { 48 | public: 49 | 50 | /** 51 | \brief traverses the inner tree of an Expression object 52 | **/ 53 | virtual 54 | T 55 | operator()(const Expression& expr) = 0; 56 | 57 | /** 58 | \brief traverses a syntax tree, starting from given tree node 59 | **/ 60 | virtual 61 | T 62 | operator()(const ExpressionNode& tree) = 0; 63 | 64 | /** 65 | \brief traverses a syntax tree, starting from given tree node, using symbol table as 66 | reference for traversal 67 | **/ 68 | virtual 69 | T 70 | operator()(const ExpressionNode& tree, const ExpressionSymbolTable::SymbolValueMap& symbols) = 0; 71 | 72 | /** 73 | \brief traverses a syntax tree, starting from given tree node, using symbol-value mappings 74 | as reference for traversal 75 | **/ 76 | virtual 77 | T 78 | operator()(const ExpressionNode& tree, const ExpressionSymbolTable& symbol_value_table) = 0; 79 | 80 | }; 81 | 82 | } //namespace ortis 83 | 84 | #endif // EXPRPAR_EXPRESSIONTRAVERSER_HPP 85 | -------------------------------------------------------------------------------- /include/exprpar/exprpar.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #ifndef EXPRPAR_EXPRPAR_HPP 24 | #define EXPRPAR_EXPRPAR_HPP 25 | 26 | #include "exprpar/Expression.hpp" 27 | #include "exprpar/ExpressionConstants.hpp" 28 | #include "exprpar/ExpressionNode.hpp" 29 | #include "exprpar/ExpressionParser.hpp" 30 | #include "exprpar/ExpressionSymbolTable.hpp" 31 | #include "exprpar/ExpressionToken.hpp" 32 | #include "exprpar/ExpressionTraverser.hpp" 33 | 34 | #endif // EXPRPAR_EXPRPAR_HPP 35 | 36 | -------------------------------------------------------------------------------- /ortis_logo_300dpi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenRealTimeSimulation/SolverCodegen/3b2dc4e2d9239ae167ec89895274da9c26578b8d/ortis_logo_300dpi.png -------------------------------------------------------------------------------- /src/codegen/components/CurrentSource.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include "codegen/components/CurrentSource.hpp" 24 | #include "codegen/SystemConductanceGenerator.hpp" 25 | #include "codegen/SystemSourceVectorGenerator.hpp" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace lblmc 32 | { 33 | 34 | CurrentSource::CurrentSource(std::string comp_name) : 35 | Component(comp_name), 36 | CURRENT(1.0), 37 | P(0), 38 | N(0), 39 | source_id(0) 40 | { 41 | if(comp_name == "") 42 | { 43 | throw std::invalid_argument("CurrentSource::constructor(): comp_name must be a valid, non-empty C++ label"); 44 | } 45 | } 46 | 47 | CurrentSource::CurrentSource(std::string comp_name, double i) : 48 | Component(comp_name), 49 | CURRENT(i), 50 | P(0), 51 | N(0), 52 | source_id(0) 53 | { 54 | if(comp_name == "") 55 | { 56 | throw std::invalid_argument("CurrentSource::constructor(): comp_name must be a valid, non-empty C++ label"); 57 | } 58 | } 59 | 60 | CurrentSource::CurrentSource(const CurrentSource& base) : 61 | Component(base), 62 | CURRENT(base.CURRENT), 63 | P(base.P), 64 | N(base.N), 65 | source_id(base.source_id) 66 | {} 67 | 68 | void CurrentSource::getSourceIds(std::vector& ids) const 69 | { 70 | ids.clear(); 71 | ids.push_back(source_id); 72 | } 73 | 74 | void CurrentSource::getResistiveCompanionElements(std::vector& elements) const 75 | { 76 | elements.clear(); 77 | 78 | RCE rce; 79 | rce.name = appendName(std::string("b")); 80 | rce.p = P; 81 | rce.n = N; 82 | rce.fixed_source_value = CURRENT; 83 | rce.parallel_conductance = 0.0; 84 | rce.source_id = source_id; 85 | rce.is_fixed = true; 86 | rce.has_no_source = false; 87 | rce.is_ideal_voltage_source = false; 88 | 89 | elements.push_back(rce); 90 | } 91 | 92 | void CurrentSource::stampConductance(SystemConductanceGenerator& gen) 93 | { 94 | //do nothing 95 | } 96 | 97 | void CurrentSource::stampSources(SystemSourceVectorGenerator& gen) 98 | { 99 | source_id = gen.insertSource(P,N); 100 | } 101 | 102 | std::string CurrentSource::generateParameters() 103 | { 104 | std::stringstream sstrm; 105 | sstrm << 106 | std::setprecision(16) << 107 | std::fixed << 108 | std::scientific; 109 | 110 | sstrm << 111 | "const static "<<"real "<. 20 | 21 | */ 22 | 23 | 24 | #include "codegen/components/FunctionalCurrentSource.hpp" 25 | #include "codegen/SystemConductanceGenerator.hpp" 26 | #include "codegen/SystemSourceVectorGenerator.hpp" 27 | #include "codegen/Object.hpp" 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | namespace lblmc 34 | { 35 | 36 | FunctionalCurrentSource::FunctionalCurrentSource(std::string comp_name) : 37 | Component(comp_name), 38 | P(0), 39 | N(0), 40 | source_id(0) 41 | { 42 | if(comp_name == "") 43 | { 44 | throw std::invalid_argument("FunctionalCurrentSource::constructor(): comp_name must be a valid, non-empty C++ label"); 45 | } 46 | } 47 | 48 | FunctionalCurrentSource::FunctionalCurrentSource(const FunctionalCurrentSource& base) : 49 | Component(base), 50 | P(base.P), 51 | N(base.N), 52 | source_id(base.source_id) 53 | {} 54 | 55 | void FunctionalCurrentSource::getSourceIds(std::vector& ids) const 56 | { 57 | ids.clear(); 58 | ids.push_back(source_id); 59 | } 60 | 61 | void FunctionalCurrentSource::getResistiveCompanionElements(std::vector& elements) const 62 | { 63 | elements.clear(); 64 | 65 | RCE rce; 66 | rce.name = appendName(std::string("b")); 67 | rce.p = P; 68 | rce.n = N; 69 | rce.fixed_source_value = 0.0; 70 | rce.parallel_conductance = 0.0; 71 | rce.source_id = source_id; 72 | rce.is_fixed = false; 73 | rce.has_no_source = false; 74 | rce.is_ideal_voltage_source = false; 75 | 76 | elements.push_back(rce); 77 | } 78 | 79 | void FunctionalCurrentSource::stampConductance(SystemConductanceGenerator& gen) 80 | { 81 | //do nothing 82 | } 83 | 84 | void FunctionalCurrentSource::stampSources(SystemSourceVectorGenerator& gen) 85 | { 86 | source_id = gen.insertSource(P,N); 87 | } 88 | 89 | std::string FunctionalCurrentSource::generateParameters() 90 | { 91 | return std::string(""); 92 | } 93 | 94 | std::string FunctionalCurrentSource::generateInputs() 95 | { 96 | std::stringstream sstrm; 97 | sstrm << 98 | std::setprecision(16) << 99 | std::fixed << 100 | std::scientific; 101 | 102 | //append name to input ports 103 | lblmc::Object i_in("real", appendName("i_in"), ""); 104 | 105 | sstrm << 106 | i_in.generateArgument(); 107 | 108 | //sstrm << "\n"; 109 | 110 | 111 | return sstrm.str(); 112 | } 113 | 114 | 115 | std::string FunctionalCurrentSource::generateUpdateBody() 116 | { 117 | std::stringstream sstrm; 118 | sstrm << 119 | std::setprecision(16) << 120 | std::fixed << 121 | std::scientific; 122 | 123 | sstrm << 124 | "b_components["<. 20 | 21 | */ 22 | 23 | 24 | #include "codegen/components/FunctionalVoltageSource.hpp" 25 | #include "codegen/SystemConductanceGenerator.hpp" 26 | #include "codegen/SystemSourceVectorGenerator.hpp" 27 | #include "codegen/Object.hpp" 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | namespace lblmc 34 | { 35 | 36 | FunctionalVoltageSource::FunctionalVoltageSource(std::string comp_name) : 37 | Component(comp_name), 38 | RES(1.0), 39 | P(0), 40 | N(0), 41 | source_id(0) 42 | { 43 | if(comp_name == "") 44 | { 45 | throw std::invalid_argument("FunctionalVoltageSource::constructor(): comp_name must be a valid, non-empty C++ label"); 46 | } 47 | } 48 | 49 | FunctionalVoltageSource::FunctionalVoltageSource(std::string comp_name, double res) : 50 | Component(comp_name), 51 | RES(res), 52 | P(0), 53 | N(0), 54 | source_id(0) 55 | { 56 | if(res <= 0) 57 | { 58 | throw std::invalid_argument("FunctionalVoltageSource::constructor(): res must be positive nonzero value"); 59 | } 60 | 61 | if(comp_name == "") 62 | { 63 | throw std::invalid_argument("FunctionalVoltageSource::constructor(): comp_name must be a valid, non-empty C++ label"); 64 | } 65 | } 66 | 67 | FunctionalVoltageSource::FunctionalVoltageSource(const FunctionalVoltageSource& base) : 68 | Component(base), 69 | RES(base.RES), 70 | P(base.P), 71 | N(base.N), 72 | source_id(base.source_id) 73 | {} 74 | 75 | void FunctionalVoltageSource::getSourceIds(std::vector& ids) const 76 | { 77 | ids.clear(); 78 | ids.push_back(source_id); 79 | } 80 | 81 | void FunctionalVoltageSource::getResistiveCompanionElements(std::vector& elements) const 82 | { 83 | elements.clear(); 84 | 85 | RCE rce; 86 | rce.name = appendName(std::string("b")); 87 | rce.p = P; 88 | rce.n = N; 89 | rce.fixed_source_value = 0.0; 90 | rce.parallel_conductance = 1.0/RES; 91 | rce.source_id = source_id; 92 | rce.is_fixed = false; 93 | rce.has_no_source = false; 94 | rce.is_ideal_voltage_source = false; 95 | 96 | elements.push_back(rce); 97 | } 98 | 99 | void FunctionalVoltageSource::stampConductance(SystemConductanceGenerator& gen) 100 | { 101 | gen.stampConductance(1.0/RES, P, N); 102 | } 103 | 104 | void FunctionalVoltageSource::stampSources(SystemSourceVectorGenerator& gen) 105 | { 106 | source_id = gen.insertSource(P,N); 107 | } 108 | 109 | std::string FunctionalVoltageSource::generateParameters() 110 | { 111 | std::stringstream sstrm; 112 | sstrm << 113 | std::setprecision(16) << 114 | std::fixed << 115 | std::scientific; 116 | 117 | sstrm << 118 | "const static "<<"real "<. 20 | 21 | */ 22 | 23 | #include "codegen/components/IdealFunctionalVoltageSource.hpp" 24 | #include "codegen/SystemConductanceGenerator.hpp" 25 | #include "codegen/SystemSourceVectorGenerator.hpp" 26 | #include "codegen/Object.hpp" 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | namespace lblmc 35 | { 36 | 37 | IdealFunctionalVoltageSource::IdealFunctionalVoltageSource(std::string comp_name) : 38 | Component(comp_name), 39 | P(0), 40 | N(0), 41 | source_id(0), 42 | solution_id(0) 43 | { 44 | if(comp_name == "") 45 | { 46 | throw std::invalid_argument("IdealFunctionalVoltageSource::constructor(): comp_name must be a valid, non-empty C++ label"); 47 | } 48 | } 49 | 50 | IdealFunctionalVoltageSource::IdealFunctionalVoltageSource(const IdealFunctionalVoltageSource& base) : 51 | Component(base), 52 | P(base.P), 53 | N(base.N), 54 | source_id(base.source_id), 55 | solution_id(base.solution_id) 56 | {} 57 | 58 | void IdealFunctionalVoltageSource::getSourceIds(std::vector& ids) const 59 | { 60 | ids.clear(); 61 | ids.push_back(source_id); 62 | } 63 | 64 | void IdealFunctionalVoltageSource::getResistiveCompanionElements(std::vector& elements) const 65 | { 66 | elements.clear(); 67 | 68 | RCE rce; 69 | rce.name = appendName(std::string("b")); 70 | rce.p = P; 71 | rce.n = N; 72 | rce.fixed_source_value = 0.0; 73 | rce.parallel_conductance = 0.0; 74 | rce.source_id = source_id; 75 | rce.is_fixed = false; 76 | rce.has_no_source = false; 77 | rce.is_ideal_voltage_source = true; 78 | 79 | elements.push_back(rce); 80 | } 81 | 82 | void IdealFunctionalVoltageSource::getSolutionIds(std::vector& ids) const 83 | { 84 | ids.clear(); 85 | ids.push_back(solution_id); 86 | } 87 | 88 | void IdealFunctionalVoltageSource::stampConductance(SystemConductanceGenerator& gen) 89 | { 90 | gen.stampIdealVoltageSourceIncidence(solution_id, P, N); 91 | } 92 | 93 | void IdealFunctionalVoltageSource::stampSources(SystemSourceVectorGenerator& gen) 94 | { 95 | source_id = gen.insertIdealVoltageSource(solution_id); 96 | } 97 | 98 | std::string IdealFunctionalVoltageSource::generateParameters() 99 | { 100 | return std::string(""); 101 | } 102 | 103 | std::string IdealFunctionalVoltageSource::generateInputs() 104 | { 105 | std::stringstream sstrm; 106 | sstrm << 107 | std::setprecision(16) << 108 | std::fixed << 109 | std::scientific; 110 | 111 | //append name to input ports 112 | lblmc::Object i_in("real", appendName("v_in"), ""); 113 | 114 | sstrm << 115 | i_in.generateArgument(); 116 | 117 | return sstrm.str(); 118 | } 119 | 120 | std::string IdealFunctionalVoltageSource::generateUpdateBody() 121 | { 122 | std::stringstream sstrm; 123 | sstrm << 124 | std::setprecision(16) << 125 | std::fixed << 126 | std::scientific; 127 | 128 | sstrm << 129 | "b_components["<. 20 | 21 | */ 22 | 23 | #include "codegen/components/IdealVoltageSource.hpp" 24 | #include "codegen/SystemConductanceGenerator.hpp" 25 | #include "codegen/SystemSourceVectorGenerator.hpp" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | namespace lblmc 34 | { 35 | 36 | IdealVoltageSource::IdealVoltageSource(std::string comp_name) : 37 | Component(comp_name), 38 | VOLTAGE(1.0), 39 | P(0), 40 | N(0), 41 | source_id(0), 42 | solution_id(0) 43 | { 44 | if(comp_name == "") 45 | { 46 | throw std::invalid_argument("IdealVoltageSource::constructor(): comp_name must be a valid, non-empty C++ label"); 47 | } 48 | } 49 | 50 | IdealVoltageSource::IdealVoltageSource(std::string comp_name, double v) : 51 | Component(comp_name), 52 | VOLTAGE(v), 53 | P(0), 54 | N(0), 55 | source_id(0), 56 | solution_id(0) 57 | { 58 | if(comp_name == "") 59 | { 60 | throw std::invalid_argument("IdealVoltageSource::constructor(): comp_name must be a valid, non-empty C++ label"); 61 | } 62 | } 63 | 64 | IdealVoltageSource::IdealVoltageSource(const IdealVoltageSource& base) : 65 | Component(base), 66 | VOLTAGE(base.VOLTAGE), 67 | P(base.P), 68 | N(base.N), 69 | source_id(base.source_id), 70 | solution_id(base.solution_id) 71 | {} 72 | 73 | void IdealVoltageSource::getSourceIds(std::vector& ids) const 74 | { 75 | ids.clear(); 76 | ids.push_back(source_id); 77 | } 78 | 79 | void IdealVoltageSource::getResistiveCompanionElements(std::vector& elements) const 80 | { 81 | elements.clear(); 82 | 83 | RCE rce; 84 | rce.name = appendName(std::string("b")); 85 | rce.p = P; 86 | rce.n = N; 87 | rce.fixed_source_value = VOLTAGE; 88 | rce.parallel_conductance = 0.0; 89 | rce.source_id = source_id; 90 | rce.is_fixed = true; 91 | rce.has_no_source = false; 92 | rce.is_ideal_voltage_source = true; 93 | 94 | elements.push_back(rce); 95 | } 96 | 97 | void IdealVoltageSource::getSolutionIds(std::vector& ids) const 98 | { 99 | ids.clear(); 100 | ids.push_back(solution_id); 101 | } 102 | 103 | void IdealVoltageSource::stampConductance(SystemConductanceGenerator& gen) 104 | { 105 | gen.stampIdealVoltageSourceIncidence(solution_id, P, N); 106 | } 107 | 108 | void IdealVoltageSource::stampSources(SystemSourceVectorGenerator& gen) 109 | { 110 | source_id = gen.insertIdealVoltageSource(solution_id); 111 | } 112 | 113 | std::string IdealVoltageSource::generateParameters() 114 | { 115 | std::stringstream sstrm; 116 | sstrm << 117 | std::setprecision(16) << 118 | std::fixed << 119 | std::scientific; 120 | 121 | sstrm << 122 | "const static "<<"real "<. 20 | 21 | */ 22 | 23 | #include "codegen/components/Resistor.hpp" 24 | #include "codegen/SystemConductanceGenerator.hpp" 25 | #include "codegen/SystemSourceVectorGenerator.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | Resistor::Resistor(std::string comp_name) : 31 | Component(comp_name), 32 | RES(1.0), 33 | P(0), 34 | N(0) 35 | { 36 | if(comp_name == "") 37 | { 38 | throw std::invalid_argument("Resistor::constructor(): comp_name must be a valid, non-empty C++ label"); 39 | } 40 | } 41 | 42 | 43 | Resistor::Resistor(std::string comp_name, double res) : 44 | Component(comp_name), 45 | RES(res), 46 | P(0), 47 | N(0) 48 | { 49 | if(res <= 0) 50 | { 51 | throw std::invalid_argument("Resistor::constructor(): res must be positive nonzero value"); 52 | } 53 | 54 | if(comp_name == "") 55 | { 56 | throw std::invalid_argument("Resistor::constructor(): comp_name must be a valid, non-empty C++ label"); 57 | } 58 | } 59 | 60 | 61 | Resistor::Resistor(const Resistor& base) : 62 | Component(base), 63 | RES(base.RES), 64 | P(base.P), 65 | N(base.N) 66 | {} 67 | 68 | void Resistor::getResistiveCompanionElements(std::vector& elements) const 69 | { 70 | elements.clear(); 71 | 72 | RCE rce; 73 | rce.name = appendName(std::string("g")); 74 | rce.p = P; 75 | rce.n = N; 76 | rce.parallel_conductance = 1.0/RES; 77 | rce.is_fixed = true; 78 | rce.has_no_source = true; 79 | 80 | elements.push_back(rce); 81 | } 82 | 83 | void Resistor::setTerminalConnections(unsigned int p, unsigned int n) 84 | { 85 | P = p; N = n; 86 | } 87 | 88 | void Resistor::stampConductance(SystemConductanceGenerator& gen) 89 | { 90 | gen.stampConductance(1.0/RES, P, N); 91 | } 92 | 93 | } //namespace lblmc 94 | -------------------------------------------------------------------------------- /src/codegen/components/VoltageControlledCurrentSource.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include "codegen/components/VoltageControlledCurrentSource.hpp" 24 | #include "codegen/SystemConductanceGenerator.hpp" 25 | #include "codegen/SystemSourceVectorGenerator.hpp" 26 | #include "codegen/ResistiveCompanionElements.hpp" 27 | 28 | namespace lblmc 29 | { 30 | 31 | VoltageControlledCurrentSource::VoltageControlledCurrentSource(std::string comp_name) : 32 | Component(comp_name), 33 | TRANSCONDUCTANCE(1.0), 34 | M(0), 35 | N(0), 36 | P(0), 37 | Q(0) 38 | { 39 | if(comp_name == "") 40 | { 41 | throw std::invalid_argument("VoltageControlledCurrentSource::constructor(): comp_name must be a valid, non-empty C++ label"); 42 | } 43 | } 44 | 45 | VoltageControlledCurrentSource::VoltageControlledCurrentSource(std::string comp_name, double transconductance) : 46 | Component(comp_name), 47 | TRANSCONDUCTANCE(transconductance), 48 | M(0), 49 | N(0), 50 | P(0), 51 | Q(0) 52 | { 53 | if(comp_name == "") 54 | { 55 | throw std::invalid_argument("VoltageControlledCurrentSource::constructor(): comp_name must be a valid, non-empty C++ label"); 56 | } 57 | } 58 | 59 | VoltageControlledCurrentSource::VoltageControlledCurrentSource(const VoltageControlledCurrentSource& base) : 60 | Component(base.comp_name), 61 | TRANSCONDUCTANCE(base.TRANSCONDUCTANCE), 62 | M(base.M), 63 | N(base.N), 64 | P(base.P), 65 | Q(base.Q) 66 | {} 67 | 68 | void VoltageControlledCurrentSource::getResistiveCompanionControlledSourceElements 69 | (std::vector& elements) const 70 | { 71 | elements.clear(); 72 | 73 | RCCSE rccse; 74 | rccse.name = appendName("g"); 75 | rccse.p_source = P; 76 | rccse.n_source = Q; 77 | rccse.p_measure = M; 78 | rccse.n_measure = N; 79 | rccse.gain = TRANSCONDUCTANCE; 80 | rccse.type = RCCSE::Type::VOLTAGE_CONTROLLED_CURRENT_SOURCE; 81 | 82 | elements.push_back(rccse); 83 | } 84 | 85 | void VoltageControlledCurrentSource::stampConductance(SystemConductanceGenerator& gen) 86 | { 87 | gen.stampTransconductance(TRANSCONDUCTANCE,M,N,P,Q); 88 | } 89 | 90 | 91 | } //namespace lblmc 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/codegen/components/VoltageSource.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include "codegen/components/VoltageSource.hpp" 24 | #include "codegen/SystemConductanceGenerator.hpp" 25 | #include "codegen/SystemSourceVectorGenerator.hpp" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace lblmc 32 | { 33 | 34 | VoltageSource::VoltageSource(std::string comp_name) : 35 | Component(comp_name), 36 | VOLTAGE(1.0), 37 | RES(1.0), 38 | P(0), 39 | N(0), 40 | source_id(0) 41 | { 42 | if(comp_name == "") 43 | { 44 | throw std::invalid_argument("VoltageSource::constructor(): comp_name must be a valid, non-empty C++ label"); 45 | } 46 | } 47 | 48 | VoltageSource::VoltageSource(std::string comp_name, double v, double res) : 49 | Component(comp_name), 50 | VOLTAGE(v), 51 | RES(res), 52 | P(0), 53 | N(0), 54 | source_id(0) 55 | { 56 | if(res <= 0) 57 | { 58 | throw std::invalid_argument("VoltageSource::constructor(): res must be positive nonzero value"); 59 | } 60 | 61 | if(comp_name == "") 62 | { 63 | throw std::invalid_argument("VoltageSource::constructor(): comp_name must be a valid, non-empty C++ label"); 64 | } 65 | } 66 | 67 | VoltageSource::VoltageSource(const VoltageSource& base) : 68 | Component(base), 69 | VOLTAGE(base.VOLTAGE), 70 | RES(base.RES), 71 | P(base.P), 72 | N(base.N), 73 | source_id(base.source_id) 74 | {} 75 | 76 | void VoltageSource::getSourceIds(std::vector& ids) const 77 | { 78 | ids.clear(); 79 | ids.push_back(source_id); 80 | } 81 | 82 | void VoltageSource::getResistiveCompanionElements(std::vector& elements) const 83 | { 84 | elements.clear(); 85 | 86 | RCE rce; 87 | rce.name = appendName(std::string("b")); 88 | rce.p = P; 89 | rce.n = N; 90 | rce.fixed_source_value = VOLTAGE/RES; 91 | rce.parallel_conductance = 1.0/RES; 92 | rce.source_id = source_id; 93 | rce.is_fixed = true; 94 | rce.has_no_source = false; 95 | rce.is_ideal_voltage_source = false; 96 | 97 | elements.push_back(rce); 98 | } 99 | 100 | 101 | void VoltageSource::stampConductance(SystemConductanceGenerator& gen) 102 | { 103 | gen.stampConductance(1.0/RES, P, N); 104 | } 105 | 106 | void VoltageSource::stampSources(SystemSourceVectorGenerator& gen) 107 | { 108 | source_id = gen.insertSource(P,N); 109 | } 110 | 111 | std::string VoltageSource::generateParameters() 112 | { 113 | std::stringstream sstrm; 114 | sstrm << 115 | std::setprecision(16) << 116 | std::fixed << 117 | std::scientific; 118 | 119 | sstrm << 120 | "const static "<<"real "<. 20 | 21 | */ 22 | 23 | #include "codegen/netlist/ComponentFactory.hpp" 24 | #include 25 | 26 | namespace lblmc 27 | { 28 | 29 | ComponentFactory::ComponentFactory() : 30 | producer_registry() 31 | {} 32 | 33 | ComponentFactory::ComponentFactory(ComponentFactory&& base) : 34 | producer_registry(std::move(base.producer_registry)) 35 | {} 36 | 37 | void ComponentFactory::registerComponentProducer(ComponentProducer* producer) 38 | { 39 | if(producer == nullptr || producer == 0) 40 | throw std::invalid_argument("ComponentFactory::registerComponentProducer(ComponentProducer*) -- given pointer to producer cannot be null"); 41 | 42 | producer_registry.erase(producer->getType()); 43 | producer_registry[producer->getType()] = ComponentProducerPtr(producer); 44 | } 45 | 46 | 47 | void ComponentFactory::registerComponentProducer(ComponentProducerPtr&& producer) 48 | { 49 | producer_registry.erase(producer->getType()); 50 | producer_registry[producer->getType()] = ComponentProducerPtr(std::move(producer)); 51 | } 52 | 53 | #if 0 54 | void ComponentFactory::registerComponentProducer(std::string component_type, const ComponentProducer& producer) 55 | { 56 | producer_registry.erase(component_type); 57 | producer_registry[component_type] = ComponentProducerPtr(producer.clone()); 58 | } 59 | #endif 60 | 61 | 62 | bool ComponentFactory::isComponentProducerRegistered(std::string component_type) 63 | { 64 | const auto iter = producer_registry.find(component_type); 65 | 66 | return ( iter != producer_registry.end() ); 67 | } 68 | 69 | const ComponentProducer* ComponentFactory::getComponentProducer(std::string component_type) 70 | { 71 | try 72 | { 73 | return producer_registry.at(component_type).get(); 74 | } 75 | catch(...) 76 | { 77 | throw std::out_of_range(std::string("ComponentFactory::getComponentProducer() -- producer doesn't exist for given component type: ")+component_type ); 78 | } 79 | 80 | } 81 | 82 | ComponentFactory::ComponentPtr ComponentFactory::produceComponent(const ComponentListing& listing) 83 | { 84 | const auto& producer = *(getComponentProducer(listing.getType())); 85 | 86 | return std::move(producer(listing)); 87 | } 88 | 89 | } //namespace lblmc 90 | -------------------------------------------------------------------------------- /src/codegen/netlist/ComponentFactory_registerBuiltinComponentProducers.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2021 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include "codegen/netlist/ComponentFactory.hpp" 27 | 28 | #include "codegen/netlist/producers/CapacitorProducer.hpp" 29 | #include "codegen/netlist/producers/CurrentSourceProducer.hpp" 30 | #include "codegen/netlist/producers/FunctionalCurrentSourceProducer.hpp" 31 | #include "codegen/netlist/producers/FunctionalVoltageSourceProducer.hpp" 32 | #include "codegen/netlist/producers/BridgeConverter3LegIdealSwitchesProducer.hpp" 33 | #include "codegen/netlist/producers/InductorProducer.hpp" 34 | #include "codegen/netlist/producers/MutualInductance3Producer.hpp" 35 | #include "codegen/netlist/producers/ResistorProducer.hpp" 36 | #include "codegen/netlist/producers/SeriesRLIdealSwitchProducer.hpp" 37 | #include "codegen/netlist/producers/VoltageSourceProducer.hpp" 38 | #include "codegen/netlist/producers/IdealVoltageSourceProducer.hpp" 39 | #include "codegen/netlist/producers/IdealFunctionalVoltageSourceProducer.hpp" 40 | #include "codegen/netlist/producers/NortonPortProducer.hpp" 41 | #include "codegen/netlist/producers/VoltageControlledCurrentSourceProducer.hpp" 42 | #include "codegen/netlist/producers/ModularMultilevelConverter_HalfBridgeModulesProducer.hpp" 43 | #include "codegen/netlist/producers/BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer.hpp" 44 | #include "codegen/netlist/producers/BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer.hpp" 45 | #include "codegen/netlist/producers/DualActiveBridgeConverter_IdealSwitchesProducer.hpp" 46 | #include "codegen/netlist/producers/ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer.hpp" 47 | 48 | namespace lblmc 49 | { 50 | 51 | void ComponentFactory::registerBuiltinComponentProducers() 52 | { 53 | registerComponentProducer( new CapacitorProducer() ); 54 | registerComponentProducer( new CurrentSourceProducer() ); 55 | registerComponentProducer( new FunctionalCurrentSourceProducer() ); 56 | registerComponentProducer( new FunctionalVoltageSourceProducer() ); 57 | registerComponentProducer( new BridgeConverter3LegIdealSwitchesProducer() ); 58 | registerComponentProducer( new InductorProducer() ); 59 | registerComponentProducer( new MutualInductance3Producer() ); 60 | registerComponentProducer( new ResistorProducer() ); 61 | registerComponentProducer( new SeriesRLIdealSwitchProducer() ); 62 | registerComponentProducer( new VoltageSourceProducer() ); 63 | registerComponentProducer( new IdealVoltageSourceProducer() ); 64 | registerComponentProducer( new IdealFunctionalVoltageSourceProducer() ); 65 | registerComponentProducer( new NortonPortProducer() ); 66 | registerComponentProducer( new VoltageControlledCurrentSourceProducer() ); 67 | registerComponentProducer( new ModularMultilevelConverter_HalfBridgeModulesProducer() ); 68 | registerComponentProducer( new BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer() ); 69 | registerComponentProducer( new BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer() ); 70 | registerComponentProducer( new DualActiveBridgeConverter_IdealSwitchesProducer() ); 71 | registerComponentProducer( new ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer() ); 72 | } 73 | 74 | } //namespace lblmc 75 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/BridgeConverter3LegIdealSwitchesProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/BridgeConverter3LegIdealSwitchesProducer.hpp" 25 | #include "codegen/components/BridgeConverter3LegIdealSwitches.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | BridgeConverter3LegIdealSwitchesProducer::BridgeConverter3LegIdealSwitchesProducer() : 31 | ComponentProducer() 32 | { 33 | type = "BridgeConverter3LegIdealSwitches"; 34 | producer_name = "BridgeConverter3LegIdealSwitchesProducer"; 35 | num_parameters = 4; 36 | num_terminals = 6; 37 | } 38 | 39 | BridgeConverter3LegIdealSwitchesProducer::BridgeConverter3LegIdealSwitchesProducer(const BridgeConverter3LegIdealSwitchesProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | BridgeConverter3LegIdealSwitchesProducer::BridgeConverter3LegIdealSwitchesProducer(BridgeConverter3LegIdealSwitchesProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr BridgeConverter3LegIdealSwitchesProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | BridgeConverter3LegIdealSwitches* comp = new BridgeConverter3LegIdealSwitches 60 | ( 61 | component_def.getLabel(), 62 | component_def.getParameter(0), 63 | component_def.getParameter(1), 64 | component_def.getParameter(2), 65 | component_def.getParameter(3) 66 | ); 67 | 68 | comp->setTerminalConnections 69 | ( 70 | component_def.getTerminalConnection(0), 71 | component_def.getTerminalConnection(1), 72 | component_def.getTerminalConnection(2), 73 | component_def.getTerminalConnection(3), 74 | component_def.getTerminalConnection(4), 75 | component_def.getTerminalConnection(5) 76 | ); 77 | 78 | return std::unique_ptr(comp); 79 | } 80 | 81 | } //namespace lblmc 82 | 83 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer.hpp" 25 | #include "codegen/components/BridgeConverter_1LegIdealSwitchesAntiParallelDiodes.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer::BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer() : 31 | ComponentProducer() 32 | { 33 | type = "BridgeConverter_1LegIdealSwitchesAntiParallelDiodes"; 34 | producer_name = "BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer"; 35 | num_parameters = 5; 36 | num_terminals = 4; 37 | } 38 | 39 | BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer::BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer(const BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer::BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer(BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr BridgeConverter_1LegIdealSwitchesAntiParallelDiodesProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | BridgeConverter_1LegIdealSwitchesAntiParallelDiodes* comp = new BridgeConverter_1LegIdealSwitchesAntiParallelDiodes 60 | ( 61 | component_def.getLabel(), 62 | component_def.getParameter(0), 63 | component_def.getParameter(1), 64 | component_def.getParameter(2), 65 | component_def.getParameter(3), 66 | component_def.getParameter(4) 67 | ); 68 | 69 | 70 | comp->setTerminalConnections 71 | ( 72 | component_def.getTerminalConnection(0), 73 | component_def.getTerminalConnection(1), 74 | component_def.getTerminalConnection(2), 75 | component_def.getTerminalConnection(3) 76 | ); 77 | 78 | return std::unique_ptr(comp); 79 | } 80 | 81 | } //namespace lblmc 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer.hpp" 25 | #include "codegen/components/BridgeConverter_3LegIdealSwitchesAntiParallelDiodes.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer::BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer() : 31 | ComponentProducer() 32 | { 33 | type = "BridgeConverter_3LegIdealSwitchesAntiParallelDiodes"; 34 | producer_name = "BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer"; 35 | num_parameters = 5; 36 | num_terminals = 6; 37 | } 38 | 39 | BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer::BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer(const BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer::BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer(BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr BridgeConverter_3LegIdealSwitchesAntiParallelDiodesProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | BridgeConverter_3LegIdealSwitchesAntiParallelDiodes* comp = new BridgeConverter_3LegIdealSwitchesAntiParallelDiodes 60 | ( 61 | component_def.getLabel(), 62 | component_def.getParameter(0), 63 | component_def.getParameter(1), 64 | component_def.getParameter(2), 65 | component_def.getParameter(3), 66 | component_def.getParameter(4) 67 | ); 68 | 69 | 70 | comp->setTerminalConnections 71 | ( 72 | component_def.getTerminalConnection(0), 73 | component_def.getTerminalConnection(1), 74 | component_def.getTerminalConnection(2), 75 | component_def.getTerminalConnection(3), 76 | component_def.getTerminalConnection(4), 77 | component_def.getTerminalConnection(5) 78 | ); 79 | 80 | return std::unique_ptr(comp); 81 | } 82 | 83 | } //namespace lblmc 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/CapacitorProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/CapacitorProducer.hpp" 25 | #include "codegen/components/Capacitor.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | CapacitorProducer::CapacitorProducer() : 31 | ComponentProducer() 32 | { 33 | type = "Capacitor"; 34 | producer_name = "CapacitorProducer"; 35 | num_parameters = 2; 36 | num_terminals = 2; 37 | } 38 | 39 | CapacitorProducer::CapacitorProducer(const CapacitorProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | CapacitorProducer::CapacitorProducer(CapacitorProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr CapacitorProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | Capacitor* comp = new Capacitor( component_def.getLabel(), component_def.getParameter(0), component_def.getParameter(1) ); 60 | comp->setTerminalConnections( component_def.getTerminalConnection(0), component_def.getTerminalConnection(1) ); 61 | 62 | return std::unique_ptr(comp); 63 | } 64 | 65 | } //namespace lblmc 66 | 67 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/ComponentProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include "codegen/netlist/producers/ComponentProducer.hpp" 24 | 25 | namespace lblmc 26 | { 27 | 28 | ComponentProducer::ComponentProducer() : 29 | type(""), 30 | producer_name("ComponentProducer"), 31 | num_parameters(0), 32 | num_terminals(0) 33 | {} 34 | 35 | ComponentProducer::ComponentProducer(const ComponentProducer& base) : 36 | type(base.type), 37 | producer_name(base.producer_name), 38 | num_parameters(base.num_parameters), 39 | num_terminals(base.num_terminals) 40 | {} 41 | 42 | ComponentProducer::ComponentProducer(ComponentProducer&& base) : 43 | type(std::move(base.type)), 44 | producer_name(std::move(base.producer_name)), 45 | num_parameters(base.num_parameters), 46 | num_terminals(base.num_terminals) 47 | {} 48 | 49 | const std::string& ComponentProducer::getType() const { return type; } 50 | 51 | bool ComponentProducer::isTypeValid(const ComponentListing& component_def) const 52 | { 53 | return component_def.getType() == getType(); 54 | } 55 | 56 | bool ComponentProducer::isLabelValid(const ComponentListing& component_def) const 57 | { 58 | return component_def.getLabel() != std::string(""); 59 | } 60 | 61 | bool ComponentProducer::isNumberOfParametersValid(const ComponentListing& component_def) const 62 | { 63 | return num_parameters == component_def.getParametersCount(); 64 | } 65 | 66 | bool ComponentProducer::isNumberOfTerminalsValid(const ComponentListing& component_def) const 67 | { 68 | return num_terminals == component_def.getTerminalConnectionsCount(); 69 | } 70 | 71 | void ComponentProducer::assertTypeValid(const ComponentListing& component_def) const 72 | { 73 | if(!isTypeValid(component_def)) 74 | { 75 | throw std::invalid_argument(producer_name+std::string("::assertTypeValid(x) -- netlist component type does not match this producer")); 76 | } 77 | } 78 | 79 | void ComponentProducer::assertLabelValid(const ComponentListing& component_def) const 80 | { 81 | if(!isLabelValid(component_def)) 82 | { 83 | throw std::invalid_argument(producer_name+std::string("::assertLabelValid(x) -- netlist component label is not valid")); 84 | } 85 | } 86 | 87 | void ComponentProducer::assertNumberOfParametersValid(const ComponentListing& component_def) const 88 | { 89 | if(!isNumberOfParametersValid(component_def)) 90 | { 91 | throw std::invalid_argument(producer_name+std::string("::assertNumberOfParametersValid(x) -- netlist component parameter amount is incorrect: amount of parameters supported is ")+std::to_string(num_parameters)); 92 | } 93 | } 94 | 95 | void ComponentProducer::assertNumberOfTerminalsValid(const ComponentListing& component_def) const 96 | { 97 | if(!isNumberOfTerminalsValid(component_def)) 98 | { 99 | throw std::invalid_argument(producer_name+std::string("::assertNumberOfTerminalsValid(x) -- netlist component terminal amount is incorrect: amount of terminals supported is ")+std::to_string(num_terminals)); 100 | } 101 | } 102 | 103 | void ComponentProducer::assertNetlistComponentInstanceValid(const ComponentListing& component_def) const 104 | { 105 | assertTypeValid(component_def); 106 | assertLabelValid(component_def); 107 | assertNumberOfParametersValid(component_def); 108 | assertNumberOfTerminalsValid(component_def); 109 | } 110 | 111 | } //namespace lblmc 112 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/CurrentSourceProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/CurrentSourceProducer.hpp" 25 | #include "codegen/components/CurrentSource.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | CurrentSourceProducer::CurrentSourceProducer() : 31 | ComponentProducer() 32 | { 33 | type = "CurrentSource"; 34 | producer_name = "CurrentSourceProducer"; 35 | num_parameters = 1; 36 | num_terminals = 2; 37 | } 38 | 39 | CurrentSourceProducer::CurrentSourceProducer(const CurrentSourceProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | CurrentSourceProducer::CurrentSourceProducer(CurrentSourceProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr CurrentSourceProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | CurrentSource* comp = new CurrentSource( component_def.getLabel(), component_def.getParameter(0) ); 60 | comp->setTerminalConnections( component_def.getTerminalConnection(0), component_def.getTerminalConnection(1) ); 61 | 62 | return std::unique_ptr(comp); 63 | } 64 | 65 | } //namespace lblmc 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/DualActiveBridgeConverter_IdealSwitchesProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/DualActiveBridgeConverter_IdealSwitchesProducer.hpp" 25 | #include "codegen/components/DualActiveBridgeConverter_IdealSwitches.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | DualActiveBridgeConverter_IdealSwitchesProducer::DualActiveBridgeConverter_IdealSwitchesProducer() : 31 | ComponentProducer() 32 | { 33 | type = "DualActiveBridgeConverter_IdealSwitches"; 34 | producer_name = "DualActiveBridgeConverter_IdealSwitchesProducer"; 35 | num_parameters = 12; 36 | num_terminals = 4; 37 | } 38 | 39 | DualActiveBridgeConverter_IdealSwitchesProducer::DualActiveBridgeConverter_IdealSwitchesProducer(const DualActiveBridgeConverter_IdealSwitchesProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | DualActiveBridgeConverter_IdealSwitchesProducer::DualActiveBridgeConverter_IdealSwitchesProducer(DualActiveBridgeConverter_IdealSwitchesProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr DualActiveBridgeConverter_IdealSwitchesProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | DualActiveBridgeConverter_IdealSwitches* comp = new DualActiveBridgeConverter_IdealSwitches 60 | ( 61 | component_def.getLabel(), 62 | component_def.getParameter(0), 63 | component_def.getParameter(1), 64 | component_def.getParameter(2), 65 | component_def.getParameter(3), 66 | component_def.getParameter(4), 67 | component_def.getParameter(5), 68 | component_def.getParameter(6), 69 | component_def.getParameter(7), 70 | component_def.getParameter(8), 71 | component_def.getParameter(9), 72 | component_def.getParameter(10), 73 | component_def.getParameter(11) 74 | ); 75 | 76 | 77 | comp->setTerminalConnections 78 | ( 79 | component_def.getTerminalConnection(0), 80 | component_def.getTerminalConnection(1), 81 | component_def.getTerminalConnection(2), 82 | component_def.getTerminalConnection(3) 83 | ); 84 | 85 | return std::unique_ptr(comp); 86 | } 87 | 88 | } //namespace lblmc 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/FunctionalCurrentSourceProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/FunctionalCurrentSourceProducer.hpp" 25 | #include "codegen/components/FunctionalCurrentSource.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | FunctionalCurrentSourceProducer::FunctionalCurrentSourceProducer() : 31 | ComponentProducer() 32 | { 33 | type = "FunctionalCurrentSource"; 34 | producer_name = "FunctionalCurrentSourceProducer"; 35 | num_parameters = 0; 36 | num_terminals = 2; 37 | } 38 | 39 | FunctionalCurrentSourceProducer::FunctionalCurrentSourceProducer(const FunctionalCurrentSourceProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | FunctionalCurrentSourceProducer::FunctionalCurrentSourceProducer(FunctionalCurrentSourceProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr FunctionalCurrentSourceProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | FunctionalCurrentSource* comp = new FunctionalCurrentSource( component_def.getLabel() ); 60 | comp->setTerminalConnections( component_def.getTerminalConnection(0), component_def.getTerminalConnection(1) ); 61 | 62 | return std::unique_ptr(comp); 63 | } 64 | 65 | } //namespace lblmc 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/FunctionalVoltageSourceProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/FunctionalVoltageSourceProducer.hpp" 25 | #include "codegen/components/FunctionalVoltageSource.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | FunctionalVoltageSourceProducer::FunctionalVoltageSourceProducer() : 31 | ComponentProducer() 32 | { 33 | type = "FunctionalVoltageSource"; 34 | producer_name = "FunctionalVoltageSourceProducer"; 35 | num_parameters = 1; 36 | num_terminals = 2; 37 | } 38 | 39 | FunctionalVoltageSourceProducer::FunctionalVoltageSourceProducer(const FunctionalVoltageSourceProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | FunctionalVoltageSourceProducer::FunctionalVoltageSourceProducer(FunctionalVoltageSourceProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr FunctionalVoltageSourceProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | FunctionalVoltageSource* comp = new FunctionalVoltageSource( component_def.getLabel(), component_def.getParameter(0) ); 60 | comp->setTerminalConnections( component_def.getTerminalConnection(0), component_def.getTerminalConnection(1) ); 61 | 62 | return std::unique_ptr(comp); 63 | } 64 | 65 | } //namespace lblmc 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/IdealFunctionalVoltageSourceProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/IdealFunctionalVoltageSourceProducer.hpp" 25 | #include "codegen/components/IdealFunctionalVoltageSource.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | IdealFunctionalVoltageSourceProducer::IdealFunctionalVoltageSourceProducer() : 31 | ComponentProducer() 32 | { 33 | type = "IdealFunctionalVoltageSource"; 34 | producer_name = "IdealFunctionalVoltageSourceProducer"; 35 | num_parameters = 1; 36 | num_terminals = 2; 37 | } 38 | 39 | IdealFunctionalVoltageSourceProducer::IdealFunctionalVoltageSourceProducer(const IdealFunctionalVoltageSourceProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | IdealFunctionalVoltageSourceProducer::IdealFunctionalVoltageSourceProducer(IdealFunctionalVoltageSourceProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr IdealFunctionalVoltageSourceProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | IdealFunctionalVoltageSource* comp = new IdealFunctionalVoltageSource( component_def.getLabel() ); 60 | comp->setTerminalConnections( component_def.getTerminalConnection(0), component_def.getTerminalConnection(1) ); 61 | comp->setSolutionIds(component_def.getParameter(0)); 62 | 63 | return std::unique_ptr(comp); 64 | } 65 | 66 | } //namespace lblmc 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/IdealVoltageSourceProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/IdealVoltageSourceProducer.hpp" 25 | #include "codegen/components/IdealVoltageSource.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | IdealVoltageSourceProducer::IdealVoltageSourceProducer() : 31 | ComponentProducer() 32 | { 33 | type = "IdealVoltageSource"; 34 | producer_name = "IdealVoltageSourceProducer"; 35 | num_parameters = 2; 36 | num_terminals = 2; 37 | } 38 | 39 | IdealVoltageSourceProducer::IdealVoltageSourceProducer(const IdealVoltageSourceProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | IdealVoltageSourceProducer::IdealVoltageSourceProducer(IdealVoltageSourceProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr IdealVoltageSourceProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | IdealVoltageSource* comp = new IdealVoltageSource( component_def.getLabel(), component_def.getParameter(0) ); 60 | comp->setTerminalConnections( component_def.getTerminalConnection(0), component_def.getTerminalConnection(1) ); 61 | comp->setSolutionIds(component_def.getParameter(1)); 62 | 63 | return std::unique_ptr(comp); 64 | } 65 | 66 | } //namespace lblmc 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/InductorProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/InductorProducer.hpp" 25 | #include "codegen/components/Inductor.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | InductorProducer::InductorProducer() : 31 | ComponentProducer() 32 | { 33 | type = "Inductor"; 34 | producer_name = "InductorProducer"; 35 | num_parameters = 2; 36 | num_terminals = 2; 37 | } 38 | 39 | InductorProducer::InductorProducer(const InductorProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | InductorProducer::InductorProducer(InductorProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr InductorProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | Inductor* comp = new Inductor( component_def.getLabel(), component_def.getParameter(0), component_def.getParameter(1) ); 60 | comp->setTerminalConnections( component_def.getTerminalConnection(0), component_def.getTerminalConnection(1) ); 61 | 62 | return std::unique_ptr(comp); 63 | } 64 | 65 | } //namespace lblmc 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2021 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer.hpp" 25 | #include "codegen/components/ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodes.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer::ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer() : 31 | ComponentProducer() 32 | { 33 | type = "ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodes"; 34 | producer_name = "ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer"; 35 | num_parameters = 9; 36 | num_terminals = 3; 37 | } 38 | 39 | ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer::ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer(const ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer::ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer(ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodesProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodes* comp = new ModularMultilevelConverter_1LegHalfBridgeAntiParallelDiodes 60 | ( 61 | component_def.getLabel(), 62 | component_def.getParameter(0), 63 | component_def.getParameter(1), 64 | component_def.getParameter(2), 65 | component_def.getParameter(3), 66 | component_def.getParameter(4), 67 | component_def.getParameter(5), 68 | component_def.getParameter(6), 69 | component_def.getParameter(7), 70 | component_def.getParameter(8) 71 | ); 72 | 73 | 74 | comp->setTerminalConnections 75 | ( 76 | component_def.getTerminalConnection(0), 77 | component_def.getTerminalConnection(1), 78 | component_def.getTerminalConnection(2) 79 | ); 80 | 81 | return std::unique_ptr(comp); 82 | } 83 | 84 | } //namespace lblmc 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/ModularMultilevelConverter_HalfBridgeModulesProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2021 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/ModularMultilevelConverter_HalfBridgeModulesProducer.hpp" 25 | #include "codegen/components/ModularMultilevelConverter_HalfBridgeModules.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | ModularMultilevelConverter_HalfBridgeModulesProducer::ModularMultilevelConverter_HalfBridgeModulesProducer() : 31 | ComponentProducer() 32 | { 33 | type = "ModularMultilevelConverter_HalfBridgeModules"; 34 | producer_name = "ModularMultilevelConverter_HalfBridgeModulesProducer"; 35 | num_parameters = 7; 36 | num_terminals = 5; 37 | } 38 | 39 | ModularMultilevelConverter_HalfBridgeModulesProducer::ModularMultilevelConverter_HalfBridgeModulesProducer(const ModularMultilevelConverter_HalfBridgeModulesProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | ModularMultilevelConverter_HalfBridgeModulesProducer::ModularMultilevelConverter_HalfBridgeModulesProducer(ModularMultilevelConverter_HalfBridgeModulesProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr ModularMultilevelConverter_HalfBridgeModulesProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | ModularMultilevelConverter_HalfBridgeModules* comp = new ModularMultilevelConverter_HalfBridgeModules 60 | ( 61 | component_def.getLabel(), 62 | component_def.getParameter(0), 63 | component_def.getParameter(1), 64 | component_def.getParameter(2), 65 | component_def.getParameter(3), 66 | component_def.getParameter(4), 67 | component_def.getParameter(5), 68 | component_def.getParameter(6) 69 | ); 70 | 71 | 72 | comp->setTerminalConnections 73 | ( 74 | component_def.getTerminalConnection(0), 75 | component_def.getTerminalConnection(1), 76 | component_def.getTerminalConnection(2), 77 | component_def.getTerminalConnection(3), 78 | component_def.getTerminalConnection(4) 79 | ); 80 | 81 | return std::unique_ptr(comp); 82 | } 83 | 84 | } //namespace lblmc 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/MutualInductance3Producer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/MutualInductance3Producer.hpp" 25 | #include "codegen/components/MutualInductance3.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | MutualInductance3Producer::MutualInductance3Producer() : 31 | ComponentProducer() 32 | { 33 | type = "MutualInductance3"; 34 | producer_name = "MutualInductance3Producer"; 35 | num_parameters = 7; 36 | num_terminals = 6; 37 | } 38 | 39 | MutualInductance3Producer::MutualInductance3Producer(const MutualInductance3Producer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | MutualInductance3Producer::MutualInductance3Producer(MutualInductance3Producer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr MutualInductance3Producer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | MutualInductance3* comp = new MutualInductance3 60 | ( 61 | component_def.getLabel(), 62 | component_def.getParameter(0), 63 | component_def.getParameter(1), 64 | component_def.getParameter(2), 65 | component_def.getParameter(3), 66 | component_def.getParameter(4), 67 | component_def.getParameter(5), 68 | component_def.getParameter(6) 69 | ); 70 | 71 | 72 | comp->setTerminalConnections 73 | ( 74 | component_def.getTerminalConnection(0), 75 | component_def.getTerminalConnection(1), 76 | component_def.getTerminalConnection(2), 77 | component_def.getTerminalConnection(3), 78 | component_def.getTerminalConnection(4), 79 | component_def.getTerminalConnection(5) 80 | ); 81 | 82 | return std::unique_ptr(comp); 83 | } 84 | 85 | } //namespace lblmc 86 | 87 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/NortonPortProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/NortonPortProducer.hpp" 25 | #include "codegen/components/NortonPort.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | NortonPortProducer::NortonPortProducer() : 31 | ComponentProducer() 32 | { 33 | type = "NortonPort"; 34 | producer_name = "NortonPortProducer"; 35 | num_parameters = 1; //minimum number of parameters in this case since parameter amount is variable 36 | num_terminals = 2; //minimum number of terminals in this case since terminal amount is variable 37 | } 38 | 39 | NortonPortProducer::NortonPortProducer(const NortonPortProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | NortonPortProducer::NortonPortProducer(NortonPortProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr NortonPortProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertTypeValid(component_def); 58 | assertLabelValid(component_def); 59 | 60 | auto parameter_count = component_def.getParametersCount(); 61 | if(parameter_count < 1) 62 | { 63 | throw std::invalid_argument(producer_name+std::string("::operator() -- netlist component parameter amount is incorrect: amount of parameters supported is 1 or greater") ); 64 | } 65 | 66 | auto terminal_count = component_def.getTerminalConnectionsCount(); 67 | if( (terminal_count < 2) || ( (terminal_count-2)/2 != (parameter_count-1) ) ) 68 | { 69 | throw std::invalid_argument(producer_name+std::string("::operator() -- netlist component terminal connection amount is incorrect: amount must be 2 + 2 * number of transconductances") ); 70 | } 71 | 72 | NortonPort* comp = new NortonPort(component_def.getLabel(), component_def.getParameters()); 73 | comp->setTerminalConnections(component_def.getTerminalConnections()); 74 | 75 | return std::unique_ptr(comp); 76 | } 77 | 78 | } //namespace lblmc 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/ResistorProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/ResistorProducer.hpp" 25 | #include "codegen/components/Resistor.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | ResistorProducer::ResistorProducer() : 31 | ComponentProducer() 32 | { 33 | type = "Resistor"; 34 | producer_name = "ResistorProducer"; 35 | num_parameters = 1; 36 | num_terminals = 2; 37 | } 38 | 39 | ResistorProducer::ResistorProducer(const ResistorProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | ResistorProducer::ResistorProducer(ResistorProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr ResistorProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | Resistor* comp = new Resistor( component_def.getLabel(), component_def.getParameter(0) ); 60 | comp->setTerminalConnections( component_def.getTerminalConnection(0), component_def.getTerminalConnection(1) ); 61 | 62 | return std::unique_ptr(comp); 63 | } 64 | 65 | } //namespace lblmc 66 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/SeriesRLIdealSwitchProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/SeriesRLIdealSwitchProducer.hpp" 25 | #include "codegen/components/SeriesRLIdealSwitch.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | SeriesRLIdealSwitchProducer::SeriesRLIdealSwitchProducer() : 31 | ComponentProducer() 32 | { 33 | type = "SeriesRLIdealSwitch"; 34 | producer_name = "SeriesRLIdealSwitchProducer"; 35 | num_parameters = 3; 36 | num_terminals = 2; 37 | } 38 | 39 | SeriesRLIdealSwitchProducer::SeriesRLIdealSwitchProducer(const SeriesRLIdealSwitchProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | SeriesRLIdealSwitchProducer::SeriesRLIdealSwitchProducer(SeriesRLIdealSwitchProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr SeriesRLIdealSwitchProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | SeriesRLIdealSwitch* comp = new SeriesRLIdealSwitch( component_def.getLabel(), component_def.getParameter(0), component_def.getParameter(1), component_def.getParameter(2) ); 60 | comp->setTerminalConnections( component_def.getTerminalConnection(0), component_def.getTerminalConnection(1) ); 61 | 62 | return std::unique_ptr(comp); 63 | } 64 | 65 | } //namespace lblmc 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/VoltageControlledCurrentSourceProducer.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Copyright (C) 2019-2020 Matthew Milton 5 | 6 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 7 | Open Real-Time Simulation (ORTiS) Framework. 8 | 9 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 21 | 22 | */ 23 | 24 | #include 25 | #include "codegen/netlist/producers/VoltageControlledCurrentSourceProducer.hpp" 26 | #include "codegen/components/VoltageControlledCurrentSource.hpp" 27 | 28 | namespace lblmc 29 | { 30 | 31 | VoltageControlledCurrentSourceProducer::VoltageControlledCurrentSourceProducer() : 32 | ComponentProducer() 33 | { 34 | type = "VoltageControlledCurrentSource"; 35 | producer_name = "VoltageControlledCurrentSourceProducer"; 36 | num_parameters = 1; 37 | num_terminals = 4; 38 | } 39 | 40 | VoltageControlledCurrentSourceProducer::VoltageControlledCurrentSourceProducer(const VoltageControlledCurrentSourceProducer& base) : 41 | ComponentProducer(base) 42 | { 43 | type = base.type; 44 | num_parameters = base.num_parameters; 45 | num_terminals = base.num_terminals; 46 | } 47 | 48 | VoltageControlledCurrentSourceProducer::VoltageControlledCurrentSourceProducer(VoltageControlledCurrentSourceProducer&& base) : 49 | ComponentProducer(base) 50 | { 51 | type = std::move(base.type); 52 | num_parameters = base.num_parameters; 53 | num_terminals = base.num_terminals; 54 | } 55 | 56 | std::unique_ptr VoltageControlledCurrentSourceProducer::operator()(const ComponentListing& component_def) const 57 | { 58 | assertNetlistComponentInstanceValid(component_def); 59 | 60 | VoltageControlledCurrentSource* comp = new VoltageControlledCurrentSource( component_def.getLabel(), component_def.getParameter(0) ); 61 | comp->setTerminalConnections( component_def.getTerminalConnection(0), component_def.getTerminalConnection(1), component_def.getTerminalConnection(2), component_def.getTerminalConnection(3) ); 62 | 63 | return std::unique_ptr(comp); 64 | } 65 | 66 | } //namespace lblmc 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/codegen/netlist/producers/VoltageSourceProducer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2019-2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include 24 | #include "codegen/netlist/producers/VoltageSourceProducer.hpp" 25 | #include "codegen/components/VoltageSource.hpp" 26 | 27 | namespace lblmc 28 | { 29 | 30 | VoltageSourceProducer::VoltageSourceProducer() : 31 | ComponentProducer() 32 | { 33 | type = "VoltageSource"; 34 | producer_name = "VoltageSourceProducer"; 35 | num_parameters = 2; 36 | num_terminals = 2; 37 | } 38 | 39 | VoltageSourceProducer::VoltageSourceProducer(const VoltageSourceProducer& base) : 40 | ComponentProducer(base) 41 | { 42 | type = base.type; 43 | num_parameters = base.num_parameters; 44 | num_terminals = base.num_terminals; 45 | } 46 | 47 | VoltageSourceProducer::VoltageSourceProducer(VoltageSourceProducer&& base) : 48 | ComponentProducer(base) 49 | { 50 | type = std::move(base.type); 51 | num_parameters = base.num_parameters; 52 | num_terminals = base.num_terminals; 53 | } 54 | 55 | std::unique_ptr VoltageSourceProducer::operator()(const ComponentListing& component_def) const 56 | { 57 | assertNetlistComponentInstanceValid(component_def); 58 | 59 | VoltageSource* comp = new VoltageSource( component_def.getLabel(), component_def.getParameter(0), component_def.getParameter(1) ); 60 | comp->setTerminalConnections( component_def.getTerminalConnection(0), component_def.getTerminalConnection(1) ); 61 | 62 | return std::unique_ptr(comp); 63 | } 64 | 65 | } //namespace lblmc 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/codegen/udc/UserDefinedComponentSourceTokenizer.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Copyright (C) 2020 Matthew Milton 5 | 6 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 7 | Open Real-Time Simulation (ORTiS) Framework. 8 | 9 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 21 | 22 | */ 23 | 24 | #include "codegen/udc/UserDefinedComponentSourceTokenizer.hpp" 25 | #include "codegen/Cpp.hpp" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace lblmc 32 | { 33 | 34 | const std::string UserDefinedComponentSourceTokenizer::WHITESPACE_CHARS(Cpp::WHITESPACE_CHARS); 35 | const std::string UserDefinedComponentSourceTokenizer::LABEL_CHARS(Cpp::VALID_NAME_CHARS); 36 | const std::string UserDefinedComponentSourceTokenizer::NUMBER_CHARS(Cpp::VALID_NUMBER_CHARS); 37 | const std::string UserDefinedComponentSourceTokenizer::LEFT_BRACKET_CHARS("({[<"); 38 | const std::string UserDefinedComponentSourceTokenizer::RIGHT_BRACKET_CHARS(")}]>"); 39 | const std::string UserDefinedComponentSourceTokenizer::QUOTE_DELIMITER_CHARS("\"\'"); 40 | const std::string UserDefinedComponentSourceTokenizer::OPERATOR_CHARS("=,."); 41 | const std::string UserDefinedComponentSourceTokenizer::STATEMENT_END_CHARS(";"); 42 | const std::string UserDefinedComponentSourceTokenizer::COMMENT_START_CHARS("//"); 43 | const std::string UserDefinedComponentSourceTokenizer::MACRO_START_CHARS("#"); 44 | 45 | //================================================================================================== 46 | 47 | std::vector 48 | UserDefinedComponentSourceTokenizer::tokenizeStream(std::istream& strm) 49 | { 50 | 51 | } 52 | 53 | std::vector 54 | UserDefinedComponentSourceTokenizer::tokenizeString(const std::string& str) 55 | { 56 | std::vector tokens; 57 | 58 | TokenType last_type = TokenType::TOKEN_UNDEFINED; 59 | 60 | const std::size_t str_size = str.size(); 61 | const static std::size_t npos = std::string::npos; 62 | 63 | std::size_t position = 0; 64 | std::size_t length = 0; 65 | 66 | std::size_t i = 0; 67 | 68 | while(i < str_size) 69 | { 70 | const char ch = str[i]; 71 | 72 | if(WHITESPACE_CHARS.find_first_of(ch) != npos) 73 | { 74 | last_type = TokenType::TOKEN_WHITESPACE; 75 | 76 | tokens.push_back(Token{i, 1, last_type}); 77 | 78 | i++; 79 | continue; 80 | } 81 | 82 | if(LEFT_BRACKET_CHARS.find_first_of(ch) != npos) 83 | { 84 | last_type = TokenType::TOKEN_LEFT_BRACKET; 85 | 86 | tokens.push_back(Token{i, 1, last_type}); 87 | 88 | i++; 89 | continue; 90 | } 91 | 92 | if(RIGHT_BRACKET_CHARS.find_first_of(ch) != npos) 93 | { 94 | last_type = TokenType::TOKEN_RIGHT_BRACKET; 95 | 96 | tokens.push_back(Token{i, 1, last_type}); 97 | 98 | i++; 99 | continue; 100 | } 101 | 102 | if(OPERATOR_CHARS.find_first_of(ch) != npos) 103 | { 104 | last_type = TokenType::TOKEN_OPERATOR; 105 | 106 | tokens.push_back(Token{i, 1, last_type}); 107 | 108 | i++; 109 | continue; 110 | } 111 | 112 | // !!! FINISH ME !!! 2020-07-19-18.21 113 | } 114 | 115 | return tokens; 116 | } 117 | 118 | std::vector 119 | UserDefinedComponentSourceTokenizer::tokenizeFile(const std::string& file) 120 | { 121 | 122 | } 123 | 124 | } //namespace lblmc 125 | -------------------------------------------------------------------------------- /src/exprpar/ExpressionConstants.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include "exprpar/ExpressionConstants.hpp" 24 | 25 | namespace ortis 26 | { 27 | 28 | namespace ExpressionConstants 29 | { 30 | 31 | const std::string OPERATOR_UNARY_PLUS_SYMBOL("u+"); 32 | const std::string OPERATOR_BINARY_PLUS_SYMBOL("+"); 33 | const std::string OPERATOR_UNARY_MINUS_SYMBOL("u-"); 34 | const std::string OPERATOR_BINARY_MINUS_SYMBOL("-"); 35 | const std::string OPERATOR_MULTIPLY_SYMBOL("*"); 36 | const std::string OPERATOR_DIVIDE_SYMBOL("/"); 37 | const std::string OPERATOR_ASSIGNMENT_SYMBOL("="); 38 | 39 | const std::string BRACKET_LEFT_SYMBOL("("); 40 | const std::string BRACKET_RIGHT_SYMBOL(")"); 41 | 42 | const std::string STATEMENT_END_SYMBOL(";"); 43 | 44 | } //namespace ExpressionConstants 45 | 46 | } //namespace ortis 47 | -------------------------------------------------------------------------------- /src/exprpar/ExpressionNode.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include "exprpar/ExpressionNode.hpp" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace ortis 30 | { 31 | 32 | ExpressionNode::ExpressionNode 33 | ( 34 | const ExpressionToken& token, 35 | std::unique_ptr left_node, 36 | std::unique_ptr right_node 37 | ) : 38 | token(token), 39 | left_node(std::move(left_node)), 40 | right_node(std::move(right_node)) 41 | {} 42 | 43 | ExpressionNode::ExpressionNode(ExpressionNode&& base) : 44 | token(std::move(base.token)), 45 | left_node(std::move(base.left_node)), 46 | right_node(std::move(base.right_node)) 47 | {} 48 | 49 | ExpressionNode& 50 | ExpressionNode::operator=(ExpressionNode&& base) 51 | { 52 | token = std::move(base.token); 53 | left_node = std::move(base.left_node); 54 | right_node = std::move(base.right_node); 55 | 56 | return *this; 57 | } 58 | 59 | std::string 60 | ExpressionNode::asString() const 61 | { 62 | std::stringstream sstrm; 63 | 64 | sstrm << 65 | token.getSymbol(); 66 | 67 | if(token.getType() == ExpressionToken::VALUE) 68 | { 69 | return sstrm.str(); 70 | } 71 | 72 | if(token.getType() == ExpressionToken::OPERATOR) 73 | { 74 | sstrm << 75 | "(" << 76 | ( (left_node) ? left_node->asString() : "" ) << 77 | ( (right_node) ? ", "+ right_node->asString() : "" ) << 78 | ")"; 79 | } 80 | 81 | return sstrm.str(); 82 | 83 | } 84 | 85 | void 86 | ExpressionNode::setToken(const ExpressionToken& token) 87 | { 88 | this->token = token; 89 | } 90 | 91 | void 92 | ExpressionNode::setToken(ExpressionToken&& token) 93 | { 94 | this->token = token; 95 | } 96 | 97 | ExpressionToken& 98 | ExpressionNode::getToken() 99 | { 100 | return token; 101 | } 102 | 103 | 104 | const ExpressionToken& 105 | ExpressionNode::getToken() const 106 | { 107 | return token; 108 | } 109 | 110 | void 111 | ExpressionNode::setLeftNode(std::unique_ptr node) 112 | { 113 | if(!node) 114 | { 115 | throw 116 | std::invalid_argument 117 | ( 118 | "void ExpressionNode::setLeftNode(std::unique_ptr node) -- node cannot be null" 119 | ); 120 | } 121 | 122 | left_node = std::move(node); 123 | } 124 | 125 | ExpressionNode* 126 | ExpressionNode::getLeftNode() 127 | { 128 | return left_node.get(); 129 | } 130 | 131 | const ExpressionNode* 132 | ExpressionNode::getLeftNode() const 133 | { 134 | return left_node.get(); 135 | } 136 | 137 | void 138 | ExpressionNode::setRightNode(std::unique_ptr node) 139 | { 140 | if(!node) 141 | { 142 | throw 143 | std::invalid_argument 144 | ( 145 | "void ExpressionNode::setRightNode(std::unique_ptr node) -- node cannot be null" 146 | ); 147 | } 148 | 149 | right_node = std::move(node); 150 | } 151 | 152 | ExpressionNode* 153 | ExpressionNode::getRightNode() 154 | { 155 | return right_node.get(); 156 | } 157 | 158 | const ExpressionNode* 159 | ExpressionNode::getRightNode() const 160 | { 161 | return right_node.get(); 162 | } 163 | 164 | } //namespace ortis 165 | -------------------------------------------------------------------------------- /src/exprpar/ExpressionSymbolTable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include "exprpar/ExpressionSymbolTable.hpp" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace ortis 31 | { 32 | 33 | ExpressionSymbolTable::ExpressionSymbolTable() 34 | : symbol_value_assignments() 35 | {} 36 | 37 | ExpressionSymbolTable::ExpressionSymbolTable 38 | ( 39 | std::map&& symbol_value_assignments 40 | ) 41 | : symbol_value_assignments(std::move(symbol_value_assignments)) 42 | {} 43 | 44 | ExpressionSymbolTable::ExpressionSymbolTable(const ExpressionSymbolTable& base) 45 | : symbol_value_assignments(base.symbol_value_assignments) 46 | {} 47 | 48 | ExpressionSymbolTable::ExpressionSymbolTable(ExpressionSymbolTable&& base) 49 | : symbol_value_assignments(std::move(base.symbol_value_assignments)) 50 | {} 51 | 52 | void 53 | ExpressionSymbolTable::addSymbol(const std::string& symbol, double value) 54 | { 55 | if(symbol.empty()) 56 | { 57 | throw 58 | std::invalid_argument 59 | ( 60 | "ExpressionSymbolTable::addSymbol(const std::string& symbol, double value) --" 61 | "symbol cannot be empty" 62 | ); 63 | } 64 | 65 | symbol_value_assignments[symbol] = value; 66 | } 67 | 68 | void 69 | ExpressionSymbolTable::addSymbol(const SymbolValuePair& symbol_value) 70 | { 71 | if(symbol_value.first.empty()) 72 | { 73 | throw 74 | std::invalid_argument 75 | ( 76 | "ExpressionSymbolTable::addSymbol(const SymbolValuePair& symbol_value) --" 77 | "symbol cannot be empty" 78 | ); 79 | } 80 | 81 | symbol_value_assignments[symbol_value.first] = symbol_value.second; 82 | } 83 | 84 | double 85 | ExpressionSymbolTable::getSymbolValue(const std::string& symbol) const 86 | { 87 | try 88 | { 89 | return symbol_value_assignments.at(symbol); 90 | } 91 | catch(const std::out_of_range& error) 92 | { 93 | throw 94 | std::out_of_range 95 | ( 96 | std::string("ExpressionSymbolTable::getSymbolValue(const std::string& symbol) const --") 97 | + error.what() 98 | ); 99 | } 100 | } 101 | 102 | double 103 | ExpressionSymbolTable::getSymbolValue 104 | ( 105 | const std::string& symbol, 106 | const SymbolValueMap& symbol_value_map 107 | ) 108 | { 109 | try 110 | { 111 | return symbol_value_map.at(symbol); 112 | } 113 | catch(const std::out_of_range& error) 114 | { 115 | throw 116 | std::out_of_range 117 | ( 118 | std::string("ExpressionSymbolTable::getSymbolValue(const std::string& symbol) const --") 119 | + error.what() 120 | ); 121 | } 122 | } 123 | 124 | bool 125 | ExpressionSymbolTable::containsSymbol(const std::string& symbol) const 126 | { 127 | return ( symbol_value_assignments.count(symbol) != 0 ); 128 | } 129 | 130 | bool 131 | ExpressionSymbolTable::containsSymbol 132 | ( 133 | const std::string& symbol, 134 | const SymbolValueMap& symbol_value_map 135 | ) 136 | { 137 | return ( symbol_value_map.count(symbol) != 0 ); 138 | } 139 | 140 | const double* 141 | ExpressionSymbolTable::findSymbolValue(const std::string& symbol) const 142 | { 143 | if(symbol_value_assignments.count(symbol) == 0) 144 | { 145 | return nullptr; 146 | } 147 | 148 | return &(symbol_value_assignments.at(symbol)); 149 | } 150 | 151 | const double* 152 | ExpressionSymbolTable::findSymbolValue(const std::string& symbol, const SymbolValueMap& symbol_value_map) 153 | { 154 | if(symbol_value_map.count(symbol) == 0) 155 | { 156 | return nullptr; 157 | } 158 | 159 | return &(symbol_value_map.at(symbol)); 160 | } 161 | 162 | } //namespace ortis 163 | -------------------------------------------------------------------------------- /src/exprpar/ExpressionToken.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2020 Matthew Milton 4 | 5 | This file is part of the LB-LMC Solver C++ Code Generation Library, included in the 6 | Open Real-Time Simulation (ORTiS) Framework. 7 | 8 | LB-LMC Solver C++ Code Generation Library is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | LB-LMC Solver C++ Code Generation Library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with LB-LMC Solver C++ Code Generation Library. If not, see . 20 | 21 | */ 22 | 23 | #include "exprpar/ExpressionToken.hpp" 24 | 25 | #include 26 | #include 27 | 28 | namespace ortis 29 | { 30 | 31 | ExpressionToken::ExpressionToken 32 | ( 33 | ExpressionToken::Type type, 34 | const std::string& symbol, 35 | unsigned char precedence, 36 | unsigned char num_operands 37 | ) : 38 | type(type), 39 | symbol(symbol), 40 | precedence(precedence), 41 | num_operands(num_operands) 42 | {} 43 | 44 | ExpressionToken::ExpressionToken(const ExpressionToken& base) : 45 | type(base.type), 46 | symbol(base.symbol), 47 | precedence(base.precedence), 48 | num_operands(base.num_operands) 49 | {} 50 | 51 | ExpressionToken::ExpressionToken(ExpressionToken&& base) : 52 | type(std::move(base.type)), 53 | symbol(std::move(base.symbol)), 54 | precedence(std::move(base.precedence)), 55 | num_operands(std::move(base.num_operands)) 56 | {} 57 | 58 | ExpressionToken& 59 | ExpressionToken::operator=(const ExpressionToken& base) 60 | { 61 | type = base.type; 62 | symbol = base.symbol; 63 | precedence = base.precedence; 64 | num_operands = base.num_operands; 65 | 66 | return *this; 67 | } 68 | 69 | ExpressionToken& 70 | ExpressionToken::operator=(ExpressionToken&& base) 71 | { 72 | type = std::move(base.type); 73 | symbol = std::move(base.symbol); 74 | precedence = std::move(base.precedence); 75 | num_operands = std::move(base.num_operands); 76 | 77 | return *this; 78 | } 79 | 80 | void 81 | ExpressionToken::setType(ExpressionToken::Type type) 82 | { 83 | this->type = type; 84 | } 85 | 86 | const ExpressionToken::Type& 87 | ExpressionToken::getType() const 88 | { 89 | return type; 90 | } 91 | 92 | void 93 | ExpressionToken::setSymbol(const std::string& sym) 94 | { 95 | symbol = sym; 96 | } 97 | 98 | void 99 | ExpressionToken::setSymbol(std::string&& sym) 100 | { 101 | symbol = std::move(sym); 102 | } 103 | 104 | const std::string& 105 | ExpressionToken::getSymbol() const 106 | { 107 | return symbol; 108 | } 109 | 110 | void 111 | ExpressionToken::setPrecedence(unsigned char precedence) 112 | { 113 | this->precedence = precedence; 114 | } 115 | 116 | const unsigned char& 117 | ExpressionToken::getPrecedence() const 118 | { 119 | return precedence; 120 | } 121 | 122 | void 123 | ExpressionToken::setNumberOfOperands(unsigned char num_operands) 124 | { 125 | this->num_operands = num_operands; 126 | } 127 | 128 | const unsigned char& 129 | ExpressionToken::getNumberOfOperands() const 130 | { 131 | return num_operands; 132 | } 133 | 134 | bool 135 | ExpressionToken::hasEqualPrecedence(const ExpressionToken& token) 136 | { 137 | return precedence == token.precedence; 138 | } 139 | 140 | bool 141 | ExpressionToken::hasEqualPrecedence(unsigned char precedence) 142 | { 143 | return this->precedence == precedence; 144 | } 145 | 146 | bool 147 | ExpressionToken::hasHigherPrecedence(const ExpressionToken& token) 148 | { 149 | return precedence > token.precedence; 150 | } 151 | 152 | bool 153 | ExpressionToken::hasHigherPrecedence(unsigned char precedence) 154 | { 155 | return this->precedence > precedence; 156 | } 157 | 158 | } //namespace ortis 159 | --------------------------------------------------------------------------------