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 ADVECTION 19 20 #include "../navierstokes.h" 21 #include "../qfunctions/setupgeo.h" 22 #include "../qfunctions/advection.h" 23 24 PetscErrorCode NS_ADVECTION(ProblemData *problem, void *setup_ctx, void *ctx) { 25 WindType wind_type; 26 BubbleType bubble_type; 27 BubbleContinuityType bubble_continuity_type; 28 StabilizationType stab; 29 SetupContext setup_context = *(SetupContext *)setup_ctx; 30 User user = *(User *)ctx; 31 MPI_Comm comm = PETSC_COMM_WORLD; 32 PetscBool implicit; 33 PetscBool has_curr_time = PETSC_FALSE; 34 PetscInt ierr; 35 PetscFunctionBeginUser; 36 37 ierr = PetscCalloc1(1, &user->phys->advection_ctx); CHKERRQ(ierr); 38 39 // ------------------------------------------------------ 40 // SET UP ADVECTION 41 // ------------------------------------------------------ 42 problem->dim = 3; 43 problem->q_data_size_vol = 10; 44 problem->q_data_size_sur = 4; 45 problem->setup_vol = Setup; 46 problem->setup_vol_loc = Setup_loc; 47 problem->setup_sur = SetupBoundary; 48 problem->setup_sur_loc = SetupBoundary_loc; 49 problem->ics = ICsAdvection; 50 problem->ics_loc = ICsAdvection_loc; 51 problem->apply_vol_rhs = Advection; 52 problem->apply_vol_rhs_loc = Advection_loc; 53 problem->apply_vol_ifunction = IFunction_Advection; 54 problem->apply_vol_ifunction_loc = IFunction_Advection_loc; 55 problem->apply_sur = Advection_Sur; 56 problem->apply_sur_loc = Advection_Sur_loc; 57 problem->bc = Exact_Advection; 58 problem->setup_ctx = SetupContext_ADVECTION; 59 problem->bc_func = BC_ADVECTION; 60 problem->non_zero_time = PETSC_FALSE; 61 problem->print_info = PRINT_ADVECTION; 62 63 // ------------------------------------------------------ 64 // Create the libCEED context 65 // ------------------------------------------------------ 66 PetscScalar lx = 8000.; // m 67 PetscScalar ly = 8000.; // m 68 PetscScalar lz = 4000.; // m 69 CeedScalar rc = 1000.; // m (Radius of bubble) 70 CeedScalar CtauS = 0.; // dimensionless 71 CeedScalar strong_form = 0.; // [0,1] 72 CeedScalar E_wind = 1.e6; // J 73 PetscReal wind[3] = {1., 0, 0}; // m/s 74 75 // ------------------------------------------------------ 76 // Create the PETSc context 77 // ------------------------------------------------------ 78 PetscScalar meter = 1e-2; // 1 meter in scaled length units 79 PetscScalar kilogram = 1e-6; // 1 kilogram in scaled mass units 80 PetscScalar second = 1e-2; // 1 second in scaled time units 81 PetscScalar Joule; 82 83 // ------------------------------------------------------ 84 // Command line Options 85 // ------------------------------------------------------ 86 ierr = PetscOptionsBegin(comm, NULL, "Options for ADVECTION problem", 87 NULL); CHKERRQ(ierr); 88 // -- Physics 89 ierr = PetscOptionsScalar("-lx", "Length scale in x direction", 90 NULL, lx, &lx, NULL); CHKERRQ(ierr); 91 ierr = PetscOptionsScalar("-ly", "Length scale in y direction", 92 NULL, ly, &ly, NULL); CHKERRQ(ierr); 93 ierr = PetscOptionsScalar("-lz", "Length scale in z direction", 94 NULL, lz, &lz, NULL); CHKERRQ(ierr); 95 ierr = PetscOptionsScalar("-rc", "Characteristic radius of thermal bubble", 96 NULL, rc, &rc, NULL); CHKERRQ(ierr); 97 PetscBool translation; 98 ierr = PetscOptionsEnum("-wind_type", "Wind type in Advection", 99 NULL, WindTypes, 100 (PetscEnum)(wind_type = WIND_ROTATION), 101 (PetscEnum *)&wind_type, &translation); CHKERRQ(ierr); 102 if (translation) user->phys->has_neumann = PETSC_TRUE; 103 PetscInt n = problem->dim; 104 PetscBool user_wind; 105 ierr = PetscOptionsRealArray("-wind_translation", "Constant wind vector", 106 NULL, wind, &n, &user_wind); CHKERRQ(ierr); 107 ierr = PetscOptionsScalar("-CtauS", 108 "Scale coefficient for tau (nondimensional)", 109 NULL, CtauS, &CtauS, NULL); CHKERRQ(ierr); 110 ierr = PetscOptionsScalar("-strong_form", 111 "Strong (1) or weak/integrated by parts (0) advection residual", 112 NULL, strong_form, &strong_form, NULL); CHKERRQ(ierr); 113 ierr = PetscOptionsScalar("-E_wind", "Total energy of inflow wind", 114 NULL, E_wind, &E_wind, NULL); CHKERRQ(ierr); 115 ierr = PetscOptionsEnum("-bubble_type", "Sphere (3D) or cylinder (2D)", 116 NULL, BubbleTypes, 117 (PetscEnum)(bubble_type = BUBBLE_SPHERE), 118 (PetscEnum *)&bubble_type, NULL); CHKERRQ(ierr); 119 ierr = PetscOptionsEnum("-bubble_continuity", "Smooth, back_sharp, or thick", 120 NULL, BubbleContinuityTypes, 121 (PetscEnum)(bubble_continuity_type = BUBBLE_CONTINUITY_SMOOTH), 122 (PetscEnum *)&bubble_continuity_type, NULL); CHKERRQ(ierr); 123 ierr = PetscOptionsEnum("-stab", "Stabilization method", NULL, 124 StabilizationTypes, (PetscEnum)(stab = STAB_NONE), 125 (PetscEnum *)&stab, NULL); CHKERRQ(ierr); 126 ierr = PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", 127 NULL, implicit=PETSC_FALSE, &implicit, NULL); 128 CHKERRQ(ierr); 129 130 // -- Units 131 ierr = PetscOptionsScalar("-units_meter", "1 meter in scaled length units", 132 NULL, meter, &meter, NULL); CHKERRQ(ierr); 133 meter = fabs(meter); 134 ierr = PetscOptionsScalar("-units_kilogram","1 kilogram in scaled mass units", 135 NULL, kilogram, &kilogram, NULL); CHKERRQ(ierr); 136 kilogram = fabs(kilogram); 137 ierr = PetscOptionsScalar("-units_second","1 second in scaled time units", 138 NULL, second, &second, NULL); CHKERRQ(ierr); 139 second = fabs(second); 140 141 // -- Warnings 142 if (wind_type == WIND_ROTATION && user_wind) { 143 ierr = PetscPrintf(comm, 144 "Warning! Use -wind_translation only with -wind_type translation\n"); 145 CHKERRQ(ierr); 146 } 147 if (wind_type == WIND_TRANSLATION 148 && bubble_type == BUBBLE_CYLINDER && wind[2] != 0.) { 149 wind[2] = 0; 150 ierr = PetscPrintf(comm, 151 "Warning! Background wind in the z direction should be zero (-wind_translation x,x,0) with -bubble_type cylinder\n"); 152 CHKERRQ(ierr); 153 } 154 if (stab == STAB_NONE && CtauS != 0) { 155 ierr = PetscPrintf(comm, 156 "Warning! Use -CtauS only with -stab su or -stab supg\n"); 157 CHKERRQ(ierr); 158 } 159 if (stab == STAB_SUPG && !implicit) { 160 ierr = PetscPrintf(comm, 161 "Warning! Use -stab supg only with -implicit\n"); 162 CHKERRQ(ierr); 163 } 164 165 ierr = PetscOptionsEnd(); CHKERRQ(ierr); 166 167 // ------------------------------------------------------ 168 // Set up the PETSc context 169 // ------------------------------------------------------ 170 // -- Define derived units 171 Joule = kilogram * PetscSqr(meter) / PetscSqr(second); 172 173 user->units->meter = meter; 174 user->units->kilogram = kilogram; 175 user->units->second = second; 176 user->units->Joule = Joule; 177 178 // ------------------------------------------------------ 179 // Set up the libCEED context 180 // ------------------------------------------------------ 181 // -- Scale variables to desired units 182 E_wind *= Joule; 183 lx = fabs(lx) * meter; 184 ly = fabs(ly) * meter; 185 lz = fabs(lz) * meter; 186 rc = fabs(rc) * meter; 187 for (int i=0; i<3; i++) wind[i] = wind[i] * (meter/second); 188 189 // -- Setup Context 190 setup_context->rc = rc; 191 setup_context->lx = lx; 192 setup_context->ly = ly; 193 setup_context->lz = lz; 194 setup_context->wind[0] = wind[0]; 195 setup_context->wind[1] = wind[1]; 196 setup_context->wind[2] = wind[2]; 197 setup_context->wind_type = wind_type; 198 setup_context->bubble_type = bubble_type; 199 setup_context->bubble_continuity_type = bubble_continuity_type; 200 setup_context->time = 0; 201 202 // -- QFunction Context 203 user->phys->stab = stab; 204 user->phys->wind_type = wind_type; 205 user->phys->bubble_type = bubble_type; 206 user->phys->bubble_continuity_type = bubble_continuity_type; 207 // if passed correctly 208 user->phys->implicit = implicit; 209 user->phys->has_curr_time = has_curr_time; 210 user->phys->advection_ctx->CtauS = CtauS; 211 user->phys->advection_ctx->E_wind = E_wind; 212 user->phys->advection_ctx->implicit = implicit; 213 user->phys->advection_ctx->strong_form = strong_form; 214 user->phys->advection_ctx->stabilization = stab; 215 216 PetscFunctionReturn(0); 217 } 218 219 PetscErrorCode SetupContext_ADVECTION(Ceed ceed, CeedData ceed_data, 220 AppCtx app_ctx, SetupContext setup_ctx, Physics phys) { 221 PetscFunctionBeginUser; 222 223 CeedQFunctionContextCreate(ceed, &ceed_data->setup_context); 224 CeedQFunctionContextSetData(ceed_data->setup_context, CEED_MEM_HOST, 225 CEED_USE_POINTER, sizeof(*setup_ctx), setup_ctx); 226 CeedQFunctionSetContext(ceed_data->qf_ics, ceed_data->setup_context); 227 CeedQFunctionContextCreate(ceed, &ceed_data->advection_context); 228 CeedQFunctionContextSetData(ceed_data->advection_context, CEED_MEM_HOST, 229 CEED_USE_POINTER, 230 sizeof(*phys->advection_ctx), phys->advection_ctx); 231 if (ceed_data->qf_rhs_vol) 232 CeedQFunctionSetContext(ceed_data->qf_rhs_vol, ceed_data->advection_context); 233 if (ceed_data->qf_ifunction_vol) 234 CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, 235 ceed_data->advection_context); 236 if (ceed_data->qf_apply_sur) 237 CeedQFunctionSetContext(ceed_data->qf_apply_sur, ceed_data->advection_context); 238 239 PetscFunctionReturn(0); 240 } 241 242 PetscErrorCode BC_ADVECTION(DM dm, SimpleBC bc, Physics phys, 243 void *setup_ctx) { 244 PetscErrorCode ierr; 245 PetscFunctionBeginUser; 246 247 // Define boundary conditions 248 if (phys->wind_type == WIND_TRANSLATION) { 249 bc->num_wall = bc->num_slip[2] = 0; 250 } else if (phys->wind_type == WIND_ROTATION && 251 phys->bubble_type == BUBBLE_CYLINDER) { 252 bc->num_slip[2] = 2; bc->slips[2][0] = 1; bc->slips[2][1] = 2; 253 bc->num_wall = 4; 254 bc->walls[0] = 3; bc->walls[1] = 4; bc->walls[2] = 5; bc->walls[3] = 6; 255 } else { 256 bc->num_slip[2] = 0; 257 bc->num_wall = 6; 258 bc->walls[0] = 1; bc->walls[1] = 2; bc->walls[2] = 3; 259 bc->walls[3] = 4; bc->walls[4] = 5; bc->walls[5] = 6; 260 } 261 262 { 263 // Set slip boundary conditions 264 DMLabel label; 265 ierr = DMGetLabel(dm, "Face Sets", &label); CHKERRQ(ierr); 266 PetscInt comps[1] = {3}; 267 ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "slipz", label, 268 bc->num_slip[2], bc->slips[2], 0, 1, comps, 269 (void(*)(void))NULL, NULL, setup_ctx, NULL); 270 CHKERRQ(ierr); 271 } 272 273 // Set wall boundary conditions 274 // zero energy density and zero flux 275 { 276 DMLabel label; 277 PetscInt comps[1] = {4}; 278 ierr = DMGetLabel(dm, "Face Sets", &label); CHKERRQ(ierr); 279 ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "wall", label, 280 bc->num_wall, bc->walls, 0, 281 1, comps, (void(*)(void))Exact_Advection, NULL, 282 setup_ctx, NULL); CHKERRQ(ierr); 283 } 284 285 PetscFunctionReturn(0); 286 } 287 288 PetscErrorCode PRINT_ADVECTION(Physics phys, SetupContext setup_ctx, 289 AppCtx app_ctx) { 290 MPI_Comm comm = PETSC_COMM_WORLD; 291 PetscErrorCode ierr; 292 PetscFunctionBeginUser; 293 294 ierr = PetscPrintf(comm, 295 " Problem:\n" 296 " Problem Name : %s\n" 297 " Stabilization : %s\n" 298 " Bubble Type : %s (%dD)\n" 299 " Bubble Continuity : %s\n" 300 " Wind Type : %s\n", 301 app_ctx->problem_name, StabilizationTypes[phys->stab], 302 BubbleTypes[phys->bubble_type], 303 phys->bubble_type == BUBBLE_SPHERE ? 3 : 2, 304 BubbleContinuityTypes[phys->bubble_continuity_type], 305 WindTypes[phys->wind_type]); CHKERRQ(ierr); 306 307 if (phys->wind_type == WIND_TRANSLATION) { 308 ierr = PetscPrintf(comm, 309 " Background Wind : %f,%f,%f\n", 310 setup_ctx->wind[0], setup_ctx->wind[1], setup_ctx->wind[2]); CHKERRQ(ierr); 311 } 312 PetscFunctionReturn(0); 313 } 314