v0.16.3
Loading...
Searching...
No Matches
Classes | Namespaces | Functions | Variables
MatAmentumUmat.cpp File Reference
#include <MoFEM.hpp>
#include "MatAmentumUmat.hpp"
#include "MatUmatImpl.hpp"

Go to the source code of this file.

Classes

struct  MatOps::AgingFpyTimeScale
 
struct  MatOps::MatAmentumUmatImpl< DIM, MODEL_TYPE >
 
struct  TSAdaptAmentum
 Custom TSAdaptivity in MoFEM for Amentum Umat. More...
 

Namespaces

namespace  MatOps
 

Functions

static MoFEMErrorCode MatOps::getShutdownTimesFromOptions (std::vector< PetscReal > &shutdown_times_vec)
 
template<>
boost::shared_ptr< PhysicalEquations > MatOps::createMatOpsPhysicalEquationsPtr< AMENTUM_UMAT, MODEL_3D > (boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
 
template<>
boost::shared_ptr< PhysicalEquations > MatOps::createMatOpsPhysicalEquationsPtr< AMENTUM_UMAT, MODEL_2D_PLANE_STRAIN > (boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
 
MoFEMErrorCode MatOps::setAmentumTimeSource (boost::shared_ptr< PhysicalEquations > material, AmentumTimeSource source)
 
MoFEMErrorCode MatOps::getAmentumElasticProperties (boost::shared_ptr< PhysicalEquations > physics_ptr, FEMethod *fe_ptr, int nb_gauss_pts, const double *&young_modulus, double &poisson_ratio, const double *endpoint_modulus)
 
static std::string formatShutdownTimes (const std::vector< PetscReal > &times)
 
static std::string formatNextShutdownTime (const std::vector< PetscReal > &times)
 
static PetscErrorCode readAmentumOptions (TSAdapt adapt)
 
static PetscErrorCode TSAdaptSetFromOptionsAmentum (TSAdapt adapt, PetscOptionItems *options)
 
static PetscErrorCode chooseAmentumStepSize (TSAdapt adapt, TS ts, PetscReal h, PetscReal *next_h)
 
PetscErrorCode TSAdaptChooseAmentumRejected (TSAdapt adapt, TS ts, PetscReal h, PetscReal *next_h)
 
PetscErrorCode TSAdaptChooseAmentum (TSAdapt adapt, TS ts, PetscReal h, PetscInt *next_sc, PetscReal *next_h, PetscBool *accept, PetscReal *wlte, PetscReal *wltea, PetscReal *wlter)
 
PetscErrorCode TSAdaptResetAmentum (TSAdapt adapt)
 
PetscErrorCode TSAdaptDestroyAmentum (TSAdapt adapt)
 
PetscErrorCode TSAdaptCreateAmentum (TSAdapt adapt)
 

Variables

static constexpr PetscReal MatOps::AMENTUM_SHUTDOWN_STEP_LEN = 1e-7
 
static constexpr PetscReal MatOps::AMENTUM_SHUTDOWN_TIME_TOL = 1e-12
 

Function Documentation

◆ chooseAmentumStepSize()

static PetscErrorCode chooseAmentumStepSize ( TSAdapt  adapt,
TS  ts,
PetscReal  h,
PetscReal *  next_h 
)
static

Definition at line 734 of file MatAmentumUmat.cpp.

735 {
737 auto ts_adapt_amentum = static_cast<TSAdaptAmentum *>(adapt->data);
738 *next_h = h;
739 if (ts_adapt_amentum->offApat) {
740 CHKERR TSGetTimeStep(ts, next_h);
741 } else {
742
743 SNES snes;
744 CHKERR TSGetSNES(ts, &snes);
745
746 SNESConvergedReason reason;
747 CHKERR SNESGetConvergedReason(snes, &reason);
748
749 int it;
750 CHKERR SNESGetIterationNumber(snes, &it);
751
752 if (reason < 0) {
753 h *= ts_adapt_amentum->alpha;
754 *next_h = h;
756 "TSWORLD", Sev::warning,
757 "\tDiverged set step length: it = %d, h = %3.4g set h = %3.4g \n", it,
758 h, *next_h);
759 } else if (reason > 0) {
760 if (ts_adapt_amentum->fixedStepLen) {
761 *next_h = PetscClipInterval(ts_adapt_amentum->regularStepLen,
762 adapt->dt_min, adapt->dt_max);
763 } else {
764 h *= pow((static_cast<double>(ts_adapt_amentum->desiredIt) /
765 static_cast<double>(it + 1)),
766 static_cast<double>(ts_adapt_amentum->gamma));
767 *next_h = PetscClipInterval(h, adapt->dt_min, adapt->dt_max);
768 }
770 "TSWORLD", Sev::inform,
771 "\tConverged set step length: it = %d, h = %3.4g set h = %3.4g \n",
772 it, h, *next_h);
773 }
774 }
775
777}
int h
Corner vertex and its two front neighbours.
#define MOFEM_LOG_C(channel, severity, format,...)
It it
Definition Schur.cpp:2568
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
Custom TSAdaptivity in MoFEM for Amentum Umat.

◆ formatNextShutdownTime()

static std::string formatNextShutdownTime ( const std::vector< PetscReal > &  times)
static

Definition at line 671 of file MatAmentumUmat.cpp.

671 {
672 if (times.empty())
673 return "none";
674
675 std::ostringstream ss;
676 ss << times.front();
677 return ss.str();
678}

◆ formatShutdownTimes()

static std::string formatShutdownTimes ( const std::vector< PetscReal > &  times)
static

Definition at line 659 of file MatAmentumUmat.cpp.

659 {
660 std::ostringstream ss;
661 ss << "[";
662 for (auto it = times.begin(); it != times.end(); ++it) {
663 if (it != times.begin())
664 ss << ", ";
665 ss << *it;
666 }
667 ss << "]";
668 return ss.str();
669}

◆ readAmentumOptions()

static PetscErrorCode readAmentumOptions ( TSAdapt  adapt)
static

Definition at line 680 of file MatAmentumUmat.cpp.

680 {
682 auto &data = *static_cast<TSAdaptAmentum *>(adapt->data);
683 const char *prefix = nullptr;
684 CHKERR PetscObjectGetOptionsPrefix(reinterpret_cast<PetscObject>(adapt),
685 &prefix);
686 data.regularStepLen = .5;
687 data.alpha = .75;
688 data.gamma = .5;
689 data.desiredIt = 6;
690 data.offApat = PETSC_FALSE;
691 data.fixedStepLen = PETSC_FALSE;
693
694 CHKERR PetscOptionsGetScalar(prefix, "-ts_amentum_adapt_alpha", &data.alpha,
695 PETSC_NULLPTR);
696 CHKERR PetscOptionsGetScalar(prefix, "-ts_amentum_adapt_gamma", &data.gamma,
697 PETSC_NULLPTR);
698 CHKERR PetscOptionsGetInt(prefix, "-ts_amentum_adapt_desired_it", &data.desiredIt,
699 PETSC_NULLPTR);
700 CHKERR PetscOptionsGetBool(prefix, "-ts_amentum_adapt_off", &data.offApat,
701 PETSC_NULLPTR);
702 CHKERR PetscOptionsGetBool(prefix, "-ts_amentum_adapt_fixed_step_len",
703 &data.fixedStepLen, PETSC_NULLPTR);
704 CHKERR PetscOptionsGetReal(nullptr, prefix, "-ts_adapt_dt_min", &data.regularStepLen,
705 PETSC_NULLPTR);
706 if (!(data.alpha > 0 && data.alpha < 1) ||
707 !std::isfinite(data.gamma) || data.gamma < 0 || data.desiredIt <= 0 ||
708 !std::isfinite(data.regularStepLen) || data.regularStepLen <= 0)
709 SETERRQ(PetscObjectComm(reinterpret_cast<PetscObject>(adapt)),
710 MOFEM_INVALID_DATA, "Invalid Amentum time-step options");
711
712 MOFEM_LOG("TSWORLD", Sev::inform)
713 << "TS adaptivity: alpha = " << data.alpha << ", gamma = " << data.gamma
714 << ", desiredIt = " << data.desiredIt << ", offAdapt = " << data.offApat
715 << ", fixedStepLen = " << data.fixedStepLen
716 << ", regularStepLen = " << data.regularStepLen
717 << ", shutdownTimes = " << formatShutdownTimes(data.shutdownTimes)
718 << ", nextShutdownTime = " << formatNextShutdownTime(data.shutdownTimes);
720}
static std::string formatShutdownTimes(const std::vector< PetscReal > &times)
static std::string formatNextShutdownTime(const std::vector< PetscReal > &times)
@ MOFEM_INVALID_DATA
Definition definitions.h:36
#define MOFEM_LOG(channel, severity)
Log.
static MoFEMErrorCode getShutdownTimesFromOptions(std::vector< PetscReal > &shutdown_times_vec)
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetReal(PetscOptions *, const char pre[], const char name[], PetscReal *dval, PetscBool *set)
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
PetscErrorCode PetscOptionsGetScalar(PetscOptions *, const char pre[], const char name[], PetscScalar *dval, PetscBool *set)

◆ TSAdaptChooseAmentum()

PetscErrorCode TSAdaptChooseAmentum ( TSAdapt  adapt,
TS  ts,
PetscReal  h,
PetscInt *  next_sc,
PetscReal *  next_h,
PetscBool *  accept,
PetscReal *  wlte,
PetscReal *  wltea,
PetscReal *  wlter 
)

Definition at line 792 of file MatAmentumUmat.cpp.

795 {
797
798 auto ts_adapt_amentum = static_cast<TSAdaptAmentum *>(adapt->data);
799 const PetscReal accepted_step_len = h;
800
801 *next_sc = 0; /* Reuse the same order scheme */
802 *wlte = -1; /* Weighted local truncation error was not evaluated */
803 *wltea = -1; /* Weighted absolute local truncation error is not used */
804 *wlter = -1; /* Weighted relative local truncation error is not used */
805
806 *accept = PETSC_TRUE;
807 *next_h = h; /* Reuse the old step */
808
809 CHKERR chooseAmentumStepSize(adapt, ts, h, next_h);
810
811 PetscReal current_t;
812 CHKERR TSGetTime(ts, &current_t);
813
814 const PetscReal accepted_t = current_t + accepted_step_len;
815
816 if (ts_adapt_amentum->restoreAfterShutdown) {
818 ts_adapt_amentum->restoreAfterShutdown = PETSC_FALSE;
819 ts_adapt_amentum->rampUpAfterShutdown = PETSC_TRUE;
820 MOFEM_LOG_C("TSWORLD", Sev::inform,
821 "\tShutdown step complete: t = %3.12g set restore h = %3.4g\n",
822 accepted_t, *next_h);
823 } else if (ts_adapt_amentum->rampUpAfterShutdown) {
824 *next_h = ts_adapt_amentum->regularStepLen;
825 ts_adapt_amentum->rampUpAfterShutdown = PETSC_FALSE;
826 while (!ts_adapt_amentum->shutdownTimes.empty() &&
827 accepted_t >= ts_adapt_amentum->shutdownTimes.front() -
829 ts_adapt_amentum->shutdownTimes.erase(
830 ts_adapt_amentum->shutdownTimes.begin());
831 }
832 MOFEM_LOG_C("TSWORLD", Sev::inform,
833 "\tField restore step complete: t = %3.12g set h = %3.4g\n",
834 accepted_t, *next_h);
835 } else if (!ts_adapt_amentum->shutdownTimes.empty()) {
836 const PetscReal nextShutdownTime = ts_adapt_amentum->shutdownTimes.front();
837
838 if (PetscAbsReal(accepted_t - nextShutdownTime) <=
841 ts_adapt_amentum->restoreAfterShutdown = PETSC_TRUE;
842 MOFEM_LOG_C("TSWORLD", Sev::inform,
843 "\tShutdown step after t = %3.12g set h = %3.4g \n",
844 accepted_t, *next_h);
845 } else {
846 const PetscReal next_t = accepted_t + *next_h;
847 if (accepted_t < nextShutdownTime && next_t >= nextShutdownTime) {
848 *next_h = nextShutdownTime - accepted_t;
849 MOFEM_LOG_C("TSWORLD", Sev::inform,
850 "\tClip step to shutdown: t = %3.12g shutdown = "
851 "%3.12g set h = %3.4g \n",
852 accepted_t, nextShutdownTime, *next_h);
853 }
854 }
855 }
856
858}
std::function< bool(size_t)> accept
Definition CGALTools.cpp:61
static PetscErrorCode chooseAmentumStepSize(TSAdapt adapt, TS ts, PetscReal h, PetscReal *next_h)
static constexpr PetscReal AMENTUM_SHUTDOWN_TIME_TOL
static constexpr PetscReal AMENTUM_SHUTDOWN_STEP_LEN

