diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ada957f30dfc62f005e90f3dec0856317474950..4f33bfef96b3b85f81313ad10d0995deefc0d2cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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/) diff --git a/eisgenerator/inductor.h b/eisgenerator/inductor.h new file mode 100644 index 0000000000000000000000000000000000000000..8edba47b832863251913472f74c74a201cffab86 --- /dev/null +++ b/eisgenerator/inductor.h @@ -0,0 +1,24 @@ +#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; +}; + +} diff --git a/inductor.cpp b/inductor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1c06219a802438cb7476f40a3a9b5c7989b3c1fe --- /dev/null +++ b/inductor.cpp @@ -0,0 +1,62 @@ +#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; +} diff --git a/model.cpp b/model.cpp index c9a46cf764cc47eedd451e37f04051c5810da96a..4a3178cf85b233fd000aaccb69074249bea82cd6 100644 --- a/model.cpp +++ b/model.cpp @@ -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)));