xref: /honee/problems/eulervortex.c (revision 727da7e70824329c32c70307643ee0d0901369c8)
1*727da7e7SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2*727da7e7SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3a515125bSLeila Ghaffari //
4*727da7e7SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5a515125bSLeila Ghaffari //
6*727da7e7SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7a515125bSLeila Ghaffari 
8a515125bSLeila Ghaffari /// @file
9a515125bSLeila Ghaffari /// Utility functions for setting up EULER_VORTEX
10a515125bSLeila Ghaffari 
11a515125bSLeila Ghaffari #include "../navierstokes.h"
12a515125bSLeila Ghaffari #include "../qfunctions/setupgeo.h"
13a515125bSLeila Ghaffari #include "../qfunctions/eulervortex.h"
14a515125bSLeila Ghaffari 
1505a512bdSLeila Ghaffari PetscErrorCode NS_EULER_VORTEX(ProblemData *problem, DM dm, void *setup_ctx,
16a515125bSLeila Ghaffari                                void *ctx) {
17a515125bSLeila Ghaffari   EulerTestType     euler_test;
18a515125bSLeila Ghaffari   SetupContext      setup_context = *(SetupContext *)setup_ctx;
19a515125bSLeila Ghaffari   User              user = *(User *)ctx;
20139613f2SLeila Ghaffari   StabilizationType stab;
21a515125bSLeila Ghaffari   MPI_Comm          comm = PETSC_COMM_WORLD;
22a515125bSLeila Ghaffari   PetscBool         implicit;
23a515125bSLeila Ghaffari   PetscBool         has_curr_time = PETSC_TRUE;
24a515125bSLeila Ghaffari   PetscBool         has_neumann = PETSC_TRUE;
25a515125bSLeila Ghaffari   PetscInt          ierr;
26a515125bSLeila Ghaffari   PetscFunctionBeginUser;
27a515125bSLeila Ghaffari 
28a515125bSLeila Ghaffari   ierr = PetscCalloc1(1, &user->phys->euler_ctx); CHKERRQ(ierr);
29a515125bSLeila Ghaffari 
30a515125bSLeila Ghaffari   // ------------------------------------------------------
31a515125bSLeila Ghaffari   //               SET UP DENSITY_CURRENT
32a515125bSLeila Ghaffari   // ------------------------------------------------------
33a515125bSLeila Ghaffari   problem->dim                     = 3;
34a515125bSLeila Ghaffari   problem->q_data_size_vol         = 10;
35a515125bSLeila Ghaffari   problem->q_data_size_sur         = 4;
36a515125bSLeila Ghaffari   problem->setup_vol               = Setup;
37a515125bSLeila Ghaffari   problem->setup_vol_loc           = Setup_loc;
38a515125bSLeila Ghaffari   problem->setup_sur               = SetupBoundary;
39a515125bSLeila Ghaffari   problem->setup_sur_loc           = SetupBoundary_loc;
40a515125bSLeila Ghaffari   problem->ics                     = ICsEuler;
41a515125bSLeila Ghaffari   problem->ics_loc                 = ICsEuler_loc;
42a515125bSLeila Ghaffari   problem->apply_vol_rhs           = Euler;
43a515125bSLeila Ghaffari   problem->apply_vol_rhs_loc       = Euler_loc;
44a515125bSLeila Ghaffari   problem->apply_vol_ifunction     = IFunction_Euler;
45a515125bSLeila Ghaffari   problem->apply_vol_ifunction_loc = IFunction_Euler_loc;
46002797a3SLeila Ghaffari   problem->apply_inflow            = TravelingVortex_Inflow;
47002797a3SLeila Ghaffari   problem->apply_inflow_loc        = TravelingVortex_Inflow_loc;
48002797a3SLeila Ghaffari   problem->apply_outflow           = Euler_Outflow;
49002797a3SLeila Ghaffari   problem->apply_outflow_loc       = Euler_Outflow_loc;
50a515125bSLeila Ghaffari   problem->bc                      = Exact_Euler;
51ba5420e5SLeila Ghaffari   problem->setup_ctx               = SetupContext_EULER_VORTEX;
52a515125bSLeila Ghaffari   problem->non_zero_time           = PETSC_TRUE;
53a515125bSLeila Ghaffari   problem->print_info              = PRINT_EULER_VORTEX;
54a515125bSLeila Ghaffari 
55a515125bSLeila Ghaffari   // ------------------------------------------------------
56a515125bSLeila Ghaffari   //             Create the libCEED context
57a515125bSLeila Ghaffari   // ------------------------------------------------------
58a515125bSLeila Ghaffari   CeedScalar vortex_strength = 5.;          // -
59f821ee77SLeila Ghaffari   CeedScalar c_tau           = 0.5;         // -
60d8a22b9eSJed Brown   // c_tau = 0.5 is reported as "optimal" in Hughes et al 2010
613b451b28SLeila Ghaffari   PetscReal center[3],                      // m
623b451b28SLeila Ghaffari             mean_velocity[3] = {1., 1., 0}; // m/s
6305a512bdSLeila Ghaffari   PetscReal domain_min[3], domain_max[3], domain_size[3];
6405a512bdSLeila Ghaffari   ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr);
6505a512bdSLeila Ghaffari   for (int i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i];
66a515125bSLeila Ghaffari 
67a515125bSLeila Ghaffari   // ------------------------------------------------------
68a515125bSLeila Ghaffari   //             Create the PETSc context
69a515125bSLeila Ghaffari   // ------------------------------------------------------
70a515125bSLeila Ghaffari   PetscScalar meter    = 1e-2; // 1 meter in scaled length units
71a515125bSLeila Ghaffari   PetscScalar second   = 1e-2; // 1 second in scaled time units
72a515125bSLeila Ghaffari 
73a515125bSLeila Ghaffari   // ------------------------------------------------------
74a515125bSLeila Ghaffari   //              Command line Options
75a515125bSLeila Ghaffari   // ------------------------------------------------------
76a515125bSLeila Ghaffari   ierr = PetscOptionsBegin(comm, NULL, "Options for EULER_VORTEX problem",
77a515125bSLeila Ghaffari                            NULL); CHKERRQ(ierr);
78a515125bSLeila Ghaffari   // -- Physics
79a515125bSLeila Ghaffari   ierr = PetscOptionsScalar("-vortex_strength", "Strength of Vortex",
80a515125bSLeila Ghaffari                             NULL, vortex_strength, &vortex_strength, NULL);
81a515125bSLeila Ghaffari   CHKERRQ(ierr);
82a515125bSLeila Ghaffari   PetscInt n = problem->dim;
83a515125bSLeila Ghaffari   PetscBool user_velocity;
84a515125bSLeila Ghaffari   ierr = PetscOptionsRealArray("-mean_velocity", "Background velocity vector",
85a515125bSLeila Ghaffari                                NULL, mean_velocity, &n, &user_velocity);
86a515125bSLeila Ghaffari   CHKERRQ(ierr);
8705a512bdSLeila Ghaffari   for (int i=0; i<3; i++) center[i] = .5*domain_size[i];
88a515125bSLeila Ghaffari   n = problem->dim;
89a515125bSLeila Ghaffari   ierr = PetscOptionsRealArray("-center", "Location of vortex center",
90a515125bSLeila Ghaffari                                NULL, center, &n, NULL); CHKERRQ(ierr);
91a515125bSLeila Ghaffari   ierr = PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation",
92a515125bSLeila Ghaffari                           NULL, implicit=PETSC_FALSE, &implicit, NULL);
93a515125bSLeila Ghaffari   CHKERRQ(ierr);
94a515125bSLeila Ghaffari   ierr = PetscOptionsEnum("-euler_test", "Euler test option", NULL,
95575f8106SLeila Ghaffari                           EulerTestTypes, (PetscEnum)(euler_test = EULER_TEST_ISENTROPIC_VORTEX),
96a515125bSLeila Ghaffari                           (PetscEnum *)&euler_test, NULL); CHKERRQ(ierr);
97139613f2SLeila Ghaffari   ierr = PetscOptionsEnum("-stab", "Stabilization method", NULL,
98139613f2SLeila Ghaffari                           StabilizationTypes, (PetscEnum)(stab = STAB_NONE),
99139613f2SLeila Ghaffari                           (PetscEnum *)&stab, NULL); CHKERRQ(ierr);
100d8a22b9eSJed Brown   ierr = PetscOptionsScalar("-c_tau", "Stabilization constant",
101d8a22b9eSJed Brown                             NULL, c_tau, &c_tau, NULL); CHKERRQ(ierr);
102a515125bSLeila Ghaffari   // -- Units
103a515125bSLeila Ghaffari   ierr = PetscOptionsScalar("-units_meter", "1 meter in scaled length units",
104a515125bSLeila Ghaffari                             NULL, meter, &meter, NULL); CHKERRQ(ierr);
105a515125bSLeila Ghaffari   meter = fabs(meter);
106a515125bSLeila Ghaffari   ierr = PetscOptionsScalar("-units_second","1 second in scaled time units",
107a515125bSLeila Ghaffari                             NULL, second, &second, NULL); CHKERRQ(ierr);
108a515125bSLeila Ghaffari   second = fabs(second);
109a515125bSLeila Ghaffari 
110a515125bSLeila Ghaffari   // -- Warnings
111139613f2SLeila Ghaffari   if (stab == STAB_SUPG && !implicit) {
112139613f2SLeila Ghaffari     ierr = PetscPrintf(comm,
113139613f2SLeila Ghaffari                        "Warning! Use -stab supg only with -implicit\n");
114139613f2SLeila Ghaffari     CHKERRQ(ierr);
115139613f2SLeila Ghaffari   }
116a515125bSLeila Ghaffari   if (user_velocity && (euler_test == EULER_TEST_1
117a515125bSLeila Ghaffari                         || euler_test == EULER_TEST_3)) {
118a515125bSLeila Ghaffari     ierr = PetscPrintf(comm,
119a515125bSLeila Ghaffari                        "Warning! Background velocity vector for -euler_test t1 and -euler_test t3 is (0,0,0)\n");
120a515125bSLeila Ghaffari     CHKERRQ(ierr);
121a515125bSLeila Ghaffari   }
122a515125bSLeila Ghaffari 
123a515125bSLeila Ghaffari   ierr = PetscOptionsEnd(); CHKERRQ(ierr);
124a515125bSLeila Ghaffari 
125a515125bSLeila Ghaffari   // ------------------------------------------------------
126a515125bSLeila Ghaffari   //           Set up the PETSc context
127a515125bSLeila Ghaffari   // ------------------------------------------------------
128a515125bSLeila Ghaffari   user->units->meter  = meter;
129a515125bSLeila Ghaffari   user->units->second = second;
130a515125bSLeila Ghaffari 
131a515125bSLeila Ghaffari   // ------------------------------------------------------
132a515125bSLeila Ghaffari   //           Set up the libCEED context
133a515125bSLeila Ghaffari   // ------------------------------------------------------
134a515125bSLeila Ghaffari   // -- Scale variables to desired units
1353b451b28SLeila Ghaffari   for (int i=0; i<3; i++) {
1363b451b28SLeila Ghaffari     center[i] *= meter;
13705a512bdSLeila Ghaffari     domain_size[i] *= meter;
13805a512bdSLeila Ghaffari     mean_velocity[i] *= (meter/second);
1393b451b28SLeila Ghaffari   }
14005a512bdSLeila Ghaffari   problem->dm_scale = meter;
141a515125bSLeila Ghaffari 
142a515125bSLeila Ghaffari   // -- Setup Context
14305a512bdSLeila Ghaffari   setup_context->lx        = domain_size[0];
14405a512bdSLeila Ghaffari   setup_context->ly        = domain_size[1];
14505a512bdSLeila Ghaffari   setup_context->lz        = domain_size[2];
146a515125bSLeila Ghaffari   setup_context->center[0] = center[0];
147a515125bSLeila Ghaffari   setup_context->center[1] = center[1];
148a515125bSLeila Ghaffari   setup_context->center[2] = center[2];
149a515125bSLeila Ghaffari   setup_context->time      = 0;
150a515125bSLeila Ghaffari 
151a515125bSLeila Ghaffari   // -- QFunction Context
152139613f2SLeila Ghaffari   user->phys->stab                        = stab;
153a515125bSLeila Ghaffari   user->phys->euler_test                  = euler_test;
154a515125bSLeila Ghaffari   user->phys->implicit                    = implicit;
155a515125bSLeila Ghaffari   user->phys->has_curr_time               = has_curr_time;
156a515125bSLeila Ghaffari   user->phys->has_neumann                 = has_neumann;
157a515125bSLeila Ghaffari   user->phys->euler_ctx->curr_time        = 0.;
158a515125bSLeila Ghaffari   user->phys->euler_ctx->implicit         = implicit;
159a515125bSLeila Ghaffari   user->phys->euler_ctx->euler_test       = euler_test;
160a515125bSLeila Ghaffari   user->phys->euler_ctx->center[0]        = center[0];
161a515125bSLeila Ghaffari   user->phys->euler_ctx->center[1]        = center[1];
162a515125bSLeila Ghaffari   user->phys->euler_ctx->center[2]        = center[2];
163a515125bSLeila Ghaffari   user->phys->euler_ctx->vortex_strength  = vortex_strength;
164d8a22b9eSJed Brown   user->phys->euler_ctx->c_tau            = c_tau;
165a515125bSLeila Ghaffari   user->phys->euler_ctx->mean_velocity[0] = mean_velocity[0];
166a515125bSLeila Ghaffari   user->phys->euler_ctx->mean_velocity[1] = mean_velocity[1];
167a515125bSLeila Ghaffari   user->phys->euler_ctx->mean_velocity[2] = mean_velocity[2];
168139613f2SLeila Ghaffari   user->phys->euler_ctx->stabilization    = stab;
169a515125bSLeila Ghaffari 
170a515125bSLeila Ghaffari   PetscFunctionReturn(0);
171a515125bSLeila Ghaffari }
172a515125bSLeila Ghaffari 
173ba5420e5SLeila Ghaffari PetscErrorCode SetupContext_EULER_VORTEX(Ceed ceed, CeedData ceed_data,
174ba5420e5SLeila Ghaffari     AppCtx app_ctx, SetupContext setup_ctx, Physics phys) {
175ba5420e5SLeila Ghaffari   PetscFunctionBeginUser;
176ba5420e5SLeila Ghaffari   CeedQFunctionContextCreate(ceed, &ceed_data->setup_context);
177ba5420e5SLeila Ghaffari   CeedQFunctionContextSetData(ceed_data->setup_context, CEED_MEM_HOST,
178ba5420e5SLeila Ghaffari                               CEED_USE_POINTER,
179ba5420e5SLeila Ghaffari                               sizeof(*setup_ctx), setup_ctx);
180ba5420e5SLeila Ghaffari   CeedQFunctionContextCreate(ceed, &ceed_data->euler_context);
181ba5420e5SLeila Ghaffari   CeedQFunctionContextSetData(ceed_data->euler_context, CEED_MEM_HOST,
182ba5420e5SLeila Ghaffari                               CEED_USE_POINTER,
183ba5420e5SLeila Ghaffari                               sizeof(*phys->euler_ctx), phys->euler_ctx);
184ba5420e5SLeila Ghaffari   if (ceed_data->qf_ics)
185ba5420e5SLeila Ghaffari     CeedQFunctionSetContext(ceed_data->qf_ics, ceed_data->euler_context);
186139613f2SLeila Ghaffari   if (ceed_data->qf_rhs_vol)
187139613f2SLeila Ghaffari     CeedQFunctionSetContext(ceed_data->qf_rhs_vol, ceed_data->euler_context);
188139613f2SLeila Ghaffari   if (ceed_data->qf_ifunction_vol)
189139613f2SLeila Ghaffari     CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, ceed_data->euler_context);
190002797a3SLeila Ghaffari   if (ceed_data->qf_apply_inflow)
191002797a3SLeila Ghaffari     CeedQFunctionSetContext(ceed_data->qf_apply_inflow, ceed_data->euler_context);
192002797a3SLeila Ghaffari   if (ceed_data->qf_apply_outflow)
193002797a3SLeila Ghaffari     CeedQFunctionSetContext(ceed_data->qf_apply_outflow, ceed_data->euler_context);
194a515125bSLeila Ghaffari   PetscFunctionReturn(0);
195a515125bSLeila Ghaffari }
196a515125bSLeila Ghaffari 
197a515125bSLeila Ghaffari PetscErrorCode PRINT_EULER_VORTEX(Physics phys, SetupContext setup_ctx,
198a515125bSLeila Ghaffari                                   AppCtx app_ctx) {
199a515125bSLeila Ghaffari   MPI_Comm       comm = PETSC_COMM_WORLD;
200a515125bSLeila Ghaffari   PetscErrorCode ierr;
201a515125bSLeila Ghaffari   PetscFunctionBeginUser;
202a515125bSLeila Ghaffari 
203a515125bSLeila Ghaffari   ierr = PetscPrintf(comm,
204a515125bSLeila Ghaffari                      "  Problem:\n"
205a515125bSLeila Ghaffari                      "    Problem Name                       : %s\n"
206a515125bSLeila Ghaffari                      "    Test Case                          : %s\n"
207139613f2SLeila Ghaffari                      "    Background Velocity                : %f,%f,%f\n"
208139613f2SLeila Ghaffari                      "    Stabilization                      : %s\n",
209a515125bSLeila Ghaffari                      app_ctx->problem_name, EulerTestTypes[phys->euler_test],
210a515125bSLeila Ghaffari                      phys->euler_ctx->mean_velocity[0],
211139613f2SLeila Ghaffari                      phys->euler_ctx->mean_velocity[1],
212139613f2SLeila Ghaffari                      phys->euler_ctx->mean_velocity[2],
213139613f2SLeila Ghaffari                      StabilizationTypes[phys->stab]); CHKERRQ(ierr);
214a515125bSLeila Ghaffari 
215a515125bSLeila Ghaffari   PetscFunctionReturn(0);
216a515125bSLeila Ghaffari }
217