v0.16.3
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
EshelbianPlasticity::IncrementalMechanics Struct Reference

#include "users_modules/eshelbian_plasticity/src/IncrementalMechanics.hpp"

Collaboration diagram for EshelbianPlasticity::IncrementalMechanics:
[legend]

Public Types

using FieldSnapshot = std::map< EntityHandle, std::vector< double > >
 

Public Member Functions

 IncrementalMechanics (EshelbianCore &ep, SmartPetscObj< TS > ts)
 
TS getTS () const
 
void addStateControlField (const std::string &field)
 
void addHistoryField (const std::string &field)
 
MoFEMErrorCode solveState (Vec state, EquilibriumSolveReport &report)
 
MoFEMErrorCode fixedDataAreCurrent (bool &current)
 
MoFEMErrorCode restoreState (Vec state)
 
MoFEMErrorCode evaluateBaseline (Vec state, double &value)
 
MoFEMErrorCode evaluateConservativeValue (double &value)
 
MoFEMErrorCode assembleConservativeGradient (DM control_dm, Vec gradient)
 
bool supportsHessianAction () const
 
MoFEMErrorCode prepareHessian (DM control_dm, Vec control)
 
MoFEMErrorCode applyHessian (Vec direction, Vec action)
 
MoFEMErrorCode assembleHessianPreconditioner (Mat metric)
 
PetscInt getMechanicalSolveCount () const
 
PetscInt getDirectionalSolveCount () const
 

Private Member Functions

MoFEMErrorCode publishTrialControl ()
 
MoFEMErrorCode stateControlBlocksEqual (Vec first, Vec second, PetscBool &equal)
 
MoFEMErrorCode zeroStateControlBlocks (Vec control)
 
MoFEMErrorCode snapshotHistory (std::vector< FieldSnapshot > &snapshot)
 
MoFEMErrorCode refreshConservativeGradient (DM control_dm)
 

Private Attributes

EshelbianCore & ep
 
SmartPetscObj< TS > timeSolver
 
std::vector< std::string > stateControlFields
 
std::vector< std::string > historyFields
 
SmartPetscObj< Vec > cachedControl
 
SmartPetscObj< Vec > cachedState
 
EquilibriumSolveReport cachedReport
 
std::vector< FieldSnapshot > cachedHistory
 
double cachedPhysicalTime = 0
 
bool cacheValid = false
 
PetscInt mechanicalSolves = 0
 
SmartPetscObj< Vec > cachedGradient
 
bool gradientValid = false
 
boost::shared_ptr< PlasticIncrementalOptimizationInternal::ReducedBulkMaterialEnergyHessianWorkspace > gradientWorkspace
 
boost::shared_ptr< PlasticIncrementalOptimizationInternal::ReducedBulkMaterialEnergyHessianWorkspace > hessianWorkspace
 

Detailed Description

Mechanical state of the incremental optimisation.

One object serves every physics. It owns the fixed-control TS equilibrium solve with its cache, the zero-increment baseline, the bulk Helmholtz value, the base adjoint of the reduced conservative gradient and the frozen tangents of the reduced Hessian action. A physics registers the control fields that enter equilibrium, so only their blocks of the trial control key the state cache, and the mesh history fields whose change invalidates that cache. The mechanical pipelines read the registered control fields from EshelbianCore::incrementalTrialControl.

Definition at line 34 of file IncrementalMechanics.hpp.

Member Typedef Documentation

◆ FieldSnapshot

using EshelbianPlasticity::IncrementalMechanics::FieldSnapshot = std::map<EntityHandle, std::vector<double> >

Definition at line 35 of file IncrementalMechanics.hpp.

Constructor & Destructor Documentation

◆ IncrementalMechanics()

EshelbianPlasticity::IncrementalMechanics::IncrementalMechanics ( EshelbianCore &  ep,
SmartPetscObj< TS >  ts 
)

Definition at line 20 of file IncrementalMechanics.cpp.

Member Function Documentation

◆ addHistoryField()

void EshelbianPlasticity::IncrementalMechanics::addHistoryField ( const std::string &  field)
inline

Definition at line 43 of file IncrementalMechanics.hpp.

43 {
44 historyFields.push_back(field);
45 }

◆ addStateControlField()

