xref: /honee/problems/channel.c (revision 9785fe939f22dc29a5e9bc719da8d1f0a67d7249)
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 
14bb8a0c61SJames Wright #ifndef channel_context_struct
15bb8a0c61SJames Wright #define channel_context_struct
16bb8a0c61SJames Wright typedef struct ChannelContext_ *ChannelContext;
17bb8a0c61SJames Wright struct ChannelContext_ {
18bb8a0c61SJames Wright   bool       implicit; // !< Using implicit timesteping or not
19bb8a0c61SJames Wright   CeedScalar theta0;   // !< Reference temperature
20bb8a0c61SJames Wright   CeedScalar P0;       // !< Reference Pressure
21bb8a0c61SJames Wright   CeedScalar umax;     // !< Centerline velocity
22bb8a0c61SJames Wright   CeedScalar center;   // !< Y Coordinate for center of channel
23bb8a0c61SJames Wright   CeedScalar H;        // !< Channel half-height
24bb8a0c61SJames Wright   CeedScalar B;        // !< Body-force driving the flow
25bb8a0c61SJames Wright   struct NewtonianIdealGasContext_ newtonian_ctx;
26bb8a0c61SJames Wright };
27bb8a0c61SJames Wright #endif
28bb8a0c61SJames Wright 
29bb8a0c61SJames Wright PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm, void *setup_ctx,
30bb8a0c61SJames Wright                           void *ctx) {
31bb8a0c61SJames Wright 
32bb8a0c61SJames Wright   PetscInt ierr;
33bb8a0c61SJames Wright   ierr = NS_NEWTONIAN_IG(problem, dm, setup_ctx, ctx); CHKERRQ(ierr);
34bb8a0c61SJames Wright   User              user = *(User *)ctx;
35bb8a0c61SJames Wright   MPI_Comm          comm = PETSC_COMM_WORLD;
36bb8a0c61SJames Wright   PetscFunctionBeginUser;
37bb8a0c61SJames Wright   ierr = PetscCalloc1(1, &user->phys->channel_ctx); CHKERRQ(ierr);
38bb8a0c61SJames Wright 
39bb8a0c61SJames Wright   // ------------------------------------------------------
40bb8a0c61SJames Wright   //               SET UP Channel
41bb8a0c61SJames Wright   // ------------------------------------------------------
42*9785fe93SJed Brown   problem->ics.qfunction               = ICsChannel;
43*9785fe93SJed Brown   problem->ics.qfunction_loc           = ICsChannel_loc;
44*9785fe93SJed Brown   problem->apply_inflow.qfunction      = Channel_Inflow;
45*9785fe93SJed Brown   problem->apply_inflow.qfunction_loc  = Channel_Inflow_loc;
46*9785fe93SJed Brown   problem->apply_outflow.qfunction     = Channel_Outflow;
47*9785fe93SJed Brown   problem->apply_outflow.qfunction_loc = Channel_Outflow_loc;
48bb8a0c61SJames Wright   problem->setup_ctx                   = SetupContext_CHANNEL;
49bb8a0c61SJames Wright 
50bb8a0c61SJames Wright   // -- Command Line Options
51bb8a0c61SJames Wright   CeedScalar umax   = 10.;  // m/s
52bb8a0c61SJames Wright   CeedScalar mu     = .01;  // Pa s, dynamic viscosity
53bb8a0c61SJames Wright   //TODO ^^ make optional/respect explicit user set
54bb8a0c61SJames Wright   CeedScalar theta0 = 300.; // K
55bb8a0c61SJames Wright   CeedScalar P0     = 1.e5; // Pa
56bb8a0c61SJames Wright   PetscOptionsBegin(comm, NULL, "Options for CHANNEL problem", NULL);
57bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-umax", "Centerline velocity of the Channel",
58bb8a0c61SJames Wright                             NULL, umax, &umax, NULL); CHKERRQ(ierr);
59bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-theta0", "Wall temperature",
60bb8a0c61SJames Wright                             NULL, theta0, &theta0, NULL); CHKERRQ(ierr);
61bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-P0", "Pressure at outflow",
62bb8a0c61SJames Wright                             NULL, P0, &P0, NULL); CHKERRQ(ierr);
63bb8a0c61SJames Wright   PetscOptionsEnd();
64bb8a0c61SJames Wright 
65bb8a0c61SJames Wright   PetscScalar meter  = user->units->meter;
66bb8a0c61SJames Wright   PetscScalar second = user->units->second;
67bb8a0c61SJames Wright   PetscScalar Kelvin = user->units->Kelvin;
68bb8a0c61SJames Wright   PetscScalar Pascal = user->units->Pascal;
69bb8a0c61SJames Wright 
70bb8a0c61SJames Wright   mu     *= Pascal * second;
71bb8a0c61SJames Wright   theta0 *= Kelvin;
72bb8a0c61SJames Wright   P0     *= Pascal;
73bb8a0c61SJames Wright   umax   *= meter / second;
74bb8a0c61SJames Wright 
75bb8a0c61SJames Wright   //-- Setup Problem information
76bb8a0c61SJames Wright   CeedScalar H, center;
77bb8a0c61SJames Wright   {
78bb8a0c61SJames Wright     PetscReal domain_min[3], domain_max[3], domain_size[3];
79bb8a0c61SJames Wright     ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr);
80bb8a0c61SJames Wright     for (int i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i];
81bb8a0c61SJames Wright 
82bb8a0c61SJames Wright     H      = 0.5*domain_size[1]*meter;
83bb8a0c61SJames Wright     center = H + domain_min[1]*meter;
84bb8a0c61SJames Wright   }
85bb8a0c61SJames Wright 
86bb8a0c61SJames Wright   user->phys->channel_ctx->center   = center;
87bb8a0c61SJames Wright   user->phys->channel_ctx->H        = H;
88bb8a0c61SJames Wright   user->phys->channel_ctx->theta0   = theta0;
89bb8a0c61SJames Wright   user->phys->channel_ctx->P0       = P0;
90bb8a0c61SJames Wright   user->phys->channel_ctx->umax     = umax;
91bb8a0c61SJames Wright   user->phys->channel_ctx->implicit = user->phys->implicit;
92bb8a0c61SJames Wright   user->phys->channel_ctx->B = -2*umax*mu/H;
93bb8a0c61SJames Wright 
94bb8a0c61SJames Wright   {
95bb8a0c61SJames Wright     // Calculate Body force
96bb8a0c61SJames Wright     CeedScalar cv  = user->phys->newtonian_ig_ctx->cv,
97bb8a0c61SJames Wright                cp  = user->phys->newtonian_ig_ctx->cp;
98bb8a0c61SJames Wright     CeedScalar Rd  = cp - cv;
99bb8a0c61SJames Wright     CeedScalar rho = P0 / (Rd*theta0);
100bb8a0c61SJames Wright     CeedScalar g[] = {user->phys->channel_ctx->B / rho, 0., 0.};
101bb8a0c61SJames Wright     ierr = PetscArraycpy(user->phys->newtonian_ig_ctx->g, g, 3); CHKERRQ(ierr);
102bb8a0c61SJames Wright   }
103bb8a0c61SJames Wright   user->phys->newtonian_ig_ctx->mu = mu;
104bb8a0c61SJames Wright   user->phys->channel_ctx->newtonian_ctx = *user->phys->newtonian_ig_ctx;
105bb8a0c61SJames Wright 
106bb8a0c61SJames Wright   PetscFunctionReturn(0);
107bb8a0c61SJames Wright }
108bb8a0c61SJames Wright 
109bb8a0c61SJames Wright PetscErrorCode SetupContext_CHANNEL(Ceed ceed, CeedData ceed_data,
110bb8a0c61SJames Wright                                     AppCtx app_ctx, SetupContext setup_ctx, Physics phys) {
111bb8a0c61SJames Wright   PetscFunctionBeginUser;
112bb8a0c61SJames Wright   PetscInt ierr;
113bb8a0c61SJames Wright   ierr = SetupContext_NEWTONIAN_IG(ceed, ceed_data, app_ctx, setup_ctx, phys);
114bb8a0c61SJames Wright   CHKERRQ(ierr);
115bb8a0c61SJames Wright   CeedQFunctionContextCreate(ceed, &ceed_data->channel_context);
116bb8a0c61SJames Wright   CeedQFunctionContextSetData(ceed_data->channel_context, CEED_MEM_HOST,
117bb8a0c61SJames Wright                               CEED_USE_POINTER,
118bb8a0c61SJames Wright                               sizeof(*phys->channel_ctx), phys->channel_ctx);
119bb8a0c61SJames Wright   phys->has_neumann = PETSC_TRUE;
120bb8a0c61SJames Wright   if (ceed_data->qf_ics)
121bb8a0c61SJames Wright     CeedQFunctionSetContext(ceed_data->qf_ics, ceed_data->channel_context);
122bb8a0c61SJames Wright   if (ceed_data->qf_apply_inflow)
123bb8a0c61SJames Wright     CeedQFunctionSetContext(ceed_data->qf_apply_inflow, ceed_data->channel_context);
124bb8a0c61SJames Wright   if (ceed_data->qf_apply_outflow)
125bb8a0c61SJames Wright     CeedQFunctionSetContext(ceed_data->qf_apply_outflow,
126bb8a0c61SJames Wright                             ceed_data->channel_context);
127bb8a0c61SJames Wright   PetscFunctionReturn(0);
128bb8a0c61SJames Wright }
129