xref: /libCEED/examples/fluids/problems/densitycurrent.c (revision 88b783a108a0e7f73f6a4b1c66ee7b6d1a268995)
1 // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3 // reserved. See files LICENSE and NOTICE for details.
4 //
5 // This file is part of CEED, a collection of benchmarks, miniapps, software
6 // libraries and APIs for efficient high-order finite element and spectral
7 // element discretizations for exascale applications. For more information and
8 // source code availability see http://github.com/ceed.
9 //
10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11 // a collaborative effort of two U.S. Department of Energy organizations (Office
12 // of Science and the National Nuclear Security Administration) responsible for
13 // the planning and preparation of a capable exascale ecosystem, including
14 // software, applications, hardware, advanced system engineering and early
15 // testbed platforms, in support of the nation's exascale computing imperative.
16 
17 /// @file
18 /// Utility functions for setting up DENSITY_CURRENT
19 
20 #include "../navierstokes.h"
21 #include "../qfunctions/densitycurrent.h"
22 
23 PetscErrorCode NS_DENSITY_CURRENT(ProblemData *problem, DM dm, void *setup_ctx,
24                                   void *ctx) {
25 
26   PetscInt ierr;
27   ierr = NS_NEWTONIAN_IG(problem, dm, setup_ctx, ctx); CHKERRQ(ierr);
28   SetupContext setup_context = *(SetupContext *)setup_ctx;
29   User         user          = *(User *)ctx;
30   MPI_Comm     comm          = PETSC_COMM_WORLD;
31   PetscFunctionBeginUser;
32 
33   // ------------------------------------------------------
34   //               SET UP DENSITY_CURRENT
35   // ------------------------------------------------------
36   problem->ics     = ICsDC;
37   problem->ics_loc = ICsDC_loc;
38   problem->bc      = Exact_DC;
39 
40   // ------------------------------------------------------
41   //             Create the libCEED context
42   // ------------------------------------------------------
43   CeedScalar rc     = 1000.;   // m (Radius of bubble)
44   PetscReal center[3], dc_axis[3] = {0, 0, 0};
45   PetscReal domain_min[3], domain_max[3], domain_size[3];
46   ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr);
47   for (int i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i];
48 
49   // ------------------------------------------------------
50   //              Command line Options
51   // ------------------------------------------------------
52   ierr = PetscOptionsBegin(comm, NULL, "Options for DENSITY_CURRENT problem",
53                            NULL); CHKERRQ(ierr);
54   ierr = PetscOptionsScalar("-rc", "Characteristic radius of thermal bubble",
55                             NULL, rc, &rc, NULL); CHKERRQ(ierr);
56   for (int i=0; i<3; i++) center[i] = .5*domain_size[i];
57   PetscInt n = problem->dim;
58   ierr = PetscOptionsRealArray("-center", "Location of bubble center",
59                                NULL, center, &n, NULL); CHKERRQ(ierr);
60   n = problem->dim;
61   ierr = PetscOptionsRealArray("-dc_axis",
62                                "Axis of density current cylindrical anomaly, or {0,0,0} for spherically symmetric",
63                                NULL, dc_axis, &n, NULL); CHKERRQ(ierr);
64   {
65     PetscReal norm = PetscSqrtReal(PetscSqr(dc_axis[0]) + PetscSqr(dc_axis[1]) +
66                                    PetscSqr(dc_axis[2]));
67     if (norm > 0) {
68       for (int i=0; i<3; i++)  dc_axis[i] /= norm;
69     }
70   }
71 
72   ierr = PetscOptionsEnd(); CHKERRQ(ierr);
73 
74   PetscScalar meter = user->units->meter;
75   rc = fabs(rc) * meter;
76   for (int i=0; i<3; i++) center[i] *= meter;
77 
78   setup_context->rc         = rc;
79   setup_context->center[0]  = center[0];
80   setup_context->center[1]  = center[1];
81   setup_context->center[2]  = center[2];
82   setup_context->dc_axis[0] = dc_axis[0];
83   setup_context->dc_axis[1] = dc_axis[1];
84   setup_context->dc_axis[2] = dc_axis[2];
85 
86   PetscFunctionReturn(0);
87 }
88 
89 PetscErrorCode SetupContext_DENSITY_CURRENT(Ceed ceed, CeedData ceed_data,
90     AppCtx app_ctx, SetupContext setup_ctx, Physics phys) {
91   PetscFunctionBeginUser;
92   PetscInt ierr = SetupContext_NEWTONIAN_IG(ceed, ceed_data, app_ctx, setup_ctx,
93                   phys);
94   CHKERRQ(ierr);
95   PetscFunctionReturn(0);
96 }
97 
98 PetscErrorCode PRINT_DENSITY_CURRENT(Physics phys, SetupContext setup_ctx,
99                                      AppCtx app_ctx) {
100   MPI_Comm       comm = PETSC_COMM_WORLD;
101   PetscErrorCode ierr;
102   PetscFunctionBeginUser;
103 
104   ierr = PetscPrintf(comm,
105                      "  Problem:\n"
106                      "    Problem Name                       : %s\n"
107                      "    Stabilization                      : %s\n",
108                      app_ctx->problem_name, StabilizationTypes[phys->stab]);
109   CHKERRQ(ierr);
110 
111   PetscFunctionReturn(0);
112 }
113