void EshelbianPlasticity::IncrementalMechanics::addStateControlField ( const std::string &  field)
inline

Definition at line 40 of file IncrementalMechanics.hpp.

40 {
41 stateControlFields.push_back(field);
42 }

◆ applyHessian()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::applyHessian ( Vec  direction,
Vec  action 
)

Write the reduced mechanical Hessian action in direction to action through one tangent-state and one incremental-adjoint solve.

Definition at line 260 of file IncrementalMechanics.cpp.

260 {
262 if (!hessianWorkspace)
264 "Mechanical Hessian action requested before prepareHessian()");
268}
boost::shared_ptr< MatrixDouble > direction
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
MoFEMErrorCode assembleReducedBulkMaterialEnergyHessianAction(EshelbianCore &ep, TS ts, ReducedBulkMaterialEnergyHessianWorkspace &workspace, Vec direction, Vec action)
MoFEM::Interface & mField
boost::shared_ptr< PlasticIncrementalOptimizationInternal::ReducedBulkMaterialEnergyHessianWorkspace > hessianWorkspace
virtual MPI_Comm & get_comm() const =0

◆ assembleConservativeGradient()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::assembleConservativeGradient ( DM  control_dm,
Vec  gradient 
)

Reduced conservative gradient on control_dm through the base adjoint; cached until the next equilibrium solve.

Definition at line 230 of file IncrementalMechanics.cpp.

◆ assembleHessianPreconditioner()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::assembleHessianPreconditioner ( Mat  metric)

Add the frozen material curvature block to the SPD metric.

Definition at line 270 of file IncrementalMechanics.cpp.

270 {
272 if (!hessianWorkspace)
274 "Mechanical metric block requested before prepareHessian()");
276 ep, *hessianWorkspace, metric, false);
278}
SmartPetscObj< Mat > metric
MoFEMErrorCode assembleReducedBulkMaterialEnergyFlowPreconditioner(EshelbianCore &ep, ReducedBulkMaterialEnergyHessianWorkspace &workspace, Mat preconditioner, bool retain_base_adjoint=true)

◆ evaluateBaseline()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::evaluateBaseline ( Vec  state,
double &  value 
)

Equilibrium with the registered control blocks zeroed and its Helmholtz value; the trial control is restored afterwards.

Definition at line 168 of file IncrementalMechanics.cpp.

169 {
171 // The baseline is the equilibrium without any increment. Zero the control
172 // blocks that enter equilibrium, solve, and put the trial control back so
173 // the current trial is not lost.
174 auto trial_before = vectorDuplicate(ep.incrementalTrialControl);
175 CHKERR VecCopy(ep.incrementalTrialControl, trial_before);
177 EquilibriumSolveReport report;
178 const MoFEMErrorCode solve_error =
180 MoFEMErrorCode value_error = 0;
181 if (!solve_error && report.status == EquilibriumSolveStatus::Converged)
183 CHKERR VecCopy(trial_before, ep.incrementalTrialControl);
184 CHKERR VecGhostUpdateBegin(ep.incrementalTrialControl, INSERT_VALUES,
185 SCATTER_FORWARD);
186 CHKERR VecGhostUpdateEnd(ep.incrementalTrialControl, INSERT_VALUES,
187 SCATTER_FORWARD);
188 CHKERR solve_error;
189 if (report.status != EquilibriumSolveStatus::Converged)
191 "Zero-increment baseline did not equilibrate (residual %g)",
192 report.equilibriumNorm);
193 CHKERR value_error;
195}
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
MoFEMErrorCode solveEquilibriumStateTS(TopologicalTAOCtxImpl *ctx_impl_ptr)
MoFEMErrorCode evaluateEquilibratedMechanicalValue(EshelbianCore &ep, TS ts, double &value)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
SmartPetscObj< Vec > incrementalTrialControl

◆ evaluateConservativeValue()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::evaluateConservativeValue ( double &  value)

Bulk Helmholtz free energy of the state on the mesh.

Definition at line 197 of file IncrementalMechanics.cpp.

197 {
199}

◆ fixedDataAreCurrent()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::fixedDataAreCurrent ( bool &  current)

Whether the histories and the physical time still match the cache.

Definition at line 145 of file IncrementalMechanics.cpp.

