Tatooine
|
This creates a 2-dimensional uniform rectilinear grid with resultion 32x64. It is in the domain [0,0]x[1,1];
tatooine::rectilinear_grid is a templated class and for each dimension holds a container of coordinates. When giving the constructor integral types (that must be > 0) a deduction guide will be used to create an object of type tatooine::rectilinear_grid<tatooine::linspace<double>, tatooine::linspace<double>>. So in the example above uniform_rectilinear_grid_2d holds two instances of tatooine::linspace<double>. The code above creates the following as here:
Candidates for other containers describing dimensions are std::vector and std::array . These types can also be mixed.
This code creates a three-dimensional rectilinear_grid that is described by three dimensions of mixed types. If possible tatooine::linspace should be taken because here the factors for differentiating do not have to be calculated.
A tatooine::rectilinear_grid can be indexed with the parantheses-operator or the at method:
These methods return a tatooine::vec that represents the position of the rectilinear_grid index.
One can iterate in two ways over the vertices of a tatooine::rectilinear_grid:
For storing properties of arbitrary types type erasure is used.
Instances of tatooine::rectilinear_grid can be equipped with vertex properties that can hold any data type. Vertex properties can be created as in the following example:
prop
has to be a reference! Otherwise you are working on a copy of the property.uniform_rectilinear_grid_2d now holds a vertex property called "property_name". Internally the method vertex_property
creates an object whose type inherits tatooine::dynamic_multidim_array.
If vertex_prop
is called again with the same name and the same type you will get a reference to same property.
If vertex_prop
is called again with the same name and the another type an exception is thrown.
When calling vertex_prop
with a name that has not been used before tatooine::rectilinear_grid::insert_vertex_property is called which then calls tatooine::rectilinear_grid::insert_contiguous_vertex_property. Hence the following code produces the same when "property_name" has not been used before as an argument on that grid:
So these functions create containers that keep their memory in linear memory. There is also a function that creates memory that is chunked:
With this the data of prop
is stored in 2x2 blocks in memory to ensure a spatial memory coherence.
If the property already exists and another container type is queried to use an exception will be thrown. Example:
Because the internal type is hidden by "type erasure" one has to specify the type again as template parameter when querying a property.
The function above receives a rectilinear_grid with an arbitrary number of dimensions with arbitrary types.
An exception will be thrown if no property with name "property_name" can be found or if a property can be found but the specified and the stored types do not match.
There are some helper methods to make the code more readable or at least to hide templates:
A property can be sampled like that:
The returned object is derived by tatooine::field so every available algorithm can be applied the the sampler.
The tatooine::rectilinear_grid::sampler method is a template function that can get interpolation kernels as template parameters. By default cubic interpolation kernels are used for every dimension. So the following code produces the same results as the code above.
One can also mix interpolation kernels:
Here the sampler interpolates linearly in the first dimension and cubicly in the second dimension.