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