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 Channel flow 10 11 #include "../qfunctions/channel.h" 12 13 #include <ceed.h> 14 #include <petscdm.h> 15 16 #include "../navierstokes.h" 17 18 PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { 19 User user = *(User *)ctx; 20 MPI_Comm comm = PETSC_COMM_WORLD; 21 ChannelContext channel_ctx; 22 NewtonianIdealGasContext newtonian_ig_ctx; 23 CeedQFunctionContext channel_context; 24 25 PetscFunctionBeginUser; 26 PetscCall(NS_NEWTONIAN_IG(problem, dm, ctx, bc)); 27 PetscCall(PetscCalloc1(1, &channel_ctx)); 28 29 // ------------------------------------------------------ 30 // SET UP Channel 31 // ------------------------------------------------------ 32 CeedQFunctionContextDestroy(&problem->ics.qfunction_context); 33 problem->ics.qfunction = ICsChannel; 34 problem->ics.qfunction_loc = ICsChannel_loc; 35 if (user->phys->state_var == STATEVAR_CONSERVATIVE) { 36 problem->apply_inflow.qfunction = Channel_Inflow; 37 problem->apply_inflow.qfunction_loc = Channel_Inflow_loc; 38 problem->apply_outflow.qfunction = Channel_Outflow; 39 problem->apply_outflow.qfunction_loc = Channel_Outflow_loc; 40 } 41 42 // -- Command Line Options 43 CeedScalar umax = 10.; // m/s 44 CeedScalar theta0 = 300.; // K 45 CeedScalar P0 = 1.e5; // Pa 46 PetscReal body_force_scale = 1.; 47 PetscOptionsBegin(comm, NULL, "Options for CHANNEL problem", NULL); 48 PetscCall(PetscOptionsScalar("-umax", "Centerline velocity of the Channel", NULL, umax, &umax, NULL)); 49 PetscCall(PetscOptionsScalar("-theta0", "Wall temperature", NULL, theta0, &theta0, NULL)); 50 PetscCall(PetscOptionsScalar("-P0", "Pressure at outflow", NULL, P0, &P0, NULL)); 51 PetscCall(PetscOptionsReal("-body_force_scale", "Multiplier for body force", NULL, body_force_scale = 1, &body_force_scale, NULL)); 52 PetscOptionsEnd(); 53 54 PetscScalar meter = user->units->meter; 55 PetscScalar second = user->units->second; 56 PetscScalar Kelvin = user->units->Kelvin; 57 PetscScalar Pascal = user->units->Pascal; 58 59 theta0 *= Kelvin; 60 P0 *= Pascal; 61 umax *= meter / second; 62 63 //-- Setup Problem information 64 CeedScalar H, center; 65 { 66 PetscReal domain_min[3], domain_max[3], domain_size[3]; 67 PetscCall(DMGetBoundingBox(dm, domain_min, domain_max)); 68 for (PetscInt i = 0; i < 3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 69 70 H = 0.5 * domain_size[1] * meter; 71 center = H + domain_min[1] * meter; 72 } 73 74 // Some properties depend on parameters from NewtonianIdealGas 75 CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx); 76 77 channel_ctx->center = center; 78 channel_ctx->H = H; 79 channel_ctx->theta0 = theta0; 80 channel_ctx->P0 = P0; 81 channel_ctx->umax = umax; 82 channel_ctx->implicit = user->phys->implicit; 83 channel_ctx->B = body_force_scale * 2 * umax * newtonian_ig_ctx->mu / (H * H); 84 85 { 86 // Calculate Body force 87 CeedScalar cv = newtonian_ig_ctx->cv, cp = newtonian_ig_ctx->cp; 88 CeedScalar Rd = cp - cv; 89 CeedScalar rho = P0 / (Rd * theta0); 90 CeedScalar g[] = {channel_ctx->B / rho, 0., 0.}; 91 PetscCall(PetscArraycpy(newtonian_ig_ctx->g, g, 3)); 92 } 93 channel_ctx->newtonian_ctx = *newtonian_ig_ctx; 94 CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx); 95 96 CeedQFunctionContextCreate(user->ceed, &channel_context); 97 CeedQFunctionContextSetData(channel_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*channel_ctx), channel_ctx); 98 CeedQFunctionContextSetDataDestroy(channel_context, CEED_MEM_HOST, FreeContextPetsc); 99 100 problem->ics.qfunction_context = channel_context; 101 CeedQFunctionContextReferenceCopy(channel_context, &problem->apply_inflow.qfunction_context); 102 CeedQFunctionContextReferenceCopy(channel_context, &problem->apply_outflow.qfunction_context); 103 PetscFunctionReturn(PETSC_SUCCESS); 104 } 105