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 <ceed.h> 95754ecacSJeremy L Thompson #include <petsc.h> 105754ecacSJeremy L Thompson #include "../problems/mooney-rivlin.h" 115754ecacSJeremy L Thompson 125754ecacSJeremy L Thompson // Build libCEED context object 135754ecacSJeremy L Thompson PetscErrorCode PhysicsContext_MR(MPI_Comm comm, Ceed ceed, Units *units, 145754ecacSJeremy L Thompson CeedQFunctionContext *ctx) { 155754ecacSJeremy L Thompson PetscErrorCode ierr; 165754ecacSJeremy L Thompson Physics_MR phys; 175754ecacSJeremy L Thompson 185754ecacSJeremy L Thompson PetscFunctionBegin; 195754ecacSJeremy L Thompson 205754ecacSJeremy L Thompson ierr = PetscMalloc1(1, units); CHKERRQ(ierr); 215754ecacSJeremy L Thompson ierr = PetscMalloc1(1, &phys); CHKERRQ(ierr); 225754ecacSJeremy L Thompson ierr = ProcessPhysics_MR(comm, phys, *units); CHKERRQ(ierr); 235754ecacSJeremy L Thompson CeedQFunctionContextCreate(ceed, ctx); 245754ecacSJeremy L Thompson CeedQFunctionContextSetData(*ctx, CEED_MEM_HOST, CEED_COPY_VALUES, 255754ecacSJeremy L Thompson sizeof(*phys), phys); 265754ecacSJeremy L Thompson ierr = PetscFree(phys); CHKERRQ(ierr); 275754ecacSJeremy L Thompson 285754ecacSJeremy L Thompson PetscFunctionReturn(0); 295754ecacSJeremy L Thompson } 305754ecacSJeremy L Thompson 315754ecacSJeremy L Thompson // Build libCEED smoother context object 325754ecacSJeremy L Thompson PetscErrorCode PhysicsSmootherContext_MR(MPI_Comm comm, Ceed ceed, 335754ecacSJeremy L Thompson CeedQFunctionContext ctx, CeedQFunctionContext *ctx_smoother) { 345754ecacSJeremy L Thompson PetscErrorCode ierr; 355754ecacSJeremy L Thompson PetscScalar nu_smoother = 0; 365754ecacSJeremy L Thompson PetscBool nu_flag = PETSC_FALSE; 375754ecacSJeremy L Thompson Physics_MR phys, phys_smoother; 385754ecacSJeremy L Thompson 395754ecacSJeremy L Thompson PetscFunctionBegin; 405754ecacSJeremy L Thompson 41*67490bc6SJeremy L Thompson PetscOptionsBegin(comm, NULL, "Mooney Rivlin physical parameters for smoother", 42*67490bc6SJeremy L Thompson NULL); 435754ecacSJeremy L Thompson 445754ecacSJeremy L Thompson ierr = PetscOptionsScalar("-nu_smoother", "Poisson's ratio for smoother", 455754ecacSJeremy L Thompson NULL, nu_smoother, &nu_smoother, &nu_flag); 465754ecacSJeremy L Thompson CHKERRQ(ierr); 475754ecacSJeremy L Thompson if (nu_smoother < 0 || 485754ecacSJeremy L Thompson nu_smoother >= 0.5) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, 495754ecacSJeremy L Thompson "Mooney-Rivlin model requires Poisson ratio -nu option in [0, .5)"); 505754ecacSJeremy L Thompson 51*67490bc6SJeremy L Thompson PetscOptionsEnd(); // End of setting Physics 525754ecacSJeremy L Thompson 535754ecacSJeremy L Thompson if (nu_flag) { 545754ecacSJeremy L Thompson // Copy context 555754ecacSJeremy L Thompson CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &phys); 565754ecacSJeremy L Thompson ierr = PetscMalloc1(1, &phys_smoother); CHKERRQ(ierr); 575754ecacSJeremy L Thompson ierr = PetscMemcpy(phys_smoother, phys, sizeof(*phys)); CHKERRQ(ierr); 585754ecacSJeremy L Thompson CeedQFunctionContextRestoreData(ctx, &phys); 595754ecacSJeremy L Thompson // Create smoother context 605754ecacSJeremy L Thompson CeedQFunctionContextCreate(ceed, ctx_smoother); 615754ecacSJeremy L Thompson phys_smoother->lambda = 2 * (phys_smoother->mu_1 + phys_smoother->mu_2) * 625754ecacSJeremy L Thompson nu_smoother / (1 - 2*nu_smoother); 635754ecacSJeremy L Thompson CeedQFunctionContextSetData(*ctx_smoother, CEED_MEM_HOST, CEED_COPY_VALUES, 645754ecacSJeremy L Thompson sizeof(*phys_smoother), phys_smoother); 655754ecacSJeremy L Thompson ierr = PetscFree(phys_smoother); CHKERRQ(ierr); 665754ecacSJeremy L Thompson } else { 675754ecacSJeremy L Thompson *ctx_smoother = NULL; 685754ecacSJeremy L Thompson } 695754ecacSJeremy L Thompson 705754ecacSJeremy L Thompson PetscFunctionReturn(0); 715754ecacSJeremy L Thompson } 725754ecacSJeremy L Thompson 735754ecacSJeremy L Thompson // Process physics options - Mooney-Rivlin 745754ecacSJeremy L Thompson PetscErrorCode ProcessPhysics_MR(MPI_Comm comm, Physics_MR phys, Units units) { 755754ecacSJeremy L Thompson PetscErrorCode ierr; 765754ecacSJeremy L Thompson PetscReal nu = -1; 775754ecacSJeremy L Thompson phys->mu_1 = -1; 785754ecacSJeremy L Thompson phys->mu_2 = -1; 795754ecacSJeremy L Thompson phys->lambda = -1; 805754ecacSJeremy L Thompson units->meter = 1; // 1 meter in scaled length units 815754ecacSJeremy L Thompson units->second = 1; // 1 second in scaled time units 825754ecacSJeremy L Thompson units->kilogram = 1; // 1 kilogram in scaled mass units 835754ecacSJeremy L Thompson 845754ecacSJeremy L Thompson PetscFunctionBeginUser; 855754ecacSJeremy L Thompson 86*67490bc6SJeremy L Thompson PetscOptionsBegin(comm, NULL, "Mooney Rivlin physical parameters", NULL); 875754ecacSJeremy L Thompson 885754ecacSJeremy L Thompson ierr = PetscOptionsScalar("-mu_1", "Material Property mu_1", NULL, 895754ecacSJeremy L Thompson phys->mu_1, &phys->mu_1, NULL); CHKERRQ(ierr); 905754ecacSJeremy L Thompson if (phys->mu_1 < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, 915754ecacSJeremy L Thompson "Mooney-Rivlin model requires non-negative -mu_1 option (Pa)"); 925754ecacSJeremy L Thompson 935754ecacSJeremy L Thompson ierr = PetscOptionsScalar("-mu_2", "Material Property mu_2", NULL, 945754ecacSJeremy L Thompson phys->mu_2, &phys->mu_2, NULL); CHKERRQ(ierr); 955754ecacSJeremy L Thompson if (phys->mu_2 < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, 965754ecacSJeremy L Thompson "Mooney-Rivlin model requires non-negative -mu_2 option (Pa)"); 975754ecacSJeremy L Thompson 985754ecacSJeremy L Thompson ierr = PetscOptionsScalar("-nu", "Poisson ratio", NULL, 995754ecacSJeremy L Thompson nu, &nu, NULL); CHKERRQ(ierr); 1005754ecacSJeremy L Thompson if (nu < 0 || nu >= 0.5) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, 1015754ecacSJeremy L Thompson "Mooney-Rivlin model requires Poisson ratio -nu option in [0, .5)"); 1025754ecacSJeremy L Thompson phys->lambda = 2 * (phys->mu_1 + phys->mu_2) * nu / (1 - 2*nu); 1035754ecacSJeremy L Thompson 1045754ecacSJeremy L Thompson ierr = PetscOptionsScalar("-units_meter", "1 meter in scaled length units", 1055754ecacSJeremy L Thompson NULL, units->meter, &units->meter, NULL); 1065754ecacSJeremy L Thompson CHKERRQ(ierr); 1075754ecacSJeremy L Thompson units->meter = fabs(units->meter); 1085754ecacSJeremy L Thompson 1095754ecacSJeremy L Thompson ierr = PetscOptionsScalar("-units_second", "1 second in scaled time units", 1105754ecacSJeremy L Thompson NULL, units->second, &units->second, NULL); 1115754ecacSJeremy L Thompson CHKERRQ(ierr); 1125754ecacSJeremy L Thompson units->second = fabs(units->second); 1135754ecacSJeremy L Thompson 1145754ecacSJeremy L Thompson ierr = PetscOptionsScalar("-units_kilogram", "1 kilogram in scaled mass units", 1155754ecacSJeremy L Thompson NULL, units->kilogram, &units->kilogram, NULL); 1165754ecacSJeremy L Thompson CHKERRQ(ierr); 1175754ecacSJeremy L Thompson units->kilogram = fabs(units->kilogram); 1185754ecacSJeremy L Thompson 119*67490bc6SJeremy L Thompson PetscOptionsEnd(); // End of setting Physics 1205754ecacSJeremy L Thompson 1215754ecacSJeremy L Thompson // Define derived units 1225754ecacSJeremy L Thompson units->Pascal = units->kilogram / (units->meter * PetscSqr(units->second)); 1235754ecacSJeremy L Thompson 1245754ecacSJeremy L Thompson // Scale material parameters based on units of Pa 1255754ecacSJeremy L Thompson phys->mu_1 *= units->Pascal; 1265754ecacSJeremy L Thompson phys->mu_2 *= units->Pascal; 1275754ecacSJeremy L Thompson phys->lambda *= units->Pascal; 1285754ecacSJeremy L Thompson 1295754ecacSJeremy L Thompson PetscFunctionReturn(0); 1305754ecacSJeremy L Thompson };