Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
h>
#include <math.h>
#define pi 3.14159265358979323846
#define gamma 1.4
#define R 287
extern void initialize(int n, float *u, float *x) // Initialize with the profile
given in the question
{
int i;
printf("Initializing!! \n");
extern void euler_backward(float *u, float cfl, int n) // Euler backward scheme
{
int i;
float u_n[n];
extern void euler_forward(float *u, float cfl, int n) // Euler forward scheme
{
int i;
float u_n[n];
extern void FTCS(float *u, float cfl, int n) // Forward time, Centered space scheme
{
int i;
float u_n[n];
extern void leap_frog(float *u, float cfl, int n) // Leap frog scheme
{
int i;
float u_n[n], u_p[n];
matx[0][0] = 0;
matx[0][1] = 1;
matx[0][2] = -1;
matx[0][3] = 0;
matx[n-1][0] = -1;
matx[n-1][1] = 1;
matx[n-1][2] = 0;
matx[n-1][3] = 0;
c_dash[0]=phi[0];
c_dash[n-1]=phi[n-1];
// Check the above markings, they may be wrong, check with python file
phi[i]=(a[i]*phi[i+1])+c_dash[i];
}
}
extern void scheme_selector(int CASE, float *u, float cfl, int n) // To select the
discretization scheme to be used
{
if (CASE==1)
{
euler_backward(u,cfl,n);
}
else if (CASE==2)
{
euler_forward(u,cfl,n);
}
else if (CASE==3)
{
FTCS(u,cfl,n);
}
else if (CASE==4)
{
lax_wendroff(u,cfl,n);
}
else if (CASE==5)
{
lax(u,cfl,n);
}
else if (CASE==6)
{
leap_frog(u,cfl,n);
}
else if (CASE==7)
{
hybrid_theta(u,cfl,n);
}
}
extern void solver (float *u, float *x,int nt, float dt, int n, float cfl,int CASE,
FILE *fichier)
{
int i,j;
if (j==0)
{
initialize(n, u, x);
fprintf(fichier, "Initial step -> t = 0 ... \n Scheme used %d \n
", CASE);
for(i=0; i< n; i++)
{
fprintf(fichier, "at x = %f, U is %f \n", x[i], u[i]);
}
}
if (j!=0)
{
scheme_selector(CASE,u,cfl,n);
for(i=0; i< n; i++)
{
fprintf(fichier, "at x = %f, U is %f \n", x[i], u[i]);
}
}
}
}
int main()
{
int n,i,nt,j,k, CASE;
float Temp, c, cfl, dt, dx, t;
FILE *fichier;