Skip to content

Commit cdcbb35

Browse files
hoangxuyenleHoang LE
and
Hoang LE
authored
dpf_extrapolate_examples (#41)
* dpf_extrapolate_examples * fix syntax * update Co-authored-by: Hoang LE <[email protected]>
1 parent a529380 commit cdcbb35

File tree

4 files changed

+280
-1
lines changed

4 files changed

+280
-1
lines changed

.ci/azure-pipelines.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ trigger:
1717

1818
pr:
1919
branches:
20-
exclude:
20+
include:
2121
- '*'
22+
exclude:
23+
- '*no-ci*'
2224

2325
jobs:
2426
- job: Windows

ansys/dpf/core/examples/downloads.py

+50
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,53 @@ def download_fluent_files()->dict:
306306
"""
307307
return {"cas":_download_file('fluent', 'FFF.cas.h5'),
308308
"dat":_download_file('fluent', 'FFF.dat.h5')}
309+
310+
def download_extrapolation_3d_result() -> dict:
311+
"""Download example static results of reference and integrated points for extrapolation of 3d-element and return return the dictionary of 2 download paths.
312+
313+
Examples files are downloaded to a persistent cache to avoid
314+
re-downloading the same file twice.
315+
316+
Returns
317+
-------
318+
dict
319+
containing path to the example file of ref and path to the example file of integrated points.
320+
321+
Examples
322+
--------
323+
Download 2 example result files and return the dictionary containing 2 files
324+
325+
>>> from ansys.dpf.core import examples
326+
>>> dict = examples.download_extrapolation_ref_result
327+
>>> dict
328+
{'file_ref': 'C:/Users/user/AppData/local/temp/file_ref.rst', 'file_integrated': 'C:/Users/user/AppData/local/temp/file.rst'}
329+
330+
"""
331+
dict={'file_ref': _download_file('extrapolate', 'file_ref.rst'), 'file_integrated': _download_file('extrapolate', 'file.rst')}
332+
333+
return dict
334+
335+
def download_extrapolation_2d_result() -> dict:
336+
"""Download example static results of reference and integrated points for extrapolation of 2d-element and return the dictionary of 2 download paths.
337+
338+
Examples files are downloaded to a persistent cache to avoid
339+
re-downloading the same file twice.
340+
341+
Returns
342+
-------
343+
dict
344+
containing path to the example file of ref and path to the example file of integrated points.
345+
346+
Examples
347+
--------
348+
Download 2 example result files and return the dictionary containing 2 files
349+
350+
>>> from ansys.dpf.core import examples
351+
>>> dict = examples.download_extrapolation_ref_result
352+
>>> dict
353+
{'file_ref': 'C:/Users/user/AppData/local/temp/extrapolate_2d_ref.rst', 'file_integrated': 'C:/Users/user/AppData/local/temp/extrapolate_2d.rst'}
354+
355+
"""
356+
dict={'file_ref': _download_file('extrapolate', 'extrapolate_2d_ref.rst'), 'file_integrated': _download_file('extrapolate', 'extrapolate_2d.rst')}
357+
358+
return dict
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
"""
2+
.. _extrapolation_test_stress_3Delement:
3+
4+
Extrapolation Method for stress result of 3D-element
5+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
This example shows how to compute the nodal components stress from Gaussian points (integration points) for 3D-element by using the method of extrapolation.
7+
Extrapolating results available at Gauss or quadrature points to nodal points for a field or fields container. The available elements are : linear quadrangle, parabolic quadrangle, linear hexagonal, quadratic hexagonal, linear tetrahedral, quadratic tetrahedral.
8+
9+
1st step : get the data source's analyse of integration points(this file was add the commands APDL "EREXS, NO").
10+
11+
2nd step: using operator of extrapolation to compute the nodal stress.
12+
13+
3rd step: get nodal stress result from data source's analyse reference. The analyse was computed by ANSYS Mechanical APDL.
14+
15+
4th step: compare the results between nodal stress from data source ref and nodal stress computed by Extrapolation Method.
16+
17+
"""
18+
19+
from ansys.dpf import core as dpf
20+
from ansys.dpf.core import examples
21+
from ansys.dpf.core import operators
22+
23+
24+
###############################################################################
25+
# Get the data source's analyse of integration points and data source's analyse reference
26+
datafile= examples.download_extrapolation_3d_result()
27+
28+
# integration points (Gaussian points)
29+
data_integration_points=datafile['file_integrated']
30+
data_sources_integration_points = dpf.DataSources(data_integration_points)
31+
32+
# reference
33+
dataSourceref=datafile['file_ref']
34+
data_sources_ref = dpf.DataSources(dataSourceref)
35+
36+
# get the mesh
37+
model = dpf.Model(data_integration_points)
38+
mesh = model.metadata.meshed_region
39+
40+
# operator instantiation scoping
41+
op_scoping = dpf.operators.scoping.splitted_on_property_type() # operator instantiation
42+
op_scoping.inputs.mesh.connect(mesh)
43+
op_scoping.inputs.requested_location.connect("Elemental")
44+
mesh_scoping = op_scoping.outputs.mesh_scoping()
45+
46+
###############################################################################
47+
# Extrapolation from integration points for stress result
48+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49+
# In this example we compute nodal component stress result from integration points's stress by using operator gauss_to_node_fc
50+
51+
# Create stress operator to get stress result of integration points
52+
stressop=dpf.operators.result.stress()
53+
stressop.inputs.data_sources.connect(data_sources_integration_points)
54+
stress=stressop.outputs.fields_container()
55+
56+
###############################################################################
57+
# Nodal stress result of integration points:
58+
###############################################################################
59+
# The command "ERESX,NO" in Mechanical APDL is used to copy directly the gaussian (integration) points results to the nodes, instead of the results at nodes or elements (which are interpolation of results at a few gauss points).
60+
# The following plot shows the nodal values which are the averaged values of stresses at each node. The value shown at the node is the average of the stresses from the gaussian points of each element that it belongs to.
61+
62+
# plot
63+
stress_nodal_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc()
64+
stress_nodal_op.inputs.fields_container.connect(stress)
65+
mesh.plot(stress_nodal_op.outputs.fields_container())
66+
67+
68+
###############################################################################
69+
# Create operator gauss_to_node_fc and compute nodal component stress by applying Extrapolation Method
70+
71+
ex_stress = dpf.operators.averaging.gauss_to_node_fc()
72+
# connect mesh
73+
ex_stress.inputs.mesh.connect(mesh)
74+
# connect fields container stress
75+
ex_stress.inputs.fields_container.connect(stress)
76+
# get output
77+
fex=ex_stress.outputs.fields_container()
78+
79+
###############################################################################
80+
# Stress result of reference ANSYS Workbench
81+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82+
83+
# Stress from file dataSourceref
84+
stressop_ref=dpf.operators.result.stress()
85+
stressop_ref.inputs.data_sources.connect(data_sources_ref)
86+
stressop_ref.inputs.mesh_scoping.connect(mesh_scoping)
87+
stress_ref=stressop_ref.outputs.fields_container()
88+
89+
###############################################################################
90+
# Plot
91+
#~~~~~~~~~~
92+
# Showing plots of Extrapolation's stress result and reference's stress result
93+
94+
# extrapolation
95+
fex_nodal_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc()
96+
fex_nodal_op.inputs.fields_container.connect(fex)
97+
mesh.plot(fex_nodal_op.outputs.fields_container())
98+
# reference
99+
stress_ref_nodal_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc()
100+
stress_ref_nodal_op.inputs.fields_container.connect(stress_ref)
101+
mesh.plot(stress_ref_nodal_op.outputs.fields_container())
102+
103+
###############################################################################
104+
# Comparison
105+
#~~~~~~~~~~~~
106+
# Compare the stress result computed by extrapolation and reference's result.
107+
# Check if two fields container are identical.
108+
# Maximum tolerance gap between to compared values: 1e-2.
109+
# Smallest value which will be considered during the comparison step : all the abs(values) in field less than 1e-8 is considered as null
110+
111+
# operator AreFieldsIdentical_fc
112+
op = dpf.operators.logic.identical_fc()
113+
op.inputs.fields_containerA.connect(fex)
114+
op.inputs.fields_containerB.connect(stress_ref)
115+
op.inputs.tolerance.connect(1.0e-8)
116+
op.inputs.small_value.connect(0.01)
117+
op.outputs.boolean()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
"""
2+
.. _extrapolation_test_strain_2Delement:
3+
4+
Extrapolation Method for strain result of 2D-element
5+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
This example shows how to compute the nodal components elastic strain from Gaussian points (integration points) for 2D-element by using the method of extrapolation.
7+
Extrapolating results available at Gauss or quadrature points to nodal points for a field or fields container. The available elements are : linear quadrangle, parabolic quadrangle, linear hexagonal, quadratic hexagonal, linear tetrahedral, quadratic tetrahedral.
8+
9+
1st step : get the data source's analyse of integration points(this file was add the commands APDL "EREXS, NO").
10+
11+
2nd step: using operator of extrapolation to compute the nodal elastic strain.
12+
13+
3rd step: get nodal elastic strain result from data source's analyse reference. The analyse was computed by ANSYS Mechanical APDL.
14+
15+
4th step: compare the results between nodal elastic strain from data source ref and nodal strain computed by Extrapolation Method.
16+
17+
"""
18+
19+
from ansys.dpf import core as dpf
20+
from ansys.dpf.core import examples
21+
from ansys.dpf.core import operators
22+
23+
24+
###############################################################################
25+
# Get the data source's analyse of integration points and data source's analyse reference
26+
datafile= examples.download_extrapolation_2d_result()
27+
28+
# integration points (Gaussian points)
29+
data_integration_points=datafile['file_integrated']
30+
data_sources_integration_points = dpf.DataSources(data_integration_points)
31+
32+
# reference
33+
dataSourceref=datafile['file_ref']
34+
data_sources_ref = dpf.DataSources(dataSourceref)
35+
36+
# get the mesh
37+
model = dpf.Model(data_integration_points)
38+
mesh = model.metadata.meshed_region
39+
40+
###############################################################################
41+
# Extrapolation from integration points for elastic strain result
42+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43+
# In this example we compute nodal component elastic strain results from integration points's elastic strain by using operator gauss_to_node_fc
44+
45+
# Create elastic strain operator to get strain result of integration points
46+
strainop=dpf.operators.result.elastic_strain()
47+
strainop.inputs.data_sources.connect(data_sources_integration_points)
48+
strain=strainop.outputs.fields_container()
49+
50+
###############################################################################
51+
# Nodal elastic strain result of integration points:
52+
###############################################################################
53+
# The command "ERESX,NO" in Mechanical APDL is used to copy directly the gaussian (integration) points results to the nodes, instead of the results at nodes or elements (which are interpolation of results at a few gauss points).
54+
# The following plot shows the nodal values which are the averaged values of elastic strain at each node. The value shown at the node is the average of the elastic strains from the gaussian points of each element that it belongs to.
55+
56+
# plot
57+
strain_nodal_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc()
58+
strain_nodal_op.inputs.fields_container.connect(strain)
59+
mesh.plot(strain_nodal_op.outputs.fields_container())
60+
61+
62+
###############################################################################
63+
# Create operator gauss_to_node_fc and compute nodal component elastic strain by applying Extrapolation Method
64+
65+
ex_strain = dpf.operators.averaging.gauss_to_node_fc()
66+
# connect mesh
67+
ex_strain.inputs.mesh.connect(mesh)
68+
# connect fields container elastic strain
69+
ex_strain.inputs.fields_container.connect(strain)
70+
# get output
71+
fex=ex_strain.outputs.fields_container()
72+
73+
###############################################################################
74+
# Elastic strain result of reference ANSYS Workbench
75+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76+
77+
# Strain from file dataSourceref
78+
strainop_ref=dpf.operators.result.elastic_strain()
79+
strainop_ref.inputs.data_sources.connect(data_sources_ref)
80+
strain_ref=strainop_ref.outputs.fields_container()
81+
82+
###############################################################################
83+
# Plot
84+
# ~~~~~~~~~~
85+
# Showing plots of Extrapolation's elastic strain result and reference's elastic strain result
86+
87+
# extrapolation
88+
fex_nodal_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc()
89+
fex_nodal_op.inputs.fields_container.connect(fex)
90+
mesh.plot(fex_nodal_op.outputs.fields_container())
91+
# reference
92+
strain_ref_nodal_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc()
93+
strain_ref_nodal_op.inputs.fields_container.connect(strain_ref)
94+
mesh.plot(strain_ref_nodal_op.outputs.fields_container())
95+
96+
###############################################################################
97+
# Comparison
98+
# ~~~~~~~~~~~~
99+
# Compare the elastic strain result computed by extrapolation and reference's result.
100+
# Check if two fields container are identical.
101+
# Maximum tolerance gap between to compared values: 1e-3.
102+
# Smallest value which will be considered during the comparison step : all the abs(values) in field less than 1e-14 is considered as null
103+
104+
# operator AreFieldsIdentical_fc
105+
op = dpf.operators.logic.identical_fc()
106+
op.inputs.fields_containerA.connect(fex)
107+
op.inputs.fields_containerB.connect(strain_ref)
108+
op.inputs.tolerance.connect(1.0e-14)
109+
op.inputs.small_value.connect(0.001)
110+
op.outputs.boolean()

0 commit comments

Comments
 (0)