145 {
147 current = true;
148 if (!cacheValid)
150 std::vector<FieldSnapshot> history;
151 CHKERR snapshotHistory(history);
152 int local_changed =
154 int changed = 0;
155 CHKERR MPI_Allreduce(&local_changed, &changed, 1, MPI_INT, MPI_MAX,
156 ep.mField.get_comm());
157 current = !changed;
159}
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
static double currentPhysicalTime
MoFEMErrorCode snapshotHistory(std::vector< FieldSnapshot > &snapshot)

◆ getDirectionalSolveCount()

PetscInt EshelbianPlasticity::IncrementalMechanics::getDirectionalSolveCount ( ) const

Definition at line 280 of file IncrementalMechanics.cpp.

280 {
283 : 0;
284}
PetscInt getReducedBulkMaterialEnergyDirectionalSolveCount(const ReducedBulkMaterialEnergyHessianWorkspace &workspace)

◆ getMechanicalSolveCount()

PetscInt EshelbianPlasticity::IncrementalMechanics::getMechanicalSolveCount ( ) const
inline

◆ getTS()

TS EshelbianPlasticity::IncrementalMechanics::getTS ( ) const
inline

Definition at line 39 of file IncrementalMechanics.hpp.

39{ return timeSolver.get(); }

◆ prepareHessian()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::prepareHessian ( DM  control_dm,
Vec  control 
)

Freeze the base adjoint and the tangent matrices at control.

Definition at line 244 of file IncrementalMechanics.cpp.

245 {
249 "The selected material does not provide the curvature of the "
250 "reduced mechanical energy");
251 if (!gradientValid)
253 if (!hessianWorkspace)
258}
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
MoFEMErrorCode freezeReducedBulkMaterialEnergyHessian(const ReducedBulkMaterialEnergyHessianWorkspace &source, Vec control, ReducedBulkMaterialEnergyHessianWorkspace &target)
boost::shared_ptr< ReducedBulkMaterialEnergyHessianWorkspace > createReducedBulkMaterialEnergyHessianWorkspace()
boost::shared_ptr< PlasticIncrementalOptimizationInternal::ReducedBulkMaterialEnergyHessianWorkspace > gradientWorkspace

◆ publishTrialControl()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::publishTrialControl ( )
private

Definition at line 24 of file IncrementalMechanics.cpp.

24 {
28 "Incremental-optimisation control storage is unavailable");
29 CHKERR VecGhostUpdateBegin(ep.incrementalTrialControl, INSERT_VALUES,
30 SCATTER_FORWARD);
31 CHKERR VecGhostUpdateEnd(ep.incrementalTrialControl, INSERT_VALUES,
32 SCATTER_FORWARD);
34 ep.incrementalTrialControl, INSERT_VALUES,
35 SCATTER_REVERSE, RowColData::ROW);
37}
@ ROW
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set local (or ghosted) vector values on mesh for partition only
Definition DMMoFEM.cpp:543
SmartPetscObj< DM > dmIncrementalOptimization

◆ refreshConservativeGradient()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::refreshConservativeGradient ( DM  control_dm)
private

Definition at line 202 of file IncrementalMechanics.cpp.

202 {
204 if (!cacheValid || !cachedState)
206 "The conservative gradient needs an equilibrated state");
207 if (!cachedGradient)
208 cachedGradient = createDMVector(control_dm);
209 CHKERR VecZeroEntries(cachedGradient);
210 if (supportsHessianAction()) {
211 // Keep the base adjoint; prepareHessian() freezes it for the shell.
218 ep, control_dm,
221 } else {
224 }
225 gradientValid = true;
227}
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
Definition DMMoFEM.hpp:1250
MoFEMErrorCode assemblePlasticAdjointContribution(EshelbianCore &ep, DM flow_output_dm, Vec adjoint, Vec gradient)
MoFEMErrorCode assembleReducedBulkMaterialEnergyGradient(EshelbianCore &ep, TS ts, Vec gradient)
MoFEMErrorCode prepareReducedBulkMaterialEnergyHessian(EshelbianCore &ep, TS ts, Vec control, Vec equilibrated_state, ReducedBulkMaterialEnergyHessianWorkspace &workspace)
Vec getReducedBulkMaterialEnergyBaseAdjoint(const ReducedBulkMaterialEnergyHessianWorkspace &workspace)

◆ restoreState()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::restoreState ( Vec  state)

Put the trial control and state back on the mesh.

Definition at line 161 of file IncrementalMechanics.cpp.

◆ snapshotHistory()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::snapshotHistory ( std::vector< FieldSnapshot > &  snapshot)
private

Definition at line 82 of file IncrementalMechanics.cpp.

82 {
84 snapshot.clear();
85 snapshot.resize(historyFields.size());
86 for (std::size_t f = 0; f != historyFields.size(); ++f) {
87 auto &field_snapshot = snapshot[f];
88 auto save = [&](boost::shared_ptr<FieldEntity> field_entity) {
90 auto data = field_entity->getEntFieldData();
91 field_snapshot.emplace(field_entity->getEnt(),
92 std::vector<double>(data.begin(), data.end()));
94 };
95 CHKERR ep.mField.getInterface<FieldBlas>()->fieldLambdaOnEntities(
96 save, historyFields[f]);
97 }
99}
boost::shared_ptr< DataAtIntegrationPts > data
Basic algebra on fields.
Definition FieldBlas.hpp:21
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.

◆ solveState()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::solveState ( Vec  state,
EquilibriumSolveReport &  report 
)

Publish the trial control and equilibrate; a cached state is reused when the registered control blocks, histories and time are unchanged.

Definition at line 102 of file IncrementalMechanics.cpp.

102 {
105 std::vector<FieldSnapshot> history;
106 CHKERR snapshotHistory(history);
107 PetscBool same_control = PETSC_FALSE;
108 if (cacheValid)
110 same_control);
111 int local_changed = !cacheValid || !same_control ||
113 history != cachedHistory;
114 int changed = 0;
115 CHKERR MPI_Allreduce(&local_changed, &changed, 1, MPI_INT, MPI_MAX,
116 ep.mField.get_comm());
117 if (!changed) {
118 CHKERR VecCopy(cachedState, state);
120 report = cachedReport;
121 report.mechanicalSolveCount = 0;
123 }
124 // Only converged states are cached. A rejected trial keeps the previous
125 // cache usable while the optimiser rolls the control back.
126 gradientValid = false;
129 report.mechanicalSolveCount = 1;
130 if (report.status == EquilibriumSolveStatus::Converged) {
131 if (!cachedControl)
133 if (!cachedState)
136 CHKERR VecCopy(state, cachedState);
137 cachedHistory = std::move(history);
139 cachedReport = report;
140 cacheValid = true;
141 }
143}
MoFEMErrorCode stateControlBlocksEqual(Vec first, Vec second, PetscBool &equal)

◆ stateControlBlocksEqual()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::stateControlBlocksEqual ( Vec  first,
Vec  second,
PetscBool &  equal 
)
private

Definition at line 39 of file IncrementalMechanics.cpp.

41 {
43 equal = PETSC_TRUE;
44 for (const auto &field : stateControlFields) {
45 IS raw_is = nullptr;
47 field.c_str(), &raw_is);
48 SmartPetscObj<IS> field_is(raw_is);
49 Vec first_block = nullptr, second_block = nullptr;
50 CHKERR VecGetSubVector(first, field_is, &first_block);
51 CHKERR VecGetSubVector(second, field_is, &second_block);
52 PetscBool block_equal = PETSC_FALSE;
53 CHKERR VecEqual(first_block, second_block, &block_equal);
54 CHKERR VecRestoreSubVector(second, field_is, &second_block);
55 CHKERR VecRestoreSubVector(first, field_is, &first_block);
56 if (!block_equal) {
57 equal = PETSC_FALSE;
58 break;
59 }
60 }
62}
PetscErrorCode DMMoFEMGetFieldIS(DM dm, RowColData rc, const char field_name[], IS *is)
get field is in the problem
Definition DMMoFEM.cpp:1536
const FTensor::Tensor2< T, Dim, Dim > Vec
intrusive_ptr for managing petsc objects

◆ supportsHessianAction()

bool EshelbianPlasticity::IncrementalMechanics::supportsHessianAction ( ) const

Whether the material provides the curvature used by applyHessian().

