xref: /honee/problems/densitycurrent.c (revision bb8a0c61f21224cefcdd60e71004bb99df1e9a58)
1*bb8a0c61SJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other
2*bb8a0c61SJames Wright // CEED contributors. All Rights Reserved. See the top-level LICENSE and NOTICE
3*bb8a0c61SJames Wright // files for details.
4a515125bSLeila Ghaffari //
5727da7e7SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
6a515125bSLeila Ghaffari //
7727da7e7SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
8a515125bSLeila Ghaffari 
9a515125bSLeila Ghaffari /// @file
10a515125bSLeila Ghaffari /// Utility functions for setting up DENSITY_CURRENT
11a515125bSLeila Ghaffari 
12a515125bSLeila Ghaffari #include "../qfunctions/densitycurrent.h"
13*bb8a0c61SJames Wright #include "../navierstokes.h"
14a515125bSLeila Ghaffari 
1505a512bdSLeila Ghaffari PetscErrorCode NS_DENSITY_CURRENT(ProblemData *problem, DM dm, void *setup_ctx,
16a515125bSLeila Ghaffari                                   void *ctx) {
173a8779fbSJames Wright 
183a8779fbSJames Wright   PetscInt ierr;
19*bb8a0c61SJames Wright   ierr = NS_NEWTONIAN_IG(problem, dm, setup_ctx, ctx);
20*bb8a0c61SJames Wright   CHKERRQ(ierr);
21a515125bSLeila Ghaffari   SetupContext setup_context = *(SetupContext *)setup_ctx;
22a515125bSLeila Ghaffari   User user = *(User *)ctx;
23a515125bSLeila Ghaffari   MPI_Comm comm = PETSC_COMM_WORLD;
24a515125bSLeila Ghaffari   PetscFunctionBeginUser;
25a515125bSLeila Ghaffari 
26a515125bSLeila Ghaffari   // ------------------------------------------------------
27a515125bSLeila Ghaffari   //               SET UP DENSITY_CURRENT
28a515125bSLeila Ghaffari   // ------------------------------------------------------
29a515125bSLeila Ghaffari   problem->ics = ICsDC;
30a515125bSLeila Ghaffari   problem->ics_loc = ICsDC_loc;
31a515125bSLeila Ghaffari   problem->bc = Exact_DC;
32a515125bSLeila Ghaffari 
33a515125bSLeila Ghaffari   // ------------------------------------------------------
34a515125bSLeila Ghaffari   //             Create the libCEED context
35a515125bSLeila Ghaffari   // ------------------------------------------------------
36*bb8a0c61SJames Wright   CeedScalar theta0 = 300.; // K
37*bb8a0c61SJames Wright   CeedScalar thetaC = -15.; // K
38*bb8a0c61SJames Wright   CeedScalar P0 = 1.e5;     // Pa
39*bb8a0c61SJames Wright   CeedScalar N = 0.01;      // 1/s
40a515125bSLeila Ghaffari   CeedScalar rc = 1000.;    // m (Radius of bubble)
41a515125bSLeila Ghaffari   PetscReal center[3], dc_axis[3] = {0, 0, 0};
4205a512bdSLeila Ghaffari   PetscReal domain_min[3], domain_max[3], domain_size[3];
43*bb8a0c61SJames Wright   ierr = DMGetBoundingBox(dm, domain_min, domain_max);
44*bb8a0c61SJames Wright   CHKERRQ(ierr);
45*bb8a0c61SJames Wright   for (int i = 0; i < 3; i++)
46*bb8a0c61SJames Wright     domain_size[i] = domain_max[i] - domain_min[i];
47a515125bSLeila Ghaffari 
48a515125bSLeila Ghaffari   // ------------------------------------------------------
49a515125bSLeila Ghaffari   //              Command line Options
50a515125bSLeila Ghaffari   // ------------------------------------------------------
511485969bSJeremy L Thompson   PetscOptionsBegin(comm, NULL, "Options for DENSITY_CURRENT problem", NULL);
52*bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-theta0", "Reference potential temperature", NULL,
53*bb8a0c61SJames Wright                             theta0, &theta0, NULL);
54*bb8a0c61SJames Wright   CHKERRQ(ierr);
55*bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-thetaC", "Perturbation of potential temperature",
56*bb8a0c61SJames Wright                             NULL, thetaC, &thetaC, NULL);
57*bb8a0c61SJames Wright   CHKERRQ(ierr);
58*bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-P0", "Atmospheric pressure", NULL, P0, &P0, NULL);
59*bb8a0c61SJames Wright   CHKERRQ(ierr);
60*bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-N", "Brunt-Vaisala frequency", NULL, N, &N, NULL);
61*bb8a0c61SJames Wright   CHKERRQ(ierr);
62a515125bSLeila Ghaffari   ierr = PetscOptionsScalar("-rc", "Characteristic radius of thermal bubble",
63*bb8a0c61SJames Wright                             NULL, rc, &rc, NULL);
64*bb8a0c61SJames Wright   CHKERRQ(ierr);
65*bb8a0c61SJames Wright   for (int i = 0; i < 3; i++)
66*bb8a0c61SJames Wright     center[i] = .5 * domain_size[i];
67a515125bSLeila Ghaffari   PetscInt n = problem->dim;
68*bb8a0c61SJames Wright   ierr = PetscOptionsRealArray("-center", "Location of bubble center", NULL,
69*bb8a0c61SJames Wright                                center, &n, NULL);
70*bb8a0c61SJames Wright   CHKERRQ(ierr);
71a515125bSLeila Ghaffari   n = problem->dim;
72a515125bSLeila Ghaffari   ierr = PetscOptionsRealArray("-dc_axis",
73*bb8a0c61SJames Wright                                "Axis of density current cylindrical anomaly, "
74*bb8a0c61SJames Wright                                "or {0,0,0} for spherically symmetric",
75*bb8a0c61SJames Wright                                NULL, dc_axis, &n, NULL);
76*bb8a0c61SJames Wright   CHKERRQ(ierr);
77a515125bSLeila Ghaffari   {
78a515125bSLeila Ghaffari     PetscReal norm = PetscSqrtReal(PetscSqr(dc_axis[0]) + PetscSqr(dc_axis[1]) +
79a515125bSLeila Ghaffari                                    PetscSqr(dc_axis[2]));
80a515125bSLeila Ghaffari     if (norm > 0) {
81*bb8a0c61SJames Wright       for (int i = 0; i < 3; i++)
82*bb8a0c61SJames Wright         dc_axis[i] /= norm;
83a515125bSLeila Ghaffari     }
84a515125bSLeila Ghaffari   }
85a515125bSLeila Ghaffari 
861485969bSJeremy L Thompson   PetscOptionsEnd();
87a515125bSLeila Ghaffari 
883a8779fbSJames Wright   PetscScalar meter           = user->units->meter;
89*bb8a0c61SJames Wright   PetscScalar second          = user->units->second;
90*bb8a0c61SJames Wright   PetscScalar Kelvin          = user->units->Kelvin;
91*bb8a0c61SJames Wright   PetscScalar Pascal          = user->units->Pascal;
92a515125bSLeila Ghaffari   rc = fabs(rc) * meter;
93*bb8a0c61SJames Wright   theta0 *= Kelvin;
94*bb8a0c61SJames Wright   thetaC *= Kelvin;
95*bb8a0c61SJames Wright   P0 *= Pascal;
96*bb8a0c61SJames Wright   N *= (1. / second);
97*bb8a0c61SJames Wright   for (int i = 0; i < 3; i++)
98*bb8a0c61SJames Wright     center[i] *= meter;
99a515125bSLeila Ghaffari 
100*bb8a0c61SJames Wright   setup_context->theta0 = theta0;
101*bb8a0c61SJames Wright   setup_context->thetaC = thetaC;
102*bb8a0c61SJames Wright   setup_context->P0 = P0;
103*bb8a0c61SJames Wright   setup_context->N = N;
104a515125bSLeila Ghaffari   setup_context->rc = rc;
105a515125bSLeila Ghaffari   setup_context->center[0] = center[0];
106a515125bSLeila Ghaffari   setup_context->center[1] = center[1];
107a515125bSLeila Ghaffari   setup_context->center[2] = center[2];
108a515125bSLeila Ghaffari   setup_context->dc_axis[0] = dc_axis[0];
109a515125bSLeila Ghaffari   setup_context->dc_axis[1] = dc_axis[1];
110a515125bSLeila Ghaffari   setup_context->dc_axis[2] = dc_axis[2];
111a515125bSLeila Ghaffari 
112a515125bSLeila Ghaffari   PetscFunctionReturn(0);
113a515125bSLeila Ghaffari }
114a515125bSLeila Ghaffari 
115ba5420e5SLeila Ghaffari PetscErrorCode SetupContext_DENSITY_CURRENT(Ceed ceed, CeedData ceed_data,
116002797a3SLeila Ghaffari     AppCtx app_ctx, SetupContext setup_ctx, Physics phys) {
117ba5420e5SLeila Ghaffari   PetscFunctionBeginUser;
118*bb8a0c61SJames Wright   PetscInt ierr =
119*bb8a0c61SJames Wright     SetupContext_NEWTONIAN_IG(ceed, ceed_data, app_ctx, setup_ctx, phys);
1203a8779fbSJames Wright   CHKERRQ(ierr);
121a515125bSLeila Ghaffari   PetscFunctionReturn(0);
122a515125bSLeila Ghaffari }
123a515125bSLeila Ghaffari 
124a515125bSLeila Ghaffari PetscErrorCode PRINT_DENSITY_CURRENT(Physics phys, SetupContext setup_ctx,
125a515125bSLeila Ghaffari                                      AppCtx app_ctx) {
126a515125bSLeila Ghaffari   MPI_Comm comm = PETSC_COMM_WORLD;
127a515125bSLeila Ghaffari   PetscErrorCode ierr;
128a515125bSLeila Ghaffari   PetscFunctionBeginUser;
129a515125bSLeila Ghaffari 
130a515125bSLeila Ghaffari   ierr = PetscPrintf(comm,
131a515125bSLeila Ghaffari                      "  Problem:\n"
132a515125bSLeila Ghaffari                      "    Problem Name                       : %s\n"
133a515125bSLeila Ghaffari                      "    Stabilization                      : %s\n",
134a515125bSLeila Ghaffari                      app_ctx->problem_name, StabilizationTypes[phys->stab]);
135a515125bSLeila Ghaffari   CHKERRQ(ierr);
136a515125bSLeila Ghaffari 
137a515125bSLeila Ghaffari   PetscFunctionReturn(0);
138a515125bSLeila Ghaffari }
139