optimad / bitpit

Open source library for scientific HPC
http://optimad.github.io/bitpit/
GNU Lesser General Public License v3.0
114 stars 34 forks source link

Levelset values on vertices of volOctree #467

Open gitg0n opened 1 month ago

gitg0n commented 1 month ago

Good evening

Is it somehow possible to calculate accurate levelset values on the vertices of a volOctree instead of the cell centers?

I'm currently calculating cell values for the levelset (based on a STL geometry) and then interpolating the cell values onto the vertices by hand. However, this can lead to strange results on vertices close to sharp corners of the source geometry.

Cheers

andrea-iob commented 1 month ago

It is possible to evaluate the levelset both on cell centroids and on arbitrary points.

The functions that allows to evaluate information on cell centroids have "Cell" in their name and take in input the id of the cell:

    double                              evalCellValue(long id, bool signedLevelSet) const;
    std::array<double,3>                evalCellGradient(long id, bool signedLevelSet) const;
    std::array<double,3>                evalCellProjectionPoint(long id) const;

The functions that allows to evaluate information on arbitrary points desn't have any prefix and take in input the coordinates of the point:

    short                               evalSign(const std::array<double,3> &point) const;
    double                              evalValue(const std::array<double,3> &point, bool signedLevelSet) const;
    std::array<double,3>                evalGradient(const std::array<double,3> &point, bool signedLevelSet) const;
    std::array<double,3>                evalProjectionPoint(const std::array<double,3> &point) const;

Therefore you can loop the vertices of the mesh, and evaluate the levelset directly on the vertices.

Note that, when evaluating the levelset on arbitrary points, no caching will be performed. The functions setCellBulkEvaluationMode/enableFieldCellCache only affects how levelset is evaluated on cell centroids.

gitg0n commented 3 weeks ago

Ah I see. I think I missed the levelset rework entirely, I still had an old version where these functions didn't exist ... I'll have to do some reworking. Thanks for the info!