eisgenerator 1.0.x
Public Member Functions
eis::Model Class Reference

The main class of eisgenerator representing a equivalent circuit model. More...

#include <model.h>

Public Member Functions

 Model (const std::string &str, size_t paramSweepCount=100, bool defaultToRange=true)
 Constructor.
 
 Model (const Model &in)
 
Modeloperator= (const Model &in)
 
size_t setParamSweepCountClosestTotal (size_t totalCount)
 Adjusts the sweep count so that the total of spectra that need to be generated in the parameter sweep is close to the given value.
 
DataPoint execute (fvalue omaga, size_t index=0)
 Gets the impedance at the given frequency this method calls resolveSteps.
 
std::vector< DataPointexecuteSweep (const Range &omega, size_t index=0)
 Executes a frequency sweep along the given range this method calls resolveSteps.
 
std::vector< DataPointexecuteSweep (const std::vector< fvalue > &omega, size_t index=0)
 Executes a frequency sweep with the given omega values.
 
std::vector< std::vector< DataPoint > > executeAllSweeps (const Range &omega)
 Executes a frequency sweep with the given omega values for each parameter combination in the applied parameter sweep this method calls resolveSteps.
 
std::string getModelStr () const
 Returns the model string corresponding to this model object, without embedded parameters.
 
std::string getModelStrWithParam (size_t index)
 Returns the model string corresponding to this model object, with embedded parameters this method calls resolveSteps.
 
std::string getModelStrWithParam () const
 Returns the model string corresponding to this model object, with embedded parameters the parameter sweep index of the last call to resolveSteps or 0 is used.
 
size_t getUuid ()
 Returns a unique id that is unique for this circuit, but not for this object specifically.
 
std::vector< Componant * > getFlatComponants (Componant *model=nullptr)
 Returns a vector of pointers to the circuit elements in this model the pointers can only be assumed to be valid until the next member call to this model object.
 
std::vector< fvalue > getFlatParameters ()
 gets the values of the parameters of the circuit elements at the current parameter sweep step
 
std::vector< RangegetFlatParameterRanges ()
 gets the ranges of the parameters of the circuit elements
 
std::vector< RangegetDefaultParameters ()
 gets the default ranges of the parameters of each type of circuit element used in the model
 
size_t getParameterCount ()
 gets the total number of parameters used by all the circuit elements in this model
 
bool compile ()
 this function compiles the model into native vectorized code for faster execution
 
bool isReady ()
 this member determines if the model is in a state ready to execute
 
void resolveSteps (int64_t index)
 this member resolves the parameters of all circuit elements at the given parameter sweep step
 
size_t getRequiredStepsForSweeps ()
 gets the total number of parameter sweep steps for the applied sweep
 
