Actual source code: ex73.c
1: static char help[] = "Tests DMAdaptor pure refinement with no PetscDS fields.\n\n";
3: #include <petscsnes.h>
4: #include <petscdmadaptor.h>
5: #include <petscdmplex.h>
7: static PetscErrorCode TransferNoOp(DMAdaptor adaptor, DM dm, Vec x, DM adm, Vec ax, PetscCtx ctx)
8: {
9: PetscFunctionBegin;
10: PetscFunctionReturn(PETSC_SUCCESS);
11: }
13: int main(int argc, char **argv)
14: {
15: DM dm, adm = NULL;
16: SNES snes;
17: Vec x, ax = NULL;
18: DMAdaptor adaptor;
19: PetscSection section;
20: PetscInt pStart, pEnd, sequence = 3;
22: PetscFunctionBeginUser;
23: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
24: PetscCall(PetscOptionsGetInt(NULL, NULL, "-adapt_sequence", &sequence, NULL));
26: PetscCall(DMCreate(PETSC_COMM_WORLD, &dm));
27: PetscCall(DMSetType(dm, DMPLEX));
28: PetscCall(DMSetFromOptions(dm));
29: PetscCall(DMPlexGetChart(dm, &pStart, &pEnd));
30: PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)dm), §ion));
31: PetscCall(PetscSectionSetChart(section, pStart, pEnd));
32: PetscCall(PetscSectionSetUp(section));
33: PetscCall(DMSetLocalSection(dm, section));
34: PetscCall(PetscSectionDestroy(§ion));
35: PetscCall(DMCreateGlobalVector(dm, &x));
37: PetscCall(SNESCreate(PETSC_COMM_WORLD, &snes));
38: PetscCall(SNESSetDM(snes, dm));
39: PetscCall(DMAdaptorCreate(PETSC_COMM_WORLD, &adaptor));
40: PetscCall(DMAdaptorSetSolver(adaptor, snes));
41: PetscCall(DMAdaptorSetCriterion(adaptor, DM_ADAPTATION_REFINE));
42: PetscCall(DMAdaptorSetTransferFunction(adaptor, TransferNoOp));
43: PetscCall(DMAdaptorSetSequenceLength(adaptor, sequence));
44: PetscCall(DMAdaptorSetUp(adaptor));
45: /* DMAdaptorAdapt() consumes one reference to the solution and to the DM of the solver */
46: PetscCall(PetscObjectReference((PetscObject)dm));
47: PetscCall(PetscObjectReference((PetscObject)x));
48: PetscCall(DMAdaptorAdapt(adaptor, x, DM_ADAPTATION_INITIAL, &adm, &ax));
50: PetscCheck(adm, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "DMAdaptorAdapt() returned a NULL adapted DM");
51: PetscCheck(ax, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "DMAdaptorAdapt() returned a NULL adapted vector");
53: PetscCall(DMAdaptorDestroy(&adaptor));
54: PetscCall(SNESDestroy(&snes));
55: PetscCall(VecDestroy(&ax));
56: PetscCall(DMDestroy(&adm));
57: PetscCall(VecDestroy(&x));
58: PetscCall(DMDestroy(&dm));
59: PetscCall(PetscFinalize());
60: return 0;
61: }
63: /*TEST
65: test:
66: suffix: adaptor_refine
67: output_file: output/empty.out
68: args: -dm_plex_simplex 0 -dm_plex_box_faces 1,1 -dm_plex_box_lower 0,0 -dm_plex_box_upper 1,1 -adapt_sequence 3
70: TEST*/