diff --git a/src/tab.cpp b/src/tab.cpp index b9831573915c835dee31bae48f8ad37e1fc7fa76..f1c62c28982fbb94a75cb9c958bdeba37ed41754 100644 --- a/src/tab.cpp +++ b/src/tab.cpp @@ -1,63 +1,83 @@ -#include <iostream> -#include <limits> -#include <iomanip> -#include "../includes/tab.h" - -using namespace std; -typedef std::numeric_limits< double > dbl; - -Materiaux::Materiaux(double lambda, double kho, double c) -{ - lambda_= lambda; - kho_ = kho; - c_ = c; -} - - - -int** settab(Materiaux mat, int m, int n , int u0,double T,double f) -{ - double dt, dx; - dt= T/100.; - dx= 1./100.; - int** temp; - - temp = new int*[m]; - for (int i = 0; i < m; i++) - temp[i] = new int[n]; - - for (int j = 0; j < n; j++){ - temp[0][j]=u0; - } - - for (int i = 0; i < m; i++){ - temp[i][n-1]=u0; - temp[i][0]= 0; - temp[i][1]=f; - } - - std::cout<< std::setprecision(std::numeric_limits<double>::digits10)<<1<<std::endl; - - for (int i = 1; i < m; i++){ - temp[i][0]= temp[i-1][0]+ mat.coeff()*dt*(2*u0 -3*temp[i-1][0] + temp[i-1][1])/(dx*dx); - for (int j = 2; j < n-1; j++){ - temp[i][j]= temp[i-1][j] + mat.coeff()*dt*(temp[i-1][j-1] -2*temp[i-1][j] + temp[i-1][j+1])/(dx*dx); - } - temp[i][n-1]= temp[i-1][n-1]+ mat.coeff()*dt*(2*u0 -3*temp[i-1][n-1] + temp[i-1][n-2])/(dx*dx); - } - - for (int i = 0; i < m; i++){ - for (int j = 0; j < n; j++){ - std::cout << temp[i][j] << " "; - } - std::cout<< std::endl; - } - - return temp; - - for (int i = 0; i < m; i++) - delete[] temp[i]; - delete[] temp; - -} - +#include <iostream> +#include <limits> +#include <iomanip> +#include <fstream> +#include "tab.h" + +using namespace std; + +Materiaux::Materiaux(double lambda, double kho, double c) +{ + lambda_= lambda; + kho_ = kho; + c_ = c; +} + + + +int** settab(Materiaux mat, int u0, double f) +{ + double T=16; + double L=1; + double dt, dx; + dt= T/100.; + dx= L/100.; + int** temp; + double coef_1= mat.getlambda()/(dx*dx); + double coef_2= dt/(mat.getc()*mat.getkho()); + double F=16*f*f; + + temp = new int*[100]; + for (int i = 0; i < 100; i++) + temp[i] = new int[101]; + + for (int j = 0; j < 101; j++){ + temp[0][j]=u0; + } + + for (int i = 0; i < 100; i++){ + temp[i][100]=u0; + temp[i][0]= u0; + } + + + for (int i = 1; i < 100; i++){ + for (int j = 1; j < 10; j++){ + temp[i][j]= temp[i-1][j] + coef_1*coef_2*(temp[i-1][j-1] -2*temp[i-1][j] + temp[i-1][j+1]); + } + + temp[i][10]= temp[i-1][10] + coef_1*coef_2*(temp[i-1][9] -2*temp[i-1][10] + temp[i-1][11])+coef_2*F; + + for (int j = 11; j < 50; j++){ + temp[i][j]= temp[i-1][j] + coef_1*coef_2*(temp[i-1][j-1] -2*temp[i-1][j] + temp[i-1][j+1]); + } + + for(int j=50;j<61;j++){ + temp[i][j]= temp[i-1][j] + coef_1*coef_2*(temp[i-1][j-1] -2*temp[i-1][j] + temp[i-1][j+1])+coef_2*F*0.75; + } + + for(int j=61;j<100;j++){ + temp[i][j]= temp[i-1][j] + coef_1*coef_2*(temp[i-1][j-1] -2*temp[i-1][j] + temp[i-1][j+1]); + } + } + + const char separateur(' '); + std::ofstream sortie("test",std::ios::out); + + + for (int i = 0; i < 100; i++){ + for (int j = 0; j < 100; j++){ + sortie << temp[i][j] << separateur; + } + sortie<< std::endl; + } + + sortie.close(); + + for (int i = 0; i < 100; i++) + delete[] temp[i]; + delete[] temp; + +} + +