https://mooseframework.inl.gov
SymmetricRankTwoTensorImplementation.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
12 template <>
13 void
14 SymmetricRankTwoTensor::syev(const char * calculation_type,
15  std::vector<Real> & eigvals,
16  std::vector<Real> & a) const
17 {
18  eigvals.resize(Ndim);
19  a.resize(Ndim * Ndim);
20 
21  // prepare data for the LAPACKsyev_ routine (which comes from petscblaslapack.h)
22  PetscBLASInt nd = Ndim;
23  PetscBLASInt lwork = 66 * nd;
24  PetscBLASInt info;
25  std::vector<PetscScalar> work(lwork);
26 
27  auto A = RankTwoTensor(*this);
28  for (auto i : make_range(Ndim))
29  for (auto j : make_range(Ndim))
30  // a is destroyed by dsyev, and if calculation_type == "V" then eigenvectors are placed
31  // there
32  a[i * Ndim + j] = A(i, j);
33 
34  // compute the eigenvalues only (if calculation_type == "N"),
35  // or both the eigenvalues and eigenvectors (if calculation_type == "V")
36  // assume upper triangle of a is stored (second "U")
37  LAPACKsyev_(calculation_type, "U", &nd, &a[0], &nd, &eigvals[0], &work[0], &lwork, &info);
38 
39  if (info != 0)
40  mooseError("In computing the eigenvalues and eigenvectors for the symmetric rank-2 tensor (",
42  "), the PETSC LAPACK syev routine returned error code ",
43  info);
44 }
45 
46 template <>
47 void
48 SymmetricRankTwoTensor::symmetricEigenvalues(std::vector<Real> & eigvals) const
49 {
50  std::vector<Real> a;
51  syev("N", eigvals, a);
52 }
53 
54 template <>
55 void
57  RankTwoTensor & eigvecs) const
58 {
59  std::vector<Real> a;
60  syev("V", eigvals, a);
61 
62  for (auto i : make_range(Ndim))
63  for (auto j : make_range(Ndim))
64  eigvecs(j, i) = a[i * Ndim + j];
65 }
RankTwoTensorTempl< Real > RankTwoTensor
MPI_Info info
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
void symmetricEigenvaluesEigenvectors(std::vector< T > &eigvals, RankTwoTensorTempl< T > &eigvecs) const
computes eigenvalues and eigenvectors, assuming tens is symmetric, and places them in ascending order...
static constexpr unsigned int Ndim
tensor dimension and Mandel vector length
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
void symmetricEigenvalues(std::vector< T > &eigvals) const
computes eigenvalues, assuming tens is symmetric, and places them in ascending order in eigvals ...
RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
Definition: RankTwoTensor.h:87
IntRange< T > make_range(T beg, T end)
void syev(const char *calculation_type, std::vector< T > &eigvals, std::vector< T > &a) const
Uses the petscblaslapack.h LAPACKsyev_ routine to find, for symmetric _vals: (1) the eigenvalues (if ...