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 "../qfunctions/channel.h" 1288626eedSJames Wright 132b730f8bSJeremy L Thompson #include "../navierstokes.h" 1488626eedSJames Wright 15*46de7363SJames Wright PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { 1688626eedSJames Wright User user = *(User *)ctx; 1788626eedSJames Wright MPI_Comm comm = PETSC_COMM_WORLD; 18841e4c73SJed Brown ChannelContext channel_ctx; 19841e4c73SJed Brown NewtonianIdealGasContext newtonian_ig_ctx; 20841e4c73SJed Brown CeedQFunctionContext channel_context; 21841e4c73SJed Brown 2288626eedSJames Wright PetscFunctionBeginUser; 23*46de7363SJames Wright PetscCall(NS_NEWTONIAN_IG(problem, dm, ctx, bc)); 242b730f8bSJeremy L Thompson PetscCall(PetscCalloc1(1, &channel_ctx)); 2588626eedSJames Wright 2688626eedSJames Wright // ------------------------------------------------------ 2788626eedSJames Wright // SET UP Channel 2888626eedSJames Wright // ------------------------------------------------------ 29841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->ics.qfunction_context); 3091e5af17SJed Brown problem->ics.qfunction = ICsChannel; 3191e5af17SJed Brown problem->ics.qfunction_loc = ICsChannel_loc; 3297baf651SJames Wright if (user->phys->state_var == STATEVAR_CONSERVATIVE) { 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; 37dc805cc4SLeila Ghaffari } 3888626eedSJames Wright 3988626eedSJames Wright // -- Command Line Options 4088626eedSJames Wright CeedScalar umax = 10.; // m/s 4188626eedSJames Wright CeedScalar theta0 = 300.; // K 4288626eedSJames Wright CeedScalar P0 = 1.e5; // Pa 43e71202f6SJed Brown PetscReal body_force_scale = 1.; 4488626eedSJames Wright PetscOptionsBegin(comm, NULL, "Options for CHANNEL problem", NULL); 452b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-umax", "Centerline velocity of the Channel", NULL, umax, &umax, NULL)); 462b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-theta0", "Wall temperature", NULL, theta0, &theta0, NULL)); 472b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-P0", "Pressure at outflow", NULL, P0, &P0, NULL)); 482b730f8bSJeremy L Thompson PetscCall(PetscOptionsReal("-body_force_scale", "Multiplier for body force", NULL, body_force_scale = 1, &body_force_scale, NULL)); 4988626eedSJames Wright PetscOptionsEnd(); 5088626eedSJames Wright 5188626eedSJames Wright PetscScalar meter = user->units->meter; 5288626eedSJames Wright PetscScalar second = user->units->second; 5388626eedSJames Wright PetscScalar Kelvin = user->units->Kelvin; 5488626eedSJames Wright PetscScalar Pascal = user->units->Pascal; 5588626eedSJames Wright 5688626eedSJames Wright theta0 *= Kelvin; 5788626eedSJames Wright P0 *= Pascal; 5888626eedSJames Wright umax *= meter / second; 5988626eedSJames Wright 6088626eedSJames Wright //-- Setup Problem information 6188626eedSJames Wright CeedScalar H, center; 6288626eedSJames Wright { 6388626eedSJames Wright PetscReal domain_min[3], domain_max[3], domain_size[3]; 642b730f8bSJeremy L Thompson PetscCall(DMGetBoundingBox(dm, domain_min, domain_max)); 65ba6664aeSJames Wright for (PetscInt i = 0; i < 3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 6688626eedSJames Wright 6788626eedSJames Wright H = 0.5 * domain_size[1] * meter; 6888626eedSJames Wright center = H + domain_min[1] * meter; 6988626eedSJames Wright } 7088626eedSJames Wright 71841e4c73SJed Brown // Some properties depend on parameters from NewtonianIdealGas 722b730f8bSJeremy L Thompson CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx); 73841e4c73SJed Brown 74841e4c73SJed Brown channel_ctx->center = center; 75841e4c73SJed Brown channel_ctx->H = H; 76841e4c73SJed Brown channel_ctx->theta0 = theta0; 77841e4c73SJed Brown channel_ctx->P0 = P0; 78841e4c73SJed Brown channel_ctx->umax = umax; 79841e4c73SJed Brown channel_ctx->implicit = user->phys->implicit; 80e71202f6SJed Brown channel_ctx->B = body_force_scale * 2 * umax * newtonian_ig_ctx->mu / (H * H); 8188626eedSJames Wright 8288626eedSJames Wright { 8388626eedSJames Wright // Calculate Body force 842b730f8bSJeremy L Thompson CeedScalar cv = newtonian_ig_ctx->cv, cp = newtonian_ig_ctx->cp; 8588626eedSJames Wright CeedScalar Rd = cp - cv; 8688626eedSJames Wright CeedScalar rho = P0 / (Rd * theta0); 87841e4c73SJed Brown CeedScalar g[] = {channel_ctx->B / rho, 0., 0.}; 882b730f8bSJeremy L Thompson PetscCall(PetscArraycpy(newtonian_ig_ctx->g, g, 3)); 8988626eedSJames Wright } 90841e4c73SJed Brown channel_ctx->newtonian_ctx = *newtonian_ig_ctx; 912b730f8bSJeremy L Thompson CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx); 9288626eedSJames Wright 93841e4c73SJed Brown CeedQFunctionContextCreate(user->ceed, &channel_context); 942b730f8bSJeremy L Thompson CeedQFunctionContextSetData(channel_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*channel_ctx), channel_ctx); 952b730f8bSJeremy L Thompson CeedQFunctionContextSetDataDestroy(channel_context, CEED_MEM_HOST, FreeContextPetsc); 96841e4c73SJed Brown 97841e4c73SJed Brown problem->ics.qfunction_context = channel_context; 982b730f8bSJeremy L Thompson CeedQFunctionContextReferenceCopy(channel_context, &problem->apply_inflow.qfunction_context); 992b730f8bSJeremy L Thompson CeedQFunctionContextReferenceCopy(channel_context, &problem->apply_outflow.qfunction_context); 10088626eedSJames Wright PetscFunctionReturn(0); 10188626eedSJames Wright } 102