188626eedSJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 288626eedSJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 388626eedSJames Wright // 488626eedSJames Wright // SPDX-License-Identifier: BSD-2-Clause 588626eedSJames Wright // 688626eedSJames Wright // This file is part of CEED: http://github.com/ceed 788626eedSJames Wright 888626eedSJames Wright /// @file 988626eedSJames Wright /// Utility functions for setting up Channel flow 1088626eedSJames Wright 1188626eedSJames Wright #include "../navierstokes.h" 1288626eedSJames Wright #include "../qfunctions/channel.h" 1388626eedSJames Wright 14*6ef2784eSLeila Ghaffari PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm, void *ctx) { 1588626eedSJames Wright 1688626eedSJames Wright PetscInt ierr; 1788626eedSJames Wright User user = *(User *)ctx; 1888626eedSJames Wright MPI_Comm comm = PETSC_COMM_WORLD; 19841e4c73SJed Brown ChannelContext channel_ctx; 20841e4c73SJed Brown NewtonianIdealGasContext newtonian_ig_ctx; 21841e4c73SJed Brown CeedQFunctionContext channel_context; 22841e4c73SJed Brown 2388626eedSJames Wright PetscFunctionBeginUser; 24a0add3c9SJed Brown ierr = NS_NEWTONIAN_IG(problem, dm, ctx); CHKERRQ(ierr); 25841e4c73SJed Brown ierr = PetscCalloc1(1, &channel_ctx); CHKERRQ(ierr); 2688626eedSJames Wright 2788626eedSJames Wright // ------------------------------------------------------ 2888626eedSJames Wright // SET UP Channel 2988626eedSJames Wright // ------------------------------------------------------ 30841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->ics.qfunction_context); 3191e5af17SJed Brown problem->ics.qfunction = ICsChannel; 3291e5af17SJed Brown problem->ics.qfunction_loc = ICsChannel_loc; 3391e5af17SJed Brown problem->apply_inflow.qfunction = Channel_Inflow; 3491e5af17SJed Brown problem->apply_inflow.qfunction_loc = Channel_Inflow_loc; 3591e5af17SJed Brown problem->apply_outflow.qfunction = Channel_Outflow; 3691e5af17SJed Brown problem->apply_outflow.qfunction_loc = Channel_Outflow_loc; 3788626eedSJames Wright 3888626eedSJames Wright // -- Command Line Options 3988626eedSJames Wright CeedScalar umax = 10.; // m/s 4088626eedSJames Wright CeedScalar theta0 = 300.; // K 4188626eedSJames Wright CeedScalar P0 = 1.e5; // Pa 42e71202f6SJed Brown PetscReal body_force_scale = 1.; 4388626eedSJames Wright PetscOptionsBegin(comm, NULL, "Options for CHANNEL problem", NULL); 4488626eedSJames Wright ierr = PetscOptionsScalar("-umax", "Centerline velocity of the Channel", 4588626eedSJames Wright NULL, umax, &umax, NULL); CHKERRQ(ierr); 4688626eedSJames Wright ierr = PetscOptionsScalar("-theta0", "Wall temperature", 4788626eedSJames Wright NULL, theta0, &theta0, NULL); CHKERRQ(ierr); 4888626eedSJames Wright ierr = PetscOptionsScalar("-P0", "Pressure at outflow", 4988626eedSJames Wright NULL, P0, &P0, NULL); CHKERRQ(ierr); 50e71202f6SJed Brown ierr = PetscOptionsReal("-body_force_scale", "Multiplier for body force", 51e71202f6SJed Brown NULL, body_force_scale=1, &body_force_scale, NULL); CHKERRQ(ierr); 5288626eedSJames Wright PetscOptionsEnd(); 5388626eedSJames Wright 5488626eedSJames Wright PetscScalar meter = user->units->meter; 5588626eedSJames Wright PetscScalar second = user->units->second; 5688626eedSJames Wright PetscScalar Kelvin = user->units->Kelvin; 5788626eedSJames Wright PetscScalar Pascal = user->units->Pascal; 5888626eedSJames Wright 5988626eedSJames Wright theta0 *= Kelvin; 6088626eedSJames Wright P0 *= Pascal; 6188626eedSJames Wright umax *= meter / second; 6288626eedSJames Wright 6388626eedSJames Wright //-- Setup Problem information 6488626eedSJames Wright CeedScalar H, center; 6588626eedSJames Wright { 6688626eedSJames Wright PetscReal domain_min[3], domain_max[3], domain_size[3]; 6788626eedSJames Wright ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr); 68ba6664aeSJames Wright for (PetscInt i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 6988626eedSJames Wright 7088626eedSJames Wright H = 0.5*domain_size[1]*meter; 7188626eedSJames Wright center = H + domain_min[1]*meter; 7288626eedSJames Wright } 7388626eedSJames Wright 74841e4c73SJed Brown // Some properties depend on parameters from NewtonianIdealGas 75841e4c73SJed Brown CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, 76841e4c73SJed Brown CEED_MEM_HOST, &newtonian_ig_ctx); 77841e4c73SJed Brown 78841e4c73SJed Brown channel_ctx->center = center; 79841e4c73SJed Brown channel_ctx->H = H; 80841e4c73SJed Brown channel_ctx->theta0 = theta0; 81841e4c73SJed Brown channel_ctx->P0 = P0; 82841e4c73SJed Brown channel_ctx->umax = umax; 83841e4c73SJed Brown channel_ctx->implicit = user->phys->implicit; 84e71202f6SJed Brown channel_ctx->B = body_force_scale * 2 * umax*newtonian_ig_ctx->mu / (H*H); 8588626eedSJames Wright 8688626eedSJames Wright { 8788626eedSJames Wright // Calculate Body force 88841e4c73SJed Brown CeedScalar cv = newtonian_ig_ctx->cv, 89841e4c73SJed Brown cp = newtonian_ig_ctx->cp; 9088626eedSJames Wright CeedScalar Rd = cp - cv; 9188626eedSJames Wright CeedScalar rho = P0 / (Rd*theta0); 92841e4c73SJed Brown CeedScalar g[] = {channel_ctx->B / rho, 0., 0.}; 93841e4c73SJed Brown ierr = PetscArraycpy(newtonian_ig_ctx->g, g, 3); CHKERRQ(ierr); 9488626eedSJames Wright } 95841e4c73SJed Brown channel_ctx->newtonian_ctx = *newtonian_ig_ctx; 96841e4c73SJed Brown CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, 97841e4c73SJed Brown &newtonian_ig_ctx); 9888626eedSJames Wright 99841e4c73SJed Brown CeedQFunctionContextCreate(user->ceed, &channel_context); 100841e4c73SJed Brown CeedQFunctionContextSetData(channel_context, CEED_MEM_HOST, 10188626eedSJames Wright CEED_USE_POINTER, 102841e4c73SJed Brown sizeof(*channel_ctx), channel_ctx); 103841e4c73SJed Brown CeedQFunctionContextSetDataDestroy(channel_context, CEED_MEM_HOST, 104841e4c73SJed Brown FreeContextPetsc); 105841e4c73SJed Brown 106841e4c73SJed Brown problem->ics.qfunction_context = channel_context; 107841e4c73SJed Brown CeedQFunctionContextReferenceCopy(channel_context, 108841e4c73SJed Brown &problem->apply_inflow.qfunction_context); 109841e4c73SJed Brown CeedQFunctionContextReferenceCopy(channel_context, 110841e4c73SJed Brown &problem->apply_outflow.qfunction_context); 11188626eedSJames Wright PetscFunctionReturn(0); 11288626eedSJames Wright } 113