Skip to content

Commit

Permalink
Add elastic inversion capability using batch materials
Browse files Browse the repository at this point in the history
Add documentation and tests

Refs idaholab#352
  • Loading branch information
dewenyushu committed Jun 9, 2023
1 parent 1dcccdb commit e494fc0
Show file tree
Hide file tree
Showing 12 changed files with 728 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
###############################################################################
#
# Optional Environment variables
# MOOSE_DIR - Root directory of the MOOSE project
# MOOSE_DIR - Root directory of the MOOSE project
#
###############################################################################
# Use the MOOSE submodule if it exists and MOOSE_DIR is not set
Expand Down Expand Up @@ -40,6 +40,7 @@ TENSOR_MECHANICS := yes
WATER_STEAM_EOS := no
XFEM := yes
POROUS_FLOW := no
OPTIMIZATION := yes

include $(MOOSE_DIR)/modules/modules.mk
###############################################################################
Expand Down
22 changes: 22 additions & 0 deletions doc/content/source/userobjects/BatchStressGrad.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# BatchStressGrad

## Description

This `UserObject` computes double contraction of the elastic tensor derivative and the forward mechanical strain, i.e.,
\begin{equation}
\underbrace{\frac{\partial \boldsymbol{C}}{\partial p}}_{\text{elastic tensor derivative}} \underbrace{(\boldsymbol{L} u)}_{\text{forward strain}}
\end{equation}
as a batch material.
Here, the $\boldsymbol{C}$ is the elastic tensor, $p$ is the interested parameter, $\boldsymbol{L}$ is the differential operator for elasticity problem, and $\boldsymbol{L} u$ is strain from the forward problem. This object requires the elastic tensor derivative material property (i.e., $\frac{\partial \boldsymbol{C}}{\partial p}$) as its input.

This object is used together with [AdjointStrainStressGradInnerProduct](/AdjointStrainStressGradInnerProduct.md) in a elastic inversion problem.

## Example Input File Syntax

!listing examples/bimaterialElastic_batch_mat/grad.i block=UserObjects/stress_grad_lambda

!syntax parameters /UserObjects/BatchStressGrad

!syntax inputs /UserObjects/BatchStressGrad

!syntax children /UserObjects/BatchStressGrad
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# AdjointStrainStressGradInnerProduct

!syntax description /VectorPostprocessors/AdjointStrainStressGradInnerProduct

## Description

This `VectorPostprocessor` computes the gradient of objective function with respect to interested parameter for elastic problem. Specifically,
\begin{equation}
\frac{\text{d}\boldsymbol{F}}{\text{d}p} = - \int \underbrace{(\boldsymbol{L}\lambda)^T}_{\text{adjoint strain}} \underbrace{\frac{\partial \boldsymbol{C}}{\partial p} (\boldsymbol{L} u)}_{\text{stress gradient}} \text{d}\Omega,
\end{equation}
where $\boldsymbol{F}$ is the objective function, $\boldsymbol{L}$ is the differential operator for the elasticity problem, $\lambda$ is the adjoint displacement, $\boldsymbol{C}$ is the elastic tensor, $p$ is the interested parameter, and $u$ is displacement from the forward problem.

Specifically, this object takes the `adjoint strain` and the `stress gradient` as inputs, computes the double contraction of the two inputs, and integrate over the entire domain. Specifically, the `adjoint strain` is the strain from the adjoint problem, the `stress gradient` should be a batch material (e.g., [BatchStressGrad](/BatchStressGrad.md)).

## Example Input File Syntax

!listing examples/bimaterialElastic_batch_mat/grad.i block=VectorPostprocessors/grad_lambda

!syntax parameters /VectorPostprocessors/AdjointStrainStressGradInnerProduct

!syntax inputs /VectorPostprocessors/AdjointStrainStressGradInnerProduct

!syntax children /VectorPostprocessors/AdjointStrainStressGradInnerProduct
33 changes: 33 additions & 0 deletions include/userobjects/BatchStressGrad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "BatchMaterial.h"

typedef BatchMaterial<
// tuple representation
BatchMaterialUtils::TupleStd,
// output data type
RankTwoTensor,
// gathered input data types:
BatchMaterialUtils::GatherMatProp<RankFourTensor>,
BatchMaterialUtils::GatherMatProp<RankTwoTensor>>

BatchStressGradParent;

class BatchStressGrad : public BatchStressGradParent
{
public:
static InputParameters validParams();

BatchStressGrad(const InputParameters & params);

void batchCompute() override;
};
31 changes: 31 additions & 0 deletions include/vectorpostprocessors/AdjointStrainStressGradInnerProduct.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "ElementOptimizationFunctionInnerProduct.h"
#include "BatchStressGrad.h"