bool isParamSweep ()
 checks if the model is a sweep (i.e.
 
std::string getCode ()
 compiles this model into efficient c++ code corresponding to the circuit of this model
 
std::string getTorchScript ()
 compiles this model into TorchScript to be compiled by torch::jit::compile
 
std::string getCompiledFunctionName ()
 Gets the function name in the code for this model.
 
std::vector< size_t > getRecommendedParamIndices (eis::Range omegaRange, double distance, bool threaded=false)
 Gets the function name in the code returned by getTorchScript and getCode for this model.
 

Detailed Description

The main class of eisgenerator representing a equivalent circuit model.

Examples
compileing.cpp, simple.cpp, and torchscript.cpp.

Constructor & Destructor Documentation

◆ Model()

eis::Model::Model ( const std::string &  str,
size_t  paramSweepCount = 100,
bool  defaultToRange = true 
)

Constructor.

Exceptions
parse_errror
Parameters
strthe model string to create a model object for
paramSweepCountoptionally the number of sweep point to use for parameter sweeps
defaultToRangeoptionally a bool that if true, circuit elements not given in str are defaulted to a range instead of a fixed value

Member Function Documentation

◆ compile()

bool eis::Model::compile ( )

this function compiles the model into native vectorized code for faster execution

This function compiles a shared-object for this model that is then loaded by eisgenerator to speed up execution of this model by a factor of 10 or more by employing vectorization and avoiding function calls.

This function is slow, but results are cached for the lifetime of process linked to libeisgenerator so that a circuit has to be compiled only once and can then be used by any number of Model objects.

This function is only implemented on UNIX, on other platforms this function will always return false. This function also requires that GCC be available in PATH.

Returns
true if compile was successful, false otherwise
Examples
compileing.cpp.

◆ execute()

DataPoint eis::Model::execute ( fvalue  omaga,
size_t  index = 0 
)

Gets the impedance at the given frequency this method calls resolveSteps.

Parameters
omegathe frequency in rad/s to calculate the impedance at
indexan optional index to the parameter sweep step at which to calculate the impedance
Returns
a DataPoint struct containing the result
Examples
simple.cpp.

◆ executeAllSweeps()

std::vector< std::vector< DataPoint > > eis::Model::executeAllSweeps ( const Range omega)

Executes a frequency sweep with the given omega values for each parameter combination in the applied parameter sweep this method calls resolveSteps.

Parameters
omegathe range along which to execute a frequency sweep
Returns
a vector of vectors of DataPoint structs containing the impedance at every frequency in the sweep with every parameter combination
Examples
compileing.cpp.

◆ executeSweep() [1/2]

std::vector< DataPoint > eis::Model::executeSweep ( const Range omega,
size_t  index = 0 
)

Executes a frequency sweep along the given range this method calls resolveSteps.

Parameters
omegathe range along which to execute a frequency sweep
indexan optional index to the parameter sweep step at which to calculate the impedance
Returns
a vector of DataPoint structs containing the impedance at every frequency in the sweep
Examples
simple.cpp.

◆ executeSweep() [2/2]

std::vector< DataPoint > eis::Model::executeSweep ( const std::vector< fvalue > &  omega,
size_t  index = 0 
)

Executes a frequency sweep with the given omega values.

Parameters
omegaa vector of frequencies in rad/s to calculate the impedance at
indexan optional index to the parameter sweep step at which to calculate the impedance
Returns
a vector of DataPoint structs containing the impedance at every frequency in the sweep

◆ getCode()

std::string eis::Model::getCode ( )

compiles this model into efficient c++ code corresponding to the circuit of this model

Returns
the code or an empty string if compilation was unsuccessfully
Examples
compileing.cpp.

◆ getCompiledFunctionName()

std::string eis::Model::getCompiledFunctionName ( )

Gets the function name in the code for this model.

Returns
the function name in the code for this model
Examples
torchscript.cpp.

◆ getDefaultParameters()

std::vector< Range > eis::Model::getDefaultParameters ( )

gets the default ranges of the parameters of each type of circuit element used in the model

Returns
the default ranges of the parameters of each type of circuit element used in the model

◆ getFlatComponants()

std::vector< Componant * > eis::Model::getFlatComponants ( Componant model = nullptr)

Returns a vector of pointers to the circuit elements in this model the pointers can only be assumed to be valid until the next member call to this model object.

Parameters
modelfor internal use only
Returns
a vector of the circuit elements in the model

◆ getFlatParameterRanges()

std::vector< Range > eis::Model::getFlatParameterRanges ( )

gets the ranges of the parameters of the circuit elements

Returns
the ranges of the parameters of the circuit elements

◆ getFlatParameters()

std::vector< fvalue > eis::Model::getFlatParameters ( )

gets the values of the parameters of the circuit elements at the current parameter sweep step

Returns
the values of the parameters of the circuit elements at the current parameter sweep step
Examples
torchscript.cpp.

◆ getModelStr()

std::string eis::Model::getModelStr ( ) const

Returns the model string corresponding to this model object, without embedded parameters.

Returns
the model string corresponding to this model object, without embedded parameters
Examples
compileing.cpp.

◆ getModelStrWithParam() [1/2]

std::string eis::Model::getModelStrWithParam ( ) const

Returns the model string corresponding to this model object, with embedded parameters the parameter sweep index of the last call to resolveSteps or 0 is used.

Returns
the model string corresponding to this model object, with embedded parameters

◆ getModelStrWithParam() [2/2]

std::string eis::Model::getModelStrWithParam ( size_t  index)

Returns the model string corresponding to this model object, with embedded parameters this method calls resolveSteps.

Parameters
indexthe parameter sweep index for which to embed the parameters
Returns
the model string corresponding to this model object, with embedded parameters
Examples
compileing.cpp, and simple.cpp.

◆ getParameterCount()

size_t eis::Model::getParameterCount ( )

gets the total number of parameters used by all the circuit elements in this model

Returns
the total number of parameters

◆ getRecommendedParamIndices()

std::vector< size_t > eis::Model::getRecommendedParamIndices ( eis::Range  omegaRange,
double  distance,
bool  threaded = false 
)

Gets the function name in the code returned by getTorchScript and getCode for this model.

Returns
the function name in the code for this model

◆ getRequiredStepsForSweeps()

size_t eis::Model::getRequiredStepsForSweeps ( )

gets the total number of parameter sweep steps for the applied sweep

Returns
the total number of parameter sweep steps for the applied sweep

◆ getTorchScript()

std::string eis::Model::getTorchScript ( )

compiles this model into TorchScript to be compiled by torch::jit::compile

Returns
the TorchScript code or an empty string if compilation was unsuccessful
Examples
torchscript.cpp.

◆ getUuid()

size_t eis::Model::getUuid ( )

Returns a unique id that is unique for this circuit, but not for this object specifically.

Returns
the uid

◆ isParamSweep()

bool eis::Model::isParamSweep ( )

checks if the model is a sweep (i.e.

has at least one parameter with a range)

Returns
true if the model contains a parameter sweep, false otherwise

◆ isReady()

bool eis::Model::isReady ( )

this member determines if the model is in a state ready to execute

Returns
true if the model is ready for the execute* family of methods

◆ resolveSteps()

void eis::Model::resolveSteps ( int64_t  index)

this member resolves the parameters of all circuit elements at the given parameter sweep step

Parameters
indexthe index to the sweep step to resolve to
Examples
torchscript.cpp.

◆ setParamSweepCountClosestTotal()

size_t eis::Model::setParamSweepCountClosestTotal ( size_t  totalCount)

Adjusts the sweep count so that the total of spectra that need to be generated in the parameter sweep is close to the given value.

Parameters
totalCountthe total number of spectra to target
Returns
the number of spectra that will be generated by a parameter sweep after calling this function, should be close to, but may not be exactly totalCount