From fea380f9cdafa16097a6948bfb78c0d1ab82ffa8 Mon Sep 17 00:00:00 2001 From: Rene Gassmoeller Date: Thu, 23 May 2024 09:31:19 +0200 Subject: [PATCH] Add unroll and constructor for SymmetricTensor --- include/aspect/utilities.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/aspect/utilities.h b/include/aspect/utilities.h index 33fe7ca1a87..5a6fadc1bab 100644 --- a/include/aspect/utilities.h +++ b/include/aspect/utilities.h @@ -1245,6 +1245,36 @@ namespace aspect */ namespace Tensors { + /** + * Convert a vector of doubles to a SymmetricTensor of the same size. + */ + template + inline + SymmetricTensor<2,dim> + to_symmetric_tensor(const ArrayView &values) + { + // Assemble stress tensor if elastic behavior is enabled + SymmetricTensor<2,dim> output; + for (unsigned int i=0; i < SymmetricTensor<2,dim>::n_independent_components; ++i) + output[SymmetricTensor<2,dim>::unrolled_to_component_indices(i)] = values[i]; + + return output; + }; + + + + /** + * Convert a vector of doubles to a SymmetricTensor of the same size. + */ + template + inline + void + unroll(const SymmetricTensor<2,dim> &tensor, + const ArrayView &values) + { + for (unsigned int i=0; i < SymmetricTensor<2,dim>::n_independent_components; ++i) + values[i] = tensor[SymmetricTensor<2,dim>::unrolled_to_component_indices(i)]; + }; /** * Rotate a 3D 4th order tensor representing the full stiffnexx matrix using a 3D 2nd order rotation tensor