xref: /honee/problems/densitycurrent.c (revision 9785fe939f22dc29a5e9bc719da8d1f0a67d7249)
1bb8a0c61SJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other
2bb8a0c61SJames Wright // CEED contributors. All Rights Reserved. See the top-level LICENSE and NOTICE
3bb8a0c61SJames 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"
13bb8a0c61SJames 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;
19bb8a0c61SJames Wright   ierr = NS_NEWTONIAN_IG(problem, dm, setup_ctx, ctx);
20bb8a0c61SJames 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   // ------------------------------------------------------
29*9785fe93SJed Brown   problem->ics.qfunction = ICsDC;
30*9785fe93SJed Brown   problem->ics.qfunction_loc = ICsDC_loc;
31a515125bSLeila Ghaffari   problem->bc = Exact_DC;
32a515125bSLeila Ghaffari 
33a515125bSLeila Ghaffari   // ------------------------------------------------------
34a515125bSLeila Ghaffari   //             Create the libCEED context
35a515125bSLeila Ghaffari   // ------------------------------------------------------
36bb8a0c61SJames Wright   CeedScalar theta0 = 300.; // K
37bb8a0c61SJames Wright   CeedScalar thetaC = -15.; // K
38bb8a0c61SJames Wright   CeedScalar P0 = 1.e5;     // Pa
39bb8a0c61SJames 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];
43bb8a0c61SJames Wright   ierr = DMGetBoundingBox(dm, domain_min, domain_max);
44bb8a0c61SJames Wright   CHKERRQ(ierr);
45bb8a0c61SJames Wright   for (int i = 0; i < 3; i++)
46bb8a0c61SJames 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);
52bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-theta0", "Reference potential temperature", NULL,
53bb8a0c61SJames Wright                             theta0, &theta0, NULL);
54bb8a0c61SJames Wright   CHKERRQ(ierr);
55bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-thetaC", "Perturbation of potential temperature",
56bb8a0c61SJames Wright                             NULL, thetaC, &thetaC, NULL);
57bb8a0c61SJames Wright   CHKERRQ(ierr);
58bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-P0", "Atmospheric pressure", NULL, P0, &P0, NULL);
59bb8a0c61SJames Wright   CHKERRQ(ierr);
60bb8a0c61SJames Wright   ierr = PetscOptionsScalar("-N", "Brunt-Vaisala frequency", NULL, N, &N, NULL);
61bb8a0c61SJames Wright   CHKERRQ(ierr);
62a515125bSLeila Ghaffari   ierr = PetscOptionsScalar("-rc", "Characteristic radius of thermal bubble",
63bb8a0c61SJames Wright                             NULL, rc, &rc, NULL);
64bb8a0c61SJames Wright   CHKERRQ(ierr);
65bb8a0c61SJames Wright   for (int i = 0; i < 3; i++)
66bb8a0c61SJames Wright     center[i] = .5 * domain_size[i];
67a515125bSLeila Ghaffari   PetscInt n = problem->dim;
68bb8a0c61SJames Wright   ierr = PetscOptionsRealArray("-center", "Location of bubble center", NULL,
69bb8a0c61SJames Wright                                center, &n, NULL);
70bb8a0c61SJames Wright   CHKERRQ(ierr);
71a515125bSLeila Ghaffari   n = problem->dim;
72a515125bSLeila Ghaffari   ierr = PetscOptionsRealArray("-dc_axis",
73bb8a0c61SJames Wright                                "Axis of density current cylindrical anomaly, "
74bb8a0c61SJames Wright                                "or {0,0,0} for spherically symmetric",
75bb8a0c61SJames Wright                                NULL, dc_axis, &n, NULL);
76bb8a0c61SJames 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) {
81bb8a0c61SJames Wright       for (int i = 0; i < 3; i++)
82bb8a0c61SJames Wright         dc_axis[i] /= norm;
83a515125bSLeila Ghaffari     }
84a515125bSLeila Ghaffari   }
85a515125bSLeila Ghaffari 
861485969bSJeremy L Thompson   PetscOptionsEnd();
87a515125bSLeila Ghaffari 
883a8779fbSJames Wright   PetscScalar meter           = user->units->meter;
89bb8a0c61SJames Wright   PetscScalar second          = user->units->second;
90bb8a0c61SJames Wright   PetscScalar Kelvin          = user->units->Kelvin;
91bb8a0c61SJames Wright   PetscScalar Pascal          = user->units->Pascal;
92a515125bSLeila Ghaffari   rc = fabs(rc) * meter;
93bb8a0c61SJames Wright   theta0 *= Kelvin;
94bb8a0c61SJames Wright   thetaC *= Kelvin;
95bb8a0c61SJames Wright   P0 *= Pascal;
96bb8a0c61SJames Wright   N *= (1. / second);
97bb8a0c61SJames Wright   for (int i = 0; i < 3; i++)
98bb8a0c61SJames Wright     center[i] *= meter;
99a515125bSLeila Ghaffari 
100bb8a0c61SJames Wright   setup_context->theta0 = theta0;
101bb8a0c61SJames Wright   setup_context->thetaC = thetaC;
102bb8a0c61SJames Wright   setup_context->P0 = P0;
103bb8a0c61SJames 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;
118bb8a0c61SJames Wright   PetscInt ierr =
119bb8a0c61SJames 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