 MFEM  v4.3.0 Finite element discretization library
symmat.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2021, Lawrence Livermore National Security, LLC. Produced
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 {
22  data.Reset();
23 }
24
26 {
27  MFEM_ASSERT(s >= 0, "invalid DenseSymmetricMatrix size: " << s);
28  if (s > 0)
29  {
30  data.New((s*(s+1))/2);
31  *this = 0.0; // init with zeroes
32  }
33  else
34  {
35  data.Reset();
36  }
37 }
38
40 {
41  MFEM_ASSERT(s >= 0,
42  "invalid DenseSymmetricMatrix size: " << s);
43  if (Height() == s)
44  {
45  return;
46  }
47  height = s;
48  width = s;
49  const int s2 = (s*(s+1))/2;
50  if (s2 > data.Capacity())
51  {
52  data.Delete();
53  data.New(s2);
54  *this = 0.0; // init with zeroes
55  }
56 }
57
59 {
60  const int s = (Height()*(Height()+1))/2;
61  for (int i = 0; i < s; i++)
62  {
63  data[i] = c;
64  }
65  return *this;
66 }
67
68 double &DenseSymmetricMatrix::Elem(int i, int j)
69 {
70  return (*this)(i,j);
71 }
72
73 const double &DenseSymmetricMatrix::Elem(int i, int j) const
74 {
75  return (*this)(i,j);
76 }
77
79 {
80  int s = Height()*(Height()+1)/2;
81  for (int i = 0; i < s; i++)
82  {
83  data[i] *= c;
84  }
85  return *this;
86 }
87
88 void DenseSymmetricMatrix::Mult(const Vector &x, Vector &y) const
89 {
90  mfem_error("DenseSymmetricMatrix::Mult() not implemented!");
91 }
92
94 {
95  mfem_error("DenseSymmetricMatrix::Inverse() not implemented!");
96  return nullptr;
97 }
98
99 void DenseSymmetricMatrix::Print (std::ostream & out, int width_) const
100 {
101  mfem_error("DenseSymmetricMatrix::Print() not implemented!");
102 }
103
105 {
106  data.Delete();
107 }
108
109 }
void SetSize(int s)
Change the size of the DenseSymmetricMatrix to s x s.
Definition: symmat.cpp:39
void Delete()
Delete the owned pointers. The Memory is not reset by this method, i.e. it will, generally, not be Empty() after this call.
DenseSymmetricMatrix & operator*=(double c)
Definition: symmat.cpp:78
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:99
virtual double & Elem(int i, int j)
Returns reference to a_{ij}.
Definition: symmat.cpp:68
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:88
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
Definition: operator.hpp:66
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:153
Abstract data type matrix.
Definition: matrix.hpp:27
void Reset()
Reset the memory to be empty, ensuring that Delete() will be a no-op.
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:93
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:104
Vector data type.
Definition: vector.hpp:60
RefCoord s
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition: globals.hpp:66
DenseSymmetricMatrix & operator=(double c)
Sets the matrix elements equal to constant c.
Definition: symmat.cpp:58
int width
Dimension of the input / number of columns in the matrix.
Definition: operator.hpp:28