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