eisgenerator 1.0.x
model.h
1//SPDX-License-Identifier: LGPL-3.0-or-later
2/* * eisgenerator - a shared library and application to generate EIS spectra
3 * Copyright (C) 2022-2024 Carl Philipp Klemm <carl@uvos.xyz>
4 *
5 * This file is part of eisgenerator.
6 *
7 * eisgenerator is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * eisgenerator 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 Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with eisgenerator. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <complex>
24#include <cstddef>
25#include <string>
26#include <vector>
27#include <functional>
28
29#include "eistype.h"
30#include "componant/componant.h"
31
32namespace eis
33{
34
35struct CompiledObject;
36
46class Model
47{
48private:
49 Componant *processBrackets(std::string& str, size_t& bracketCounter, size_t paramSweepCount, bool defaultToRange);
50 Componant *processBracket(std::string& str, size_t paramSweepCount, bool defaultToRange);
51 std::string getParamStr(const std::string& str, size_t index);
52 static size_t paramSkipIndex(const std::string& str, size_t index);
53 static void addComponantToFlat(Componant* componant, std::vector<Componant*>* flatComponants);
54
55 static void sweepThreadFn(std::vector<std::vector<DataPoint>>* data, Model* model, size_t start, size_t stop, const Range& omega);
56
57 size_t getActiveParameterCount();
58
59private:
60 Componant *_model = nullptr;
61 std::vector<Componant*> _bracketComponants;
62 std::string _modelStr;
63 std::vector<Componant*> _flatComponants;
64 std::string _modelUuid;
65 CompiledObject* _compiledModel = nullptr;
66
67public:
68
77 Model(const std::string& str, size_t paramSweepCount = 100, bool defaultToRange = true);
78 Model(const Model& in);
79 Model& operator=(const Model& in);
80 ~Model();
81
88 size_t setParamSweepCountClosestTotal(size_t totalCount);
89
98 DataPoint execute(fvalue omaga, size_t index = 0);
99
108 std::vector<DataPoint> executeSweep(const Range& omega, size_t index = 0);
109
117 std::vector<DataPoint> executeSweep(const std::vector<fvalue>& omega, size_t index = 0);
118
126 std::vector<std::vector<DataPoint>> executeAllSweeps(const Range& omega);
127
133 std::string getModelStr() const;
134
142 std::string getModelStrWithParam(size_t index);
143
150 std::string getModelStrWithParam() const;
151
157 size_t getUuid();
158
166 std::vector<Componant*> getFlatComponants(Componant *model = nullptr);
167
173 std::vector<fvalue> getFlatParameters();
174
180 std::vector<Range> getFlatParameterRanges();
181
187 std::vector<Range> getDefaultParameters();
188
195
211 bool compile();
212
218 bool isReady();
219
225 void resolveSteps(int64_t index);
226
233
240
246 std::string getCode();
247
254 std::string getTorchScript();
255
262
268 std::vector<size_t> getRecommendedParamIndices(eis::Range omegaRange, double distance, bool threaded = false);
269};
270
288}
Definition componant.h:33
Basic singular EIS data point.
Definition eistype.h:47
The main class of eisgenerator representing a equivalent circuit model.
Definition model.h:47
std::string getCompiledFunctionName()
Gets the function name in the code for this model.
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 t...
std::vector< DataPoint > executeSweep(const Range &omega, size_t index=0)
Executes a frequency sweep along the given range this method calls resolveSteps.
std::vector< fvalue > getFlatParameters()
gets the values of the parameters of the circuit elements at the current parameter sweep step
Model(const std::string &str, size_t paramSweepCount=100, bool defaultToRange=true)
Constructor.
std::vector< Range > getDefaultParameters()
gets the default ranges of the parameters of each type of circuit element used in the model
std::string getModelStr() const
Returns the model string corresponding to this model object, without embedded parameters.
bool isReady()
this member determines if the model is in a state ready to execute
std::string getTorchScript()
compiles this model into TorchScript to be compiled by torch::jit::compile
std::string getModelStrWithParam(size_t index)
Returns the model string corresponding to this model object, with embedded parameters this method cal...
std::vector< Range > getFlatParameterRanges()
gets the ranges of the parameters of the circuit elements
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.
size_t getRequiredStepsForSweeps()
gets the total number of parameter sweep steps for the applied sweep
std::string getModelStrWithParam() const
Returns the model string corresponding to this model object, with embedded parameters the parameter s...
DataPoint execute(fvalue omaga, size_t index=0)
Gets the impedance at the given frequency this method calls resolveSteps.
std::string getCode()
compiles this model into efficient c++ code corresponding to the circuit of this model
size_t getParameterCount()
gets the total number of parameters used by all the circuit elements in this model
std::vector< DataPoint > executeSweep(const std::vector< fvalue > &omega, size_t index=0)
Executes a frequency sweep with the given omega values.
void resolveSteps(int64_t index)
this member resolves the parameters of all circuit elements at the given parameter sweep step
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...
bool compile()
this function compiles the model into native vectorized code for faster execution
size_t getUuid()
Returns a unique id that is unique for this circuit, but not for this object specifically.
bool isParamSweep()
checks if the model is a sweep (i.e.
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 ...
A range.
Definition eistype.h:110
eisgenerator Copyright (C) 2021 Carl Klemm
Definition basicmath.h:26