Skip to content
Snippets Groups Projects
Commit e7441601 authored by Timon Habenicht's avatar Timon Habenicht
Browse files

new FFTCalucator

parent 740c4f34
No related branches found
No related tags found
No related merge requests found
#include "FFTCalculator.h"
#include "Utilities/SimulationResults/SimulationResults.h"
#include "Utilities/Results/SimulationResults/SimulationResults.h"
#include "Tests/PhiAndNuTest/PhiAndNuTest.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdlib.h>
void FFTCalculator::calcAndCopyToTestResults()
void FFTCalculator::calc()
{
init();
nu = calcNu();
nudiff = calcNuDiff(nu);
phidiff = calcPhiDiff();
phidiff = calcPhi();
}
double FFTCalculator::getNuDiff()
{
return nudiff;
}
testResults->add(nudiff, phidiff, lx);
testResults->evaluate();
double FFTCalculator::getPhiDiff()
{
return phidiff;
}
std::shared_ptr<FFTCalculator> FFTCalculator::getNewInstance(double viscosity)
{
return std::shared_ptr<FFTCalculator>(new FFTCalculator(viscosity));
}
void FFTCalculator::setSimulationResults(std::shared_ptr<SimulationResults> simResults)
......@@ -24,17 +36,26 @@ void FFTCalculator::setSimulationResults(std::shared_ptr<SimulationResults> simR
this->simResults = simResults;
}
void FFTCalculator::setVectorToCalc(std::vector<std::vector<double>> data)
{
this->data = data;
}
void FFTCalculator::init()
{
setVectorToCalc();
lz = (double)simResults->getZNodes();
lx = (double)simResults->getXNodes();
fftResultsIm.clear();
fftResultsRe.clear();
phi.clear();
amplitude.clear();
logAmplitude.clear();
lz = (double)simResults->getNumberOfZNodes();
lx = (double)simResults->getNumberOfXNodes();
timeStepLength = simResults->getTimeStepLength();
numberOfTimeSteps = simResults->getNumberOfTimeSteps();
fftCalculated = false;
}
FFTCalculator::FFTCalculator(double viscosity, std::shared_ptr<PhiAndNuTest> testResults) : vis(viscosity), testResults(testResults)
FFTCalculator::FFTCalculator(double viscosity) : vis(viscosity)
{
}
......@@ -54,9 +75,9 @@ double FFTCalculator::calcNuDiff(double nu)
return nudiff;
}
double FFTCalculator::calcPhiDiff()
double FFTCalculator::calcPhi()
{
calcPhiForAllTimeSteps();
phi = calcPhiForAllTimeSteps();
std::vector<double> linReg = calcLinReg(phi);
return linReg.at(0);
......@@ -121,8 +142,10 @@ void FFTCalculator::calcAmplitudeForAllTimeSteps()
amplitude.push_back(4.0 / (lx * lz) * sqrt(fftResultsRe.at(timeStep).at(pos) * fftResultsRe.at(timeStep).at(pos) + fftResultsIm.at(timeStep).at(pos) * fftResultsIm.at(timeStep).at(pos)));
}
void FFTCalculator::calcPhiForAllTimeSteps()
std::vector<double> FFTCalculator::calcPhiForAllTimeSteps()
{
std::vector<double> result;
if (fftCalculated == false) {
for (int timeStep = 0; timeStep < numberOfTimeSteps; timeStep++)
calcFFT2D(timeStep);
......@@ -130,7 +153,8 @@ void FFTCalculator::calcPhiForAllTimeSteps()
}
int pos = 2 + (lx - 1);
for (int timeStep = 0; timeStep < numberOfTimeSteps; timeStep++)
phi.push_back(atan(fftResultsIm.at(timeStep).at(pos) / fftResultsRe.at(timeStep).at(pos)));
result.push_back(atan(fftResultsIm.at(timeStep).at(pos) / fftResultsRe.at(timeStep).at(pos)));
return result;
}
void FFTCalculator::calcFFT2D(unsigned int timeStep)
......
#ifndef FFTCALCULATOR_H
#define FFTCALCULATOR_H
#include "../Calculator.h"
#include <memory>
#include <vector>
#include <fftw3.h>
......@@ -12,46 +10,44 @@ class EvaluationParameter;
class TestResults;
class PhiAndNuTest;
class FFTCalculator : public Calculator
class FFTCalculator
{
public:
void calcAndCopyToTestResults();
static std::shared_ptr<FFTCalculator> getNewInstance(double viscosity);
void setSimulationResults(std::shared_ptr<SimulationResults> simResults);
protected:
FFTCalculator(double viscosity, std::shared_ptr<PhiAndNuTest> testResults);
virtual void setVectorToCalc() = 0;
std::shared_ptr<SimulationResults> simResults;
std::vector<std::vector<double>> data;
void setVectorToCalc(std::vector<std::vector<double>> data);
void calc();
double getNuDiff();
double getPhiDiff();
private:
FFTCalculator(double viscosity);
void init();
double calcNu();
double calcNuDiff(double nu);
double calcPhiDiff();
std::vector<double> calcLinReg(std::vector<double> y);
double calcPhi();
std::vector< double> calcPhiForAllTimeSteps();
std::vector< double> calcLinReg(std::vector<double> y);
void calcLogAmplitudeForAllTimeSteps();
void calcAmplitudeForAllTimeSteps();
void calcPhiForAllTimeSteps();
void calcFFT2D(unsigned int timeStep);
void initDataForFFT(fftw_complex* input, unsigned int timeStep);
void setFFTResults(fftw_complex* result, unsigned int timeStep);
std::shared_ptr<PhiAndNuTest> testResults;
std::shared_ptr<SimulationResults> simResults;
std::vector<std::vector<double>> data;
std::vector<std::vector<double>> fftResultsIm;
std::vector<std::vector<double>> fftResultsRe;
std::vector<double> phi;
std::vector<double> amplitude;
std::vector<double> logAmplitude;
bool fftCalculated;
double lx, lz;
double vis;
double timeStepLength;
int numberOfTimeSteps;
double nu;
double nudiff, phidiff;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment