CS 294-73 Software Engineering For Scientific Computing Lecture 8: Unstructured Grids and Sparse Matrices
CS 294-73 Software Engineering For Scientific Computing Lecture 8: Unstructured Grids and Sparse Matrices
Step 2: We replace by ,a
finite-dimensional space of test
functions. For this exercise, we will
Interior Nodes = NI
use linear combinations of
continuous, piecewise linear Elements e = 0, . . . E 1
functions, indexed by interior
nodes nodes, linear on each
triangle containing the node. A
basis for this space is given
by { hn (x) : n .2 NI }.
Step 3: We also approximate the
solution as a linear combination of
the the elements in .
h
n (xn0 ) = nn0 , n0 2 N
09/19/2017 CS294-73 Lecture 8 5
Weak form -> matrix equation.
Two issues:
• Computing L.
• Quadrature for computing b.
Typical non-zero
entries in A matrix
from a finite element
problem
⎛1.5 0 0 0 0 0 0 0 ⎞
⎜ ⎟
⎜ 0 2.3 0 1.4 0 0 0 0 ⎟
⎜ 0 0 3.7 0 0 0 0 0 ⎟
⎜ ⎟
⎜ 0 − 1.6 0 2.3 9.9 0 0 0 ⎟
A=⎜
⎜ 0 0 0 0 5.8 0 0 0 ⎟⎟
⎜ 0 0 0 0 0 7.4 0 0 ⎟
⎜ ⎟
⎜ 0 0 1.9 0 0 0 4.9 0 ⎟
⎜ 0 0 0 0 0 0 0 3.6 ⎟⎠
⎝
Part of your homework 2 will be to implement this class, with a few more functions
#define VERTICES 3
class Element
{
0
public:
Element();
/// Constructor. iElt
Element(array<int,VERTICES>& a_tr); 2
/// Destructor.
1
~Element(); Local node numbers
/// local indexing to get nodeNumber. for element iElt.
const int& operator[](const int& a_localNodeNumber) const;
private:
array<int,VERTICES> m_vertices;
};
class FEGrid We’re implementing this one (along with Node and Element)for
{ you – you just have to use them correctly.
public:
FEGrid();
/// Constructor by reading from file.
FEGrid(char* a_nodeFileName,char* a_elementFileName);
///Destructor.
~FEGrid(); Read in the file names from argv.
/// Get number of elements, nodes, interior nodes.
int getNumElts() const;
int getNumNodes() const;
int getNumInteriorNodes() const;
...
/// get reference to node on an element.
const Node& getNode(const int& a_eltNumber,
const int& a_localNodeNumber) const;
private:
vector<Node > m_nodes;
vector<Element > m_elements;
int m_numInteriorNodes;
Notice what we don’t have: neither an
};
explicit mapping that gives all of the
elements touching a given node, nor
one that maps interiorNodes into
nodes. The first one we don’t need,
and the second is encoded implicitly in
Node.
class FEPoissonOperator
{
public:
FEPoissonOperator();
FEPoissonOperator(const FEGrid& a_grid);
void applyOperator(vector<float> & a_LOfPhi, const
vector<double> & a_phi) const;
void makeRHS(vector<double> & a_rhsAtNodes, const
vector<float> & a_rhsAtCentroids) const;
const FEGrid& getFEGrid() const;
const SparseMatrix& getSparseMatrix() const;
~FEPoissonOperator();
private:
SparseMatrix m_matrix; Note that a_phi is defined
only on the interior nodes, as is
FEGrid m_grid;
a_LOfPhi, a_rhsAtNodes .
};