PLaSK library
Loading...
Searching...
No Matches
Meshes

About meshes

The mesh represents (ordered) set of points in 2D or 3D space. All meshes in PLaSK implements (inherits from) instantiation of plask::Mesh template interface.

Typically, there is some data associated with points in mesh. In PLaSK, all this data is not stored in the mesh class, hence they must be stored separately. As the points in the mesh are ordered and each one have unique index in a range from 0 to plask::Mesh::size()-1, you can store data in any indexed structure, like an array (1D) or std::vector (which is recommended), storing the data value for the i-th point in the mesh under the i-th index.

See also
Interpolation Boundaries

How to implement a new mesh?

Typical approaches to implementing new types of meshes:

See also
How to write a new interpolation algorithm? Boundaries implementations.

Direct implementation of plask::MeshD<DIM>

To implement a new mesh directly you have to write class inherited from the plask::MeshD<DIM>, where DIM (is equal 2 or 3) is a number of dimension of space your mesh is defined over.

You are required to:

Example implementation of singleton mesh (mesh which represent set with only one point in 3D space):

struct OnePoint3DMesh: public plask::MeshD<3> {
// Held point:
: point(point) {}
// plask::MeshD<3> methods implementation:
std::size_t size() const override {
return 1;
}
plask::Vec<3, double> at(std::size_t index) const override {
return point;
}
void writeXML(XMLElement& object) const override {
object.attr("type", "point3d"); // this is required attribute for the provided object
object.addTag("point")
.attr("c0", point.c0)
.attr("c1", point.c1)
.attr("c2", point.c2); // store this point coordinates in attributes of the tag <point>
}
};
// Now write reading function (when it is called, the current tag is the <mesh> tag):
static shared_ptr<Mesh> readOnePoint3DMesh(plask::XMLReader& reader) {
reader.requireTag("point");
double c0 = reader.requireAttribute<double>("c0");
double c1 = reader.requireAttribute<double>("c1");
double c2 = reader.requireAttribute<double>("c2");
reader.requireTagEnd(); // this is necessary to make sure the tag <point> is closed
// Now create the mesh into a shared pointer and return it:
}
// Declare global variable of type RegisterMeshReader in order to register the reader:
// the first argument must be the same string which has been written into 'type' attribute in OnePoint3DMesh::writeXML() method,
// the second one is the address of your reading function,
// variable name does not matter.
static RegisterMeshReader onepoint3dmesh_reader("point3d", &readOnePoint3DMesh);

You should also implement interpolation algorithms for your mesh, see How to write a new interpolation algorithm? for more details.