#include <uggridfactory.hh>
If you want to write a routine that reads a grid from some file into a Dune UGGrid object you have to know how to use the UGGrid grid factory. In the following we assume that you have a grid in some file format and an empty UGGrid object, created by one of its constructors. Hence, your file reader method signature may look like this:
UGGrid<3>* readMyFileFormat(const std::string& filename)
Now, in order to create a valid UGGrid object do the following steps:
Get a new GridFactory object by calling
GridFactory<UGGrid<dim> > factory;
Insert the grid vertices by calling
factory.insertVertex(const FieldVector<double,dimworld>& position);
for each vertex. The order of insertion determines the level- and leaf indices of your level 0 vertices.
For each element call
factory.insertElement(Dune::GeometryType type, const std::vector<int>& vertices);
The parameters are
The numbering of the vertices of each element is expected to follow the DUNE conventions. Refer to the page on reference elements for the details.
UGGrid supports parametrized domains. That means that you can provide a smooth description of your grid boundary. The actual grid will always be piecewise linear; however, as you refine, the grid will approach your prescribed boundary. You don't have to do this. If your coarse grid boundary describes your domain well read on at Section 5.
In order to create curved boundary segments, for each segment you have to write a class which implements the correct geometry. These classes are then handed over to the UGGrid object. Boundary segment implementations must be derived from
template <int dimworld> Dune::BoundarySegmentThis is an abstract base class which requires you to overload the method
virtual FieldVector< double, dimworld > operator() (const FieldVector< double, dimworld-1 > &local)
This methods must compute the world coordinates from the local ones on the boundary segment. Give these classes to your grid by calling
grid.insertBoundarySegment(const std::vector<int>& vertices, const BoundarySegment<dimworld> *boundarySegment);
Control over the allocated objects is taken from you, and the grid object will take care of their destruction.
To finish off the construction of the UGGrid object call
UGGrid<dim>* grid = factory.createGrid();
This time it is you who gets full responsibility for the allocated object.
If you're working on a parallel machine, and you want to set up a parallel grid, proceed as described on all processes. This will create the grid on the master process and set up UG correctly on all other process. Call loadBalance()
to actually distribute the grid.
Public Member Functions | |
GridFactory () | |
Default constructor. | |
GridFactory (UGGrid< dimworld > *grid) | |
Constructor for a given grid object. | |
~GridFactory () | |
Destructor. | |
virtual void | insertVertex (const FieldVector< ctype, dimworld > &pos) |
Insert a vertex into the coarse grid. | |
virtual void | insertElement (const GeometryType &type, const std::vector< unsigned int > &vertices) |
Insert an element into the coarse grid. | |
void | insertBoundarySegment (const std::vector< unsigned int > vertices, const BoundarySegment< dimworld > *boundarySegment) |
Method to insert an arbitrarily shaped boundary segment into a coarse grid. | |
virtual UGGrid< dimworld > * | createGrid () |
Finalize grid creation and hand over the grid. | |
virtual void | insertVertex (const FieldVector< ctype, dimworld > &pos)=0 |
Insert a vertex into the coarse grid. |
Dune::GridFactory< UGGrid< dimworld > >::GridFactory | ( | UGGrid< dimworld > * | grid | ) |
Constructor for a given grid object.
If you already have your grid object constructed you can hand it over using this constructor. A reason may be that you need a UGGrid object with a non-default heap size.
If you construct your factory class using this constructor the pointer handed over to you by the method createGrid() is the one you supplied here.
virtual void Dune::GridFactory< UGGrid< dimworld > >::insertElement | ( | const GeometryType & | type, | |
const std::vector< unsigned int > & | vertices | |||
) | [virtual] |
Insert an element into the coarse grid.
type | The GeometryType of the new element | |
vertices | The vertices of the new element, using the DUNE numbering |
Implements Dune::GridFactoryInterface< GridType >.
void Dune::GridFactory< UGGrid< dimworld > >::insertBoundarySegment | ( | const std::vector< unsigned int > | vertices, | |
const BoundarySegment< dimworld > * | boundarySegment | |||
) | [virtual] |
Method to insert an arbitrarily shaped boundary segment into a coarse grid.
vertices | The indices of the vertices of the segment | |
boundarySegment | Class implementing the geometry of the boundary segment. The grid object takes control of this object and deallocates it when destructing itself. |
Reimplemented from Dune::GridFactoryInterface< GridType >.
virtual UGGrid<dimworld>* Dune::GridFactory< UGGrid< dimworld > >::createGrid | ( | ) | [virtual] |
Finalize grid creation and hand over the grid.
The receiver takes responsibility of the memory allocated for the grid
Implements Dune::GridFactoryInterface< GridType >.