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