From 7eede71b3a63307f3833378555141424da39f6aa Mon Sep 17 00:00:00 2001 From: "U-INTERNAL\\LROSLG" Date: Thu, 12 Sep 2013 10:25:07 +0200 Subject: [PATCH] Updated the CGNS read tp DMPlex function. Corrected loop counters and hexahedra cones. Also added counter to the coordinate reading for proper multi dimensional reads. --- src/dm/impls/plex/plexcgns.c | 35 ++++++++++++----------------------- 1 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/dm/impls/plex/plexcgns.c b/src/dm/impls/plex/plexcgns.c index d2a2505..04c3bf6 100644 --- a/src/dm/impls/plex/plexcgns.c +++ b/src/dm/impls/plex/plexcgns.c @@ -101,7 +101,7 @@ PetscErrorCode DMPlexCreateCGNS(MPI_Comm comm, PetscInt cgid, PetscBool interpol ierr = cg_ElementDataSize(cgid, 1, z, 1, &elementDataSize);CHKERRQ(ierr); ierr = PetscMalloc(elementDataSize * sizeof(cgsize_t), &elements);CHKERRQ(ierr); ierr = cg_elements_read(cgid, 1, z, 1, elements, NULL);CHKERRQ(ierr); - for (c_loc = start, off = 0; c_loc < end; ++c_loc, ++c) { + for (c_loc = start, off = 0; c_loc <= end; ++c_loc, ++c) { switch (elements[off]) { case TRI_3: numCorners = 3;break; case QUAD_4: numCorners = 4;break; @@ -121,7 +121,7 @@ PetscErrorCode DMPlexCreateCGNS(MPI_Comm comm, PetscInt cgid, PetscBool interpol case HEXA_8: numCorners = 8;break; default: SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Invalid cell type %d", (int) cellType); } - for (c_loc = start; c_loc < end; ++c_loc, ++c) { + for (c_loc = start; c_loc <= end; ++c_loc, ++c) { ierr = DMPlexSetConeSize(*dm, c, numCorners);CHKERRQ(ierr); } } @@ -129,7 +129,7 @@ PetscErrorCode DMPlexCreateCGNS(MPI_Comm comm, PetscInt cgid, PetscBool interpol ierr = DMSetUp(*dm);CHKERRQ(ierr); for (z = 1, c = 0; z <= nzones; ++z) { ElementType_t cellType; - cgsize_t *elements, elementDataSize, start, end; + cgsize_t *elements, elementDataSize, start, end, subCellType; int nbndry, parentFlag; PetscInt *cone, numc, numCorners, maxCorners = 27; @@ -141,8 +141,9 @@ PetscErrorCode DMPlexCreateCGNS(MPI_Comm comm, PetscInt cgid, PetscBool interpol ierr = cg_elements_read(cgid, 1, z, 1, elements, NULL);CHKERRQ(ierr); if (cellType == MIXED) { /* CGNS uses Fortran-based indexing, sieve uses C-style and numbers cell first then vertices. */ - for (c_loc = 0, v = 0; c_loc < numc; ++c_loc, ++c) { - switch (elements[v]) { + for (c_loc = 0, v = 0; c_loc <= numc; ++c_loc, ++c) { + subCellType = elements[v]; + switch (subCellType) { case TRI_3: numCorners = 3;break; case QUAD_4: numCorners = 4;break; case TETRA_4: numCorners = 4;break; @@ -153,18 +154,12 @@ PetscErrorCode DMPlexCreateCGNS(MPI_Comm comm, PetscInt cgid, PetscBool interpol for (v_loc = 0; v_loc < numCorners; ++v_loc, ++v) { cone[v_loc] = elements[v]+numCells-1; } - /* Tetrahedra are inverted */ - if (cellType == TETRA_4) { + /* Tetrahedra and hexahedra are inverted */ + if (subCellType == TETRA_4 || subCellType == HEXA_8) { PetscInt tmp = cone[0]; cone[0] = cone[1]; cone[1] = tmp; } - /* Hexahedra are inverted */ - if (cellType == HEXA_8) { - PetscInt tmp = cone[1]; - cone[1] = cone[3]; - cone[3] = tmp; - } ierr = DMPlexSetCone(*dm, c, cone);CHKERRQ(ierr); ierr = DMPlexSetLabelValue(*dm, "zone", c, z);CHKERRQ(ierr); } @@ -178,22 +173,16 @@ PetscErrorCode DMPlexCreateCGNS(MPI_Comm comm, PetscInt cgid, PetscBool interpol } /* CGNS uses Fortran-based indexing, sieve uses C-style and numbers cell first then vertices. */ - for (c_loc = 0, v = 0; c_loc < numc; ++c_loc, ++c) { + for (c_loc = 0, v = 0; c_loc <= numc; ++c_loc, ++c) { for (v_loc = 0; v_loc < numCorners; ++v_loc, ++v) { cone[v_loc] = elements[v]+numCells-1; } - /* Tetrahedra are inverted */ - if (cellType == TETRA_4) { + /* Tetrahedra and hexahedra are inverted */ + if (cellType == TETRA_4 || cellType == HEXA_8) { PetscInt tmp = cone[0]; cone[0] = cone[1]; cone[1] = tmp; } - /* Hexahedra are inverted */ - if (cellType == HEXA_8) { - PetscInt tmp = cone[1]; - cone[1] = cone[3]; - cone[3] = tmp; - } ierr = DMPlexSetCone(*dm, c, cone);CHKERRQ(ierr); ierr = DMPlexSetLabelValue(*dm, "zone", c, z);CHKERRQ(ierr); } @@ -255,7 +244,7 @@ PetscErrorCode DMPlexCreateCGNS(MPI_Comm comm, PetscInt cgid, PetscBool interpol ierr = cg_ncoords(cgid, 1, z, &ncoords);CHKERRQ(ierr); if (ncoords != dim) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CGNS file must have a coordinate array for each dimension, not %d\n",ncoords); for (d = 0; d < dim; ++d) { - ierr = cg_coord_info(cgid, 1, z, 1, &datatype, buffer);CHKERRQ(ierr); + ierr = cg_coord_info(cgid, 1, z, 1+d, &datatype, buffer);CHKERRQ(ierr); ierr = cg_coord_read(cgid, 1, z, buffer, RealSingle, range_min, range_max, x[d]);CHKERRQ(ierr); } if (dim > 0) { -- 1.7.9