Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init_ghosted gives rounding errors on domain boundary #543

Closed
EmilyBourne opened this issue Jul 15, 2024 · 2 comments · Fixed by #556
Closed

init_ghosted gives rounding errors on domain boundary #543

EmilyBourne opened this issue Jul 15, 2024 · 2 comments · Fixed by #556
Assignees

Comments

@EmilyBourne
Copy link
Collaborator

When using init_ghosted on a uniform point sampling the addition of the ghosts leads to rounding errors on the domain boundary. This issue can be avoided using tolerances as was done in #519 so it may not be serious, but it should at least be documented so users are aware of this potential pitfall.

Minimum reprocible example

#include <iostream>

#include <ddc/ddc.hpp>

struct Vx {
    static bool constexpr PERIODIC = false;
};

struct DDimVx : ddc::UniformPointSampling<Vx> {
};

int main(int argc, char** argv) {
    ddc::ScopeGuard ddc_scope(argc, argv);

    ddc::Coordinate<Vx> vx_min(-8);
    ddc::Coordinate<Vx> vx_max(8);
    ddc::DiscreteVector<DDimVx> npoints(128);
    ddc::DiscreteVector<DDimVx> nghosts(3);

    ddc::DiscreteDomain<DDimVx> pre_ghost;
    ddc::DiscreteDomain<DDimVx> post_ghost;
    ddc::DiscreteDomain<DDimVx> main_domain;
    ddc::DiscreteDomain<DDimVx> full_domain;
    std::tie(main_domain, full_domain, pre_ghost, post_ghost) =
        ddc::init_discrete_space<DDimVx>(DDimVx::template init_ghosted<DDimVx>(
            vx_min, vx_max, npoints, nghosts, nghosts));

    std::cout << (vx_min - ddc::coordinate(main_domain.front())) << std::endl;

    return 0;
}

Output is:

(-8.88178e-16)
@tpadioleau
Copy link
Member

It is true that you cannot expect exact equality between vx_min and ddc::coordinate(main_domain.front())/vx_xmax and ddc::coordinate(main_domain.back()). I don't think it is related to init_ghosted though, I guess init also has the same behavior. Are you relying on it in Gysela ?

@EmilyBourne
Copy link
Collaborator Author

I guess init also has the same behavior

I think for init you cannot expect exact equality between vx_xmax and ddc::coordinate(main_domain.back()) but you can expect exact equality between vx_xmin and ddc::coordinate(main_domain.front())

We are not relying on this for Gysela, but in DDC you were relying on it here:

assert(x - rmin() >= -length() * 1e-14);
assert(rmax() - x >= -length() * 1e-14);

if the extrapolation condition for a spline evaluator evaluates the value at the boundary.

As I say in the issue

it may not be serious, but it should at least be documented so users are aware of this potential pitfall.

@tpadioleau tpadioleau linked a pull request Jul 19, 2024 that will close this issue
@tpadioleau tpadioleau self-assigned this Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants