1 static const char help[] = "Test of CAD functionality"; 2 3 #include <petscdmplex.h> 4 5 /* TODO 6 - Fix IGES 7 - Test tessellation using -dm_plex_egads_with_tess 8 */ 9 10 typedef struct { 11 char filename[PETSC_MAX_PATH_LEN]; 12 PetscBool volumeMesh; 13 } AppCtx; 14 15 static PetscErrorCode ProcessOptions(MPI_Comm comm, AppCtx *options) 16 { 17 PetscErrorCode ierr; 18 19 PetscFunctionBeginUser; 20 options->filename[0] = '\0'; 21 options->volumeMesh = PETSC_TRUE; 22 23 ierr = PetscOptionsBegin(comm, "", "EGADSPlex Problem Options", "EGADSLite");PetscCall(ierr); 24 PetscCall(PetscOptionsString("-filename", "The CAD file", "ex37.c", options->filename, options->filename, sizeof(options->filename), NULL)); 25 PetscCall(PetscOptionsBool("-volume_mesh", "Create a volume mesh", "ex37.c", options->volumeMesh, &options->volumeMesh, NULL)); 26 ierr = PetscOptionsEnd();PetscCall(ierr); 27 PetscFunctionReturn(0); 28 } 29 30 static PetscErrorCode ComputeVolume(DM dm) 31 { 32 PetscObject obj = (PetscObject) dm; 33 DMLabel bodyLabel, faceLabel, edgeLabel; 34 double surface = 0., volume = 0., vol; 35 PetscInt dim, pStart, pEnd, p, pid; 36 const char *name; 37 38 PetscFunctionBeginUser; 39 PetscCall(DMGetDimension(dm, &dim)); 40 if (dim < 2) PetscFunctionReturn(0); 41 PetscCall(DMGetLabel(dm, "EGADS Body ID", &bodyLabel)); 42 PetscCall(DMGetLabel(dm, "EGADS Face ID", &faceLabel)); 43 PetscCall(DMGetLabel(dm, "EGADS Edge ID", &edgeLabel)); 44 45 PetscCall(DMPlexGetHeightStratum(dm, 0, &pStart, &pEnd)); 46 for (p = pStart; p < pEnd; ++p) { 47 PetscCall(DMLabelGetValue(dim == 2 ? faceLabel : bodyLabel, p, &pid)); 48 if (pid >= 0) { 49 PetscCall(DMPlexComputeCellGeometryFVM(dm, p, &vol, NULL, NULL)); 50 volume += vol; 51 } 52 } 53 PetscCall(DMPlexGetHeightStratum(dm, 1, &pStart, &pEnd)); 54 for (p = pStart; p < pEnd; ++p) { 55 PetscCall(DMLabelGetValue(dim == 2 ? edgeLabel : faceLabel, p, &pid)); 56 if (pid >= 0) { 57 PetscCall(DMPlexComputeCellGeometryFVM(dm, p, &vol, NULL, NULL)); 58 surface += vol; 59 } 60 } 61 62 PetscCall(PetscObjectGetName(obj, &name)); 63 PetscCall(PetscPrintf(PetscObjectComm(obj), "DM %s: Surface Area = %.6e Volume = %.6e\n", name ? name : "", surface, volume)); 64 PetscFunctionReturn(0); 65 } 66 67 int main(int argc, char *argv[]) 68 { 69 DM surface, dm; 70 AppCtx ctx; 71 72 PetscCall(PetscInitialize(&argc, &argv, NULL, help)); 73 PetscCall(ProcessOptions(PETSC_COMM_WORLD, &ctx)); 74 PetscCall(DMPlexCreateFromFile(PETSC_COMM_WORLD, ctx.filename, "ex37_plex", PETSC_TRUE, &surface)); 75 PetscCall(PetscObjectSetName((PetscObject) surface, "CAD Surface")); 76 PetscCall(PetscObjectSetOptionsPrefix((PetscObject) surface, "sur_")); 77 PetscCall(DMSetFromOptions(surface)); 78 PetscCall(DMViewFromOptions(surface, NULL, "-dm_view")); 79 PetscCall(ComputeVolume(surface)); 80 81 if (ctx.volumeMesh) { 82 PetscCall(DMPlexGenerate(surface, "tetgen", PETSC_TRUE, &dm)); 83 PetscCall(PetscObjectSetName((PetscObject) dm, "CAD Mesh")); 84 PetscCall(DMPlexSetRefinementUniform(dm, PETSC_TRUE)); 85 PetscCall(DMViewFromOptions(dm, NULL, "-pre_dm_view")); 86 87 PetscCall(DMPlexInflateToGeomModel(dm)); 88 PetscCall(DMViewFromOptions(dm, NULL, "-inf_dm_view")); 89 90 PetscCall(DMSetFromOptions(dm)); 91 PetscCall(DMViewFromOptions(dm, NULL, "-dm_view")); 92 PetscCall(ComputeVolume(dm)); 93 } 94 95 PetscCall(DMDestroy(&dm)); 96 PetscCall(DMDestroy(&surface)); 97 PetscCall(PetscFinalize()); 98 return 0; 99 } 100 101 /*TEST 102 103 build: 104 requires: egads tetgen 105 106 test: 107 suffix: sphere_0 108 args: -filename ${wPETSC_DIR}/share/petsc/datafiles/meshes/unit_sphere.egadslite -dm_refine 1 -sur_dm_view -dm_plex_check_all -dm_plex_egads_print_model -sur_dm_plex_view_labels "EGADS Body ID","EGADS Face ID","EGADS Edge ID" 109 110 test: 111 suffix: sphere_egads 112 args: -filename ${wPETSC_DIR}/share/petsc/datafiles/meshes/unit_sphere.egads -dm_refine 1 -sur_dm_view -dm_plex_check_all -dm_plex_egads_print_model -sur_dm_plex_view_labels "EGADS Body ID","EGADS Face ID","EGADS Edge ID" 113 114 test: 115 suffix: sphere_iges 116 requires: broken 117 args: -filename ${wPETSC_DIR}/share/petsc/datafiles/meshes/unit_sphere.igs -dm_refine 1 -sur_dm_view -dm_plex_check_all -dm_plex_egads_print_model -sur_dm_plex_view_labels "EGADS Body ID","EGADS Face ID","EGADS Edge ID" 118 119 test: 120 suffix: sphere_step 121 args: -filename ${wPETSC_DIR}/share/petsc/datafiles/meshes/unit_sphere.stp -dm_refine 1 -sur_dm_view -dm_plex_check_all -dm_plex_egads_print_model -sur_dm_plex_view_labels "EGADS Body ID","EGADS Face ID","EGADS Edge ID" 122 123 test: 124 suffix: nozzle_0 125 args: -filename ${wPETSC_DIR}/share/petsc/datafiles/meshes/nozzle.egadslite -sur_dm_refine 1 -sur_dm_view -dm_plex_check_all 126 127 test: 128 suffix: nozzle_egads 129 args: -filename ${wPETSC_DIR}/share/petsc/datafiles/meshes/nozzle.egads -sur_dm_refine 1 -sur_dm_view -dm_plex_check_all 130 131 test: 132 suffix: nozzle_iges 133 args: -filename ${wPETSC_DIR}/share/petsc/datafiles/meshes/nozzle.igs -sur_dm_refine 1 -sur_dm_view -dm_plex_check_all 134 135 test: 136 suffix: nozzle_step 137 args: -filename ${wPETSC_DIR}/share/petsc/datafiles/meshes/nozzle.stp -sur_dm_refine 1 -sur_dm_view -dm_plex_check_all 138 139 TEST*/ 140