xref: /libCEED/examples/fluids/src/velocity_gradient_projection.c (revision 999ff5c7ca91b692a440ecf149a8ab458a4dc7a6)
1*999ff5c7SJames Wright // Copyright (c) 2017-2023, Lawrence Livermore National Security, LLC and other CEED contributors.
2*999ff5c7SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3*999ff5c7SJames Wright //
4*999ff5c7SJames Wright // SPDX-License-Identifier: BSD-2-Clause
5*999ff5c7SJames Wright //
6*999ff5c7SJames Wright // This file is part of CEED:  http://github.com/ceed
7*999ff5c7SJames Wright /// @file
8*999ff5c7SJames Wright /// Functions for setting up and projecting the velocity gradient
9*999ff5c7SJames Wright 
10*999ff5c7SJames Wright #include "../qfunctions/velocity_gradient_projection.h"
11*999ff5c7SJames Wright 
12*999ff5c7SJames Wright #include <petscdmplex.h>
13*999ff5c7SJames Wright 
14*999ff5c7SJames Wright #include "../navierstokes.h"
15*999ff5c7SJames Wright 
16*999ff5c7SJames Wright PetscErrorCode VelocityGradientProjectionCreateDM(NodalProjectionData grad_velo_proj, User user, PetscInt degree) {
17*999ff5c7SJames Wright   PetscFE      fe;
18*999ff5c7SJames Wright   PetscSection section;
19*999ff5c7SJames Wright   PetscInt     dim;
20*999ff5c7SJames Wright 
21*999ff5c7SJames Wright   PetscFunctionBeginUser;
22*999ff5c7SJames Wright   grad_velo_proj->num_comp = 9;  // 9 velocity gradient
23*999ff5c7SJames Wright 
24*999ff5c7SJames Wright   PetscCall(DMClone(user->dm, &grad_velo_proj->dm));
25*999ff5c7SJames Wright   PetscCall(DMGetDimension(grad_velo_proj->dm, &dim));
26*999ff5c7SJames Wright   PetscCall(PetscObjectSetName((PetscObject)grad_velo_proj->dm, "Velocity Gradient Projection"));
27*999ff5c7SJames Wright 
28*999ff5c7SJames Wright   PetscCall(PetscFECreateLagrange(PETSC_COMM_SELF, dim, grad_velo_proj->num_comp, PETSC_FALSE, degree, PETSC_DECIDE, &fe));
29*999ff5c7SJames Wright   PetscCall(PetscObjectSetName((PetscObject)fe, "Velocity Gradient Projection"));
30*999ff5c7SJames Wright   PetscCall(DMAddField(grad_velo_proj->dm, NULL, (PetscObject)fe));
31*999ff5c7SJames Wright   PetscCall(DMCreateDS(grad_velo_proj->dm));
32*999ff5c7SJames Wright   PetscCall(DMPlexSetClosurePermutationTensor(grad_velo_proj->dm, PETSC_DETERMINE, NULL));
33*999ff5c7SJames Wright 
34*999ff5c7SJames Wright   PetscCall(DMGetLocalSection(grad_velo_proj->dm, &section));
35*999ff5c7SJames Wright   PetscCall(PetscSectionSetFieldName(section, 0, ""));
36*999ff5c7SJames Wright   PetscCall(PetscSectionSetComponentName(section, 0, 0, "VelocityGradientXX"));
37*999ff5c7SJames Wright   PetscCall(PetscSectionSetComponentName(section, 0, 1, "VelocityGradientXY"));
38*999ff5c7SJames Wright   PetscCall(PetscSectionSetComponentName(section, 0, 2, "VelocityGradientXZ"));
39*999ff5c7SJames Wright   PetscCall(PetscSectionSetComponentName(section, 0, 3, "VelocityGradientYX"));
40*999ff5c7SJames Wright   PetscCall(PetscSectionSetComponentName(section, 0, 4, "VelocityGradientYY"));
41*999ff5c7SJames Wright   PetscCall(PetscSectionSetComponentName(section, 0, 5, "VelocityGradientYZ"));
42*999ff5c7SJames Wright   PetscCall(PetscSectionSetComponentName(section, 0, 6, "VelocityGradientZX"));
43*999ff5c7SJames Wright   PetscCall(PetscSectionSetComponentName(section, 0, 7, "VelocityGradientZY"));
44*999ff5c7SJames Wright   PetscCall(PetscSectionSetComponentName(section, 0, 8, "VelocityGradientZZ"));
45*999ff5c7SJames Wright 
46*999ff5c7SJames Wright   PetscCall(PetscFEDestroy(&fe));
47*999ff5c7SJames Wright   PetscFunctionReturn(0);
48*999ff5c7SJames Wright };
49