class AdjointStrainStressGradInnerProduct : public ElementOptimizationFunctionInnerProduct
{
public:
static InputParameters validParams();

AdjointStrainStressGradInnerProduct(const InputParameters & parameters);

protected:
virtual Real computeQpInnerProduct() override;
/// Base name of the material system
const std::string _base_name;
/// Holds adjoint strain at current quadrature points
const MaterialProperty<RankTwoTensor> & _adjoint_strain;
/// UO that holds gradient of stress wrt material parameter at current quadrature points
const BatchStressGrad & _stress_grad_uo;
const BatchStressGrad::OutputVector & _stress_grad_uo_output;
};
46 changes: 46 additions & 0 deletions src/userobjects/BatchStressGrad.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "BatchStressGrad.h"
#include "libmesh/int_range.h"

registerMooseObject("BlackBearApp", BatchStressGrad);

InputParameters
BatchStressGrad::validParams()
{
auto params = BatchStressGradParent::validParams();
params.addRequiredParam<MaterialPropertyName>(
"elastic_tensor_derivative", "Name of the elastic tensor derivative material property.");
return params;
}

BatchStressGrad::BatchStressGrad(const InputParameters & params)
: BatchStressGradParent(params,
// here we pass the derivative of elastic tensor wrt to the parameter
"elastic_tensor_derivative",
// here we pass in the forward strain
"forward_mechanical_strain")
{
}

void
BatchStressGrad::batchCompute()
{
for (const auto i : index_range(_input_data))
{
const auto & input = _input_data[i];
auto & output = _output_data[i];

const auto & elasticity_dev = std::get<0>(input);
const auto & strain = std::get<1>(input);

output = elasticity_dev * strain;
}
}
49 changes: 49 additions & 0 deletions src/vectorpostprocessors/AdjointStrainStressGradInnerProduct.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "AdjointStrainStressGradInnerProduct.h"

registerMooseObject("BlackBearApp", AdjointStrainStressGradInnerProduct);

InputParameters
AdjointStrainStressGradInnerProduct::validParams()
{
InputParameters params = ElementOptimizationFunctionInnerProduct::validParams();
params.addRequiredParam<UserObjectName>(
"stress_grad_name",
"Name of the stress gradient user object with respect to the material parameter");

params.addRequiredParam<MaterialPropertyName>(
"adjoint_strain_name",
"Name of the strain property in the adjoint problem");

params.addClassDescription("Compute the gradient for elastic material inversion");
return params;
}
AdjointStrainStressGradInnerProduct::
AdjointStrainStressGradInnerProduct(const InputParameters & parameters)
: ElementOptimizationFunctionInnerProduct(parameters),
_base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
_adjoint_strain(getMaterialPropertyByName<RankTwoTensor>(
getParam<MaterialPropertyName>("adjoint_strain_name"))),
_stress_grad_uo(getUserObject<BatchStressGrad>("stress_grad_name")),
_stress_grad_uo_output(_stress_grad_uo.getOutputData())
{
}

Real
AdjointStrainStressGradInnerProduct::computeQpInnerProduct()
{
if (!_stress_grad_uo.outputReady())
mooseError("Stress gradient batch material property is not ready to output.");

const auto index = _stress_grad_uo.getIndex(_current_elem->id());

return -_adjoint_strain[_qp].doubleContraction(_stress_grad_uo_output[index + _qp]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
grad_lambda,grad_mu,lambda,measurement_time,measurement_values,measurement_xcoord,measurement_ycoord,measurement_zcoord,misfit_values,mu,simulation_values
6.1849349929517e-08,2.7439401009507e-06,4.9999848958062,0,4.46462,-1,-1,0,-1.3156694844696e-07,1.0000001501249,4.4646198684331
6.0822263185714e-09,2.2329018523184e-07,4.0000654135139,0,6.447155,-1,0,0,-1.5608052539307e-07,2.0000014605072,6.4471548439195
1.5709256099651e-09,3.1031720332756e-09,3.0001400501022,0,8.434803,-1,1,0,-1.6059464336138e-07,2.9999869855298,8.4348028394054
0,0,0,0,4.176264,0,-1,0,-1.5114235196734e-07,0,4.1762638488576
0,0,0,0,6.172984,0,0,0,-1.7986893752209e-07,0,6.1729838201311
0,0,0,0,8.200859,0,1,0,5.6683557403403e-08,0,8.2008590566836
0,0,0,0,4.049477,1,-1,0,1.9859902877783e-07,0,4.049477198599
0,0,0,0,6.052499,1,0,0,3.469401415046e-07,0,6.0524993469401
0,0,0,0,8.079385,1,1,0,-2.7443372196956e-07,0,8.0793847255663
Loading

0 comments on commit e494fc0

Please sign in to comment.