Skip to content

Commit

Permalink
Merge pull request #186 from TDycores-Project/jeff-cohere/fix-compile…
Browse files Browse the repository at this point in the history
…r-warnings

Fixes a few compiler warnings (and some whitespace).
  • Loading branch information
jeff-cohere authored Jul 26, 2021
2 parents c4c7228 + cd2bb14 commit 5b0dfec
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 63 deletions.
6 changes: 1 addition & 5 deletions src/mesh/tdycoremesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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 }
Expand Down
30 changes: 15 additions & 15 deletions src/mesh/tdycoremeshutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; d<dim; d++) nu_vec[d] = subcells->nu_vector[sOffsetNu + i].V[d];
PetscFunctionReturn(0);
}
Expand All @@ -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; d<dim; d++) nu_vec[d] = subcells->nu_star_vector[sOffsetNu + i].V[d];
PetscFunctionReturn(0);
}
Expand Down Expand Up @@ -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; iface<vertices->num_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)++;
Expand All @@ -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);
}

Expand Down Expand Up @@ -707,7 +707,7 @@ PetscErrorCode IdentifyLocalVertices(TDy tdy) {

PetscFunctionBegin;


ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd); CHKERRQ(ierr);

for (ivertex=0; ivertex<mesh->num_vertices; ivertex++) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
87 changes: 44 additions & 43 deletions src/tdyio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand All @@ -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);
}

Expand All @@ -88,7 +88,7 @@ PetscErrorCode TDyIOWriteVec(TDy tdy){
for (n=0;n<num_vars;++n){
zonalVarNames[n] = tdy->io->zonalVarNames[n];
}

ierr = DMCreateGlobalVector(dm, &s);
ierr = VecGetArray(s,&s_vec_ptr);
ierr = DMPlexGetHeightStratum(tdy->dm,0,&cStart,&cEnd); CHKERRQ(ierr);
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}

Expand All @@ -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.");
Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -259,29 +259,30 @@ 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";
cellMap[8] = "Quadrilateral";
cellMap[12] = "Tetrahedron";
cellMap[18] = "Wedge";
cellMap[24] = "Hexahedron";

// xmf_filename = "out.xmf";
fid = fopen("out.xmf","w");
fprintf(fid,"<?xml version=\"1.0\" ?>");
fprintf(fid,"\n<!DOCTYPE Xdmf SYSTEM \"Xdmf.dtd\" [");
fprintf(fid,"\n<!ENTITY HeavyData \"out.h5\">");
fprintf(fid,"\n<!ENTITY HeavyData \"out.h5\">");
fprintf(fid,"\n]>");
fprintf(fid, "\n\n<Xdmf>\n <Domain Name=\"domain\">");

//cells
fprintf(fid,"\n <DataItem Name=\"cells\"");
fprintf(fid,"\n ItemType=\"Uniform\"");
fprintf(fid,"\n Format=\"HDF\"");
fprintf(fid,"\n NumberType=\"Float\" Precision=\"8\"");
fprintf(fid,"\n Dimensions=\"%i %i\">",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 </DataItem>");

Expand All @@ -294,15 +295,15 @@ PetscErrorCode TDyIOWriteXMFHeader(PetscInt numCell,PetscInt dim,PetscInt numVer
fprintf(fid,"\n </DataItem>");

//Topology and Geometry
fprintf(fid,"\n <Grid Name=\"domain\" GridType=\"Uniform\">");
fprintf(fid,"\n <Grid Name=\"domain\" GridType=\"Uniform\">");
fprintf(fid,"\n <Topology");
fprintf(fid,"\n TopologyType=\"%s\"",cellMap[dim*numCorner]);
fprintf(fid,"\n NumberOfElements=\"%i\">",numCell);
fprintf(fid,"\n <DataItem Reference=\"XML\">");
fprintf(fid,"\n /Xdmf/Domain/DataItem[@Name=\"cells\"]");
fprintf(fid,"\n </DataItem>");
fprintf(fid,"\n </Topology>");

if (dim > 2) {
fprintf(fid,"\n <Geometry GeometryType=\"XYZ\">");
}
Expand All @@ -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 <Attribute");
fprintf(fid,"\n Name=\"%s_%s\"",time,name);
fprintf(fid,"\n Name=\"%s_%s\"",time,name);
fprintf(fid,"\n Type=\"Scalar\"");
fprintf(fid,"\n Center=\"Cell\">");

fprintf(fid,"\n <DataItem ItemType=\"HyperSlab\"");
fprintf(fid,"\n Dimensions=\"1 %i 1\"",numCell);
fprintf(fid,"\n Type=\"HyperSlab\">");
Expand All @@ -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 </DataItem>");
fprintf(fid,"\n <DataItem");
fprintf(fid,"\n DataType=\"Float\" Precision=\"8\"");
fprintf(fid,"\n Dimensions=\"1 %i 1\"",numCell);
fprintf(fid,"\n Dimensions=\"1 %i 1\"",numCell);
fprintf(fid,"\n Format=\"HDF\">");
fprintf(fid,"\n &HeavyData;:/cell_fields/%s_%s",time,name);
fprintf(fid,"\n </DataItem>");
Expand All @@ -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 </Grid>");
fprintf(fid,"\n </Domain>");
fprintf(fid,"\n</Xdmf>\n");
Expand Down

0 comments on commit 5b0dfec

Please sign in to comment.