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