-
Notifications
You must be signed in to change notification settings - Fork 708
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
Add tolerance to box in compute_point_locations_try_all #15102
Merged
peterrum
merged 3 commits into
dealii:master
from
kronbichler:add_tolerance_compute_point_locations
Apr 17, 2023
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// --------------------------------------------------------------------- | ||
// | ||
// Copyright (C) 2019 - 2020 by the deal.II authors | ||
// | ||
// This file is part of the deal.II library. | ||
// | ||
// The deal.II library is free software; you can use it, redistribute | ||
// it, and/or modify it under the terms of the GNU Lesser General | ||
// Public License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// The full text of the license can be found in the file LICENSE.md at | ||
// the top level directory of deal.II. | ||
// | ||
// --------------------------------------------------------------------- | ||
|
||
// Test GridTools::compute_point_locations_try_all for the case where | ||
// some points only lie outside a cell by some roundoff, and another case | ||
// where they are farther away | ||
|
||
#include <deal.II/fe/mapping_q.h> | ||
|
||
#include <deal.II/grid/grid_generator.h> | ||
#include <deal.II/grid/grid_tools.h> | ||
#include <deal.II/grid/grid_tools_cache.h> | ||
#include <deal.II/grid/tria.h> | ||
|
||
#include "../tests.h" | ||
|
||
template <int dim> | ||
void | ||
check_found(const Triangulation<dim> & tria, | ||
const GridTools::Cache<dim> & cache, | ||
const std::vector<Point<dim>> &points) | ||
{ | ||
auto cell_qpoint_map = | ||
GridTools::compute_point_locations_try_all(cache, points); | ||
const auto &cells = std::get<0>(cell_qpoint_map); | ||
const auto &qpoints = std::get<1>(cell_qpoint_map); | ||
const auto &indices = std::get<2>(cell_qpoint_map); | ||
const auto &other_p = std::get<3>(cell_qpoint_map); | ||
size_t n_cells = cells.size(); | ||
|
||
deallog << "Points found in " << n_cells << " cells" << std::endl; | ||
|
||
for (unsigned int i = 0; i < n_cells; ++i) | ||
{ | ||
deallog << "On cell " << cells[i]->id() << " found:" << std::endl; | ||
unsigned int j = 0; | ||
for (const Point<dim> &p : qpoints[i]) | ||
deallog << "real " << points[indices[i][j++]] << " unit " << p | ||
<< std::endl; | ||
} | ||
deallog << "Points not found: "; | ||
for (const auto i : other_p) | ||
deallog << points[i] << " "; | ||
deallog << std::endl << std::endl; | ||
} | ||
|
||
|
||
int | ||
main() | ||
{ | ||
initlog(); | ||
|
||
deallog << std::setprecision(18); | ||
|
||
const int dim = 2; | ||
Triangulation<dim> triangulation; | ||
GridGenerator::hyper_cube(triangulation, -0.3, 0.7); | ||
triangulation.refine_global(2); | ||
|
||
MappingQ<dim> mapping(1); | ||
GridTools::Cache<dim> cache(triangulation, mapping); | ||
|
||
// Point is outside by 1e-16 | ||
Point<dim> p0(-0.299999999999999989, -0.247168783648703205), | ||
p1(-0.300000000000000044, -0.102831216351296786); | ||
|
||
check_found(triangulation, cache, {{p0, p1}}); | ||
|
||
// Shift point by 1e-8 | ||
p0[0] -= 1e-8; | ||
|
||
check_found(triangulation, cache, {{p0, p1}}); | ||
|
||
// Shift point by more | ||
p0[0] += 0.5; | ||
p1[0] += 1e-15; | ||
|
||
check_found(triangulation, cache, {{p0, p1}}); | ||
|
||
// Shift outside | ||
p0[0] += 1.; | ||
|
||
check_found(triangulation, cache, {{p0, p1}}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
DEAL::Points found in 1 cells | ||
DEAL::On cell 0_2:00 found: | ||
DEAL::real -0.299999999999999989 -0.247168783648703205 unit 0.00000000000000000 0.211324865405187134 | ||
DEAL::real -0.300000000000000044 -0.102831216351296786 unit -2.22044604925031308e-16 0.788675134594812866 | ||
DEAL::Points not found: | ||
DEAL:: | ||
DEAL::Points found in 1 cells | ||
DEAL::On cell 0_2:00 found: | ||
DEAL::real -0.300000000000000044 -0.102831216351296786 unit -2.22044604925031308e-16 0.788675134594812866 | ||
DEAL::Points not found: -0.300000009999999984 -0.247168783648703205 | ||
DEAL:: | ||
DEAL::Points found in 2 cells | ||
DEAL::On cell 0_2:01 found: | ||
DEAL::real 0.199999990000000016 -0.247168783648703205 unit 0.999999960000000132 0.211324865405187134 | ||
DEAL::On cell 0_2:00 found: | ||
DEAL::real -0.299999999999999045 -0.102831216351296786 unit 3.77475828372553224e-15 0.788675134594812866 | ||
DEAL::Points not found: | ||
DEAL:: | ||
DEAL::Points found in 1 cells | ||
DEAL::On cell 0_2:00 found: | ||
DEAL::real -0.299999999999999045 -0.102831216351296786 unit 3.77475828372553224e-15 0.788675134594812866 | ||
DEAL::Points not found: 1.19999999000000002 -0.247168783648703205 | ||
DEAL:: |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better if we scale each side length with a relative tolerance. Thanks for tackling this! @kronbichler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about creating
BB::create_extended_relative()
? @bergbauer could write this ;)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added @bergbauer's suggestion (via his own commit) to this PR.