diff --git a/doc/content/source/tensor_computes/LBMFixedFirstOrderBC.md b/doc/content/source/tensor_computes/LBMFixedFirstOrderBC.md index 75cd5bf..e99a6a0 100644 --- a/doc/content/source/tensor_computes/LBMFixedFirstOrderBC.md +++ b/doc/content/source/tensor_computes/LBMFixedFirstOrderBC.md @@ -1,13 +1,13 @@ -# LBMFixedFirstOrderBC9Q +# LBMFixedFirstOrderBC -!syntax description /TensorComputes/Solve/LBMFixedFirstOrderBC9Q +!syntax description /TensorComputes/Solve/LBMFixedFirstOrderBC -LBMFixedFirstOrderBC implements Zou\-He velocity boundary conditions at the inlet and outlet for D2Q9, D3Q19 and D3Q27 stencils. The choice of stencil should be indicated in the name of the compute object such as LBMFixedFirstOrderBC9Q for D2Q9. +LBMFixedFirstOrderBC implements Zou\-He velocity boundary conditions at the inlet and outlet for D2Q9, D3Q19 and D3Q27 stencils. ## Overview Enforces first\-order accurate macroscopic velocity at selected domain faces via Zou\-He formulas. -Choose faces with [!param](/TensorComputes/Solve/LBMFixedFirstOrderBC9Q/boundary) and provide +Choose faces with [!param](/TensorComputes/Solve/LBMFixedFirstOrderBC/boundary) and provide macroscopic fields as required by the implementation. ## Example Input File Syntax @@ -15,8 +15,4 @@ macroscopic fields as required by the implementation. !listing test/tests/lbm/vertical_velocity_bcs.i block=TensorComputes/Boundary/top !listing test/tests/lbm/vertical_velocity_bcs.i block=TensorComputes/Boundary/bottom -!syntax parameters /TensorComputes/Solve/LBMFixedFirstOrderBC9Q - -!syntax inputs /TensorComputes/Solve/LBMFixedFirstOrderBC9Q - -!syntax children /TensorComputes/Solve/LBMFixedFirstOrderBC9Q +!syntax parameters /TensorComputes/Solve/LBMFixedFirstOrderBC diff --git a/doc/content/source/tensor_computes/LBMFixedZerothOrderBC.md b/doc/content/source/tensor_computes/LBMFixedZerothOrderBC.md index f2cfd2e..32fd834 100644 --- a/doc/content/source/tensor_computes/LBMFixedZerothOrderBC.md +++ b/doc/content/source/tensor_computes/LBMFixedZerothOrderBC.md @@ -1,13 +1,13 @@ -# LBMFixedZerothOrderBC9Q +# LBMFixedZerothOrderBC -!syntax description /TensorComputes/Solve/LBMFixedZerothOrderBC9Q +!syntax description /TensorComputes/Solve/LBMFixedZerothOrderBC -LBMFixedZerothOrderBC implements Zou-He pressure boundary conditions at the inlet and outlet for D2Q9, D3Q19 and D3Q27 stencils. The choice of stencil should be indicated in the name of the compute object such as LBMFixedZerothOrderBC9Q for D2Q9. +LBMFixedZerothOrderBC implements Zou-He pressure boundary conditions at the inlet and outlet for D2Q9, D3Q19 and D3Q27 stencils. ## Overview -LBMFixedZerothOrderBC implements Zou\-He pressure boundary conditions at the inlet and outlet for D2Q9, D3Q19 and D3Q27 stencils. The choice of stencil should be indicated in the name of the compute object such as LBMFixedZerothOrderBC9Q for D2Q9. -Choose faces with [!param](/TensorComputes/Solve/LBMFixedZerothOrderBC9Q/boundary) and provide macroscopic fields as +LBMFixedZerothOrderBC implements Zou\-He pressure boundary conditions at the inlet and outlet for D2Q9, D3Q19 and D3Q27 stencils. +Choose faces with [!param](/TensorComputes/Solve/LBMFixedZerothOrderBC/boundary) and provide macroscopic fields as required by the implementation. ## Example Input File Syntax @@ -15,8 +15,4 @@ required by the implementation. !listing test/tests/lbm/vertical_density_bcs.i block=TensorComputes/Boundary/top !listing test/tests/lbm/vertical_density_bcs.i block=TensorComputes/Boundary/bottom -!syntax parameters /TensorComputes/Solve/LBMFixedZerothOrderBC9Q - -!syntax inputs /TensorComputes/Solve/LBMFixedZerothOrderBC9Q - -!syntax children /TensorComputes/Solve/LBMFixedZerothOrderBC9Q +!syntax parameters /TensorComputes/Solve/LBMFixedZerothOrderBC diff --git a/examples/lbm/Formula1-aerodynamics/f1.i b/examples/lbm/Formula1-aerodynamics/f1.i index be54247..41b6d8e 100644 --- a/examples/lbm/Formula1-aerodynamics/f1.i +++ b/examples/lbm/Formula1-aerodynamics/f1.i @@ -144,7 +144,7 @@ [] [left] - type = LBMFixedFirstOrderBC27Q + type = LBMFixedFirstOrderBC buffer=f f=f value=0.01 diff --git a/examples/lbm/Karman-vortex/cylinder.i b/examples/lbm/Karman-vortex/cylinder.i index 8cb055d..91b65f8 100644 --- a/examples/lbm/Karman-vortex/cylinder.i +++ b/examples/lbm/Karman-vortex/cylinder.i @@ -128,7 +128,7 @@ boundary = wall [] [left] - type = LBMFixedFirstOrderBC9Q + type = LBMFixedFirstOrderBC buffer=f f=f value='Ux' diff --git a/examples/lbm/Pebbles/pebbles.i b/examples/lbm/Pebbles/pebbles.i index aabd833..5a11e53 100644 --- a/examples/lbm/Pebbles/pebbles.i +++ b/examples/lbm/Pebbles/pebbles.i @@ -245,7 +245,7 @@ [Boundary] ##### for fluid [inlet] - type = LBMFixedFirstOrderBC19Q + type = LBMFixedFirstOrderBC buffer = f f = f value = u0 @@ -293,7 +293,7 @@ ##### for temperature [t_inlet] - type = LBMFixedZerothOrderBC19Q + type = LBMFixedZerothOrderBC buffer = g f = g value = T_C diff --git a/examples/lbm/Rayleigh-Benard/boundary.i b/examples/lbm/Rayleigh-Benard/boundary.i index 1ee6c21..bb89b22 100644 --- a/examples/lbm/Rayleigh-Benard/boundary.i +++ b/examples/lbm/Rayleigh-Benard/boundary.i @@ -17,7 +17,7 @@ ##### for temperature [temperature_g_top] - type = LBMFixedZerothOrderBC9Q + type = LBMFixedZerothOrderBC buffer = g f = g value = T_C @@ -25,7 +25,7 @@ [] [temperature_g_bottom] - type = LBMFixedZerothOrderBC9Q + type = LBMFixedZerothOrderBC buffer = g f = g value = T_H diff --git a/include/tensor_computes/LBMFixedFirstOrderBC.h b/include/tensor_computes/LBMFixedFirstOrderBC.h index f3f8e52..bf3ac76 100644 --- a/include/tensor_computes/LBMFixedFirstOrderBC.h +++ b/include/tensor_computes/LBMFixedFirstOrderBC.h @@ -13,20 +13,23 @@ /** * LBMFixedFirstOrderBC object */ -template -class LBMFixedFirstOrderBCTempl : public LBMBoundaryCondition +class LBMFixedFirstOrderBC : public LBMBoundaryCondition { public: static InputParameters validParams(); - LBMFixedFirstOrderBCTempl(const InputParameters & parameters); + LBMFixedFirstOrderBC(const InputParameters & parameters); void init() override {}; void topBoundary() override; + void topBoundaryD2Q9(); void bottomBoundary() override; + void bottomBoundaryD2Q9(); void leftBoundary() override; + void leftBoundaryD2Q9(); void rightBoundary() override; + void rightBoundaryD2Q9(); void frontBoundary() override; void backBoundary() override; void computeBuffer() override; @@ -37,7 +40,3 @@ class LBMFixedFirstOrderBCTempl : public LBMBoundaryCondition const Real & _value; const bool _perturb; }; - -typedef LBMFixedFirstOrderBCTempl<9> LBMFixedFirstOrderBC9Q; -typedef LBMFixedFirstOrderBCTempl<19> LBMFixedFirstOrderBC19Q; -typedef LBMFixedFirstOrderBCTempl<27> LBMFixedFirstOrderBC27Q; diff --git a/include/tensor_computes/LBMFixedZerothOrderBC.h b/include/tensor_computes/LBMFixedZerothOrderBC.h index 34c3e9e..7221761 100644 --- a/include/tensor_computes/LBMFixedZerothOrderBC.h +++ b/include/tensor_computes/LBMFixedZerothOrderBC.h @@ -13,18 +13,21 @@ /** * LBMFixedZerothOrderBC object */ -template -class LBMFixedZerothOrderBCTempl : public LBMBoundaryCondition +class LBMFixedZerothOrderBC : public LBMBoundaryCondition { public: static InputParameters validParams(); - LBMFixedZerothOrderBCTempl(const InputParameters & parameters); + LBMFixedZerothOrderBC(const InputParameters & parameters); void topBoundary() override; + void topBoundaryD2Q9(); void bottomBoundary() override; + void bottomBoundaryD2Q9(); void leftBoundary() override; + void leftBoundaryD2Q9(); void rightBoundary() override; + void rightBoundaryD2Q9(); void frontBoundary() override; void backBoundary() override; void computeBuffer() override; @@ -34,7 +37,3 @@ class LBMFixedZerothOrderBCTempl : public LBMBoundaryCondition const std::array _grid_size; const Real _value; }; - -typedef LBMFixedZerothOrderBCTempl<9> LBMFixedZerothOrderBC9Q; -typedef LBMFixedZerothOrderBCTempl<19> LBMFixedZerothOrderBC19Q; -typedef LBMFixedZerothOrderBCTempl<27> LBMFixedZerothOrderBC27Q; diff --git a/src/tensor_computes/LBMFixedFirstOrderBC.C b/src/tensor_computes/LBMFixedFirstOrderBC.C index c22f00e..5512e34 100644 --- a/src/tensor_computes/LBMFixedFirstOrderBC.C +++ b/src/tensor_computes/LBMFixedFirstOrderBC.C @@ -14,13 +14,10 @@ using namespace torch::indexing; -registerMooseObject("SwiftApp", LBMFixedFirstOrderBC9Q); -registerMooseObject("SwiftApp", LBMFixedFirstOrderBC19Q); -registerMooseObject("SwiftApp", LBMFixedFirstOrderBC27Q); +registerMooseObject("SwiftApp", LBMFixedFirstOrderBC); -template InputParameters -LBMFixedFirstOrderBCTempl::validParams() +LBMFixedFirstOrderBC::validParams() { InputParameters params = LBMBoundaryCondition::validParams(); params.addClassDescription("LBMFixedFirstOrderBC object"); @@ -30,8 +27,7 @@ LBMFixedFirstOrderBCTempl::validParams() return params; } -template -LBMFixedFirstOrderBCTempl::LBMFixedFirstOrderBCTempl(const InputParameters & parameters) +LBMFixedFirstOrderBC::LBMFixedFirstOrderBC(const InputParameters & parameters) : LBMBoundaryCondition(parameters), _f(getInputBufferByName(getParam("f"))), _grid_size(_lb_problem.getGridSize()), @@ -40,57 +36,28 @@ LBMFixedFirstOrderBCTempl::LBMFixedFirstOrderBCTempl(const InputParam { } -template <> void -LBMFixedFirstOrderBCTempl<9>::frontBoundary() +LBMFixedFirstOrderBC::frontBoundary() { - // There is no front boundary in 2D - mooseError("There is no front boundary in 2 dimensions."); -} - -template <> -void -LBMFixedFirstOrderBCTempl<19>::frontBoundary() -{ - // TBD - mooseError("Front boundary for D3Q19 is not implemented."); -} - -template <> -void -LBMFixedFirstOrderBCTempl<27>::frontBoundary() -{ - // TBD - mooseError("Front boundary for D3Q27 is not implemented."); -} - -template <> -void -LBMFixedFirstOrderBCTempl<9>::backBoundary() -{ - // There is no back boundary in 2D - mooseError("There is no back boundary in 2 dimensions."); -} - -template <> -void -LBMFixedFirstOrderBCTempl<19>::backBoundary() -{ - // TBD - mooseError("Back boundary for D3Q19 is not implemented."); + if (_domain.getDim() == 2) + mooseError("There is no front boundary in 2 dimensions."); + else + mooseError("Front boundary is not implemented, but it can be replaced by any other boundary by " + "rotating the domain."); } -template <> void -LBMFixedFirstOrderBCTempl<27>::backBoundary() +LBMFixedFirstOrderBC::backBoundary() { - // TBD - mooseError("Back boundary for D3Q27 is not implemented."); + if (_domain.getDim() == 2) + mooseError("There is no back boundary in 2 dimensions."); + else + mooseError("Back boundary is not implemented, but it can be replaced by any other boundary by " + "rotating the domain."); } -template <> void -LBMFixedFirstOrderBCTempl<9>::leftBoundary() +LBMFixedFirstOrderBC::leftBoundaryD2Q9() { Real deltaU = 0.0; torch::Tensor u_x_perturbed = torch::zeros({_grid_size[1], 1}, MooseTensor::floatTensorOptions()); @@ -132,64 +99,34 @@ LBMFixedFirstOrderBCTempl<9>::leftBoundary() } } -template <> void -LBMFixedFirstOrderBCTempl<19>::leftBoundary() +LBMFixedFirstOrderBC::leftBoundary() { - torch::Tensor density = 1.0 / (1.0 - _value) * - (torch::sum(_f.index({0, Slice(), Slice(), -_stencil._neutral_x}), -1) + - 2 * torch::sum(_f.index({0, Slice(), Slice(), _stencil._right}), -1)); - - _u.index_put_({0, Slice(), Slice(), _stencil._left[0]}, - _f.index({0, Slice(), Slice(), _stencil._right[0]}) + - 2.0 * _stencil._weights[_stencil._left[0]] / _lb_problem._cs2 * _value * - density); - - for (unsigned int i = 1; i < _stencil._left.size(0); i++) - { - _u.index_put_({0, Slice(), Slice(), _stencil._left[i]}, - _f.index({0, Slice(), Slice(), _stencil._right[i]}) + - 2.0 * _stencil._weights[_stencil._left[i]] / _lb_problem._cs2 * _value * - density); - } -} - -template <> -void -LBMFixedFirstOrderBCTempl<27>::leftBoundary() -{ - torch::Tensor density = 1.0 / (1.0 - _value) * - (torch::sum(_f.index({0, Slice(), Slice(), -_stencil._neutral_x}), -1) + - 2 * torch::sum(_f.index({0, Slice(), Slice(), _stencil._right}), -1)); - - _u.index_put_({0, Slice(), Slice(), _stencil._left[0]}, - _f.index({0, Slice(), Slice(), _stencil._right[0]}) + - 2.0 * _stencil._weights[_stencil._left[0]] / _lb_problem._cs2 * _value * - density); - - for (unsigned int i = 1; i < _stencil._left.size(0); i++) + if (_stencil._q == 9) + leftBoundaryD2Q9(); // higher order specialization for D2Q9 + else { - // auto n1 = torch::sum(_f.index({0, Slice(), Slice(), _stencil._neutral_x_pos_y}), -1); - // auto n2 = torch::sum(_f.index({0, Slice(), Slice(), _stencil._neutral_x_neg_y}), -1); - // auto n3 = torch::sum(_f.index({0, Slice(), Slice(), _stencil._neutral_x_pos_z}), -1); - // auto n4 = torch::sum(_f.index({0, Slice(), Slice(), _stencil._neutral_x_neg_z}), -1); + torch::Tensor density = 1.0 / (1.0 - _value) * + (torch::sum(_f.index({0, Slice(), Slice(), -_stencil._neutral_x}), -1) + + 2 * torch::sum(_f.index({0, Slice(), Slice(), _stencil._right}), -1)); - _u.index_put_({0, Slice(), Slice(), _stencil._left[i]}, - _f.index({0, Slice(), Slice(), _stencil._right[i]}) + - 2.0 * _stencil._weights[_stencil._left[i]] / _lb_problem._cs2 * _value * + _u.index_put_({0, Slice(), Slice(), _stencil._left[0]}, + _f.index({0, Slice(), Slice(), _stencil._right[0]}) + + 2.0 * _stencil._weights[_stencil._left[0]] / _lb_problem._cs2 * _value * density); - /*- - 0.5 * _stencil._ey[_stencil._left[i]] * (n1 - n2) - - 0.5 * _stencil._ez[_stencil._left[i]] * (n3 - n4) - - 0.5 * _stencil._ey[_stencil._left[i]] * _stencil._ez[_stencil._left[i]] * - (_f.index({0, Slice(), Slice(), 15}) + _f.index({0, Slice(), Slice(), 18})) */ + for (unsigned int i = 1; i < _stencil._left.size(0); i++) + { + _u.index_put_({0, Slice(), Slice(), _stencil._left[i]}, + _f.index({0, Slice(), Slice(), _stencil._right[i]}) + + 2.0 * _stencil._weights[_stencil._left[i]] / _lb_problem._cs2 * _value * + density); + } } } -template <> void -LBMFixedFirstOrderBCTempl<9>::rightBoundary() +LBMFixedFirstOrderBC::rightBoundaryD2Q9() { torch::Tensor density = 1.0 / (1.0 + _value) * (_f.index({_grid_size[0] - 1, Slice(), Slice(), 0}) + @@ -218,72 +155,35 @@ LBMFixedFirstOrderBCTempl<9>::rightBoundary() } } -template <> void -LBMFixedFirstOrderBCTempl<19>::rightBoundary() +LBMFixedFirstOrderBC::rightBoundary() { - torch::Tensor density = - 1.0 / (1.0 + _value) * - (torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), -_stencil._neutral_x}), -1) + - 2 * torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left}), -1)); - - _u.index_put_({_grid_size[0] - 1, Slice(), Slice(), _stencil._right[0]}, - _f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left[0]}) - - 2.0 * _stencil._weights[_stencil._right[0]] / _lb_problem._cs2 * _value * - density); - - for (unsigned int i = 1; i < _stencil._right.size(0); i++) + if (_stencil._q == 9) + rightBoundaryD2Q9(); // higher order specialization for D2Q9 + else { - _u.index_put_({_grid_size[0] - 1, Slice(), Slice(), _stencil._right[i]}, - _f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left[i]}) - - 2.0 * _stencil._weights[_stencil._right[i]] / _lb_problem._cs2 * _value * + torch::Tensor density = + 1.0 / (1.0 + _value) * + (torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), -_stencil._neutral_x}), -1) + + 2 * torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left}), -1)); + + _u.index_put_({_grid_size[0] - 1, Slice(), Slice(), _stencil._right[0]}, + _f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left[0]}) - + 2.0 * _stencil._weights[_stencil._right[0]] / _lb_problem._cs2 * _value * density); - } -} - -template <> -void -LBMFixedFirstOrderBCTempl<27>::rightBoundary() -{ - torch::Tensor density = - 1.0 / (1.0 + _value) * - (torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), -_stencil._neutral_x}), -1) + - 2 * torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left}), -1)); - - _u.index_put_({_grid_size[0] - 1, Slice(), Slice(), _stencil._right[0]}, - _f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left[0]}) - - 2.0 * _stencil._weights[_stencil._right[0]] / _lb_problem._cs2 * _value * - density); - for (unsigned int i = 1; i < _stencil._right.size(0); i++) - { - // auto n1 = - // torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._neutral_x_pos_y}), - // -1); - // auto n2 = - // torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._neutral_x_neg_y}), - // -1); - - // auto n3 = - // torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._neutral_x_pos_z}), - // -1); - // auto n4 = - // torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._neutral_x_neg_z}), - // -1); - - _u.index_put_({_grid_size[0] - 1, Slice(), Slice(), _stencil._right[i]}, - _f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left[i]}) - - 2.0 * _stencil._weights[_stencil._right[i]] / _lb_problem._cs2 * _value * - density); - /*+ - 0.5 * _stencil._ey[_stencil._right[i]] * (n1 - n2) - - 0.5 * _stencil._ez[_stencil._right[i]] * (n3 - n4)*/ + for (unsigned int i = 1; i < _stencil._right.size(0); i++) + { + _u.index_put_({_grid_size[0] - 1, Slice(), Slice(), _stencil._right[i]}, + _f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left[i]}) - + 2.0 * _stencil._weights[_stencil._right[i]] / _lb_problem._cs2 * _value * + density); + } } } -template <> void -LBMFixedFirstOrderBCTempl<9>::bottomBoundary() +LBMFixedFirstOrderBC::bottomBoundaryD2Q9() { torch::Tensor density = 1.0 / (1.0 - _value) * @@ -310,25 +210,18 @@ LBMFixedFirstOrderBCTempl<9>::bottomBoundary() } } -template <> -void -LBMFixedFirstOrderBCTempl<19>::bottomBoundary() -{ - // TBD - mooseError("Bottom boundary for D3Q19 is not implemented."); -} - -template <> void -LBMFixedFirstOrderBCTempl<27>::bottomBoundary() +LBMFixedFirstOrderBC::bottomBoundary() { - // TBD - mooseError("Bottom boundary for D3Q27 is not implemented."); + if (_stencil._q == 9) + bottomBoundaryD2Q9(); + else + mooseError("Bottom boundary is not implemented, but it can be replaced by another boundary by " + "rotating the domain."); } -template <> void -LBMFixedFirstOrderBCTempl<9>::topBoundary() +LBMFixedFirstOrderBC::topBoundaryD2Q9() { torch::Tensor density = 1.0 / (1.0 + _value) * (_f.index({Slice(), _grid_size[1] - 1, Slice(), 0}) + @@ -357,25 +250,18 @@ LBMFixedFirstOrderBCTempl<9>::topBoundary() } } -template <> void -LBMFixedFirstOrderBCTempl<19>::topBoundary() +LBMFixedFirstOrderBC::topBoundary() { - // TBD - mooseError("Top boundary for D3Q19 is not implemented."); -} - -template <> -void -LBMFixedFirstOrderBCTempl<27>::topBoundary() -{ - // TBD - mooseError("Top boundary for D3Q27 is not implemented."); + if (_stencil._q == 9) + topBoundaryD2Q9(); + else + mooseError("Top boundary is not implemented, but it can be replaced by another boundary by " + "rotating the domain."); } -template void -LBMFixedFirstOrderBCTempl::computeBuffer() +LBMFixedFirstOrderBC::computeBuffer() { _u = _u.clone(); switch (_boundary) @@ -406,7 +292,3 @@ LBMFixedFirstOrderBCTempl::computeBuffer() } _lb_problem.maskedFillSolids(_u, 0); } - -template class LBMFixedFirstOrderBCTempl<9>; -template class LBMFixedFirstOrderBCTempl<19>; -template class LBMFixedFirstOrderBCTempl<27>; diff --git a/src/tensor_computes/LBMFixedZerothOrderBC.C b/src/tensor_computes/LBMFixedZerothOrderBC.C index 98d27ee..2539ed3 100644 --- a/src/tensor_computes/LBMFixedZerothOrderBC.C +++ b/src/tensor_computes/LBMFixedZerothOrderBC.C @@ -12,13 +12,10 @@ using namespace torch::indexing; -registerMooseObject("SwiftApp", LBMFixedZerothOrderBC9Q); -registerMooseObject("SwiftApp", LBMFixedZerothOrderBC19Q); -registerMooseObject("SwiftApp", LBMFixedZerothOrderBC27Q); +registerMooseObject("SwiftApp", LBMFixedZerothOrderBC); -template InputParameters -LBMFixedZerothOrderBCTempl::validParams() +LBMFixedZerothOrderBC::validParams() { InputParameters params = LBMBoundaryCondition::validParams(); params.addClassDescription("LBMFixedZerothOrderBC object"); @@ -27,9 +24,7 @@ LBMFixedZerothOrderBCTempl::validParams() return params; } -template -LBMFixedZerothOrderBCTempl::LBMFixedZerothOrderBCTempl( - const InputParameters & parameters) +LBMFixedZerothOrderBC::LBMFixedZerothOrderBC(const InputParameters & parameters) : LBMBoundaryCondition(parameters), _f(getInputBufferByName(getParam("f"))), _grid_size(_lb_problem.getGridSize()), @@ -37,57 +32,28 @@ LBMFixedZerothOrderBCTempl::LBMFixedZerothOrderBCTempl( { } -template <> void -LBMFixedZerothOrderBCTempl<9>::frontBoundary() +LBMFixedZerothOrderBC::frontBoundary() { - // There is no front boundary in 2D - mooseError("There is no front boundary in 2 dimensions."); + if (_domain.getDim() == 2) + mooseError("There is no front boundary in 2 dimensions."); + else + mooseError("Front boundary is not implemented, but it can be replaced by any other boundary by " + "rotating the domain."); } -template <> void -LBMFixedZerothOrderBCTempl<19>::frontBoundary() +LBMFixedZerothOrderBC::backBoundary() { - // TBD - mooseError("Front boundary for D3Q19 is not implemented."); + if (_domain.getDim() == 2) + mooseError("There is no back boundary in 2 dimensions."); + else + mooseError("Back boundary is not implemented, but it can be replaced by any other boundary by " + "rotating the domain."); } -template <> void -LBMFixedZerothOrderBCTempl<27>::frontBoundary() -{ - // TBD - mooseError("Front boundary for D3Q27 is not implemented."); -} - -template <> -void -LBMFixedZerothOrderBCTempl<9>::backBoundary() -{ - // There is no back boundary in 2D - mooseError("There is no back boundary in 2 dimensions."); -} - -template <> -void -LBMFixedZerothOrderBCTempl<19>::backBoundary() -{ - // TBD - mooseError("Back boundary for D3Q19 is not implemented."); -} - -template <> -void -LBMFixedZerothOrderBCTempl<27>::backBoundary() -{ - // TBD - mooseError("Back boundary for D3Q27 is not implemented."); -} - -template <> -void -LBMFixedZerothOrderBCTempl<9>::leftBoundary() +LBMFixedZerothOrderBC::leftBoundaryD2Q9() { torch::Tensor velocity = 1.0 - (_f.index({0, Slice(), Slice(), 0}) + _f.index({0, Slice(), Slice(), 2}) + @@ -114,63 +80,35 @@ LBMFixedZerothOrderBCTempl<9>::leftBoundary() } } -template <> void -LBMFixedZerothOrderBCTempl<19>::leftBoundary() +LBMFixedZerothOrderBC::leftBoundary() { - torch::Tensor velocity = - 1.0 - (torch::sum(_f.index({0, Slice(), Slice(), -_stencil._neutral_x}), -1) + - 2 * torch::sum(_f.index({0, Slice(), Slice(), _stencil._right}), -1)) / - _value; - - _u.index_put_({0, Slice(), Slice(), _stencil._left[0]}, - _f.index({0, Slice(), Slice(), _stencil._right[0]}) + - 2.0 * _stencil._weights[_stencil._left[0]] / _lb_problem._cs2 * _value * - velocity); - - for (unsigned int i = 1; i < _stencil._left.size(0); i++) + if (_stencil._q == 9) + leftBoundaryD2Q9(); + else { - _u.index_put_({0, Slice(), Slice(), _stencil._left[i]}, - _f.index({0, Slice(), Slice(), _stencil._right[i]}) + - 2.0 * _stencil._weights[_stencil._left[i]] / _lb_problem._cs2 * _value * + torch::Tensor velocity = + 1.0 - (torch::sum(_f.index({0, Slice(), Slice(), -_stencil._neutral_x}), -1) + + 2 * torch::sum(_f.index({0, Slice(), Slice(), _stencil._right}), -1)) / + _value; + + _u.index_put_({0, Slice(), Slice(), _stencil._left[0]}, + _f.index({0, Slice(), Slice(), _stencil._right[0]}) + + 2.0 * _stencil._weights[_stencil._left[0]] / _lb_problem._cs2 * _value * velocity); - } -} - -template <> -void -LBMFixedZerothOrderBCTempl<27>::leftBoundary() -{ - torch::Tensor velocity = - 1.0 - (torch::sum(_f.index({0, Slice(), Slice(), -_stencil._neutral_x}), -1) + - 2 * torch::sum(_f.index({0, Slice(), Slice(), _stencil._right}), -1)) / - _value; - _u.index_put_({0, Slice(), Slice(), _stencil._left[0]}, - _f.index({0, Slice(), Slice(), _stencil._right[0]}) + - 2.0 * _stencil._weights[_stencil._left[0]] / _lb_problem._cs2 * _value * - velocity); - - for (unsigned int i = 1; i < _stencil._left.size(0); i++) - { - // auto n1 = torch::sum(_f.index({0, Slice(), Slice(), _stencil._neutral_x_pos_y}), -1); - // auto n2 = torch::sum(_f.index({0, Slice(), Slice(), _stencil._neutral_x_neg_y}), -1); - // auto n3 = torch::sum(_f.index({0, Slice(), Slice(), _stencil._neutral_x_pos_z}), -1); - // auto n4 = torch::sum(_f.index({0, Slice(), Slice(), _stencil._neutral_x_neg_z}), -1); - - _u.index_put_({0, Slice(), Slice(), _stencil._left[i]}, - _f.index({0, Slice(), Slice(), _stencil._right[i]}) + - 2.0 * _stencil._weights[_stencil._left[i]] / _lb_problem._cs2 * _value * - velocity); - /*- - 0.5 * _stencil._ey[_stencil._left[i]] * (n1 - n2) - - 0.5 * _stencil._ez[_stencil._left[i]] * (n3 - n4)*/ + for (unsigned int i = 1; i < _stencil._left.size(0); i++) + { + _u.index_put_({0, Slice(), Slice(), _stencil._left[i]}, + _f.index({0, Slice(), Slice(), _stencil._right[i]}) + + 2.0 * _stencil._weights[_stencil._left[i]] / _lb_problem._cs2 * _value * + velocity); + } } } -template <> void -LBMFixedZerothOrderBCTempl<9>::rightBoundary() +LBMFixedZerothOrderBC::rightBoundaryD2Q9() { torch::Tensor velocity = (_f.index({_grid_size[0] - 1, Slice(), Slice(), 0}) + _f.index({_grid_size[0] - 1, Slice(), Slice(), 2}) + @@ -200,74 +138,36 @@ LBMFixedZerothOrderBCTempl<9>::rightBoundary() } } -template <> void -LBMFixedZerothOrderBCTempl<19>::rightBoundary() +LBMFixedZerothOrderBC::rightBoundary() { - torch::Tensor velocity = - (torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), -_stencil._neutral_x}), -1) + - 2 * torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left}), -1)) / - _value - - 1.0; - - _u.index_put_({_grid_size[0] - 1, Slice(), Slice(), _stencil._right[0]}, - _f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left[0]}) - - 2.0 * _stencil._weights[_stencil._right[0]] / _lb_problem._cs2 * _value * - velocity); - - for (unsigned int i = 1; i < _stencil._right.size(0); i++) + if (_stencil._q == 9) + rightBoundaryD2Q9(); + else { - _u.index_put_({_grid_size[0] - 1, Slice(), Slice(), _stencil._right[i]}, - _f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left[i]}) - - 2.0 * _stencil._weights[_stencil._right[i]] / _lb_problem._cs2 * _value * + torch::Tensor velocity = + (torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), -_stencil._neutral_x}), -1) + + 2 * torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left}), -1)) / + _value - + 1.0; + + _u.index_put_({_grid_size[0] - 1, Slice(), Slice(), _stencil._right[0]}, + _f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left[0]}) - + 2.0 * _stencil._weights[_stencil._right[0]] / _lb_problem._cs2 * _value * velocity); - } -} - -template <> -void -LBMFixedZerothOrderBCTempl<27>::rightBoundary() -{ - torch::Tensor velocity = - (torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), -_stencil._neutral_x}), -1) + - 2 * torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left}), -1)) / - _value - - 1.0; - _u.index_put_({_grid_size[0] - 1, Slice(), Slice(), _stencil._right[0]}, - _f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left[0]}) - - 2.0 * _stencil._weights[_stencil._right[0]] / _lb_problem._cs2 * _value * - velocity); - - for (unsigned int i = 1; i < _stencil._right.size(0); i++) - { - // auto n1 = - // torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._neutral_x_pos_y}), - // -1); - // auto n2 = - // torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._neutral_x_neg_y}), - // -1); - - // auto n3 = - // torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._neutral_x_pos_z}), - // -1); - // auto n4 = - // torch::sum(_f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._neutral_x_neg_z}), - // -1); - - _u.index_put_({_grid_size[0] - 1, Slice(), Slice(), _stencil._right[i]}, - _f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left[i]}) - - 2.0 * _stencil._weights[_stencil._right[i]] / _lb_problem._cs2 * _value * - velocity); - /*+ - 0.5 * _stencil._ey[_stencil._right[i]] * (n1 - n2) + - 0.5 * _stencil._ez[_stencil._right[i]] * (n3 - n4)*/ + for (unsigned int i = 1; i < _stencil._right.size(0); i++) + { + _u.index_put_({_grid_size[0] - 1, Slice(), Slice(), _stencil._right[i]}, + _f.index({_grid_size[0] - 1, Slice(), Slice(), _stencil._left[i]}) - + 2.0 * _stencil._weights[_stencil._right[i]] / _lb_problem._cs2 * _value * + velocity); + } } } -template <> void -LBMFixedZerothOrderBCTempl<9>::bottomBoundary() +LBMFixedZerothOrderBC::bottomBoundaryD2Q9() { torch::Tensor velocity = 1.0 - (_f.index({Slice(), 0, Slice(), 0}) + _f.index({Slice(), 0, Slice(), 1}) + @@ -294,25 +194,19 @@ LBMFixedZerothOrderBCTempl<9>::bottomBoundary() } } -template <> -void -LBMFixedZerothOrderBCTempl<19>::bottomBoundary() -{ - // TBD - mooseError("Bottom boundary for D3Q19 is not implemented."); -} - -template <> void -LBMFixedZerothOrderBCTempl<27>::bottomBoundary() +LBMFixedZerothOrderBC::bottomBoundary() { // TBD - mooseError("Bottom boundary for D3Q27 is not implemented."); + if (_stencil._q == 9) + bottomBoundaryD2Q9(); + else + mooseError("Bottom boundary is not implemented, but it can be replaced by any other boundary " + "by rotating the domain"); } -template <> void -LBMFixedZerothOrderBCTempl<9>::topBoundary() +LBMFixedZerothOrderBC::topBoundaryD2Q9() { torch::Tensor velocity = (_f.index({Slice(), _grid_size[1] - 1, Slice(), 0}) + _f.index({Slice(), _grid_size[1] - 1, Slice(), 1}) + @@ -342,25 +236,19 @@ LBMFixedZerothOrderBCTempl<9>::topBoundary() } } -template <> -void -LBMFixedZerothOrderBCTempl<19>::topBoundary() -{ - // TBD - mooseError("Top boundary for D3Q19 is not implemented."); -} - -template <> void -LBMFixedZerothOrderBCTempl<27>::topBoundary() +LBMFixedZerothOrderBC::topBoundary() { // TBD - mooseError("Top boundary for D3Q27 is not implemented."); + if (_stencil._q == 9) + topBoundaryD2Q9(); + else + mooseError("Top boundary is not implemented, but it can be replaced by any other boundary by " + "rotating the domain"); } -template void -LBMFixedZerothOrderBCTempl::computeBuffer() +LBMFixedZerothOrderBC::computeBuffer() { switch (_boundary) { @@ -390,7 +278,3 @@ LBMFixedZerothOrderBCTempl::computeBuffer() } _lb_problem.maskedFillSolids(_u, 0); } - -template class LBMFixedZerothOrderBCTempl<9>; -template class LBMFixedZerothOrderBCTempl<19>; -template class LBMFixedZerothOrderBCTempl<27>; diff --git a/test/tests/lbm/advan_bc.i b/test/tests/lbm/advan_bc.i index 127ad57..9b6d509 100644 --- a/test/tests/lbm/advan_bc.i +++ b/test/tests/lbm/advan_bc.i @@ -221,7 +221,7 @@ [Boundary] ##### for fluid [inlet] - type = LBMFixedFirstOrderBC19Q + type = LBMFixedFirstOrderBC buffer = f f = f value = u0 @@ -269,7 +269,7 @@ ##### for temperature [t_inlet] - type = LBMFixedZerothOrderBC19Q + type = LBMFixedZerothOrderBC buffer = g f = g value = T_C diff --git a/test/tests/lbm/horizontal_mixed_bcs_d2q9.i b/test/tests/lbm/horizontal_mixed_bcs_d2q9.i index ab91c6b..e77e06d 100644 --- a/test/tests/lbm/horizontal_mixed_bcs_d2q9.i +++ b/test/tests/lbm/horizontal_mixed_bcs_d2q9.i @@ -66,14 +66,14 @@ [] [Boundary] [left] - type = LBMFixedZerothOrderBC9Q + type = LBMFixedZerothOrderBC buffer = f f = f value = 1.1 boundary = left [] [right] - type = LBMFixedFirstOrderBC9Q + type = LBMFixedFirstOrderBC buffer = f f = f value = 0.0001 diff --git a/test/tests/lbm/horizontal_mixed_bcs_d2q9_reverse.i b/test/tests/lbm/horizontal_mixed_bcs_d2q9_reverse.i index 7e3f065..612ba3e 100644 --- a/test/tests/lbm/horizontal_mixed_bcs_d2q9_reverse.i +++ b/test/tests/lbm/horizontal_mixed_bcs_d2q9_reverse.i @@ -66,7 +66,7 @@ [] [Boundary] [right] - type = LBMFixedZerothOrderBC9Q + type = LBMFixedZerothOrderBC buffer = f f = f value = 1.1 diff --git a/test/tests/lbm/mixed_bcs_d3q19.i b/test/tests/lbm/mixed_bcs_d3q19.i index 96a2f93..b9abeb5 100644 --- a/test/tests/lbm/mixed_bcs_d3q19.i +++ b/test/tests/lbm/mixed_bcs_d3q19.i @@ -67,14 +67,14 @@ [] [Boundary] [left] - type = LBMFixedZerothOrderBC19Q + type = LBMFixedZerothOrderBC buffer = f f = f value = 1.11 boundary = left [] [right] - type = LBMFixedFirstOrderBC19Q + type = LBMFixedFirstOrderBC buffer = f f = f value = 0.0001 diff --git a/test/tests/lbm/mixed_bcs_d3q19_reverse.i b/test/tests/lbm/mixed_bcs_d3q19_reverse.i index d2b2910..6d13a32 100644 --- a/test/tests/lbm/mixed_bcs_d3q19_reverse.i +++ b/test/tests/lbm/mixed_bcs_d3q19_reverse.i @@ -67,14 +67,14 @@ [] [Boundary] [right] - type = LBMFixedZerothOrderBC19Q + type = LBMFixedZerothOrderBC buffer = f f = f value = 1.11 boundary = right [] [left] - type = LBMFixedFirstOrderBC19Q + type = LBMFixedFirstOrderBC buffer = f f = f value = 0.0001 diff --git a/test/tests/lbm/mixed_bcs_d3q27.i b/test/tests/lbm/mixed_bcs_d3q27.i index 0300e66..b4e7e28 100644 --- a/test/tests/lbm/mixed_bcs_d3q27.i +++ b/test/tests/lbm/mixed_bcs_d3q27.i @@ -67,14 +67,14 @@ [] [Boundary] [left] - type = LBMFixedZerothOrderBC27Q + type = LBMFixedZerothOrderBC buffer = f f = f value = 1.1 boundary = left [] [right] - type = LBMFixedFirstOrderBC27Q + type = LBMFixedFirstOrderBC buffer = f f = f value = 0.0001 diff --git a/test/tests/lbm/mixed_bcs_d3q27_reverse.i b/test/tests/lbm/mixed_bcs_d3q27_reverse.i index 2387e1e..a24137a 100644 --- a/test/tests/lbm/mixed_bcs_d3q27_reverse.i +++ b/test/tests/lbm/mixed_bcs_d3q27_reverse.i @@ -67,14 +67,14 @@ [] [Boundary] [right] - type = LBMFixedZerothOrderBC27Q + type = LBMFixedZerothOrderBC buffer = f f = f value = 1.1 boundary = right [] [left] - type = LBMFixedFirstOrderBC27Q + type = LBMFixedFirstOrderBC buffer = f f = f value = 0.0001 diff --git a/test/tests/lbm/obstacle.i b/test/tests/lbm/obstacle.i index 54cc4aa..0a1175e 100644 --- a/test/tests/lbm/obstacle.i +++ b/test/tests/lbm/obstacle.i @@ -125,7 +125,7 @@ boundary = wall [] [left] - type = LBMFixedFirstOrderBC9Q + type = LBMFixedFirstOrderBC buffer=f f=f value='Ux' diff --git a/test/tests/lbm/vertical_density_bcs.i b/test/tests/lbm/vertical_density_bcs.i index 90943e8..d65ae2f 100644 --- a/test/tests/lbm/vertical_density_bcs.i +++ b/test/tests/lbm/vertical_density_bcs.i @@ -76,14 +76,14 @@ boundary = right [] [top] - type = LBMFixedZerothOrderBC9Q + type = LBMFixedZerothOrderBC buffer = f f = f value = 1.1 boundary = top [] [bottom] - type = LBMFixedZerothOrderBC9Q + type = LBMFixedZerothOrderBC buffer = f f = f value = 1.00000 diff --git a/test/tests/lbm/vertical_velocity_bcs.i b/test/tests/lbm/vertical_velocity_bcs.i index 3843051..60072d6 100644 --- a/test/tests/lbm/vertical_velocity_bcs.i +++ b/test/tests/lbm/vertical_velocity_bcs.i @@ -78,14 +78,14 @@ boundary = right [] [top] - type = LBMFixedFirstOrderBC9Q + type = LBMFixedFirstOrderBC buffer = f f = f value = 0.0001 boundary = top [] [bottom] - type = LBMFixedFirstOrderBC9Q + type = LBMFixedFirstOrderBC buffer = f f = f value = 0.00011