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 EULER_VORTEX 19 20 #include "../navierstokes.h" 21 #include "../qfunctions/setupgeo.h" 22 #include "../qfunctions/eulervortex.h" 23 24 PetscErrorCode NS_EULER_VORTEX(ProblemData *problem, void *setup_ctx, 25 void *ctx) { 26 EulerTestType euler_test; 27 SetupContext setup_context = *(SetupContext *)setup_ctx; 28 User user = *(User *)ctx; 29 MPI_Comm comm = PETSC_COMM_WORLD; 30 PetscBool implicit; 31 PetscBool has_curr_time = PETSC_TRUE; 32 PetscBool has_neumann = PETSC_TRUE; 33 PetscInt ierr; 34 PetscFunctionBeginUser; 35 36 ierr = PetscCalloc1(1, &user->phys->euler_ctx); CHKERRQ(ierr); 37 38 // ------------------------------------------------------ 39 // SET UP DENSITY_CURRENT 40 // ------------------------------------------------------ 41 problem->dim = 3; 42 problem->q_data_size_vol = 10; 43 problem->q_data_size_sur = 4; 44 problem->setup_vol = Setup; 45 problem->setup_vol_loc = Setup_loc; 46 problem->setup_sur = SetupBoundary; 47 problem->setup_sur_loc = SetupBoundary_loc; 48 problem->ics = ICsEuler; 49 problem->ics_loc = ICsEuler_loc; 50 problem->apply_vol_rhs = Euler; 51 problem->apply_vol_rhs_loc = Euler_loc; 52 problem->apply_vol_ifunction = IFunction_Euler; 53 problem->apply_vol_ifunction_loc = IFunction_Euler_loc; 54 problem->apply_sur = Euler_Sur; 55 problem->apply_sur_loc = Euler_Sur_loc; 56 problem->bc = Exact_Euler; 57 problem->bc_func = BC_EULER_VORTEX; 58 problem->non_zero_time = PETSC_TRUE; 59 problem->print_info = PRINT_EULER_VORTEX; 60 61 // ------------------------------------------------------ 62 // Create the libCEED context 63 // ------------------------------------------------------ 64 CeedScalar vortex_strength = 5.; // - 65 PetscScalar lx = 1000.; // m 66 PetscScalar ly = 1000.; // m 67 PetscScalar lz = 1.; // m 68 PetscReal center[3], mean_velocity[3] = {1., 1., 0}; 69 70 // ------------------------------------------------------ 71 // Create the PETSc context 72 // ------------------------------------------------------ 73 PetscScalar meter = 1e-2; // 1 meter in scaled length units 74 PetscScalar second = 1e-2; // 1 second in scaled time units 75 76 // ------------------------------------------------------ 77 // Command line Options 78 // ------------------------------------------------------ 79 ierr = PetscOptionsBegin(comm, NULL, "Options for EULER_VORTEX problem", 80 NULL); CHKERRQ(ierr); 81 // -- Physics 82 ierr = PetscOptionsScalar("-vortex_strength", "Strength of Vortex", 83 NULL, vortex_strength, &vortex_strength, NULL); 84 CHKERRQ(ierr); 85 PetscInt n = problem->dim; 86 PetscBool user_velocity; 87 ierr = PetscOptionsRealArray("-mean_velocity", "Background velocity vector", 88 NULL, mean_velocity, &n, &user_velocity); 89 CHKERRQ(ierr); 90 ierr = PetscOptionsScalar("-lx", "Length scale in x direction", 91 NULL, lx, &lx, NULL); CHKERRQ(ierr); 92 ierr = PetscOptionsScalar("-ly", "Length scale in y direction", 93 NULL, ly, &ly, NULL); CHKERRQ(ierr); 94 ierr = PetscOptionsScalar("-lz", "Length scale in z direction", 95 NULL, lz, &lz, NULL); CHKERRQ(ierr); 96 n = problem->dim; 97 center[0] = 0.5 * lx; 98 center[1] = 0.5 * ly; 99 center[2] = 0.5 * lz; 100 ierr = PetscOptionsRealArray("-center", "Location of vortex center", 101 NULL, center, &n, NULL); CHKERRQ(ierr); 102 ierr = PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", 103 NULL, implicit=PETSC_FALSE, &implicit, NULL); 104 CHKERRQ(ierr); 105 ierr = PetscOptionsEnum("-euler_test", "Euler test option", NULL, 106 EulerTestTypes, (PetscEnum)(euler_test = EULER_TEST_NONE), 107 (PetscEnum *)&euler_test, NULL); CHKERRQ(ierr); 108 109 // -- Units 110 ierr = PetscOptionsScalar("-units_meter", "1 meter in scaled length units", 111 NULL, meter, &meter, NULL); CHKERRQ(ierr); 112 meter = fabs(meter); 113 ierr = PetscOptionsScalar("-units_second","1 second in scaled time units", 114 NULL, second, &second, NULL); CHKERRQ(ierr); 115 second = fabs(second); 116 117 // -- Warnings 118 if (user_velocity && (euler_test == EULER_TEST_1 119 || euler_test == EULER_TEST_3)) { 120 ierr = PetscPrintf(comm, 121 "Warning! Background velocity vector for -euler_test t1 and -euler_test t3 is (0,0,0)\n"); 122 CHKERRQ(ierr); 123 } 124 125 ierr = PetscOptionsEnd(); CHKERRQ(ierr); 126 127 // ------------------------------------------------------ 128 // Set up the PETSc context 129 // ------------------------------------------------------ 130 user->units->meter = meter; 131 user->units->second = second; 132 133 // ------------------------------------------------------ 134 // Set up the libCEED context 135 // ------------------------------------------------------ 136 // -- Scale variables to desired units 137 lx = fabs(lx) * meter; 138 ly = fabs(ly) * meter; 139 lz = fabs(lz) * meter; 140 for (int i=0; i<3; i++) center[i] *= meter; 141 142 // -- Setup Context 143 setup_context->lx = lx; 144 setup_context->ly = ly; 145 setup_context->lz = lz; 146 setup_context->center[0] = center[0]; 147 setup_context->center[1] = center[1]; 148 setup_context->center[2] = center[2]; 149 setup_context->time = 0; 150 151 // -- QFunction Context 152 user->phys->euler_test = euler_test; 153 user->phys->implicit = implicit; 154 user->phys->has_curr_time = has_curr_time; 155 user->phys->has_neumann = has_neumann; 156 user->phys->euler_ctx->curr_time = 0.; 157 user->phys->euler_ctx->implicit = implicit; 158 user->phys->euler_ctx->euler_test = euler_test; 159 user->phys->euler_ctx->center[0] = center[0]; 160 user->phys->euler_ctx->center[1] = center[1]; 161 user->phys->euler_ctx->center[2] = center[2]; 162 user->phys->euler_ctx->vortex_strength = vortex_strength; 163 user->phys->euler_ctx->mean_velocity[0] = mean_velocity[0]; 164 user->phys->euler_ctx->mean_velocity[1] = mean_velocity[1]; 165 user->phys->euler_ctx->mean_velocity[2] = mean_velocity[2]; 166 167 PetscFunctionReturn(0); 168 } 169 170 PetscErrorCode BC_EULER_VORTEX(DM dm, SimpleBC bc, Physics phys, 171 void *setup_ctx) { 172 PetscErrorCode ierr; 173 PetscFunctionBeginUser; 174 175 // Define boundary conditions 176 bc->num_slip[2] = 2; bc->slips[2][0] = 1; bc->slips[2][1] = 2; 177 178 // Set boundary conditions 179 DMLabel label; 180 ierr = DMGetLabel(dm, "Face Sets", &label); CHKERRQ(ierr); 181 PetscInt comps[1] = {3}; 182 ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "slipz", label, "Face Sets", 183 bc->num_slip[2], bc->slips[2], 0, 1, comps, 184 (void(*)(void))NULL, NULL, setup_ctx, NULL); 185 CHKERRQ(ierr); 186 187 PetscFunctionReturn(0); 188 } 189 190 PetscErrorCode PRINT_EULER_VORTEX(Physics phys, SetupContext setup_ctx, 191 AppCtx app_ctx) { 192 MPI_Comm comm = PETSC_COMM_WORLD; 193 PetscErrorCode ierr; 194 PetscFunctionBeginUser; 195 196 ierr = PetscPrintf(comm, 197 " Problem:\n" 198 " Problem Name : %s\n" 199 " Test Case : %s\n" 200 " Background Velocity : %f,%f\n", 201 app_ctx->problem_name, EulerTestTypes[phys->euler_test], 202 phys->euler_ctx->mean_velocity[0], 203 phys->euler_ctx->mean_velocity[1]); CHKERRQ(ierr); 204 205 PetscFunctionReturn(0); 206 } 207