gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
linearSystemFull.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef LINEAR_SYSTEM_FULL_H
7 #define LINEAR_SYSTEM_FULL_H
8 
9 // Interface to a linear system with a FULL matrix
10 
11 #include "GmshMessage.h"
12 #include "linearSystem.h"
13 #include "fullMatrix.h"
14 #include <stdlib.h>
15 #include <set>
16 
17 template <class scalar> class linearSystemFull : public linearSystem<scalar> {
18 private:
21 
22 public:
23  linearSystemFull() : _a(0), _b(0), _x(0) {}
24  virtual bool isAllocated() const { return _a != 0; }
25  virtual void allocate(int nbRows)
26  {
27  clear();
28  _a = new fullMatrix<scalar>(nbRows, nbRows);
29  _b = new fullVector<scalar>(nbRows);
30  _x = new fullVector<scalar>(nbRows);
31  }
32  virtual ~linearSystemFull() { clear(); }
33  virtual void clear()
34  {
35  if(_a) {
36  delete _a;
37  delete _b;
38  delete _x;
39  }
40  _a = 0;
41  }
42  virtual void addToMatrix(int row, int col, const scalar &val)
43  {
44  if(val != 0.0) (*_a)(row, col) += val;
45  }
46  virtual void getFromMatrix(int row, int col, scalar &val) const
47  {
48  val = (*_a)(row, col);
49  }
50  virtual void addToRightHandSide(int row, const scalar &val, int ith = 0)
51  {
52  if(val != 0.0) (*_b)(row) += val;
53  }
54  virtual void addToSolution(int row, const scalar &val)
55  {
56  if(val != 0.0) (*_x)(row) += val;
57  }
58  virtual void getFromRightHandSide(int row, scalar &val) const
59  {
60  val = (*_b)(row);
61  }
62  virtual void getFromSolution(int row, scalar &val) const { val = (*_x)(row); }
63  virtual void zeroMatrix() { _a->setAll(0.); }
64  virtual void zeroRightHandSide() { _b->setAll(0.); }
65  virtual void zeroSolution() { _x->setAll(0.); }
66  virtual double normInfRightHandSide() const
67  {
68  double nor = 0.;
69  double temp;
70  for(int i = 0; i < _b->size(); i++) {
71  temp = (*_b)(i);
72  if(temp < 0) temp = -temp;
73  if(nor < temp) nor = temp;
74  }
75  return nor;
76  }
77  virtual int systemSolve()
78  {
79  if(_b->size()) _a->luSolve(*_b, *_x);
80  // _x->print("X in solve");
81  return 1;
82  }
83 };
84 
85 #endif
linearSystemFull::zeroRightHandSide
virtual void zeroRightHandSide()
Definition: linearSystemFull.h:64
linearSystemFull
Definition: linearSystemFull.h:17
fullVector
Definition: MElement.h:26
linearSystemFull::zeroSolution
virtual void zeroSolution()
Definition: linearSystemFull.h:65
linearSystemFull::zeroMatrix
virtual void zeroMatrix()
Definition: linearSystemFull.h:63
GmshMessage.h
linearSystemFull::_a
fullMatrix< scalar > * _a
Definition: linearSystemFull.h:19
linearSystemFull::getFromMatrix
virtual void getFromMatrix(int row, int col, scalar &val) const
Definition: linearSystemFull.h:46
linearSystemFull::addToRightHandSide
virtual void addToRightHandSide(int row, const scalar &val, int ith=0)
Definition: linearSystemFull.h:50
fullMatrix
Definition: MElement.h:27
linearSystemFull::allocate
virtual void allocate(int nbRows)
Definition: linearSystemFull.h:25
linearSystemFull::isAllocated
virtual bool isAllocated() const
Definition: linearSystemFull.h:24
linearSystemFull::addToSolution
virtual void addToSolution(int row, const scalar &val)
Definition: linearSystemFull.h:54
linearSystemFull::linearSystemFull
linearSystemFull()
Definition: linearSystemFull.h:23
linearSystemFull::systemSolve
virtual int systemSolve()
Definition: linearSystemFull.h:77
linearSystemFull::addToMatrix
virtual void addToMatrix(int row, int col, const scalar &val)
Definition: linearSystemFull.h:42
linearSystemFull::~linearSystemFull
virtual ~linearSystemFull()
Definition: linearSystemFull.h:32
linearSystemFull::normInfRightHandSide
virtual double normInfRightHandSide() const
Definition: linearSystemFull.h:66
linearSystemFull::_x
fullVector< scalar > * _x
Definition: linearSystemFull.h:20
linearSystemFull::getFromSolution
virtual void getFromSolution(int row, scalar &val) const
Definition: linearSystemFull.h:62
linearSystemFull::_b
fullVector< scalar > * _b
Definition: linearSystemFull.h:20
linearSystemFull::getFromRightHandSide
virtual void getFromRightHandSide(int row, scalar &val) const
Definition: linearSystemFull.h:58
linearSystemFull::clear
virtual void clear()
Definition: linearSystemFull.h:33
fullMatrix.h
linearSystem
Definition: linearSystem.h:38
linearSystem.h