You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
6.2 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 CERN
  5. * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 3
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * https://www.gnu.org/licenses/gpl-3.0.html
  20. * or you may search the http://www.gnu.org website for the version 3 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef SPICE_SIMULATOR_H
  25. #define SPICE_SIMULATOR_H
  26. #include "sim_types.h"
  27. #include <string>
  28. #include <vector>
  29. #include <complex>
  30. #include <memory>
  31. #include <wx/string.h>
  32. class SPICE_REPORTER;
  33. class SPICE_SIMULATOR;
  34. typedef std::complex<double> COMPLEX;
  35. class SPICE_SIMULATOR
  36. {
  37. public:
  38. SPICE_SIMULATOR() : m_reporter( NULL ) {}
  39. virtual ~SPICE_SIMULATOR() {}
  40. ///> Creates a simulator instance of particular type (currently only ngspice is handled)
  41. static std::shared_ptr<SPICE_SIMULATOR> CreateInstance( const std::string& aName );
  42. ///> Initializes the simulator
  43. virtual void Init() = 0;
  44. /*
  45. * @brief Loads a netlist for the simulation.
  46. * @return True in case of success, false otherwise.
  47. */
  48. virtual bool LoadNetlist( const std::string& aNetlist ) = 0;
  49. /**
  50. * @brief Executes the simulation with currently loaded netlist.
  51. * @return True in case of success, false otherwise.
  52. */
  53. virtual bool Run() = 0;
  54. /**
  55. * @brief Halts the simulation.
  56. * @return True in case of success, false otherwise.
  57. */
  58. virtual bool Stop() = 0;
  59. /**
  60. * @brief Checks if simulation is running at the moment.
  61. * @return True if simulation is currently executed.
  62. */
  63. virtual bool IsRunning() = 0;
  64. /**
  65. * @brief Executes a Spice command as if it was typed into console.
  66. * @param aCmd is the command to be issued.
  67. */
  68. virtual bool Command( const std::string& aCmd ) = 0;
  69. ///> Returns X axis name for a given simulation type
  70. virtual std::string GetXAxis( SIM_TYPE aType ) const = 0;
  71. ///> Sets a SPICE_REPORTER object to receive the simulation log.
  72. virtual void SetReporter( SPICE_REPORTER* aReporter )
  73. {
  74. m_reporter = aReporter;
  75. }
  76. /**
  77. * @brief Returns a list with all vectors generated in current simulation.
  78. * @param none
  79. * @return List of vector names. ?May not match to the net name elements.
  80. */
  81. virtual std::vector<std::string> AllPlots() = 0;
  82. /**
  83. * @brief Returns a requested vector with complex values. If the vector is real, then
  84. * the imaginary part is set to 0 in all values.
  85. * @param aName is the vector named in Spice convention (e.g. V(3), I(R1)).
  86. * @param aMaxLen is max count of returned values.
  87. * if -1 (default) all available values are returned.
  88. * @return Requested vector. It might be empty if there is no vector with requested name.
  89. */
  90. virtual std::vector<COMPLEX> GetPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
  91. /**
  92. * @brief Returns a requested vector with real values. If the vector is complex, then
  93. * the real part is returned.
  94. * @param aName is the vector named in Spice convention (e.g. V(3), I(R1)).
  95. * @param aMaxLen is max count of returned values.
  96. * if -1 (default) all available values are returned.
  97. * @return Requested vector. It might be empty if there is no vector with requested name.
  98. */
  99. virtual std::vector<double> GetRealPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
  100. /**
  101. * @brief Returns a requested vector with imaginary values. If the vector is complex, then
  102. * the imaginary part is returned. If the vector is reql, then only zeroes are returned.
  103. * @param aName is the vector named in Spice convention (e.g. V(3), I(R1)).
  104. * @param aMaxLen is max count of returned values.
  105. * if -1 (default) all available values are returned.
  106. * @return Requested vector. It might be empty if there is no vector with requested name.
  107. */
  108. virtual std::vector<double> GetImagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
  109. /**
  110. * @brief Returns a requested vector with magnitude values.
  111. * @param aName is the vector named in Spice convention (e.g. V(3), I(R1)).
  112. * @param aMaxLen is max count of returned values.
  113. * if -1 (default) all available values are returned.
  114. * @return Requested vector. It might be empty if there is no vector with requested name.
  115. */
  116. virtual std::vector<double> GetMagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
  117. /**
  118. * @brief Returns a requested vector with phase values.
  119. * @param aName is the vector named in Spice convention (e.g. V(3), I(R1)).
  120. * @param aMaxLen is max count of returned values.
  121. * if -1 (default) all available values are returned.
  122. * @return Requested vector. It might be empty if there is no vector with requested name.
  123. */
  124. virtual std::vector<double> GetPhasePlot( const std::string& aName, int aMaxLen = -1 ) = 0;
  125. /**
  126. * @brief Returns current SPICE netlist used by the simulator.
  127. * @return The netlist.
  128. */
  129. virtual const std::string GetNetlist() const = 0;
  130. /**
  131. * @brief Returns a string with simulation name based on enum.
  132. * @param aType is the enum describing simulation type
  133. * @param aShortName if true - return is in format "TRAN", "OP".
  134. * if false - return is in format "Transient", "Operating Point".
  135. * @return String with requested name as described above.
  136. */
  137. static wxString TypeToName( SIM_TYPE aType, bool aShortName );
  138. protected:
  139. ///> Reporter object to receive simulation log
  140. SPICE_REPORTER* m_reporter;
  141. };
  142. #endif /* SPICE_SIMULATOR_H */