13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 33d8e8822SJeremy L Thompson // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 53d8e8822SJeremy L Thompson // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 73d8e8822SJeremy L Thompson 85754ecacSJeremy L Thompson #include "../problems/mooney-rivlin.h" 95754ecacSJeremy L Thompson 10*2b730f8bSJeremy L Thompson #include <ceed.h> 11*2b730f8bSJeremy L Thompson #include <petsc.h> 12*2b730f8bSJeremy L Thompson 135754ecacSJeremy L Thompson // Build libCEED context object 14*2b730f8bSJeremy L Thompson PetscErrorCode PhysicsContext_MR(MPI_Comm comm, Ceed ceed, Units *units, CeedQFunctionContext *ctx) { 155754ecacSJeremy L Thompson Physics_MR phys; 165754ecacSJeremy L Thompson 175754ecacSJeremy L Thompson PetscFunctionBegin; 185754ecacSJeremy L Thompson 19*2b730f8bSJeremy L Thompson PetscCall(PetscMalloc1(1, units)); 20*2b730f8bSJeremy L Thompson PetscCall(PetscMalloc1(1, &phys)); 21*2b730f8bSJeremy L Thompson PetscCall(ProcessPhysics_MR(comm, phys, *units)); 225754ecacSJeremy L Thompson CeedQFunctionContextCreate(ceed, ctx); 23*2b730f8bSJeremy L Thompson CeedQFunctionContextSetData(*ctx, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(*phys), phys); 24*2b730f8bSJeremy L Thompson PetscCall(PetscFree(phys)); 255754ecacSJeremy L Thompson 265754ecacSJeremy L Thompson PetscFunctionReturn(0); 275754ecacSJeremy L Thompson } 285754ecacSJeremy L Thompson 295754ecacSJeremy L Thompson // Build libCEED smoother context object 30*2b730f8bSJeremy L Thompson PetscErrorCode PhysicsSmootherContext_MR(MPI_Comm comm, Ceed ceed, CeedQFunctionContext ctx, CeedQFunctionContext *ctx_smoother) { 315754ecacSJeremy L Thompson PetscScalar nu_smoother = 0; 325754ecacSJeremy L Thompson PetscBool nu_flag = PETSC_FALSE; 335754ecacSJeremy L Thompson Physics_MR phys, phys_smoother; 345754ecacSJeremy L Thompson 355754ecacSJeremy L Thompson PetscFunctionBegin; 365754ecacSJeremy L Thompson 37*2b730f8bSJeremy L Thompson PetscOptionsBegin(comm, NULL, "Mooney Rivlin physical parameters for smoother", NULL); 385754ecacSJeremy L Thompson 39*2b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-nu_smoother", "Poisson's ratio for smoother", NULL, nu_smoother, &nu_smoother, &nu_flag)); 40*2b730f8bSJeremy L Thompson if (nu_smoother < 0 || nu_smoother >= 0.5) 41*2b730f8bSJeremy L Thompson SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Mooney-Rivlin model requires Poisson ratio -nu option in [0, .5)"); 425754ecacSJeremy L Thompson 4367490bc6SJeremy L Thompson PetscOptionsEnd(); // End of setting Physics 445754ecacSJeremy L Thompson 455754ecacSJeremy L Thompson if (nu_flag) { 465754ecacSJeremy L Thompson // Copy context 475754ecacSJeremy L Thompson CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &phys); 48*2b730f8bSJeremy L Thompson PetscCall(PetscMalloc1(1, &phys_smoother)); 49*2b730f8bSJeremy L Thompson PetscCall(PetscMemcpy(phys_smoother, phys, sizeof(*phys))); 505754ecacSJeremy L Thompson CeedQFunctionContextRestoreData(ctx, &phys); 515754ecacSJeremy L Thompson // Create smoother context 525754ecacSJeremy L Thompson CeedQFunctionContextCreate(ceed, ctx_smoother); 53*2b730f8bSJeremy L Thompson phys_smoother->lambda = 2 * (phys_smoother->mu_1 + phys_smoother->mu_2) * nu_smoother / (1 - 2 * nu_smoother); 54*2b730f8bSJeremy L Thompson CeedQFunctionContextSetData(*ctx_smoother, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(*phys_smoother), phys_smoother); 55*2b730f8bSJeremy L Thompson PetscCall(PetscFree(phys_smoother)); 565754ecacSJeremy L Thompson } else { 575754ecacSJeremy L Thompson *ctx_smoother = NULL; 585754ecacSJeremy L Thompson } 595754ecacSJeremy L Thompson 605754ecacSJeremy L Thompson PetscFunctionReturn(0); 615754ecacSJeremy L Thompson } 625754ecacSJeremy L Thompson 635754ecacSJeremy L Thompson // Process physics options - Mooney-Rivlin 645754ecacSJeremy L Thompson PetscErrorCode ProcessPhysics_MR(MPI_Comm comm, Physics_MR phys, Units units) { 655754ecacSJeremy L Thompson PetscReal nu = -1; 665754ecacSJeremy L Thompson phys->mu_1 = -1; 675754ecacSJeremy L Thompson phys->mu_2 = -1; 685754ecacSJeremy L Thompson phys->lambda = -1; 695754ecacSJeremy L Thompson units->meter = 1; // 1 meter in scaled length units 705754ecacSJeremy L Thompson units->second = 1; // 1 second in scaled time units 715754ecacSJeremy L Thompson units->kilogram = 1; // 1 kilogram in scaled mass units 725754ecacSJeremy L Thompson 735754ecacSJeremy L Thompson PetscFunctionBeginUser; 745754ecacSJeremy L Thompson 7567490bc6SJeremy L Thompson PetscOptionsBegin(comm, NULL, "Mooney Rivlin physical parameters", NULL); 765754ecacSJeremy L Thompson 77*2b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-mu_1", "Material Property mu_1", NULL, phys->mu_1, &phys->mu_1, NULL)); 78*2b730f8bSJeremy L Thompson if (phys->mu_1 < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Mooney-Rivlin model requires non-negative -mu_1 option (Pa)"); 795754ecacSJeremy L Thompson 80*2b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-mu_2", "Material Property mu_2", NULL, phys->mu_2, &phys->mu_2, NULL)); 81*2b730f8bSJeremy L Thompson if (phys->mu_2 < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Mooney-Rivlin model requires non-negative -mu_2 option (Pa)"); 825754ecacSJeremy L Thompson 83*2b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-nu", "Poisson ratio", NULL, nu, &nu, NULL)); 84*2b730f8bSJeremy L Thompson if (nu < 0 || nu >= 0.5) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Mooney-Rivlin model requires Poisson ratio -nu option in [0, .5)"); 855754ecacSJeremy L Thompson phys->lambda = 2 * (phys->mu_1 + phys->mu_2) * nu / (1 - 2 * nu); 865754ecacSJeremy L Thompson 87*2b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-units_meter", "1 meter in scaled length units", NULL, units->meter, &units->meter, NULL)); 885754ecacSJeremy L Thompson units->meter = fabs(units->meter); 895754ecacSJeremy L Thompson 90*2b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-units_second", "1 second in scaled time units", NULL, units->second, &units->second, NULL)); 915754ecacSJeremy L Thompson units->second = fabs(units->second); 925754ecacSJeremy L Thompson 93*2b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-units_kilogram", "1 kilogram in scaled mass units", NULL, units->kilogram, &units->kilogram, NULL)); 945754ecacSJeremy L Thompson units->kilogram = fabs(units->kilogram); 955754ecacSJeremy L Thompson 9667490bc6SJeremy L Thompson PetscOptionsEnd(); // End of setting Physics 975754ecacSJeremy L Thompson 985754ecacSJeremy L Thompson // Define derived units 995754ecacSJeremy L Thompson units->Pascal = units->kilogram / (units->meter * PetscSqr(units->second)); 1005754ecacSJeremy L Thompson 1015754ecacSJeremy L Thompson // Scale material parameters based on units of Pa 1025754ecacSJeremy L Thompson phys->mu_1 *= units->Pascal; 1035754ecacSJeremy L Thompson phys->mu_2 *= units->Pascal; 1045754ecacSJeremy L Thompson phys->lambda *= units->Pascal; 1055754ecacSJeremy L Thompson 1065754ecacSJeremy L Thompson PetscFunctionReturn(0); 1075754ecacSJeremy L Thompson };