From 2af28a3c70bfcc938d17ad587f5242e95b292d92 Mon Sep 17 00:00:00 2001 From: Daniel Garcia-Sanchez Date: Sun, 31 May 2020 16:36:28 +0200 Subject: [PATCH] Improve the assembly efficiency of step-62 --- examples/step-62/step-62.cc | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/examples/step-62/step-62.cc b/examples/step-62/step-62.cc index 0840067677..88ff8e2047 100644 --- a/examples/step-62/step-62.cc +++ b/examples/step-62/step-62.cc @@ -877,6 +877,24 @@ namespace step62 s[component] = pml_values[q][component]; xi *= s[component]; } + + // Here we calculate the $\alpha_{mnkl}$ and $\beta_{mnkl}$ + // tensors. + Tensor<4, dim, std::complex> alpha; + Tensor<4, dim, std::complex> beta; + for (unsigned int m = 0; m < dim; ++m) + for (unsigned int n = 0; n < dim; ++n) + for (unsigned int k = 0; k < dim; ++k) + for (unsigned int l = 0; l < dim; ++l) + { + alpha[m][n][k][l] = xi * + stiffness_tensor[m][n][k][l] / + (2.0 * s[n] * s[k]); + beta[m][n][k][l] = xi * + stiffness_tensor[m][n][k][l] / + (2.0 * s[n] * s[l]); + } + for (unsigned int i = 0; i < dofs_per_cell; ++i) { const Tensor<1, dim> phi_i = @@ -903,15 +921,6 @@ namespace step62 for (unsigned int k = 0; k < dim; ++k) for (unsigned int l = 0; l < dim; ++l) { - // Here we calculate the tensors - // $\alpha_{mnkl}$ and $\beta_{mnkl}$ - const std::complex alpha = - xi * stiffness_tensor[m][n][k][l] / - (2.0 * s[n] * s[k]); - const std::complex beta = - xi * stiffness_tensor[m][n][k][l] / - (2.0 * s[n] * s[l]); - // Here we calculate the stiffness matrix. // Note that the stiffness matrix is not // symmetric because of the PMLs. We use the @@ -931,8 +940,8 @@ namespace step62 // very easy to make a mistake. stiffness_coefficient += grad_phi_i[m][n] * - (alpha * grad_phi_j[l][k] + - beta * grad_phi_j[k][l]); + (alpha[m][n][k][l] * grad_phi_j[l][k] + + beta[m][n][k][l] * grad_phi_j[k][l]); } // We save the value of the stiffness matrix in -- 2.39.5