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 "FFTElasticChemicalPotential.h" 10 : #include "SwiftUtils.h" 11 : #include "DomainAction.h" 12 : 13 : registerMooseObject("SwiftApp", FFTElasticChemicalPotential); 14 : 15 : InputParameters 16 0 : FFTElasticChemicalPotential::validParams() 17 : { 18 0 : InputParameters params = TensorOperator<>::validParams(); 19 0 : params.addClassDescription("FFT based elastic strain energy chemical potential solve."); 20 0 : params.addParam<std::vector<TensorInputBufferName>>("displacements", "Displacements"); 21 0 : params.addParam<TensorInputBufferName>("cbar", "FFT of concentration buffer"); 22 0 : params.addRequiredParam<Real>("mu", "Lame mu"); 23 0 : params.addRequiredParam<Real>("lambda", "Lame lambda"); 24 0 : params.addRequiredParam<Real>("e0", "volumetric eigenstrain"); 25 0 : return params; 26 0 : } 27 : 28 0 : FFTElasticChemicalPotential::FFTElasticChemicalPotential(const InputParameters & parameters) 29 : : TensorOperator<>(parameters), 30 0 : _two_pi_i(torch::tensor(c10::complex<double>(0.0, 2.0 * pi), 31 0 : MooseTensor::complexFloatTensorOptions())), 32 0 : _mu(getParam<Real>("mu")), 33 0 : _lambda(getParam<Real>("lambda")), 34 0 : _e0(getParam<Real>("e0")), 35 0 : _cbar(getInputBuffer("cbar")) 36 : 37 : { 38 0 : for (const auto & name : getParam<std::vector<TensorOutputBufferName>>("displacements")) 39 0 : _displacements.push_back(&getInputBufferByName(name)); 40 : 41 0 : if (_domain.getDim() != _displacements.size()) 42 0 : paramError("displacements", "Need one displacement variable per mesh dimension"); 43 0 : } 44 : 45 : void 46 0 : FFTElasticChemicalPotential::computeBuffer() 47 : { 48 : // wave vector 49 0 : const auto kx = _two_pi_i * _i; 50 0 : const auto ky = _two_pi_i * _j; 51 0 : const auto kz = _two_pi_i * _k; 52 : 53 : // FFT displacements 54 0 : auto ux = _domain.fft(*_displacements[0]); 55 0 : auto uy = _domain.fft(*_displacements[1]); 56 0 : auto uz = _domain.fft(*_displacements[2]); 57 : 58 : // mu mech bar 59 0 : _u = -_e0 * (_e0 * (9.0 * _lambda * _cbar + _mu * 6.0 * _cbar) - 60 0 : (2.0 * _mu + 3.0 * _lambda) * (kx * ux + ky * uy + kz * uz)); 61 0 : }