hydrocode_Radial_Lag 0.3
This is an implementation of fully explict forward Euler scheme for multi-D radially symmetric compressible flows on Lagrangian coordinate
radial_mesh.c
浏览该文件的文档.
1
6#include <math.h>
7#include <stdlib.h>
8#include <stdio.h>
9
10#include "../include_cii/mem.h"
11#include "../include/var_struc.h"
12
13
19struct radial_mesh_var radial_mesh_init(const char *example)
20{
21 double const dr = config[10]; // initial d_raidus
22 double const dtheta = config[11]; // initial d_angle
23 double const r_0 = config[20];
24 int const Md = (int)config[3]+2; // max vector dimension
25
26 struct radial_mesh_var rmv;
27 rmv.Rb = (double*)ALLOC(Md*sizeof(double)); //radius and length of outer cell boundary
28 rmv.Lb = (double*)ALLOC(Md*sizeof(double));
29 rmv.RR = (double*)ALLOC(Md*sizeof(double)); //centroidal radius and variable in cells
30 rmv.DdrL = (double*)ALLOC(Md*sizeof(double)); //distance from boundary to center in a cell
31 rmv.DdrR = (double*)ALLOC(Md*sizeof(double));
32 rmv.Ddr = (double*)ALLOC(Md*sizeof(double));
33 rmv.dRc = (double*)ALLOC(Md*sizeof(double)); //(derivative)centers distance
34 rmv.vol = (double*)ALLOC(Md*sizeof(double));
35
36 rmv.Rb[0]=0.0;
37 rmv.Lb[0]=0.0;
38 rmv.RR[0]=(2.0/3.0*r_0)*cos(0.5*dtheta);
39 for(int i = 1; i < Md; i++)//center cell is cell 0
40 {
41 rmv.Rb[i]=(r_0+(i-1)*dr)*cos(0.5*dtheta);//outer cell boundary
42 rmv.Lb[i]=(r_0+(i-1)*dr)*sin(0.5*dtheta)*2.0;
43 //centroid of triangular and trapezoid
44 rmv.RR[i]=(r_0+i*dr-(3*r_0/dr+3*i-2)/(6*r_0/dr+6*i-3)*dr)*cos(0.5*dtheta);
45 //rmv.RR[i]=rmv.Rb[i+1]-(2.0*rmv.Lb[i]+rmv.Lb[i+1])/(3.0*(rmv.Lb[i]+rmv.Lb[i+1]))*(rmv.Rb[i+1]-rmv.Rb[i]);
46 }
47
48 printf("Mesh of %s has been constructed!\n", example);
49 return rmv;
50}
51
52
57void radial_mesh_update(struct radial_mesh_var *rmv)
58{
59 int const Ncell = (int)config[3]; // Number of computing cells in r direction
60
61 double *Rb = rmv->Rb; //radius and length of outer cell boundary
62 double *Lb = rmv->Lb;
63 double *RR = rmv->RR; //centroidal radius and variable in cells
64 /* Variables to be updated */
65 double *DdrL = rmv->DdrL;//distance from boundary to center in a cell
66 double *DdrR = rmv->DdrR;
67 double *Ddr = rmv->Ddr;
68 double *dRc = rmv->dRc; //(derivative)centers distance
69 double *vol = rmv->vol;
70
71 for(int i = 0; i <= Ncell; i++)
72 {
73 dRc[i] = RR[i]-RR[i-1];
74 DdrL[i] = Rb[i+1]-RR[i]; // Right side length of cell i
75 DdrR[i] = RR[i]-Rb[i]; // Left side length of cell i
76 Ddr[i] = DdrL[i]+DdrR[i];
77 if(Ddr[i] < 0.0)
78 {
79 fprintf(stderr, "ERROR! deltar_r < 0 in cell %d.\n", i);
80 exit(3);
81 }
82 vol[i] = RR[i]*0.5*(Lb[i]+Lb[i+1])*Ddr[i]; //m=2.
83 }
84 dRc[Ncell+1] = RR[Ncell+1]-RR[Ncell]; // boundary condition
85 DdrR[Ncell+1] = RR[Ncell+1]-Rb[Ncell+1];
86 Ddr[Ncell+1] = Ddr[Ncell];
87}
88
89
94void radial_mesh_mem_free(struct radial_mesh_var *rmv)
95{
96 FREE(rmv->Rb);
97 FREE(rmv->Lb);
98 FREE(rmv->RR);
99 FREE(rmv->DdrL);
100 FREE(rmv->DdrR);
101 FREE(rmv->Ddr);
102 FREE(rmv->dRc);
103 FREE(rmv->vol);
104}
double config[N_CONF]
Initial configuration data array.
Definition: hydrocode.c:123
#define FREE(ptr)
Definition: mem.h:25
#define ALLOC(nbytes)
Definition: mem.h:19
void radial_mesh_update(struct radial_mesh_var *rmv)
This function updates radially symmetric meshing variables after each time step update.
Definition: radial_mesh.c:57
struct radial_mesh_var radial_mesh_init(const char *example)
This function initializes radially symmetric meshing variables.
Definition: radial_mesh.c:19
void radial_mesh_mem_free(struct radial_mesh_var *rmv)
This function free memory for storing radially symmetric meshing variables.
Definition: radial_mesh.c:94