Skip to content
Snippets Groups Projects
Commit 8907000e authored by Carl Klemm's avatar Carl Klemm
Browse files

add missing files

parent 4918344f
Branches
Tags
No related merge requests found
......@@ -29,6 +29,7 @@ set(API_HEADERS_CPP
${API_HEADERS_CPP_DIR}/paralellseriel.h
${API_HEADERS_CPP_DIR}/basicmath.h
${API_HEADERS_CPP_DIR}/eistype.h
${API_HEADERS_CPP_DIR}/normalize.h
)
set(API_HEADERS_C_DIR eisgenerator/c/)
......
#pragma once
#include <complex>
typedef double fvalue;
namespace eis
{
struct DataPoint
{
std::complex<fvalue> im;
fvalue omega;
};
struct Range
{
fvalue start;
fvalue end;
size_t count;
bool log = false;
fvalue stepSize() const
{
return (end-start)/count;
}
Range operator*(fvalue in) const
{
return Range(start*in, end*in, count, log);
}
Range operator/(fvalue in) const
{
return operator*(static_cast<fvalue>(1.0)/in);
}
Range operator*(int in) const
{
return operator*(static_cast<fvalue>(in));
}
Range operator/(int in) const
{
return operator*(static_cast<fvalue>(1.0)/in);
}
Range(fvalue startI, fvalue endI, size_t countI, bool logI = false): start(startI), end(endI), count(countI), log(logI){}
Range() = default;
};
}
/**
* eisgenerator
* Copyright (C) 2021 Carl Klemm
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <iostream>
#include <string>
namespace eis
{
class Log
{
public:
enum Level
{
DEBUG,
INFO,
WARN,
ERROR
};
private:
bool opened = false;
Level msglevel = DEBUG;
std::string getLabel(Level level);
public:
static bool headers;
static Level level;
static bool endline;
Log() {}
Log(Level type);
~Log();
template<class T> Log &operator<<(const T &msg)
{
if(msglevel >= level)
{
std::cout<<msg;
opened = true;
}
return *this;
}
};
}
......@@ -11,5 +11,6 @@ namespace eis
void normalize(std::vector<eis::DataPoint>& data);
std::vector<eis::DataPoint> reduceRegion(const std::vector<eis::DataPoint>& data, fvalue gradThreshFactor = 0.01);
void eraseSingularites(std::vector<eis::DataPoint>& data);
std::vector<eis::DataPoint> rescale(const std::vector<eis::DataPoint>& data, size_t outputSize);
}
log.cpp 0 → 100644
/**
* Lubricant Detecter
* Copyright (C) 2021 Carl Klemm
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "log.h"
using namespace eis;
Log::Log(Level type)
{
msglevel = type;
if(headers)
{
operator << ("["+getLabel(type)+"] ");
}
}
Log::~Log()
{
if(opened && endline)
{
std::cout<<'\n';
}
opened = false;
}
std::string Log::getLabel(Level level)
{
std::string label;
switch(level)
{
case DEBUG:
label = "DEBUG";
break;
case INFO:
label = "INFO ";
break;
case WARN:
label = "WARN ";
break;
case ERROR:
label = "ERROR";
break;
}
return label;
}
bool Log::headers = false;
Log::Level Log::level = WARN;
bool Log::endline = true;
#include "normalize.h"
#include <assert.h>
#include <cmath>
#include <complex>
#include <limits>
......@@ -88,3 +89,18 @@ std::vector<eis::DataPoint> eis::reduceRegion(const std::vector<eis::DataPoint>&
return data;
}
std::vector<eis::DataPoint> eis::rescale(const std::vector<eis::DataPoint>& data, size_t outputSize)
{
std::vector<eis::DataPoint> output(outputSize);
for(size_t i = 0; i < output.size(); ++i)
{
double position = static_cast<double>(i) / (output.size()-1);
double sourcePosF = (data.size()-1)*position;
size_t sourcePos = (data.size()-1)*position;
double frac = sourcePosF - sourcePos;
output[i].im = data[sourcePos].im*(1-frac) + data[sourcePos+1].im*frac;
output[i].omega = data[sourcePos].omega*(1-frac) + data[sourcePos+1].omega*frac;
}
return output;
}
test.cpp 0 → 100644
#include <iostream>
#include <complex>
#include <chrono>
#include "model.h"
#include "log.h"
#include "normalize.h"
void printComponants(eis::Model& model)
{
eis::Log(eis::Log::DEBUG)<<"Compnants:";
for(eis::Componant* componant : model.getFlatComponants())
{
eis::Log(eis::Log::DEBUG)<<eis::Componant::getComponantChar(componant)<<"{";
for(size_t i = 0; i < componant->paramCount(); ++i)
{
eis::Log(eis::Log::DEBUG)<<componant->getParam()[i];
if(i != componant->paramCount()-1)
eis::Log(eis::Log::DEBUG)<<", ";
}
eis::Log(eis::Log::DEBUG)<<"}";
}
}
void runSingle()
{
eis::Log(eis::Log::INFO)<<__func__;
std::string modelStr("w{1e3}p{1e-7, 0.7}");
std::vector<eis::DataPoint> results;
eis::Model model(modelStr);
printComponants(model);
eis::Range omega(0, 1e6, 50);
auto start = std::chrono::high_resolution_clock::now();
results = model.executeSweep(omega);
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
for(const eis::DataPoint& res : results)
eis::Log(eis::Log::INFO)<<"omega: "<<res.omega<<" real = "<<res.im.real()<<" im = "<<res.im.imag();
eis::Log(eis::Log::INFO)<<"time taken: "<<duration.count()<<" us";
}
void sweepCb(std::vector<eis::DataPoint>& data, const std::vector<fvalue>& parameters)
{
static size_t i = 0;
++i;
if((i & 0x3FF) == 0)
std::cout<<'.'<<std::flush;
}
void runSweep()
{
eis::Log(eis::Log::INFO)<<__func__;
std::string modelStr("w{20e3}p{1e-7, 0.9}");
eis::Model model(modelStr);
std::vector<eis::Range> parameters;
parameters.push_back(eis::Range(1e3, 50e3, 100));
parameters.push_back(eis::Range(1e-7, 20e-7, 100));
parameters.push_back(eis::Range(0.7, 1.2, 100));
eis::Range omega(0, 1e6, 25);
auto start = std::chrono::high_resolution_clock::now();
model.executeParamSweep(parameters, omega, &sweepCb);
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout<<std::endl;
eis::Log(eis::Log::INFO)<<"time taken: "<<duration.count()<<" ms";
}
void runSweepByIndex()
{
eis::Log(eis::Log::INFO)<<__func__;
std::string modelStr("w{20e3}p{1e-7, 0.9}");
eis::Model model(modelStr);
std::vector<eis::Range> parameters;
parameters.push_back(eis::Range(1e3, 50e3, 100));
parameters.push_back(eis::Range(1e-7, 20e-7, 100));
parameters.push_back(eis::Range(0.7, 1.2, 100));
eis::Range omega(0, 1e6, 25);
auto start = std::chrono::high_resolution_clock::now();
std::vector<eis::DataPoint> results = model.executeParamByIndex(parameters, omega, 0);
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
printComponants(model);
for(const eis::DataPoint& res : results)
eis::Log(eis::Log::INFO)<<"omega: "<<res.omega<<" real = "<<res.im.real()<<" im = "<<res.im.imag();
eis::Log(eis::Log::INFO)<<"time taken: "<<duration.count()<<" ms";
}
void runRescale()
{
std::vector<eis::DataPoint> data;
for(size_t i = 0; i < 10; ++i)
{
eis::DataPoint point;
point.im = std::complex<fvalue>(i,i);
point.omega = (i+1)*3;
data.push_back(point);
}
std::cout<<"original: ";
for(const eis::DataPoint& res : data)
std::cout<<res.omega<<','<<res.im.real()<<','<<res.im.imag()<<'\n';
data = eis::rescale(data, 5);
std::cout<<"rescaled: ";
for(const eis::DataPoint& res : data)
std::cout<<res.omega<<','<<res.im.real()<<','<<res.im.imag()<<'\n';
}
int main(int argc, char** argv)
{
eis::Log::headers = true;
eis::Log::level = eis::Log::INFO;
runSingle();
runSweepByIndex();
runSweep();
runRescale();
return 0;
}
#pragma once
#include <string>
#include <vector>
#include <sstream>
std::vector<std::string> tokenize(const std::string& str, const char delim = ' ', const char ignBracketStart = '\0', const char ignBracketEnd = '\0');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment