You are on page 1of 3

#include #include #include #include #include #include #include #include #include #include #include

<fstream> <iostream> <dirent.h> <sys/stat.h> <fftw3.h> <math.h> <algorithm> <string> <vector> "functions.H" <stdint.h>

int main(void) { bool timersOn = true; uint64 startTimer, totalTimer; std::string alphaFilePaths, alphaFilePathLine; if (timersOn) { startTimer = timerNow(); totalTimer = timerNow(); } #include "readControlDict.H" #include "findAlphaFiles.H" /* --------------------------------------| This header sets the value of | alphaFilePaths. The format gives one | path per line, contained within the | string. Also sets int numLines. \* --------------------------------------if (timersOn){endTimer(startTimer, "findAlphaFiles.H");} std::cout << "numLines = " << numLines << std::endl; const char * c; const char * ftofn;

*\ | | | | */

if (timersOn){startTimer = timerNow();} #include "readBlockMeshDict.m4.H" if (timersOn){endTimer(startTimer, "readBlockMeshDict.m4.H and readControlDict.H ");} std::ofstream gnuplotFile, gnuplotFile2, ampvstimedata, wavenumberdata; gnuplotFile.open("AnimateFourierTransforms.gpi"); gnuplotFile2.open("PlotFourierTransforms.gpi"); ampvstimedata.open("FT/AmplitudeVsTimeData"); wavenumberdata.open("Wavenumber_figures"); // if directory FT doesn't exist, mkdir. // FTimages, FTheights also. if (numLines == 0) { std::cout << "Could not find any directories containing alpha1. Exiting." << std::endl; return(5); } else if (numLines > 0) { int lineCounter; double increment; double MaxAmplitude; double Atwood = (20.0/2020.0); bool RecordEstimatedHeights = true;

bool DIAG_timers = false, DIAG_timersX = false; uint64 readTimer; int tid = 1; // Make a plan once, instead of many times. if (timersOn){startTimer = timerNow();} fftw_complex *in, *out; fftw_plan p; in = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * xcells)); out = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * xcells)) ; p = fftw_plan_dft_1d(xcells, in, out, FFTW_FORWARD, FFTW_MEASURE); if (timersOn){endTimer(startTimer, "fftw_plan");} // Some memory allocation here! // Memory is always allocated (regardless of simulation size) in readWaveHei ghts.H // The memory is cleared in this file. //int stackLimit = 2000000; // I think the limit is 2097152 (8192 kB / 4 b ytes per int) int totalCells = xcells * ycells; std::cout << "The total number of cells is " << totalCells << std::endl; std::stringstream alphaFilePaths2; alphaFilePaths2 << alphaFilePaths; int xindex, yindex; double lambda; double* yProfileHeight = NULL; yProfileHeight = new double [xcells]; double ** alphaValue = NULL; alphaValue = new double* [xcells]; for (xindex=0; xindex<xcells; xindex++) alphaValue[xindex] = new double [ycells]; if (timersOn){startTimer = timerNow();} for (lineCounter = 0; lineCounter < numLines; lineCounter ++) { double percentageDone = (double(lineCounter)/double(numLines))*100; std::cout << percentageDone << "%\n"; getline(alphaFilePaths2, alphaFilePathLine); c = alphaFilePathLine.c_str(); increment = lineCounter*timestep; std::stringstream FourierTransformOutputFileNameSS; std::string FourierTransformOutputFileName; FourierTransformOutputFileNameSS << "FT/FourierTransformOutput_" << (inc rement); FourierTransformOutputFileName = FourierTransformOutputFileNameSS.str(); ftofn = FourierTransformOutputFileName.c_str(); #include "readWaveHeights.H" /* ------------------------------------------ *\ | Reads the alpha1 file (currently pos sible | | problem regarding choice of file) an d | | provides values for yProfile(Min/Max )Height | | which is indexed by the xcell number . |

\* ------------------------------------------ */ for (xindex=0; xindex<xcells; xindex++) { in[xindex][0] = yProfileHeight[xindex]; in[xindex][1] = 0; } fftw_execute(p); #include "Fourier.H" MaxAmplitude = *std::max_element(yProfileHeight, yProfileHeight+xcells); lambda = sqrt( (9.81)*Atwood*avgWavenumber[3] ); ampvstimedata << increment << " " << MaxAmplitude << " " << lambda << st d::endl; wavenumberdata << increment << " " << avgWavenumber[0] << " " << avgWave number[1] << " " << avgWavenumber[2] << " " << avgWavenumber[3] << std::endl; } // Clear the memory allocation for this time step. delete[] yProfileHeight; for (xindex=0; xindex<xcells; xindex++) delete[] alphaValue[xindex]; if (timersOn){endTimer(startTimer, "loop through all lines of the alphaFiles , including readWaveHeights.H and Fourier.H, along with outputting plotting inst ructions.");} ampvstimedata.close(); if (RecordEstimatedHeights) { if (timersOn){startTimer = timerNow();} #include "RecordEstimatedHeights.H" if (timersOn){endTimer(startTimer, "RecordEstimatedHeights.H");} } #include "GnuPlotFiles.H" fftw_destroy_plan(p); fftw_free(in); fftw_free(out); gnuplotFile.close(); gnuplotFile2.close(); if (timersOn){endTimer(totalTimer, "whole program");} return(0); } else { std::cout << "Some problem with numLines occured. Exiting." << std::endl; return(6); } }

You might also like