Definition at line 239 of file IncrementalMechanics.cpp.

239 {
240 return ep.physicalEquations &&
241 ep.physicalEquations->providesHelmholtzCurvature();
242}
boost::shared_ptr< PhysicalEquations > physicalEquations

◆ zeroStateControlBlocks()

MoFEMErrorCode EshelbianPlasticity::IncrementalMechanics::zeroStateControlBlocks ( Vec  control)
private

Definition at line 64 of file IncrementalMechanics.cpp.

64 {
66 for (const auto &field : stateControlFields) {
67 IS raw_is = nullptr;
69 field.c_str(), &raw_is);
70 SmartPetscObj<IS> field_is(raw_is);
71 Vec block = nullptr;
72 CHKERR VecGetSubVector(control, field_is, &block);
73 CHKERR VecZeroEntries(block);
74 CHKERR VecRestoreSubVector(control, field_is, &block);
75 }
76 CHKERR VecGhostUpdateBegin(control, INSERT_VALUES, SCATTER_FORWARD);
77 CHKERR VecGhostUpdateEnd(control, INSERT_VALUES, SCATTER_FORWARD);
79}

Member Data Documentation

◆ cachedControl

SmartPetscObj<Vec> EshelbianPlasticity::IncrementalMechanics::cachedControl
private

Definition at line 89 of file IncrementalMechanics.hpp.

◆ cachedGradient

SmartPetscObj<Vec> EshelbianPlasticity::IncrementalMechanics::cachedGradient
private

Definition at line 97 of file IncrementalMechanics.hpp.

◆ cachedHistory

std::vector<FieldSnapshot> EshelbianPlasticity::IncrementalMechanics::cachedHistory
private

Definition at line 92 of file IncrementalMechanics.hpp.

◆ cachedPhysicalTime

double EshelbianPlasticity::IncrementalMechanics::cachedPhysicalTime = 0
private

Definition at line 93 of file IncrementalMechanics.hpp.

◆ cachedReport

EquilibriumSolveReport EshelbianPlasticity::IncrementalMechanics::cachedReport
private

Definition at line 91 of file IncrementalMechanics.hpp.

◆ cachedState

SmartPetscObj<Vec> EshelbianPlasticity::IncrementalMechanics::cachedState
private

Definition at line 90 of file IncrementalMechanics.hpp.

◆ cacheValid

bool EshelbianPlasticity::IncrementalMechanics::cacheValid = false
private

Definition at line 94 of file IncrementalMechanics.hpp.

◆ ep

EshelbianCore& EshelbianPlasticity::IncrementalMechanics::ep
private

Definition at line 84 of file IncrementalMechanics.hpp.

◆ gradientValid

bool EshelbianPlasticity::IncrementalMechanics::gradientValid = false
private

Definition at line 98 of file IncrementalMechanics.hpp.

◆ gradientWorkspace

boost::shared_ptr<PlasticIncrementalOptimizationInternal:: ReducedBulkMaterialEnergyHessianWorkspace> EshelbianPlasticity::IncrementalMechanics::gradientWorkspace
private

Definition at line 101 of file IncrementalMechanics.hpp.

◆ hessianWorkspace

boost::shared_ptr<PlasticIncrementalOptimizationInternal:: ReducedBulkMaterialEnergyHessianWorkspace> EshelbianPlasticity::IncrementalMechanics::hessianWorkspace
private

Definition at line 101 of file IncrementalMechanics.hpp.

◆ historyFields

std::vector<std::string> EshelbianPlasticity::IncrementalMechanics::historyFields
private

Definition at line 87 of file IncrementalMechanics.hpp.

◆ mechanicalSolves

PetscInt EshelbianPlasticity::IncrementalMechanics::mechanicalSolves = 0
private

Definition at line 95 of file IncrementalMechanics.hpp.

◆ stateControlFields

std::vector<std::string> EshelbianPlasticity::IncrementalMechanics::stateControlFields
private

Definition at line 86 of file IncrementalMechanics.hpp.

◆ timeSolver

SmartPetscObj<TS> EshelbianPlasticity::IncrementalMechanics::timeSolver
private

Definition at line 85 of file IncrementalMechanics.hpp.


The documentation for this struct was generated from the following files: