This example shows how to initialize a DataMatrix object, store it to a file and then to restore it back.
Configuring the Grid
Start with defining the dimensionality of the grid. This is done by modifying the configuration file located at:
"library/source/abbrevi.h"
Example definition:
#define DimensionSparseGrid 2
Regular sparse grid
This example initializes a regular sparse grid, using the class AdaptiveSparseGrid, refines it recursively around a center point, and outputs its structure in both textual and GNU plotting formats. It illustrates how to:
- Define the refinement level of the grid.
- Add recursive sons (children) of a given point.
- Print grid points at specified levels.
- Export the grid structure for visualization.
#include "source/sparseEXPDE.h"
int main(int argc, char **argv) {
int level=3;
IndexDimension centerPoint;
regular_grid.AddRecursiveSonsOfPoint(centerPoint,level);
return 0;
}
void Print_gnu(string name)
Prints coordinates of adaptive sparse grid in gnu-file.
Definition sparseGrid.cc:258
void PrintActiveHanging(int level)
prints active nodes (o) and hanging nodes (x)
Definition sparseGrid.cc:139
Definition sparseGrid.h:277
Adaptive Sparse Grid
Next, we want to generate an adaptive sparse grid. Let us do this in more detail. We start by initializing an adaptive sparse grid, defining grid points (IndexDimension) and adding them to our grid.
#include "source/sparseEXPDE.h"
int main(int argc, char **argv) {
int level = 3;
IndexDimension centerPoint;
IndexDimension bottomLeft = centerPoint.leftSon(0).leftSon(1).leftSon(0).leftSon(1);
IndexDimension topRight = centerPoint.rightSon(0).rightSon(1).rightSon(0).rightSon(1);
adaptiveSparseGrid.
AddPoint(bottomLeft);
bool AddPoint(const IndexDimension I)
Definition sparseGrid.cc:482
In order to perform a Matrix-Vector-Multiplication on such a grid, we need to add grid points.
This is done as follows:
adaptiveSparseGrid.completeDirichletGrid();
Finally we can export the grid structure.
adaptiveSparseGrid.Print_vtk("grid.vtk");
cout << adaptiveSparseGrid.getDOFS() << " " << adaptiveSparseGrid.getHangingNodes() << endl;
return 0;
}