xref: /libCEED/examples/fluids/problems/channel.c (revision 841e4c7362a2acf3a6f116f4961b1eb52fa410fc)
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 
1488626eedSJames Wright PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm, void *setup_ctx,
1588626eedSJames Wright                           void *ctx) {
1688626eedSJames Wright 
1788626eedSJames Wright   PetscInt ierr;
1888626eedSJames Wright   User              user = *(User *)ctx;
1988626eedSJames Wright   MPI_Comm          comm = PETSC_COMM_WORLD;
20*841e4c73SJed Brown   ChannelContext    channel_ctx;
21*841e4c73SJed Brown   NewtonianIdealGasContext newtonian_ig_ctx;
22*841e4c73SJed Brown   CeedQFunctionContext channel_context;
23*841e4c73SJed Brown 
2488626eedSJames Wright   PetscFunctionBeginUser;
25*841e4c73SJed Brown   ierr = NS_NEWTONIAN_IG(problem, dm, setup_ctx, ctx); CHKERRQ(ierr);
26*841e4c73SJed Brown   ierr = PetscCalloc1(1, &channel_ctx); CHKERRQ(ierr);
2788626eedSJames Wright 
2888626eedSJames Wright   // ------------------------------------------------------
2988626eedSJames Wright   //               SET UP Channel
3088626eedSJames Wright   // ------------------------------------------------------
31*841e4c73SJed Brown   CeedQFunctionContextDestroy(&problem->ics.qfunction_context);
3291e5af17SJed Brown   problem->ics.qfunction               = ICsChannel;
3391e5af17SJed Brown   problem->ics.qfunction_loc           = ICsChannel_loc;
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;
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
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);
5088626eedSJames Wright   PetscOptionsEnd();
5188626eedSJames Wright 
5288626eedSJames Wright   PetscScalar meter  = user->units->meter;
5388626eedSJames Wright   PetscScalar second = user->units->second;
5488626eedSJames Wright   PetscScalar Kelvin = user->units->Kelvin;
5588626eedSJames Wright   PetscScalar Pascal = user->units->Pascal;
5688626eedSJames Wright 
5788626eedSJames Wright   theta0 *= Kelvin;
5888626eedSJames Wright   P0     *= Pascal;
5988626eedSJames Wright   umax   *= meter / second;
6088626eedSJames Wright 
6188626eedSJames Wright   //-- Setup Problem information
6288626eedSJames Wright   CeedScalar H, center;
6388626eedSJames Wright   {
6488626eedSJames Wright     PetscReal domain_min[3], domain_max[3], domain_size[3];
6588626eedSJames Wright     ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr);
6688626eedSJames Wright     for (int i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i];
6788626eedSJames Wright 
6888626eedSJames Wright     H      = 0.5*domain_size[1]*meter;
6988626eedSJames Wright     center = H + domain_min[1]*meter;
7088626eedSJames Wright   }
7188626eedSJames Wright 
72*841e4c73SJed Brown   // Some properties depend on parameters from NewtonianIdealGas
73*841e4c73SJed Brown   CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context,
74*841e4c73SJed Brown                               CEED_MEM_HOST, &newtonian_ig_ctx);
75*841e4c73SJed Brown 
76*841e4c73SJed Brown   channel_ctx->center   = center;
77*841e4c73SJed Brown   channel_ctx->H        = H;
78*841e4c73SJed Brown   channel_ctx->theta0   = theta0;
79*841e4c73SJed Brown   channel_ctx->P0       = P0;
80*841e4c73SJed Brown   channel_ctx->umax     = umax;
81*841e4c73SJed Brown   channel_ctx->implicit = user->phys->implicit;
82*841e4c73SJed Brown   channel_ctx->B = -2*umax*newtonian_ig_ctx->mu/H;
8388626eedSJames Wright 
8488626eedSJames Wright   {
8588626eedSJames Wright     // Calculate Body force
86*841e4c73SJed Brown     CeedScalar cv  = newtonian_ig_ctx->cv,
87*841e4c73SJed Brown                cp  = newtonian_ig_ctx->cp;
8888626eedSJames Wright     CeedScalar Rd  = cp - cv;
8988626eedSJames Wright     CeedScalar rho = P0 / (Rd*theta0);
90*841e4c73SJed Brown     CeedScalar g[] = {channel_ctx->B / rho, 0., 0.};
91*841e4c73SJed Brown     ierr = PetscArraycpy(newtonian_ig_ctx->g, g, 3); CHKERRQ(ierr);
9288626eedSJames Wright   }
93*841e4c73SJed Brown   channel_ctx->newtonian_ctx = *newtonian_ig_ctx;
94*841e4c73SJed Brown   CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context,
95*841e4c73SJed Brown                                   &newtonian_ig_ctx);
9688626eedSJames Wright 
97*841e4c73SJed Brown   CeedQFunctionContextCreate(user->ceed, &channel_context);
98*841e4c73SJed Brown   CeedQFunctionContextSetData(channel_context, CEED_MEM_HOST,
9988626eedSJames Wright                               CEED_USE_POINTER,
100*841e4c73SJed Brown                               sizeof(*channel_ctx), channel_ctx);
101*841e4c73SJed Brown   CeedQFunctionContextSetDataDestroy(channel_context, CEED_MEM_HOST,
102*841e4c73SJed Brown                                      FreeContextPetsc);
103*841e4c73SJed Brown 
104*841e4c73SJed Brown   problem->ics.qfunction_context = channel_context;
105*841e4c73SJed Brown   CeedQFunctionContextReferenceCopy(channel_context,
106*841e4c73SJed Brown                                     &problem->apply_inflow.qfunction_context);
107*841e4c73SJed Brown   CeedQFunctionContextReferenceCopy(channel_context,
108*841e4c73SJed Brown                                     &problem->apply_outflow.qfunction_context);
10988626eedSJames Wright   PetscFunctionReturn(0);
11088626eedSJames Wright }
111