◆ TSAdaptChooseAmentumRejected()

PetscErrorCode TSAdaptChooseAmentumRejected ( TSAdapt  adapt,
TS  ts,
PetscReal  h,
PetscReal *  next_h 
)

Apply the same step-size rule to a failed physical trial, without advancing the shutdown state. The supplied TS carries the failed SNES feedback.

Definition at line 779 of file MatAmentumUmat.cpp.

780 {
782 PetscBool amentum = PETSC_FALSE;
783 CHKERR PetscObjectTypeCompare(reinterpret_cast<PetscObject>(adapt),
784 TSADAPTAMENTUM, &amentum);
785 if (!amentum)
786 SETERRQ(PetscObjectComm(reinterpret_cast<PetscObject>(adapt)),
787 MOFEM_INVALID_DATA, "Rejected physical step requires Amentum adaptivity");
788 CHKERR chooseAmentumStepSize(adapt, ts, h, next_h);
790}
#define TSADAPTAMENTUM

◆ TSAdaptCreateAmentum()

PetscErrorCode TSAdaptCreateAmentum ( TSAdapt  adapt)

Definition at line 876 of file MatAmentumUmat.cpp.

876 {
877 PetscFunctionBegin;
878 adapt->data = new TSAdaptAmentum();
879 adapt->ops->choose = TSAdaptChooseAmentum;
880 adapt->ops->setfromoptions = TSAdaptSetFromOptionsAmentum;
881 adapt->ops->reset = TSAdaptResetAmentum;
882 adapt->ops->destroy = TSAdaptDestroyAmentum;
883 PetscFunctionReturn(0);
884}
PetscErrorCode TSAdaptChooseAmentum(TSAdapt adapt, TS ts, PetscReal h, PetscInt *next_sc, PetscReal *next_h, PetscBool *accept, PetscReal *wlte, PetscReal *wltea, PetscReal *wlter)
PetscErrorCode TSAdaptResetAmentum(TSAdapt adapt)
PetscErrorCode TSAdaptDestroyAmentum(TSAdapt adapt)
static PetscErrorCode TSAdaptSetFromOptionsAmentum(TSAdapt adapt, PetscOptionItems *options)

◆ TSAdaptDestroyAmentum()

PetscErrorCode TSAdaptDestroyAmentum ( TSAdapt  adapt)

Definition at line 869 of file MatAmentumUmat.cpp.

869 {
871 delete static_cast<TSAdaptAmentum *>(adapt->data);
872 adapt->data = nullptr;
874}

◆ TSAdaptResetAmentum()

PetscErrorCode TSAdaptResetAmentum ( TSAdapt  adapt)

Definition at line 860 of file MatAmentumUmat.cpp.

860 {
861 PetscFunctionBegin;
862 if (adapt->data) {
863 *static_cast<TSAdaptAmentum *>(adapt->data) = TSAdaptAmentum();
864 PetscCall(readAmentumOptions(adapt));
865 }
866 PetscFunctionReturn(0);
867}
static PetscErrorCode readAmentumOptions(TSAdapt adapt)

◆ TSAdaptSetFromOptionsAmentum()

static PetscErrorCode TSAdaptSetFromOptionsAmentum ( TSAdapt  adapt,
PetscOptionItems *  options 
)
static

Definition at line 722 of file MatAmentumUmat.cpp.

723 {
725 // PETSc passes the parent TS options block; TSGetAdapt does not inherit its
726 // object prefix. Retain that prefix on the adaptor for subsequent resets.
727 CHKERR TSAdaptSetOptionsPrefix(adapt, options->prefix);
730}