xref: /libCEED/examples/fluids/problems/eulervortex.c (revision 2fe7aee7a837446ac12fe008ea12313e81769bbb)
177841947SLeila Ghaffari // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
277841947SLeila Ghaffari // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
377841947SLeila Ghaffari // reserved. See files LICENSE and NOTICE for details.
477841947SLeila Ghaffari //
577841947SLeila Ghaffari // This file is part of CEED, a collection of benchmarks, miniapps, software
677841947SLeila Ghaffari // libraries and APIs for efficient high-order finite element and spectral
777841947SLeila Ghaffari // element discretizations for exascale applications. For more information and
877841947SLeila Ghaffari // source code availability see http://github.com/ceed.
977841947SLeila Ghaffari //
1077841947SLeila Ghaffari // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
1177841947SLeila Ghaffari // a collaborative effort of two U.S. Department of Energy organizations (Office
1277841947SLeila Ghaffari // of Science and the National Nuclear Security Administration) responsible for
1377841947SLeila Ghaffari // the planning and preparation of a capable exascale ecosystem, including
1477841947SLeila Ghaffari // software, applications, hardware, advanced system engineering and early
1577841947SLeila Ghaffari // testbed platforms, in support of the nation's exascale computing imperative.
1677841947SLeila Ghaffari 
1777841947SLeila Ghaffari /// @file
1877841947SLeila Ghaffari /// Utility functions for setting up EULER_VORTEX
1977841947SLeila Ghaffari 
2077841947SLeila Ghaffari #include "../navierstokes.h"
2177841947SLeila Ghaffari #include "../qfunctions/setupgeo.h"
2277841947SLeila Ghaffari #include "../qfunctions/eulervortex.h"
23*2fe7aee7SLeila Ghaffari #include "../qfunctions/euler-outflow.h"
2477841947SLeila Ghaffari 
251864f1c2SLeila Ghaffari PetscErrorCode NS_EULER_VORTEX(ProblemData *problem, DM dm, void *setup_ctx,
2677841947SLeila Ghaffari                                void *ctx) {
2777841947SLeila Ghaffari   EulerTestType     euler_test;
2877841947SLeila Ghaffari   SetupContext      setup_context = *(SetupContext *)setup_ctx;
2977841947SLeila Ghaffari   User              user = *(User *)ctx;
30e6225c47SLeila Ghaffari   StabilizationType stab;
3177841947SLeila Ghaffari   MPI_Comm          comm = PETSC_COMM_WORLD;
3277841947SLeila Ghaffari   PetscBool         implicit;
3377841947SLeila Ghaffari   PetscBool         has_curr_time = PETSC_TRUE;
3477841947SLeila Ghaffari   PetscBool         has_neumann = PETSC_TRUE;
3577841947SLeila Ghaffari   PetscInt          ierr;
3677841947SLeila Ghaffari   PetscFunctionBeginUser;
3777841947SLeila Ghaffari 
3877841947SLeila Ghaffari   ierr = PetscCalloc1(1, &user->phys->euler_ctx); CHKERRQ(ierr);
3977841947SLeila Ghaffari 
4077841947SLeila Ghaffari   // ------------------------------------------------------
4177841947SLeila Ghaffari   //               SET UP DENSITY_CURRENT
4277841947SLeila Ghaffari   // ------------------------------------------------------
4377841947SLeila Ghaffari   problem->dim                     = 3;
4477841947SLeila Ghaffari   problem->q_data_size_vol         = 10;
4577841947SLeila Ghaffari   problem->q_data_size_sur         = 4;
4677841947SLeila Ghaffari   problem->setup_vol               = Setup;
4777841947SLeila Ghaffari   problem->setup_vol_loc           = Setup_loc;
4877841947SLeila Ghaffari   problem->setup_sur               = SetupBoundary;
4977841947SLeila Ghaffari   problem->setup_sur_loc           = SetupBoundary_loc;
5077841947SLeila Ghaffari   problem->ics                     = ICsEuler;
5177841947SLeila Ghaffari   problem->ics_loc                 = ICsEuler_loc;
5277841947SLeila Ghaffari   problem->apply_vol_rhs           = Euler;
5377841947SLeila Ghaffari   problem->apply_vol_rhs_loc       = Euler_loc;
5477841947SLeila Ghaffari   problem->apply_vol_ifunction     = IFunction_Euler;
5577841947SLeila Ghaffari   problem->apply_vol_ifunction_loc = IFunction_Euler_loc;
56*2fe7aee7SLeila Ghaffari   problem->apply_inflow            = TravelingVortex_Inflow;
57*2fe7aee7SLeila Ghaffari   problem->apply_inflow_loc        = TravelingVortex_Inflow_loc;
58*2fe7aee7SLeila Ghaffari   problem->apply_outflow           = Euler_Outflow;
59*2fe7aee7SLeila Ghaffari   problem->apply_outflow_loc       = Euler_Outflow_loc;
6077841947SLeila Ghaffari   problem->bc                      = Exact_Euler;
61d0b732dbSLeila Ghaffari   problem->setup_ctx               = SetupContext_EULER_VORTEX;
6277841947SLeila Ghaffari   problem->non_zero_time           = PETSC_TRUE;
6377841947SLeila Ghaffari   problem->print_info              = PRINT_EULER_VORTEX;
6477841947SLeila Ghaffari 
6577841947SLeila Ghaffari   // ------------------------------------------------------
6677841947SLeila Ghaffari   //             Create the libCEED context
6777841947SLeila Ghaffari   // ------------------------------------------------------
6877841947SLeila Ghaffari   CeedScalar vortex_strength = 5.;          // -
69504dc8e0SLeila Ghaffari   CeedScalar c_tau           = 0.5;         // -
70932417b3SJed Brown   // c_tau = 0.5 is reported as "optimal" in Hughes et al 2010
71e535bb46SLeila Ghaffari   PetscReal center[3],                      // m
72e535bb46SLeila Ghaffari             mean_velocity[3] = {1., 1., 0}; // m/s
731864f1c2SLeila Ghaffari   PetscReal domain_min[3], domain_max[3], domain_size[3];
741864f1c2SLeila Ghaffari   ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr);
751864f1c2SLeila Ghaffari   for (int i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i];
7677841947SLeila Ghaffari 
7777841947SLeila Ghaffari   // ------------------------------------------------------
7877841947SLeila Ghaffari   //             Create the PETSc context
7977841947SLeila Ghaffari   // ------------------------------------------------------
8077841947SLeila Ghaffari   PetscScalar meter    = 1e-2; // 1 meter in scaled length units
8177841947SLeila Ghaffari   PetscScalar second   = 1e-2; // 1 second in scaled time units
8277841947SLeila Ghaffari 
8377841947SLeila Ghaffari   // ------------------------------------------------------
8477841947SLeila Ghaffari   //              Command line Options
8577841947SLeila Ghaffari   // ------------------------------------------------------
8677841947SLeila Ghaffari   ierr = PetscOptionsBegin(comm, NULL, "Options for EULER_VORTEX problem",
8777841947SLeila Ghaffari                            NULL); CHKERRQ(ierr);
8877841947SLeila Ghaffari   // -- Physics
8977841947SLeila Ghaffari   ierr = PetscOptionsScalar("-vortex_strength", "Strength of Vortex",
9077841947SLeila Ghaffari                             NULL, vortex_strength, &vortex_strength, NULL);
9177841947SLeila Ghaffari   CHKERRQ(ierr);
9277841947SLeila Ghaffari   PetscInt n = problem->dim;
9377841947SLeila Ghaffari   PetscBool user_velocity;
9477841947SLeila Ghaffari   ierr = PetscOptionsRealArray("-mean_velocity", "Background velocity vector",
9577841947SLeila Ghaffari                                NULL, mean_velocity, &n, &user_velocity);
9677841947SLeila Ghaffari   CHKERRQ(ierr);
971864f1c2SLeila Ghaffari   for (int i=0; i<3; i++) center[i] = .5*domain_size[i];
9877841947SLeila Ghaffari   n = problem->dim;
9977841947SLeila Ghaffari   ierr = PetscOptionsRealArray("-center", "Location of vortex center",
10077841947SLeila Ghaffari                                NULL, center, &n, NULL); CHKERRQ(ierr);
10177841947SLeila Ghaffari   ierr = PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation",
10277841947SLeila Ghaffari                           NULL, implicit=PETSC_FALSE, &implicit, NULL);
10377841947SLeila Ghaffari   CHKERRQ(ierr);
10477841947SLeila Ghaffari   ierr = PetscOptionsEnum("-euler_test", "Euler test option", NULL,
105bc7bbd5dSLeila Ghaffari                           EulerTestTypes, (PetscEnum)(euler_test = EULER_TEST_ISENTROPIC_VORTEX),
10677841947SLeila Ghaffari                           (PetscEnum *)&euler_test, NULL); CHKERRQ(ierr);
107e6225c47SLeila Ghaffari   ierr = PetscOptionsEnum("-stab", "Stabilization method", NULL,
108e6225c47SLeila Ghaffari                           StabilizationTypes, (PetscEnum)(stab = STAB_NONE),
109e6225c47SLeila Ghaffari                           (PetscEnum *)&stab, NULL); CHKERRQ(ierr);
110932417b3SJed Brown   ierr = PetscOptionsScalar("-c_tau", "Stabilization constant",
111932417b3SJed Brown                             NULL, c_tau, &c_tau, NULL); CHKERRQ(ierr);
11277841947SLeila Ghaffari   // -- Units
11377841947SLeila Ghaffari   ierr = PetscOptionsScalar("-units_meter", "1 meter in scaled length units",
11477841947SLeila Ghaffari                             NULL, meter, &meter, NULL); CHKERRQ(ierr);
11577841947SLeila Ghaffari   meter = fabs(meter);
11677841947SLeila Ghaffari   ierr = PetscOptionsScalar("-units_second","1 second in scaled time units",
11777841947SLeila Ghaffari                             NULL, second, &second, NULL); CHKERRQ(ierr);
11877841947SLeila Ghaffari   second = fabs(second);
11977841947SLeila Ghaffari 
12077841947SLeila Ghaffari   // -- Warnings
121e6225c47SLeila Ghaffari   if (stab == STAB_SUPG && !implicit) {
122e6225c47SLeila Ghaffari     ierr = PetscPrintf(comm,
123e6225c47SLeila Ghaffari                        "Warning! Use -stab supg only with -implicit\n");
124e6225c47SLeila Ghaffari     CHKERRQ(ierr);
125e6225c47SLeila Ghaffari   }
12677841947SLeila Ghaffari   if (user_velocity && (euler_test == EULER_TEST_1
12777841947SLeila Ghaffari                         || euler_test == EULER_TEST_3)) {
12877841947SLeila Ghaffari     ierr = PetscPrintf(comm,
12977841947SLeila Ghaffari                        "Warning! Background velocity vector for -euler_test t1 and -euler_test t3 is (0,0,0)\n");
13077841947SLeila Ghaffari     CHKERRQ(ierr);
13177841947SLeila Ghaffari   }
13277841947SLeila Ghaffari 
13377841947SLeila Ghaffari   ierr = PetscOptionsEnd(); CHKERRQ(ierr);
13477841947SLeila Ghaffari 
13577841947SLeila Ghaffari   // ------------------------------------------------------
13677841947SLeila Ghaffari   //           Set up the PETSc context
13777841947SLeila Ghaffari   // ------------------------------------------------------
13877841947SLeila Ghaffari   user->units->meter  = meter;
13977841947SLeila Ghaffari   user->units->second = second;
14077841947SLeila Ghaffari 
14177841947SLeila Ghaffari   // ------------------------------------------------------
14277841947SLeila Ghaffari   //           Set up the libCEED context
14377841947SLeila Ghaffari   // ------------------------------------------------------
14477841947SLeila Ghaffari   // -- Scale variables to desired units
145e535bb46SLeila Ghaffari   for (int i=0; i<3; i++) {
146e535bb46SLeila Ghaffari     center[i] *= meter;
1471864f1c2SLeila Ghaffari     domain_size[i] *= meter;
1481864f1c2SLeila Ghaffari     mean_velocity[i] *= (meter/second);
149e535bb46SLeila Ghaffari   }
1501864f1c2SLeila Ghaffari   problem->dm_scale = meter;
15177841947SLeila Ghaffari 
15277841947SLeila Ghaffari   // -- Setup Context
1531864f1c2SLeila Ghaffari   setup_context->lx        = domain_size[0];
1541864f1c2SLeila Ghaffari   setup_context->ly        = domain_size[1];
1551864f1c2SLeila Ghaffari   setup_context->lz        = domain_size[2];
15677841947SLeila Ghaffari   setup_context->center[0] = center[0];
15777841947SLeila Ghaffari   setup_context->center[1] = center[1];
15877841947SLeila Ghaffari   setup_context->center[2] = center[2];
15977841947SLeila Ghaffari   setup_context->time      = 0;
16077841947SLeila Ghaffari 
16177841947SLeila Ghaffari   // -- QFunction Context
162e6225c47SLeila Ghaffari   user->phys->stab                        = stab;
16377841947SLeila Ghaffari   user->phys->euler_test                  = euler_test;
16477841947SLeila Ghaffari   user->phys->implicit                    = implicit;
16577841947SLeila Ghaffari   user->phys->has_curr_time               = has_curr_time;
16677841947SLeila Ghaffari   user->phys->has_neumann                 = has_neumann;
16777841947SLeila Ghaffari   user->phys->euler_ctx->curr_time        = 0.;
16877841947SLeila Ghaffari   user->phys->euler_ctx->implicit         = implicit;
16977841947SLeila Ghaffari   user->phys->euler_ctx->euler_test       = euler_test;
17077841947SLeila Ghaffari   user->phys->euler_ctx->center[0]        = center[0];
17177841947SLeila Ghaffari   user->phys->euler_ctx->center[1]        = center[1];
17277841947SLeila Ghaffari   user->phys->euler_ctx->center[2]        = center[2];
17377841947SLeila Ghaffari   user->phys->euler_ctx->vortex_strength  = vortex_strength;
174932417b3SJed Brown   user->phys->euler_ctx->c_tau            = c_tau;
17577841947SLeila Ghaffari   user->phys->euler_ctx->mean_velocity[0] = mean_velocity[0];
17677841947SLeila Ghaffari   user->phys->euler_ctx->mean_velocity[1] = mean_velocity[1];
17777841947SLeila Ghaffari   user->phys->euler_ctx->mean_velocity[2] = mean_velocity[2];
178e6225c47SLeila Ghaffari   user->phys->euler_ctx->stabilization    = stab;
17977841947SLeila Ghaffari 
18077841947SLeila Ghaffari   PetscFunctionReturn(0);
18177841947SLeila Ghaffari }
18277841947SLeila Ghaffari 
183d0b732dbSLeila Ghaffari PetscErrorCode SetupContext_EULER_VORTEX(Ceed ceed, CeedData ceed_data,
184d0b732dbSLeila Ghaffari     AppCtx app_ctx, SetupContext setup_ctx, Physics phys) {
185d0b732dbSLeila Ghaffari   PetscFunctionBeginUser;
186d0b732dbSLeila Ghaffari   CeedQFunctionContextCreate(ceed, &ceed_data->setup_context);
187d0b732dbSLeila Ghaffari   CeedQFunctionContextSetData(ceed_data->setup_context, CEED_MEM_HOST,
188d0b732dbSLeila Ghaffari                               CEED_USE_POINTER,
189d0b732dbSLeila Ghaffari                               sizeof(*setup_ctx), setup_ctx);
190d0b732dbSLeila Ghaffari   CeedQFunctionContextCreate(ceed, &ceed_data->euler_context);
191d0b732dbSLeila Ghaffari   CeedQFunctionContextSetData(ceed_data->euler_context, CEED_MEM_HOST,
192d0b732dbSLeila Ghaffari                               CEED_USE_POINTER,
193d0b732dbSLeila Ghaffari                               sizeof(*phys->euler_ctx), phys->euler_ctx);
194d0b732dbSLeila Ghaffari   if (ceed_data->qf_ics)
195d0b732dbSLeila Ghaffari     CeedQFunctionSetContext(ceed_data->qf_ics, ceed_data->euler_context);
196e6225c47SLeila Ghaffari   if (ceed_data->qf_rhs_vol)
197e6225c47SLeila Ghaffari     CeedQFunctionSetContext(ceed_data->qf_rhs_vol, ceed_data->euler_context);
198e6225c47SLeila Ghaffari   if (ceed_data->qf_ifunction_vol)
199e6225c47SLeila Ghaffari     CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, ceed_data->euler_context);
200*2fe7aee7SLeila Ghaffari   if (ceed_data->qf_apply_inflow)
201*2fe7aee7SLeila Ghaffari     CeedQFunctionSetContext(ceed_data->qf_apply_inflow, ceed_data->euler_context);
202*2fe7aee7SLeila Ghaffari   if (ceed_data->qf_apply_outflow)
203*2fe7aee7SLeila Ghaffari     CeedQFunctionSetContext(ceed_data->qf_apply_outflow, ceed_data->euler_context);
20477841947SLeila Ghaffari   PetscFunctionReturn(0);
20577841947SLeila Ghaffari }
20677841947SLeila Ghaffari 
20777841947SLeila Ghaffari PetscErrorCode PRINT_EULER_VORTEX(Physics phys, SetupContext setup_ctx,
20877841947SLeila Ghaffari                                   AppCtx app_ctx) {
20977841947SLeila Ghaffari   MPI_Comm       comm = PETSC_COMM_WORLD;
21077841947SLeila Ghaffari   PetscErrorCode ierr;
21177841947SLeila Ghaffari   PetscFunctionBeginUser;
21277841947SLeila Ghaffari 
21377841947SLeila Ghaffari   ierr = PetscPrintf(comm,
21477841947SLeila Ghaffari                      "  Problem:\n"
21577841947SLeila Ghaffari                      "    Problem Name                       : %s\n"
21677841947SLeila Ghaffari                      "    Test Case                          : %s\n"
217e6225c47SLeila Ghaffari                      "    Background Velocity                : %f,%f,%f\n"
218e6225c47SLeila Ghaffari                      "    Stabilization                      : %s\n",
21977841947SLeila Ghaffari                      app_ctx->problem_name, EulerTestTypes[phys->euler_test],
22077841947SLeila Ghaffari                      phys->euler_ctx->mean_velocity[0],
221e6225c47SLeila Ghaffari                      phys->euler_ctx->mean_velocity[1],
222e6225c47SLeila Ghaffari                      phys->euler_ctx->mean_velocity[2],
223e6225c47SLeila Ghaffari                      StabilizationTypes[phys->stab]); CHKERRQ(ierr);
22477841947SLeila Ghaffari 
22577841947SLeila Ghaffari   PetscFunctionReturn(0);
22677841947SLeila Ghaffari }
227