From eca43782c93a0fd7ea4186a1a0d59c5545abf34a Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Sun, 30 Nov 2014 15:38:23 +0100 Subject: [PATCH] Avoid unnecessary inversion of a transformation matrix --- source/dofs/dof_tools_constraints.cc | 38 ++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/source/dofs/dof_tools_constraints.cc b/source/dofs/dof_tools_constraints.cc index cf1832a494..3811a3433c 100644 --- a/source/dofs/dof_tools_constraints.cc +++ b/source/dofs/dof_tools_constraints.cc @@ -2129,19 +2129,35 @@ namespace DoFTools const FullMatrix transformation = compute_transformation(fe, matrix, first_vector_components); - if (!face_2->has_children()) + if (! face_2->has_children()) { - FullMatrix inverse(transformation.m()); - inverse.invert(transformation); + // Performance hack: We do not need to compute an inverse if + // the matrix is the identity matrix. + if (first_vector_components.empty() && matrix.m() == 0) + { + set_periodicity_constraints(face_2, + face_1, + transformation, + constraint_matrix, + component_mask, + face_orientation, + face_flip, + face_rotation); + } + else + { + FullMatrix inverse(transformation.m()); + inverse.invert(transformation); - set_periodicity_constraints(face_2, - face_1, - inverse, - constraint_matrix, - component_mask, - face_orientation, - face_flip, - face_rotation); + set_periodicity_constraints(face_2, + face_1, + inverse, + constraint_matrix, + component_mask, + face_orientation, + face_flip, + face_rotation); + } } else { -- 2.39.5