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 "LBMPhaseEquilibrium.h" 10 : 11 : registerMooseObject("SwiftApp", LBMPhaseEquilibrium); 12 : 13 : InputParameters 14 0 : LBMPhaseEquilibrium::validParams() 15 : { 16 0 : InputParameters params = LatticeBoltzmannOperator::validParams(); 17 0 : params.addClassDescription("Compute LB equilibrium distribution object."); 18 0 : params.addRequiredParam<TensorInputBufferName>("phi", "LBM phase field parameter"); 19 0 : params.addRequiredParam<TensorInputBufferName>("grad_phi", 20 : "Gradient of LBM phase field parameter"); 21 0 : params.addRequiredParam<std::string>("tau_phi", "Relaxation parameter for LBM phase field"); 22 0 : params.addRequiredParam<std::string>("thickness", "Interface thickness"); 23 : 24 0 : return params; 25 0 : } 26 : 27 0 : LBMPhaseEquilibrium::LBMPhaseEquilibrium(const InputParameters & parameters) 28 : : LatticeBoltzmannOperator(parameters), 29 0 : _phi(getInputBuffer("phi")), 30 0 : _grad_phi(getInputBuffer("grad_phi")), 31 0 : _tau_phi(_lb_problem.getConstant<Real>(getParam<std::string>("tau_phi"))), 32 0 : _D(_lb_problem.getConstant<Real>(getParam<std::string>("thickness"))) 33 : { 34 0 : } 35 : 36 : void 37 0 : LBMPhaseEquilibrium::computeBuffer() 38 : { 39 0 : const unsigned int & dim = _domain.getDim(); 40 : 41 0 : if (_phi.dim() < 3) 42 0 : _phi.unsqueeze_(2); 43 : 44 0 : torch::Tensor _phi_unsqueezed = _phi.unsqueeze(3); 45 : 46 : // in the future when phase field is coupled with NS this will be extended to include fluid 47 : // velocity and density 48 0 : auto gamma_eq = _w * _phi_unsqueezed; 49 : 50 0 : switch (dim) 51 : { 52 0 : case 3: 53 0 : mooseError("Not implemented fo 3D yet!"); 54 : break; 55 : case 2: 56 : { 57 : torch::Tensor phase_eq_2; 58 : { 59 : torch::Tensor phase_eq; 60 : torch::Tensor e_dot_n; 61 : { 62 0 : auto mag = torch::norm(_grad_phi, 2, -1); 63 : // _lb_problem.printBuffer(mag, 10, 0); 64 : 65 0 : auto unit_normal = _grad_phi / (mag.unsqueeze(-1) + 1.0e-16); 66 : unit_normal.unsqueeze_(3); 67 : // _lb_problem.printBuffer(unit_normal, 10, 0); 68 : 69 0 : auto e_xyz = torch::stack( 70 : { 71 : _ex, 72 : _ey, 73 : }, 74 : -1) 75 0 : .to(MooseTensor::floatTensorOptions()); 76 0 : e_dot_n = torch::einsum("ijklm,abcdm->abcl", {e_xyz, unit_normal}); 77 : // _lb_problem.printBuffer(e_dot_n, 10, 1); 78 0 : phase_eq = 4.0 / _D * _phi_unsqueezed * (1.0 - _phi_unsqueezed) * e_dot_n; 79 : } 80 0 : phase_eq_2 = _w * (_tau_phi)*phase_eq; 81 : } 82 0 : _u = gamma_eq; // + phase_eq_2; 83 : // _lb_problem.printBuffer(_u, 10, 1); 84 : break; 85 : } 86 0 : default: 87 0 : mooseError("Unsupported dimension for buffer _u"); 88 : } 89 0 : _lb_problem.maskedFillSolids(_u, 0); 90 0 : }