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 13*49aac155SJeremy L Thompson #include <ceed.h> 14*49aac155SJeremy L Thompson #include <petscdm.h> 15*49aac155SJeremy L Thompson 162b730f8bSJeremy L Thompson #include "../navierstokes.h" 1788626eedSJames Wright 1846de7363SJames Wright PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { 1988626eedSJames Wright User user = *(User *)ctx; 2088626eedSJames Wright MPI_Comm comm = PETSC_COMM_WORLD; 21841e4c73SJed Brown ChannelContext channel_ctx; 22841e4c73SJed Brown NewtonianIdealGasContext newtonian_ig_ctx; 23841e4c73SJed Brown CeedQFunctionContext channel_context; 24841e4c73SJed Brown 2588626eedSJames Wright PetscFunctionBeginUser; 2646de7363SJames Wright PetscCall(NS_NEWTONIAN_IG(problem, dm, ctx, bc)); 272b730f8bSJeremy L Thompson PetscCall(PetscCalloc1(1, &channel_ctx)); 2888626eedSJames Wright 2988626eedSJames Wright // ------------------------------------------------------ 3088626eedSJames Wright // SET UP Channel 3188626eedSJames Wright // ------------------------------------------------------ 32841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->ics.qfunction_context); 3391e5af17SJed Brown problem->ics.qfunction = ICsChannel; 3491e5af17SJed Brown problem->ics.qfunction_loc = ICsChannel_loc; 3597baf651SJames Wright if (user->phys->state_var == STATEVAR_CONSERVATIVE) { 3691e5af17SJed Brown problem->apply_inflow.qfunction = Channel_Inflow; 3791e5af17SJed Brown problem->apply_inflow.qfunction_loc = Channel_Inflow_loc; 3891e5af17SJed Brown problem->apply_outflow.qfunction = Channel_Outflow; 3991e5af17SJed Brown problem->apply_outflow.qfunction_loc = Channel_Outflow_loc; 40dc805cc4SLeila Ghaffari } 4188626eedSJames Wright 4288626eedSJames Wright // -- Command Line Options 4388626eedSJames Wright CeedScalar umax = 10.; // m/s 4488626eedSJames Wright CeedScalar theta0 = 300.; // K 4588626eedSJames Wright CeedScalar P0 = 1.e5; // Pa 46e71202f6SJed Brown PetscReal body_force_scale = 1.; 4788626eedSJames Wright PetscOptionsBegin(comm, NULL, "Options for CHANNEL problem", NULL); 482b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-umax", "Centerline velocity of the Channel", NULL, umax, &umax, NULL)); 492b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-theta0", "Wall temperature", NULL, theta0, &theta0, NULL)); 502b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-P0", "Pressure at outflow", NULL, P0, &P0, NULL)); 512b730f8bSJeremy L Thompson PetscCall(PetscOptionsReal("-body_force_scale", "Multiplier for body force", NULL, body_force_scale = 1, &body_force_scale, NULL)); 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]; 672b730f8bSJeremy L Thompson PetscCall(DMGetBoundingBox(dm, domain_min, domain_max)); 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 752b730f8bSJeremy L Thompson CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx); 76841e4c73SJed Brown 77841e4c73SJed Brown channel_ctx->center = center; 78841e4c73SJed Brown channel_ctx->H = H; 79841e4c73SJed Brown channel_ctx->theta0 = theta0; 80841e4c73SJed Brown channel_ctx->P0 = P0; 81841e4c73SJed Brown channel_ctx->umax = umax; 82841e4c73SJed Brown channel_ctx->implicit = user->phys->implicit; 83e71202f6SJed Brown channel_ctx->B = body_force_scale * 2 * umax * newtonian_ig_ctx->mu / (H * H); 8488626eedSJames Wright 8588626eedSJames Wright { 8688626eedSJames Wright // Calculate Body force 872b730f8bSJeremy L Thompson CeedScalar cv = newtonian_ig_ctx->cv, cp = newtonian_ig_ctx->cp; 8888626eedSJames Wright CeedScalar Rd = cp - cv; 8988626eedSJames Wright CeedScalar rho = P0 / (Rd * theta0); 90841e4c73SJed Brown CeedScalar g[] = {channel_ctx->B / rho, 0., 0.}; 912b730f8bSJeremy L Thompson PetscCall(PetscArraycpy(newtonian_ig_ctx->g, g, 3)); 9288626eedSJames Wright } 93841e4c73SJed Brown channel_ctx->newtonian_ctx = *newtonian_ig_ctx; 942b730f8bSJeremy L Thompson CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx); 9588626eedSJames Wright 96841e4c73SJed Brown CeedQFunctionContextCreate(user->ceed, &channel_context); 972b730f8bSJeremy L Thompson CeedQFunctionContextSetData(channel_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*channel_ctx), channel_ctx); 982b730f8bSJeremy L Thompson CeedQFunctionContextSetDataDestroy(channel_context, CEED_MEM_HOST, FreeContextPetsc); 99841e4c73SJed Brown 100841e4c73SJed Brown problem->ics.qfunction_context = channel_context; 1012b730f8bSJeremy L Thompson CeedQFunctionContextReferenceCopy(channel_context, &problem->apply_inflow.qfunction_context); 1022b730f8bSJeremy L Thompson CeedQFunctionContextReferenceCopy(channel_context, &problem->apply_outflow.qfunction_context); 10388626eedSJames Wright PetscFunctionReturn(0); 10488626eedSJames Wright } 105