1*9ba83ac0SJeremy L Thompson // Copyright (c) 2017-2026, 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
102b730f8bSJeremy L Thompson #include <ceed.h>
1149aac155SJeremy L Thompson #include <petscsys.h>
122b730f8bSJeremy L Thompson
135754ecacSJeremy L Thompson // Build libCEED context object
PhysicsContext_MR(MPI_Comm comm,Ceed ceed,Units * units,CeedQFunctionContext * ctx)142b730f8bSJeremy 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
192b730f8bSJeremy L Thompson PetscCall(PetscMalloc1(1, units));
202b730f8bSJeremy L Thompson PetscCall(PetscMalloc1(1, &phys));
212b730f8bSJeremy L Thompson PetscCall(ProcessPhysics_MR(comm, phys, *units));
225754ecacSJeremy L Thompson CeedQFunctionContextCreate(ceed, ctx);
232b730f8bSJeremy L Thompson CeedQFunctionContextSetData(*ctx, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(*phys), phys);
242b730f8bSJeremy L Thompson PetscCall(PetscFree(phys));
255754ecacSJeremy L Thompson
26ee4ca9cbSJames Wright PetscFunctionReturn(PETSC_SUCCESS);
275754ecacSJeremy L Thompson }
285754ecacSJeremy L Thompson
295754ecacSJeremy L Thompson // Build libCEED smoother context object
PhysicsSmootherContext_MR(MPI_Comm comm,Ceed ceed,CeedQFunctionContext ctx,CeedQFunctionContext * ctx_smoother)302b730f8bSJeremy 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
372b730f8bSJeremy L Thompson PetscOptionsBegin(comm, NULL, "Mooney Rivlin physical parameters for smoother", NULL);
385754ecacSJeremy L Thompson
392b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-nu_smoother", "Poisson's ratio for smoother", NULL, nu_smoother, &nu_smoother, &nu_flag));
4049aac155SJeremy L Thompson if (nu_smoother < 0 || nu_smoother >= 0.5) {
412b730f8bSJeremy L Thompson SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Mooney-Rivlin model requires Poisson ratio -nu option in [0, .5)");
4249aac155SJeremy L Thompson }
435754ecacSJeremy L Thompson
4467490bc6SJeremy L Thompson PetscOptionsEnd(); // End of setting Physics
455754ecacSJeremy L Thompson
465754ecacSJeremy L Thompson if (nu_flag) {
475754ecacSJeremy L Thompson // Copy context
485754ecacSJeremy L Thompson CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &phys);
492b730f8bSJeremy L Thompson PetscCall(PetscMalloc1(1, &phys_smoother));
502b730f8bSJeremy L Thompson PetscCall(PetscMemcpy(phys_smoother, phys, sizeof(*phys)));
515754ecacSJeremy L Thompson CeedQFunctionContextRestoreData(ctx, &phys);
525754ecacSJeremy L Thompson // Create smoother context
535754ecacSJeremy L Thompson CeedQFunctionContextCreate(ceed, ctx_smoother);
542b730f8bSJeremy L Thompson phys_smoother->lambda = 2 * (phys_smoother->mu_1 + phys_smoother->mu_2) * nu_smoother / (1 - 2 * nu_smoother);
552b730f8bSJeremy L Thompson CeedQFunctionContextSetData(*ctx_smoother, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(*phys_smoother), phys_smoother);
562b730f8bSJeremy L Thompson PetscCall(PetscFree(phys_smoother));
575754ecacSJeremy L Thompson } else {
585754ecacSJeremy L Thompson *ctx_smoother = NULL;
595754ecacSJeremy L Thompson }
605754ecacSJeremy L Thompson
61ee4ca9cbSJames Wright PetscFunctionReturn(PETSC_SUCCESS);
625754ecacSJeremy L Thompson }
635754ecacSJeremy L Thompson
645754ecacSJeremy L Thompson // Process physics options - Mooney-Rivlin
ProcessPhysics_MR(MPI_Comm comm,Physics_MR phys,Units units)655754ecacSJeremy L Thompson PetscErrorCode ProcessPhysics_MR(MPI_Comm comm, Physics_MR phys, Units units) {
665754ecacSJeremy L Thompson PetscReal nu = -1;
675754ecacSJeremy L Thompson phys->mu_1 = -1;
685754ecacSJeremy L Thompson phys->mu_2 = -1;
695754ecacSJeremy L Thompson phys->lambda = -1;
705754ecacSJeremy L Thompson units->meter = 1; // 1 meter in scaled length units
715754ecacSJeremy L Thompson units->second = 1; // 1 second in scaled time units
725754ecacSJeremy L Thompson units->kilogram = 1; // 1 kilogram in scaled mass units
735754ecacSJeremy L Thompson
745754ecacSJeremy L Thompson PetscFunctionBeginUser;
755754ecacSJeremy L Thompson
7667490bc6SJeremy L Thompson PetscOptionsBegin(comm, NULL, "Mooney Rivlin physical parameters", NULL);
775754ecacSJeremy L Thompson
782b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-mu_1", "Material Property mu_1", NULL, phys->mu_1, &phys->mu_1, NULL));
792b730f8bSJeremy L Thompson if (phys->mu_1 < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Mooney-Rivlin model requires non-negative -mu_1 option (Pa)");
805754ecacSJeremy L Thompson
812b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-mu_2", "Material Property mu_2", NULL, phys->mu_2, &phys->mu_2, NULL));
822b730f8bSJeremy L Thompson if (phys->mu_2 < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Mooney-Rivlin model requires non-negative -mu_2 option (Pa)");
835754ecacSJeremy L Thompson
842b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-nu", "Poisson ratio", NULL, nu, &nu, NULL));
852b730f8bSJeremy 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)");
865754ecacSJeremy L Thompson phys->lambda = 2 * (phys->mu_1 + phys->mu_2) * nu / (1 - 2 * nu);
875754ecacSJeremy L Thompson
882b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-units_meter", "1 meter in scaled length units", NULL, units->meter, &units->meter, NULL));
895754ecacSJeremy L Thompson units->meter = fabs(units->meter);
905754ecacSJeremy L Thompson
912b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-units_second", "1 second in scaled time units", NULL, units->second, &units->second, NULL));
925754ecacSJeremy L Thompson units->second = fabs(units->second);
935754ecacSJeremy L Thompson
942b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-units_kilogram", "1 kilogram in scaled mass units", NULL, units->kilogram, &units->kilogram, NULL));
955754ecacSJeremy L Thompson units->kilogram = fabs(units->kilogram);
965754ecacSJeremy L Thompson
9767490bc6SJeremy L Thompson PetscOptionsEnd(); // End of setting Physics
985754ecacSJeremy L Thompson
995754ecacSJeremy L Thompson // Define derived units
1005754ecacSJeremy L Thompson units->Pascal = units->kilogram / (units->meter * PetscSqr(units->second));
1015754ecacSJeremy L Thompson
1025754ecacSJeremy L Thompson // Scale material parameters based on units of Pa
1035754ecacSJeremy L Thompson phys->mu_1 *= units->Pascal;
1045754ecacSJeremy L Thompson phys->mu_2 *= units->Pascal;
1055754ecacSJeremy L Thompson phys->lambda *= units->Pascal;
1065754ecacSJeremy L Thompson
107ee4ca9cbSJames Wright PetscFunctionReturn(PETSC_SUCCESS);
1085754ecacSJeremy L Thompson };