From f97a10a3a0d1e8f9037a402d070025ba4116537a Mon Sep 17 00:00:00 2001 From: Youssef <youssef.samlali@ensiie.fr> Date: Thu, 9 Jan 2020 09:04:48 +0100 Subject: [PATCH] =?UTF-8?q?first=20commit=20mat=C3=A9riaux=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 36 +++++++++++++++++++++++++++ tab.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tab.h | 43 ++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 main.cpp create mode 100644 tab.cpp create mode 100644 tab.h diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..fff7e66 --- /dev/null +++ b/main.cpp @@ -0,0 +1,36 @@ +// A simple call_scilab example + +#include <stdio.h> /* stderr */ +#include <stdlib.h> + +#include "call_scilab.h" /* Provide functions to call Scilab engine */ +/* Provide functions to access to the memory of Scilab */ + +// Filename: simple_call_scilab.c + +int main(void) +{ +/****** INITIALIZATION **********/ +#ifdef _MSC_VER + if ( StartScilab(NULL,NULL,NULL) == FALSE ) +#else + if ( StartScilab(getenv("SCI"),NULL,NULL) == FALSE ) +#endif + { + fprintf(stderr,"Error while calling StartScilab\n"); + return -1; + } + +/****** ACTUAL Scilab TASKS *******/ + + SendScilabJob("myMatrix=['sample','for the help']"); + SendScilabJob("disp(myMatrix);"); // Will display !sample for the help ! + SendScilabJob("disp([2,3]+[-44,39]);"); // Will display - 42. 42. + +/****** TERMINATION **********/ + if ( TerminateScilab(NULL) == FALSE ) { + fprintf(stderr,"Error while calling TerminateScilab\n"); + return -2; + } + return 0; +} diff --git a/tab.cpp b/tab.cpp new file mode 100644 index 0000000..b6efde9 --- /dev/null +++ b/tab.cpp @@ -0,0 +1,74 @@ +#include <iostream> +#include <limits> +#include <iomanip> +#include "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 L, 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; + +} + +int main(){ + +Materiaux cuivre = Materiaux(389, 8940,380); +Materiaux fer= Materiaux (80.2,7874,440); +Materiaux verre= Materiaux(1.2,2530,840); +Materiaux polystyrene= Materiaux(0.1,1040,1200); + +int ** s = settab(cuivre, 100,100,253,16,1,600); + +return 0; +} diff --git a/tab.h b/tab.h new file mode 100644 index 0000000..ddf29dc --- /dev/null +++ b/tab.h @@ -0,0 +1,43 @@ +#ifndef TAB_H +#define TAB_H + +#include <iostream> +#include <limits> +#include <iomanip> + +class Materiaux +{ + private: + double lambda_; + double kho_; + double c_; + + public: + Materiaux(double lambda, double kho, double c); + + double getlambda() + { + return lambda_; + } + + double getkho() + { + return kho_; + } + + double getc() + { + return c_; + } + + double coeff() + { + return (lambda_/(c_*kho_)); + } + +}; + +int** settab(Materiaux mat, int m, int n , int u0,double T, double L, double f); + + +#endif -- GitLab