├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── amr_grid_treat.cpp ├── amr_grid_treat_shkVor.cpp ├── approx_sol.cpp ├── background_grid.cpp ├── bodygridclass.cpp ├── cal_te_res.cpp ├── commons.cpp ├── face_flux_all.cpp ├── face_vec.cpp ├── farfield_boundary.cpp ├── findneighbor.cpp ├── findneighbor.h ├── findrefp.cpp ├── formlist.cpp ├── hllc.cpp ├── initVor.cpp ├── initial_data.cpp ├── initial_data_bk.cpp ├── main.cpp ├── multi_value_cell.cpp ├── non_uniform_grid.h ├── out_para.cpp ├── outputgrid.cpp ├── point_half_circle.cpp ├── point_position.cpp ├── point_quad.cpp ├── point_triangle.cpp ├── point_vec.cpp ├── points_solid.cpp ├── restart.cpp ├── riemann.cpp ├── riemannWallBound.cpp ├── rk.cpp ├── roe.cpp ├── setflag.cpp ├── solveAMR.cpp ├── sonCellAvg.cpp ├── spatial_discretization.cpp ├── time_step.cpp ├── tree_avg.cpp ├── tvbm_limiter4all.cpp ├── vec2d.cpp ├── vec2d.h ├── vec3d.cpp ├── vec3d.h ├── vec4d.cpp ├── vec4d.h ├── vecnd.cpp ├── vecnd.h ├── wall4amrdg2013.cpp └── wall4amrdgOct26.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | *.smod 19 | 20 | # Compiled Static libraries 21 | *.lai 22 | *.la 23 | *.a 24 | *.lib 25 | 26 | # Executables 27 | *.exe 28 | *.out 29 | *.app 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Jianming Liu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # DMU PhD research code 3 | #16/11/2010, developed by Liu Jianming, Xuzhou Normal Univ. 4 | #Version 0 5 | ############################################################ 6 | 7 | CC=g++ 8 | 9 | OPTS= -O3 10 | #OPTS= -Wall -g 11 | EXE=pos_amrdg2 12 | 13 | SRC=background_grid.cpp bodygridclass.cpp vec3d.cpp\ 14 | commons.cpp setflag.cpp vec4d.cpp point_vec.cpp\ 15 | outputgrid.cpp findneighbor.cpp face_vec.cpp\ 16 | points_solid.cpp vecnd.cpp findrefp.cpp\ 17 | formlist.cpp amr_grid_treat.cpp vec2d.cpp main.cpp\ 18 | approx_sol.cpp face_flux_all.cpp hllc.cpp roe.cpp\ 19 | spatial_discretization.cpp wall4amrdg2013.cpp\ 20 | rk.cpp farfield_boundary.cpp time_step.cpp\ 21 | initial_data.cpp tvbm_limiter4all.cpp\ 22 | tree_avg.cpp sonCellAvg.cpp out_para.cpp\ 23 | solveAMR.cpp multi_value_cell.cpp cal_te_res.cpp\ 24 | riemannWallBound.cpp 25 | 26 | #wall4_amr_dg.cpp 27 | 28 | .SUFFIXES: .cpp .o 29 | 30 | OBJ= $(SRC:.cpp=.o) 31 | 32 | .cpp.o: 33 | $(CC) $(OPTS) -c $< 34 | 35 | all: $(EXE) 36 | 37 | $(EXE): $(OBJ) 38 | $(CC) $(OPTS) -o $@ $(OBJ) 39 | 40 | clean: 41 | rm $(OBJ) $(EXE) 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # amrdg2d 2 | Discontinuous Galerkin Adaptive Mesh Refinement Code can treat any 2d complex geometry problems on Cartesian grid. 3 | -------------------------------------------------------------------------------- /amr_grid_treat.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/amr_grid_treat.cpp -------------------------------------------------------------------------------- /amr_grid_treat_shkVor.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/amr_grid_treat_shkVor.cpp -------------------------------------------------------------------------------- /approx_sol.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include"vec2d.h" 3 | 4 | //x,y belong to [-1,1]X[-1,1] 需要将 [x_{i-1/2} x_{i+1/2}] => [-1,1] 5 | double approx_sol(double x, double y, double *doftmp, int n ) 6 | { 7 | 8 | double uh; 9 | if(n==6) { 10 | uh=doftmp[0]+doftmp[1]*x+doftmp[2]*y+doftmp[3]*x*y 11 | +doftmp[4]*(x*x-1.0/3.0) + doftmp[5]*(y*y-1.0/3.0); 12 | } 13 | else if(n==3) { 14 | uh=doftmp[0]+doftmp[1]*x+doftmp[2]*y; 15 | } 16 | else if(n==1) { 17 | uh=doftmp[0]; 18 | } 19 | 20 | return uh; 21 | } 22 | 23 | //直接x,y是原始计算区域的坐标 [x_{i-1/2} x_{i+1/2}] 24 | double n_approx_sol(double x,double y, double xc1, double yc1, double dx, double dy, double *doftmp, int n ) 25 | { 26 | double uh; 27 | if(n==6) { 28 | uh=doftmp[0]+doftmp[1]*2.0*(x-xc1)/dx+doftmp[2]*2.0*(y-yc1)/dy+doftmp[3]*4.0*(x-xc1)*(y-yc1)/(dx*dy) 29 | +doftmp[4]*((x-xc1)*(x-xc1)*4.0/(dx*dx)-1.0/3.0) + doftmp[5]*((y-yc1)*(y-yc1)*4.0/(dy*dy)-1.0/3.0); 30 | } 31 | else if(n==3) { 32 | uh=doftmp[0]+doftmp[1]*2.0*(x-xc1)/dx+doftmp[2]*2.0*(y-yc1)/dy; 33 | } 34 | else if(n==1) { 35 | uh=doftmp[0]; 36 | } 37 | 38 | return uh; 39 | } 40 | 41 | 42 | 43 | double n_approx_sol(const double xi[2], const double xc[2], double dx, double dy, double *doftmp, int n ) 44 | { 45 | double uh; 46 | if(n==6) { 47 | uh=doftmp[0]+doftmp[1]*2.0*(xi[0]-xc[0])/dx+doftmp[2]*2.0*(xi[1]-xc[1])/dy+doftmp[3]*4.0*(xi[0]-xc[0])*(xi[1]-xc[1])/(dx*dy) 48 | +doftmp[4]*((xi[0]-xc[0])*(xi[0]-xc[0])*4.0/(dx*dx)-1.0/3.0) + doftmp[5]*((xi[1]-xc[1])*(xi[1]-xc[1])*4.0/(dy*dy)-1.0/3.0); 49 | } 50 | else if(n==3) { 51 | uh=doftmp[0]+doftmp[1]*2.0*(xi[0]-xc[0])/dx+doftmp[2]*2.0*(xi[1]-xc[1])/dy; 52 | } 53 | else if(n==1) { 54 | uh=doftmp[0]; 55 | } 56 | return uh; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /background_grid.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/background_grid.cpp -------------------------------------------------------------------------------- /bodygridclass.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/bodygridclass.cpp -------------------------------------------------------------------------------- /cal_te_res.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include"non_uniform_grid.h" 3 | //extern OctCell *bodygrid; 4 | extern Node *HeadListAllGrid; 5 | extern double dt; 6 | extern double timesum; 7 | 8 | void cal_te_res() 9 | { 10 | Node *current; 11 | current = HeadListAllGrid; 12 | OctCell *pcell0; 13 | double db_tmp=0.0; 14 | while(current != NULL) 15 | { 16 | pcell0 = current->cell; 17 | if(pcell0->flag == 0 && current->flg<=2 ) { 18 | db_tmp+=pcell0->residual[0][0]*pcell0->residual[0][0] 19 | *pcell0->dx*pcell0->dy; 20 | } 21 | current = current->next; 22 | } 23 | db_tmp=sqrt(db_tmp); 24 | // cout<<"rhoE ie. residual[3][0]->"< refcell[Nr+1]; 8 | //OctCell *solrefcell[NneedRefineGrid]; 9 | vectorsolrefcell;//solution AMR cell 10 | 11 | vectorsolcoacell;//solution coase cell 12 | 13 | PXYZ MultiCircle[N_BODY+1][500]; //points at solid wall 14 | int NWallPts[N_BODY+3]={NPOINTCIRCLE, NPOINTCIRCLE1, 15 | NPOINTCIRCLE2}; 16 | 17 | string WallPtsFile[N_BODY+3]={ WALL_POINT_FILE, WALL_POINT_FILE1, 18 | WALL_POINT_FILE2}; 19 | //PXYZ Circle[NPOINTCIRCLE+1]; //points at solid wall 20 | //PXYZ Circle1[NPOINTCIRCLE1+1]; //points at solid wall 21 | //PXYZ Circle2[NPOINTCIRCLE2+1]; //points at solid wall 22 | PXYZ ext_wall[NPT_EXT_WALL+1]; //points at external computational domain 23 | 24 | Node *HeadListAllGrid=NULL; //the head of all cell 25 | 26 | BndryNode *HeadFaceCell=NULL;//the head of boudnary internal cell 27 | vector ExtWallBndry; 28 | vector InletBndry; 29 | vector OutletBndry; 30 | 31 | vector faces; //临时面 32 | 33 | vector faces_comp; //需要计算的面 34 | 35 | map cellEbools; //用来找边的临时map 36 | 37 | map cellPoints; //cell由那几个点组成序号为points4out的下标+1 38 | 39 | vector points4out; //输出时候用,给出点的坐标 40 | 41 | double dt; //global time step 42 | double timesum=0.0; 43 | 44 | setmvalue_set; //可能的多值cell集合 45 | PXYZ MBsharp_point[N_BODY+1][8]; 46 | //多值点个数不止一个时候不要忘记solveAMR.cpp中还有个确定多值点的函数不要少调用了 47 | Vec2D ExtPnt0(-3.0,2.0); 48 | Vec2D ExtPnt1(-3.0,-2.0); 49 | Vec2D ExtPnt2(5.0,-2.0); 50 | Vec2D ExtPnt3(5.0,2.0); 51 | double CL,Cd; 52 | 53 | double value_kxrcf_amr=1.0; 54 | string str0("OUT2//"); 55 | JBBL State_l; 56 | JBBL State_r; 57 | 58 | setColCoa; 59 | double sumVorM; 60 | double epsPos=1.0e-13; 61 | double max_cv_x; 62 | double max_cv_y; 63 | double CFL=0.10; 64 | -------------------------------------------------------------------------------- /face_flux_all.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/face_flux_all.cpp -------------------------------------------------------------------------------- /face_vec.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/face_vec.cpp -------------------------------------------------------------------------------- /farfield_boundary.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/farfield_boundary.cpp -------------------------------------------------------------------------------- /findneighbor.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/findneighbor.cpp -------------------------------------------------------------------------------- /findneighbor.h: -------------------------------------------------------------------------------- 1 | #ifndef FIND_NEIGHBOR_H 2 | #define FIND_NEIGHBOR_H 3 | #include "non_uniform_grid.h" 4 | 5 | OctCell *NorthNeighbor(OctCell *pp); 6 | OctCell *WestNeighbor(OctCell *pp); 7 | OctCell *EastNeighbor(OctCell *pp); 8 | OctCell *SouthNeighbor(OctCell *pp); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /findrefp.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/findrefp.cpp -------------------------------------------------------------------------------- /formlist.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/formlist.cpp -------------------------------------------------------------------------------- /hllc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/hllc.cpp -------------------------------------------------------------------------------- /initVor.cpp: -------------------------------------------------------------------------------- 1 | 2 | void initialvortex(struct cell *pc,double U[]) 3 | { 4 | double dtT,dU,tau,rxy,epsi=0.5,Radc=0.05,alph=0.204; 5 | double x,y,xo,yo; 6 | xo=0.25,yo=0.5; 7 | x=pc->xc;y=pc->yc; 8 | // if(x<0.5) 9 | { 10 | rxy=(x-xo)*(x-xo)+(y-yo)*(y-yo); 11 | if(rxy>1e-6)rxy=sqrt(rxy); 12 | 13 | tau=rxy/Radc; 14 | dtT=-(gama-1.0)*epsi*epsi*exp(2.0*alph*(1.0-tau*tau))/(4.0*alph*gama); 15 | dU=epsi*tau*exp(alph*(1.0-tau*tau)); 16 | 17 | U[0]=pow(1.0+dtT,2.5); 18 | if(rxy>1e-6){ 19 | U[1]=Uinf[1]+dU*(y-yo)/rxy; 20 | U[2]=Uinf[2]-dU*(x-xo)/rxy; 21 | }else{ 22 | U[1]=Uinf[1]; 23 | U[2]=Uinf[2]; 24 | } 25 | U[3]=Uinf[3]; 26 | U[4]=pow(U[0],1.4); 27 | } 28 | /* else 29 | { 30 | U[0]=1.169; 31 | U[1]=1.1133; 32 | U[2]=0.0; 33 | U[3]=0.0; 34 | U[4]=1.245; 35 | }*/ 36 | // printf("d=%f,u=%f,v=%f,w=%f,p=%f\n",U[0],U[1],U[2],U[3],U[4]); 37 | } 38 | -------------------------------------------------------------------------------- /initial_data.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/initial_data.cpp -------------------------------------------------------------------------------- /initial_data_bk.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/initial_data_bk.cpp -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/main.cpp -------------------------------------------------------------------------------- /multi_value_cell.cpp: -------------------------------------------------------------------------------- 1 | #include"non_uniform_grid.h" 2 | #include"findneighbor.h" 3 | #include 4 | #include 5 | #include 6 | extern OctCell *bodygrid; 7 | 8 | //extern PXYZ Circle[NPOINTCIRCLE+1]; 9 | 10 | //const PXYZ *const wallpoint = Circle; 11 | //const int NumberAirfoilPoint=NPOINTCIRCLE; 12 | //const int HalfNumberAirfoilPoint=NumberAirfoilPoint / 2; 13 | //const int n_sharp_point=HalfNumberAirfoilPoint; 14 | 15 | void find_sol_refp(OctCell *pp[],OctCell *parent); 16 | 17 | //PXYZ sharp_point=wallpoint[n_sharp_point]; 18 | 19 | extern setmvalue_set; 20 | void insert_cell2(OctCell *pp, set &grid) 21 | { 22 | if(pp->reflag==0){ 23 | if(pp->flag%2==0)grid.insert(pp); 24 | } 25 | else { 26 | for(int m=0; m<4;++m) 27 | insert_cell2(pp->children[m], grid); 28 | } 29 | } 30 | 31 | //这里只是找到可能有多值点情况的 32 | void find_multivalue_cell(const PXYZ &sharppoint) 33 | { 34 | double hcx, hcy; 35 | OctCell *cellflow=NULL; 36 | OctCell *in_this_cell=NULL; 37 | OctCell *ppvec[9]={NULL}; 38 | // PXYZ point; 39 | // point=wallpoint[n_sharp_point]; 40 | mvalue_set.clear(); 41 | for(int i=1;i<=Nx*Ny;++i){ 42 | cellflow=bodygrid+i; 43 | hcx=cellflow->dx; 44 | hcy=cellflow->dy; 45 | 46 | if(sharppoint.x < cellflow->xc1 + 0.5 * hcx + ERRS 47 | && sharppoint.x > cellflow->xc1 - 0.5 * hcx - ERRS 48 | && sharppoint.y < cellflow->yc1 + 0.5 * hcy + ERRS 49 | && sharppoint.y > cellflow->yc1 - 0.5 * hcy - ERRS){ 50 | in_this_cell=cellflow; 51 | break; 52 | } 53 | } 54 | 55 | find_sol_refp(ppvec,in_this_cell); 56 | ppvec[8]=in_this_cell; 57 | for(int i=0; i<9;++i) 58 | insert_cell2(ppvec[i],mvalue_set); 59 | 60 | for(set::iterator it_set=mvalue_set.begin(); 61 | it_set!=mvalue_set.end();++it_set) { 62 | (*it_set)->mvflg=true; 63 | } 64 | } 65 | 66 | 67 | -------------------------------------------------------------------------------- /non_uniform_grid.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/non_uniform_grid.h -------------------------------------------------------------------------------- /out_para.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"non_uniform_grid.h" 3 | 4 | using namespace std; 5 | extern string str0; 6 | extern double CFL; 7 | void out_para( const string &str123) 8 | { 9 | ofstream fpxx; 10 | string proxfile1(FILE_PROX); 11 | 12 | string str1=str0+proxfile1; 13 | 14 | ostringstream omess1; 15 | 16 | omess1 << str1<"<"< 6 | 7 | extern PXYZ Circle[NPOINTCIRCLE+1]; 8 | extern Node *HeadListAllGrid; 9 | void formListForAllGrid(); 10 | extern PXYZ MultiCircle[N_BODY+1][500]; //points at solid wall 11 | extern int NWallPts[N_BODY+3]; 12 | double approx_sol(double x, double y, double *doftmp, int n ); 13 | typedef struct point0123 14 | { 15 | double x,y; 16 | // double SumVo; 17 | // double SumP,SumQ,SumU,SumV;//基本变量加和 18 | 19 | // double sxlgq,sylgq; 20 | // double xlgq,ylgq; 21 | 22 | // JBBL jb; 23 | }PointJBoutput; 24 | 25 | typedef struct cell0123 26 | { 27 | int cpoint[4]; 28 | }ControlCellOutput; 29 | 30 | PointJBoutput *pointOutput=NULL; 31 | 32 | ControlCellOutput *cellOutput=NULL; 33 | 34 | static int NU=1,Np=1; 35 | 36 | extern WALLP MultiCompany[][500]; //壁面输出量 37 | extern WALLP Company[NPOINTCIRCLE+1]; //壁面输出量 38 | void PrintNode_bk(OctCell* parent) 39 | { 40 | int i,j; 41 | int ix,jy,kz,m; 42 | // double plevel; 43 | double x[4],y[4];//网格顶点的坐标 44 | double hcx,xc,yc,hcy; 45 | 46 | if(parent->children[1]==NULL) 47 | { 48 | // if(parent->flag>0) 49 | //{ 50 | // plevel=parent->level+1.0; 51 | //hc=h/pow(2.0,plevel);//子网格的步长 52 | hcx=0.5*parent->dx; 53 | hcy=0.5*parent->dy; 54 | xc=parent->xc1; 55 | yc=parent->yc1; 56 | //printf("xc=%15.8e,yc=%15.8e\n",parent->xc1,parent->yc1); 57 | // cout<<"xc= "<children[im]); 113 | } 114 | } 115 | } 116 | extern string str0; 117 | 118 | void outputcell(int ij) 119 | { 120 | // 121 | ofstream fpxx; 122 | 123 | string proxfile1(FILE_PROX); 124 | 125 | string str1=str0+proxfile1; 126 | 127 | ostringstream omess1; 128 | 129 | omess1 << str1 << ij<<".plt"; 130 | 131 | //fpxx.open(filename1[ljm]); 132 | fpxx.open(omess1.str().c_str()); 133 | 134 | // 135 | long i; 136 | long k,j; 137 | 138 | Node *current; 139 | OctCell *lsbl; 140 | current = HeadListAllGrid; 141 | 142 | pointOutput=new PointJBoutput[NpointForOutput]; 143 | cellOutput=new ControlCellOutput[NpointForOutput]; 144 | 145 | while(current != NULL) 146 | { 147 | 148 | lsbl = current->cell; 149 | if(lsbl->flag % 2 == 0 && current->flg<=2 ) 150 | PrintNode_bk(lsbl); 151 | current = current->next; 152 | } 153 | 154 | // for(i=1;i<=Nx*Ny;i++) 155 | // { 156 | // PrintNode(&bodygrid[i]); 157 | // } 158 | 159 | fpxx<<"TITLE =\"EULER SOLVER\"\n" 160 | <<"VARIABLES = \"X\", \"Y\"\n" 161 | <<"ZONE N= "< cellPoints; 194 | extern vector points4out; 195 | 196 | void outputcell_new(int ij)//output mesh 197 | { 198 | // 199 | ofstream fpxx; 200 | 201 | string proxfile1(FILE_PROX); 202 | 203 | string str1=str0+proxfile1; 204 | 205 | ostringstream omess1; 206 | 207 | omess1 << str1<<"mesh_tn" << ij<<".plt"; 208 | 209 | fpxx.open(omess1.str().c_str()); 210 | 211 | fpxx<<"TITLE =\"EULER SOLVER\"\n" 212 | <<"VARIABLES = \"X\", \"Y\"\n" 213 | <<"ZONE N= "<::size_type j=0;j!=points4out.size();++j) 216 | { 217 | fpxx< ::iterator ik=cellPoints.begin();ik!=cellPoints.end(); ++ik) 220 | { 221 | for(int i=0;i<4;i++) 222 | { 223 | fpxx<second.iPoint[i]<<" "; 224 | 225 | } 226 | fpxx<<"\n"; 227 | } 228 | 229 | /* fpxx<<"\n\n"; 230 | fpxx<<"TITLE =\"Wall Points\"\n" 231 | <<"VARIABLES = \"X\", \"Y\"\n" 232 | <<"ZONE I= "<::size_type j=0;j!=points4out.size();++j) 275 | { 276 | volsum=0.0; 277 | tm_tdiv=0.0; 278 | u=v=p=den=0.0; 279 | // if(j==0){int iitm; cout<<"look look"<< points4out[j].nmc<>iitm;} 280 | 281 | for(int ii=0; ii< points4out[j].nmc; ++ii){ 282 | vol=1.0/((points4out[j].mcell[ii])->dx*(points4out[j].mcell[ii])->dy); 283 | volsum+=vol; 284 | den1=(points4out[j].mcell[ii])->dof[0][0]; 285 | u1=(points4out[j].mcell[ii])->dof[1][0]/den1; 286 | v1=(points4out[j].mcell[ii])->dof[2][0]/den1; 287 | Et=(points4out[j].mcell[ii])->dof[3][0]; 288 | p1=GAM11*(Et-0.5*den1*(u1*u1+v1*v1)); 289 | 290 | den+=vol*den1; 291 | u+=vol*u1; 292 | v+=vol*v1; 293 | p+=vol*p1; 294 | // rtp000=(((points4out[j].mcell[ii])->trb==true)?1.0:0.0); 295 | rtp000=(points4out[j].mcell[ii])->kxrcf; 296 | // rtp000=(points4out[j].mcell[ii])->vorM; 297 | // tm_tdiv+=vol*(points4out[j].mcell[ii])->tdiv; 298 | tm_tdiv+=vol*rtp000; 299 | } 300 | 301 | u/=volsum; 302 | v/=volsum; 303 | den/=volsum; 304 | p/=volsum; 305 | tm_tdiv/=volsum; 306 | 307 | entrpy = p/pow(den,GAMMA); 308 | erss=fabs(initP/pow(initQ,GAMMA)-entrpy)/(initP/pow(initQ,GAMMA)); 309 | tp = 0.5 * den * (u *u + v * v) + p; 310 | tper = fabs(tp-0.5*initQ*(uFree*uFree + vFree*vFree)-initP); 311 | 312 | ma=sqrt(u*u+v*v)/sqrt(GAMMA*p/den); 313 | 314 | fpxx< ::iterator ik=cellPoints.begin();ik!=cellPoints.end(); ++ik) 319 | { 320 | for(int i=0;i<4;i++) 321 | { 322 | fpxx<second.iPoint[i]<<" "; 323 | 324 | } 325 | fpxx<<"\n"; 326 | } 327 | 328 | for (int jj=0; jjcell; 374 | for(i=0;i<4;++i) fp1<dof[i][0]<<" "; 375 | fp1<<"\n"; 376 | current = current->next; 377 | } 378 | fp1.close(); 379 | } 380 | 381 | void read4restart() 382 | { 383 | Node *current; 384 | int i,j; 385 | current = HeadListAllGrid; 386 | OctCell *pcell0; 387 | ifstream fp1; 388 | fp1.open("IN//restart_data"); 389 | current = HeadListAllGrid; 390 | while(current != NULL) 391 | { 392 | pcell0 = current->cell; 393 | for(i=0;i<4;++i){ 394 | fp1>>pcell0->dof[i][0]; 395 | pcell0->dof0[i][0]=pcell0->dof[i][0]; 396 | for(j=1;jdof[i][j]=0.0; 398 | } 399 | 400 | current = current->next; 401 | } 402 | fp1.close(); 403 | } 404 | 405 | 406 | 407 | 408 | 409 | -------------------------------------------------------------------------------- /point_half_circle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include"vec2d.h" 6 | const double PI = 3.14159265358979; 7 | using namespace std; 8 | const double rrr=0.5; 9 | int main() 10 | { 11 | ofstream fpxx; 12 | double theta=20.0; 13 | double stp; 14 | int NWallPts=100; 15 | int n0=60;// the number of equal spatial 16 | double x0,y0; 17 | x0=0.0; 18 | y0=0.0; 19 | Vec2D vec0; 20 | Vec2D pt0; 21 | Vec2D pt1; 22 | Vec2D nml0; 23 | 24 | int tn; 25 | tn=n0+NWallPts; 26 | cout<<"total point "< Polygon; 32 | 33 | 34 | 35 | // 计算叉乘 |P0P1| × |P0P2| 36 | 37 | double Multiply(Point p1, Point p2, Point p0) 38 | 39 | { 40 | 41 | return ( (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y) ); 42 | 43 | } 44 | 45 | // 判断线段是否包含点point 46 | 47 | bool IsOnline(Point point, LineSegment line) 48 | 49 | { 50 | 51 | return( ( fabs(Multiply(line.pt1, line.pt2, point)) < ESP ) && 52 | 53 | ( ( point.x - line.pt1.x ) * ( point.x - line.pt2.x ) <= 0 ) && 54 | 55 | ( ( point.y - line.pt1.y ) * ( point.y - line.pt2.y ) <= 0 ) ); 56 | 57 | } 58 | 59 | // 判断线段相交 60 | 61 | bool Intersect(LineSegment L1, LineSegment L2) 62 | 63 | { 64 | 65 | return( (max(L1.pt1.x, L1.pt2.x) >= min(L2.pt1.x, L2.pt2.x)) && 66 | 67 | (max(L2.pt1.x, L2.pt2.x) >= min(L1.pt1.x, L1.pt2.x)) && 68 | 69 | (max(L1.pt1.y, L1.pt2.y) >= min(L2.pt1.y, L2.pt2.y)) && 70 | 71 | (max(L2.pt1.y, L2.pt2.y) >= min(L1.pt1.y, L1.pt2.y)) && 72 | 73 | (Multiply(L2.pt1, L1.pt2, L1.pt1) * Multiply(L1.pt2, L2.pt2, L1.pt1) >= 0) && 74 | 75 | (Multiply(L1.pt1, L2.pt2, L2.pt1) * Multiply(L2.pt2, L1.pt2, L2.pt1) >= 0) 76 | 77 | ); 78 | 79 | } 80 | 81 | // 判断点在多边形内 82 | 83 | bool InPolygon(const Polygon& polygon, Point point) 84 | 85 | { 86 | 87 | int n = polygon.size(); 88 | 89 | int count = 0; 90 | 91 | LineSegment line; 92 | 93 | line.pt1 = point; 94 | 95 | line.pt2.y = point.y; 96 | 97 | line.pt2.x = - INFINITY; 98 | 99 | 100 | 101 | for( int i = 0; i < n; i++ ) { 102 | 103 | // 得到多边形的一条边 104 | 105 | LineSegment side; 106 | 107 | side.pt1 = polygon[i]; 108 | 109 | side.pt2 = polygon[(i + 1) % n]; 110 | 111 | 112 | 113 | if( IsOnline(point, side) ) { 114 | 115 | return 1 ; 116 | 117 | } 118 | 119 | 120 | 121 | // 如果side平行x轴则不作考虑 122 | 123 | if( fabs(side.pt1.y - side.pt2.y) < ESP ) { 124 | 125 | continue; 126 | 127 | } 128 | 129 | 130 | 131 | if( IsOnline(side.pt1, line) ) { 132 | 133 | if( side.pt1.y > side.pt2.y ) count++; 134 | 135 | } else if( IsOnline(side.pt2, line) ) { 136 | 137 | if( side.pt2.y > side.pt1.y ) count++; 138 | 139 | } else if( Intersect(line, side) ) { 140 | 141 | count++; 142 | 143 | } 144 | 145 | } 146 | 147 | 148 | 149 | if ( count % 2 == 1 ) {return 0;} 150 | 151 | else { return 2;} 152 | 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /point_quad.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include"vec2d.h" 6 | const double PI = 3.14159265358979; 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ofstream fpxx; 12 | double theta=20.0; 13 | int n0=78;// the number of equal spatial 14 | int n1=78; 15 | int n2=78; 16 | int n3=78; 17 | Vec2D pt0(-3.0,2.0); 18 | Vec2D pt1(-3.0,-2.0); 19 | Vec2D pt2(5.0,-2.0); 20 | Vec2D pt3(5.0,2.0); 21 | /*int n0=30;// the number of equal spatial 22 | int n1=100; 23 | int n2=10; 24 | int n3=100; 25 | Vec2D pt0(0.0,2.0); 26 | Vec2D pt1(0.0,0.0); 27 | Vec2D pt2(8.0,0.0); 28 | Vec2D pt3(8.0,0.8);*/ 29 | 30 | Vec2D nml0, nml1,nml2,nml3; 31 | Vec2D vec0; 32 | 33 | nml0=(pt1-pt0).norm(); 34 | nml1=(pt2-pt1).norm(); 35 | nml2=(pt3-pt2).norm(); 36 | nml3=(pt0-pt3).norm(); 37 | 38 | double h0=fabs(pt1-pt0)/n0; 39 | double h1=fabs(pt2-pt1)/n1; 40 | double h2=fabs(pt2-pt3)/n2; 41 | double h3=fabs(pt0-pt3)/n3; 42 | 43 | double db1; 44 | int tn; 45 | tn=n0+1+n1+n2+n3-1; 46 | cout<<"total point "< 2 | #include 3 | #include 4 | #include 5 | const double PI = 3.14159265358979; 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | ofstream fpxx; 11 | double h=1.0; 12 | double theta=30.0; 13 | int nx=100; 14 | int ny=100; 15 | double hx,hy; 16 | double db_tmp; 17 | int tn; 18 | tn=nx+1+ny+nx-1; 19 | cout<<"total point "<0;--i){ 39 | fpxx<>r1>>r1>>jb1.q>>jb1.u>>jb1.v>>jb1.p>>r1>>r1; 29 | jbblToShbl(&jb1,&sh1); 30 | 31 | lsbl->dof0[0][0]=lsbl->dof[0][0]=sh1.q; 32 | lsbl->dof0[1][0]=lsbl->dof[1][0]=sh1.qu; 33 | lsbl->dof0[2][0]=lsbl->dof[2][0]=sh1.qv; 34 | lsbl->dof0[3][0]=lsbl->dof[3][0]=sh1.te; 35 | 36 | for(int imm=0;imm<4;++imm) 37 | for(int i=1; i<=nDOF-1; i++) 38 | lsbl->dof0[imm][i]=lsbl->dof[imm][i]=0.0; 39 | } 40 | } 41 | */ 42 | 43 | void output4restart() 44 | { 45 | Node *current; 46 | int i; 47 | current = HeadListAllGrid; 48 | OctCell *pcell0; 49 | ofstream fp1; 50 | fp1.open("restart_data2"); 51 | current = HeadListAllGrid; 52 | while(current != NULL) 53 | { 54 | pcell0 = current->cell; 55 | for(i=0;i<4;++i) fp1<dof[i][0]<<" "; 56 | fp1<<"\n"; 57 | current = current->next; 58 | } 59 | fp1.close(); 60 | } 61 | 62 | void read4restart() 63 | { 64 | Node *current; 65 | int i,j; 66 | current = HeadListAllGrid; 67 | OctCell *pcell0; 68 | ifstream fp1; 69 | fp1.open("IN//restart_data"); 70 | current = HeadListAllGrid; 71 | while(current != NULL) 72 | { 73 | pcell0 = current->cell; 74 | for(i=0;i<4;++i){ 75 | fp1>>pcell0->dof[i][0]; 76 | pcell0->dof0[i][0]=pcell0->dof[i][0]; 77 | for(j=1;jdof[i][j]=0.0; 79 | } 80 | 81 | current = current->next; 82 | } 83 | fp1.close(); 84 | } 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /riemann.cpp: -------------------------------------------------------------------------------- 1 | /* riemann.cpp 2 | * 3 | * Exact Riemann solver for the Euler equations in one dimension 4 | * Translated from the Fortran code er1pex.f and er1pex.ini 5 | * by Dr. E.F. Toro downloaded from 6 | * http://www.numeritek.com/numerica_software.html#freesample 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | using namespace std; 16 | #include"non_uniform_grid.h" 17 | 18 | // global variables 19 | 20 | const double gama=GAMMA; // ratio of specific heats 21 | 22 | static double g1 = (gama - 1.0)/(2.0*gama); 23 | static double g2 = (gama + 1.0)/(2.0*gama); 24 | static double g3 = 2.0*gama/(gama - 1.0); 25 | static double g4 = 2.0/(gama - 1.0); 26 | static double g5 = 2.0/(gama + 1.0); 27 | static double g6 = (gama - 1.0)/(gama + 1.0); 28 | static double g7 = (gama - 1.0)/2.0; 29 | static double g8 = gama - 1.0; 30 | 31 | /* 32 | double // density, velocity, pressure, speed of sound 33 | dl, ul, pl, cl, // in left region 34 | dr, ur, pr, cr; // in right region 35 | void initialize( 36 | const int test, // test number of input data set in e1rpex.ini 37 | double &domlen, // domain length 38 | double &diaph1, // position of diaphragm 39 | int &cells, // number of cells in evaluating exact solution 40 | double &timeou, // output time 41 | double &pscale) // normalizing factor for pressure and energy 42 | { 43 | domlen = 1.0; // same for all tests 44 | cells = 1000; // same for all tests 45 | pscale = 1.0; // same for all tests 46 | 47 | double values[][9] = { 48 | // diaph1, gama, timeou, dl, ul, pl, dr, ur, pr 49 | { 0, 0, 0, 0, 0, 0, 0, 0, 0}, // no TEST 0 50 | // TEST 1 (Modified Sod) 51 | {0.3, 1.4, 0.20, 1.0, 0.75, 1.0, 0.125, 0.0, 0.1}, 52 | // TEST 2 (123 problem) 53 | {0.5, 1.4, 0.15, 1.0, -2.0, 0.4, 1.0, 2.0, 0.4}, 54 | // TEST 3 (Left Woodward & Colella) 55 | {0.5, 1.4, 0.012, 1.0, 0.0, 1000.0, 1.0, 0.0, 0.01}, 56 | // TEST 4 (Collision of 2 shocks) 57 | {0.4, 1.4, 0.035, 5.99924, 19.5975, 460.894, 5.99242, 58 | -6.19633, 46.0950}, 59 | // TEST 5 (Stationary contact) 60 | {0.8, 1.4, 0.012, 1.0, -19.59745, 1000.0, 1.0, -19.59745, 0.01} 61 | }; 62 | 63 | diaph1 = values[test][0]; 64 | gama = values[test][1]; 65 | timeou = values[test][2]; 66 | dl = values[test][3]; 67 | ul = values[test][4]; 68 | pl = values[test][5]; 69 | dr = values[test][6]; 70 | ur = values[test][7]; 71 | pr = values[test][8]; 72 | } 73 | */ 74 | 75 | void guessp(double dl, double ul, double pl, double cl, 76 | double dr, double ur, double pr,double cr, double &pm) 77 | { 78 | // purpose: to provide a guessed value for pressure 79 | // pm in the Star Region. The choice is made 80 | // according to adaptive Riemann solver using 81 | // the PVRS, TRRS and TSRS approximate 82 | // Riemann solvers. See Sect. 9.5 of Chapt. 9 of Ref. 1 83 | 84 | double cup, gel, ger, pmax, pmin, ppv, pq, ptl, ptr, 85 | qmax, quser, um; 86 | 87 | quser = 2.0; 88 | 89 | // compute guess pressure from PVRS Riemann solver 90 | cup = 0.25*(dl + dr)*(cl + cr); 91 | ppv = 0.5*(pl + pr) + 0.5*(ul - ur)*cup; 92 | ppv = max(0.0, ppv); 93 | pmin = min(pl, pr); 94 | pmax = max(pl, pr); 95 | qmax = pmax/pmin; 96 | 97 | if (qmax <= quser && (pmin <= ppv && ppv <= pmax)) 98 | pm = ppv; // select PVRS Riemann solver 99 | else { 100 | if (ppv < pmin) { 101 | // select Two-Rarefaction Riemann solver 102 | pq = pow(pl/pr, g1); 103 | um = (pq*ul/cl + ur/cr + g4*(pq - 1.0))/(pq/cl + 1.0/cr); 104 | ptl = 1.0 + g7*(ul - um)/cl; 105 | ptr = 1.0 + g7*(um - ur)/cr; 106 | pm = 0.5*(pow(pl*ptl, g3) + pow(pr*ptr, g3)); 107 | } else { 108 | // select Two-Shock Riemann solver with PVRS as estimate 109 | gel = sqrt((g5/dl)/(g6*pl + ppv)); 110 | ger = sqrt((g5/dr)/(g6*pr + ppv)); 111 | pm = (gel*pl + ger*pr - (ur - ul))/(gel + ger); 112 | } 113 | } 114 | } 115 | 116 | void prefun( 117 | double &f, 118 | double &fd, 119 | double &p, 120 | double &dk, 121 | double &pk, 122 | double &ck) 123 | { 124 | // purpose: to evaluate the pressure functions 125 | // fl and fr in exact Riemann solver 126 | // and their first derivatives 127 | 128 | double ak, bk, pratio, qrt; 129 | 130 | if (p <= pk) { 131 | // rarefaction wave 132 | pratio = p/pk; 133 | f = g4*ck*(pow(pratio, g1) - 1.0); 134 | fd = (1.0/(dk*ck))*pow(pratio, -g2); 135 | } else { 136 | // shock wave 137 | ak = g5/dk; 138 | bk = g6*pk; 139 | qrt = sqrt(ak/(bk + p)); 140 | f = (p - pk)*qrt; 141 | fd = (1.0 - 0.5*(p - pk)/(bk + p))*qrt; 142 | } 143 | } 144 | 145 | void starpu(double dl, double ul, double pl, double cl, double dr, double ur, double pr,double cr, 146 | double &p, 147 | double &u, 148 | const double pscale) 149 | { 150 | // purpose: to compute the solution for pressure and 151 | // velocity in the Star Region 152 | 153 | const int nriter = 20; 154 | const double tolpre = 1.0e-6; 155 | double change, fl, fld, fr, frd, pold, pstart, udiff; 156 | 157 | // guessed value pstart is computed 158 | guessp(dl,ul,pl,cl,dr,ur,pr,cr,pstart); 159 | pold = pstart; 160 | udiff = ur - ul; 161 | 162 | // cout << "----------------------------------------\n" 163 | // << " Iteration number Change\n" 164 | // << "----------------------------------------" << endl; 165 | 166 | int i = 1; 167 | for ( ; i <= nriter; i++) { 168 | prefun(fl, fld, pold, dl, pl, cl); 169 | prefun(fr, frd, pold, dr, pr, cr); 170 | p = pold - (fl + fr + udiff)/(fld + frd); 171 | change = 2.0*fabs((p - pold)/(p + pold)); 172 | // cout << '\t' << i << "\t\t" << change << endl; 173 | if (change <= tolpre) 174 | break; 175 | if (p < 0.0) 176 | p = tolpre; 177 | pold = p; 178 | } 179 | if (i > nriter) 180 | cout << "divergence in Newton-Raphson iteration" << endl; 181 | 182 | // compute velocity in star region 183 | u = 0.5*(ul + ur + fr - fl); 184 | // cout << "----------------------------------------\n" 185 | // << " Pressure Velocity\n" 186 | // << "----------------------------------------\n" 187 | // << " " << p/pscale << "\t\t" << u << '\n' 188 | // << "----------------------------------------" << endl; 189 | } 190 | 191 | void sample(double dl, double ul, double pl, double cl, double dr, double ur, double pr,double cr, 192 | const double pm, 193 | const double um, 194 | const double s, 195 | double &d, 196 | double &u, 197 | double &p) 198 | { 199 | // purpose: to sample the solution throughout the wave 200 | // pattern. Pressure pm and velocity um in the 201 | // star region are known. Sampling is performed 202 | // in terms of the 'speed' s = x/t. Sampled 203 | // values are d, u, p 204 | 205 | double c, cml, cmr, pml, pmr, shl, shr, sl, sr, stl, str; 206 | 207 | if (s <= um) { 208 | // sampling point lies to the left of the contact discontinuity 209 | if (pm <= pl) { 210 | // left rarefaction 211 | shl = ul - cl; 212 | if (s <= shl) { 213 | // sampled point is left data state 214 | d = dl; 215 | u = ul; 216 | p = pl; 217 | } else { 218 | cml = cl*pow(pm/pl, g1); 219 | stl = um - cml; 220 | if (s > stl) { 221 | // sampled point is star left state 222 | d = dl*pow(pm/pl, 1.0/gama); 223 | u = um; 224 | p = pm; 225 | } else { 226 | // sampled point is inside left fan 227 | u = g5*(cl + g7*ul + s); 228 | c = g5*(cl + g7*(ul - s)); 229 | d = dl*pow(c/cl, g4); 230 | p = pl*pow(c/cl, g3); 231 | } 232 | } 233 | } else { 234 | // left shock 235 | pml = pm/pl; 236 | sl = ul - cl*sqrt(g2*pml + g1); 237 | if (s <= sl) { 238 | // sampled point is left data state 239 | d = dl; 240 | u = ul; 241 | p = pl; 242 | } else { 243 | // sampled point is star left state 244 | d = dl*(pml + g6)/(pml*g6 + 1.0); 245 | u = um; 246 | p = pm; 247 | } 248 | } 249 | } else { 250 | // sampling point lies to the right of the contact discontinuity 251 | if (pm > pr) { 252 | // right shock 253 | pmr = pm/pr; 254 | sr = ur + cr*sqrt(g2*pmr + g1); 255 | if (s >= sr) { 256 | // sampled point is right data state 257 | d = dr; 258 | u = ur; 259 | p = pr; 260 | } else { 261 | // sampled point is star right state 262 | d = dr*(pmr + g6)/(pmr*g6 + 1.0); 263 | u = um; 264 | p = pm; 265 | } 266 | } else { 267 | // right rarefaction 268 | shr = ur + cr; 269 | if (s >= shr) { 270 | // sampled point is right data state 271 | d = dr; 272 | u = ur; 273 | p = pr; 274 | } else { 275 | cmr = cr*pow(pm/pr, g1); 276 | str = um + cmr; 277 | if (s <= str) { 278 | // sampled point is star right state 279 | d = dr*pow(pm/pr, 1.0/gama); 280 | u = um; 281 | p = pm; 282 | } else { 283 | // sampled point is inside left fan 284 | u = g5*(-cr + g7*ur + s); 285 | c = g5*(cr - g7*(ur - s)); 286 | d = dr*pow(c/cr, g4); 287 | p = pr*pow(c/cr, g3); 288 | } 289 | } 290 | } 291 | } 292 | } 293 | 294 | int main(int argc, char *argv[]) 295 | { 296 | int cells; // number of cells in evaluating exact solution 297 | double 298 | domlen, // domain length 299 | diaph1, // position of diaphragm 1 300 | timeou, // output time 301 | pscale, // normalizing constant 302 | ds, dx, pm, ps, s, um, us, xpos; 303 | 304 | int test = 1; 305 | if (argc > 1) { 306 | // read first command line argument as test number 307 | istringstream is(argv[1]); 308 | is >> test; 309 | if (test < 1 || test > 5) { 310 | cerr << "test number not in range 1..5" << endl; 311 | exit(1); 312 | } 313 | } 314 | 315 | initialize(test, domlen, diaph1, cells, timeou, pscale); 316 | 317 | // compute gamma related constants 318 | g1 = (gama - 1.0)/(2.0*gama); 319 | g2 = (gama + 1.0)/(2.0*gama); 320 | g3 = 2.0*gama/(gama - 1.0); 321 | g4 = 2.0/(gama - 1.0); 322 | g5 = 2.0/(gama + 1.0); 323 | g6 = (gama - 1.0)/(gama + 1.0); 324 | g7 = (gama - 1.0)/2.0; 325 | g8 = gama - 1.0; 326 | 327 | // compute sound speeds 328 | cl = sqrt(gama*pl/dl); 329 | cr = sqrt(gama*pr/dr); 330 | 331 | // the pressure positivity condition is tested for 332 | if (g4*(cl+cr) <= (ur-ul)) { 333 | 334 | cerr << "the initial data is such that vacuum is generated" 335 | << "\nstopping program" << endl; 336 | exit(1); 337 | } 338 | 339 | // exact solution for pressure and velocity in star region is found 340 | starpu(pm, um, pscale); 341 | dx = domlen/double(cells); 342 | 343 | // complete solution at time timeou is found 344 | ofstream file("riemann.data"); 345 | for (int i = 0; i < cells; i++) { 346 | xpos = (i - 0.5)*dx; 347 | s = (xpos - diaph1)/timeou; 348 | 349 | // solution at point (x,t) = (xpos-diaph1, timeou) is found 350 | sample(pm, um, s, ds, us, ps); 351 | 352 | // exact solution profiles are written to data file 353 | file << xpos << '\t' << ds << '\t' << us << '\t' 354 | << ps/pscale << '\t' << ps/ds/g8/pscale << '\n'; 355 | } 356 | } 357 | 358 | void solveERS(double dl,double ul, double pl,double dr,double ur, 359 | double pr, double *dil,double *dir,double *ui,double *pi) 360 | { 361 | double cl,cr; 362 | double pscale=1.0, // normalizing constant 363 | ds, dx, pm, ps, s, um, us, xpos; 364 | cl = sqrt(gama*pl/dl); 365 | cr = sqrt(gama*pr/dr); 366 | // the pressure positivity condition is tested for 367 | if (g4*(cl+cr) <= (ur-ul)) { 368 | *dil=dl; 369 | *dir=dr; 370 | *ui=(ul+ur); 371 | *pi=0.5*(pl+pr); 372 | return; 373 | } 374 | 375 | starpu(dl,ul,pl,cl,dr,ur,pr,cr,pm, um, pscale); 376 | 377 | s=0.0; 378 | sample(dl,ul,pl,cl,dr,ur,pr,cr,pm, um, s, ds, us, ps); 379 | *dir=ds; 380 | *ui=us; 381 | *pi=ps; 382 | 383 | 384 | 385 | 386 | -------------------------------------------------------------------------------- /riemannWallBound.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include"non_uniform_grid.h" 3 | 4 | const double gama=GAMMA; 5 | 6 | const double g1 = (gama - 1.0)/(2.0*gama); 7 | const double g2 = (gama + 1.0)/(2.0*gama); 8 | const double g3 = 2.0*gama/(gama - 1.0); 9 | const double g4 = 2.0/(gama - 1.0); 10 | const double g5 = 2.0/(gama + 1.0); 11 | const double g6 = (gama - 1.0)/(gama + 1.0); 12 | const double g7 = (gama - 1.0)/2.0; 13 | const double g8 = gama - 1.0; 14 | //here n normal to wall(from fluid to wall) 15 | void solveERS(double dl,double ul, double pl, 16 | double uw, double *di,double *pi) 17 | { 18 | double cM, A_M,B_M,aM; 19 | double du0; 20 | cM=ul-uw; 21 | A_M=g5/dl; 22 | B_M=pl*g6; 23 | 24 | du0=ul-uw; 25 | aM=sqrt(gama*pl/dl); 26 | 27 | if(du0<0.0){ 28 | *pi=pl*pow(1.0+g7*cM/aM, g3); 29 | *di=dl*pow(*pi/pl, 1.0/gama); 30 | } 31 | else 32 | { 33 | *pi=pl+cM*0.5/A_M*(cM+sqrt(cM*cM+4.0*A_M*(B_M+pl))); 34 | *di=dl*(*pi/pl+g6)/(g6*(*pi)/pl+1.0); 35 | } 36 | } 37 | 38 | //hr 参考点到墙的距离,hg壁面到ghost点的距离 39 | 40 | void reflectionRie(double hr,double hg, double vw,double U[4], PXYZ *nml, JBBL *jbugst) 41 | { 42 | double tx,ty,nx,ny; 43 | nx=nml->x; 44 | ny=nml->y; 45 | tx=ny; 46 | ty=-nx; 47 | Vec2D ndir(nx,ny); 48 | Vec2D tdir(tx,ty); 49 | Vec2D ur(U[1],U[2]); 50 | double un1,ut1,un2,ut2; 51 | un1=ur.dot(ndir); 52 | ut1=ur.dot(tdir); 53 | un2=-(hg/hr)*un1; 54 | ut2=ut1; 55 | 56 | jbugst->u = (ny * ut2 - ty * un2)/(tx * ny - nx * ty); 57 | jbugst->v = (tx * un2 - nx * ut2)/(tx * ny - nx * ty); 58 | double dw,pw; 59 | 60 | solveERS(U[0],-un1,U[3],vw,&dw,&pw); 61 | 62 | // jbugst->p=U[3]; 63 | // jbugst->q=U[0]; 64 | jbugst->p=pw+hg/hr*(pw-U[3]); 65 | jbugst->q=dw+hg/hr*(dw-U[0]); 66 | // jbugst->p=pw; 67 | // jbugst->q=dw; 68 | if(jbugst->p<1.0e-13 || jbugst->q < 1.0e-13|| 69 | pw<1.0e-13|| dw<1.0e-13){ 70 | jbugst->p=U[3]; 71 | jbugst->q=U[0]; 72 | } 73 | } 74 | 75 | 76 | double getWallCurvatureRadius(const PXYZ *pt, PXYZ &ndir); 77 | double getWallCurvatureRadius(const PXYZ *pt); 78 | 79 | void reflectionRieQVLV(double hr,double hg, double vw,double U[4], PXYZ *nml, const PXYZ *wpt, JBBL *jbugst) 80 | { 81 | double rd,tx,ty,nx,ny; 82 | nx=nml->x; 83 | ny=nml->y; 84 | tx=ny; 85 | ty=-nx; 86 | rd=getWallCurvatureRadius(wpt); 87 | Vec2D ndir(nx,ny); 88 | Vec2D tdir(tx,ty); 89 | Vec2D ur(U[1],U[2]); 90 | double un1,ut1,un2,ut2; 91 | un1=ur.dot(ndir); 92 | ut1=ur.dot(tdir); 93 | un2=-(hg/hr)*un1; 94 | ut2=ut1; 95 | 96 | jbugst->u = (ny * ut2 - ty * un2)/(tx * ny - nx * ty); 97 | jbugst->v = (tx * un2 - nx * ut2)/(tx * ny - nx * ty); 98 | double dw,pw; 99 | 100 | solveERS(U[0],-un1,U[3],vw,&dw,&pw); 101 | 102 | jbugst->p=pw+hg*((pw-U[3])/hr-dw*ut2*ut2/rd); 103 | jbugst->q=dw+hg/hr*(dw-U[0]); 104 | if(jbugst->p<1.0e-13|| jbugst->q<1.0e-13 105 | || pw<1.0e-13||dw<1.0e-13){ 106 | jbugst->p=U[3]; 107 | jbugst->q=U[0]; 108 | } 109 | } 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /rk.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/rk.cpp -------------------------------------------------------------------------------- /roe.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/roe.cpp -------------------------------------------------------------------------------- /setflag.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include"non_uniform_grid.h" 3 | #include"findneighbor.h" 4 | 5 | int newFlagpoint(double x, double y, int NumberAirfoilPoint,PXYZ wallpoint[] ); 6 | //应用射线方法 //in the solid flag==-1, out the solid flag=0 7 | //at the surface of the solid flag=2 8 | extern Node *HeadListAllGrid; 9 | extern PXYZ MultiCircle[N_BODY+1][500]; //points at solid wall 10 | extern int NWallPts[N_BODY+3]; 11 | //int newFlagpoint(double x, double y);////应用射线方法 12 | //网格中心在airfoil中的为-1流场内部为0 在翼型上的为2, 尖后缘为4 13 | //网格中心在流体中的为0,网格中心在固体内部且和流体网格相邻的为2其他网格为-1, TODO 多值点 14 | void setFlagForAll() 15 | { 16 | Node *current; 17 | OctCell *lsbl; 18 | OctCell *lss; 19 | OctCell *lse; 20 | OctCell *lsw; 21 | OctCell *lsn; 22 | double x1,y1; 23 | int value, flg[N_BODY+1]; 24 | 25 | current = HeadListAllGrid; 26 | 27 | double xcn[4],ycn[4]; 28 | int flgn[4], sflg; 29 | int i; 30 | int n0,n2,nm; 31 | 32 | while(current != NULL) 33 | { 34 | lsbl = current->cell; 35 | 36 | x1=lsbl->xc1; 37 | y1=lsbl->yc1; 38 | 39 | for (int jj=0; jjxc1; 50 | ycn[0]=lss->yc1; 51 | xcn[1]=lse->xc1; 52 | ycn[1]=lse->yc1; 53 | xcn[2]=lsn->xc1; 54 | ycn[2]=lsn->yc1; 55 | xcn[3]=lsw->xc1; 56 | ycn[3]=lsw->yc1; 57 | sflg=0; 58 | for(i=0; i<4; ++i) { 59 | flgn[i]=newFlagpoint(xcn[i],ycn[i],NWallPts[jj], MultiCircle[jj]); 60 | 61 | if(flgn[i]==0) { 62 | flg[jj]=2; 63 | ++sflg; 64 | break; 65 | } 66 | } 67 | 68 | if(sflg==0) flg[jj]=-1; 69 | } 70 | } 71 | n0=n2=nm=0; 72 | 73 | for (int jj=0; jjflag=0; 80 | else if(n2>0) lsbl->flag=2; 81 | else lsbl->flag=-1; 82 | current=current->next; 83 | } 84 | } 85 | // 86 | //网格中心在流体中的为0,网格中心在固体内部且和流体网格相邻的为2其他网格为-1, TODO 多值点 87 | //in order to solve internal flow problem 88 | ////网格中心在固壁内部的为-1流场内部为0 在翼型上的为2, 尖后缘为4 89 | void set_exFlag4All(int nmpnt, PXYZ wallpt[]) 90 | { 91 | Node *current; 92 | OctCell *lsbl; 93 | OctCell *lsbl1[4]; 94 | double x1,y1; 95 | int value, flg=0; 96 | 97 | double xcn[4],ycn[4]; 98 | int flgn[4], sflg; 99 | 100 | current = HeadListAllGrid; 101 | while(current != NULL) 102 | { 103 | lsbl = current->cell; 104 | 105 | x1=lsbl->xc1; 106 | y1=lsbl->yc1; 107 | flg=0; 108 | 109 | value = newFlagpoint(x1,y1,nmpnt, wallpt); 110 | if(value==0 ) { 111 | flg=-1; 112 | lsbl->flag=-1; /// 113 | } 114 | lsbl->exflag=flg; 115 | current=current->next; 116 | } 117 | //cout<<"it is ok\n"; 118 | 119 | current = HeadListAllGrid; 120 | while(current != NULL) 121 | { 122 | lsbl = current->cell; 123 | if(lsbl->exflag==-1){ 124 | if(current->flg!=6) 125 | { 126 | //----------------------- 127 | lsbl1[0]=SouthNeighbor(lsbl); 128 | lsbl1[1]=EastNeighbor(lsbl); 129 | lsbl1[2]=NorthNeighbor(lsbl); 130 | lsbl1[3]=WestNeighbor(lsbl); 131 | sflg=0; 132 | for(int i=0; i<4; ++i) { 133 | if(lsbl1[i]->exflag==0) { 134 | flg=2; 135 | ++sflg; 136 | break; 137 | } 138 | } 139 | 140 | if(sflg==0) flg=-1; 141 | lsbl->exflag=flg; 142 | } 143 | } 144 | current=current->next; 145 | } 146 | } 147 | 148 | void charggrid0(OctCell*); 149 | //flag=0:fluid cell, flag=-1:solid cell, flag=2:interface cell(只要相交) 150 | void setFlagForAll0() 151 | { 152 | Node *current; 153 | OctCell *lsbl; 154 | double x1,y1; 155 | int value, flg; 156 | 157 | current = HeadListAllGrid; 158 | 159 | double xcn[4],ycn[4]; 160 | int flgn[4], sflg; 161 | 162 | while(current != NULL) 163 | { 164 | lsbl = current->cell; 165 | 166 | charggrid0(lsbl); 167 | // lsbl->flag=flg; //here wrong 2012.4.20 168 | current=current->next; 169 | } 170 | cout<<"setFlagAll0 finished\n"; 171 | } 172 | 173 | -------------------------------------------------------------------------------- /solveAMR.cpp: -------------------------------------------------------------------------------- 1 | // solution AMR 2 | #include"non_uniform_grid.h" 3 | #include"findneighbor.h" 4 | extern vectorsolrefcell;//solution AMR cell 5 | extern vectorsolcoacell;//solution coase cell 6 | extern setColCoa; 7 | 8 | extern vector faces_comp; 9 | extern Node *HeadListAllGrid; 10 | 11 | static int N_total_adpcell=0; 12 | static double Sigma_curl=0.0; 13 | static double Sigma_div=0.0;//旋度和散度的标准差 14 | static double Sigma_pio=0.0; //压力梯度 15 | //计算自适应参数的均方根 16 | // 17 | 18 | extern Vec2D ExtPnt0; 19 | extern Vec2D ExtPnt1; 20 | extern Vec2D ExtPnt2; 21 | extern Vec2D ExtPnt3; 22 | extern double sumVorM; 23 | //计算自适应参数 consider entropy 24 | 25 | void getCellVorM(OctCell *unp) 26 | { 27 | unp->vorM=(unp->Ux[2]-unp->Uy[1])*unp->dx*unp->dy; 28 | } 29 | 30 | void solveGradient(); 31 | void getAllVorM() 32 | { 33 | solveGradient(); 34 | 35 | Node *current; 36 | current = HeadListAllGrid; 37 | OctCell *lsbl; 38 | 39 | Vec2D tpvec; 40 | double jl0,jl1,jl2,jl3; 41 | double maxhxy; 42 | maxhxy=max2(hx,hy); 43 | sumVorM=0.0; 44 | 45 | while(current != NULL) 46 | { 47 | lsbl = current->cell; 48 | if(lsbl->flag == 0 && current->flg==0 49 | // && lsbl->xc1xc1>xInlet+1.0*hx 51 | // && lsbl->yc1>ExtPnt1[1]+1.0*hy 52 | // && lsbl->yc1xc1; 56 | tpvec[1]=lsbl->yc1; 57 | jl0=fabs(tpvec-ExtPnt0); 58 | jl1=fabs(tpvec-ExtPnt1); 59 | jl2=fabs(tpvec-ExtPnt2); 60 | jl3=fabs(tpvec-ExtPnt3); 61 | 62 | if(jl0>3.0*maxhxy && jl1>3.0*maxhxy 63 | && jl2 > 3.0*maxhxy && jl3>3.0*maxhxy){ 64 | #endif 65 | getCellVorM(lsbl); 66 | 67 | sumVorM+=lsbl->vorM; 68 | 69 | #if IS_TUBE==1 70 | } 71 | #endif 72 | } 73 | current = current->next; 74 | } 75 | } 76 | 77 | void getAdaptiveParameters(OctCell *unp) 78 | { 79 | double li; 80 | li=pow(sqrt(unp->dx*unp->dy),1.5); 81 | unp->tcur=fabs(unp->Ux[2]-unp->Uy[1])*li; 82 | unp->vorM=(unp->Ux[2]-unp->Uy[1])*unp->dx*unp->dy; 83 | unp->tdiv=fabs(unp->Ux[1]+unp->Uy[2])*li; 84 | //0:den,1:press, 2:entropy,3: 85 | #if ADAPTIVE_INDICATOR==0 86 | unp->pio=sqrt((unp->Ux[0]*unp->Ux[0])+(unp->Uy[0]*unp->Uy[0]))*li; 87 | #elif ADAPTIVE_INDICATOR==1 88 | unp->pio=sqrt((unp->Ux[3]*unp->Ux[3])+(unp->Uy[3]*unp->Uy[3]))*li; 89 | #elif ADAPTIVE_INDICATOR==2 90 | double ason2, a2;//ason2:pressure 91 | ason2=GAM11*(unp->dof[3][0]-0.5*(unp->dof[1][0]*unp->dof[1][0] 92 | /unp->dof[0][0]+unp->dof[2][0]*unp->dof[2][0]/unp->dof[0][0])); 93 | a2=GAMMA*ason2/unp->dof[0][0]; 94 | unp->pio=(fabs(unp->Ux[3]-a2*unp->Ux[0]) 95 | +fabs(unp->Uy[3]-a2*unp->Uy[0]))*li; 96 | #elif ADAPTIVE_INDICATOR==3 97 | #else 98 | #endif 99 | } 100 | extern double sumVorM; 101 | void getAllAdpParametersList() 102 | { 103 | Node *current; 104 | current = HeadListAllGrid; 105 | OctCell *lsbl; 106 | 107 | Vec2D tpvec; 108 | double jl0,jl1,jl2,jl3; 109 | double maxhxy; 110 | Sigma_curl=0.0; 111 | Sigma_div=0.0; 112 | Sigma_pio=0.0; 113 | N_total_adpcell=0; 114 | maxhxy=max2(hx,hy); 115 | 116 | while(current != NULL) 117 | { 118 | lsbl = current->cell; 119 | if(lsbl->flag == 0 && current->flg==0 120 | // && lsbl->xc1xc1>xInlet+1.0*hx 122 | // && lsbl->yc1>ExtPnt1[1]+1.0*hy 123 | // && lsbl->yc1xc1; 127 | tpvec[1]=lsbl->yc1; 128 | jl0=fabs(tpvec-ExtPnt0); 129 | jl1=fabs(tpvec-ExtPnt1); 130 | jl2=fabs(tpvec-ExtPnt2); 131 | jl3=fabs(tpvec-ExtPnt3); 132 | 133 | if(jl0>3.0*maxhxy && jl1>3.0*maxhxy 134 | && jl2 > 3.0*maxhxy && jl3>3.0*maxhxy){ 135 | #endif 136 | getAdaptiveParameters(lsbl); 137 | 138 | Sigma_curl += lsbl->tcur * lsbl->tcur; 139 | Sigma_div += lsbl->tdiv *lsbl->tdiv; 140 | Sigma_pio+=lsbl->pio* lsbl->pio; 141 | 142 | ++N_total_adpcell; 143 | #if IS_TUBE==1 144 | } 145 | #endif 146 | } 147 | current = current->next; 148 | } 149 | Sigma_curl = sqrt(Sigma_curl/N_total_adpcell); 150 | Sigma_div = sqrt(Sigma_div/N_total_adpcell); 151 | Sigma_pio = sqrt(Sigma_pio/N_total_adpcell); 152 | } 153 | 154 | //判断哪些网格需要加密 155 | //int Namr=0; 156 | void charg_sol_grid(OctCell *pg)//pg为网格单元的指针 157 | { 158 | bool refflag; 159 | Vec2D tpvec; 160 | double jl0,jl1,jl2,jl3; 161 | double maxhxy; 162 | maxhxy=max2(hx,hy); 163 | switch(AMRP) 164 | { 165 | case 0: 166 | refflag=(pg->tcur > refine_coe*Sigma_curl 167 | || pg->tdiv > refine_coe1*Sigma_div); 168 | break; 169 | case 1: refflag=(pg->tdiv > refine_coe*Sigma_div); break; 170 | case 2: refflag=(pg->tcur > refine_coe*Sigma_curl); break; 171 | case 3: refflag=(pg->pio > refine_coe*Sigma_pio); break; 172 | case 4: 173 | refflag=(pg->tdiv > refine_coe*Sigma_div 174 | || pg->pio > refine_coe1*Sigma_pio); 175 | break; 176 | case 5: 177 | refflag=(pg->tdiv > refine_coe*Sigma_div || pg->trbamr); 178 | break; 179 | } 180 | 181 | if(refflag==true) 182 | { 183 | #if IS_TUBE==1 184 | tpvec[0]=pg->xc1; 185 | tpvec[1]=pg->yc1; 186 | jl0=fabs(tpvec-ExtPnt0); 187 | jl1=fabs(tpvec-ExtPnt1); 188 | jl2=fabs(tpvec-ExtPnt2); 189 | jl3=fabs(tpvec-ExtPnt3); 190 | 191 | if(jl0>3.0*maxhxy && jl1>3.0*maxhxy 192 | && jl2 > 3.0*maxhxy && jl3>3.0*maxhxy) 193 | #endif 194 | solrefcell.push_back(pg); 195 | 196 | //solrefcell[Namr]=pg;//用于存放需要加密的网格单元地址的数组 197 | //Namr++;//记录需要加密的网格单元的数目 198 | } 199 | } 200 | 201 | void charg_sol_gridAll()//判断哪些网格单元需要加密 202 | { 203 | Node *current; 204 | OctCell *lsbl; 205 | current = HeadListAllGrid; 206 | // Namr=0; //需要加密网格单元数目初始化 207 | solrefcell.clear(); 208 | while(current != NULL) 209 | { 210 | lsbl = current->cell; 211 | if(current->flg==0 && lsbl->flag==0 212 | #if NAR_MAXAMR==1 213 | && lsbl->level < lsbl->level0+Nar 214 | #elif NAR_MAXAMR==0 215 | && lsbl->level < MaxAMR 216 | #endif 217 | ) //最多只作MaxAMR次解自适应 218 | //20121111--------------------- 219 | // && lsbl->level < lsbl->level0+Nar) //最多只作Nar次解自适应 220 | { 221 | charg_sol_grid(lsbl); 222 | } 223 | current = current->next; 224 | } 225 | } 226 | 227 | //这个函数可以优化一下,对于pp使用set这样可以杜绝找到相同的地址值 228 | //找到需要加密的网格单元的周边网格(一层) 229 | void find_sol_refp(OctCell *pp[],OctCell *parent) 230 | { 231 | pp[0]=EastNeighbor(parent); 232 | pp[1]=WestNeighbor(parent); 233 | pp[2]=NorthNeighbor(parent); 234 | pp[3]=SouthNeighbor(parent); 235 | pp[4]=WestNeighbor(pp[2]); 236 | pp[5]=EastNeighbor(pp[2]); 237 | pp[6]=WestNeighbor(pp[3]); 238 | pp[7]=EastNeighbor(pp[3]); 239 | } 240 | 241 | void find_sol_4nbr(OctCell *pp[],OctCell *parent) 242 | { 243 | pp[0]=EastNeighbor(parent); 244 | pp[1]=WestNeighbor(parent); 245 | pp[2]=NorthNeighbor(parent); 246 | pp[3]=SouthNeighbor(parent); 247 | //pp[4]=WestNeighbor(pp[2]); 248 | //pp[5]=EastNeighbor(pp[2]); 249 | //pp[6]=WestNeighbor(pp[3]); 250 | //pp[7]=EastNeighbor(pp[3]); 251 | } 252 | 253 | int chargeleveldifference(OctCell *parent) 254 | { 255 | int i; 256 | OctCell *pp[8]={NULL}; 257 | int plevel,nlevel;//目标单元的层次-1,邻居单元的层次 258 | plevel=parent->level+1; 259 | find_sol_refp(pp,parent); 260 | for(i=0;i<8;i++) 261 | { 262 | if(pp[i]!=NULL)//here don't need if TODO 263 | { 264 | nlevel=pp[i]->level; 265 | if(abs(nlevel-plevel)>1) 266 | {break;} 267 | } 268 | } 269 | if(i==8) return(0); 270 | else return(1); 271 | } 272 | 273 | void charggrid(OctCell *pg); 274 | void charggrid0(OctCell *pg); 275 | 276 | void childrenvalue(OctCell *p1, OctCell *parent,int m,double hcx, double hcy); 277 | void childrenvalue(OctCell *p1,OctCell *parent,double hx,double hy,int m); 278 | void son_cell_value(OctCell *pcell, int nson, OctCell *pchild); 279 | //由父亲pcell得到它的孩子的moment使用L2投影 280 | void parent_cell_value(OctCell *pchildren[4], OctCell *pcell); 281 | //由四个孩子得到父亲的moment 282 | void creat_sol_children(OctCell *parent) 283 | { 284 | int j,m,preflag,dlevel; 285 | OctCell *children[4]={NULL}; 286 | //double plevel,hx,hy; 287 | double hx1,hy1; 288 | if(parent!=NULL)//here do not need if TODO 289 | { 290 | preflag=parent->reflag; 291 | dlevel=chargeleveldifference(parent); 292 | if(preflag==1||dlevel==1) return;//判断该网格单元是否加密 293 | else 294 | { 295 | // plevel=parent->level+1; 296 | // hx=Hx/pow(2.0,plevel);hy=Hy/pow(2.0,plevel);//子网格的步长 297 | hx1=0.5*parent->dx; 298 | hy1=0.5*parent->dy; 299 | for(m=0;m<4;++m) 300 | { 301 | //children[m]=(struct cell*)malloc(LENC); 302 | children[m]=new OctCell(hx1,hy1); 303 | 304 | parent->children[m]=children[m]; 305 | childrenvalue(children[m],parent,hx1,hy1,m); 306 | charggrid0(children[m]);// here I omit is right TODO 307 | } 308 | parent->reflag=1; 309 | // parent->p_node=NULL; 310 | } 311 | } 312 | 313 | for(m=0;m<4;m++) 314 | { 315 | children[m]->level0=parent->level0;// 316 | son_cell_value(parent,m,children[m]); 317 | } 318 | } 319 | //加密网格 320 | void creat_amr_grid() 321 | { 322 | int kr,Nk; 323 | int i,j,k,ir; 324 | OctCell *parent; 325 | 326 | // Nk=Namr-1;//需要加密的网格 327 | Nk=solrefcell.size()-1; 328 | //printf("refine solution grid number: Nk=%d\n",Nk); 329 | 330 | OctCell *pp[9]={NULL},*pc[9]={NULL},*p=NULL; 331 | //物面相交的网格邻近的需要加密的网格单元地址 332 | #if NAR_MAXAMR==1 333 | for(ir=0;ir<=Nr+Nar;ir++) 334 | #elif NAR_MAXAMR==0 335 | for(ir=0;irlevel==ir) 343 | { 344 | //找到需加密的网格邻近的需要加密的网格单元 345 | find_sol_refp(pp,parent); 346 | // find_sol_4nbr(pp,parent); 347 | pp[8]=parent; 348 | k=0; 349 | for(i=0;i<9;i++) 350 | { 351 | if(pp[i]!=NULL)//here do not need if TODO 352 | {pc[k]=pp[i];k++;} 353 | } 354 | //根据网格单元的层次对这些网格进行排序 355 | for(j=1;j<=k-1;j++) 356 | { 357 | for(i=1;i<=k-j;i++) 358 | if(pc[i-1]->level>pc[i]->level) 359 | {p=pc[i-1];pc[i-1]=pc[i];pc[i]=p;} 360 | } 361 | for(i=0;ireflag == 0) 364 | { 365 | //creat_sol_children(pc[i],pc[i]->cflag); 366 | creat_sol_children(pc[i]); 367 | // pc[i]->reflag=1; 368 | } 369 | } 370 | } 371 | } 372 | } 373 | cout<<"refine solution grid number: Nk= "<tcur tdiv tdiv tcur pio tdiv pio trbamr) 447 | && pg->tdiv exflag!=0) refflag=true; 449 | break; 450 | } 451 | #if IS_TUBE==1 452 | // if(pg->exflag!=0) refflag=true;//20121112 453 | #endif 454 | if(refflag==true && pg->level>pg->level0) 455 | { 456 | // solcoacell[Ncoar]=pg;//用于存放需要粗化的网格单元地址的数组 457 | solcoacell.push_back(pg); 458 | pg->coflag=true; 459 | // Ncoar++;//记录需要粗化的网格单元的数目 460 | } 461 | } 462 | 463 | void chargegridforcoarse() 464 | { 465 | Node *current; 466 | OctCell *lsbl; 467 | current = HeadListAllGrid; 468 | solcoacell.clear(); 469 | //Ncoar=0; //需要粗化网格单元数目初始化 470 | while(current != NULL) 471 | { 472 | lsbl = current->cell; 473 | #if IS_TUBE==0 474 | if(lsbl->flag== 0 475 | #elif IS_TUBE==1 476 | if((lsbl->flag== 0 || lsbl->exflag!=0) 477 | #endif 478 | && current->flg<=2) 479 | chargsolgridforcoarse(lsbl); 480 | current = current->next; 481 | } 482 | } 483 | 484 | //删除子网格单元,给父网格单元赋值 485 | void creatsolcoarseparent(OctCell *parent,OctCell *pp[4]) 486 | { 487 | for(int i=0;i<4;++i) { 488 | parent->dof[i][0]=0.25*(pp[0]->dof[i][0]+pp[1]->dof[i][0] 489 | +pp[2]->dof[i][0]+pp[3]->dof[i][0]); 490 | 491 | parent->dof[i][1]=0.125*(pp[0]->dof[i][1]+pp[1]->dof[i][1] 492 | +pp[2]->dof[i][1]+pp[3]->dof[i][1]) 493 | +0.375*(-pp[0]->dof[i][0]+pp[1]->dof[i][0] 494 | -pp[3]->dof[i][0]+pp[2]->dof[i][0]); 495 | 496 | parent->dof[i][2]=0.125*(pp[0]->dof[i][2]+pp[1]->dof[i][2] 497 | +pp[2]->dof[i][2]+pp[3]->dof[i][2]) 498 | +0.375*(-pp[0]->dof[i][0]-pp[1]->dof[i][0] 499 | +pp[3]->dof[i][0]+pp[2]->dof[i][0]); 500 | 501 | parent->dof[i][3]=0.0625*(pp[0]->dof[i][3]+pp[1]->dof[i][3] 502 | +pp[2]->dof[i][3]+pp[3]->dof[i][3]) 503 | +0.1875*(-pp[0]->dof[i][2]+pp[1]->dof[i][2] 504 | -pp[3]->dof[i][2]+pp[2]->dof[i][2]) 505 | +0.1875*(-pp[0]->dof[i][1]-pp[1]->dof[i][1] 506 | +pp[3]->dof[i][1]+pp[2]->dof[i][1]) 507 | +0.5625*(pp[0]->dof[i][0]-pp[1]->dof[i][0] 508 | -pp[3]->dof[i][0]+pp[2]->dof[i][0]); 509 | 510 | parent->dof[i][4]=0.0625*(pp[0]->dof[i][4]+pp[1]->dof[i][4] 511 | +pp[2]->dof[i][4]+pp[3]->dof[i][4]) 512 | +0.46875*(-pp[0]->dof[i][1]+pp[1]->dof[i][1] 513 | -pp[3]->dof[i][1]+pp[2]->dof[i][1]); 514 | 515 | parent->dof[i][5]=0.0625*(pp[0]->dof[i][5]+pp[1]->dof[i][5] 516 | +pp[2]->dof[i][5]+pp[3]->dof[i][5]) 517 | +0.46875*(-pp[0]->dof[i][2]-pp[1]->dof[i][2] 518 | +pp[3]->dof[i][2]+pp[2]->dof[i][2]); 519 | } 520 | parent->level0=pp[0]->level0; 521 | for(int i=0; i<4;++i){ 522 | parent->children[i]=NULL; 523 | if(pp[i]!=NULL)delete pp[i];//TODO 524 | // if(pp[i]!=NULL)ColCoa.insert(pp[i]);//TODO 525 | } 526 | } 527 | /*void release_ColCoa() 528 | { 529 | for(set::iterator iz=ColCoa.begin(); 530 | iz!= ColCoa.end();++iz){ 531 | delete *iz; 532 | } 533 | ColCoa.clear(); 534 | } 535 | */ 536 | 537 | int chargecoarselevel(OctCell *pc) 538 | { 539 | int i; 540 | OctCell *pp[8]={NULL}; 541 | find_sol_refp(pp,pc); 542 | for(i=0;i<4;i++) 543 | { 544 | if(pp[i]!=NULL&&pp[i]->reflag==1) 545 | //if(pp[i]->reflag==1) 546 | { 547 | break; 548 | } 549 | } 550 | if(i==4) return(0); 551 | else return(1); 552 | } 553 | 554 | //粗化网格 555 | void creatcoarsegrid() 556 | { 557 | int kr,Nk; 558 | int i,ppflag; 559 | OctCell *parent,*p; 560 | // Nk=Ncoar-1;//需要加密的网格 561 | Nk=solcoacell.size()-1; 562 | //printf("coarse solution grid number: Nk=%d\n",Nk); 563 | 564 | for(kr=0;kr<=Nk;kr++)//Nk与解自适应网格数 565 | { 566 | OctCell *pp[4]; 567 | //需要粗化的网格单元的兄弟网格单元的地址网格单元地址 568 | p= solcoacell[kr]; 569 | parent=p->parent; 570 | // printf("Kr=%d\n",kr); 571 | ppflag=0; 572 | if(parent!=NULL&&parent->reflag==1) 573 | // if(parent->reflag==1) 574 | { 575 | // NOchild=p->NOchildren; 576 | for(i=0;i<4;i++) 577 | { 578 | pp[i]=parent->children[i]; 579 | ppflag+=chargecoarselevel(pp[i]); 580 | } 581 | if(ppflag==0 && pp[0]->coflag==true 582 | && pp[1]->coflag==true && pp[2]->coflag==true 583 | && pp[3]->coflag==true )//四个子节点都要粗华则粗化 584 | { 585 | creatsolcoarseparent(parent,pp); 586 | parent->coflag=false; 587 | parent->reflag=0; 588 | } 589 | } 590 | } 591 | cout<<"coarse solution grid number: Nk= "<reflag==1&&pp[1]!=NULL&&pp[1]->reflag==1) 604 | ||(pp[2]!=NULL&&pp[2]->reflag==1&&pp[3]!=NULL&&pp[3]->reflag==1)) 605 | //if((pp[0]->reflag==1&&pp[1]->reflag==1) 606 | // ||(pp[2]->reflag==1&&pp[3]->reflag==1)) 607 | return(1); 608 | else 609 | return(0); 610 | } 611 | /**************************** 612 | 判断是否是hill grid 613 | ****************************/ 614 | int chargehillgrid(OctCell *pc) 615 | { 616 | OctCell *pp[8],*parent; 617 | parent=pc->parent; 618 | if(parent!=NULL) 619 | { 620 | if(parent->reflag==1) 621 | { 622 | find_sol_refp(pp,parent); 623 | if((pp[0]!=NULL&&pp[0]->reflag==0 624 | &&pp[1]!=NULL&&pp[1]->reflag==0) 625 | &&(pp[2]!=NULL&&pp[2]->reflag==0 626 | &&pp[3]!=NULL&&pp[3]->reflag==0)) 627 | // if((pp[0]->reflag==0&&pp[1]->reflag==0) 628 | // &&(pp[2]->reflag==0&&pp[3]->reflag==0)) 629 | return(1); 630 | else 631 | return(0); 632 | } 633 | } 634 | return(0); 635 | } 636 | 637 | void formListForAllGrid(); 638 | void releaseList(); 639 | void setFlagForAll(); 640 | void setFlagForAll0(); 641 | //光顺网格 642 | void smoothcell() 643 | { 644 | // long Nac; 645 | int hoflag,hiflag,i,nncell; 646 | Node *current;//新生成的四个节点 647 | OctCell *pc,*parent,*pp[4];//定义4个叶子节点的地址 648 | int n_smth=3; 649 | do 650 | { 651 | // releaselist(0); 652 | // releasecelllist(Adpcelllist); 653 | //创建新的链表 654 | // Nac=FormAdpCellList(cartcell,cNx,cNy); 655 | 656 | releaseList(); 657 | formListForAllGrid(); 658 | // setFlagForAll0(); 659 | nncell=0; 660 | //current=Adpcelllist; 661 | current = HeadListAllGrid; 662 | 663 | while(current!=NULL) 664 | { 665 | pc=current->cell; 666 | if(pc->flag==0 && current->flg==0){ 667 | //if(current->flg!=6){ 668 | hiflag=0; 669 | hoflag=0; 670 | hoflag=chargeholegrid(pc);//判断是否是hole grid 671 | //cout<<"smooth\n"; 672 | //if(hoflag==1){printf("hoflag=%d\n",hoflag);getchar();} 673 | hiflag=chargehillgrid(pc);//判断是否是hill grid 674 | //if(hiflag==1){printf("hiflag=%d\n",hiflag);getchar();} 675 | /**/ 676 | if(hoflag==1) 677 | { 678 | creat_sol_children(pc); 679 | // pc->reflag=1; 680 | nncell++; 681 | } 682 | 683 | if(hiflag==1) 684 | { 685 | parent=pc->parent; 686 | for(i=0;i<4;i++) 687 | { 688 | pp[i]=parent->children[i]; 689 | pp[i]->coflag=true; 690 | } 691 | creatsolcoarseparent(parent,pp); 692 | parent->coflag=false; 693 | parent->reflag=0; 694 | nncell++; 695 | } 696 | } 697 | current=current->next; 698 | } 699 | // printf("nncell=%d\n",nncell); 700 | cout<<"nncell= "<0&& n_smth>0); 703 | } 704 | 705 | void solveEdge4Gradient(Face &fc, double fjbx[],double fjby[]) 706 | { 707 | OctCell *lsbl,*lsbl0; 708 | 709 | lsbl0=fc.parent; 710 | lsbl=fc.neighbor; 711 | double ush0[4],ush[4]; 712 | double ujb0[4],ujb[4]; 713 | for(int i=0;i<4;++i) 714 | { 715 | ush0[i]=lsbl0->dof[i][0]; 716 | ush[i]=lsbl->dof[i][0]; 717 | } 718 | shbl2jbbl(ush0,ujb0); 719 | shbl2jbbl(ush,ujb); 720 | 721 | for(int i=0; i<4;++i){ 722 | fjbx[i]=0.5*(ujb0[i]+ujb[i])*fc.nml[0]*fc.area; 723 | fjby[i]=0.5*(ujb0[i]+ujb[i])*fc.nml[1]*fc.area; 724 | } 725 | } 726 | 727 | //void solveEdge4Gradient(Face &fc, double fjbx[],double fjby[]) 728 | void solveGradient() 729 | { 730 | double fjbx[4],fjby[4]; 731 | double vol0,vol1; 732 | 733 | for(vector::size_type isz=0; isz!=faces_comp.size(); ++isz){ 734 | for(int i=0;i<4;++i){ 735 | faces_comp[isz].parent->Ux[i]=0.0; 736 | faces_comp[isz].parent->Uy[i]=0.0; 737 | faces_comp[isz].neighbor->Ux[i]=0.0; 738 | faces_comp[isz].neighbor->Uy[i]=0.0; 739 | } 740 | } 741 | 742 | for(vector::size_type isz=0; isz!=faces_comp.size(); ++isz){ 743 | solveEdge4Gradient(faces_comp[isz], fjbx,fjby); 744 | vol0=faces_comp[isz].parent->dx*faces_comp[isz].parent->dy; 745 | vol1=faces_comp[isz].neighbor->dx*faces_comp[isz].neighbor->dy; 746 | for(int i=0;i<4;++i){ 747 | faces_comp[isz].parent->Ux[i]+=fjbx[i]/vol0; 748 | faces_comp[isz].parent->Uy[i]+=fjby[i]/vol0;; 749 | faces_comp[isz].neighbor->Ux[i]-=fjbx[i]/vol1; 750 | faces_comp[isz].neighbor->Uy[i]-=fjby[i]/vol1; 751 | } 752 | } 753 | } 754 | 755 | void son_cell_value(OctCell *pp, int nson, OctCell *pson) 756 | { 757 | switch(nson) { 758 | case 0: 759 | for(int i=0;i<4;++i){ 760 | pson->dof[i][0]=pp->dof[i][0]-0.5*pp->dof[i][1] 761 | -0.5*pp->dof[i][2]+0.25*pp->dof[i][3]; 762 | 763 | pson->dof[i][1]=0.5*pp->dof[i][1]-0.25*pp->dof[i][3] 764 | -0.5*pp->dof[i][4]; 765 | 766 | 767 | pson->dof[i][2]=0.5*pp->dof[i][2]-0.25*pp->dof[i][3] 768 | -0.5*pp->dof[i][5]; 769 | 770 | pson->dof[i][3]=0.25*pp->dof[i][3]; 771 | 772 | pson->dof[i][4]=0.25*pp->dof[i][4]; 773 | pson->dof[i][5]=0.25*pp->dof[i][5]; 774 | } 775 | break; 776 | case 1: 777 | for(int i=0;i<4;++i){ 778 | pson->dof[i][0]=pp->dof[i][0]+0.5*pp->dof[i][1] 779 | -0.5*pp->dof[i][2]-0.25*pp->dof[i][3]; 780 | 781 | pson->dof[i][1]=0.5*pp->dof[i][1]-0.25*pp->dof[i][3] 782 | +0.5*pp->dof[i][4]; 783 | 784 | 785 | pson->dof[i][2]=0.5*pp->dof[i][2]+0.25*pp->dof[i][3] 786 | -0.5*pp->dof[i][5]; 787 | 788 | pson->dof[i][3]=0.25*pp->dof[i][3]; 789 | 790 | pson->dof[i][4]=0.25*pp->dof[i][4]; 791 | pson->dof[i][5]=0.25*pp->dof[i][5]; 792 | } 793 | break; 794 | case 2: 795 | for(int i=0;i<4;++i){ 796 | pson->dof[i][0]=pp->dof[i][0]+0.5*pp->dof[i][1] 797 | +0.5*pp->dof[i][2]+0.25*pp->dof[i][3]; 798 | 799 | pson->dof[i][1]=0.5*pp->dof[i][1]+0.25*pp->dof[i][3] 800 | +0.5*pp->dof[i][4]; 801 | 802 | 803 | pson->dof[i][2]=0.5*pp->dof[i][2]+0.25*pp->dof[i][3] 804 | +0.5*pp->dof[i][5]; 805 | 806 | pson->dof[i][3]=0.25*pp->dof[i][3]; 807 | 808 | pson->dof[i][4]=0.25*pp->dof[i][4]; 809 | pson->dof[i][5]=0.25*pp->dof[i][5]; 810 | } 811 | break; 812 | case 3: 813 | for(int i=0;i<4;++i){ 814 | pson->dof[i][0]=pp->dof[i][0]-0.5*pp->dof[i][1] 815 | +0.5*pp->dof[i][2]-0.25*pp->dof[i][3]; 816 | 817 | pson->dof[i][1]=0.5*pp->dof[i][1]+0.25*pp->dof[i][3] 818 | -0.5*pp->dof[i][4]; 819 | 820 | 821 | pson->dof[i][2]=0.5*pp->dof[i][2]-0.25*pp->dof[i][3] 822 | +0.5*pp->dof[i][5]; 823 | 824 | pson->dof[i][3]=0.25*pp->dof[i][3]; 825 | 826 | pson->dof[i][4]=0.25*pp->dof[i][4]; 827 | pson->dof[i][5]=0.25*pp->dof[i][5]; 828 | } 829 | break; 830 | } 831 | } 832 | 833 | 834 | void outputcell_sol(int ij=0, const string& str123="amr"); 835 | void outputcell_new(int ij=0); 836 | void setFlagForAll(); 837 | void formListFaceCellAll(); 838 | void face_vec(); 839 | void point_vec(); 840 | void solveGradient(); 841 | 842 | extern PXYZ ext_wall[NPT_EXT_WALL+1]; //points at external computational domain 843 | void formExtWallInOutBndry(); 844 | void set_exFlag4All(int nmpnt, PXYZ wallpt[]);//网格中心在固壁内部的为-1流场内部为0 在翼型上的为2, 尖后缘为4 845 | void find_multivalue_cell(const PXYZ &sharppoint); 846 | //void find_multivalue_cell(PXYZ &sharppoint); 847 | void releaseFaceCellList(); 848 | extern PXYZ MBsharp_point[][8]; 849 | void kxrcf_relate(); 850 | void face_kxrcf_all(); 851 | void set_kxrcf(); 852 | void release_ColCoa(); 853 | void SolutionAMR(int i) 854 | { 855 | #ifndef KXRCF_AMR 856 | solveGradient(); 857 | getAllAdpParametersList(); 858 | #else 859 | kxrcf_relate(); 860 | face_kxrcf_all(); 861 | set_kxrcf(); 862 | #endif 863 | charg_sol_gridAll(); 864 | chargegridforcoarse(); 865 | creatcoarsegrid(); 866 | creat_amr_grid(); 867 | // release_ColCoa(); 868 | solrefcell.clear();//solution AMR cell 869 | solcoacell.clear();//solution coase cell 870 | 871 | cout<<"Adaptively Refine and Coarsen Mesh Complete>>>>>\n"; 872 | smoothcell(); 873 | cout<<"Smooth Adaptively Mesh Complete>>>>>\n"; 874 | releaseList(); 875 | formListForAllGrid(); 876 | 877 | setFlagForAll(); 878 | 879 | releaseFaceCellList(); 880 | formListFaceCellAll(); 881 | #if IS_TUBE==1 882 | set_exFlag4All(NPT_EXT_WALL, ext_wall); 883 | formExtWallInOutBndry(); 884 | #endif 885 | face_vec(); 886 | point_vec(); 887 | // outputcell_new(i);//output mesh 888 | //outputcell_sol(i);//output solution 889 | #if HAVE_MV!=0 890 | for(int wy=0; wydof[i][j]; 9 | } 10 | } 11 | 12 | switch(nson) { 13 | case 0: 14 | for(int i=0;i<4;++i) { 15 | dof0[i]= dof[i][0]-0.5*dof[i][1]-0.5*dof[i][2]+0.25*dof[i][3]; 16 | } 17 | break; 18 | case 1: 19 | for(int i=0;i<4;++i){ 20 | dof0[i]= dof[i][0]+0.5*dof[i][1]-0.5*dof[i][2]-0.25*dof[i][3]; 21 | } 22 | break; 23 | case 2: 24 | for(int i=0;i<4;++i){ 25 | dof0[i]= dof[i][0]+0.5*dof[i][1]+0.5*dof[i][2]+0.25*dof[i][3]; 26 | } 27 | break; 28 | case 3: 29 | for(int i=0;i<4;++i){ 30 | dof0[i]= dof[i][0]-0.5*dof[i][1]+0.5*dof[i][2]-0.25*dof[i][3]; 31 | } 32 | break; 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /spatial_discretization.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include"non_uniform_grid.h" 4 | #include"findneighbor.h" 5 | extern OctCell *bodygrid; 6 | extern Node *HeadListAllGrid; 7 | //x,y belong to [-1,1]X[-1,1] 需要将 [x_{i-1/2} x_{i+1/2}] => [-1,1] 8 | double approx_sol(double x, double y, double *doftmp, int n=nDOF ); 9 | //直接x,y是原始计算区域的坐标 [x_{i-1/2} x_{i+1/2}] 10 | double n_approx_sol(double x,double y, double xc1, double yc1, double dx, double dy, double *doftmp, int n=nDOF ); 11 | double n_approx_sol(const double xi[2], const double xc[2], double dx, double dy, double *doftmp, int n=nDOF ); 12 | 13 | extern vector faces_comp; 14 | 15 | void spatial_discretize_f(Face &fc) 16 | { 17 | OctCell *un; 18 | OctCell *un1; 19 | // OctCell *unp1x, *unp1y, *unm1x, *unm1y; 20 | 21 | // double tmp92=0.0; 22 | // double tmp93=0.0; 23 | // double tmp94=0.0; 24 | // double tmpx=0.0, tmpy=0.0; 25 | 26 | un=fc.parent; 27 | un1=fc.neighbor; 28 | double xc1,yc1, xc2,yc2; 29 | double dx1,dy1,dy2,dx2; 30 | // double uapp[4][3][3]={0.0}; 31 | // double uapp1[4][3][3]={0.0}; 32 | 33 | xc1=un->xc1; 34 | yc1=un->yc1; 35 | dx1=un->dx; 36 | dy1=un->dy; 37 | 38 | xc2=un1->xc1; 39 | yc2=un1->yc1; 40 | dx2=un1->dx; 41 | dy2=un1->dy; 42 | 43 | double fflx[4][6]={0.0}; 44 | double rfflx[4][6]={0.0}; 45 | 46 | for (short j=0; j<4; j++) { 47 | fflx[j][0]=(wei[0]*fc.faceflux[0][j]+wei[1]*fc.faceflux[1][j]+wei[2]*fc.faceflux[2][j])*fc.area*0.5; 48 | fflx[j][1]=(wei[0]*fc.faceflux[0][j]*phix(fc.gs_pt[0][0],xc1,dx1)+wei[1]*fc.faceflux[1][j]*phix(fc.gs_pt[1][0],xc1,dx1) 49 | +wei[2]*fc.faceflux[2][j]*phix(fc.gs_pt[2][0],xc1,dx1))*fc.area*0.5; 50 | 51 | fflx[j][2]=(wei[0]*fc.faceflux[0][j]*psiy(fc.gs_pt[0][1],yc1,dy1)+wei[1]*fc.faceflux[1][j]*psiy(fc.gs_pt[1][1],yc1,dy1) 52 | +wei[2]*fc.faceflux[2][j]*psiy(fc.gs_pt[2][1],yc1,dy1))*fc.area*0.5; 53 | 54 | // if(nDOF==6) { 55 | fflx[j][3]=(wei[0]*fc.faceflux[0][j]*phix_psiy(fc.gs_pt[0][0], fc.gs_pt[0][1],xc1,yc1,dx1, dy1) 56 | +wei[1]*fc.faceflux[1][j]*phix_psiy(fc.gs_pt[1][0], fc.gs_pt[1][1],xc1,yc1,dx1,dy1) 57 | +wei[2]*fc.faceflux[2][j]*phix_psiy(fc.gs_pt[2][0],fc.gs_pt[2][1],xc1,yc1,dx1, dy1))*fc.area*0.5; 58 | 59 | fflx[j][4]=(wei[0]*fc.faceflux[0][j]*phix2m(fc.gs_pt[0][0],xc1,dx1)+wei[1]*fc.faceflux[1][j]*phix2m(fc.gs_pt[1][0],xc1,dx1) 60 | +wei[2]*fc.faceflux[2][j]*phix2m(fc.gs_pt[2][0],xc1,dx1))*fc.area*0.5; 61 | 62 | fflx[j][5]=(wei[0]*fc.faceflux[0][j]*psiy2m(fc.gs_pt[0][1],yc1,dy1)+wei[1]*fc.faceflux[1][j]*psiy2m(fc.gs_pt[1][1],yc1,dy1) 63 | +wei[2]*fc.faceflux[2][j]*psiy2m(fc.gs_pt[2][1],yc1,dy1))*fc.area*0.5; 64 | // } 65 | //right face 66 | rfflx[j][0]=fflx[j][0]; 67 | rfflx[j][1]=(wei[0]*fc.faceflux[0][j]*phix(fc.gs_pt[0][0],xc2,dx2)+wei[1]*fc.faceflux[1][j]*phix(fc.gs_pt[1][0],xc2,dx2) 68 | +wei[2]*fc.faceflux[2][j]*phix(fc.gs_pt[2][0],xc2,dx2))*fc.area*0.5; 69 | 70 | rfflx[j][2]=(wei[0]*fc.faceflux[0][j]*psiy(fc.gs_pt[0][1],yc2,dy2)+wei[1]*fc.faceflux[1][j]*psiy(fc.gs_pt[1][1],yc2,dy2) 71 | +wei[2]*fc.faceflux[2][j]*psiy(fc.gs_pt[2][1],yc2,dy2))*fc.area*0.5; 72 | 73 | // if(nDOF==6) { 74 | rfflx[j][3]=(wei[0]*fc.faceflux[0][j]*phix_psiy(fc.gs_pt[0][0], fc.gs_pt[0][1],xc2,yc2,dx2, dy2) 75 | +wei[1]*fc.faceflux[1][j]*phix_psiy(fc.gs_pt[1][0], fc.gs_pt[1][1],xc2,yc2,dx2,dy2) 76 | +wei[2]*fc.faceflux[2][j]*phix_psiy(fc.gs_pt[2][0],fc.gs_pt[2][1],xc2,yc2,dx2, dy2))*fc.area*0.5; 77 | 78 | rfflx[j][4]=(wei[0]*fc.faceflux[0][j]*phix2m(fc.gs_pt[0][0],xc2,dx2)+wei[1]*fc.faceflux[1][j]*phix2m(fc.gs_pt[1][0],xc2,dx2) 79 | +wei[2]*fc.faceflux[2][j]*phix2m(fc.gs_pt[2][0],xc2,dx2))*fc.area*0.5; 80 | 81 | rfflx[j][5]=(wei[0]*fc.faceflux[0][j]*psiy2m(fc.gs_pt[0][1],yc2,dy2)+wei[1]*fc.faceflux[1][j]*psiy2m(fc.gs_pt[1][1],yc2,dy2) 82 | +wei[2]*fc.faceflux[2][j]*psiy2m(fc.gs_pt[2][1],yc2,dy2))*fc.area*0.5; 83 | // } 84 | } 85 | 86 | //face flux 87 | for(short j=0;j<4;++j){ 88 | for(short imm=0; imm<6;++imm) { 89 | un->residual[j][imm] += fflx[j][imm]; 90 | un1->residual[j][imm] -= rfflx[j][imm]; 91 | } 92 | } 93 | 94 | //end face flux 95 | } 96 | 97 | 98 | void spatial_discretize_v(OctCell* un) 99 | { 100 | double tmp92=0.0; 101 | double tmp93=0.0; 102 | double tmp94=0.0; 103 | double tmpx=0.0, tmpy=0.0; 104 | 105 | double uapp[4][3][3]={0.0}; 106 | double dx,dy, dxpdy; 107 | dx=un->dx; 108 | dy=un->dy; 109 | dxpdy=dx*dy; 110 | 111 | for(short j=0; j<4; j++) { 112 | for(short imm=0; imm<3;imm++) { 113 | for(short jmm=0; jmm<3; jmm++) { 114 | uapp[j][jmm][imm]=approx_sol(gspt[jmm], gspt[imm], un->dof[j], nDOF); //u(x,y) 115 | } 116 | } 117 | } 118 | 119 | double pre[3][3]={0.0}; 120 | double pre1[3][3]={0.0}; 121 | 122 | for(short imm=0; imm<3;imm++) { 123 | for(short jmm=0; jmm<3; jmm++) { 124 | pre[jmm][imm]=GAM11 *(uapp[3][jmm][imm]-0.5*(uapp[1][jmm][imm]*uapp[1][jmm][imm]/uapp[0][jmm][imm] 125 | + uapp[2][jmm][imm]*uapp[2][jmm][imm]/uapp[0][jmm][imm])); 126 | } 127 | } 128 | 129 | double flxfunx[4][3][3]={0.0}; 130 | double flxfuny[4][3][3]={0.0}; 131 | 132 | for(short imm=0; imm<3;imm++) { 133 | for(short jmm=0; jmm<3; jmm++) { 134 | 135 | flxfunx[0][jmm][imm]=uapp[1][jmm][imm]; 136 | flxfuny[0][jmm][imm]=uapp[2][jmm][imm]; 137 | 138 | flxfunx[1][jmm][imm]=uapp[1][jmm][imm]*uapp[1][jmm][imm]/uapp[0][jmm][imm] + pre[jmm][imm]; 139 | 140 | flxfunx[2][jmm][imm] = flxfuny[1][jmm][imm] = uapp[1][jmm][imm]*uapp[2][jmm][imm]/uapp[0][jmm][imm]; 141 | 142 | flxfuny[2][jmm][imm]=uapp[2][jmm][imm]*uapp[2][jmm][imm]/uapp[0][jmm][imm] + pre[jmm][imm]; 143 | 144 | flxfunx[3][jmm][imm] = (uapp[3][jmm][imm] + pre[jmm][imm])* uapp[1][jmm][imm]/uapp[0][jmm][imm]; 145 | flxfuny[3][jmm][imm] = (uapp[3][jmm][imm] + pre[jmm][imm])* uapp[2][jmm][imm]/uapp[0][jmm][imm]; 146 | 147 | } 148 | } 149 | 150 | //体积积分项 151 | 152 | // euler equation for aerodynamics 153 | //uapp[j][jmm][imm] 154 | for(short j=0; j<4;++j) { 155 | tmp92=0.0; 156 | tmp93=0.0; 157 | tmp94=0.0; 158 | tmpx=tmpy=0.0; 159 | 160 | //base function: phi_i(x) & psi_j(y) 161 | for(short imm=0; imm < 3;imm++) { 162 | for(short jmm=0; jmm < 3; jmm++) { 163 | tmp92 += flxfunx[j][jmm][imm]*wei[imm]*wei[jmm]; 164 | 165 | tmp93 += flxfuny[j][jmm][imm]*wei[imm]*wei[jmm]; 166 | } 167 | } 168 | 169 | tmp92 *= 0.25*dxpdy; 170 | tmp93 *= 0.25*dxpdy; 171 | 172 | un->residual[j][1] -= 2.0/dx * tmp92; 173 | un->residual[j][2] -= 2.0/dy * tmp93; 174 | 175 | tmp92=tmp93=0.0; 176 | 177 | //base function: phi_i(x)*psi_j(y), phi_i(x)^2-1.0/3.0, & psi_j(y)^2-1.0/3 178 | if(nDOF==6) { 179 | for(short imm=0; imm<3;imm++) { 180 | for(short jmm=0; jmm<3; jmm++) { 181 | tmp93 += flxfuny[j][jmm][imm] *gspt[jmm]*wei[imm]*wei[jmm]; //fy*x 182 | 183 | tmp94 += flxfunx[j][jmm][imm] *gspt[imm]*wei[imm]*wei[jmm]; //fx*y 184 | 185 | tmpx += flxfunx[j][jmm][imm] *gspt[jmm]*wei[imm]*wei[jmm]; //fx*x 186 | tmpy += flxfuny[j][jmm][imm] *gspt[imm]*wei[imm]*wei[jmm]; //fy*y 187 | } 188 | } 189 | 190 | tmp94 *= 0.25*dxpdy; 191 | tmp93 *= 0.25*dxpdy; 192 | tmpx *= 0.25*dxpdy; 193 | tmpy *= 0.25*dxpdy; 194 | 195 | un->residual[j][3] -= 2.0/dx * tmp94 + 2.0/dy * tmp93; 196 | 197 | un->residual[j][4] -= 4.0/dx * tmpx; 198 | un->residual[j][5] -= 4.0/dy * tmpy; 199 | 200 | } 201 | } //end for 202 | //===== 203 | 204 | } 205 | 206 | void spatial_discretization_all() 207 | { 208 | Node *current; 209 | current = HeadListAllGrid; 210 | OctCell *pcell0; 211 | while(current != NULL) 212 | { 213 | pcell0 = current->cell; 214 | if(pcell0->flag % 2 == 0 && current->flg<=2 ) { 215 | for(int im=0;im<4; ++im){ 216 | for(int jm=0;jm<6; ++jm){ 217 | pcell0->residual[im][jm]=0.0; 218 | } 219 | } 220 | } 221 | 222 | current = current->next; 223 | } 224 | 225 | 226 | for(vector::size_type isz=0; isz!=faces_comp.size(); ++isz){ 227 | spatial_discretize_f(faces_comp[isz]); 228 | } 229 | 230 | current = HeadListAllGrid; 231 | while(current != NULL) 232 | { 233 | pcell0 = current->cell; 234 | if(pcell0->flag == 0 && current->flg<=2 ) 235 | spatial_discretize_v(pcell0); 236 | current = current->next; 237 | } 238 | } 239 | 240 | #ifdef RES_SMOOTH 241 | const double sm_ep=500.1; //0.5-0.8 242 | void resd_smoothing() 243 | { 244 | OctCell *pc0,*pc1; 245 | Node *current; 246 | current = HeadListAllGrid; 247 | OctCell *pcell0; 248 | double vol0,vol1; 249 | while(current != NULL) 250 | { 251 | pcell0 = current->cell; 252 | if(pcell0->flag == 0 && current->flg<=2 ) { 253 | for(int im=0;im<4; ++im){ 254 | for(int jm=0;jm<6; ++jm){ 255 | pcell0->resd1[im][jm]=pcell0->residual[im][jm]; 256 | 257 | // pcell0->resd0[im][jm]=0.0; 258 | 259 | } 260 | } 261 | } 262 | 263 | current = current->next; 264 | } 265 | 266 | OctCell *pcs,*pcn; 267 | double renb[4][6],renb1[4][6]; 268 | double renbs[4][6],renbn[4][6]; 269 | double rtmx,rtmy; 270 | for(int itm=0;itm<2;++itm){ 271 | current = HeadListAllGrid; 272 | while(current != NULL) 273 | { 274 | pcell0 = current->cell; 275 | if(pcell0->flag == 0 && current->flg<=2 ) { 276 | pc0=WestNeighbor(pcell0); 277 | pc1=EastNeighbor(pcell0); 278 | pcs=SouthNeighbor(pcell0); 279 | pcn=NorthNeighbor(pcell0); 280 | 281 | rtmx=rtmy=0.0; 282 | if(pc0->reflag==1){ 283 | for(int iu=0;iu<4;++iu) 284 | for(int ju=0;ju<6;++ju) 285 | renb[iu][ju]=0.0; 286 | } 287 | else { 288 | ++rtmx; 289 | for(int iu=0;iu<4;++iu) 290 | for(int ju=0;ju<6;++ju) 291 | renb[iu][ju]=pc0->resd1[iu][ju]; 292 | } 293 | 294 | if(pc1->reflag==1){ 295 | for(int iu=0;iu<4;++iu) 296 | for(int ju=0;ju<6;++ju) 297 | renb1[iu][ju]=0.0; 298 | } 299 | else { 300 | ++rtmx; 301 | for(int iu=0;iu<4;++iu) 302 | for(int ju=0;ju<6;++ju) 303 | renb1[iu][ju]=pc1->resd1[iu][ju]; 304 | } 305 | 306 | 307 | if(pcs->reflag==1){ 308 | for(int iu=0;iu<4;++iu) 309 | for(int ju=0;ju<6;++ju) 310 | renbs[iu][ju]=0.0; 311 | } 312 | else { 313 | ++rtmy; 314 | for(int iu=0;iu<4;++iu) 315 | for(int ju=0;ju<6;++ju) 316 | renbs[iu][ju]=pcs->resd1[iu][ju]; 317 | } 318 | 319 | if(pcn->reflag==1){ 320 | for(int iu=0;iu<4;++iu) 321 | for(int ju=0;ju<6;++ju) 322 | renbn[iu][ju]=0.0; 323 | } 324 | else { 325 | ++rtmy; 326 | for(int iu=0;iu<4;++iu) 327 | for(int ju=0;ju<6;++ju) 328 | renbn[iu][ju]=pcn->resd1[iu][ju]; 329 | } 330 | 331 | for(int im=0;im<4; ++im){ 332 | for(int jm=0;jm<6; ++jm){ 333 | pcell0->resd1[im][jm] 334 | =(pcell0->resd1[im][jm]+sm_ep*(renb[im][jm]+renb1[im][jm])) 335 | /(1.0+sm_ep*rtmx); 336 | } 337 | } 338 | 339 | for(int im=0;im<4; ++im){ 340 | for(int jm=0;jm<6; ++jm){ 341 | pcell0->resd1[im][jm] 342 | =(pcell0->resd1[im][jm]+sm_ep*(renbs[im][jm]+renbn[im][jm])) 343 | /(1.0+sm_ep*rtmy); 344 | } 345 | } 346 | } 347 | 348 | current = current->next; 349 | } 350 | } 351 | 352 | /* 353 | for(int itmp=0;itmp<2;++itmp){ 354 | for(vector::size_type isz=0; isz!=faces_comp.size(); ++isz){ 355 | pc0=faces_comp[isz].parent; 356 | vol0=pc0->dx*pc0->dy; 357 | vol0=1.; 358 | pc1=faces_comp[isz].neighbor; 359 | vol1=pc1->dx*pc1->dy; 360 | vol1=1.; 361 | for(int im=0;im<4;++im){ 362 | for(int jm=0;jm<6;++jm){ 363 | if(pc0->flag==0){ 364 | pc0->resd0[im][jm]+=vol0/vol1*pc1->resd1[im][jm]*sm_ep; 365 | } 366 | if(pc1->flag==0){ 367 | pc1->resd0[im][jm]+=vol1/vol0*pc0->resd1[im][jm]*sm_ep; 368 | } 369 | } 370 | } 371 | } 372 | 373 | current = HeadListAllGrid; 374 | while(current != NULL) 375 | { 376 | pcell0 = current->cell; 377 | if(pcell0->flag == 0 && current->flg<=2 ) { 378 | for(int im=0;im<4; ++im){ 379 | for(int jm=0;jm<6; ++jm){ 380 | pcell0->resd1[im][jm] 381 | =(pcell0->resd1[im][jm]+pcell0->resd0[im][jm]) 382 | /(1.0+sm_ep*pcell0->p_node->n_nb); 383 | } 384 | } 385 | } 386 | 387 | current = current->next; 388 | } 389 | 390 | */ 391 | current = HeadListAllGrid; 392 | while(current != NULL) 393 | { 394 | pcell0 = current->cell; 395 | if(pcell0->flag == 0 && current->flg<=2 ) { 396 | // for(int im=0;im<4; ++im){ 397 | // for(int jm=0;jm<6; ++jm){ 398 | // if(fabs(pcell0->resd1[im][jm]) 399 | // residual[im][jm])) 400 | // pcell0->residual[im][jm]=pcell0->resd1[im][jm]; 401 | // } 402 | // } 403 | 404 | for(int im=0;im<4; ++im){ 405 | if(fabs(pcell0->resd1[im][0]) 406 | residual[im][0])) 407 | pcell0->residual[im][0]=pcell0->resd1[im][0]; 408 | } 409 | 410 | } 411 | 412 | current = current->next; 413 | } 414 | //} 415 | } 416 | #endif 417 | 418 | 419 | -------------------------------------------------------------------------------- /time_step.cpp: -------------------------------------------------------------------------------- 1 | #include"non_uniform_grid.h" 2 | 3 | extern double dt; 4 | extern Node *HeadListAllGrid; 5 | extern OctCell *bodygrid; 6 | extern double CFL; 7 | 8 | void getMinTimeStep(OctCell *unp) 9 | { 10 | double ls; 11 | 12 | if( unp->flag == 0) 13 | { 14 | ls=unp->dt1; 15 | if(dt>ls) dt=ls; 16 | } 17 | 18 | } 19 | 20 | void shblToJbbl(SHBL *, JBBL *); 21 | void getTimeStep(OctCell *unp) 22 | { 23 | 24 | double u, v; 25 | 26 | double dx,dy; 27 | 28 | double a; 29 | JBBL jbu; 30 | SHBL shu; 31 | 32 | dx=unp->dx; 33 | dy=unp->dy; 34 | shu.q=unp->dof[0][0]; 35 | shu.qu=unp->dof[1][0]; 36 | shu.qv=unp->dof[2][0]; 37 | shu.te=unp->dof[3][0]; 38 | 39 | shblToJbbl(&shu,&jbu); 40 | 41 | u = jbu.u; 42 | v = jbu.v; 43 | 44 | a = sqrt(GAMMA * jbu.p / jbu.q); 45 | 46 | unp->dt1 = CFL * dx * dy/ ((fabs(u) + a)*dy + (fabs(v) + a)*dx); 47 | } 48 | 49 | 50 | void timestep() 51 | { 52 | Node *current; 53 | current = HeadListAllGrid; 54 | OctCell *pcell0; 55 | 56 | dt=2000.0; 57 | current = HeadListAllGrid; 58 | while(current != NULL) 59 | { 60 | pcell0 = current->cell; 61 | if(pcell0->flag == 0 && current->flg<=2 ) { 62 | getTimeStep(pcell0); 63 | #ifndef LOCAL_TIME 64 | getMinTimeStep(pcell0); 65 | #endif 66 | } 67 | current = current->next; 68 | } 69 | } 70 | 71 | 72 | -------------------------------------------------------------------------------- /tree_avg.cpp: -------------------------------------------------------------------------------- 1 | //由叶子节点获得他的父亲的单元平均,好用于限制器设置,或者将来的多重网格 2 | #include"non_uniform_grid.h" 3 | #include"findneighbor.h" 4 | 5 | extern Node *HeadListAllGrid; 6 | //pcell 是叶子节点 7 | const int back_para=4; //最大设置平均到爷爷的父辈 8 | 9 | void limit_cell_avg(OctCell *pcell); 10 | 11 | void setAllLeafbAvgFalse() 12 | { 13 | Node *current; 14 | current = HeadListAllGrid; 15 | OctCell *pcell0; 16 | 17 | current = HeadListAllGrid; 18 | while(current != NULL) 19 | { 20 | pcell0 = current->cell; 21 | if(pcell0->flag%2 == 0 && current->flg<=2 ) { 22 | pcell0->bAvg=false; 23 | } 24 | current = current->next; 25 | } 26 | } 27 | 28 | void parent0bAvg(OctCell *pcell) 29 | { 30 | int lev=pcell->level; 31 | OctCell *parent; 32 | parent=pcell->parent; 33 | int isum=0; 34 | 35 | // while(lev>=0) { //>0 or >=0 ?? TODO 36 | while(parent!=NULL) { 37 | if(parent->bAvg!=false){ 38 | if(parent->children[0]->bAvg== false 39 | && parent->children[1]->bAvg== false 40 | && parent->children[2]->bAvg== false 41 | && parent->children[3]->bAvg== false){ 42 | parent->bAvg=false; 43 | } 44 | else{ 45 | break; 46 | } 47 | 48 | } 49 | ++isum; 50 | if(isum>back_para) break; 51 | parent=parent->parent; 52 | } 53 | } 54 | 55 | 56 | void parent_avg(OctCell *pcell) 57 | { 58 | int lev=pcell->level; 59 | 60 | OctCell *parent; 61 | parent=pcell->parent; 62 | int isum=0; 63 | 64 | // while(lev>=0) { //>0 or >=0 ?? TODO 65 | while(parent!=NULL) { 66 | if(parent->bAvg!=true){ 67 | if(parent->children[0]->bAvg== true 68 | && parent->children[1]->bAvg== true 69 | && parent->children[2]->bAvg== true 70 | && parent->children[3]->bAvg== true){ 71 | limit_cell_avg(parent); //由儿子的单元平均获得父亲的单元平均 72 | } 73 | else{ 74 | break; 75 | } 76 | 77 | } 78 | ++isum; 79 | if(isum>back_para) break; 80 | parent=parent->parent; 81 | 82 | } 83 | } 84 | 85 | //obtain the cell avarage from his four sons' cell moment 86 | void limit_cell_avg(OctCell *pcell) 87 | { 88 | pcell->bAvg=true; 89 | 90 | for(int i=0; i<4;++i) { 91 | pcell->dof[i][0]=0.25*(pcell->children[0]->dof[i][0] 92 | + pcell->children[1]->dof[i][0] 93 | + pcell->children[2]->dof[i][0] +pcell->children[3]->dof[i][0] ); 94 | } 95 | } 96 | 97 | void tree_0bAvg() 98 | { 99 | Node *current; 100 | current = HeadListAllGrid; 101 | OctCell *pcell0; 102 | short lev0; 103 | OctCell *pnbr[4]={NULL}; 104 | short levnbr[4]; 105 | 106 | current = HeadListAllGrid; 107 | while(current != NULL) 108 | { 109 | pcell0 = current->cell; 110 | if(pcell0->flag%2 == 0 && current->flg<=2 ) { 111 | lev0=pcell0->level; 112 | 113 | pnbr[0]=EastNeighbor(pcell0); 114 | pnbr[1]=SouthNeighbor(pcell0); 115 | pnbr[2]=WestNeighbor(pcell0); 116 | pnbr[3]=NorthNeighbor(pcell0); 117 | 118 | for(int i=0;i<4;++i){ 119 | levnbr[i]=pnbr[i]->level; 120 | // reflg0[i]=pnbr[i]->reflag; 121 | if(lev0>levnbr[i]){ 122 | parent0bAvg(pcell0); 123 | //for(int j=0;j<4;++j){ 124 | // parent0bAvg(pnbr[j]); 125 | //} 126 | break; 127 | } 128 | } 129 | } 130 | current = current->next; 131 | } 132 | } 133 | 134 | /* 135 | OctCell *NorthNeighbor(OctCell *pp); 136 | OctCell *WestNeighbor(OctCell *pp); 137 | OctCell *EastNeighbor(OctCell *pp); 138 | OctCell *SouthNeighbor(OctCell *pp); 139 | */ 140 | 141 | void tree_avg() 142 | { 143 | Node *current; 144 | current = HeadListAllGrid; 145 | OctCell *pcell0; 146 | OctCell *pnbr[4]={NULL}; 147 | short levnbr[4]={0}; 148 | // short reflgnbr[4]={0}; 149 | short lev0; 150 | //short reflg0; 151 | 152 | current = HeadListAllGrid; 153 | while(current != NULL) 154 | { 155 | pcell0 = current->cell; 156 | if(pcell0->flag%2 == 0 && current->flg<=2 ) { 157 | lev0=pcell0->level; 158 | // reflg0=pcell0->reflag; 159 | 160 | pnbr[0]=EastNeighbor(pcell0); 161 | pnbr[1]=SouthNeighbor(pcell0); 162 | pnbr[2]=WestNeighbor(pcell0); 163 | pnbr[3]=NorthNeighbor(pcell0); 164 | for(int i=0;i<4;++i){ 165 | levnbr[i]=pnbr[i]->level; 166 | // reflg0[i]=pnbr[i]->reflag; 167 | if(lev0>levnbr[i]){ 168 | parent_avg(pcell0); 169 | // for(int j=0;j<4;++j){ 170 | // parent_avg(pnbr[j]); 171 | //} 172 | break; 173 | } 174 | } 175 | } 176 | current = current->next; 177 | } 178 | } 179 | 180 | -------------------------------------------------------------------------------- /tvbm_limiter4all.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/tvbm_limiter4all.cpp -------------------------------------------------------------------------------- /vec2d.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | 3 | Copyright 2007-2009 Emre Sozer & Patrick Clark Trizila 4 | 5 | Contact: emresozer@freecfd.com , ptrizila@freecfd.com 6 | 7 | This file is a part of Free CFD 8 | 9 | Free CFD is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 2 of the License, or 12 | any later version. 13 | 14 | Free CFD is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | For a copy of the GNU General Public License, 20 | see . 21 | 22 | *************************************************************************/ 23 | #include 24 | #include 25 | #include 26 | using namespace std; 27 | #include "vec2d.h" 28 | 29 | Vec2D::Vec2D(double x, double y) { 30 | comp[0]=x; 31 | comp[1]=y; 32 | //comp[2]=z; 33 | } 34 | 35 | double Vec2D::dot(const Vec2D &right) { 36 | //return (comp[0]*right.comp[0]+comp[1]*right.comp[1]+comp[2]*right.comp[2]); 37 | return (comp[0]*right.comp[0]+comp[1]*right.comp[1]); 38 | } 39 | 40 | double fabs(const Vec2D vec) { 41 | //return sqrt(vec.comp[0]*vec.comp[0]+vec.comp[1]*vec.comp[1]+vec.comp[2]*vec.comp[2]); 42 | return sqrt(vec.comp[0]*vec.comp[0]+vec.comp[1]*vec.comp[1]); 43 | } 44 | /* 45 | Vec3D Vec3D::cross(const Vec3D &right) { 46 | Vec3D temp; 47 | temp.comp[0]=comp[1]*right.comp[2]-comp[2]*right.comp[1]; 48 | temp.comp[1]=-comp[0]*right.comp[2]+comp[2]*right.comp[0]; 49 | temp.comp[2]=comp[0]*right.comp[1]-comp[1]*right.comp[0]; 50 | return temp; 51 | } 52 | */ 53 | 54 | Vec2D Vec2D::norm(void) { 55 | return (*this)/=fabs(*this); 56 | } 57 | 58 | Vec2D &Vec2D::operator= (const Vec2D &right) { 59 | comp[0]=right.comp[0]; 60 | comp[1]=right.comp[1]; 61 | // comp[2]=right.comp[2]; 62 | return *this; 63 | } 64 | 65 | Vec2D &Vec2D::operator= (const double &right) { 66 | comp[0]=right; 67 | comp[1]=right; 68 | // comp[2]=right; 69 | return *this; 70 | } 71 | 72 | Vec2D &Vec2D::operator*= (const double &right) { 73 | comp[0]*=right; 74 | comp[1]*=right; 75 | // comp[2]*=right; 76 | return *this; 77 | } 78 | 79 | Vec2D Vec2D::operator*(const double &right) { 80 | Vec2D temp; 81 | temp.comp[0]=comp[0]*right; 82 | temp.comp[1]=comp[1]*right; 83 | // temp.comp[2]=comp[2]*right; 84 | return temp; 85 | } 86 | 87 | Vec2D &Vec2D::operator/= (const double &right) { 88 | comp[0]/=right; 89 | comp[1]/=right; 90 | //comp[2]/=right; 91 | return *this; 92 | } 93 | 94 | Vec2D Vec2D::operator/ (const double &right) { 95 | Vec2D temp; 96 | temp.comp[0]=comp[0]/right; 97 | temp.comp[1]=comp[1]/right; 98 | // temp.comp[2]=comp[2]/right; 99 | return temp; 100 | } 101 | 102 | Vec2D &Vec2D::operator+= (const double &right) { 103 | comp[0]+=right; 104 | comp[1]+=right; 105 | // comp[2]+=right; 106 | return *this; 107 | } 108 | 109 | Vec2D &Vec2D::operator+= (const Vec2D &right) { 110 | comp[0]+=right.comp[0]; 111 | comp[1]+=right.comp[1]; 112 | // comp[2]+=right.comp[2]; 113 | return *this; 114 | } 115 | 116 | Vec2D Vec2D::operator+ (const double &right) { 117 | Vec2D temp; 118 | temp.comp[0]=comp[0]+right; 119 | temp.comp[1]=comp[1]+right; 120 | // temp.comp[2]=comp[2]+right; 121 | return temp; 122 | } 123 | 124 | Vec2D &Vec2D::operator-= (const double &right) { 125 | comp[0]-=right; 126 | comp[1]-=right; 127 | // comp[2]-=right; 128 | return *this; 129 | } 130 | 131 | Vec2D &Vec2D::operator-= (const Vec2D &right) { 132 | comp[0]-=right.comp[0]; 133 | comp[1]-=right.comp[1]; 134 | //comp[2]-=right.comp[2]; 135 | return *this; 136 | } 137 | 138 | Vec2D Vec2D::operator- (const double &right) { 139 | Vec2D temp; 140 | temp.comp[0]=comp[0]-right; 141 | temp.comp[1]=comp[1]-right; 142 | //temp.comp[2]=comp[2]-right; 143 | return temp; 144 | } 145 | 146 | Vec2D operator*(const double &left, const Vec2D &right) { 147 | Vec2D temp; 148 | temp.comp[0]=left*right.comp[0]; 149 | temp.comp[1]=left*right.comp[1]; 150 | // temp.comp[2]=left*right.comp[2]; 151 | return temp; 152 | } 153 | 154 | Vec2D operator/ (const double &left, const Vec2D &right) { 155 | Vec2D temp; 156 | temp.comp[0]=left/right.comp[0]; 157 | temp.comp[1]=left/right.comp[1]; 158 | // temp.comp[2]=left/right.comp[2]; 159 | return temp; 160 | } 161 | 162 | Vec2D operator+ (const double &left, const Vec2D &right) { 163 | Vec2D temp; 164 | temp.comp[0]=left+right.comp[0]; 165 | temp.comp[1]=left+right.comp[1]; 166 | // temp.comp[2]=left+right.comp[2]; 167 | return temp; 168 | } 169 | 170 | Vec2D operator+ (const Vec2D &left, const Vec2D &right) { 171 | Vec2D temp; 172 | temp.comp[0]=left.comp[0]+right.comp[0]; 173 | temp.comp[1]=left.comp[1]+right.comp[1]; 174 | // temp.comp[2]=left.comp[2]+right.comp[2]; 175 | return temp; 176 | } 177 | 178 | Vec2D operator- (const double &left, const Vec2D &right) { 179 | Vec2D temp; 180 | temp.comp[0]=left-right.comp[0]; 181 | temp.comp[1]=left-right.comp[1]; 182 | // temp.comp[2]=left-right.comp[2]; 183 | return temp; 184 | } 185 | 186 | Vec2D operator- (const Vec2D &left, const Vec2D &right) { 187 | Vec2D temp; 188 | temp.comp[0]=left.comp[0]-right.comp[0]; 189 | temp.comp[1]=left.comp[1]-right.comp[1]; 190 | // temp.comp[2]=left.comp[2]-right.comp[2]; 191 | return temp; 192 | } 193 | 194 | bool Vec2D::operator== (const Vec2D &right) { 195 | return (comp[0]==right.comp[0] && comp[1]==right.comp[1]); 196 | } 197 | 198 | bool Vec2D::operator!= (const Vec2D &right) { 199 | return (comp[0]!=right.comp[0] || comp[1]!=right.comp[1]); 200 | } 201 | 202 | double &Vec2D::operator[] (int i) {return comp[i];} 203 | 204 | ostream &operator<< (ostream &output,const Vec2D &right) { 205 | output << "{" << right.comp[0] << "," << right.comp[1] << "}"; 206 | return output; 207 | } 208 | -------------------------------------------------------------------------------- /vec2d.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/vec2d.h -------------------------------------------------------------------------------- /vec3d.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | 3 | Copyright 2007-2009 Emre Sozer & Patrick Clark Trizila 4 | 5 | Contact: emresozer@freecfd.com , ptrizila@freecfd.com 6 | 7 | This file is a part of Free CFD 8 | 9 | Free CFD is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | any later version. 13 | 14 | Free CFD is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | For a copy of the GNU General Public License, 20 | see . 21 | 22 | *************************************************************************/ 23 | #include 24 | #include 25 | #include 26 | using namespace std; 27 | #include "vec3d.h" 28 | 29 | Vec3D::Vec3D(double x, double y, double z) { 30 | comp[0]=x; 31 | comp[1]=y; 32 | comp[2]=z; 33 | } 34 | 35 | double Vec3D::dot(const Vec3D &right) { 36 | return (comp[0]*right.comp[0]+comp[1]*right.comp[1]+comp[2]*right.comp[2]); 37 | } 38 | 39 | double fabs(const Vec3D vec) { 40 | return sqrt(vec.comp[0]*vec.comp[0]+vec.comp[1]*vec.comp[1]+vec.comp[2]*vec.comp[2]); 41 | } 42 | 43 | Vec3D Vec3D::cross(const Vec3D &right) { 44 | Vec3D temp; 45 | temp.comp[0]=comp[1]*right.comp[2]-comp[2]*right.comp[1]; 46 | temp.comp[1]=-comp[0]*right.comp[2]+comp[2]*right.comp[0]; 47 | temp.comp[2]=comp[0]*right.comp[1]-comp[1]*right.comp[0]; 48 | return temp; 49 | } 50 | 51 | Vec3D Vec3D::norm(void) { 52 | return (*this)/=fabs(*this); 53 | } 54 | 55 | Vec3D &Vec3D::operator= (const Vec3D &right) { 56 | comp[0]=right.comp[0]; 57 | comp[1]=right.comp[1]; 58 | comp[2]=right.comp[2]; 59 | return *this; 60 | } 61 | 62 | Vec3D &Vec3D::operator= (const double &right) { 63 | comp[0]=right; 64 | comp[1]=right; 65 | comp[2]=right; 66 | return *this; 67 | } 68 | 69 | Vec3D &Vec3D::operator*= (const double &right) { 70 | comp[0]*=right; 71 | comp[1]*=right; 72 | comp[2]*=right; 73 | return *this; 74 | } 75 | 76 | Vec3D Vec3D::operator*(const double &right) { 77 | Vec3D temp; 78 | temp.comp[0]=comp[0]*right; 79 | temp.comp[1]=comp[1]*right; 80 | temp.comp[2]=comp[2]*right; 81 | return temp; 82 | } 83 | 84 | Vec3D &Vec3D::operator/= (const double &right) { 85 | comp[0]/=right; 86 | comp[1]/=right; 87 | comp[2]/=right; 88 | return *this; 89 | } 90 | 91 | Vec3D Vec3D::operator/ (const double &right) { 92 | Vec3D temp; 93 | temp.comp[0]=comp[0]/right; 94 | temp.comp[1]=comp[1]/right; 95 | temp.comp[2]=comp[2]/right; 96 | return temp; 97 | } 98 | 99 | Vec3D &Vec3D::operator+= (const double &right) { 100 | comp[0]+=right; 101 | comp[1]+=right; 102 | comp[2]+=right; 103 | return *this; 104 | } 105 | 106 | Vec3D &Vec3D::operator+= (const Vec3D &right) { 107 | comp[0]+=right.comp[0]; 108 | comp[1]+=right.comp[1]; 109 | comp[2]+=right.comp[2]; 110 | return *this; 111 | } 112 | 113 | Vec3D Vec3D::operator+ (const double &right) { 114 | Vec3D temp; 115 | temp.comp[0]=comp[0]+right; 116 | temp.comp[1]=comp[1]+right; 117 | temp.comp[2]=comp[2]+right; 118 | return temp; 119 | } 120 | 121 | Vec3D &Vec3D::operator-= (const double &right) { 122 | comp[0]-=right; 123 | comp[1]-=right; 124 | comp[2]-=right; 125 | return *this; 126 | } 127 | 128 | Vec3D &Vec3D::operator-= (const Vec3D &right) { 129 | comp[0]-=right.comp[0]; 130 | comp[1]-=right.comp[1]; 131 | comp[2]-=right.comp[2]; 132 | return *this; 133 | } 134 | 135 | Vec3D Vec3D::operator- (const double &right) { 136 | Vec3D temp; 137 | temp.comp[0]=comp[0]-right; 138 | temp.comp[1]=comp[1]-right; 139 | temp.comp[2]=comp[2]-right; 140 | return temp; 141 | } 142 | 143 | Vec3D operator*(const double &left, const Vec3D &right) { 144 | Vec3D temp; 145 | temp.comp[0]=left*right.comp[0]; 146 | temp.comp[1]=left*right.comp[1]; 147 | temp.comp[2]=left*right.comp[2]; 148 | return temp; 149 | } 150 | 151 | Vec3D operator/ (const double &left, const Vec3D &right) { 152 | Vec3D temp; 153 | temp.comp[0]=left/right.comp[0]; 154 | temp.comp[1]=left/right.comp[1]; 155 | temp.comp[2]=left/right.comp[2]; 156 | return temp; 157 | } 158 | 159 | Vec3D operator+ (const double &left, const Vec3D &right) { 160 | Vec3D temp; 161 | temp.comp[0]=left+right.comp[0]; 162 | temp.comp[1]=left+right.comp[1]; 163 | temp.comp[2]=left+right.comp[2]; 164 | return temp; 165 | } 166 | 167 | Vec3D operator+ (const Vec3D &left, const Vec3D &right) { 168 | Vec3D temp; 169 | temp.comp[0]=left.comp[0]+right.comp[0]; 170 | temp.comp[1]=left.comp[1]+right.comp[1]; 171 | temp.comp[2]=left.comp[2]+right.comp[2]; 172 | return temp; 173 | } 174 | 175 | Vec3D operator- (const double &left, const Vec3D &right) { 176 | Vec3D temp; 177 | temp.comp[0]=left-right.comp[0]; 178 | temp.comp[1]=left-right.comp[1]; 179 | temp.comp[2]=left-right.comp[2]; 180 | return temp; 181 | } 182 | 183 | Vec3D operator- (const Vec3D &left, const Vec3D &right) { 184 | Vec3D temp; 185 | temp.comp[0]=left.comp[0]-right.comp[0]; 186 | temp.comp[1]=left.comp[1]-right.comp[1]; 187 | temp.comp[2]=left.comp[2]-right.comp[2]; 188 | return temp; 189 | } 190 | 191 | bool Vec3D::operator== (const Vec3D &right) { 192 | return (comp[0]==right.comp[0] && comp[1]==right.comp[1] && comp[2]==right.comp[2]); 193 | } 194 | 195 | bool Vec3D::operator!= (const Vec3D &right) { 196 | return (comp[0]!=right.comp[0] || comp[1]!=right.comp[1] || comp[2]!=right.comp[2]); 197 | } 198 | 199 | double &Vec3D::operator[] (int i) {return comp[i];} 200 | 201 | ostream &operator<< (ostream &output,const Vec3D &right) { 202 | output << "{" << right.comp[0] << "," << right.comp[1] << "," << right.comp[2] << "}"; 203 | return output; 204 | } 205 | -------------------------------------------------------------------------------- /vec3d.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/vec3d.h -------------------------------------------------------------------------------- /vec4d.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | 3 | Copyright 2007-2009 Emre Sozer & Patrick Clark Trizila 4 | 5 | Contact: emresozer@freecfd.com , ptrizila@freecfd.com 6 | 7 | This file is a part of Free CFD 8 | 9 | Free CFD is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 4 of the License, or 12 | any later version. 13 | 14 | Free CFD is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | For a copy of the GNU General Public License, 20 | see . 21 | 22 | *************************************************************************/ 23 | #include 24 | #include 25 | #include 26 | using namespace std; 27 | #include "vec4d.h" 28 | 29 | Vec4D::Vec4D(double x, double y, double z, double r) { 30 | comp[0]=x; 31 | comp[1]=y; 32 | comp[2]=z; 33 | comp[3]=r; 34 | } 35 | 36 | double Vec4D::dot(const Vec4D &right) { 37 | return (comp[0]*right.comp[0]+comp[1]*right.comp[1]+comp[2]*right.comp[2]+comp[3]*right.comp[3]); 38 | } 39 | 40 | double fabs(const Vec4D vec) { 41 | return sqrt(vec.comp[0]*vec.comp[0]+vec.comp[1]*vec.comp[1]+vec.comp[2]*vec.comp[2]+vec.comp[3]*vec.comp[3]); 42 | } 43 | /* 44 | Vec4D Vec4D::cross(const Vec4D &right) { 45 | Vec4D temp; 46 | temp.comp[0]=comp[1]*right.comp[2]-comp[2]*right.comp[1]; 47 | temp.comp[1]=-comp[0]*right.comp[2]+comp[2]*right.comp[0]; 48 | temp.comp[2]=comp[0]*right.comp[1]-comp[1]*right.comp[0]; 49 | return temp; 50 | }*/ 51 | 52 | Vec4D Vec4D::norm(void) { 53 | return (*this)/=fabs(*this); 54 | } 55 | 56 | Vec4D &Vec4D::operator= (const Vec4D &right) { 57 | comp[0]=right.comp[0]; 58 | comp[1]=right.comp[1]; 59 | comp[2]=right.comp[2]; 60 | comp[3]=right.comp[3]; 61 | return *this; 62 | } 63 | 64 | Vec4D &Vec4D::operator= (const double &right) { 65 | comp[0]=right; 66 | comp[1]=right; 67 | comp[2]=right; 68 | comp[3]=right; 69 | return *this; 70 | } 71 | 72 | Vec4D &Vec4D::operator*= (const double &right) { 73 | comp[0]*=right; 74 | comp[1]*=right; 75 | comp[2]*=right; 76 | comp[3]*=right; 77 | 78 | return *this; 79 | } 80 | 81 | Vec4D Vec4D::operator*(const double &right) { 82 | Vec4D temp; 83 | temp.comp[0]=comp[0]*right; 84 | temp.comp[1]=comp[1]*right; 85 | temp.comp[2]=comp[2]*right; 86 | temp.comp[3]=comp[3]*right; 87 | return temp; 88 | } 89 | 90 | Vec4D &Vec4D::operator/= (const double &right) { 91 | comp[0]/=right; 92 | comp[1]/=right; 93 | comp[2]/=right; 94 | comp[3]/=right; 95 | return *this; 96 | } 97 | 98 | Vec4D Vec4D::operator/ (const double &right) { 99 | Vec4D temp; 100 | temp.comp[0]=comp[0]/right; 101 | temp.comp[1]=comp[1]/right; 102 | temp.comp[2]=comp[2]/right; 103 | temp.comp[3]=comp[3]/right; 104 | 105 | return temp; 106 | } 107 | 108 | Vec4D &Vec4D::operator+= (const double &right) { 109 | comp[0]+=right; 110 | comp[1]+=right; 111 | comp[2]+=right; 112 | comp[3]+=right; 113 | return *this; 114 | } 115 | 116 | Vec4D &Vec4D::operator+= (const Vec4D &right) { 117 | comp[0]+=right.comp[0]; 118 | comp[1]+=right.comp[1]; 119 | comp[2]+=right.comp[2]; 120 | comp[3]+=right.comp[3]; 121 | return *this; 122 | } 123 | 124 | Vec4D Vec4D::operator+ (const double &right) { 125 | Vec4D temp; 126 | temp.comp[0]=comp[0]+right; 127 | temp.comp[1]=comp[1]+right; 128 | temp.comp[2]=comp[2]+right; 129 | temp.comp[3]=comp[3]+right; 130 | return temp; 131 | } 132 | 133 | Vec4D &Vec4D::operator-= (const double &right) { 134 | comp[0]-=right; 135 | comp[1]-=right; 136 | comp[2]-=right; 137 | comp[3]-=right; 138 | return *this; 139 | } 140 | 141 | Vec4D &Vec4D::operator-= (const Vec4D &right) { 142 | comp[0]-=right.comp[0]; 143 | comp[1]-=right.comp[1]; 144 | comp[2]-=right.comp[2]; 145 | comp[3]-=right.comp[3]; 146 | return *this; 147 | } 148 | 149 | Vec4D Vec4D::operator- (const double &right) { 150 | Vec4D temp; 151 | temp.comp[0]=comp[0]-right; 152 | temp.comp[1]=comp[1]-right; 153 | temp.comp[2]=comp[2]-right; 154 | temp.comp[3]=comp[3]-right; 155 | return temp; 156 | } 157 | 158 | Vec4D operator*(const double &left, const Vec4D &right) { 159 | Vec4D temp; 160 | temp.comp[0]=left*right.comp[0]; 161 | temp.comp[1]=left*right.comp[1]; 162 | temp.comp[2]=left*right.comp[2]; 163 | temp.comp[3]=left*right.comp[3]; 164 | return temp; 165 | } 166 | 167 | Vec4D operator/ (const double &left, const Vec4D &right) { 168 | Vec4D temp; 169 | temp.comp[0]=left/right.comp[0]; 170 | temp.comp[1]=left/right.comp[1]; 171 | temp.comp[2]=left/right.comp[2]; 172 | temp.comp[3]=left/right.comp[3]; 173 | return temp; 174 | } 175 | 176 | Vec4D operator+ (const double &left, const Vec4D &right) { 177 | Vec4D temp; 178 | temp.comp[0]=left+right.comp[0]; 179 | temp.comp[1]=left+right.comp[1]; 180 | temp.comp[2]=left+right.comp[2]; 181 | temp.comp[3]=left+right.comp[3]; 182 | return temp; 183 | } 184 | 185 | Vec4D operator+ (const Vec4D &left, const Vec4D &right) { 186 | Vec4D temp; 187 | temp.comp[0]=left.comp[0]+right.comp[0]; 188 | temp.comp[1]=left.comp[1]+right.comp[1]; 189 | temp.comp[2]=left.comp[2]+right.comp[2]; 190 | temp.comp[3]=left.comp[3]+right.comp[3]; 191 | return temp; 192 | } 193 | 194 | Vec4D operator- (const double &left, const Vec4D &right) { 195 | Vec4D temp; 196 | temp.comp[0]=left-right.comp[0]; 197 | temp.comp[1]=left-right.comp[1]; 198 | temp.comp[2]=left-right.comp[2]; 199 | temp.comp[3]=left-right.comp[3]; 200 | return temp; 201 | } 202 | 203 | Vec4D operator- (const Vec4D &left, const Vec4D &right) { 204 | Vec4D temp; 205 | temp.comp[0]=left.comp[0]-right.comp[0]; 206 | temp.comp[1]=left.comp[1]-right.comp[1]; 207 | temp.comp[2]=left.comp[2]-right.comp[2]; 208 | temp.comp[3]=left.comp[3]-right.comp[3]; 209 | return temp; 210 | } 211 | 212 | bool Vec4D::operator== (const Vec4D &right) { 213 | return (comp[0]==right.comp[0] && comp[1]==right.comp[1] && comp[2]==right.comp[2]&& comp[3]==right.comp[3]); 214 | } 215 | 216 | bool Vec4D::operator!= (const Vec4D &right) { 217 | return (comp[0]!=right.comp[0] || comp[1]!=right.comp[1] || comp[2]!=right.comp[2]|| comp[3]!=right.comp[3]); 218 | } 219 | 220 | double &Vec4D::operator[] (int i) {return comp[i];} 221 | 222 | ostream &operator<< (ostream &output,const Vec4D &right) { 223 | output << "{" << right.comp[0] << "," << right.comp[1] << "," << right.comp[2] << "," << right.comp[3]<< "}"; 224 | return output; 225 | } 226 | -------------------------------------------------------------------------------- /vec4d.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/vec4d.h -------------------------------------------------------------------------------- /vecnd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | #include "vecnd.h" 8 | 9 | //Vec3D::Vec3D(double x, double y, double z) { 10 | // comp[0]=x; 11 | // comp[1]=y; 12 | // comp[2]=z; 13 | //} 14 | 15 | VecND::VecND(int n) { 16 | comp.resize(n,0.0); 17 | } 18 | 19 | void VecND::resize(int n, double r) { 20 | comp.clear(); 21 | comp.resize(n,r); 22 | } 23 | 24 | 25 | int VecND::size() { 26 | return comp.size(); 27 | } 28 | 29 | double VecND::dot(const VecND &right) { 30 | // double rtmp=0.0; 31 | // for(vdsz_type cnt=0; cnt!=comp.size(); ++cnt) 32 | // rtmp+=comp[cnt]*right.comp[cnt]; 33 | // return rtmp; 34 | return (inner_product(comp.begin(), comp.end(), right.comp.begin(),0.0)); 35 | // return (comp[0]*right.comp[0]+comp[1]*right.comp[1]+comp[2]*right.comp[2]); 36 | } 37 | 38 | double fabs(const VecND &vec) { 39 | //return sqrt(vec.comp[0]*vec.comp[0]+vec.comp[1]*vec.comp[1]+vec.comp[2]*vec.comp[2]); 40 | //return sqrt(vec.dot(vec)); 41 | 42 | double rtmp=0.0; 43 | for(vdsz_type cnt=0; cnt!=vec.comp.size(); ++cnt) 44 | rtmp+=vec.comp[cnt]*vec.comp[cnt]; 45 | return sqrt(rtmp); 46 | } 47 | 48 | //Vec3D Vec3D::cross(const Vec3D &right) { 49 | // Vec3D temp; 50 | // temp.comp[0]=comp[1]*right.comp[2]-comp[2]*right.comp[1]; 51 | // temp.comp[1]=-comp[0]*right.comp[2]+comp[2]*right.comp[0]; 52 | // temp.comp[2]=comp[0]*right.comp[1]-comp[1]*right.comp[0]; 53 | // return temp; 54 | //} 55 | 56 | VecND VecND::norm(void) { 57 | return (*this)/=fabs(*this); 58 | } 59 | 60 | VecND &VecND::operator= (const VecND &right) { 61 | comp=right.comp; 62 | /// comp[0]=right.comp[0]; 63 | // comp[1]=right.comp[1]; 64 | // comp[2]=right.comp[2]; 65 | return *this; 66 | } 67 | 68 | VecND &VecND::operator= (const double &right) { 69 | for(vdsz_type cnt=0; cnt!=comp.size();++cnt) 70 | comp[cnt]=right; 71 | //comp[0]=right; 72 | //comp[1]=right; 73 | //comp[2]=right; 74 | return *this; 75 | } 76 | 77 | VecND &VecND::operator*= (const double &right) { 78 | for(vdsz_type cnt=0; cnt!=comp.size();++cnt) 79 | comp[cnt]*=right; 80 | //comp[0]*=right; 81 | // comp[1]*=right; 82 | // comp[2]*=right; 83 | return *this; 84 | } 85 | 86 | VecND VecND::operator*(const double &right) { 87 | VecND temp(comp.size()); 88 | for(vdsz_type cnt=0; cnt!=comp.size();++cnt) { 89 | temp.comp[cnt]=comp[cnt]*right; 90 | } 91 | 92 | // Vec3D temp; 93 | // temp.comp[0]=comp[0]*right; 94 | // temp.comp[1]=comp[1]*right; 95 | // temp.comp[2]=comp[2]*right; 96 | return temp; 97 | } 98 | 99 | VecND &VecND::operator/= (const double &right) { 100 | for(vdsz_type cnt=0; cnt!=comp.size();++cnt) 101 | comp[cnt]/=right; 102 | //comp[0]/=right; 103 | //comp[1]/=right; 104 | //comp[2]/=right; 105 | return *this; 106 | } 107 | 108 | VecND VecND::operator/ (const double &right) { 109 | VecND temp(comp.size()); 110 | for(vdsz_type cnt=0; cnt!=comp.size();++cnt) 111 | temp.comp[cnt]=comp[cnt]/right; 112 | //Vec3D temp; 113 | // temp.comp[0]=comp[0]/right; 114 | // temp.comp[1]=comp[1]/right; 115 | // temp.comp[2]=comp[2]/right; 116 | return temp; 117 | } 118 | 119 | VecND &VecND::operator+= (const double &right) { 120 | for(vdsz_type cnt=0; cnt!=comp.size();++cnt) 121 | comp[cnt]+=right; 122 | /// comp[0]+=right; 123 | // comp[1]+=right; 124 | // comp[2]+=right; 125 | return *this; 126 | } 127 | 128 | VecND &VecND::operator+= (const VecND &right) { 129 | for(vdsz_type cnt=0; cnt!=comp.size();++cnt) 130 | comp[cnt]+=right.comp[cnt]; 131 | // comp[0]+=right.comp[0]; 132 | // comp[1]+=right.comp[1]; 133 | // comp[2]+=right.comp[2]; 134 | return *this; 135 | } 136 | 137 | VecND VecND::operator+ (const double &right) { 138 | VecND temp(comp.size()); 139 | for(vdsz_type cnt=0; cnt!=comp.size();++cnt) 140 | temp.comp[cnt]=comp[cnt]+right; 141 | //Vec3D temp; 142 | //temp.comp[0]=comp[0]+right; 143 | //temp.comp[1]=comp[1]+right; 144 | //temp.comp[2]=comp[2]+right; 145 | return temp; 146 | } 147 | 148 | VecND &VecND::operator-= (const double &right) { 149 | 150 | for(vdsz_type cnt=0; cnt!=comp.size();++cnt) 151 | comp[cnt]-=right; 152 | // comp[0]-=right; 153 | /// comp[1]-=right; 154 | // comp[2]-=right; 155 | return *this; 156 | } 157 | 158 | VecND &VecND::operator-= (const VecND &right) { 159 | 160 | for(vdsz_type cnt=0; cnt!=comp.size();++cnt) 161 | comp[cnt]-=right.comp[cnt]; 162 | // comp[0]-=right.comp[0]; 163 | // comp[1]-=right.comp[1]; 164 | // comp[2]-=right.comp[2]; 165 | return *this; 166 | } 167 | 168 | VecND VecND::operator- (const double &right) { 169 | VecND temp(comp.size()); 170 | for(vdsz_type cnt=0; cnt!=comp.size();++cnt) 171 | temp.comp[cnt]=comp[cnt]-right; 172 | //VecND temp; 173 | // temp.comp[0]=comp[0]-right; 174 | //temp.comp[1]=comp[1]-right; 175 | // temp.comp[2]=comp[2]-right; 176 | return temp; 177 | } 178 | 179 | VecND operator*(const double &left, const VecND &right) { 180 | VecND temp(right.comp.size()); 181 | for(vdsz_type cnt=0; cnt!=right.comp.size();++cnt) 182 | temp.comp[cnt]=left*right.comp[cnt]; 183 | //Vec3D temp; 184 | //temp.comp[0]=left*right.comp[0]; 185 | //temp.comp[1]=left*right.comp[1]; 186 | // temp.comp[2]=left*right.comp[2]; 187 | return temp; 188 | } 189 | 190 | VecND operator/ (const double &left, const VecND &right) { 191 | VecND temp(right.comp.size()); 192 | for(vdsz_type cnt=0; cnt!=right.comp.size();++cnt) 193 | temp.comp[cnt]=left/right.comp[cnt]; 194 | // Vec3D temp; 195 | // temp.comp[0]=left/right.comp[0]; 196 | // temp.comp[1]=left/right.comp[1]; 197 | // temp.comp[2]=left/right.comp[2]; 198 | return temp; 199 | } 200 | 201 | VecND operator+ (const double &left, const VecND &right) { 202 | VecND temp(right.comp.size()); 203 | for(vdsz_type cnt=0; cnt!=right.comp.size();++cnt) 204 | temp.comp[cnt]=left+right.comp[cnt]; 205 | // Vec3D temp; 206 | // temp.comp[0]=left+right.comp[0]; 207 | // temp.comp[1]=left+right.comp[1]; 208 | // temp.comp[2]=left+right.comp[2]; 209 | return temp; 210 | } 211 | 212 | VecND operator+ (const VecND &left, const VecND &right) { 213 | VecND temp(right.comp.size()); 214 | for(vdsz_type cnt=0; cnt!=right.comp.size();++cnt) 215 | temp.comp[cnt]=left.comp[cnt]+right.comp[cnt]; 216 | // Vec3D temp; 217 | // temp.comp[0]=left.comp[0]+right.comp[0]; 218 | // temp.comp[1]=left.comp[1]+right.comp[1]; 219 | // temp.comp[2]=left.comp[2]+right.comp[2]; 220 | return temp; 221 | } 222 | 223 | VecND operator- (const double &left, const VecND &right) { 224 | VecND temp(right.comp.size()); 225 | for(vdsz_type cnt=0; cnt!=right.comp.size();++cnt) 226 | temp.comp[cnt]=left-right.comp[cnt]; 227 | // Vec3D temp; 228 | // temp.comp[0]=left-right.comp[0]; 229 | // temp.comp[1]=left-right.comp[1]; 230 | // temp.comp[2]=left-right.comp[2]; 231 | return temp; 232 | } 233 | 234 | VecND operator- (const VecND &left, const VecND &right) { 235 | VecND temp(right.comp.size()); 236 | for(vdsz_type cnt=0; cnt!=right.comp.size();++cnt) 237 | temp.comp[cnt]=left.comp[cnt]-right.comp[cnt]; 238 | // Vec3D temp; 239 | // temp.comp[0]=left.comp[0]-right.comp[0]; 240 | // temp.comp[1]=left.comp[1]-right.comp[1]; 241 | // temp.comp[2]=left.comp[2]-right.comp[2]; 242 | return temp; 243 | } 244 | 245 | bool VecND::operator== (const VecND &right) { 246 | return (comp==right.comp); 247 | //return (comp[0]==right.comp[0] && comp[1]==right.comp[1] && comp[2]==right.comp[2]); 248 | } 249 | 250 | bool VecND::operator!= (const VecND &right) { 251 | return (comp!=right.comp); 252 | // return (comp[0]!=right.comp[0] || comp[1]!=right.comp[1] || comp[2]!=right.comp[2]); 253 | } 254 | 255 | double &VecND::operator[] (int i) {return comp[i];} 256 | 257 | ostream &operator<< (ostream &output,const VecND &right) { 258 | //output << "{" << right.comp[0] << "," << right.comp[1] << "," << right.comp[2] << "}"; 259 | output << "{"; 260 | for(vdsz_type cnt=0; cnt!=right.comp.size()-1;++cnt) 261 | output << right.comp[cnt]<<","; 262 | output << right.comp[right.comp.size()-1]<<"}"; 263 | return output; 264 | } 265 | -------------------------------------------------------------------------------- /vecnd.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/vecnd.h -------------------------------------------------------------------------------- /wall4amrdg2013.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/wall4amrdg2013.cpp -------------------------------------------------------------------------------- /wall4amrdgOct26.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesliu516/amrdg2d/1845a6c455907383b36b3c6df5c9a4914b6fd334/wall4amrdgOct26.cpp --------------------------------------------------------------------------------