Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
552 changes: 552 additions & 0 deletions 2D/CFD.cpp

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions 2D/CFD.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef CFD_H
#define CFD_H

#include "boost/multi_array.hpp"


#include "Class_Cell.h"
#include "config.h"

void SolutionInitializerSquareWave(boost::multi_array<Cell,2> &);

void SolutionInitializerSineWave(boost::multi_array<Cell,2> &);

void SolutionInitializerCircle(boost::multi_array<Cell,2> & , const int &);

void GhostCellsUpdater(boost::multi_array<Cell,2> &, int &);

void ReconstructVariablesFirstOrder(boost::multi_array<Cell,2> &, int &);

void ReconstructVariablesBeamWarming(boost::multi_array<Cell,2> &, int &);

void ReconstructVariablesLaxWendroff(boost::multi_array<Cell,2> &, int &);

void ReconstructVariablesLimitedLW(boost::multi_array<Cell,2> &, int &);

void ReconstructVariablesFromm(boost::multi_array<Cell,2> &, int &);

void ReconstructVariablesWENO5thOrder(boost::multi_array<Cell,2> &, int &);

void CalculateFlux(boost::multi_array<Cell,2> &, int &);

void UpdateCellAveragesEuler(boost::multi_array<Cell,2> &, int &, double &);

void UpdateCellAveragesRK2(boost::multi_array<Cell,2> &, int &, double &);

void UpdateCellAveragesRK3(boost::multi_array<Cell,2> &, int &, double &);

void CopyVariables(boost::multi_array<Cell,2> &);

void ErrorCalculation(boost::multi_array<Cell,2> &);

void UpdateCellAveragesRungeKutta2LevelSet(boost::multi_array<Cell,2> &, int &, double &);

#endif
21 changes: 21 additions & 0 deletions 2D/Class_Cell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef CLASS_CELL_H
#define CLASS_CELL_H

#include "config.h"

class Cell
{
public:
double u[NUM_RK_STEPS + 1];//talvez não dẽ
double uEast;
double uWest;
double uNorth;
double uSouth;
double cx;
double cy;
double dx;
double dy;
double TotalFlux;
};

#endif
39 changes: 39 additions & 0 deletions 2D/SolutionInitializer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef SOLUTIONINITIALIZER_H
#define SOLUTIONINITIALIZER_H

#include <cmath>
#include "boost/multi_array.hpp"

#include "config.h"
#include "Class_Cell.h"

void SolutionInitializerSquareWave(boost::multi_array<Cell,2> &cells)
{
for(int i = 0; i < cells.shape()[0]; i++)
{
for(int j = 0; j < cells.shape()[1]; j++)
{
if(cells[i][j].cx > -0.25 && cells[i][j].cx < 0.25 && cells[i][j].cy > -0.25 && cells[i][j].cy < 0.25)
{
cells[i][j].u[0] = 1.0;
}
else
{
cells[i][j].u[0] = 0.0;
}
}
}
}

void SolutionInitializerSineWave(boost::multi_array<Cell,2> &cells)
{
for(int i = 0; i < cells.shape()[0]; i++)
{
for(int j = 0; j < cells.shape()[1]; j++)
{
cells[i][j].u[0]= sin((cells[i][j].cx + cells[i][j].cy)*M_PI) / double(2);
}
}
}

#endif
33 changes: 33 additions & 0 deletions 2D/SolutionWriter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef SOLUTIONWRITER_H
#define SOLUTIONWRITER_H

#include<iostream>
#include<fstream>
#include<string>
#include "boost/multi_array.hpp"


#include "Class_Cell.h"
#include "config.h"

void WriteSolution(boost::multi_array<Cell,2> &cells, double &time, std::string name)
{
std::ofstream out( name , std::ofstream::out);

out << "Num X cells: " << NUM_X_CELLS << std::endl;
out << "Num Y cells: " << NUM_Y_CELLS << std::endl;
out << "Num ghost cells: " << NUM_GHOST_CELLS << std::endl;
out << "Time: " << time << std::endl;

for(int i = 0; i < cells.shape()[0]; i++)
{
for(int j = 0; j < cells.shape()[1]; j++)
{
out << cells[i][j].cx << " " << cells[i][j].cy << " " <<cells[i][j].u[0] << std::endl;
}
}

}


