MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
symmat.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 
13 // Implementation of data type DenseSymmetricMatrix
14 
15 #include "symmat.hpp"
16 
17 namespace mfem
18 {
19 
21 
23 {
24  MFEM_ASSERT(s >= 0, "invalid DenseSymmetricMatrix size: " << s);
25  if (s > 0)
26  {
27  data.New((s*(s+1))/2);
28  *this = 0.0; // init with zeroes
29  }
30 }
31 
33 {
34  MFEM_ASSERT(s >= 0,
35  "invalid DenseSymmetricMatrix size: " << s);
36  if (Height() == s)
37  {
38  return;
39  }
40  height = s;
41  width = s;
42  const int s2 = (s*(s+1))/2;
43  if (s2 > data.Capacity())
44  {
45  data.Delete();
46  data.New(s2);
47  *this = 0.0; // init with zeroes
48  }
49 }
50 
52 {
53  const int s = (Height()*(Height()+1))/2;
54  for (int i = 0; i < s; i++)
55  {
56  data[i] = c;
57  }
58  return *this;
59 }
60 
61 double &DenseSymmetricMatrix::Elem(int i, int j)
62 {
63  return (*this)(i,j);
64 }
65 
66 const double &DenseSymmetricMatrix::Elem(int i, int j) const
67 {
68  return (*this)(i,j);
69 }
70 
72 {
73  int s = GetStoredSize();
74  for (int i = 0; i < s; i++)
75  {
76  data[i] *= c;
77  }
78  return *this;
79 }
80 
81 void DenseSymmetricMatrix::Mult(const Vector &x, Vector &y) const
82 {
83  mfem_error("DenseSymmetricMatrix::Mult() not implemented!");
84 }
85 
87 {
88  mfem_error("DenseSymmetricMatrix::Inverse() not implemented!");
89  return nullptr;
90 }
91 
92 void DenseSymmetricMatrix::Print (std::ostream & os, int width_) const
93 {
94  mfem_error("DenseSymmetricMatrix::Print() not implemented!");
95 }
96 
98 {
99  data.Delete();
100 }
101 
102 }
void SetSize(int s)
Change the size of the DenseSymmetricMatrix to s x s.
Definition: symmat.cpp:32
void Delete()
Delete the owned pointers and reset the Memory object.
DenseSymmetricMatrix & operator*=(double c)
Definition: symmat.cpp:71
Abstract data type for matrix inverse.
Definition: matrix.hpp:62
virtual void Print(std::ostream &out=mfem::out, int width_=4) const
Prints matrix to stream out.
Definition: symmat.cpp:92
virtual double & Elem(int i, int j)
Returns reference to a_{ij}.
Definition: symmat.cpp:61
int Capacity() const
Return the size of the allocated memory.
virtual void Mult(const Vector &x, Vector &y) const
Matrix vector multiplication.
Definition: symmat.cpp:81
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
Definition: operator.hpp:67
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
Definition: error.cpp:154
Abstract data type matrix.
Definition: matrix.hpp:27
int height
Dimension of the output / number of rows in the matrix.
Definition: operator.hpp:27
virtual MatrixInverse * Inverse() const
Returns a pointer to (an approximation) of the matrix inverse.
Definition: symmat.cpp:86
void New(int size)
Allocate host memory for size entries with the current host memory type returned by MemoryManager::Ge...
virtual ~DenseSymmetricMatrix()
Destroys the symmetric matrix.
Definition: symmat.cpp:97
Vector data type.
Definition: vector.hpp:60
RefCoord s[3]
int GetStoredSize() const
Return the number of stored nonzeros in the matrix.
Definition: symmat.hpp:73
DenseSymmetricMatrix & operator=(double c)
Sets the matrix elements equal to constant c.
Definition: symmat.cpp:51
int width
Dimension of the input / number of columns in the matrix.
Definition: operator.hpp:28