Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogstools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Max Bittens
ogstools
Commits
1ec4941b
Commit
1ec4941b
authored
1 year ago
by
Florian Zill
Browse files
Options
Downloads
Patches
Plain Diff
added probe function to MeshSeries
parent
860679a2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ogstools/meshlib/mesh_series.py
+76
-1
76 additions, 1 deletion
ogstools/meshlib/mesh_series.py
with
76 additions
and
1 deletion
ogstools/meshlib/mesh_series.py
+
76
−
1
View file @
1ec4941b
"""
A class to handle Meshseries data.
"""
from
pathlib
import
Path
from
typing
import
Optional
,
Union
from
typing
import
Literal
,
Optional
,
Union
import
meshio
import
numpy
as
np
import
pyvista
as
pv
import
vtuIO
from
meshio.xdmf.time_series
import
(
ReadError
,
cell_data_from_raw
,
xdmf_to_numpy_type
,
)
from
scipy.interpolate
import
LinearNDInterpolator
,
NearestNDInterpolator
from
tqdm.auto
import
tqdm
...
...
@@ -163,6 +165,7 @@ class MeshSeries:
"""
if
isinstance
(
filepath
,
Path
):
filepath
=
str
(
filepath
)
self
.
filepath
=
filepath
self
.
time_unit
=
time_unit
self
.
_data
:
dict
[
int
,
pv
.
UnstructuredGrid
]
=
{}
self
.
_data_type
=
filepath
.
split
(
"
.
"
)[
-
1
]
...
...
@@ -290,3 +293,75 @@ class MeshSeries:
if
self
.
_data_type
==
"
pvd
"
:
return
[
self
.
read
(
t
)[
data_name
]
for
t
in
tqdm
(
self
.
timesteps
)]
return
mesh
[
data_name
]
def
_probe_pvd
(
self
,
points
:
np
.
ndarray
,
data_name
:
str
,
interp_method
:
Optional
[
Literal
[
"
nearest
"
,
"
probefilter
"
]]
=
None
,
interp_backend
:
Optional
[
Literal
[
"
vtk
"
,
"
scipy
"
]]
=
None
,
):
obs_pts_dict
=
{
f
"
pt
{
j
}
"
:
point
for
j
,
point
in
enumerate
(
points
)}
dim
=
self
.
read
(
0
).
get_cell
(
0
).
dimension
pvd_path
=
self
.
filepath
pvdio
=
vtuIO
.
PVDIO
(
pvd_path
,
dim
=
dim
,
interpolation_backend
=
interp_backend
)
values_dict
=
pvdio
.
read_time_series
(
data_name
,
obs_pts_dict
,
interpolation_method
=
interp_method
)
return
np
.
asarray
(
list
(
values_dict
.
values
()))
def
_probe_xdmf
(
self
,
points
:
np
.
ndarray
,
data_name
:
str
,
interp_method
:
Optional
[
Literal
[
"
nearest
"
,
"
linear
"
]]
=
None
,
):
values
=
self
.
hdf5
[
"
meshes
"
][
self
.
hdf5_bulk_name
][
data_name
][:]
geom
=
self
.
hdf5
[
"
meshes
"
][
self
.
hdf5_bulk_name
][
"
geometry
"
][
0
]
# remove flat dimensions for interpolation
for
index
,
axis
in
enumerate
(
geom
.
T
):
if
np
.
all
(
np
.
isclose
(
axis
,
axis
[
0
])):
geom
=
np
.
delete
(
geom
,
index
,
1
)
points
=
np
.
delete
(
points
,
index
,
1
)
if
interp_method
is
None
:
interp_method
=
"
linear
"
interp
=
{
"
nearest
"
:
NearestNDInterpolator
(
geom
,
values
.
T
),
"
linear
"
:
LinearNDInterpolator
(
geom
,
values
.
T
,
np
.
nan
),
}[
interp_method
]
return
interp
(
points
).
T
def
probe
(
self
,
points
:
np
.
ndarray
,
data_name
:
str
,
interp_method
:
Optional
[
Literal
[
"
nearest
"
,
"
linear
"
,
"
probefilter
"
]
]
=
None
,
interp_backend_pvd
:
Optional
[
Literal
[
"
vtk
"
,
"
scipy
"
]]
=
None
,
)
->
np
.
ndarray
:
"""
Probe the MeshSeries at observation points.
:param points: The points to sample at.
:param data_name: Name of the data to sample.
:param interp_method: Choose the interpolation method, defaults to
`linear` for xdmf MeshSeries and `probefilter`
for pvd MeshSeries.
:param interp_backend: Interpolation backend for PVD MeshSeries.
:returns: `numpy` array of interpolated data at observation points.
"""
if
self
.
_data_type
==
"
xdmf
"
:
assert
interp_method
!=
"
probefilter
"
return
self
.
_probe_xdmf
(
points
,
data_name
,
interp_method
)
assert
self
.
_data_type
==
"
pvd
"
assert
interp_method
!=
"
linear
"
return
self
.
_probe_pvd
(
points
,
data_name
,
interp_method
,
interp_backend_pvd
)
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