From 6198c483b41ce54992c93ab4a155d871e01c7995 Mon Sep 17 00:00:00 2001 From: dewenyushu Date: Tue, 27 Jun 2023 16:08:27 -0700 Subject: [PATCH 1/2] Add elastic inversion capability using batch materials Refs #77 --- .../source/userobjects/BatchStressGrad.md | 22 ++ .../AdjointStrainStressGradInnerProduct.md | 31 +++ include/userobjects/BatchStressGrad.h | 33 +++ .../AdjointStrainStressGradInnerProduct.h | 31 +++ src/userobjects/BatchStressGrad.C | 54 +++++ .../AdjointStrainStressGradInnerProduct.C | 49 +++++ .../main_out_OptimizationReporter_0001.csv | 10 + .../grad.i | 204 ++++++++++++++++++ .../main.i | 126 +++++++++++ .../model.i | 166 ++++++++++++++ .../tests | 16 ++ 11 files changed, 742 insertions(+) create mode 100644 doc/content/source/userobjects/BatchStressGrad.md create mode 100644 doc/content/source/vectorpostprocessors/AdjointStrainStressGradInnerProduct.md create mode 100644 include/userobjects/BatchStressGrad.h create mode 100644 include/vectorpostprocessors/AdjointStrainStressGradInnerProduct.h create mode 100644 src/userobjects/BatchStressGrad.C create mode 100644 src/vectorpostprocessors/AdjointStrainStressGradInnerProduct.C create mode 100644 test/tests/bimaterial_elastic_inversion_batch_mat/gold/main_out_OptimizationReporter_0001.csv create mode 100644 test/tests/bimaterial_elastic_inversion_batch_mat/grad.i create mode 100644 test/tests/bimaterial_elastic_inversion_batch_mat/main.i create mode 100644 test/tests/bimaterial_elastic_inversion_batch_mat/model.i create mode 100644 test/tests/bimaterial_elastic_inversion_batch_mat/tests diff --git a/doc/content/source/userobjects/BatchStressGrad.md b/doc/content/source/userobjects/BatchStressGrad.md new file mode 100644 index 00000000..d9f8e4c3 --- /dev/null +++ b/doc/content/source/userobjects/BatchStressGrad.md @@ -0,0 +1,22 @@ +# BatchStressGrad + +## Description + +This `UserObject` computes double contraction of the elasticity tensor derivative and the forward mechanical strain, i.e., +\begin{equation} +\underbrace{\frac{\partial \boldsymbol{C}}{\partial p}}_{\text{elasticity tensor derivative}} \underbrace{(\boldsymbol{L} u)}_{\text{forward strain}} +\end{equation} +as a batch material. +Here, $\boldsymbol{C}$ is the elasticity tensor, $p$ is the interested parameter, $\boldsymbol{L}$ is the symmetric strain operator for the elasticity problem, and $\boldsymbol{L} u$ is the strain from the forward problem. This object requires the elasticity 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 linear elastic inversion problem. + +## Example Input File Syntax + +!listing test/tests/bimaterial_elastic_inversion_batch_mat/grad.i block=UserObjects/stress_grad_lambda + +!syntax parameters /UserObjects/BatchStressGrad + +!syntax inputs /UserObjects/BatchStressGrad + +!syntax children /UserObjects/BatchStressGrad diff --git a/doc/content/source/vectorpostprocessors/AdjointStrainStressGradInnerProduct.md b/doc/content/source/vectorpostprocessors/AdjointStrainStressGradInnerProduct.md new file mode 100644 index 00000000..b938c8c5 --- /dev/null +++ b/doc/content/source/vectorpostprocessors/AdjointStrainStressGradInnerProduct.md @@ -0,0 +1,31 @@ +# AdjointStrainStressGradInnerProduct + +!syntax description /VectorPostprocessors/AdjointStrainStressGradInnerProduct + +## Description + +This `VectorPostprocessor` is utilized in a mechanical inverse optimization problem (see [Inverse Optimization Theory](/InvOptTheory.md)) for computing the gradient of objective function with respect to a parameter of interest. + +Specifically, the objective function is defined as the sum of the regularization and the displacement mismatch (between the simulation and the measurement data at specific locations) as follows: +\begin{equation} + F({u}, \boldsymbol{p}) = ||\boldsymbol{S}{u} - \boldsymbol{u}_m ||^2 + R({u}, \boldsymbol{p}), +\end{equation} +where ${u}$ denotes the displacement from the forward problem, $\boldsymbol{S}$ is the sampling operator, $\boldsymbol{u}_m$ are the measurements, $\boldsymbol{p} = [p_1, p_2, ..., p_n]$ is the vector of parameters, and $R$ is the regularization term. + +The gradient of objective function with respect to one scalar parameter ($p_i$) is +\begin{equation} + \frac{\text{d}{F}}{\text{d}p_i} = - \int \underbrace{(\boldsymbol{L}\lambda)^T}_{\text{adjoint strain}} \underbrace{\frac{\partial \boldsymbol{C}}{\partial p_i} (\boldsymbol{L} u)}_{\text{gradient of stress}} \text{d}\Omega, +\end{equation} +where ${F}$ is the objective function, $\boldsymbol{L}$ is the symmetric strain operator for the elasticity problem, $\lambda$ is the adjoint displacement, $\boldsymbol{C}$ is the elasticity tensor, and $p_i$ is the interested scalar parameter. + +Specifically, this object takes the `adjoint strain` and the `gradient of stress w.r.t. parameter` 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 `gradient of stress w.r.t. parameter` should be a batch material (e.g., [BatchStressGrad](/BatchStressGrad.md)). + +## Example Input File Syntax + +!listing test/tests/bimaterial_elastic_inversion_batch_mat/grad.i block=VectorPostprocessors/grad_lambda + +!syntax parameters /VectorPostprocessors/AdjointStrainStressGradInnerProduct + +!syntax inputs /VectorPostprocessors/AdjointStrainStressGradInnerProduct + +!syntax children /VectorPostprocessors/AdjointStrainStressGradInnerProduct diff --git a/include/userobjects/BatchStressGrad.h b/include/userobjects/BatchStressGrad.h new file mode 100644 index 00000000..ff7006e1 --- /dev/null +++ b/include/userobjects/BatchStressGrad.h @@ -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, + BatchMaterialUtils::GatherMatProp> + + BatchStressGradParent; + +class BatchStressGrad : public BatchStressGradParent +{ +public: + static InputParameters validParams(); + + BatchStressGrad(const InputParameters & params); + + void batchCompute() override; +}; diff --git a/include/vectorpostprocessors/AdjointStrainStressGradInnerProduct.h b/include/vectorpostprocessors/AdjointStrainStressGradInnerProduct.h new file mode 100644 index 00000000..6c9009fe --- /dev/null +++ b/include/vectorpostprocessors/AdjointStrainStressGradInnerProduct.h @@ -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 & _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; +}; diff --git a/src/userobjects/BatchStressGrad.C b/src/userobjects/BatchStressGrad.C new file mode 100644 index 00000000..62c0ec19 --- /dev/null +++ b/src/userobjects/BatchStressGrad.C @@ -0,0 +1,54 @@ +//* 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("isopodApp", BatchStressGrad); + +InputParameters +BatchStressGrad::validParams() +{ + auto params = BatchStressGradParent::validParams(); + params.addRequiredParam( + "elasticity_tensor_derivative", + "Name of the elasticity tensor derivative material property."); + params.addClassDescription("Compute the double contraction of the elasticity tensor derivative " + "and the forward mechanical strain"); + return params; +} + +BatchStressGrad::BatchStressGrad(const InputParameters & params) + : BatchStressGradParent(params, + // here we pass the derivative of elasticity tensor wrt to the parameter + "elasticity_tensor_derivative", + // here we pass in the forward strain + "forward_mechanical_strain") +{ +} + +/* + Note: The following calculation is currently specialized for a linear elastic inverse optimization + problem. This will be swapped out later on when we can get the gradient of stress w.r.t. the + interested parameter from NEML for general material models. +*/ +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; + } +} diff --git a/src/vectorpostprocessors/AdjointStrainStressGradInnerProduct.C b/src/vectorpostprocessors/AdjointStrainStressGradInnerProduct.C new file mode 100644 index 00000000..ce284cca --- /dev/null +++ b/src/vectorpostprocessors/AdjointStrainStressGradInnerProduct.C @@ -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("isopodApp", AdjointStrainStressGradInnerProduct); + +InputParameters +AdjointStrainStressGradInnerProduct::validParams() +{ + InputParameters params = ElementOptimizationFunctionInnerProduct::validParams(); + params.addRequiredParam( + "stress_grad_name", + "Name of the stress gradient user object with respect to the material parameter"); + + params.addRequiredParam( + "adjoint_strain_name", "Name of the strain property in the adjoint problem"); + + params.addClassDescription( + "Compute the parameter gradient for linear elastic material inversion"); + return params; +} +AdjointStrainStressGradInnerProduct::AdjointStrainStressGradInnerProduct( + const InputParameters & parameters) + : ElementOptimizationFunctionInnerProduct(parameters), + _base_name(isParamValid("base_name") ? getParam("base_name") + "_" : ""), + _adjoint_strain(getMaterialPropertyByName( + getParam("adjoint_strain_name"))), + _stress_grad_uo(getUserObject("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]); +} diff --git a/test/tests/bimaterial_elastic_inversion_batch_mat/gold/main_out_OptimizationReporter_0001.csv b/test/tests/bimaterial_elastic_inversion_batch_mat/gold/main_out_OptimizationReporter_0001.csv new file mode 100644 index 00000000..8f37c9c5 --- /dev/null +++ b/test/tests/bimaterial_elastic_inversion_batch_mat/gold/main_out_OptimizationReporter_0001.csv @@ -0,0 +1,10 @@ +grad_lambda,grad_mu,lambda,measurement_time,measurement_values,measurement_xcoord,measurement_ycoord,measurement_zcoord,misfit_values,mu,simulation_values +5.1698615078396e-11,5.2394323056988e-11,4.9999752463318,0,4.46462,-1,-1,0,9.2479240265675e-08,1.0000001055133,4.4646200924792 +5.097187284528e-12,3.5417284419815e-11,4.0000666870441,0,6.447155,-1,0,0,5.2641227377137e-08,2.0000064790597,6.4471550526412 +-2.7212788369455e-12,8.6258766757591e-12,2.9997143457064,0,8.434803,-1,1,0,-1.0044113984975e-07,2.9999940961679,8.4348028995589 +0,0,0,0,4.176264,0,-1,0,-1.14358395642e-07,0,4.1762638856416 +0,0,0,0,6.172984,0,0,0,-1.7726937251439e-07,0,6.1729838227306 +0,0,0,0,8.200859,0,1,0,1.9391855410333e-07,0,8.2008591939186 +0,0,0,0,4.049477,1,-1,0,2.2853767767117e-08,0,4.0494770228538 +0,0,0,0,6.052499,1,0,0,1.1289934853664e-07,0,6.0524991128993 +0,0,0,0,8.079385,1,1,0,-8.6613697547477e-08,0,8.0793849133863 diff --git a/test/tests/bimaterial_elastic_inversion_batch_mat/grad.i b/test/tests/bimaterial_elastic_inversion_batch_mat/grad.i new file mode 100644 index 00000000..7d468b01 --- /dev/null +++ b/test/tests/bimaterial_elastic_inversion_batch_mat/grad.i @@ -0,0 +1,204 @@ +[Mesh] + [gmg] + type = GeneratedMeshGenerator + dim = 2 + nx = 11 + ny = 11 + xmin = -4 + xmax = 4 + ymin = -4 + ymax = 4 + [] +[] + +[Variables] + [ux] + [] + [uy] + [] +[] + +[AuxVariables] + [state_x] + [] + [state_y] + [] + [dummy] + [] +[] + +[DiracKernels] + [misfit_is_adjoint_force] + type = ReporterPointSource + variable = ux + x_coord_name = misfit/measurement_xcoord + y_coord_name = misfit/measurement_ycoord + z_coord_name = misfit/measurement_zcoord + value_name = misfit/misfit_values + [] +[] + +[Kernels] + [div_sigma_x] + type = StressDivergenceTensors + variable = ux + displacements = 'ux uy' + component = 0 + volumetric_locking_correction = false + [] + [div_sigma_y] + type = StressDivergenceTensors + variable = uy + displacements = 'ux uy' + component = 1 + volumetric_locking_correction = false + [] +[] + +[BCs] + [bottom_ux] + type = DirichletBC + variable = ux + boundary = bottom + value = 0.0 + [] + [bottom_uy] + type = DirichletBC + variable = uy + boundary = bottom + value = 0.0 + [] +[] + +[Materials] + [stress] + type = ComputeLinearElasticStress + [] + [strain] + type = ComputeSmallStrain + displacements = 'ux uy' + [] + [elasticity_tensor] + type = ComputeVariableIsotropicElasticityTensor + args = dummy + youngs_modulus = E_material + poissons_ratio = nu_material + [] + [E_material] + type = GenericFunctionMaterial + prop_names = 'E_material' + prop_values = E + [] + [nu_material] + type = GenericFunctionMaterial + prop_names = 'nu_material' + prop_values = nu + [] + [forward_strain] + type = ComputeSmallStrain + displacements = 'state_x state_y' + base_name = 'forward' + [] + # Below are the gradients of elasticity tensor for this elastic inversion problem + [dC_dlambda] + type = ComputeElasticityTensor + C_ijkl = '1 1 1 1 1 1 0 0 0' + fill_method = symmetric9 + base_name = 'dC_dlambda' + [] + [dC_dmu] + type = ComputeElasticityTensor + C_ijkl = '2 0 0 2 0 2 1 1 1' + fill_method = symmetric9 + base_name = 'dC_dmu' + [] +[] + +[Functions] + [E] + type = ParsedFunction + expression = mu*(3*lambda+2*mu)/(lambda+mu) + symbol_names = 'lambda mu' + symbol_values = 'lambda mu' + [] + [nu] + type = ParsedFunction + expression = lambda/2/(lambda+mu) + symbol_names = 'lambda mu' + symbol_values = 'lambda mu' + [] + [lambda] + type = NearestReporterCoordinatesFunction + x_coord_name = parametrization/coordx + y_coord_name = parametrization/coordy + value_name = parametrization/lambda + [] + [mu] + type = NearestReporterCoordinatesFunction + x_coord_name = parametrization/coordx + y_coord_name = parametrization/coordy + value_name = parametrization/mu + [] +[] + +[Reporters] + [measure_data] + type = OptimizationData + variable = ux + [] + [misfit] + type = OptimizationData + [] + [parametrization] + type = ConstantReporter + real_vector_names = 'coordx coordy lambda mu' + real_vector_values = '0 1 2; 0 1 2; 5 4 3; 1 2 3' + [] +[] + +# Below is the part where a customized userObject that takes NEML stress gradient +# and transforms it into a batch material that has the output type as RankTwoTensor +# One userObject per gradient material property from NEML +[UserObjects] + [stress_grad_lambda] + type = BatchStressGrad + elasticity_tensor_derivative = 'dC_dlambda_elasticity_tensor' # calculated in dC_dlambda + execution_order_group = -1 # need to make sure that the UO executes before the VPP + [] + [stress_grad_mu] + type = BatchStressGrad + elasticity_tensor_derivative = 'dC_dmu_elasticity_tensor' # calculated in dC_dmu + execution_order_group = -1 # need to make sure that the UO executes before the VPP + [] +[] + +# Below is where the stress gradient batch material objects are utilized in the +# actual gradient calculations +[VectorPostprocessors] + [grad_lambda] + type = AdjointStrainStressGradInnerProduct + stress_grad_name = 'stress_grad_lambda' + adjoint_strain_name = 'mechanical_strain' + variable = dummy + function = lambda + [] + [grad_mu] + type = AdjointStrainStressGradInnerProduct + stress_grad_name = 'stress_grad_mu' + adjoint_strain_name = 'mechanical_strain' + variable = dummy + function = mu + [] +[] + +[Executioner] + type = Steady + solve_type = NEWTON + petsc_options_iname = '-pc_type' + petsc_options_value = 'lu' +[] + +[Outputs] + file_base = 'adjoint' + console = false +[] diff --git a/test/tests/bimaterial_elastic_inversion_batch_mat/main.i b/test/tests/bimaterial_elastic_inversion_batch_mat/main.i new file mode 100644 index 00000000..e7e1c30f --- /dev/null +++ b/test/tests/bimaterial_elastic_inversion_batch_mat/main.i @@ -0,0 +1,126 @@ +[Optimization] +[] + +[OptimizationReporter] + type = OptimizationReporter + parameter_names = 'lambda mu' + num_values = '3 3' + #initial_condition = '5 4 3 ; 1 2 1' + initial_condition = '5.0 5.0 5.0; 1.0 1.0 1.0' + lower_bounds = '0.1; 0.1' + upper_bounds = '10.0; 10.0' + measurement_points = '-1.0 -1.0 0.0 + -1.0 0.0 0.0 + -1.0 1.0 0.0 + 0.0 -1.0 0.0 + 0.0 0.0 0.0 + 0.0 1.0 0.0 + 1.0 -1.0 0.0 + 1.0 0.0 0.0 + 1.0 1.0 0.0' + measurement_values = '4.464620e+00 6.447155e+00 8.434803e+00 + 4.176264e+00 6.172984e+00 8.200859e+00 + 4.049477e+00 6.052499e+00 8.079385e+00' +[] + +[Executioner] + type = Optimize + tao_solver = taobqnls #taobncg #taoblmvm + petsc_options_iname = '-tao_gatol -tao_ls_type -tao_max_it' + petsc_options_value = '1e-10 unit 1000' + + #THESE OPTIONS ARE FOR TESTING THE ADJOINT GRADIENT + #petsc_options_iname='-tao_max_it -tao_fd_test -tao_test_gradient -tao_fd_gradient -tao_fd_delta -tao_gatol' + #petsc_options_value='1 true true false 1e-8 0.1' + #petsc_options = '-tao_test_gradient_view' + verbose = true +[] + +[MultiApps] + [forward] + type = FullSolveMultiApp + input_files = model.i + execute_on = FORWARD + [] + [adjoint] + type = FullSolveMultiApp + input_files = grad.i + execute_on = ADJOINT + [] +[] + +[Transfers] + [toForward] + type = MultiAppReporterTransfer + to_multi_app = forward + from_reporters = 'OptimizationReporter/measurement_xcoord + OptimizationReporter/measurement_ycoord + OptimizationReporter/measurement_zcoord + OptimizationReporter/measurement_time + OptimizationReporter/measurement_values + OptimizationReporter/lambda + OptimizationReporter/mu' + to_reporters = 'measure_data/measurement_xcoord + measure_data/measurement_ycoord + measure_data/measurement_zcoord + measure_data/measurement_time + measure_data/measurement_values + parametrization/lambda + parametrization/mu' + [] + [get_misfit] + type = MultiAppReporterTransfer + from_multi_app = forward + from_reporters = 'measure_data/simulation_values' + to_reporters = 'OptimizationReporter/simulation_values' + [] + [set_state_for_adjoint] + type = MultiAppCopyTransfer + from_multi_app = forward + to_multi_app = adjoint + source_variable = 'ux uy' + variable = 'state_x state_y' + [] + [setup_adjoint_run] + type = MultiAppReporterTransfer + to_multi_app = adjoint + from_reporters = 'OptimizationReporter/measurement_xcoord + OptimizationReporter/measurement_ycoord + OptimizationReporter/measurement_zcoord + OptimizationReporter/measurement_time + OptimizationReporter/misfit_values + OptimizationReporter/lambda + OptimizationReporter/mu' + to_reporters = 'misfit/measurement_xcoord + misfit/measurement_ycoord + misfit/measurement_zcoord + misfit/measurement_time + misfit/misfit_values + parametrization/lambda + parametrization/mu' + [] + [get_grad_lambda] + type = MultiAppReporterTransfer + from_multi_app = adjoint + from_reporters = 'grad_lambda/inner_product' + to_reporters = 'OptimizationReporter/grad_lambda' + [] + [get_grad_mu] + type = MultiAppReporterTransfer + from_multi_app = adjoint + from_reporters = 'grad_mu/inner_product' + to_reporters = 'OptimizationReporter/grad_mu' + [] +[] + +[Reporters] + [optInfo] + type = OptimizationInfo + items = 'current_iterate function_value gnorm' + [] +[] + +[Outputs] + console = false + csv = true +[] diff --git a/test/tests/bimaterial_elastic_inversion_batch_mat/model.i b/test/tests/bimaterial_elastic_inversion_batch_mat/model.i new file mode 100644 index 00000000..c6717e0f --- /dev/null +++ b/test/tests/bimaterial_elastic_inversion_batch_mat/model.i @@ -0,0 +1,166 @@ +[Mesh] + [gmg] + type = GeneratedMeshGenerator + dim = 2 + nx = 11 + ny = 11 + xmin = -4 + xmax = 4 + ymin = -4 + ymax = 4 + [] +[] + +[Variables] + [ux] + [] + [uy] + [] +[] + +[AuxVariables] + [dummy] + [] +[] + +[Kernels] + [div_sigma_x] + type = StressDivergenceTensors + variable = ux + displacements = 'ux uy' + component = 0 + volumetric_locking_correction = false + [] + [div_sigma_y] + type = StressDivergenceTensors + variable = uy + displacements = 'ux uy' + component = 1 + volumetric_locking_correction = false + [] +[] + +[BCs] + [bottom_ux] + type = DirichletBC + variable = ux + boundary = bottom + value = 0.0 + [] + [bottom_uy] + type = DirichletBC + variable = uy + boundary = bottom + value = 0.0 + [] + [top_fx] + type = NeumannBC + variable = ux + boundary = top + value = 1.0 + [] + [top_fy] + type = NeumannBC + variable = uy + boundary = top + value = 1.0 + [] +[] + +[Materials] + [stress] + type = ComputeLinearElasticStress + [] + [strain] + type = ComputeSmallStrain + displacements = 'ux uy' + [] + [elasticity_tensor] + type = ComputeVariableIsotropicElasticityTensor + args = dummy + youngs_modulus = E_material + poissons_ratio = nu_material + [] + [E_material] + type = GenericFunctionMaterial + prop_names = 'E_material' + prop_values = E + [] + [nu_material] + type = GenericFunctionMaterial + prop_names = 'nu_material' + prop_values = nu + [] +[] + +[Functions] + [E] + type = ParsedFunction + expression = mu*(3*lambda+2*mu)/(lambda+mu) + symbol_names = 'lambda mu' + symbol_values = 'lambda mu' + [] + [nu] + type = ParsedFunction + expression = lambda/2/(lambda+mu) + symbol_names = 'lambda mu' + symbol_values = 'lambda mu' + [] + [lambda] + type = NearestReporterCoordinatesFunction + x_coord_name = parametrization/coordx + y_coord_name = parametrization/coordy + value_name = parametrization/lambda + [] + [mu] + type = NearestReporterCoordinatesFunction + x_coord_name = parametrization/coordx + y_coord_name = parametrization/coordy + value_name = parametrization/mu + [] +[] + +[Reporters] + [measure_data] + type = OptimizationData + variable = ux + [] + [parametrization] + type = ConstantReporter + real_vector_names = 'coordx coordy lambda mu' + real_vector_values = '0 1 2; 0 1 2; 5 4 3; 1 2 3' + [] +[] + +[Executioner] + type = Steady + solve_type = NEWTON + petsc_options_iname = '-pc_type' + petsc_options_value = 'lu' +[] + +[Postprocessors] + [point1] + type = PointValue + point = '-1.0 -1.0 0.0' + variable = ux + execute_on = TIMESTEP_END + [] + [point2] + type = PointValue + point = '-1.0 0.0 0.0' + variable = ux + execute_on = TIMESTEP_END + [] + [point3] + type = PointValue + point = '-1.0 1.0 0.0' + variable = ux + execute_on = TIMESTEP_END + [] +[] + +[Outputs] + file_base = 'forward' + console = false +[] diff --git a/test/tests/bimaterial_elastic_inversion_batch_mat/tests b/test/tests/bimaterial_elastic_inversion_batch_mat/tests new file mode 100644 index 00000000..352d4f39 --- /dev/null +++ b/test/tests/bimaterial_elastic_inversion_batch_mat/tests @@ -0,0 +1,16 @@ +[Tests] + issues = '#352' + design= 'BatchStressGrad.md AdjointStrainStressGradInnerProduct.md' + [grad] + requirement = "The system shall be able to invert for elastic moduli using batch materials." + type = CSVDiff + abs_zero = 1e-5 + rel_err = 5e-4 + input = main.i + csvdiff = main_out_OptimizationReporter_0001.csv + max_threads = 1 + method = opt + # steady solve + recover = false + [] +[] From 259241b3292d07d405a441f9fcc5757d29e5e30e Mon Sep 17 00:00:00 2001 From: dewenyushu Date: Wed, 28 Jun 2023 21:03:17 -0700 Subject: [PATCH 2/2] Address more comments --- src/userobjects/BatchStressGrad.C | 4 ++++ test/tests/bimaterial_elastic_inversion_batch_mat/grad.i | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/userobjects/BatchStressGrad.C b/src/userobjects/BatchStressGrad.C index 62c0ec19..ce9ecd8c 100644 --- a/src/userobjects/BatchStressGrad.C +++ b/src/userobjects/BatchStressGrad.C @@ -19,6 +19,10 @@ BatchStressGrad::validParams() params.addRequiredParam( "elasticity_tensor_derivative", "Name of the elasticity tensor derivative material property."); + params.setDocString( + "execution_order_group", + "BatchStressGrad userObject needs to be completely executed before vectorPostprocessors."); + params.set("execution_order_group") = -1; params.addClassDescription("Compute the double contraction of the elasticity tensor derivative " "and the forward mechanical strain"); return params; diff --git a/test/tests/bimaterial_elastic_inversion_batch_mat/grad.i b/test/tests/bimaterial_elastic_inversion_batch_mat/grad.i index 7d468b01..24ce9a5d 100644 --- a/test/tests/bimaterial_elastic_inversion_batch_mat/grad.i +++ b/test/tests/bimaterial_elastic_inversion_batch_mat/grad.i @@ -163,12 +163,10 @@ [stress_grad_lambda] type = BatchStressGrad elasticity_tensor_derivative = 'dC_dlambda_elasticity_tensor' # calculated in dC_dlambda - execution_order_group = -1 # need to make sure that the UO executes before the VPP [] [stress_grad_mu] type = BatchStressGrad elasticity_tensor_derivative = 'dC_dmu_elasticity_tensor' # calculated in dC_dmu - execution_order_group = -1 # need to make sure that the UO executes before the VPP [] []