Skip to content
Snippets Groups Projects
Commit 130491b1 authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

add inductor model primitive

parent 754608bd
Branches
Tags
No related merge requests found
......@@ -5,6 +5,7 @@ project(eisgenerator)
set(SRC_FILES
componant.cpp
cap.cpp
inductor.cpp
resistor.cpp
constantphase.cpp
warburg.cpp
......@@ -14,6 +15,9 @@ set(SRC_FILES
log.cpp
normalize.cpp
basicmath.cpp
log.cpp
normalize.cpp
basicmath.cpp
)
set(API_HEADERS_CPP_DIR eisgenerator/)
......@@ -30,6 +34,7 @@ set(API_HEADERS_CPP
${API_HEADERS_CPP_DIR}/basicmath.h
${API_HEADERS_CPP_DIR}/eistype.h
${API_HEADERS_CPP_DIR}/normalize.h
${API_HEADERS_CPP_DIR}/inductor.h
)
set(API_HEADERS_C_DIR eisgenerator/c/)
......
#pragma once
#include <complex>
#include <string>
#include <vector>
#include "componant.h"
namespace eis
{
class Inductor: public Componant
{
private:
fvalue _L;
public:
Inductor(std::string paramStr);
Inductor(fvalue L = 1e-6);
virtual std::complex<fvalue> execute(fvalue omega) override;
virtual std::vector<fvalue> getParam() override;
virtual void setParam(const std::vector<fvalue>& param) override;
virtual size_t paramCount() override;
virtual ~Inductor() = default;
};
}
#include "inductor.h"
#include "tokenize.h"
#include <cstdlib>
#include <math.h>
#include "log.h"
using namespace eis;
Inductor::Inductor(fvalue L): _L(L)
{
}
Inductor::Inductor(std::string paramStr)
{
std::vector<std::string> tokens = tokenize(paramStr, ',');
if(tokens.empty())
{
Log(Log::WARN)<<"to few parameters in "<<__func__<<" parameter string: "<<paramStr<<'\n';
_L = 1e-6;
return;
}
else
{
try
{
_L = std::stod(tokens[0]);
}
catch(const std::invalid_argument& ia)
{
Log(Log::WARN)<<"Warning: cant parse parameter in "<<__func__<<" parameter: "<<tokens[0]<<'\n';
_L = 1e3;
}
}
}
std::complex<fvalue> Inductor::execute(fvalue omega)
{
return std::complex<fvalue>(0, _L*omega);
}
std::vector<fvalue> Inductor::getParam()
{
return std::vector<fvalue>({_L});
}
void Inductor::setParam(const std::vector<fvalue>& param)
{
if(param.empty())
{
Log(Log::WARN)<<"invalid parameter list sent to "<<__func__<<'\n';
return;
}
_L = param[0];
}
size_t Inductor::paramCount()
{
return 1;
}
......@@ -4,6 +4,7 @@
#include "tokenize.h"
#include "cap.h"
#include "resistor.h"
#include "inductor.h"
#include "constantphase.h"
#include "warburg.h"
#include "paralellseriel.h"
......@@ -116,6 +117,11 @@ Componant *Model::processBracket(std::string& str)
componants.push_back(new Resistor(getParamStr(nodeStr, i)));
i = opposingBraket(nodeStr, i, '}');
break;
case 'l':
case 'L':
componants.push_back(new Inductor(getParamStr(nodeStr, i)));
i = opposingBraket(nodeStr, i, '}');
break;
case 'p':
case 'P':
componants.push_back(new Cpe(getParamStr(nodeStr, i)));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment