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