-
Notifications
You must be signed in to change notification settings - Fork 25
Intersection of geometry objects with meshed_regions #724
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
Open
GuillemBarroso
wants to merge
17
commits into
master
Choose a base branch
from
feat/geometry-mesh-intersect
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
22f1079
WIP: add intersection plane/mesh
GuillemBarroso 071b294
WIP: plane/mesh intersection already working
GuillemBarroso f9045a4
Split example in 3, one per geometry
GuillemBarroso f27e293
Improve planes example
GuillemBarroso b738214
Improve lines example
GuillemBarroso 6ec73d6
Improve geometry exampels
GuillemBarroso 2c45d1c
Compute norm using operator in line plot example
GuillemBarroso aa3a4f1
Add comment clarifying why getting the first field
GuillemBarroso eb26950
Improve geometry examples
GuillemBarroso 852a835
Add units property to geometry objects
GuillemBarroso f2b9de9
Remove arguments and use **kwargs
GuillemBarroso 397c1cf
Include units assertion in tests
GuillemBarroso ad004bb
Use **kwargs
GuillemBarroso bbab689
Rename units by unit
GuillemBarroso 03363eb
Add units in line plot
GuillemBarroso c0dba80
Property coordinates instead of coordiantes.data
GuillemBarroso 5238fec
Fix levelset plots
GuillemBarroso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,88 @@ | ||
""" | ||
.. _plot_on_points: | ||
|
||
Plot on geometry elements | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
This example shows how to plot a Field on a Points object. | ||
|
||
.. note:: | ||
This example requires the Premium ServerContext. | ||
For more information, see :ref:`user_guide_server_context`. | ||
|
||
""" | ||
|
||
|
||
############################################################################### | ||
# Imports and load model | ||
# ~~~~~~~~~~~~~~~~~~~~~~ | ||
# Import modules and set context as Premium. | ||
from ansys.dpf import core as dpf | ||
from ansys.dpf.core import examples | ||
from ansys.dpf.core import operators as ops | ||
from ansys.dpf.core.geometry import Points | ||
from ansys.dpf.core.plotter import DpfPlotter | ||
from ansys.dpf.core.fields_factory import field_from_array | ||
|
||
dpf.set_default_server_context(dpf.AvailableServerContexts.premium) | ||
|
||
############################################################################### | ||
# Load model from examples and print information | ||
model = dpf.Model(examples.find_static_rst()) | ||
print(model) | ||
|
||
############################################################################### | ||
# Create Points object | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Create 8 points in the corners and one in the middle | ||
points = Points( | ||
[ | ||
[0.0, 0.03, 0.0], | ||
[0.0, 0.03, 0.03], | ||
[0.0, 0.06, 0.00], | ||
[0.0, 0.06, 0.03], | ||
[0.03, 0.03, 0.0], | ||
[0.03, 0.03, 0.03], | ||
[0.03, 0.06, 0.00], | ||
[0.03, 0.06, 0.03], | ||
[0.015, 0.045, 0.015], | ||
] | ||
) | ||
|
||
############################################################################### | ||
# Get mesh from model | ||
mesh = model.metadata.meshed_region | ||
|
||
############################################################################### | ||
# Set camera position (obtained with ``cpos=pl.show_figure(return_cpos=True)``) | ||
cpos = [ | ||
(0.07635352356975698, 0.1200500294271993, 0.041072502929096165), | ||
(0.015, 0.045, 0.015), | ||
(-0.16771051558419411, -0.1983722658245161, 0.9656715938216944), | ||
] | ||
############################################################################### | ||
# Show points together with the mesh | ||
points.plot(mesh, cpos=cpos) | ||
|
||
############################################################################### | ||
# Map displacement field to Points | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Use :class:`on_coordinates <ansys.dpf.core.operators.mapping.on_coordinates. | ||
# on_coordinates>`: mapping opretor | ||
disp = model.results.displacement | ||
mapping_operator = ops.mapping.on_coordinates( | ||
fields_container=disp, | ||
coordinates=field_from_array(points.coordinates.data), | ||
create_support=True, | ||
mesh=mesh, | ||
) | ||
fields_mapped = mapping_operator.outputs.fields_container() | ||
field_points = fields_mapped[0] | ||
|
||
############################################################################### | ||
# Plotting displacement field on the geometry objects | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# 3D plot of Points and display mesh | ||
pl = DpfPlotter() | ||
pl.add_field(field_points, render_points_as_spheres=True, point_size=10) | ||
pl.add_mesh(mesh, style="surface", show_edges=True, color="w", opacity=0.3) | ||
pl.show_figure(show_axes=True, cpos=cpos) |
This file contains hidden or 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 @@ | ||
""" | ||
.. _plot_on_lines: | ||
|
||
Plot on Line object | ||
~~~~~~~~~~~~~~~~~~~ | ||
This example shows how to plot a Field on a Line object. | ||
|
||
.. note:: | ||
This example requires the Premium ServerContext. | ||
For more information, see :ref:`user_guide_server_context`. | ||
|
||
""" | ||
|
||
|
||
############################################################################### | ||
# Imports and load model | ||
# ~~~~~~~~~~~~~~~~~~~~~~ | ||
# Import modules and set context as Premium. | ||
import matplotlib.pyplot as plt | ||
|
||
from ansys.dpf import core as dpf | ||
from ansys.dpf.core import examples | ||
from ansys.dpf.core import operators as ops | ||
from ansys.dpf.core.geometry import Line | ||
from ansys.dpf.core.plotter import DpfPlotter | ||
|
||
dpf.set_default_server_context(dpf.AvailableServerContexts.premium) | ||
|
||
############################################################################### | ||
# Load model from examples and print information | ||
model = dpf.Model(examples.find_static_rst()) | ||
print(model) | ||
|
||
############################################################################### | ||
# Create Line object | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Create line passing through the geometry's diagonal | ||
line = Line([[0.03, 0.03, 0.05], [0.0, 0.06, 0.0]], n_points=50) | ||
|
||
############################################################################### | ||
# Get mesh from model | ||
mesh = model.metadata.meshed_region | ||
|
||
############################################################################### | ||
# Define the camera position (obtained with ``cpos=pl.show_figure(return_cpos=True)``) | ||
cpos = [ | ||
(0.07635352356975698, 0.1200500294271993, 0.041072502929096165), | ||
(0.015, 0.045, 0.015), | ||
(-0.16771051558419411, -0.1983722658245161, 0.9656715938216944), | ||
] | ||
|
||
############################################################################### | ||
# Plot the line with the mesh in the background | ||
line.plot(mesh, cpos=cpos) | ||
|
||
############################################################################### | ||
# Map displacement field to Line | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Use :class:`on_coordinates <ansys.dpf.core.operators.mapping.on_coordinates.on_coordinates>`: | ||
# mapping opretor to obtain the displacement Field on the line: | ||
disp = model.results.displacement | ||
mapping_operator = ops.mapping.on_coordinates( | ||
fields_container=disp, | ||
coordinates=line.mesh.nodes.coordinates_field, | ||
create_support=True, | ||
mesh=mesh, | ||
) | ||
fields_mapped = mapping_operator.outputs.fields_container() | ||
field_line = fields_mapped[0] | ||
|
||
############################################################################### | ||
# 3D plot of the line and the mesh | ||
pl = DpfPlotter() | ||
pl.add_field(field_line, line.mesh, line_width=5) | ||
pl.add_mesh(mesh, style="surface", show_edges=True, color="w", opacity=0.3) | ||
pl.show_figure(show_axes=True, cpos=cpos) | ||
|
||
############################################################################### | ||
# 2D Plot displacement field alogn line length | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Get norm of the displacement using | ||
# :class:`norm <ansys.dpf.core.operators.math.norm.norm>`: | ||
norm_op = dpf.operators.math.norm() # operator instantiation | ||
norm_op.inputs.field.connect(field_line) | ||
norm = norm_op.outputs.field() | ||
|
||
############################################################################### | ||
# Get discretized line's path | ||
path = line.path[field_line.scoping.ids - 1] | ||
|
||
############################################################################### | ||
# 2D plot (graph) of Line (line length vs displacement field) | ||
plt.plot(path, norm.data) | ||
plt.xlabel("Line length") | ||
plt.ylabel("Displacement norm field") | ||
plt.show() |
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.
Uh oh!
There was an error while loading. Please reload this page.