Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dumux-repositories
dumux
Commits
93c5b166
Commit
93c5b166
authored
5 years ago
by
Timo Koch
Browse files
Options
Downloads
Patches
Plain Diff
[test][bugfix][vtucompare] Fuzzy sort vertices of grid
parent
7532daf2
No related branches found
No related tags found
1 merge request
!1785
[cakegridmanager] Fix bugs, allow zero well radius
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/testing/fuzzycomparevtu.py
+39
-2
39 additions, 2 deletions
bin/testing/fuzzycomparevtu.py
with
39 additions
and
2 deletions
bin/testing/fuzzycomparevtu.py
+
39
−
2
View file @
93c5b166
...
@@ -18,6 +18,7 @@ from six.moves import zip
...
@@ -18,6 +18,7 @@ from six.moves import zip
import
os
import
os
import
re
import
re
import
glob
import
glob
import
functools
# fuzzy compare VTK tree from VTK strings
# fuzzy compare VTK tree from VTK strings
def
compare_vtk
(
vtk1
,
vtk2
,
absolute
=
1.5e-7
,
relative
=
1e-2
,
zeroValueThreshold
=
{},
verbose
=
True
):
def
compare_vtk
(
vtk1
,
vtk2
,
absolute
=
1.5e-7
,
relative
=
1e-2
,
zeroValueThreshold
=
{},
verbose
=
True
):
...
@@ -75,8 +76,10 @@ def compare_vtk(vtk1, vtk2, absolute=1.5e-7, relative=1e-2, zeroValueThreshold={
...
@@ -75,8 +76,10 @@ def compare_vtk(vtk1, vtk2, absolute=1.5e-7, relative=1e-2, zeroValueThreshold={
# do the fuzzy compare
# do the fuzzy compare
if
is_fuzzy_equal_node
(
sortedroot1
,
sortedroot2
,
absolute
,
relative
,
zeroValueThreshold
,
verbose
,
convertedFromParallelVtu
):
if
is_fuzzy_equal_node
(
sortedroot1
,
sortedroot2
,
absolute
,
relative
,
zeroValueThreshold
,
verbose
,
convertedFromParallelVtu
):
print
(
"
Fuzzy comparison done (equal)
"
)
return
0
return
0
else
:
else
:
print
(
"
Fuzzy comparison done (not equal)
"
)
return
1
return
1
# convert a parallel vtu file into sequential one by glueing the pieces together
# convert a parallel vtu file into sequential one by glueing the pieces together
...
@@ -365,7 +368,7 @@ def sort_vtk(root):
...
@@ -365,7 +368,7 @@ def sort_vtk(root):
# sorts the data by point coordinates so that it is independent of index numbering
# sorts the data by point coordinates so that it is independent of index numbering
def
sort_vtk_by_coordinates
(
root1
,
root2
,
verbose
,
convertedFromParallelVtu
=
False
):
def
sort_vtk_by_coordinates
(
root1
,
root2
,
verbose
,
convertedFromParallelVtu
=
False
):
if
not
is_fuzzy_equal_node
(
root1
.
find
(
"
.//Points/DataArray
"
),
root2
.
find
(
"
.//Points/DataArray
"
),
absolute
=
1e-2
,
relative
=
1.5e-7
,
zeroValueThreshold
=
dict
(),
verbose
=
Tru
e
,
convertedFromParallelVtu
=
False
):
if
not
is_fuzzy_equal_node
(
root1
.
find
(
"
.//Points/DataArray
"
),
root2
.
find
(
"
.//Points/DataArray
"
),
absolute
=
1e-2
,
relative
=
1.5e-7
,
zeroValueThreshold
=
dict
(),
verbose
=
Fals
e
,
convertedFromParallelVtu
=
False
):
if
verbose
:
if
verbose
:
print
(
"
Sorting vtu by coordinates...
"
)
print
(
"
Sorting vtu by coordinates...
"
)
for
root
in
[
root1
,
root2
]:
for
root
in
[
root1
,
root2
]:
...
@@ -431,6 +434,40 @@ def sort_vtk_by_coordinates(root1, root2, verbose, convertedFromParallelVtu=Fals
...
@@ -431,6 +434,40 @@ def sort_vtk_by_coordinates(root1, root2, verbose, convertedFromParallelVtu=Fals
for
vertexIndex
in
cell
:
for
vertexIndex
in
cell
:
largestCellMidPointForVertex
[
vertexIndex
]
=
max
(
largestCellMidPointForVertex
[
vertexIndex
],
midpoint
)
largestCellMidPointForVertex
[
vertexIndex
]
=
max
(
largestCellMidPointForVertex
[
vertexIndex
],
midpoint
)
# floating point comparison operator for scalars
def
float_cmp
(
a
,
b
,
eps
):
if
math
.
fabs
(
a
-
b
)
<
eps
:
return
0
elif
a
>
b
:
return
1
else
:
return
-
1
# floating point comparison operator for vectors
def
floatvec_cmp
(
a
,
b
,
eps
):
for
i
,
j
in
zip
(
a
,
b
):
res
=
float_cmp
(
i
,
j
,
eps
)
if
res
!=
0
:
return
res
return
0
# compute an epsilon and a comparison operator for floating point comparisons
bBoxMax
=
max
(
vertexArray
)
bBoxMin
=
min
(
vertexArray
)
epsilon
=
math
.
sqrt
(
sum
([(
a
-
b
)
**
2
for
a
,
b
in
zip
(
bBoxMax
,
bBoxMin
)]))
*
1e-7
# first compare by coordinates, if the same compare largestCellMidPointForVertex
# TODO: is there a more pythonic way?
def
vertex_cmp
(
a
,
b
):
res
=
floatvec_cmp
(
a
[
1
],
b
[
1
],
epsilon
)
if
res
!=
0
:
return
res
res2
=
floatvec_cmp
(
largestCellMidPointForVertex
[
a
[
0
]],
largestCellMidPointForVertex
[
b
[
0
]],
epsilon
)
if
res2
!=
0
:
return
res2
return
0
# obtain a vertex index map
# obtain a vertex index map
vMap
=
[]
vMap
=
[]
for
idx
,
coords
in
enumerate
(
vertexArray
):
for
idx
,
coords
in
enumerate
(
vertexArray
):
...
@@ -439,7 +476,7 @@ def sort_vtk_by_coordinates(root1, root2, verbose, convertedFromParallelVtu=Fals
...
@@ -439,7 +476,7 @@ def sort_vtk_by_coordinates(root1, root2, verbose, convertedFromParallelVtu=Fals
vertexIndexMap
=
[
0
]
*
len
(
vMap
)
vertexIndexMap
=
[
0
]
*
len
(
vMap
)
vertexIndexMapInverse
=
[
0
]
*
len
(
vMap
)
vertexIndexMapInverse
=
[
0
]
*
len
(
vMap
)
# first sort by coordinates, if the same by largestCellMidPointForVertex
# first sort by coordinates, if the same by largestCellMidPointForVertex
for
idxNew
,
idxOld
in
enumerate
(
sorted
(
vMap
,
key
=
lambda
x
:
(
x
[
1
],
largestCellMidPointForVertex
[
x
[
0
]]
))):
for
idxNew
,
idxOld
in
enumerate
(
sorted
(
vMap
,
key
=
functools
.
cmp_to_key
(
vertex_cmp
))):
vertexIndexMap
[
idxOld
[
0
]]
=
idxNew
vertexIndexMap
[
idxOld
[
0
]]
=
idxNew
vertexIndexMapInverse
[
idxNew
]
=
idxOld
[
0
]
vertexIndexMapInverse
[
idxNew
]
=
idxOld
[
0
]
...
...
This diff is collapsed.
Click to expand it.
Timo Koch
@timok
mentioned in commit
003dd6d5
·
5 years ago
mentioned in commit
003dd6d5
mentioned in commit 003dd6d50fe393265df71b7d3a5787955e9268d6
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment