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 "LBMD3Q27.h"
10 :
11 : registerMooseObject("SwiftApp", LBMD3Q27);
12 :
13 : InputParameters
14 0 : LBMD3Q27::validParams()
15 : {
16 0 : InputParameters params = LatticeBoltzmannStencilBase::validParams();
17 0 : params.addClassDescription("LBMD3Q27 Stencil object.");
18 0 : return params;
19 0 : }
20 :
21 0 : LBMD3Q27::LBMD3Q27(const InputParameters & parameters) : LatticeBoltzmannStencilBase(parameters)
22 : {
23 0 : _q = 27;
24 :
25 : // LBMD3Q27 lattice
26 0 : _ex = torch::tensor(
27 : {0, 1, -1, 0, 0, 0, 0, 1, 1, -1, -1, 1, 1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 1, -1, -1, -1, -1},
28 0 : MooseTensor::intTensorOptions());
29 :
30 0 : _ey = torch::tensor(
31 : {0, 0, 0, 1, -1, 0, 0, 1, -1, 1, -1, 0, 0, 0, 0, 1, 1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1},
32 0 : MooseTensor::intTensorOptions());
33 :
34 0 : _ez = torch::tensor(
35 : {0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, -1},
36 0 : MooseTensor::intTensorOptions());
37 :
38 0 : _weights = torch::tensor(
39 : {8.0 / 27.0, 2.0 / 27.0, 2.0 / 27.0, 2.0 / 27.0, 2.0 / 27.0, 2.0 / 27.0, 2.0 / 27.0,
40 : 1.0 / 54.0, 1.0 / 54.0, 1.0 / 54.0, 1.0 / 54.0, 1.0 / 54.0, 1.0 / 54.0, 1.0 / 54.0,
41 : 1.0 / 54.0, 1.0 / 54.0, 1.0 / 54.0, 1.0 / 54.0, 1.0 / 54.0, 1.0 / 216.0, 1.0 / 216.0,
42 : 1.0 / 216.0, 1.0 / 216.0, 1.0 / 216.0, 1.0 / 216.0, 1.0 / 216.0, 1.0 / 216.0},
43 0 : MooseTensor::floatTensorOptions());
44 :
45 0 : _op = torch::tensor({0, 2, 1, 4, 3, 6, 5, 10, 9, 8, 7, 14, 13, 12,
46 : 11, 18, 17, 16, 15, 25, 26, 23, 24, 21, 22, 19, 20},
47 0 : MooseTensor::intTensorOptions());
48 :
49 : // transformation matrix
50 0 : _M = torch::tensor(
51 : {{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
52 : 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0},
53 : {1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0, -1.0, -1.0, 1.0, 1.0, 0.0, -1.0, 0.0,
54 : 1.0, 0.0, -1.0, 0.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 0.0},
55 : {0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, -1.0, -1.0, 0.0, 1.0, 0.0, -1.0,
56 : 0.0, 1.0, 0.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 0.0},
57 : {0.0, 0.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
58 : -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 0.0},
59 : {-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
60 : 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -2.0},
61 : {2.0, -1.0, 2.0, -1.0, -1.0, -1.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1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 0.0}},
105 0 : MooseTensor::floatTensorOptions());
106 :
107 0 : _M_inv = at::linalg_inv(_M);
108 :
109 : // relaxation matrix
110 0 : _S = torch::diag(torch::tensor(
111 : {
112 : 0.0, 0.0, 0.0, 0.0, 1.0 / 1.54, 1.0 / 1.0, 1.0 / 1.0,
113 : 1.0 / 1.0, 1.0 / 1.0, 1.0 / 1.0, 1.0 / 1.5, 1.0 / 1.5, 1.0 / 1.5, 1.0 / 1.83,
114 : 1.0 / 1.83, 1.0 / 1.83, 1.0 / 1.4, 1.0 / 1.61, 1.0 / 1.98, 1.0 / 1.98, 1.0 / 1.98,
115 : 1.0 / 1.98, 1.0 / 1.98, 1.0 / 1.74, 1.0 / 1.74, 1.0 / 1.74, 1.0 / 1.74,
116 : },
117 0 : MooseTensor::floatTensorOptions()));
118 :
119 : // indices where relaxation parameter related to kinematic viscosity (i.e. shear stress) is
120 : // located
121 0 : _id_kinematic_visc = torch::tensor({5, 6, 7, 8, 9}, MooseTensor::intTensorOptions());
122 : /**
123 : * incoming unknown distribution functions at every face
124 : * the opposite faces can be determined using _op vector
125 : * E.g. the opposite of _top[0] is _bottom[0] = _op[top[0]]
126 : */
127 0 : _left = torch::tensor({1, 7, 8, 11, 12, 19, 20, 21, 22},
128 0 : MooseTensor::intTensorOptions()); // x dir; x = 0
129 0 : _right = _op.index({_left}); // x dir; x = nx-1
130 :
131 0 : _bottom = torch::tensor({3, 7, 9, 15, 16, 19, 22, 23, 26},
132 0 : MooseTensor::intTensorOptions()); // y dir; y = 0
133 0 : _top = _op.index({_bottom}); // y dir; x = ny-1
134 :
135 0 : _front = torch::tensor({5, 11, 13, 15, 17, 19, 20, 23, 24},
136 0 : MooseTensor::intTensorOptions()); // z dir ; z = 0
137 0 : _back = _op.index({_front}); // z dir; z = nz-1
138 :
139 : // further classify directions
140 0 : _neutral_x = torch::tensor({0, 3, 4, 5, 6, 15, 16, 17, 18}, MooseTensor::intTensorOptions());
141 0 : _neutral_x_pos_y = torch::tensor({3, 15, 16}, MooseTensor::intTensorOptions());
142 0 : _neutral_x_neg_y = _op.index({_neutral_x_pos_y});
143 0 : _neutral_x_pos_z = torch::tensor({5, 15, 17}, MooseTensor::intTensorOptions());
144 0 : _neutral_x_neg_z = _op.index({_neutral_x_pos_z});
145 0 : }
|