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