xref: /libCEED/examples/fluids/src/turb_spanstats.c (revision 51ee423effa42c276127ddad5a633b95f9664987)
1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3 //
4 // SPDX-License-Identifier: BSD-2-Clause
5 //
6 // This file is part of CEED:  http://github.com/ceed
7 
8 /// @file
9 /// Utility functions for setting up statistics collection
10 
11 #include "../navierstokes.h"
12 
13 PetscErrorCode CreateStatsDM(User user, ProblemData *problem, PetscInt degree, SimpleBC bc) {
14   user->spanstats.num_comp_stats = 1;
15   PetscFunctionBeginUser;
16 
17   // Get DM from surface
18   {
19     DMLabel label;
20     PetscCall(DMGetLabel(user->dm, "Face Sets", &label));
21     PetscCall(DMPlexLabelComplete(user->dm, label));
22     PetscCall(DMPlexFilter(user->dm, label, 1, &user->spanstats.dm));
23     PetscCall(DMProjectCoordinates(user->spanstats.dm, NULL));  // Ensure that a coordinate FE exists
24   }
25 
26   PetscCall(PetscObjectSetName((PetscObject)user->spanstats.dm, "Spanwise_Stats"));
27   PetscCall(DMSetOptionsPrefix(user->spanstats.dm, "spanstats_"));
28   PetscCall(PetscOptionsSetValue(NULL, "-spanstats_dm_sparse_localize", "0"));  // [Jed] Not relevant because not periodic in this direction
29 
30   PetscCall(DMSetFromOptions(user->spanstats.dm));
31   PetscCall(DMViewFromOptions(user->spanstats.dm, NULL, "-dm_view"));  // -spanstats_dm_view (option includes prefix)
32   {
33     PetscFE fe;
34     DMLabel label;
35 
36     PetscCall(PetscFECreateLagrange(PETSC_COMM_SELF, problem->dim - 1, user->spanstats.num_comp_stats, PETSC_FALSE, degree, PETSC_DECIDE, &fe));
37     PetscCall(PetscObjectSetName((PetscObject)fe, "stats"));
38     PetscCall(DMAddField(user->spanstats.dm, NULL, (PetscObject)fe));
39     PetscCall(DMCreateDS(user->spanstats.dm));
40     PetscCall(DMGetLabel(user->spanstats.dm, "Face Sets", &label));
41 
42     // // Set wall BCs
43     // if (bc->num_wall > 0) {
44     //   PetscCall(DMAddBoundary(dm, DM_BC_ESSENTIAL, "wall", label, bc->num_wall, bc->walls, 0, bc->num_comps, bc->wall_comps,
45     //                           (void (*)(void))problem->bc, NULL, problem->bc_ctx, NULL));
46     // }
47     // // Set slip BCs in the x direction
48     // if (bc->num_slip[0] > 0) {
49     //   PetscInt comps[1] = {1};
50     //   PetscCall(DMAddBoundary(dm, DM_BC_ESSENTIAL, "slipx", label, bc->num_slip[0], bc->slips[0], 0, 1, comps, (void (*)(void))NULL, NULL,
51     //                           problem->bc_ctx, NULL));
52     // }
53     // // Set slip BCs in the y direction
54     // if (bc->num_slip[1] > 0) {
55     //   PetscInt comps[1] = {2};
56     //   PetscCall(DMAddBoundary(dm, DM_BC_ESSENTIAL, "slipy", label, bc->num_slip[1], bc->slips[1], 0, 1, comps, (void (*)(void))NULL, NULL,
57     //                           problem->bc_ctx, NULL));
58     // }
59     // // Set slip BCs in the z direction
60     // if (bc->num_slip[2] > 0) {
61     //   PetscInt comps[1] = {3};
62     //   PetscCall(DMAddBoundary(dm, DM_BC_ESSENTIAL, "slipz", label, bc->num_slip[2], bc->slips[2], 0, 1, comps, (void (*)(void))NULL, NULL,
63     //                           problem->bc_ctx, NULL));
64     // }
65 
66     PetscCall(DMPlexSetClosurePermutationTensor(user->spanstats.dm, PETSC_DETERMINE, NULL));
67     PetscCall(PetscFEDestroy(&fe));
68   }
69 
70   PetscSection section;
71   PetscCall(DMGetLocalSection(user->spanstats.dm, &section));
72   PetscCall(PetscSectionSetFieldName(section, 0, ""));
73   PetscCall(PetscSectionSetComponentName(section, 0, 0, "Test"));
74   // PetscCall(PetscSectionSetComponentName(section, 0, 0, "Mean Velocity Products XX"));
75   // PetscCall(PetscSectionSetComponentName(section, 0, 1, "Mean Velocity Products YY"));
76   // PetscCall(PetscSectionSetComponentName(section, 0, 2, "Mean Velocity Products ZZ"));
77   // PetscCall(PetscSectionSetComponentName(section, 0, 3, "Mean Velocity Products YZ"));
78   // PetscCall(PetscSectionSetComponentName(section, 0, 4, "Mean Velocity Products XZ"));
79   // PetscCall(PetscSectionSetComponentName(section, 0, 5, "Mean Velocity Products XY"));
80 
81   // Vec test;
82   // PetscCall(DMCreateLocalVector(user->spanstats.dm, &test));
83   // PetscCall(VecZeroEntries(test));
84   // PetscCall(VecViewFromOptions(test, NULL, "-test_view"));
85 
86   PetscFunctionReturn(0);
87 }
88