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 "LBMComputeForces.h" 10 : #include "LatticeBoltzmannProblem.h" 11 : 12 : using namespace torch::indexing; 13 : 14 : registerMooseObject("SwiftApp", LBMComputeForces); 15 : 16 : InputParameters 17 0 : LBMComputeForces::validParams() 18 : { 19 0 : InputParameters params = LatticeBoltzmannOperator::validParams(); 20 : // params.addRequiredParam<TensorInputBufferName>("f", "Distribution function"); 21 0 : params.addParam<TensorInputBufferName>("temperature", "T", "Macroscopic temperature"); 22 0 : params.addParam<TensorInputBufferName>("rho", "rho", "Macroscopic density"); 23 : 24 0 : params.addParam<std::string>("rho0", "1.0", "Reference density"); 25 0 : params.addParam<std::string>("T0", "1.0", "Reference temperature"); 26 0 : params.addParam<std::string>("gravity", "0.001", "Gravitational accelaration"); 27 0 : params.addParam<Real>("gravity_direction", 1, "Gravitational accelaration direction"); 28 : 29 0 : params.addParam<bool>("enable_gravity", false, "Whether to consider gravity"); 30 0 : params.addParam<bool>("enable_buoyancy", false, "Whether to consider buoyancy"); 31 0 : params.addParam<bool>( 32 0 : "enable_surface_forces", false, "Whether to consider surface tension in multiphase flow"); 33 : 34 0 : params.addClassDescription("Compute object for LB forces"); 35 0 : return params; 36 0 : } 37 : 38 0 : LBMComputeForces::LBMComputeForces(const InputParameters & parameters) 39 : : LatticeBoltzmannOperator(parameters), 40 0 : _reference_density((_lb_problem.getConstant<Real>(getParam<std::string>("rho0")))), 41 0 : _reference_temperature((_lb_problem.getConstant<Real>(getParam<std::string>("T0")))), 42 0 : _enable_gravity(getParam<bool>("enable_gravity")), 43 0 : _enable_buoyancy(getParam<bool>("enable_buoyancy")), 44 0 : _enable_surface_forces(getParam<bool>("enable_surface_forces")), 45 0 : _g(_lb_problem.getConstant<Real>(getParam<std::string>("gravity"))), 46 0 : _gravity_direction(static_cast<int64_t>(getParam<Real>("gravity_direction"))), 47 0 : _density_tensor(getInputBufferByName(getParam<TensorInputBufferName>("rho"))), 48 0 : _temperature(getInputBufferByName(getParam<TensorInputBufferName>("temperature"))) 49 : { 50 0 : } 51 : 52 : void 53 0 : LBMComputeForces::computeGravity() 54 : { 55 0 : _u.index({Slice(), Slice(), Slice(), _gravity_direction}) += _g * _density_tensor; 56 0 : } 57 : 58 : void 59 0 : LBMComputeForces::computeBuoyancy() 60 : { 61 : // Boussinesq approximation 62 0 : _u.index({Slice(), Slice(), Slice(), _gravity_direction}) += 63 0 : _g * _reference_density * (_temperature - _reference_temperature); 64 0 : } 65 : 66 : void 67 0 : LBMComputeForces::computeSurfaceForces() 68 : { 69 : // TBD 70 0 : mooseError("computeSurfaceForces is not yet implemented."); 71 : } 72 : 73 : void 74 0 : LBMComputeForces::computeBuffer() 75 : { 76 0 : _u = torch::zeros_like(_u); 77 : 78 0 : if (_enable_gravity) 79 0 : computeGravity(); 80 0 : if (_enable_buoyancy) 81 0 : computeBuoyancy(); 82 0 : if (_enable_surface_forces) 83 0 : computeSurfaceForces(); 84 : 85 : /// more forces can be added ? 86 : 87 0 : _lb_problem.maskedFillSolids(_u, 0); 88 0 : }