From cd2bb14496e0cd62b9d1cc40f70cb005fbcd069b Mon Sep 17 00:00:00 2001 From: "Jeffrey N. Johnson" Date: Fri, 23 Jul 2021 11:09:41 -0700 Subject: [PATCH] Fixes a few compiler warnings (and some whitespace). --- src/mesh/tdycoremesh.c | 6 +-- src/mesh/tdycoremeshutils.c | 30 ++++++------- src/tdyio.c | 87 +++++++++++++++++++------------------ 3 files changed, 60 insertions(+), 63 deletions(-) diff --git a/src/mesh/tdycoremesh.c b/src/mesh/tdycoremesh.c index 1199d940..0a0955be 100644 --- a/src/mesh/tdycoremesh.c +++ b/src/mesh/tdycoremesh.c @@ -3254,7 +3254,7 @@ PetscErrorCode SetupSubcellsFor3DMesh(TDy tdy) { // nu_vec on the "iface"-th is given as: // = (x_{iface+1} - x_{cell_centroid}) x (x_{iface+2} - x_{cell_centroid}) // = (x_{f1_idx } - x_{cell_centroid}) x (x_{f2_idx } - x_{cell_centroid}) - PetscInt f1_idx, f2_idx, f3_idx; + PetscInt f1_idx = -1, f2_idx = -1, f3_idx = -1; // determin the f1_idx and f2_idx PetscReal f1[3], f2[3], f3[3]; @@ -3275,10 +3275,6 @@ PetscErrorCode SetupSubcellsFor3DMesh(TDy tdy) { f1_idx = 0; f2_idx = 1; f3_idx = 2; - break; - - default: - break; } // Save x_{f1_idx } and x_{f2_idx } diff --git a/src/mesh/tdycoremeshutils.c b/src/mesh/tdycoremeshutils.c index e4a8298d..ee1ad363 100644 --- a/src/mesh/tdycoremeshutils.c +++ b/src/mesh/tdycoremeshutils.c @@ -460,7 +460,7 @@ PetscErrorCode TDySubCell_GetIthNuVector(TDySubcell *subcells, PetscInt isubcell if (i>=subcells->num_nu_vectors[isubcell]) { SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Subcell: Requested i-th nu_vec exceeds max nu_vecs"); } - + for (d=0; dnu_vector[sOffsetNu + i].V[d]; PetscFunctionReturn(0); } @@ -474,7 +474,7 @@ PetscErrorCode TDySubCell_GetIthNuStarVector(TDySubcell *subcells, PetscInt isub if (i>=subcells->num_nu_vectors[isubcell]) { SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Subcell: Requested i-th nu_vec exceeds max nu_vecs"); } - + for (d=0; dnu_star_vector[sOffsetNu + i].V[d]; PetscFunctionReturn(0); } @@ -622,23 +622,23 @@ PetscErrorCode FindFaceIDsOfACellCommonToAVertex(PetscInt cell_id, TDyFace *face TDyVertex *vertices, PetscInt ivertex, PetscInt f_idx[3], PetscInt *num_shared_faces) { - + PetscFunctionBegin; - + PetscInt iface; //PetscInt cell_id = cell->id; - + *num_shared_faces = 0; - + // Find the faces of "cell_id" that are shared by the vertex for (iface=0; ifacenum_faces[ivertex]; iface++){ - + PetscInt vOffsetFace = vertices->face_offset[ivertex]; PetscInt face_id = vertices->face_ids[vOffsetFace + iface]; PetscInt fOffsetCell = faces->cell_offset[face_id]; - + if (faces->cell_ids[fOffsetCell + 0] == cell_id || faces->cell_ids[fOffsetCell + 1] == cell_id){ - + // Check if the number of shared faces doesn't exceed max faces if ((*num_shared_faces) == 3) { (*num_shared_faces)++; @@ -648,12 +648,12 @@ PetscErrorCode FindFaceIDsOfACellCommonToAVertex(PetscInt cell_id, TDyFace *face (*num_shared_faces)++; } } - + if (*num_shared_faces != 3) { printf("Was expecting to find 3 faces of the cell to be shared by the vertex, but instead found %d common faces\n",*num_shared_faces); SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Unsupported vertex type for 3D mesh"); } - + PetscFunctionReturn(0); } @@ -707,7 +707,7 @@ PetscErrorCode IdentifyLocalVertices(TDy tdy) { PetscFunctionBegin; - + ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd); CHKERRQ(ierr); for (ivertex=0; ivertexnum_vertices; ivertex++) { @@ -852,9 +852,9 @@ PetscErrorCode TDyFindSubcellOfACellThatIncludesAVertex(TDyCell *cells, PetscInt if (isubcell == -1) { SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Did not find a subcell of a given cell that includes the given vertex"); } - + *subcell_id = cells->id[cell_id]*cells->num_subcells[cell_id]+isubcell; - + PetscFunctionReturn(0); } @@ -891,7 +891,7 @@ PetscErrorCode TDyGetCellNaturalIDsLocal(TDy tdy, PetscInt *ni, PetscInt nat_ids /* -------------------------------------------------------------------------- */ /// Finds the id of subcell in the mesh->subcells struct that corresponds to /// cell_id and vertex_id and face_id. -/// +/// /// @param [in] tdy A TDy struct /// @param [in] cell_id ID of cell /// @param [in] vertix_id ID of vertex diff --git a/src/tdyio.c b/src/tdyio.c index 388205b6..4b48d222 100644 --- a/src/tdyio.c +++ b/src/tdyio.c @@ -14,13 +14,13 @@ PetscErrorCode TDyIOCreate(TDyIO *_io) { *_io = io; io->io_process = PETSC_FALSE; - io->print_intermediate = PETSC_FALSE; + io->print_intermediate = PETSC_FALSE; io->num_vars = 2; strcpy(io->zonalVarNames[0], "LiquidPressure"); strcpy(io->zonalVarNames[1], "Saturation"); io->format = NullFormat; io->num_times = 0; - + PetscFunctionReturn(0); } @@ -40,7 +40,7 @@ PetscErrorCode TDyIOSetMode(TDy tdy, TDyIOFormat format){ PetscFunctionBegin; PetscErrorCode ierr; int n; - + tdy->io->format = format; int num_vars = tdy->io->num_vars; DM dm = tdy->dm; @@ -61,15 +61,15 @@ PetscErrorCode TDyIOSetMode(TDy tdy, TDyIOFormat format){ strcpy(tdy->io->filename, "out.h5"); char *ofilename = tdy->io->filename; numCorner = TDyGetNumberOfCellVertices(dm); - ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr); - ierr = DMPlexGetHeightStratum(dm,3,&istart,&iend);CHKERRQ(ierr); + ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr); + ierr = DMPlexGetHeightStratum(dm,3,&istart,&iend);CHKERRQ(ierr); numVert = iend-istart; ierr = VecGetSize(tdy->solution, &numCell);CHKERRQ(ierr); - + ierr = TDyIOInitializeHDF5(ofilename,dm);CHKERRQ(ierr); ierr = TDyIOWriteXMFHeader(numCell,dim,numVert,numCorner);CHKERRQ(ierr); } - + PetscFunctionReturn(0); } @@ -88,7 +88,7 @@ PetscErrorCode TDyIOWriteVec(TDy tdy){ for (n=0;nio->zonalVarNames[n]; } - + ierr = DMCreateGlobalVector(dm, &s); ierr = VecGetArray(s,&s_vec_ptr); ierr = DMPlexGetHeightStratum(tdy->dm,0,&cStart,&cEnd); CHKERRQ(ierr); @@ -111,7 +111,7 @@ PetscErrorCode TDyIOWriteVec(TDy tdy){ } else if (tdy->io->format == HDF5Format) { char *ofilename = tdy->io->filename; - + ierr = DMGetUseNatural(dm, &useNatural); CHKERRQ(ierr); if (useNatural) { Vec p_natural; @@ -137,20 +137,20 @@ PetscErrorCode TDyIOWriteVec(TDy tdy){ } PetscErrorCode TDyIOInitializeHDF5(char *ofilename, DM dm){ - PetscViewer viewer; + PetscViewer viewer; PetscErrorCode ierr; PetscViewerFormat format; format = PETSC_VIEWER_HDF5_XDMF; - + ierr = PetscViewerHDF5Open(PETSC_COMM_WORLD,ofilename,FILE_MODE_WRITE,&viewer);CHKERRQ(ierr); ierr = PetscViewerPushFormat(viewer, format);CHKERRQ(ierr); ierr = DMView(dm,viewer);CHKERRQ(ierr); ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); - + PetscFunctionReturn(0); } -PetscErrorCode TDyIOWriteHDF5Var(char *ofilename,DM dm,Vec U,char *VariableName,PetscReal time){ +PetscErrorCode TDyIOWriteHDF5Var(char *ofilename,DM dm,Vec U,char *VariableName,PetscReal time){ PetscViewer viewer; PetscErrorCode ierr; PetscInt numCell; @@ -159,24 +159,24 @@ PetscErrorCode TDyIOWriteHDF5Var(char *ofilename,DM dm,Vec U,char *VariableName, PetscSection sec; ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank); CHKERRQ(ierr); - + sprintf(word,"%11.5e",time); - + ierr = PetscViewerHDF5Open(PETSC_COMM_WORLD,ofilename,FILE_MODE_APPEND,&viewer);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) U,word);CHKERRQ(ierr); ierr = DMGetSection(dm, &sec); - //Change to field name + //Change to field name ierr = PetscSectionSetFieldName(sec, 0, VariableName); CHKERRQ(ierr); ierr = VecView(U,viewer);CHKERRQ(ierr); ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); - + if (rank == 0){ ierr = VecGetSize(U, &numCell);CHKERRQ(ierr); ierr = TDyIOWriteXMFAttribute(VariableName,word,numCell);CHKERRQ(ierr); } - + PetscFunctionReturn(0); } @@ -191,11 +191,11 @@ PetscErrorCode TDyIOInitializeExodus(char *ofilename, char *zonalVarNames[], DM ierr = PetscViewerView(viewer,PETSC_VIEWER_STDOUT_WORLD); ierr = DMView(dm,viewer);CHKERRQ(ierr); ierr = PetscViewerView(viewer,PETSC_VIEWER_STDOUT_WORLD); - + ierr = PetscViewerExodusIIGetId(viewer,&exoid);CHKERRQ(ierr); ierr = ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_vars);CHKERRQ(ierr); ierr = ex_put_variable_names(exoid,EX_ELEM_BLOCK, num_vars, zonalVarNames);CHKERRQ(ierr); - + ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr); #else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP, "PETSc not compiled with Exodus II support."); @@ -210,11 +210,11 @@ PetscErrorCode TDyIOAddExodusTime(char *ofilename, PetscReal time, DM dm, TDyIO float version; PetscErrorCode ierr; int exoid = -1; - + CPU_word_size = sizeof(PetscReal); IO_word_size = sizeof(PetscReal); - - io->num_times = io->num_times + 1; + + io->num_times = io->num_times + 1; exoid = ex_open(ofilename, EX_WRITE, &CPU_word_size, &IO_word_size, &version); if (exoid < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_FILE_UNEXPECTED, "Unable to open exodus file %\n", ofilename); ierr = ex_put_time(exoid,io->num_times,&time);CHKERRQ(ierr); @@ -224,14 +224,14 @@ PetscErrorCode TDyIOAddExodusTime(char *ofilename, PetscReal time, DM dm, TDyIO PetscFunctionReturn(0); } - -PetscErrorCode TDyIOWriteExodusVar(char *ofilename, Vec U, char *VariableName, TDyIO io, PetscReal time){ + +PetscErrorCode TDyIOWriteExodusVar(char *ofilename, Vec U, char *VariableName, TDyIO io, PetscReal time){ #if defined(PETSC_HAVE_EXODUSII) PetscErrorCode ierr; PetscViewer viewer; ierr = PetscViewerExodusIIOpen(PETSC_COMM_WORLD,ofilename,FILE_MODE_APPEND,&viewer);CHKERRQ(ierr); - + ierr = PetscObjectSetName((PetscObject) U, VariableName);CHKERRQ(ierr); ierr = VecView(U, viewer);CHKERRQ(ierr); @@ -259,7 +259,8 @@ PetscErrorCode TDyIOWriteXMFHeader(PetscInt numCell,PetscInt dim,PetscInt numVer FILE *fid; - const char *cellMap[24] = {"0"}; + // This array maps numbers of cells to strings describing topology types. + const char *cellMap[25] = {"0"}; cellMap[1] = "Polyvertex"; cellMap[2] = "Polyline"; cellMap[6] = "Triangle"; @@ -267,12 +268,12 @@ PetscErrorCode TDyIOWriteXMFHeader(PetscInt numCell,PetscInt dim,PetscInt numVer cellMap[12] = "Tetrahedron"; cellMap[18] = "Wedge"; cellMap[24] = "Hexahedron"; - + // xmf_filename = "out.xmf"; fid = fopen("out.xmf","w"); fprintf(fid,""); fprintf(fid,"\n"); + fprintf(fid,"\n"); fprintf(fid,"\n]>"); fprintf(fid, "\n\n\n "); @@ -280,8 +281,8 @@ PetscErrorCode TDyIOWriteXMFHeader(PetscInt numCell,PetscInt dim,PetscInt numVer fprintf(fid,"\n ",numCell,numCorner); + fprintf(fid,"\n NumberType=\"Float\" Precision=\"8\""); + fprintf(fid,"\n Dimensions=\"%i %i\">",numCell,numCorner); fprintf(fid,"\n &HeavyData;:/viz/topology/cells"); fprintf(fid,"\n "); @@ -294,7 +295,7 @@ PetscErrorCode TDyIOWriteXMFHeader(PetscInt numCell,PetscInt dim,PetscInt numVer fprintf(fid,"\n "); //Topology and Geometry - fprintf(fid,"\n "); + fprintf(fid,"\n "); fprintf(fid,"\n ",numCell); @@ -302,7 +303,7 @@ PetscErrorCode TDyIOWriteXMFHeader(PetscInt numCell,PetscInt dim,PetscInt numVer fprintf(fid,"\n /Xdmf/Domain/DataItem[@Name=\"cells\"]"); fprintf(fid,"\n "); fprintf(fid,"\n "); - + if (dim > 2) { fprintf(fid,"\n "); } @@ -320,17 +321,17 @@ PetscErrorCode TDyIOWriteXMFHeader(PetscInt numCell,PetscInt dim,PetscInt numVer } PetscErrorCode TDyIOWriteXMFAttribute(char* name,char* time,PetscInt numCell){ - + FILE *fid; - + // xmf_filename = "out.xmf"; - fid = fopen("out.xmf","a"); - + fid = fopen("out.xmf","a"); + fprintf(fid,"\n "); - + fprintf(fid,"\n "); @@ -340,11 +341,11 @@ PetscErrorCode TDyIOWriteXMFAttribute(char* name,char* time,PetscInt numCell){ fprintf(fid,"\n 0 0 0");//dimension fprintf(fid,"\n 1 1 1"); - fprintf(fid,"\n 1 %i 1",numCell); + fprintf(fid,"\n 1 %i 1",numCell); fprintf(fid,"\n "); fprintf(fid,"\n "); fprintf(fid,"\n &HeavyData;:/cell_fields/%s_%s",time,name); fprintf(fid,"\n "); @@ -358,10 +359,10 @@ PetscErrorCode TDyIOWriteXMFAttribute(char* name,char* time,PetscInt numCell){ PetscErrorCode TDyIOWriteXMFFooter(){ FILE *fid; - + // xmf_filename = "out.xmf"; fid = fopen("out.xmf","a"); - + fprintf(fid,"\n "); fprintf(fid,"\n "); fprintf(fid,"\n\n");