static void parse_util_args (int argc, char *argv[], FileList *f){ char c; if (argc == 0) { fputs (usage, stderr); exit (1); } iparam_set("Dump", 0); while (--argc && (*++argv)[0] == '-') { while (c = *++argv[0]) /* more to parse... */ switch (c) { case 'c': option_set("CONCATENATEDFILE",1); break; case 'd': if (*++argv[0]) iparam_set("Dump", atoi(*argv)); else { iparam_set("Dump", atoi(*++argv)); argc--; } (*argv)[1] = '\0'; break; case 'p': if (*++argv[0]) option_set("Nfiles", atoi(*argv)); else { option_set("Nfiles", atoi(*++argv)); argc--; } (*argv)[1] = '\0'; break; case 't': option_set("Totheader",1); break; default: fprintf(stderr, "%s: unknown option -- %c\n", prog, c); break; } } f->in.name = strdup(*argv); /* open input file */ if (option("verbose")) { fprintf (stderr, "%s: in = %s, rea = %s, out = %s\n", prog, f->in.name ? f->in.name : "<stdin>", f->rea.name, f->out.name ? f->out.name : "<stdout>"); } return; }
static void setup (FileList *f, Element_List **U){ int i,k; Curve *curve; ReadParams (f->rea.fp); //option_set("FAMOFF", 1); if((i=iparam("NORDER-req"))!=UNSET){ iparam_set("LQUAD",i); iparam_set("MQUAD",i); } *U = ReadMesh(f->rea.fp, strtok(f->rea.name,".")); /* Generate the list of elements */ U[0]->Cat_mem(); if(option("variable")) ReadOrderFile (strtok(f->rea.name,"."),*U); if(f->mesh.name) Get_Body(f->mesh.fp); return; }
Element_List *setup_surflist(Domain *omega, Bndry *Ubc, char type){ Bndry *Bc; Element **selmt; int S_nbcs, i,j,k; Coord X; iparam_set("FAMILIES", 0); Element_List *U = omega->U; X.x = dvector(0, 4); X.y = dvector(0, 4); for(S_nbcs = 0, Bc = Ubc ; Bc ; Bc=Bc->next) if(Bc->type == type){ ++S_nbcs; #ifdef TRI_SURF if(Bc->elmt->Nfverts(Bc->face) != 3){ fprintf(stderr,"Quad face attached to surface: Check setup_trilist\n"); exit(-1); } #endif } if(!S_nbcs) return (Element_List *) NULL; selmt = (Element **) calloc (S_nbcs, sizeof(Element *)); i = 0; for(Bc = Ubc;Bc;Bc=Bc->next) if(Bc->type == type){ X.x[0] = -1.0; X.y[0] = -1.0; X.x[1] = 1.0; X.y[1] = -1.0; if(Bc->elmt->Nfverts(Bc->face) == 3){ X.x[2] = -1.0; X.y[2] = 1.0; int faceid = (Bc->elmt->identify() == Nek_Tet)? 0: 1; selmt[i++] = (Element*) new Tri(i, type,Bc->elmt->lmax, Bc->elmt->get_face_q1(faceid), Bc->elmt->get_face_q2(faceid), 0, &X); } else{ X.x[2] = 1.0; X.y[2] = 1.0; X.x[3] = -1.0; X.y[3] = 1.0; selmt[i++] = (Element*) new Quad(i, type,Bc->elmt->lmax, Bc->elmt->get_face_q1(0), Bc->elmt->get_face_q2(0), 0, &X); } } for(i = 0; i < S_nbcs-1; ++i) selmt[i]->next = selmt[i+1]; selmt[i]->next = (Element*) NULL; Element_List *surf_list = (Element_List*) new Element_List(selmt, S_nbcs); surf_list->Cat_mem(); i = 0; for(Bc = Ubc;Bc;Bc=Bc->next) if(Bc->type == type){ selmt[i]->id = i; selmt[i]->set_geofac(); selmt[i]->set_curved_elmt((Element_List*)NULL); for(j=0;j<Bc->elmt->Nfverts(Bc->face);++j){ selmt[i]->vert[j].gid = Bc->elmt->vert[Bc->elmt->vnum(Bc->face,j)].gid; selmt[i]->edge[j].gid = Bc->elmt->edge[Bc->elmt->ednum(Bc->face,j)].gid; selmt[i]->edge[j].con = Bc->elmt->edge[Bc->elmt->ednum(Bc->face,j)].con; } ++i; } free(X.x); free(X.y); return surf_list; }
static void parse_util_args (int argc, char *argv[], FileList *f) { char c; int i; char fname[FILENAME_MAX]; if (argc == 0) { fputs (usage, stderr); exit (1); } option_set("SingMesh",0); while (--argc && (*++argv)[0] == '-') { while (c = *++argv[0]) /* more to parse... */ switch (c) { case 'b': option_set("Body",1); break; case 'e': if (*++argv[0]) option_set("ELMTID", atoi(*argv)); else { option_set("ELMTID", atoi(*++argv)); argc--; } while(*++argv[0]); /* skip over whole number */ case 'R': option_set("Range",1); break; case 'g': option_set("SingMesh",1); break; case 's': option_set("Spre",1); break; case 'q': option_set("Qpts",1); break; case 'f': option_set("FEstorage",1); break; case 'S': option_set("SMformat",1); break; default: fprintf(stderr, "%s: unknown option -- %c\n", prog, c); break; } } #if DIM ==2 if(iparam("NORDER-req") == UNSET) iparam_set("NORDER-req",8); #endif /* open the .rea file */ if ((*argv)[0] == '-') { f->rea.fp = stdin; } else { strcpy (fname, *argv); if ((f->rea.fp = fopen(fname, "r")) == (FILE*) NULL) { sprintf(fname, "%s.rea", *argv); if ((f->rea.fp = fopen(fname, "r")) == (FILE*) NULL) { fprintf(stderr, "%s: unable to open the input file -- %s or %s\n", prog, *argv, fname); exit(1); } } f->rea.name = strdup(fname); } if (option("verbose")) { fprintf (stderr, "%s: in = %s, rea = %s, out = %s\n", prog, f->in.name ? f->in.name : "<stdin>", f->rea.name, f->out.name ? f->out.name : "<stdout>"); } return; }
main (int argc, char *argv[]){ int i,j,k; manager_init(); parse_util_args(argc, argv); iparam_set("LQUAD",3); iparam_set("MQUAD",3); iparam_set("NQUAD",3); iparam_set("MODES",iparam("LQUAD")-1); char *buf = (char*) calloc(BUFSIZ, sizeof(char)); char *fname = (char*) calloc(BUFSIZ, sizeof(char)); get_string("Enter name of input file", buf); sprintf(fname, strtok(buf, "\n")); Grid *grid = new Grid(fname); Grid *grida = new Grid(grid); grida->RenumberPrisms(); grida->FixPrismOrientation(); grid->ImportPrismOrientation(grida); grida->RemovePrisms(); grida->RemoveHexes(); grida->FixTetOrientation(); grid->ImportTetOrientation(grida); Element_List *U = grid->gen_aux_field(); int nel = U->nel; get_string("Enter name of output file", buf); sprintf(fname, strtok(buf, "\n")); FILE *fout = fopen(fname, "w"); int Nfields, Nbdry; get_int ("Enter number of fields", &Nfields); get_int ("Enter number of boundaries (including default)", &Nbdry); char **eqn = (char**) calloc(Nfields, sizeof(char*)); for(i=0;i<Nfields;++i){ eqn[i] = (char*)calloc(BUFSIZ, sizeof(char)); } Bndry *Bc; Bndry **Vbc = (Bndry**) calloc(Nfields, sizeof(Bndry*)); char *bndryeqn = (char*) calloc(BUFSIZ, sizeof(char)); int **bcmatrix = imatrix(0, U->nel-1, 0, Max_Nfaces-1); izero(U->nel*Max_Nfaces, bcmatrix[0], 1); int nb; char type; char curved, curvetype; Curve *cur; int curveid = 0; for(nb=0;nb<Nbdry;++nb){ if(nb != Nbdry-1){ fprintf(stderr, "#\nBoundary: %d\n#\n", nb+1); get_string("Enter function which has roots at boundary", bndryeqn); fprintf(stderr, "#\n"); } else{ fprintf(stderr, "#\nDefault Boundary:\n#\n"); } get_char("Enter character type\n(v=velocity)\n" "(W=wall)\n(O=outflow)\n(s=flux (Compressible only))\n", &type); fprintf(stderr, "#\n"); switch(type){ case 'W': case 'O': break; case 'v': case 's': for(i=0;i<Nfields;++i){ get_string("Enter function definition", eqn[i]); fprintf(stderr, "\n"); } } get_char("Is this boundary curved (y/n)?", &curved); if(curved == 'y'){ ++curveid; get_char("Enter curve type\n(S=sphere)\n(C=cylinder)\n(T=taurus)\n", &curvetype); switch(curvetype){ case 'S':{ double cx, cy, cz, cr; get_double("Enter center x-coord", &cx); get_double("Enter center y-coord", &cy); get_double("Enter center z-coord", &cz); get_double("Enter radius", &cr); cur = (Curve*) calloc(1, sizeof(Curve)); cur->type = T_Sphere; cur->info.sph.xc = cx; cur->info.sph.yc = cy; cur->info.sph.zc = cz; cur->info.sph.radius = cr; cur->id = curveid; break; } case 'C':{ double cx, cy, cz, cr; double ax, ay, az; get_double("Enter point on axis x-coord", &cx); get_double("Enter point on axis y-coord", &cy); get_double("Enter point on axis z-coord", &cz); get_double("Enter axis vector x-coord", &ax); get_double("Enter axis vector y-coord", &ay); get_double("Enter axis vector z-coord", &az); get_double("Enter radius", &cr); cur = (Curve*) calloc(1, sizeof(Curve)); cur->type = T_Cylinder; cur->info.cyl.xc = cx; cur->info.cyl.yc = cy; cur->info.cyl.zc = cz; cur->info.cyl.ax = ax; cur->info.cyl.ay = ay; cur->info.cyl.az = az; cur->info.cyl.radius = cr; cur->id = curveid; break; } } } if(nb == Nbdry-1) break; double res; Element *E; for(E=U->fhead;E;E=E->next){ for(i=0;i<E->Nfaces;++i){ for(j=0;j<E->Nfverts(i);++j){ vector_def("x y z",bndryeqn); vector_set(1, &(E->vert[E->fnum(i,j)].x), &(E->vert[E->fnum(i,j)].y), &(E->vert[E->fnum(i,j)].z), &res); if(fabs(res)> TOL) break; } if(j==E->Nfverts(i)){ if(curved == 'y'){ E->curve = (Curve*) calloc(1, sizeof(Curve)); memcpy(E->curve, cur, sizeof(Curve)); E->curve->face = i; } switch(type){ case 'W': case 'O': for(j=0;j<Nfields;++j){ Bc = E->gen_bndry(type, i, 0.); Bc->type = type; add_bc(&Vbc[j], Bc); } bcmatrix[E->id][i] = 1; break; case 'v': case 's': for(j=0;j<Nfields;++j){ Bc = E->gen_bndry(type, i, eqn[j]); Bc->type = type; add_bc(&Vbc[j], Bc); } bcmatrix[E->id][i] = 1; break; } } } } } char is_periodic; get_char("Is there periodicity in the x-direction (y/n)?", &is_periodic); if(is_periodic == 'y') get_double("Enter periodic length",&XPERIOD); get_char("Is there periodicity in the y-direction (y/n)?", &is_periodic); if(is_periodic == 'y') get_double("Enter periodic length",&YPERIOD); get_char("Is there periodicity in the z-direction (y/n)?", &is_periodic); if(is_periodic == 'y') get_double("Enter periodic length",&ZPERIOD); // Do remaining connections Element *E, *F; for(E=U->fhead;E;E=E->next) for(i=0;i<E->Nfaces;++i) if(!bcmatrix[E->id][i]) for(F=E;F;F=F->next) for(j=0;j<F->Nfaces;++j) if(!bcmatrix[F->id][j]) if(neighbourtest(E,i,F,j) && !(E->id == F->id && i==j)){ bcmatrix[E->id][i] = 2; bcmatrix[F->id][j] = 2; set_link(E,i,F,j); break; } // if the default bc is curved the make default bndries curved if(curved == 'y'){ for(E=U->fhead;E;E=E->next) for(i=0;i<E->Nfaces;++i) if(!bcmatrix[E->id][i]){ E->curve = (Curve*) calloc(1, sizeof(Curve)); memcpy(E->curve, cur, sizeof(Curve)); E->curve->face = i; } } fprintf(fout, "****** PARAMETERS *****\n"); fprintf(fout, " SolidMes \n"); fprintf(fout, " 3 DIMENSIONAL RUN\n"); fprintf(fout, " 0 PARAMETERS FOLLOW\n"); fprintf(fout, "0 Lines of passive scalar data follows2 CONDUCT; 2RHOCP\n"); fprintf(fout, " 0 LOGICAL SWITCHES FOLLOW\n"); fprintf(fout, "Dummy line from old nekton file\n"); fprintf(fout, "**MESH DATA** x,y,z, values of vertices 1,2,3,4.\n"); fprintf(fout, "%d 3 1 NEL NDIM NLEVEL\n", U->nel); for(E=U->fhead;E;E=E->next){ switch(E->identify()){ case Nek_Tet: fprintf(fout, "Element %d Tet\n", E->id+1); break; case Nek_Pyr: fprintf(fout, "Element %d Pyr\n", E->id+1); break; case Nek_Prism: fprintf(fout, "Element %d Prism\n", E->id+1); break; case Nek_Hex: fprintf(fout, "Element %d Hex\n", E->id+1); break; } for(i=0;i<E->Nverts;++i) fprintf(fout, "%lf ", E->vert[i].x); fprintf(fout, "\n"); for(i=0;i<E->Nverts;++i) fprintf(fout, "%lf ", E->vert[i].y); fprintf(fout, "\n"); for(i=0;i<E->Nverts;++i) fprintf(fout, "%lf ", E->vert[i].z); fprintf(fout, "\n"); } fprintf(fout, "***** CURVED SIDE DATA ***** \n"); fprintf(fout, "%d Number of curve types\n", curveid); for(i=0;i<curveid;++i){ int flag = 0; for(E=U->fhead;!flag && E;E=E->next){ if(E->curve && E->curve->type != T_Straight){ if(E->curve->id == i+1){ switch(E->curve->type){ case T_Sphere: fprintf(fout, "Sphere\n"); fprintf(fout, "%lf %lf %lf %lf %c\n", E->curve->info.sph.xc, E->curve->info.sph.yc, E->curve->info.sph.zc, E->curve->info.sph.radius, 'a'+i+1); flag = 1; break; case T_Cylinder: fprintf(fout, "Cylinder\n"); fprintf(fout, "%lf %lf %lf %lf %lf %lf %lf %c\n", E->curve->info.cyl.xc, E->curve->info.cyl.yc, E->curve->info.cyl.zc, E->curve->info.cyl.ax, E->curve->info.cyl.ay, E->curve->info.cyl.az, E->curve->info.cyl.radius, 'a'+i+1); flag = 1; break; } } } } } int ncurvedsides = 0; for(E=U->fhead;E;E=E->next){ if(E->curve && E->curve->type != T_Straight) ++ncurvedsides; } fprintf(fout, "%d Curved sides follow\n", ncurvedsides); for(E=U->fhead;E;E=E->next) if(E->curve && E->curve->type != T_Straight) fprintf(fout, "%d %d %c\n", E->curve->face+1, E->id+1, 'a'+E->curve->id); fprintf(fout, "***** BOUNDARY CONDITIONS ***** \n"); fprintf(fout, "***** FLUID BOUNDARY CONDITIONS ***** \n"); for(E=U->fhead;E;E=E->next){ for(j=0;j<E->Nfaces;++j){ if(bcmatrix[E->id][j] == 2){ fprintf(fout, "E %d %d %d %d\n", E->id+1, j+1, E->face[j].link->eid+1, E->face[j].link->id+1); } else if(bcmatrix[E->id][j] == 1){ for(i=0;i<Nfields;++i) for(Bc=Vbc[i];Bc;Bc=Bc->next){ if(Bc->elmt == E && Bc->face == j){ if(i==0) switch(Bc->type){ case 'W': fprintf(fout, "W %d %d 0. 0. 0.\n", E->id+1, j+1); break; case 'O': fprintf(fout, "O %d %d 0. 0. 0.\n", E->id+1, j+1); break; case 'v': fprintf(fout, "v %d %d 0. 0. 0.\n", E->id+1, j+1); break; case 's': fprintf(fout, "s %d %d 0. 0. 0.\n", E->id+1, j+1); break; } if(Bc->type == 's' || Bc->type == 'v') fprintf(fout, "%c=%s\n", 'u'+i,Bc->bstring); break; } } } else{ switch(type){ case 'W': fprintf(fout, "W %d %d 0. 0. 0.\n", E->id+1, j+1); break; case 'O': fprintf(fout, "O %d %d 0. 0. 0.\n", E->id+1, j+1); break; case 'v': fprintf(fout, "v %d %d 0. 0. 0.\n", E->id+1, j+1); break; case 's': fprintf(fout, "s %d %d 0. 0. 0.\n", E->id+1, j+1); break; } if(type == 's' || type == 'v') for(i=0;i<Nfields;++i) fprintf(fout, "%c=%s\n", 'u'+i,eqn[i]); } } } char bufa[BUFSIZ]; fprintf(fout, "***** NO THERMAL BOUNDARY CONDITIONS *****\n"); get_char("Are you using a field file restart (y/n)?", &type); if(type == 'y'){ fprintf(fout, "%d INITIAL CONDITIONS *****\n",1); get_string("Enter name of restart file:", buf); fprintf(fout, "Restart\n"); fprintf(fout, "%s\n", buf); } else{ fprintf(fout, "%d INITIAL CONDITIONS *****\n",1+Nfields); fprintf(fout, "Given\n"); for(i=0;i<Nfields;++i){ sprintf(bufa, "Field %d ", i+1); get_string(bufa, buf); fprintf(fout, "%s\n", buf); } } fprintf(fout, "***** DRIVE FORCE DATA ***** PRESSURE GRAD, FLOW, Q\n"); get_char("Are you using a forcing function (y/n)?", &type); if(type == 'y'){ fprintf(fout, "%d Lines of Drive force data follow\n", Nfields); for(i=0;i<Nfields;++i){ sprintf(bufa, "FF%c = ", 'X'+i); get_string(bufa,buf); fprintf(fout, "FF%c = %s\n",'X'+i, buf); } } else{ fprintf(fout, "0 Lines of Drive force data follow\n"); } fprintf(fout, "***** Variable Property Data ***** Overrrides Parameter data.\n"); fprintf(fout, " 1 Lines follow.\n"); fprintf(fout, " 0 PACKETS OF DATA FOLLOW\n"); fprintf(fout, "***** HISTORY AND INTEGRAL DATA *****\n"); get_char("Are you using history points (y/n)?", &type); if(type == 'y'){ int npoints; get_int ("Enter number of points", &npoints); fprintf(fout, " %d POINTS. Hcode, I,J,H,IEL\n", npoints); for(i=0;i<npoints;++i){ sprintf(bufa, "Enter element number for point %d", i+1); get_int(bufa,&j); sprintf(bufa, "Enter vertex number for point %d", i+1); get_int(bufa, &k); fprintf(fout, "UVWP H %d 1 1 %d\n", k, j); } } else{ fprintf(fout, " 0 POINTS. Hcode, I,J,H,IEL\n"); } fprintf(fout, " ***** OUTPUT FIELD SPECIFICATION *****\n"); fprintf(fout, " 0 SPECIFICATIONS FOLLOW\n"); return 0; }
Element_List *Grid::gen_aux_field(){ int L, qa, qb, qc=0, k; char buf[BUFSIZ]; char buf_a[BUFSIZ]; Element **new_E; register int i; option_set("NZ",1); option_set("NZTOT",1); /* set up modes and quadrature points */ if(!( L = iparam("MODES"))) {fputs("ReadMesh: Number of modes not specified\n",stderr);exit(-1);} /* note quadrature order reset for variable order runs */ if(qa = iparam("LQUAD")); else qa = L + 1; if(qb = iparam("MQUAD")); else qb = L; if(qc = iparam("NQUAD")); else qc = L; iparam_set("ELEMENTS", nel); /* Set up a new element vector */ QGmax = max(max(qa,qb),qc); LGmax = L; new_E = (Element**) malloc(nel*sizeof(Element*)); Coord X; X.x = dvector(0,Max_Nverts-1); X.y = dvector(0,Max_Nverts-1); X.z = dvector(0,Max_Nverts-1); /* Read in mesh information */ for(k = 0; k < nel; k++) { for(i=0;i<nverts[k];++i){ X.x[i] = xcoords[vertids[k][vertexmap[k][i]]]; X.y[i] = ycoords[vertids[k][vertexmap[k][i]]]; X.z[i] = zcoords[vertids[k][vertexmap[k][i]]]; } switch(nverts[k]){ case 4: new_E[k] = new Tet(k,'u', L, qa, qb, qb, &X); break; case 8: new_E[k] = new Hex(k,'u', L, qa, qa, qa, &X); break; case 6: new_E[k] = new Prism(k,'u', L, qa, qa, qb, &X); break; case 5: new_E[k] = new Pyr(k,'u', L, qa, qa, qb, &X); break; } } for(k = 0; k < nel-1; ++k) new_E[k]->next = new_E[k+1]; new_E[k]->next = (Element*) NULL; Element_List* E_List = (Element_List*) new Element_List(new_E, nel); E_List->Cat_mem(); Tri_work(); Quad_work(); for(k = 0; k < nel; ++k) new_E[k]->set_curved_elmt(E_List); for(k = 0; k < nel; ++k) new_E[k]->set_geofac(); return E_List; }