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/neo-hookean.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_NH(MPI_Comm comm,Ceed ceed,Units * units,CeedQFunctionContext * ctx)142b730f8bSJeremy L Thompson PetscErrorCode PhysicsContext_NH(MPI_Comm comm, Ceed ceed, Units *units, CeedQFunctionContext *ctx) {
155754ecacSJeremy L Thompson Physics_NH 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_NH(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_NH(MPI_Comm comm,Ceed ceed,CeedQFunctionContext ctx,CeedQFunctionContext * ctx_smoother)302b730f8bSJeremy L Thompson PetscErrorCode PhysicsSmootherContext_NH(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_NH phys, phys_smoother;
345754ecacSJeremy L Thompson
355754ecacSJeremy L Thompson PetscFunctionBegin;
365754ecacSJeremy L Thompson
372b730f8bSJeremy L Thompson PetscOptionsBegin(comm, NULL, "Neo-Hookean 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));
405754ecacSJeremy L Thompson
4167490bc6SJeremy L Thompson PetscOptionsEnd(); // End of setting Physics
425754ecacSJeremy L Thompson
435754ecacSJeremy L Thompson if (nu_flag) {
445754ecacSJeremy L Thompson // Copy context
455754ecacSJeremy L Thompson CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &phys);
462b730f8bSJeremy L Thompson PetscCall(PetscMalloc1(1, &phys_smoother));
472b730f8bSJeremy L Thompson PetscCall(PetscMemcpy(phys_smoother, phys, sizeof(*phys)));
485754ecacSJeremy L Thompson CeedQFunctionContextRestoreData(ctx, &phys);
495754ecacSJeremy L Thompson // Create smoother context
505754ecacSJeremy L Thompson CeedQFunctionContextCreate(ceed, ctx_smoother);
515754ecacSJeremy L Thompson phys_smoother->nu = nu_smoother;
522b730f8bSJeremy L Thompson CeedQFunctionContextSetData(*ctx_smoother, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(*phys_smoother), phys_smoother);
532b730f8bSJeremy L Thompson PetscCall(PetscFree(phys_smoother));
545754ecacSJeremy L Thompson } else {
555754ecacSJeremy L Thompson *ctx_smoother = NULL;
565754ecacSJeremy L Thompson }
575754ecacSJeremy L Thompson
58ee4ca9cbSJames Wright PetscFunctionReturn(PETSC_SUCCESS);
595754ecacSJeremy L Thompson }
605754ecacSJeremy L Thompson
615754ecacSJeremy L Thompson // Process physics options - Neo-Hookean
ProcessPhysics_NH(MPI_Comm comm,Physics_NH phys,Units units)625754ecacSJeremy L Thompson PetscErrorCode ProcessPhysics_NH(MPI_Comm comm, Physics_NH phys, Units units) {
635754ecacSJeremy L Thompson PetscBool nu_flag = PETSC_FALSE;
645754ecacSJeremy L Thompson PetscBool Young_flag = PETSC_FALSE;
655754ecacSJeremy L Thompson phys->nu = 0;
665754ecacSJeremy L Thompson phys->E = 0;
675754ecacSJeremy L Thompson units->meter = 1; // 1 meter in scaled length units
685754ecacSJeremy L Thompson units->second = 1; // 1 second in scaled time units
695754ecacSJeremy L Thompson units->kilogram = 1; // 1 kilogram in scaled mass units
705754ecacSJeremy L Thompson
715754ecacSJeremy L Thompson PetscFunctionBeginUser;
725754ecacSJeremy L Thompson
7367490bc6SJeremy L Thompson PetscOptionsBegin(comm, NULL, "Neo-Hookean physical parameters", NULL);
745754ecacSJeremy L Thompson
752b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-nu", "Poisson's ratio", NULL, phys->nu, &phys->nu, &nu_flag));
765754ecacSJeremy L Thompson
772b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-E", "Young's Modulus", NULL, phys->E, &phys->E, &Young_flag));
785754ecacSJeremy L Thompson
792b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-units_meter", "1 meter in scaled length units", NULL, units->meter, &units->meter, NULL));
805754ecacSJeremy L Thompson units->meter = fabs(units->meter);
815754ecacSJeremy L Thompson
822b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-units_second", "1 second in scaled time units", NULL, units->second, &units->second, NULL));
835754ecacSJeremy L Thompson units->second = fabs(units->second);
845754ecacSJeremy L Thompson
852b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-units_kilogram", "1 kilogram in scaled mass units", NULL, units->kilogram, &units->kilogram, NULL));
865754ecacSJeremy L Thompson units->kilogram = fabs(units->kilogram);
875754ecacSJeremy L Thompson
8867490bc6SJeremy L Thompson PetscOptionsEnd(); // End of setting Physics
895754ecacSJeremy L Thompson
905754ecacSJeremy L Thompson // Check for all required options to be set
915754ecacSJeremy L Thompson if (!nu_flag) {
925754ecacSJeremy L Thompson SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "-nu option needed");
935754ecacSJeremy L Thompson }
945754ecacSJeremy L Thompson if (!Young_flag) {
955754ecacSJeremy L Thompson SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "-E option needed");
965754ecacSJeremy L Thompson }
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 E to Pa
1025754ecacSJeremy L Thompson phys->E *= units->Pascal;
1035754ecacSJeremy L Thompson
104ee4ca9cbSJames Wright PetscFunctionReturn(PETSC_SUCCESS);
1055754ecacSJeremy L Thompson };