PRISMS-PF Manual v3.0-pre
All Classes Functions Variables Enumerations Pages
utilities.h
1// SPDX-FileCopyrightText: © 2025 PRISMS Center at the University of Michigan
2// SPDX-License-Identifier: GNU Lesser General Public Version 2.1
3
4#ifndef utilities_h
5#define utilities_h
6
7#include <deal.II/base/tensor.h>
8#include <deal.II/base/vectorization.h>
9#include <deal.II/matrix_free/evaluation_flags.h>
10
11#include <prismspf/config.h>
12
13#include <array>
14
15PRISMS_PF_BEGIN_NAMESPACE
16
20template <typename number, typename T>
21constexpr auto
22constV(T value)
23{
24 return dealii::make_vectorized_array<number>(static_cast<number>(value));
25}
26
30template <int dim, typename number>
31constexpr auto
32constT(const std::array<number, dim> &vector)
33{
34 dealii::Tensor<1, dim, dealii::VectorizedArray<number>> tensor;
35
36 // Populate the Tensor with vectorized arrays
37 for (std::size_t i = 0; i < dim; ++i)
38 {
39 tensor[i] = dealii::make_vectorized_array<number>(vector[i]);
40 }
41
42 return tensor;
43}
44
49template <int dim, typename T>
50inline void
51compute_stress(const dealii::Tensor<2, (2 * dim) - 1 + (dim / 3), T> &elasticity_tensor,
52 const dealii::Tensor<1, (2 * dim) - 1 + (dim / 3), T> &strain,
53 dealii::Tensor<1, (2 * dim) - 1 + (dim / 3), T> &stress)
54{
55 stress = elasticity_tensor * strain;
56}
57
61inline const char *
62bool_to_string(bool boolean)
63{
64 return boolean ? "true" : "false";
65}
66
70inline std::string
71eval_flags_to_string(dealii::EvaluationFlags::EvaluationFlags flag)
72{
73 std::string result;
74
75 if ((flag & dealii::EvaluationFlags::values) != 0U)
76 {
77 result += "values";
78 }
79 if ((flag & dealii::EvaluationFlags::gradients) != 0U)
80 {
81 if (!result.empty())
82 {
83 result += " | ";
84 }
85 result += "gradients";
86 }
87 if ((flag & dealii::EvaluationFlags::hessians) != 0U)
88 {
89 if (!result.empty())
90 {
91 result += " | ";
92 }
93 result += "hessians";
94 }
95
96 if (result.empty())
97 {
98 return "nothing";
99 }
100
101 return result;
102}
103
104PRISMS_PF_END_NAMESPACE
105
106#endif