Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Romin Tomasetti
gmsh
Commits
90347b8b
Commit
90347b8b
authored
Dec 31, 2021
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
improve DistanceField in multi-threaded case
parent
09b16636
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mesh/Field.cpp
+62
-64
62 additions, 64 deletions
src/mesh/Field.cpp
with
62 additions
and
64 deletions
src/mesh/Field.cpp
+
62
−
64
View file @
90347b8b
...
...
@@ -2650,11 +2650,9 @@ class DistanceField : public Field {
SPoint3CloudAdaptor
<
SPoint3Cloud
>
_pc2kdtree
;
SPoint3KDTree
*
_kdtree
;
std
::
size_t
_outIndex
;
double
_outDistSqr
;
public:
DistanceField
()
:
_pc2kdtree
(
_pc
),
_kdtree
(
nullptr
),
_outIndex
(
0
),
_outDistSqr
(
0.
)
DistanceField
()
:
_pc2kdtree
(
_pc
),
_kdtree
(
nullptr
),
_outIndex
(
0
)
{
_sampling
=
20
;
...
...
@@ -2689,8 +2687,7 @@ public:
new
FieldOptionInt
(
_sampling
,
"[Deprecated]"
,
&
updateNeeded
,
true
);
}
DistanceField
(
int
dim
,
int
tag
,
int
nbe
)
:
_sampling
(
nbe
),
_pc2kdtree
(
_pc
),
_kdtree
(
nullptr
),
_outIndex
(
0
),
_outDistSqr
(
0
)
:
_sampling
(
nbe
),
_pc2kdtree
(
_pc
),
_kdtree
(
nullptr
),
_outIndex
(
0
)
{
if
(
dim
==
0
)
_pointTags
.
push_back
(
tag
);
...
...
@@ -2721,15 +2718,14 @@ public:
}
void
update
()
{
if
(
updateNeeded
)
{
_infos
.
clear
();
std
::
vector
<
SPoint3
>
&
points
=
_pc
.
pts
;
points
.
clear
()
;
_pc
.
pts
.
clear
()
;
if
(
_kdtree
)
delete
_kdtree
;
for
(
auto
it
=
_pointTags
.
begin
();
it
!=
_pointTags
.
end
();
++
it
)
{
GVertex
*
gv
=
GModel
::
current
()
->
getVertexByTag
(
*
it
);
if
(
gv
)
{
poin
ts
.
push_back
(
SPoint3
(
gv
->
x
(),
gv
->
y
(),
gv
->
z
()));
_pc
.
p
ts
.
push_back
(
SPoint3
(
gv
->
x
(),
gv
->
y
(),
gv
->
z
()));
_infos
.
push_back
(
AttractorInfo
(
*
it
,
0
,
0
,
0
));
}
else
{
...
...
@@ -2742,7 +2738,7 @@ public:
if
(
e
)
{
if
(
e
->
mesh_vertices
.
size
())
{
for
(
std
::
size_t
i
=
0
;
i
<
e
->
mesh_vertices
.
size
();
i
++
)
{
poin
ts
.
push_back
(
SPoint3
(
e
->
mesh_vertices
[
i
]
->
x
(),
_pc
.
p
ts
.
push_back
(
SPoint3
(
e
->
mesh_vertices
[
i
]
->
x
(),
e
->
mesh_vertices
[
i
]
->
y
(),
e
->
mesh_vertices
[
i
]
->
z
()));
double
t
=
0.
;
...
...
@@ -2756,7 +2752,7 @@ public:
Range
<
double
>
b
=
e
->
parBounds
(
0
);
double
t
=
b
.
low
()
+
u
*
(
b
.
high
()
-
b
.
low
());
GPoint
gp
=
e
->
point
(
t
);
poin
ts
.
push_back
(
SPoint3
(
gp
.
x
(),
gp
.
y
(),
gp
.
z
()));
_pc
.
p
ts
.
push_back
(
SPoint3
(
gp
.
x
(),
gp
.
y
(),
gp
.
z
()));
_infos
.
push_back
(
AttractorInfo
(
*
it
,
1
,
t
,
0
));
}
}
...
...
@@ -2770,7 +2766,7 @@ public:
if
(
f
)
{
double
maxDist
=
f
->
bounds
().
diag
()
/
_sampling
;
std
::
vector
<
SPoint2
>
uvpoints
;
f
->
fillPointCloud
(
maxDist
,
&
poin
ts
,
&
uvpoints
);
f
->
fillPointCloud
(
maxDist
,
&
_pc
.
p
ts
,
&
uvpoints
);
for
(
std
::
size_t
i
=
0
;
i
<
uvpoints
.
size
();
i
++
)
_infos
.
push_back
(
AttractorInfo
(
*
it
,
2
,
uvpoints
[
i
].
x
(),
uvpoints
[
i
].
y
()));
...
...
@@ -2786,17 +2782,19 @@ public:
_kdtree
->
buildIndex
();
updateNeeded
=
false
;
}
}
using
Field
::
operator
();
virtual
double
operator
()(
double
X
,
double
Y
,
double
Z
,
GEntity
*
ge
=
nullptr
)
{
if
(
!
_kdtree
)
return
MAX_LC
;
#pragma omp critical
{
if
(
!
_kdtree
||
updateNeeded
)
update
();
}
double
query_pt
[
3
]
=
{
X
,
Y
,
Z
};
const
size_t
num_results
=
1
;
nanoflann
::
KNNResultSet
<
double
>
resultSet
(
num_results
)
;
resultSet
.
init
(
&
_outIndex
,
&
_
outDistSqr
);
nanoflann
::
KNNResultSet
<
double
>
resultSet
(
1
)
;
double
outDistSqr
;
resultSet
.
init
(
&
_outIndex
,
&
outDistSqr
);
_kdtree
->
findNeighbors
(
resultSet
,
&
query_pt
[
0
],
nanoflann
::
SearchParams
(
10
));
return
sqrt
(
_
outDistSqr
);
return
sqrt
(
outDistSqr
);
}
};
...
...
This diff is collapsed.
Click to expand it.
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