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 #include <ceed.h> 9 #include <petsc.h> 10 #include "../problems/mooney-rivlin.h" 11 12 // Build libCEED context object 13 PetscErrorCode PhysicsContext_MR(MPI_Comm comm, Ceed ceed, Units *units, 14 CeedQFunctionContext *ctx) { 15 PetscErrorCode ierr; 16 Physics_MR phys; 17 18 PetscFunctionBegin; 19 20 ierr = PetscMalloc1(1, units); CHKERRQ(ierr); 21 ierr = PetscMalloc1(1, &phys); CHKERRQ(ierr); 22 ierr = ProcessPhysics_MR(comm, phys, *units); CHKERRQ(ierr); 23 CeedQFunctionContextCreate(ceed, ctx); 24 CeedQFunctionContextSetData(*ctx, CEED_MEM_HOST, CEED_COPY_VALUES, 25 sizeof(*phys), phys); 26 ierr = PetscFree(phys); CHKERRQ(ierr); 27 28 PetscFunctionReturn(0); 29 } 30 31 // Build libCEED smoother context object 32 PetscErrorCode PhysicsSmootherContext_MR(MPI_Comm comm, Ceed ceed, 33 CeedQFunctionContext ctx, CeedQFunctionContext *ctx_smoother) { 34 PetscErrorCode ierr; 35 PetscScalar nu_smoother = 0; 36 PetscBool nu_flag = PETSC_FALSE; 37 Physics_MR phys, phys_smoother; 38 39 PetscFunctionBegin; 40 41 PetscOptionsBegin(comm, NULL, "Mooney Rivlin physical parameters for smoother", 42 NULL); 43 44 ierr = PetscOptionsScalar("-nu_smoother", "Poisson's ratio for smoother", 45 NULL, nu_smoother, &nu_smoother, &nu_flag); 46 CHKERRQ(ierr); 47 if (nu_smoother < 0 || 48 nu_smoother >= 0.5) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, 49 "Mooney-Rivlin model requires Poisson ratio -nu option in [0, .5)"); 50 51 PetscOptionsEnd(); // End of setting Physics 52 53 if (nu_flag) { 54 // Copy context 55 CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &phys); 56 ierr = PetscMalloc1(1, &phys_smoother); CHKERRQ(ierr); 57 ierr = PetscMemcpy(phys_smoother, phys, sizeof(*phys)); CHKERRQ(ierr); 58 CeedQFunctionContextRestoreData(ctx, &phys); 59 // Create smoother context 60 CeedQFunctionContextCreate(ceed, ctx_smoother); 61 phys_smoother->lambda = 2 * (phys_smoother->mu_1 + phys_smoother->mu_2) * 62 nu_smoother / (1 - 2*nu_smoother); 63 CeedQFunctionContextSetData(*ctx_smoother, CEED_MEM_HOST, CEED_COPY_VALUES, 64 sizeof(*phys_smoother), phys_smoother); 65 ierr = PetscFree(phys_smoother); CHKERRQ(ierr); 66 } else { 67 *ctx_smoother = NULL; 68 } 69 70 PetscFunctionReturn(0); 71 } 72 73 // Process physics options - Mooney-Rivlin 74 PetscErrorCode ProcessPhysics_MR(MPI_Comm comm, Physics_MR phys, Units units) { 75 PetscErrorCode ierr; 76 PetscReal nu = -1; 77 phys->mu_1 = -1; 78 phys->mu_2 = -1; 79 phys->lambda = -1; 80 units->meter = 1; // 1 meter in scaled length units 81 units->second = 1; // 1 second in scaled time units 82 units->kilogram = 1; // 1 kilogram in scaled mass units 83 84 PetscFunctionBeginUser; 85 86 PetscOptionsBegin(comm, NULL, "Mooney Rivlin physical parameters", NULL); 87 88 ierr = PetscOptionsScalar("-mu_1", "Material Property mu_1", NULL, 89 phys->mu_1, &phys->mu_1, NULL); CHKERRQ(ierr); 90 if (phys->mu_1 < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, 91 "Mooney-Rivlin model requires non-negative -mu_1 option (Pa)"); 92 93 ierr = PetscOptionsScalar("-mu_2", "Material Property mu_2", NULL, 94 phys->mu_2, &phys->mu_2, NULL); CHKERRQ(ierr); 95 if (phys->mu_2 < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, 96 "Mooney-Rivlin model requires non-negative -mu_2 option (Pa)"); 97 98 ierr = PetscOptionsScalar("-nu", "Poisson ratio", NULL, 99 nu, &nu, NULL); CHKERRQ(ierr); 100 if (nu < 0 || nu >= 0.5) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, 101 "Mooney-Rivlin model requires Poisson ratio -nu option in [0, .5)"); 102 phys->lambda = 2 * (phys->mu_1 + phys->mu_2) * nu / (1 - 2*nu); 103 104 ierr = PetscOptionsScalar("-units_meter", "1 meter in scaled length units", 105 NULL, units->meter, &units->meter, NULL); 106 CHKERRQ(ierr); 107 units->meter = fabs(units->meter); 108 109 ierr = PetscOptionsScalar("-units_second", "1 second in scaled time units", 110 NULL, units->second, &units->second, NULL); 111 CHKERRQ(ierr); 112 units->second = fabs(units->second); 113 114 ierr = PetscOptionsScalar("-units_kilogram", "1 kilogram in scaled mass units", 115 NULL, units->kilogram, &units->kilogram, NULL); 116 CHKERRQ(ierr); 117 units->kilogram = fabs(units->kilogram); 118 119 PetscOptionsEnd(); // End of setting Physics 120 121 // Define derived units 122 units->Pascal = units->kilogram / (units->meter * PetscSqr(units->second)); 123 124 // Scale material parameters based on units of Pa 125 phys->mu_1 *= units->Pascal; 126 phys->mu_2 *= units->Pascal; 127 phys->lambda *= units->Pascal; 128 129 PetscFunctionReturn(0); 130 };