KiCad PCB EDA Suite
ngspice.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016-2018 CERN
5  * Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  * @author Maciej Suminski <maciej.suminski@cern.ch>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 3
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * https://www.gnu.org/licenses/gpl-3.0.html
23  * or you may search the http://www.gnu.org website for the version 3 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <config.h> // Needed for MSW compilation
29 #include <wx/log.h>
30 
31 #include "ngspice.h"
32 #include "spice_reporter.h"
33 #include "spice_settings.h"
34 
35 #include <common.h>
36 #include <locale_io.h>
37 
38 #include <paths.h>
39 
40 #include <wx/stdpaths.h>
41 #include <wx/dir.h>
42 
43 #include <stdexcept>
44 
45 #include <algorithm>
46 
47 using namespace std;
48 
49 
57 static const wxChar* const traceNgspice = wxT( "KICAD_NGSPICE" );
58 
59 
61  m_ngSpice_Init( nullptr ),
62  m_ngSpice_Circ( nullptr ),
63  m_ngSpice_Command( nullptr ),
64  m_ngGet_Vec_Info( nullptr ),
65  m_ngSpice_CurPlot( nullptr ),
66  m_ngSpice_AllPlots( nullptr ),
67  m_ngSpice_AllVecs( nullptr ),
68  m_ngSpice_Running( nullptr ),
69  m_error( false )
70 {
71  init_dll();
72 }
73 
74 
76 {
77 }
78 
79 
80 void NGSPICE::Init( const SPICE_SIMULATOR_SETTINGS* aSettings )
81 {
82  Command( "reset" );
83 
84  for( const std::string& command : GetSettingCommands() )
85  {
86  wxLogTrace( traceNgspice, "Sending Ngspice configuration command '%s'.", command );
87  Command( command );
88  }
89 }
90 
91 
92 vector<string> NGSPICE::AllPlots() const
93 {
94  LOCALE_IO c_locale; // ngspice works correctly only with C locale
95  char* currentPlot = m_ngSpice_CurPlot();
96  char** allPlots = m_ngSpice_AllVecs( currentPlot );
97  int noOfPlots = 0;
98 
99  vector<string> retVal;
100 
101  if( allPlots != nullptr )
102  {
103  for( char** plot = allPlots; *plot != nullptr; plot++ )
104  noOfPlots++;
105 
106  retVal.reserve( noOfPlots );
107 
108  for( int i = 0; i < noOfPlots; i++, allPlots++ )
109  {
110  string vec = *allPlots;
111  retVal.push_back( vec );
112  }
113  }
114 
115 
116  return retVal;
117 }
118 
119 
120 vector<COMPLEX> NGSPICE::GetPlot( const string& aName, int aMaxLen )
121 {
122  LOCALE_IO c_locale; // ngspice works correctly only with C locale
123  vector<COMPLEX> data;
124  vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
125 
126  if( vi )
127  {
128  int length = aMaxLen < 0 ? vi->v_length : std::min( aMaxLen, vi->v_length );
129  data.reserve( length );
130 
131  if( vi->v_realdata )
132  {
133  for( int i = 0; i < length; i++ )
134  data.emplace_back( vi->v_realdata[i], 0.0 );
135  }
136  else if( vi->v_compdata )
137  {
138  for( int i = 0; i < length; i++ )
139  data.emplace_back( vi->v_compdata[i].cx_real, vi->v_compdata[i].cx_imag );
140  }
141  }
142 
143  return data;
144 }
145 
146 
147 vector<double> NGSPICE::GetRealPlot( const string& aName, int aMaxLen )
148 {
149  LOCALE_IO c_locale; // ngspice works correctly only with C locale
150  vector<double> data;
151  vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
152 
153  if( vi )
154  {
155  int length = aMaxLen < 0 ? vi->v_length : std::min( aMaxLen, vi->v_length );
156  data.reserve( length );
157 
158  if( vi->v_realdata )
159  {
160  for( int i = 0; i < length; i++ )
161  {
162  data.push_back( vi->v_realdata[i] );
163  }
164  }
165  else if( vi->v_compdata )
166  {
167  for( int i = 0; i < length; i++ )
168  {
169  wxASSERT( vi->v_compdata[i].cx_imag == 0.0 );
170  data.push_back( vi->v_compdata[i].cx_real );
171  }
172  }
173  }
174 
175  return data;
176 }
177 
178 
179 vector<double> NGSPICE::GetImagPlot( const string& aName, int aMaxLen )
180 {
181  LOCALE_IO c_locale; // ngspice works correctly only with C locale
182  vector<double> data;
183  vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
184 
185  if( vi )
186  {
187  int length = aMaxLen < 0 ? vi->v_length : std::min( aMaxLen, vi->v_length );
188  data.reserve( length );
189 
190  if( vi->v_compdata )
191  {
192  for( int i = 0; i < length; i++ )
193  {
194  data.push_back( vi->v_compdata[i].cx_imag );
195  }
196  }
197  }
198 
199  return data;
200 }
201 
202 
203 vector<double> NGSPICE::GetMagPlot( const string& aName, int aMaxLen )
204 {
205  LOCALE_IO c_locale; // ngspice works correctly only with C locale
206  vector<double> data;
207  vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
208 
209  if( vi )
210  {
211  int length = aMaxLen < 0 ? vi->v_length : std::min( aMaxLen, vi->v_length );
212  data.reserve( length );
213 
214  if( vi->v_realdata )
215  {
216  for( int i = 0; i < length; i++ )
217  data.push_back( vi->v_realdata[i] );
218  }
219  else if( vi->v_compdata )
220  {
221  for( int i = 0; i < length; i++ )
222  data.push_back( hypot( vi->v_compdata[i].cx_real, vi->v_compdata[i].cx_imag ) );
223  }
224  }
225 
226  return data;
227 }
228 
229 
230 vector<double> NGSPICE::GetPhasePlot( const string& aName, int aMaxLen )
231 {
232  LOCALE_IO c_locale; // ngspice works correctly only with C locale
233  vector<double> data;
234  vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
235 
236  if( vi )
237  {
238  int length = aMaxLen < 0 ? vi->v_length : std::min( aMaxLen, vi->v_length );
239  data.reserve( length );
240 
241  if( vi->v_realdata )
242  {
243  for( int i = 0; i < length; i++ )
244  data.push_back( 0.0 ); // well, that's life
245  }
246  else if( vi->v_compdata )
247  {
248  for( int i = 0; i < length; i++ )
249  data.push_back( atan2( vi->v_compdata[i].cx_imag, vi->v_compdata[i].cx_real ) );
250  }
251  }
252 
253  return data;
254 }
255 
256 
257 bool NGSPICE::LoadNetlist( const string& aNetlist )
258 {
259  LOCALE_IO c_locale; // ngspice works correctly only with C locale
260  vector<char*> lines;
261  stringstream ss( aNetlist );
262 
263  m_netlist = "";
264 
265  while( !ss.eof() )
266  {
267  char line[1024];
268  ss.getline( line, sizeof( line ) );
269  lines.push_back( strdup( line ) );
270  m_netlist += std::string( line ) + std::string( "\n" );
271  }
272 
273  lines.push_back( nullptr ); // sentinel, as requested in ngSpice_Circ description
274  m_ngSpice_Circ( lines.data() );
275 
276  for( auto line : lines )
277  free( line );
278 
279  return true;
280 }
281 
282 
284 {
285  LOCALE_IO c_locale; // ngspice works correctly only with C locale
286  return Command( "bg_run" ); // bg_* commands execute in a separate thread
287 }
288 
289 
291 {
292  LOCALE_IO c_locale; // ngspice works correctly only with C locale
293  return Command( "bg_halt" ); // bg_* commands execute in a separate thread
294 }
295 
296 
298 {
299  LOCALE_IO c_locale; // ngspice works correctly only with C locale
300  return m_ngSpice_Running();
301 }
302 
303 
304 bool NGSPICE::Command( const string& aCmd )
305 {
306  LOCALE_IO c_locale; // ngspice works correctly only with C locale
307  validate();
308  m_ngSpice_Command( (char*) aCmd.c_str() );
309  return true;
310 }
311 
312 
313 string NGSPICE::GetXAxis( SIM_TYPE aType ) const
314 {
315  switch( aType )
316  {
317  case ST_AC:
318  case ST_NOISE:
319  return string( "frequency" );
320 
321  case ST_DC:
322  // find plot, which ends with "-sweep"
323  for( auto& plot : AllPlots() )
324  {
325  const string sweepEnding = "-sweep";
326  unsigned int len = sweepEnding.length();
327 
328  if( plot.length() > len
329  && plot.substr( plot.length() - len, len ).compare( sweepEnding ) == 0 )
330  {
331  return string( plot );
332  }
333  }
334  break;
335 
336  case ST_TRANSIENT:
337  return string( "time" );
338 
339  default:
340  break;
341  }
342 
343  return string( "" );
344 }
345 
346 
347 std::vector<std::string> NGSPICE::GetSettingCommands() const
348 {
349  const NGSPICE_SIMULATOR_SETTINGS* settings =
350  dynamic_cast<const NGSPICE_SIMULATOR_SETTINGS*>( Settings().get() );
351 
352  std::vector<std::string> commands;
353 
354  wxCHECK( settings, commands );
355 
356  switch( settings->GetModelMode() )
357  {
359  break;
360 
362  commands.emplace_back( "unset ngbehavior" );
363  break;
364 
366  commands.emplace_back( "set ngbehavior=ps" );
367  break;
368 
370  commands.emplace_back( "set ngbehavior=lt" );
371  break;
372 
374  commands.emplace_back( "set ngbehavior=ltps" );
375  break;
376 
378  commands.emplace_back( "set ngbehavior=hs" );
379  break;
380 
381  default:
382  wxFAIL_MSG( wxString::Format( "Undefined NGSPICE_MODEL_MODE %d.",
383  settings->GetModelMode() ) );
384  break;
385  }
386 
387  return commands;
388 }
389 
390 
391 const std::string NGSPICE::GetNetlist() const
392 {
393  return m_netlist;
394 }
395 
396 
398 {
399  if( m_initialized )
400  return;
401 
402  LOCALE_IO c_locale; // ngspice works correctly only with C locale
403  const wxStandardPaths& stdPaths = wxStandardPaths::Get();
404 
405  if( m_dll.IsLoaded() ) // enable force reload
406  m_dll.Unload();
407 
408  // Extra effort to find libngspice
409  // @todo Shouldn't we be using the normal KiCad path searching mechanism here?
410  wxFileName dllFile( "", NGSPICE_DLL_FILE );
411 #if defined(__WINDOWS__)
412  #if defined( _MSC_VER )
413  const vector<string> dllPaths = { "" };
414  #else
415  const vector<string> dllPaths = { "", "/mingw64/bin", "/mingw32/bin" };
416  #endif
417 #elif defined(__WXMAC__)
418  const vector<string> dllPaths = {
419  PATHS::GetOSXKicadUserDataDir().ToStdString() + "/PlugIns/ngspice",
420  PATHS::GetOSXKicadMachineDataDir().ToStdString() + "/PlugIns/ngspice",
421 
422  // when running kicad.app
423  stdPaths.GetPluginsDir().ToStdString() + "/sim",
424 
425  // when running eeschema.app
426  wxFileName( stdPaths.GetExecutablePath() ).GetPath().ToStdString() +
427  "/../../../../../Contents/PlugIns/sim"
428  };
429 #else // Unix systems
430  const vector<string> dllPaths = { "/usr/local/lib" };
431 #endif
432 
433 #if defined(__WINDOWS__) || (__WXMAC__)
434  for( const auto& path : dllPaths )
435  {
436  dllFile.SetPath( path );
437  wxLogTrace( traceNgspice, "libngspice search path: %s", dllFile.GetFullPath() );
438  m_dll.Load( dllFile.GetFullPath(), wxDL_VERBATIM | wxDL_QUIET | wxDL_NOW );
439 
440  if( m_dll.IsLoaded() )
441  {
442  wxLogTrace( traceNgspice, "libngspice path found in: %s", dllFile.GetFullPath() );
443  break;
444  }
445  }
446 
447  if( !m_dll.IsLoaded() ) // try also the system libraries
448  m_dll.Load( wxDynamicLibrary::CanonicalizeName( "ngspice" ) );
449 #else
450  // First, try the system libraries
451  m_dll.Load( NGSPICE_DLL_FILE, wxDL_VERBATIM | wxDL_QUIET | wxDL_NOW );
452 
453  // If failed, try some other paths:
454  if( !m_dll.IsLoaded() )
455  {
456  for( const auto& path : dllPaths )
457  {
458  dllFile.SetPath( path );
459  wxLogTrace( traceNgspice, "libngspice search path: %s", dllFile.GetFullPath() );
460  m_dll.Load( dllFile.GetFullPath(), wxDL_VERBATIM | wxDL_QUIET | wxDL_NOW );
461 
462  if( m_dll.IsLoaded() )
463  {
464  wxLogTrace( traceNgspice, "libngspice path found in: %s", dllFile.GetFullPath() );
465  break;
466  }
467  }
468  }
469 #endif
470 
471  if( !m_dll.IsLoaded() )
472  throw std::runtime_error( "Missing ngspice shared library" );
473 
474  m_error = false;
475 
476  // Obtain function pointers
477  m_ngSpice_Init = (ngSpice_Init) m_dll.GetSymbol( "ngSpice_Init" );
478  m_ngSpice_Circ = (ngSpice_Circ) m_dll.GetSymbol( "ngSpice_Circ" );
479  m_ngSpice_Command = (ngSpice_Command) m_dll.GetSymbol( "ngSpice_Command" );
480  m_ngGet_Vec_Info = (ngGet_Vec_Info) m_dll.GetSymbol( "ngGet_Vec_Info" );
481  m_ngSpice_CurPlot = (ngSpice_CurPlot) m_dll.GetSymbol( "ngSpice_CurPlot" );
482  m_ngSpice_AllPlots = (ngSpice_AllPlots) m_dll.GetSymbol( "ngSpice_AllPlots" );
483  m_ngSpice_AllVecs = (ngSpice_AllVecs) m_dll.GetSymbol( "ngSpice_AllVecs" );
484  m_ngSpice_Running = (ngSpice_Running) m_dll.GetSymbol( "ngSpice_running" ); // it is not a typo
485 
487  &cbBGThreadRunning, this );
488 
489  // Load a custom spinit file, to fix the problem with loading .cm files
490  // Switch to the executable directory, so the relative paths are correct
491  wxString cwd( wxGetCwd() );
492  wxFileName exeDir( stdPaths.GetExecutablePath() );
493  wxSetWorkingDirectory( exeDir.GetPath() );
494 
495  // Find *.cm files
496  string cmPath = findCmPath();
497 
498  // __CMPATH is used in custom spinit file to point to the codemodels directory
499  if( !cmPath.empty() )
500  Command( "set __CMPATH=\"" + cmPath + "\"" );
501 
502  // Possible relative locations for spinit file
503  const vector<string> spiceinitPaths =
504  {
505  ".",
506 #ifdef __WXMAC__
507  stdPaths.GetPluginsDir().ToStdString() + "/sim/ngspice/scripts",
508  wxFileName( stdPaths.GetExecutablePath() ).GetPath().ToStdString() +
509  "/../../../../../Contents/PlugIns/sim/ngspice/scripts"
510 #endif
511  "../share/kicad",
512  "../share",
513  "../../share/kicad",
514  "../../share"
515  };
516 
517  bool foundSpiceinit = false;
518 
519  for( const auto& path : spiceinitPaths )
520  {
521  wxLogTrace( traceNgspice, "ngspice init script search path: %s", path );
522 
523  if( loadSpinit( path + "/spiceinit" ) )
524  {
525  wxLogTrace( traceNgspice, "ngspice path found in: %s", path );
526  foundSpiceinit = true;
527  break;
528  }
529  }
530 
531  // Last chance to load codemodel files, we have not found
532  // spiceinit file, but we know the path to *.cm files
533  if( !foundSpiceinit && !cmPath.empty() )
534  loadCodemodels( cmPath );
535 
536  // Restore the working directory
537  wxSetWorkingDirectory( cwd );
538 
539  // Workarounds to avoid hang ups on certain errors
540  // These commands have to be called, no matter what is in the spinit file
541  Command( "unset interactive" );
542  Command( "set noaskquit" );
543  Command( "set nomoremode" );
544 
545  m_initialized = true;
546 }
547 
548 
549 bool NGSPICE::loadSpinit( const string& aFileName )
550 {
551  if( !wxFileName::FileExists( aFileName ) )
552  return false;
553 
554  wxTextFile file;
555 
556  if( !file.Open( aFileName ) )
557  return false;
558 
559  for( auto cmd = file.GetFirstLine(); !file.Eof(); cmd = file.GetNextLine() )
560  Command( cmd.ToStdString() );
561 
562  return true;
563 }
564 
565 
566 string NGSPICE::findCmPath() const
567 {
568  const vector<string> cmPaths =
569  {
570 #ifdef __WXMAC__
571  "/Applications/ngspice/lib/ngspice",
572  "Contents/Frameworks",
573  wxStandardPaths::Get().GetPluginsDir().ToStdString() + "/sim/ngspice",
574  wxFileName( wxStandardPaths::Get().GetExecutablePath() ).GetPath().ToStdString() +
575  "/../../../../../Contents/PlugIns/sim/ngspice",
576  "../Plugins/sim/ngspice",
577 #endif
578  "../lib/ngspice",
579  "../../lib/ngspice",
580  "lib/ngspice",
581  "ngspice"
582  };
583 
584  for( const auto& path : cmPaths )
585  {
586  wxLogTrace( traceNgspice, "ngspice code models search path: %s", path );
587 
588  if( wxFileName::FileExists( path + "/spice2poly.cm" ) )
589  {
590  wxLogTrace( traceNgspice, "ngspice code models found in: %s", path );
591  return path;
592  }
593  }
594 
595  return string();
596 }
597 
598 
599 bool NGSPICE::loadCodemodels( const string& aPath )
600 {
601  wxArrayString cmFiles;
602  size_t count = wxDir::GetAllFiles( aPath, &cmFiles );
603 
604  for( const auto& cm : cmFiles )
605  Command( "codemodel " + cm.ToStdString() );
606 
607  return count != 0;
608 }
609 
610 
611 int NGSPICE::cbSendChar( char* what, int id, void* user )
612 {
613  NGSPICE* sim = reinterpret_cast<NGSPICE*>( user );
614 
615  if( sim->m_reporter )
616  {
617  // strip stdout/stderr from the line
618  if( ( strncasecmp( what, "stdout ", 7 ) == 0 )
619  || ( strncasecmp( what, "stderr ", 7 ) == 0 ) )
620  what += 7;
621 
622  sim->m_reporter->Report( what );
623  }
624 
625  return 0;
626 }
627 
628 
629 int NGSPICE::cbSendStat( char* what, int id, void* user )
630 {
631  return 0;
632 }
633 
634 
635 int NGSPICE::cbBGThreadRunning( bool is_running, int id, void* user )
636 {
637  NGSPICE* sim = reinterpret_cast<NGSPICE*>( user );
638 
639  if( sim->m_reporter )
640  // I know the test below seems like an error, but well, it works somehow..
641  sim->m_reporter->OnSimStateChange( sim, is_running ? SIM_IDLE : SIM_RUNNING );
642 
643  return 0;
644 }
645 
646 
647 int NGSPICE::cbControlledExit( int status, bool immediate, bool exit_upon_quit, int id, void* user )
648 {
649  // Something went wrong, reload the dll
650  NGSPICE* sim = reinterpret_cast<NGSPICE*>( user );
651  sim->m_error = true;
652 
653  return 0;
654 }
655 
656 
658 {
659  if( m_error )
660  {
661  m_initialized = false;
662  init_dll();
663  }
664 }
665 
666 
667 bool NGSPICE::m_initialized = false;
std::vector< std::string > AllPlots() const override
Return a requested vector with complex values.
Definition: ngspice.cpp:92
virtual ~NGSPICE()
Definition: ngspice.cpp:75
bool Run() override
Halt the simulation.
Definition: ngspice.cpp:283
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
static int cbBGThreadRunning(bool is_running, int id, void *user)
Definition: ngspice.cpp:635
void validate()
Error flag indicating that ngspice needs to be reloaded.
Definition: ngspice.cpp:657
static const wxChar *const traceNgspice
Flag to enable debug output of Ngspice simulator.
Definition: ngspice.cpp:57
std::string findCmPath() const
Load codemodel files from a directory.
Definition: ngspice.cpp:566
SPICE_REPORTER * m_reporter
< Reporter object to receive simulation log.
std::shared_ptr< SPICE_SIMULATOR_SETTINGS > & Settings()
Return the simulator configuration settings.
Definition: bitmap.cpp:63
std::vector< double > GetRealPlot(const std::string &aName, int aMaxLen=-1) override
Return a requested vector with imaginary values.
Definition: ngspice.cpp:147
static int cbControlledExit(int status, bool immediate, bool exit_upon_quit, int id, void *user)
Definition: ngspice.cpp:647
char **(* ngSpice_AllVecs)(char *plotname)
Definition: ngspice.h:101
static int cbSendChar(char *what, int id, void *user)
Definition: ngspice.cpp:611
wxDynamicLibrary m_dll
Execute commands from a file.
Definition: ngspice.h:114
bool loadCodemodels(const std::string &aPath)
Definition: ngspice.cpp:599
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
std::vector< double > GetImagPlot(const std::string &aName, int aMaxLen=-1) override
Return a requested vector with magnitude values.
Definition: ngspice.cpp:179
ngSpice_Running m_ngSpice_Running
Definition: ngspice.h:112
std::vector< double > GetMagPlot(const std::string &aName, int aMaxLen=-1) override
Return a requested vector with phase values.
Definition: ngspice.cpp:203
static bool m_initialized
current netlist
Definition: ngspice.h:139
void(* ngSpice_Init)(SendChar *, SendStat *, ControlledExit *, SendData *, SendInitData *, BGThreadRunning *, void *)
Definition: ngspice.h:94
virtual const std::string GetNetlist() const override
Return current SPICE netlist used by the simulator.
Definition: ngspice.cpp:391
#define NULL
NGSPICE()
Definition: ngspice.cpp:60
ngGet_Vec_Info m_ngGet_Vec_Info
Definition: ngspice.h:108
bool m_error
Ngspice should be initialized only once.
Definition: ngspice.h:136
void init_dll()
Definition: ngspice.cpp:397
SIM_TYPE
< Possible simulation types
Definition: sim_types.h:31
pvector_info(* ngGet_Vec_Info)(char *vecname)
Definition: ngspice.h:98
char *(* ngSpice_CurPlot)(void)
Definition: ngspice.h:99
std::vector< COMPLEX > GetPlot(const std::string &aName, int aMaxLen=-1) override
Return a requested vector with real values.
Definition: ngspice.cpp:120
bool Stop() override
Check if simulation is running at the moment.
Definition: ngspice.cpp:290
ngSpice_Init m_ngSpice_Init
Definition: ngspice.h:105
std::string GetXAxis(SIM_TYPE aType) const override
Return a list with all vectors generated in current simulation.
Definition: ngspice.cpp:313
std::vector< double > GetPhasePlot(const std::string &aName, int aMaxLen=-1) override
Return a requested vector with phase values.
Definition: ngspice.cpp:230
int(* ngSpice_Command)(char *command)
Definition: ngspice.h:97
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void Init(const SPICE_SIMULATOR_SETTINGS *aSettings=nullptr) override
Load a netlist for the simulation.
Definition: ngspice.cpp:80
NGSPICE_MODEL_MODE GetModelMode() const
bool LoadNetlist(const std::string &aNetlist) override
Execute the simulation with currently loaded netlist.
Definition: ngspice.cpp:257
bool(* ngSpice_Running)(void)
Handle to DLL functions.
Definition: ngspice.h:102
Container for Ngspice simulator settings.
bool Command(const std::string &aCmd) override
Set a SPICE_REPORTER object to receive the simulation log.
Definition: ngspice.cpp:304
bool IsRunning() override
Execute a Spice command as if it was typed into console.
Definition: ngspice.cpp:297
ngSpice_AllVecs m_ngSpice_AllVecs
Definition: ngspice.h:111
std::vector< std::string > GetSettingCommands() const override
Return current SPICE netlist used by the simulator.
Definition: ngspice.cpp:347
The common library.
virtual void OnSimStateChange(SPICE_SIMULATOR *aObject, SIM_STATE aNewState)=0
ngSpice_Command m_ngSpice_Command
Definition: ngspice.h:107
std::string m_netlist
Definition: ngspice.h:142
bool loadSpinit(const std::string &aFileName)
Check a few different locations for codemodel files and returns one if it exists.
Definition: ngspice.cpp:549
ngSpice_Circ m_ngSpice_Circ
Definition: ngspice.h:106
ngSpice_CurPlot m_ngSpice_CurPlot
Definition: ngspice.h:109
ngSpice_AllPlots m_ngSpice_AllPlots
Definition: ngspice.h:110
static int cbSendStat(char *what, int id, void *user)
Definition: ngspice.cpp:629
char **(* ngSpice_AllPlots)(void)
Definition: ngspice.h:100
int(* ngSpice_Circ)(char **circarray)
Definition: ngspice.h:96
Storage for simulator specific settings.