13 template<
class N,
class DF,
int dimension>
27 enum { dim = dimension };
31 static const int negative = -1;
38 const DomainFunction & df;
41 std::vector<size_type> node_map;
42 std::vector<size_type> grid_map;
43 std::vector<bool> inside_map;
44 std::vector<bool> boundary_map;
51 for(
int d=dim-1; d>=0; --d){
52 c[d] = index / offsets[d];
53 index -= c[d] * offsets[d];
61 for(
int d=dim-1; d>=0; --d)
95 const DomainFunction & df_)
96 : extent(extent_), size(size_), df(df_),
98 invalid_node(std::numeric_limits<size_type>::max())
105 for(
int d=0; d<dim; ++d){
107 offsets[d] = d==0 ? 1 : size[d-1] * offsets[d-1];
113 inside_map.resize(n_nodes);
114 grid_map.resize(n_nodes);
115 boundary_map.resize(0);
116 boundary_map.resize(n_nodes,
false);
118 for(size_type n=0; n<n_nodes; ++n){
122 inside_map[n] = df.evaluate(x);
124 node_map.push_back(n);
125 grid_map[n] = node_map.size()-1;
132 for(size_type n=0; n<node_map.size(); ++n){
133 for(
int d=0; d<dim; ++d){
134 for(
int s=0; s<2; ++s){
135 const int side = s*2-1;
137 if(neighbor == invalid_node)
138 boundary_map[node_map[n]] =
true;
164 size_type
getNeighborIndex(
const size_type ln,
const size_type n_dim,
const int n_side,
const int k = 1)
const 166 const size_type n = node_map[ln];
168 size_type neighbors[2];
169 neighbors[0] = c[n_dim];
170 neighbors[1] = size[n_dim]-c[n_dim]-1;
172 assert(n_side == 1 || n_side == -1);
173 if(
size_type(k) > neighbors[(n_side+1)/2])
176 const size_type neighbor = n + offsets[n_dim] * n_side * k;
178 if(!inside_map[neighbor])
181 return grid_map[neighbor];
189 return boundary_map[node_map[ln]];
197 return node_map.size();
217 return index2world(node_map[ln]);
220 std::vector<Vector<number_type> > getNodeCoordinates()
const 222 std::vector<Vector<number_type> > coords;
223 for(size_type n=0; n<node_map.size(); ++n){
225 coords.back() = index2world(node_map[n]);
234 #endif // HDNUM_SGRID_HH
size_type getNeighborIndex(const size_type ln, const size_type n_dim, const int n_side, const int k=1) const
Provides the index of the k-th neighbor of the node with index ln.
Definition: sgrid.hh:164
Structured Grid for Finite Differences.
Definition: sgrid.hh:14
Vector< number_type > getCoordinates(const size_type ln) const
Returns the world coordinates of the node with the given node index.
Definition: sgrid.hh:215
Vector< number_type > getCellWidth() const
Returns the cell width h of the structured grid.
Definition: sgrid.hh:207
bool isBoundaryNode(const size_type ln) const
Returns true if the node is on the boundary of the discrete compuational domain.
Definition: sgrid.hh:187
static const int positive
Side definitions for usage in getNeighborIndex(..)
Definition: sgrid.hh:30
size_type getNumberOfNodes() const
Returns the number of nodes which are in the compuational domain.
Definition: sgrid.hh:195
DF DomainFunction
Type of the function defining the domain.
Definition: sgrid.hh:25
SGrid(const Vector< number_type > extent_, const Vector< size_type > size_, const DomainFunction &df_)
Constructor.
Definition: sgrid.hh:93
std::size_t size_type
Export size type.
Definition: sgrid.hh:19
Definition: densematrix.hh:21
const size_type invalid_node
The value which is returned to indicate an invalid node.
Definition: sgrid.hh:77
N number_type
Export number type.
Definition: sgrid.hh:22