-
Notifications
You must be signed in to change notification settings - Fork 0
/
chaleurVect.cpp
76 lines (54 loc) · 1.16 KB
/
chaleurVect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#define ARMA_DONT_USE_WRAPPER
#include <armadillo>
#include <stdio.hpp>
#include <stdlib.hpp>
#include <math.hpp>
#include <string.hpp>
#include <iostream>
using namespace std;
using namespace arma;
int main(){
//initialisation
double h; double dt; int Nmax; double a ; double b;
FILE *f;
a=0.0; b=2.0; dt=0.0001; Nmax=1000;
h=(b-a)/Nmax;
cout << h << endl;
// condition CFL verification
//if( dt/(h*h) > 0.5){
// cout << "erreur sur la condition CFL";
//exit(0);
//}
// initialisation matrices
vec X(Nmax+1);
for (int i=0; i<=Nmax; i++){
X[i]=i*h;
}
mat A(Nmax+1, Nmax+1, fill::eye);
vec U(Nmax+1, fill:: zeros);
// initialisation second membre
vec B(Nmax+1);
for (int i=1; i<=Nmax+1; i++) { B[i]=X[i]*X[i]; }
// Construction matrice Laplacien //
for (int i=1; i<Nmax; i++)
{
A(i,i)=2;
A(i,i-1)=-1;
A(i,i+1)=-1;
}
A(1,1)=2;
A(1,2)=-1;
A(Nmax,Nmax)=2;
A(Nmax,Nmax-1)=-1;
A=(1/h/h)*A;
// resolution syst lineaire //
U=solve(A,B);
// sauvegarde dans un fichier pour tracer avec gnuplot
f= fopen("chaleurarma.dat","w");
for (int i=1; i<=Nmax; i++){
fprintf(f,"%lf %lf \n", X[i], U[i] );
}
fclose(f);
getchar();
return(0);
}