1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3 // 4 // SPDX-License-Identifier: BSD-2-Clause 5 // 6 // This file is part of CEED: http://github.com/ceed 7 8 /// @file 9 /// Utility functions for setting up Blasius Boundary Layer 10 11 #include "../navierstokes.h" 12 #include "../qfunctions/blasius.h" 13 14 /* \brief Modify the domain and mesh for blasius 15 * 16 * Modifies mesh such that `N` elements are within 1.2*`delta0` with a geometric 17 * growth ratio of `growth`. Excess elements are then geometrically distributed 18 * to the top surface. 19 * 20 * The top surface is also angled downwards, so that it may be used as an 21 * outflow. It's angle is controlled by top_angle (in units of degrees). 22 */ 23 PetscErrorCode modifyMesh(DM dm, PetscInt dim, PetscReal growth, PetscInt N, 24 PetscReal refine_height, PetscReal top_angle) { 25 26 PetscInt ierr, narr, ncoords; 27 PetscReal domain_min[3], domain_max[3], domain_size[3]; 28 PetscScalar *arr_coords; 29 Vec vec_coords; 30 PetscFunctionBeginUser; 31 32 PetscReal angle_coeff = tan(top_angle*(M_PI/180)); 33 34 // Get domain boundary information 35 ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr); 36 for (int i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 37 38 // Get coords array from DM 39 ierr = DMGetCoordinatesLocal(dm, &vec_coords); CHKERRQ(ierr); 40 ierr = VecGetLocalSize(vec_coords, &narr); CHKERRQ(ierr); 41 ierr = VecGetArray(vec_coords, &arr_coords); CHKERRQ(ierr); 42 43 PetscScalar (*coords)[dim] = (PetscScalar(*)[dim]) arr_coords; 44 ncoords = narr/dim; 45 46 // Get mesh information 47 PetscInt nmax = 3, faces[3]; 48 ierr = PetscOptionsGetIntArray(NULL, NULL, "-dm_plex_box_faces", faces, &nmax, 49 NULL); CHKERRQ(ierr); 50 51 // Calculate the first element height 52 PetscReal dybox = domain_size[1]/faces[1]; 53 PetscReal dy1 = refine_height*(growth-1)/(pow(growth, N)-1); 54 55 // Calculate log of sizing outside BL 56 PetscReal logdy = (log(domain_max[1]) - log(refine_height)) / (faces[1] - N); 57 58 for(int i=0; i<ncoords; i++) { 59 PetscInt y_box_index = round(coords[i][1]/dybox); 60 if(y_box_index <= N) { 61 coords[i][1] = (1 - (coords[i][0]/domain_max[0])*angle_coeff) * 62 dy1*(pow(growth, coords[i][1]/dybox)-1)/(growth-1); 63 } else { 64 PetscInt j = y_box_index - N; 65 coords[i][1] = (1 - (coords[i][0]/domain_max[0])*angle_coeff) * 66 exp(log(refine_height) + logdy*j); 67 } 68 } 69 70 ierr = VecRestoreArray(vec_coords, &arr_coords); CHKERRQ(ierr); 71 ierr = DMSetCoordinatesLocal(dm, vec_coords); CHKERRQ(ierr); 72 73 PetscFunctionReturn(0); 74 } 75 76 PetscErrorCode NS_BLASIUS(ProblemData *problem, DM dm, void *ctx) { 77 78 PetscInt ierr; 79 User user = *(User *)ctx; 80 MPI_Comm comm = PETSC_COMM_WORLD; 81 BlasiusContext blasius_ctx; 82 NewtonianIdealGasContext newtonian_ig_ctx; 83 CeedQFunctionContext blasius_context; 84 85 PetscFunctionBeginUser; 86 ierr = NS_NEWTONIAN_IG(problem, dm, ctx); CHKERRQ(ierr); 87 ierr = PetscCalloc1(1, &blasius_ctx); CHKERRQ(ierr); 88 89 // ------------------------------------------------------ 90 // SET UP Blasius 91 // ------------------------------------------------------ 92 CeedQFunctionContextDestroy(&problem->ics.qfunction_context); 93 problem->ics.qfunction = ICsBlasius; 94 problem->ics.qfunction_loc = ICsBlasius_loc; 95 problem->apply_inflow.qfunction = Blasius_Inflow; 96 problem->apply_inflow.qfunction_loc = Blasius_Inflow_loc; 97 problem->apply_outflow.qfunction = Blasius_Outflow; 98 problem->apply_outflow.qfunction_loc = Blasius_Outflow_loc; 99 100 // CeedScalar mu = .04; // Pa s, dynamic viscosity 101 CeedScalar Uinf = 40; // m/s 102 CeedScalar delta0 = 4.2e-4; // m 103 PetscReal refine_height = 5.9e-4; // m 104 PetscReal growth = 1.08; // [-] 105 PetscInt Ndelta = 45; // [-] 106 PetscReal top_angle = 5; // degrees 107 CeedScalar theta0 = 288.; // K 108 CeedScalar P0 = 1.01e5; // Pa 109 PetscBool weakT = PETSC_FALSE; // weak density or temperature 110 111 PetscOptionsBegin(comm, NULL, "Options for CHANNEL problem", NULL); 112 ierr = PetscOptionsBool("-weakT", "Change from rho weak to T weak at inflow", 113 NULL, weakT, &weakT, NULL); CHKERRQ(ierr); 114 ierr = PetscOptionsScalar("-Uinf", "Velocity at boundary layer edge", 115 NULL, Uinf, &Uinf, NULL); CHKERRQ(ierr); 116 ierr = PetscOptionsScalar("-delta0", "Boundary layer height at inflow", 117 NULL, delta0, &delta0, NULL); CHKERRQ(ierr); 118 ierr = PetscOptionsScalar("-theta0", "Wall temperature", 119 NULL, theta0, &theta0, NULL); CHKERRQ(ierr); 120 ierr = PetscOptionsScalar("-P0", "Pressure at outflow", 121 NULL, P0, &P0, NULL); CHKERRQ(ierr); 122 ierr = PetscOptionsBoundedInt("-Ndelta", "Velocity at boundary layer edge", 123 NULL, Ndelta, &Ndelta, NULL, 1); CHKERRQ(ierr); 124 ierr = PetscOptionsScalar("-refine_height", 125 "Height of boundary layer mesh refinement", 126 NULL, refine_height, &refine_height, NULL); CHKERRQ(ierr); 127 ierr = PetscOptionsScalar("-growth", 128 "Geometric growth rate of boundary layer mesh", 129 NULL, growth, &growth, NULL); CHKERRQ(ierr); 130 ierr = PetscOptionsScalar("-top_angle", 131 "Geometric top_angle rate of boundary layer mesh", 132 NULL, top_angle, &top_angle, NULL); CHKERRQ(ierr); 133 PetscOptionsEnd(); 134 135 PetscScalar meter = user->units->meter; 136 PetscScalar second = user->units->second; 137 PetscScalar Kelvin = user->units->Kelvin; 138 PetscScalar Pascal = user->units->Pascal; 139 140 theta0 *= Kelvin; 141 P0 *= Pascal; 142 Uinf *= meter / second; 143 delta0 *= meter; 144 145 ierr = modifyMesh(dm, problem->dim, growth, Ndelta, refine_height, top_angle); 146 CHKERRQ(ierr); 147 148 // Some properties depend on parameters from NewtonianIdealGas 149 CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, 150 CEED_MEM_HOST, &newtonian_ig_ctx); 151 152 blasius_ctx->weakT = !!weakT; 153 blasius_ctx->Uinf = Uinf; 154 blasius_ctx->delta0 = delta0; 155 blasius_ctx->theta0 = theta0; 156 blasius_ctx->P0 = P0; 157 blasius_ctx->implicit = user->phys->implicit; 158 blasius_ctx->newtonian_ctx = *newtonian_ig_ctx; 159 CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, 160 &newtonian_ig_ctx); 161 162 CeedQFunctionContextCreate(user->ceed, &blasius_context); 163 CeedQFunctionContextSetData(blasius_context, CEED_MEM_HOST, 164 CEED_USE_POINTER, 165 sizeof(*blasius_ctx), blasius_ctx); 166 CeedQFunctionContextSetDataDestroy(blasius_context, CEED_MEM_HOST, 167 FreeContextPetsc); 168 169 problem->ics.qfunction_context = blasius_context; 170 CeedQFunctionContextReferenceCopy(blasius_context, 171 &problem->apply_inflow.qfunction_context); 172 CeedQFunctionContextReferenceCopy(blasius_context, 173 &problem->apply_outflow.qfunction_context); 174 PetscFunctionReturn(0); 175 } 176