xref: /libCEED/examples/fluids/problems/channel.c (revision e71202f6ed1f7658a951fb96c00ca70137d558f9)
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 
14a0add3c9SJed Brown PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm,
1588626eedSJames Wright                           void *ctx) {
1688626eedSJames Wright 
1788626eedSJames Wright   PetscInt ierr;
1888626eedSJames Wright   User              user = *(User *)ctx;
1988626eedSJames Wright   MPI_Comm          comm = PETSC_COMM_WORLD;
20841e4c73SJed Brown   ChannelContext    channel_ctx;
21841e4c73SJed Brown   NewtonianIdealGasContext newtonian_ig_ctx;
22841e4c73SJed Brown   CeedQFunctionContext channel_context;
23841e4c73SJed Brown 
2488626eedSJames Wright   PetscFunctionBeginUser;
25a0add3c9SJed Brown   ierr = NS_NEWTONIAN_IG(problem, dm, ctx); CHKERRQ(ierr);
26841e4c73SJed Brown   ierr = PetscCalloc1(1, &channel_ctx); CHKERRQ(ierr);
2788626eedSJames Wright 
2888626eedSJames Wright   // ------------------------------------------------------
2988626eedSJames Wright   //               SET UP Channel
3088626eedSJames Wright   // ------------------------------------------------------
31841e4c73SJed 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
43*e71202f6SJed Brown   PetscReal body_force_scale = 1.;
4488626eedSJames Wright   PetscOptionsBegin(comm, NULL, "Options for CHANNEL problem", NULL);
4588626eedSJames Wright   ierr = PetscOptionsScalar("-umax", "Centerline velocity of the Channel",
4688626eedSJames Wright                             NULL, umax, &umax, NULL); CHKERRQ(ierr);
4788626eedSJames Wright   ierr = PetscOptionsScalar("-theta0", "Wall temperature",
4888626eedSJames Wright                             NULL, theta0, &theta0, NULL); CHKERRQ(ierr);
4988626eedSJames Wright   ierr = PetscOptionsScalar("-P0", "Pressure at outflow",
5088626eedSJames Wright                             NULL, P0, &P0, NULL); CHKERRQ(ierr);
51*e71202f6SJed Brown   ierr = PetscOptionsReal("-body_force_scale", "Multiplier for body force",
52*e71202f6SJed Brown                           NULL, body_force_scale=1, &body_force_scale, NULL); CHKERRQ(ierr);
5388626eedSJames Wright   PetscOptionsEnd();
5488626eedSJames Wright 
5588626eedSJames Wright   PetscScalar meter  = user->units->meter;
5688626eedSJames Wright   PetscScalar second = user->units->second;
5788626eedSJames Wright   PetscScalar Kelvin = user->units->Kelvin;
5888626eedSJames Wright   PetscScalar Pascal = user->units->Pascal;
5988626eedSJames Wright 
6088626eedSJames Wright   theta0 *= Kelvin;
6188626eedSJames Wright   P0     *= Pascal;
6288626eedSJames Wright   umax   *= meter / second;
6388626eedSJames Wright 
6488626eedSJames Wright   //-- Setup Problem information
6588626eedSJames Wright   CeedScalar H, center;
6688626eedSJames Wright   {
6788626eedSJames Wright     PetscReal domain_min[3], domain_max[3], domain_size[3];
6888626eedSJames Wright     ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr);
6988626eedSJames Wright     for (int i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i];
7088626eedSJames Wright 
7188626eedSJames Wright     H      = 0.5*domain_size[1]*meter;
7288626eedSJames Wright     center = H + domain_min[1]*meter;
7388626eedSJames Wright   }
7488626eedSJames Wright 
75841e4c73SJed Brown   // Some properties depend on parameters from NewtonianIdealGas
76841e4c73SJed Brown   CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context,
77841e4c73SJed Brown                               CEED_MEM_HOST, &newtonian_ig_ctx);
78841e4c73SJed Brown 
79841e4c73SJed Brown   channel_ctx->center   = center;
80841e4c73SJed Brown   channel_ctx->H        = H;
81841e4c73SJed Brown   channel_ctx->theta0   = theta0;
82841e4c73SJed Brown   channel_ctx->P0       = P0;
83841e4c73SJed Brown   channel_ctx->umax     = umax;
84841e4c73SJed Brown   channel_ctx->implicit = user->phys->implicit;
85*e71202f6SJed Brown   channel_ctx->B = body_force_scale * 2 * umax*newtonian_ig_ctx->mu / (H*H);
8688626eedSJames Wright 
8788626eedSJames Wright   {
8888626eedSJames Wright     // Calculate Body force
89841e4c73SJed Brown     CeedScalar cv  = newtonian_ig_ctx->cv,
90841e4c73SJed Brown                cp  = newtonian_ig_ctx->cp;
9188626eedSJames Wright     CeedScalar Rd  = cp - cv;
9288626eedSJames Wright     CeedScalar rho = P0 / (Rd*theta0);
93841e4c73SJed Brown     CeedScalar g[] = {channel_ctx->B / rho, 0., 0.};
94841e4c73SJed Brown     ierr = PetscArraycpy(newtonian_ig_ctx->g, g, 3); CHKERRQ(ierr);
9588626eedSJames Wright   }
96841e4c73SJed Brown   channel_ctx->newtonian_ctx = *newtonian_ig_ctx;
97841e4c73SJed Brown   CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context,
98841e4c73SJed Brown                                   &newtonian_ig_ctx);
9988626eedSJames Wright 
100841e4c73SJed Brown   CeedQFunctionContextCreate(user->ceed, &channel_context);
101841e4c73SJed Brown   CeedQFunctionContextSetData(channel_context, CEED_MEM_HOST,
10288626eedSJames Wright                               CEED_USE_POINTER,
103841e4c73SJed Brown                               sizeof(*channel_ctx), channel_ctx);
104841e4c73SJed Brown   CeedQFunctionContextSetDataDestroy(channel_context, CEED_MEM_HOST,
105841e4c73SJed Brown                                      FreeContextPetsc);
106841e4c73SJed Brown 
107841e4c73SJed Brown   problem->ics.qfunction_context = channel_context;
108841e4c73SJed Brown   CeedQFunctionContextReferenceCopy(channel_context,
109841e4c73SJed Brown                                     &problem->apply_inflow.qfunction_context);
110841e4c73SJed Brown   CeedQFunctionContextReferenceCopy(channel_context,
111841e4c73SJed Brown                                     &problem->apply_outflow.qfunction_context);
11288626eedSJames Wright   PetscFunctionReturn(0);
11388626eedSJames Wright }
114