xref: /libCEED/examples/fluids/problems/densitycurrent.c (revision 88626eed6564cd43033d3137230605fb5f962840)
1*88626eedSJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other
2*88626eedSJames Wright // CEED contributors. All Rights Reserved. See the top-level LICENSE and NOTICE
3*88626eedSJames Wright // files for details.
477841947SLeila Ghaffari //
53d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
677841947SLeila Ghaffari //
73d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
877841947SLeila Ghaffari 
977841947SLeila Ghaffari /// @file
1077841947SLeila Ghaffari /// Utility functions for setting up DENSITY_CURRENT
1177841947SLeila Ghaffari 
1277841947SLeila Ghaffari #include "../qfunctions/densitycurrent.h"
13*88626eedSJames Wright #include "../navierstokes.h"
1477841947SLeila Ghaffari 
151864f1c2SLeila Ghaffari PetscErrorCode NS_DENSITY_CURRENT(ProblemData *problem, DM dm, void *setup_ctx,
1677841947SLeila Ghaffari                                   void *ctx) {
1788b783a1SJames Wright 
1888b783a1SJames Wright   PetscInt ierr;
19*88626eedSJames Wright   ierr = NS_NEWTONIAN_IG(problem, dm, setup_ctx, ctx);
20*88626eedSJames Wright   CHKERRQ(ierr);
2177841947SLeila Ghaffari   SetupContext setup_context = *(SetupContext *)setup_ctx;
2277841947SLeila Ghaffari   User user = *(User *)ctx;
2377841947SLeila Ghaffari   MPI_Comm comm = PETSC_COMM_WORLD;
2477841947SLeila Ghaffari   PetscFunctionBeginUser;
2577841947SLeila Ghaffari 
2677841947SLeila Ghaffari   // ------------------------------------------------------
2777841947SLeila Ghaffari   //               SET UP DENSITY_CURRENT
2877841947SLeila Ghaffari   // ------------------------------------------------------
2977841947SLeila Ghaffari   problem->ics = ICsDC;
3077841947SLeila Ghaffari   problem->ics_loc = ICsDC_loc;
3177841947SLeila Ghaffari   problem->bc = Exact_DC;
3277841947SLeila Ghaffari 
3377841947SLeila Ghaffari   // ------------------------------------------------------
3477841947SLeila Ghaffari   //             Create the libCEED context
3577841947SLeila Ghaffari   // ------------------------------------------------------
36*88626eedSJames Wright   CeedScalar theta0 = 300.; // K
37*88626eedSJames Wright   CeedScalar thetaC = -15.; // K
38*88626eedSJames Wright   CeedScalar P0 = 1.e5;     // Pa
39*88626eedSJames Wright   CeedScalar N = 0.01;      // 1/s
4077841947SLeila Ghaffari   CeedScalar rc = 1000.;    // m (Radius of bubble)
4177841947SLeila Ghaffari   PetscReal center[3], dc_axis[3] = {0, 0, 0};
421864f1c2SLeila Ghaffari   PetscReal domain_min[3], domain_max[3], domain_size[3];
43*88626eedSJames Wright   ierr = DMGetBoundingBox(dm, domain_min, domain_max);
44*88626eedSJames Wright   CHKERRQ(ierr);
45*88626eedSJames Wright   for (int i = 0; i < 3; i++)
46*88626eedSJames Wright     domain_size[i] = domain_max[i] - domain_min[i];
4777841947SLeila Ghaffari 
4877841947SLeila Ghaffari   // ------------------------------------------------------
4977841947SLeila Ghaffari   //              Command line Options
5077841947SLeila Ghaffari   // ------------------------------------------------------
5167490bc6SJeremy L Thompson   PetscOptionsBegin(comm, NULL, "Options for DENSITY_CURRENT problem", NULL);
52*88626eedSJames Wright   ierr = PetscOptionsScalar("-theta0", "Reference potential temperature", NULL,
53*88626eedSJames Wright                             theta0, &theta0, NULL);
54*88626eedSJames Wright   CHKERRQ(ierr);
55*88626eedSJames Wright   ierr = PetscOptionsScalar("-thetaC", "Perturbation of potential temperature",
56*88626eedSJames Wright                             NULL, thetaC, &thetaC, NULL);
57*88626eedSJames Wright   CHKERRQ(ierr);
58*88626eedSJames Wright   ierr = PetscOptionsScalar("-P0", "Atmospheric pressure", NULL, P0, &P0, NULL);
59*88626eedSJames Wright   CHKERRQ(ierr);
60*88626eedSJames Wright   ierr = PetscOptionsScalar("-N", "Brunt-Vaisala frequency", NULL, N, &N, NULL);
61*88626eedSJames Wright   CHKERRQ(ierr);
6277841947SLeila Ghaffari   ierr = PetscOptionsScalar("-rc", "Characteristic radius of thermal bubble",
63*88626eedSJames Wright                             NULL, rc, &rc, NULL);
64*88626eedSJames Wright   CHKERRQ(ierr);
65*88626eedSJames Wright   for (int i = 0; i < 3; i++)
66*88626eedSJames Wright     center[i] = .5 * domain_size[i];
6777841947SLeila Ghaffari   PetscInt n = problem->dim;
68*88626eedSJames Wright   ierr = PetscOptionsRealArray("-center", "Location of bubble center", NULL,
69*88626eedSJames Wright                                center, &n, NULL);
70*88626eedSJames Wright   CHKERRQ(ierr);
7177841947SLeila Ghaffari   n = problem->dim;
7277841947SLeila Ghaffari   ierr = PetscOptionsRealArray("-dc_axis",
73*88626eedSJames Wright                                "Axis of density current cylindrical anomaly, "
74*88626eedSJames Wright                                "or {0,0,0} for spherically symmetric",
75*88626eedSJames Wright                                NULL, dc_axis, &n, NULL);
76*88626eedSJames Wright   CHKERRQ(ierr);
7777841947SLeila Ghaffari   {
7877841947SLeila Ghaffari     PetscReal norm = PetscSqrtReal(PetscSqr(dc_axis[0]) + PetscSqr(dc_axis[1]) +
7977841947SLeila Ghaffari                                    PetscSqr(dc_axis[2]));
8077841947SLeila Ghaffari     if (norm > 0) {
81*88626eedSJames Wright       for (int i = 0; i < 3; i++)
82*88626eedSJames Wright         dc_axis[i] /= norm;
8377841947SLeila Ghaffari     }
8477841947SLeila Ghaffari   }
8577841947SLeila Ghaffari 
8667490bc6SJeremy L Thompson   PetscOptionsEnd();
8777841947SLeila Ghaffari 
8888b783a1SJames Wright   PetscScalar meter           = user->units->meter;
89*88626eedSJames Wright   PetscScalar second          = user->units->second;
90*88626eedSJames Wright   PetscScalar Kelvin          = user->units->Kelvin;
91*88626eedSJames Wright   PetscScalar Pascal          = user->units->Pascal;
9277841947SLeila Ghaffari   rc = fabs(rc) * meter;
93*88626eedSJames Wright   theta0 *= Kelvin;
94*88626eedSJames Wright   thetaC *= Kelvin;
95*88626eedSJames Wright   P0 *= Pascal;
96*88626eedSJames Wright   N *= (1. / second);
97*88626eedSJames Wright   for (int i = 0; i < 3; i++)
98*88626eedSJames Wright     center[i] *= meter;
9977841947SLeila Ghaffari 
100*88626eedSJames Wright   setup_context->theta0 = theta0;
101*88626eedSJames Wright   setup_context->thetaC = thetaC;
102*88626eedSJames Wright   setup_context->P0 = P0;
103*88626eedSJames Wright   setup_context->N = N;
10477841947SLeila Ghaffari   setup_context->rc = rc;
10577841947SLeila Ghaffari   setup_context->center[0] = center[0];
10677841947SLeila Ghaffari   setup_context->center[1] = center[1];
10777841947SLeila Ghaffari   setup_context->center[2] = center[2];
10877841947SLeila Ghaffari   setup_context->dc_axis[0] = dc_axis[0];
10977841947SLeila Ghaffari   setup_context->dc_axis[1] = dc_axis[1];
11077841947SLeila Ghaffari   setup_context->dc_axis[2] = dc_axis[2];
11177841947SLeila Ghaffari 
11277841947SLeila Ghaffari   PetscFunctionReturn(0);
11377841947SLeila Ghaffari }
11477841947SLeila Ghaffari 
115d0b732dbSLeila Ghaffari PetscErrorCode SetupContext_DENSITY_CURRENT(Ceed ceed, CeedData ceed_data,
1162fe7aee7SLeila Ghaffari     AppCtx app_ctx, SetupContext setup_ctx, Physics phys) {
117d0b732dbSLeila Ghaffari   PetscFunctionBeginUser;
118*88626eedSJames Wright   PetscInt ierr =
119*88626eedSJames Wright     SetupContext_NEWTONIAN_IG(ceed, ceed_data, app_ctx, setup_ctx, phys);
12088b783a1SJames Wright   CHKERRQ(ierr);
12177841947SLeila Ghaffari   PetscFunctionReturn(0);
12277841947SLeila Ghaffari }
12377841947SLeila Ghaffari 
12477841947SLeila Ghaffari PetscErrorCode PRINT_DENSITY_CURRENT(Physics phys, SetupContext setup_ctx,
12577841947SLeila Ghaffari                                      AppCtx app_ctx) {
12677841947SLeila Ghaffari   MPI_Comm comm = PETSC_COMM_WORLD;
12777841947SLeila Ghaffari   PetscErrorCode ierr;
12877841947SLeila Ghaffari   PetscFunctionBeginUser;
12977841947SLeila Ghaffari 
13077841947SLeila Ghaffari   ierr = PetscPrintf(comm,
13177841947SLeila Ghaffari                      "  Problem:\n"
13277841947SLeila Ghaffari                      "    Problem Name                       : %s\n"
13377841947SLeila Ghaffari                      "    Stabilization                      : %s\n",
13477841947SLeila Ghaffari                      app_ctx->problem_name, StabilizationTypes[phys->stab]);
13577841947SLeila Ghaffari   CHKERRQ(ierr);
13677841947SLeila Ghaffari 
13777841947SLeila Ghaffari   PetscFunctionReturn(0);
13877841947SLeila Ghaffari }
139