xref: /honee/problems/channel.c (revision cbe60e318f71d8fedc7dbd515907b9b7df1392f5)
1bb8a0c61SJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2bb8a0c61SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3bb8a0c61SJames Wright //
4bb8a0c61SJames Wright // SPDX-License-Identifier: BSD-2-Clause
5bb8a0c61SJames Wright //
6bb8a0c61SJames Wright // This file is part of CEED:  http://github.com/ceed
7bb8a0c61SJames Wright 
8bb8a0c61SJames Wright /// @file
9bb8a0c61SJames Wright /// Utility functions for setting up Channel flow
10bb8a0c61SJames Wright 
11bb8a0c61SJames Wright #include "../navierstokes.h"
12bb8a0c61SJames Wright #include "../qfunctions/channel.h"
13bb8a0c61SJames Wright 
146dd99bedSLeila Ghaffari PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm, void *ctx) {
15bb8a0c61SJames Wright 
16bb8a0c61SJames Wright   PetscInt ierr;
17bb8a0c61SJames Wright   User              user = *(User *)ctx;
18bb8a0c61SJames Wright   MPI_Comm          comm = PETSC_COMM_WORLD;
1915a3537eSJed Brown   ChannelContext    channel_ctx;
2015a3537eSJed Brown   NewtonianIdealGasContext newtonian_ig_ctx;
2115a3537eSJed Brown   CeedQFunctionContext channel_context;
2215a3537eSJed Brown 
23bb8a0c61SJames Wright   PetscFunctionBeginUser;
24b7f03f12SJed Brown   ierr = NS_NEWTONIAN_IG(problem, dm, ctx); CHKERRQ(ierr);
2515a3537eSJed Brown   ierr = PetscCalloc1(1, &channel_ctx); CHKERRQ(ierr);
26bb8a0c61SJames Wright 
27bb8a0c61SJames Wright   // ------------------------------------------------------
28bb8a0c61SJames Wright   //               SET UP Channel
29bb8a0c61SJames Wright   // ------------------------------------------------------
3015a3537eSJed Brown   CeedQFunctionContextDestroy(&problem->ics.qfunction_context);
319785fe93SJed Brown   problem->ics.qfunction     = ICsChannel;
329785fe93SJed Brown   problem->ics.qfunction_loc = ICsChannel_loc;
33*cbe60e31SLeila Ghaffari   if (!user->phys->primitive) {
349785fe93SJed Brown     problem->apply_inflow.qfunction      = Channel_Inflow;
359785fe93SJed Brown     problem->apply_inflow.qfunction_loc  = Channel_Inflow_loc;
369785fe93SJed Brown     problem->apply_outflow.qfunction     = Channel_Outflow;
379785fe93SJed Brown     problem->apply_outflow.qfunction_loc = Channel_Outflow_loc;
38*cbe60e31SLeila Ghaffari   }
39bb8a0c61SJames Wright 
40bb8a0c61SJames Wright   // -- Command Line Options
41bb8a0c61SJames Wright   CeedScalar umax   = 10.;  // m/s
42bb8a0c61SJames Wright   CeedScalar theta0 = 300.; // K
43bb8a0c61SJames Wright   CeedScalar P0     = 1.e5; // Pa
4410786903SJed Brown   PetscReal body_force_scale = 1.;
45bb8a0c61SJames Wright   PetscOptionsBegin(comm, NULL, "Options for CHANNEL problem", NULL);
46bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-umax", "Centerline velocity of the Channel",
47bb8a0c61SJames Wright                             NULL, umax, &umax, NULL); CHKERRQ(ierr);
48bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-theta0", "Wall temperature",
49bb8a0c61SJames Wright                             NULL, theta0, &theta0, NULL); CHKERRQ(ierr);
50bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-P0", "Pressure at outflow",
51bb8a0c61SJames Wright                             NULL, P0, &P0, NULL); CHKERRQ(ierr);
5210786903SJed Brown   ierr = PetscOptionsReal("-body_force_scale", "Multiplier for body force",
5310786903SJed Brown                           NULL, body_force_scale=1, &body_force_scale, NULL); CHKERRQ(ierr);
54bb8a0c61SJames Wright   PetscOptionsEnd();
55bb8a0c61SJames Wright 
56bb8a0c61SJames Wright   PetscScalar meter  = user->units->meter;
57bb8a0c61SJames Wright   PetscScalar second = user->units->second;
58bb8a0c61SJames Wright   PetscScalar Kelvin = user->units->Kelvin;
59bb8a0c61SJames Wright   PetscScalar Pascal = user->units->Pascal;
60bb8a0c61SJames Wright 
61bb8a0c61SJames Wright   theta0 *= Kelvin;
62bb8a0c61SJames Wright   P0     *= Pascal;
63bb8a0c61SJames Wright   umax   *= meter / second;
64bb8a0c61SJames Wright 
65bb8a0c61SJames Wright   //-- Setup Problem information
66bb8a0c61SJames Wright   CeedScalar H, center;
67bb8a0c61SJames Wright   {
68bb8a0c61SJames Wright     PetscReal domain_min[3], domain_max[3], domain_size[3];
69bb8a0c61SJames Wright     ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr);
70493642f1SJames Wright     for (PetscInt i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i];
71bb8a0c61SJames Wright 
72bb8a0c61SJames Wright     H      = 0.5*domain_size[1]*meter;
73bb8a0c61SJames Wright     center = H + domain_min[1]*meter;
74bb8a0c61SJames Wright   }
75bb8a0c61SJames Wright 
7615a3537eSJed Brown   // Some properties depend on parameters from NewtonianIdealGas
7715a3537eSJed Brown   CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context,
7815a3537eSJed Brown                               CEED_MEM_HOST, &newtonian_ig_ctx);
7915a3537eSJed Brown 
8015a3537eSJed Brown   channel_ctx->center   = center;
8115a3537eSJed Brown   channel_ctx->H        = H;
8215a3537eSJed Brown   channel_ctx->theta0   = theta0;
8315a3537eSJed Brown   channel_ctx->P0       = P0;
8415a3537eSJed Brown   channel_ctx->umax     = umax;
8515a3537eSJed Brown   channel_ctx->implicit = user->phys->implicit;
8610786903SJed Brown   channel_ctx->B = body_force_scale * 2 * umax*newtonian_ig_ctx->mu / (H*H);
87bb8a0c61SJames Wright 
88bb8a0c61SJames Wright   {
89bb8a0c61SJames Wright     // Calculate Body force
9015a3537eSJed Brown     CeedScalar cv  = newtonian_ig_ctx->cv,
9115a3537eSJed Brown                cp  = newtonian_ig_ctx->cp;
92bb8a0c61SJames Wright     CeedScalar Rd  = cp - cv;
93bb8a0c61SJames Wright     CeedScalar rho = P0 / (Rd*theta0);
9415a3537eSJed Brown     CeedScalar g[] = {channel_ctx->B / rho, 0., 0.};
9515a3537eSJed Brown     ierr = PetscArraycpy(newtonian_ig_ctx->g, g, 3); CHKERRQ(ierr);
96bb8a0c61SJames Wright   }
9715a3537eSJed Brown   channel_ctx->newtonian_ctx = *newtonian_ig_ctx;
9815a3537eSJed Brown   CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context,
9915a3537eSJed Brown                                   &newtonian_ig_ctx);
100bb8a0c61SJames Wright 
10115a3537eSJed Brown   CeedQFunctionContextCreate(user->ceed, &channel_context);
10215a3537eSJed Brown   CeedQFunctionContextSetData(channel_context, CEED_MEM_HOST,
103bb8a0c61SJames Wright                               CEED_USE_POINTER,
10415a3537eSJed Brown                               sizeof(*channel_ctx), channel_ctx);
10515a3537eSJed Brown   CeedQFunctionContextSetDataDestroy(channel_context, CEED_MEM_HOST,
10615a3537eSJed Brown                                      FreeContextPetsc);
10715a3537eSJed Brown 
10815a3537eSJed Brown   problem->ics.qfunction_context = channel_context;
10915a3537eSJed Brown   CeedQFunctionContextReferenceCopy(channel_context,
11015a3537eSJed Brown                                     &problem->apply_inflow.qfunction_context);
11115a3537eSJed Brown   CeedQFunctionContextReferenceCopy(channel_context,
11215a3537eSJed Brown                                     &problem->apply_outflow.qfunction_context);
113bb8a0c61SJames Wright   PetscFunctionReturn(0);
114bb8a0c61SJames Wright }
115