Line data Source code
1 : /**********************************************************************/ 2 : /* DO NOT MODIFY THIS HEADER */ 3 : /* Swift, a Fourier spectral solver for MOOSE */ 4 : /* */ 5 : /* Copyright 2024 Battelle Energy Alliance, LLC */ 6 : /* ALL RIGHTS RESERVED */ 7 : /**********************************************************************/ 8 : 9 : #include "ComputeVonMisesStress.h" 10 : #include "MooseError.h" 11 : #include "DomainAction.h" 12 : #include "SwiftUtils.h" 13 : #include <ATen/core/TensorBody.h> 14 : 15 : registerMooseObject("SwiftApp", ComputeVonMisesStress); 16 : 17 : InputParameters 18 0 : ComputeVonMisesStress::validParams() 19 : { 20 0 : InputParameters params = TensorOperator<>::validParams(); 21 0 : params.addClassDescription("Compute vonMises stress."); 22 0 : params.addParam<TensorInputBufferName>("stress", "stress", "Stress tensor."); 23 0 : return params; 24 0 : } 25 : 26 0 : ComputeVonMisesStress::ComputeVonMisesStress(const InputParameters & parameters) 27 0 : : TensorOperator<>(parameters), _stress(getInputBuffer("stress")) 28 : { 29 0 : } 30 : 31 : void 32 0 : ComputeVonMisesStress::computeBuffer() 33 : { 34 : using namespace torch::indexing; 35 0 : if (!_stress.defined()) 36 : return; 37 : 38 0 : if (_dim == 3) 39 : { 40 0 : auto stress_xx = _stress.index({Ellipsis, 0, 0}); 41 0 : auto stress_yy = _stress.index({Ellipsis, 1, 1}); 42 0 : auto stress_zz = _stress.index({Ellipsis, 2, 2}); 43 0 : auto stress_xy = _stress.index({Ellipsis, 0, 1}); 44 0 : auto stress_yz = _stress.index({Ellipsis, 1, 2}); 45 0 : auto stress_zx = _stress.index({Ellipsis, 2, 0}); 46 : 47 0 : auto term1 = (stress_xx - stress_yy).pow(2); 48 0 : auto term2 = (stress_yy - stress_zz).pow(2); 49 0 : auto term3 = (stress_zz - stress_xx).pow(2); 50 0 : auto term4 = 6 * (stress_xy.pow(2) + stress_yz.pow(2) + stress_zx.pow(2)); 51 : 52 0 : _u = torch::sqrt(0.5 * (term1 + term2 + term3 + term4)); 53 : } 54 0 : else if (_dim == 2) 55 : { 56 0 : auto stress_xx = _stress.index({Ellipsis, 0, 0}); 57 0 : auto stress_yy = _stress.index({Ellipsis, 1, 1}); 58 0 : auto stress_xy = _stress.index({Ellipsis, 0, 1}); 59 : 60 0 : auto term1 = (stress_xx - stress_yy).pow(2); 61 0 : auto term2 = 6 * stress_xy.pow(2); 62 : 63 0 : _u = torch::sqrt(0.5 * (term1 + term2)); 64 : } 65 : else 66 0 : mooseError("Unsupported problem dimension ", _dim); 67 0 : }