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 146ef2784eSLeila 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; 33*dc805cc4SLeila Ghaffari if (!user->phys->primitive) { 3491e5af17SJed Brown problem->apply_inflow.qfunction = Channel_Inflow; 3591e5af17SJed Brown problem->apply_inflow.qfunction_loc = Channel_Inflow_loc; 3691e5af17SJed Brown problem->apply_outflow.qfunction = Channel_Outflow; 3791e5af17SJed Brown problem->apply_outflow.qfunction_loc = Channel_Outflow_loc; 38*dc805cc4SLeila Ghaffari } 3988626eedSJames Wright 4088626eedSJames Wright // -- Command Line Options 4188626eedSJames Wright CeedScalar umax = 10.; // m/s 4288626eedSJames Wright CeedScalar theta0 = 300.; // K 4388626eedSJames Wright CeedScalar P0 = 1.e5; // Pa 44e71202f6SJed Brown PetscReal body_force_scale = 1.; 4588626eedSJames Wright PetscOptionsBegin(comm, NULL, "Options for CHANNEL problem", NULL); 4688626eedSJames Wright ierr = PetscOptionsScalar("-umax", "Centerline velocity of the Channel", 4788626eedSJames Wright NULL, umax, &umax, NULL); CHKERRQ(ierr); 4888626eedSJames Wright ierr = PetscOptionsScalar("-theta0", "Wall temperature", 4988626eedSJames Wright NULL, theta0, &theta0, NULL); CHKERRQ(ierr); 5088626eedSJames Wright ierr = PetscOptionsScalar("-P0", "Pressure at outflow", 5188626eedSJames Wright NULL, P0, &P0, NULL); CHKERRQ(ierr); 52e71202f6SJed Brown ierr = PetscOptionsReal("-body_force_scale", "Multiplier for body force", 53e71202f6SJed Brown NULL, body_force_scale=1, &body_force_scale, NULL); CHKERRQ(ierr); 5488626eedSJames Wright PetscOptionsEnd(); 5588626eedSJames Wright 5688626eedSJames Wright PetscScalar meter = user->units->meter; 5788626eedSJames Wright PetscScalar second = user->units->second; 5888626eedSJames Wright PetscScalar Kelvin = user->units->Kelvin; 5988626eedSJames Wright PetscScalar Pascal = user->units->Pascal; 6088626eedSJames Wright 6188626eedSJames Wright theta0 *= Kelvin; 6288626eedSJames Wright P0 *= Pascal; 6388626eedSJames Wright umax *= meter / second; 6488626eedSJames Wright 6588626eedSJames Wright //-- Setup Problem information 6688626eedSJames Wright CeedScalar H, center; 6788626eedSJames Wright { 6888626eedSJames Wright PetscReal domain_min[3], domain_max[3], domain_size[3]; 6988626eedSJames Wright ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr); 70ba6664aeSJames Wright for (PetscInt i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 7188626eedSJames Wright 7288626eedSJames Wright H = 0.5*domain_size[1]*meter; 7388626eedSJames Wright center = H + domain_min[1]*meter; 7488626eedSJames Wright } 7588626eedSJames Wright 76841e4c73SJed Brown // Some properties depend on parameters from NewtonianIdealGas 77841e4c73SJed Brown CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, 78841e4c73SJed Brown CEED_MEM_HOST, &newtonian_ig_ctx); 79841e4c73SJed Brown 80841e4c73SJed Brown channel_ctx->center = center; 81841e4c73SJed Brown channel_ctx->H = H; 82841e4c73SJed Brown channel_ctx->theta0 = theta0; 83841e4c73SJed Brown channel_ctx->P0 = P0; 84841e4c73SJed Brown channel_ctx->umax = umax; 85841e4c73SJed Brown channel_ctx->implicit = user->phys->implicit; 86e71202f6SJed Brown channel_ctx->B = body_force_scale * 2 * umax*newtonian_ig_ctx->mu / (H*H); 8788626eedSJames Wright 8888626eedSJames Wright { 8988626eedSJames Wright // Calculate Body force 90841e4c73SJed Brown CeedScalar cv = newtonian_ig_ctx->cv, 91841e4c73SJed Brown cp = newtonian_ig_ctx->cp; 9288626eedSJames Wright CeedScalar Rd = cp - cv; 9388626eedSJames Wright CeedScalar rho = P0 / (Rd*theta0); 94841e4c73SJed Brown CeedScalar g[] = {channel_ctx->B / rho, 0., 0.}; 95841e4c73SJed Brown ierr = PetscArraycpy(newtonian_ig_ctx->g, g, 3); CHKERRQ(ierr); 9688626eedSJames Wright } 97841e4c73SJed Brown channel_ctx->newtonian_ctx = *newtonian_ig_ctx; 98841e4c73SJed Brown CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, 99841e4c73SJed Brown &newtonian_ig_ctx); 10088626eedSJames Wright 101841e4c73SJed Brown CeedQFunctionContextCreate(user->ceed, &channel_context); 102841e4c73SJed Brown CeedQFunctionContextSetData(channel_context, CEED_MEM_HOST, 10388626eedSJames Wright CEED_USE_POINTER, 104841e4c73SJed Brown sizeof(*channel_ctx), channel_ctx); 105841e4c73SJed Brown CeedQFunctionContextSetDataDestroy(channel_context, CEED_MEM_HOST, 106841e4c73SJed Brown FreeContextPetsc); 107841e4c73SJed Brown 108841e4c73SJed Brown problem->ics.qfunction_context = channel_context; 109841e4c73SJed Brown CeedQFunctionContextReferenceCopy(channel_context, 110841e4c73SJed Brown &problem->apply_inflow.qfunction_context); 111841e4c73SJed Brown CeedQFunctionContextReferenceCopy(channel_context, 112841e4c73SJed Brown &problem->apply_outflow.qfunction_context); 11388626eedSJames Wright PetscFunctionReturn(0); 11488626eedSJames Wright } 115