#endif
Binary file added 2D/a.out
Binary file not shown.
18 changes: 18 additions & 0 deletions 2D/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef CONFIG_H
#define CONFIG_H
//Macros para as constantes do problema, todas estão em unidades do sistema internacional

static const unsigned int NUM_X_CELLS = 60;
static const unsigned int NUM_Y_CELLS = 80;
static const unsigned int NUM_GHOST_CELLS = 4;
static const unsigned int NUM_RK_STEPS = 3;
static const double STOPPING_TIME = 2.0;
static const unsigned int MAX_ITERATIONS = 100000;
static const double MAX_X_SIDE = 1.0;
static const double MIN_X_SIDE = -1.0;
static const double MAX_Y_SIDE = 1.0;
static const double MIN_Y_SIDE = -1.0;
static const double ADVECTION_VEL_X = 1.0;
static const double ADVECTION_VEL_Y = 1.0;
static const double COURANT_NUM = 0.5;
#endif
91 changes: 91 additions & 0 deletions 2D/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include<iostream>
#include<cstdlib>
#include "boost/multi_array.hpp"


using namespace std;
using namespace boost;


#include "Class_Cell.h"
#include "config.h"

#include "SolutionWriter.h"
#include "CFD.h"


int main()
{
boost::multi_array<Cell,2> cells;
cells.resize(extents[NUM_X_CELLS + 2*NUM_GHOST_CELLS][NUM_Y_CELLS + 2*NUM_GHOST_CELLS]);//Array de objetos da classe Cell

double dx = (MAX_X_SIDE - MIN_X_SIDE) / NUM_X_CELLS;
double dy = (MAX_Y_SIDE - MIN_Y_SIDE) / NUM_Y_CELLS;
double time = 0.0;

for(int i = 0; i < cells.shape()[0]; i++)
{
for(int j = 0; j < cells.shape()[1]; j++)
{
cells[i][j].dx = dx;
cells[i][j].dy = dy;
cells[i][j].cx = MIN_X_SIDE + dx*( i + 0.5 - NUM_GHOST_CELLS );
cells[i][j].cy = MIN_Y_SIDE + dy*( j + 0.5 - NUM_GHOST_CELLS );
}
}

SolutionInitializerSquareWave(cells);

std::string name = "Solução no tempo " + std::to_string(time) + ".txt";
WriteSolution(cells,time,name);

bool LastTimeStep = false;


//Time step calculation
double dtx = (cells[0][0].dx / abs(ADVECTION_VEL_X));
double dty = (cells[0][0].dy / abs(ADVECTION_VEL_Y));
double dt = (1.0/float((1.0/float(dtx)) + (1.0/float(dty))))*COURANT_NUM;

for(int RKsteps = 0; RKsteps < NUM_RK_STEPS; RKsteps++)
{
GhostCellsUpdater(cells,RKsteps);
ReconstructVariablesLimitedLW(cells,RKsteps);
CalculateFlux(cells,RKsteps);
UpdateCellAveragesRK3(cells,RKsteps,dt);
}
CopyVariables(cells);
time += dt;

for(int timeIteration = 1; timeIteration < MAX_ITERATIONS; timeIteration++)
{
if(time + dt > STOPPING_TIME)
{
dt = STOPPING_TIME - time;
LastTimeStep = true;
}

for(int RKsteps = 0; RKsteps < NUM_RK_STEPS; RKsteps++)
{
GhostCellsUpdater(cells,RKsteps);
ReconstructVariablesWENO5thOrder(cells,RKsteps);
CalculateFlux(cells,RKsteps);
UpdateCellAveragesRK3(cells,RKsteps,dt);
}
CopyVariables(cells);
time += dt;

if(LastTimeStep){break;}

if( (timeIteration) % 25 == 0.0)
{
name = "Solução no tempo " + std::to_string(time) + ".txt";
WriteSolution(cells,time,name);
}

}
name = "Solução no tempo " + std::to_string(time) + ".txt";
WriteSolution(cells,time,name);
ErrorCalculation(cells);
return 0;
}
3 changes: 3 additions & 0 deletions 2D/out/Erro.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ErrorL1 = 0.0039857
ErrorL2 = 0.0270528
ErrorLinf = 0.405629
Binary file added 2D/out/Solução no tempo 0.000000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading