Skip to content

Commit f6c5882

Browse files
PipKatkmkoshygerma89
authored
General edit of Krylov example (#1605)
* General edit of Krylov example * Make one additional edit * minor changes in example doc * Adding link to struc guide * Use RST.link method in Krylov topic in user guide * Missed changing another link to the RST file method * Fix double occurrence of "see" * Apply suggestions from code review Add German's review comments Co-authored-by: German <[email protected]> * Incorporate German's review comments Co-authored-by: Kevin Mathew <[email protected]> Co-authored-by: German <[email protected]> Co-authored-by: German <[email protected]>
1 parent 9a4df0b commit f6c5882

File tree

3 files changed

+88
-91
lines changed

3 files changed

+88
-91
lines changed

doc/source/examples/extended_examples/Krylov/krylov_example.rst

Lines changed: 78 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,36 @@
55
Harmonic analysis using the frequency-sweep Krylov method
66
=========================================================
77

8-
This example shows how to use the Krylov method in `PyMAPDL <https://mapdl.docs.pyansys.com/>`_ for harmonic
9-
analysis.
8+
This example shows how to use the frequency-sweep Krylov method
9+
implemented in PyMAPDL. For more information, including the
10+
theory behind this method, see `Frequency-Sweep Harmonic Analysis via the Krylov Method
11+
<ansys_krylov_sweep_harmonic_analysis_>`_
12+
in the **Structural Analysis** guide for Mechanical APDL.
1013

11-
These are the main steps required:
14+
Overview
15+
--------
1216

13-
- Generate a Krylov subspace for model reduction in the harmonic analysis using
14-
the :func:`KrylovSolver.gensubspace() <ansys.mapdl.core.krylov.KrylovSolver.gensubspace>`
15-
method.
17+
This example uses the frequency-sweep Krylov method to perform a harmonic analysis
18+
on a cylindrical acoustic duct and study the response of the system over
19+
a range of frequencies.
1620

17-
- Reduce the system of equations and solve at each frequency using the
18-
:func:`KrylovSolver.solve() <ansys.mapdl.core.krylov.KrylovSolver.solve>` method.
21+
The model is a cylindrical acoustic duct with pressure load on one end
22+
and output impedance on the other end.
1923

20-
- Expand the reduced solution back to the FE space using the
21-
:func:`KrylovSolver.expand() <ansys.mapdl.core.krylov.KrylovSolver.expand>` method.
24+
These are the main steps required:
2225

23-
Problem Description
24-
-------------------
26+
- Use the :func:`KrylovSolver.gensubspace() <ansys.mapdl.core.krylov.KrylovSolver.gensubspace>`
27+
method to generate a Krylov subspace for model reduction in the harmonic analysis.
2528

26-
To perform an harmonic analysis on a cylindrical acoustic duct using the Krylov method
27-
and study the response of the system over a range of frequencies.
29+
- Use the :func:`KrylovSolver.solve() <ansys.mapdl.core.krylov.KrylovSolver.solve>`
30+
method to reduce the system of equations and solve at each frequency.
2831

32+
- Use the :func:`KrylovSolver.expand() <ansys.mapdl.core.krylov.KrylovSolver.expand>` method
33+
to expand the reduced solution back to the FE space.
2934

30-
The model is a cylindrical acoustic duct with pressure load on one end
31-
and output impedance on the other end.
35+
Perform required imports
36+
------------------------
37+
Perform required imports and launch mapdl.
3238

3339
.. code:: ipython3
3440
@@ -42,16 +48,14 @@ and output impedance on the other end.
4248
mapdl.clear()
4349
mm = mapdl.math
4450
51+
52+
Define parameters
53+
-----------------
4554

46-
47-
48-
Parameters definition
49-
~~~~~~~~~~~~~~~~~~~~~
50-
51-
This section defines some geometry parameters and analysis settings.
52-
As mentioned earlier, the geometry is a cylinder defined by its radius (``cyl_r``) and its length (``cyl_L``).
53-
The length of the duct is such that three complete wavelengths (``no_wl``) can fit in its length and can have
54-
ten elements per wavelength.
55+
Define some geometry parameters and analysis settings. As mentioned earlier, the geometry
56+
is a cylinder defined by its radius (``cyl_r``) and its length (``cyl_L``). The length
57+
of the duct is such that three complete wavelengths (``no_wl``) can fit in its length
58+
and can have ten elements per wavelength.
5559

5660
.. code:: ipython3
5761
@@ -75,11 +79,10 @@ ten elements per wavelength.
7579
nelem_wl = 10 # no of elements per wavelength
7680
tol_elem = nelem_wl * no_wl # total number of elements across length
7781
78-
Element and material definition
79-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80-
81-
Here we will assign fluid medium (Air) properties to the duct.
82-
We will use Fluid 220 (Keyopt(2)=1) with one degree of freedom per node : pressure,
82+
Define element type and materials
83+
---------------------------------
84+
Assign fluid medium (air) properties to the duct. This example
85+
uses Fluid 220 (``Keyopt(2)=1``) with one degree of freedom per node (pressure),
8386
with no FSI interface in the element.
8487

8588
.. code:: ipython3
@@ -92,44 +95,45 @@ with no FSI interface in the element.
9295
mapdl.mp("VISC", 1, visco)
9396
9497
95-
Geometry definition
96-
~~~~~~~~~~~~~~~~~~~
98+
Define geometry
99+
---------------
97100

98-
Here we discuss creating a cylinder of required dimensions and splitting it into
99-
4 segments for uniform generation of the mesh in each segment.
101+
Create a cylinder of the required dimensions and split it into
102+
four segments for uniform generation of the mesh in each segment.
100103

101104
.. code:: ipython3
102105
103-
# Setting back to default
106+
# Set back to default
104107
mapdl.csys(0)
105108
106-
# Rotating working plane for the cylinder generation
109+
# Rotate working plane for the cylinder generation
107110
mapdl.wpcsys(-1)
108111
mapdl.wprota(thzx=90)
109112
110-
# Generating a circular area with specified radius
113+
# Generate a circular area with a specified radius
111114
mapdl.cyl4(0, 0, cyl_r)
112115
113116
mapdl.wpcsys(-1)
114117
115-
# Extrude the circular area to generate cylinder of specified length
118+
# Extrude the circular area to generate a cylinder of specified length
116119
mapdl.vext("ALL", dx=cyl_L)
117120
118-
# Segment the cylinder into four quadrants to create a more uniform mesh
121+
# Split the cylinder into four segments to create a more uniform mesh
119122
mapdl.vsbw("ALL", keep='DELETE')
120123
mapdl.wprota(thzx=90)
121-
mapdl.vsbw("ALL", keep='DELETE') # Why this is needed?
124+
mapdl.vsbw("ALL", keep='DELETE')
122125
123126
mapdl.wpcsys(-1)
124127
125-
# Creating a component with the created volume
128+
# Create a component with the created volume
126129
mapdl.cm('cm1', 'volu')
127130
128131
129132
130-
Create mesh:
133+
Create mesh
134+
-----------
131135

132-
Mesh the
136+
Create the mesh and plot the FE model.
133137

134138
.. code:: ipython3
135139
@@ -154,28 +158,23 @@ a length element size constraint to the longitudinal lines.
154158
mapdl.lsel("U", 'loc', 'x', 0)
155159
mapdl.lsel("U", 'loc', 'x', cyl_L)
156160
157-
# Apply length constraint.
161+
# Apply length constraint
158162
mapdl.lesize('ALL',ndiv = tol_elem)
159163
mapdl.lsla()
160164
161165
# Mesh
162166
mapdl.vsweep('ALL')
163-
164167
mapdl.allsel()
165-
166-
167-
168-
Plot FE model:
169-
170-
.. code:: ipython3
171-
168+
169+
# Plot the FE model
172170
mapdl.eplot()
173171
172+
174173
.. image:: ../../../examples/extended_examples/Krylov/Harmonic_Analysis_using_krylov_pymapdl_files/Harmonic_Analysis_using_krylov_pymapdl_15_1.png
175174

176175

177176
Define boundary conditions
178-
~~~~~~~~~~~~~~~~~~~~~~~~~~
177+
--------------------------
179178

180179
Apply pressure load on one end and output impedance on other end of the acoustic duct.
181180

@@ -203,11 +202,10 @@ Apply pressure load on one end and output impedance on other end of the acoustic
203202
mapdl.allsel()
204203
205204
206-
207205
Perform modal analysis
208206
----------------------
209207

210-
Get the first 10 natural frequency modes of the acoustic duct
208+
Get the first 10 natural frequency modes of the acoustic duct.
211209

212210
.. code:: ipython3
213211
@@ -243,28 +241,24 @@ Get the first 10 natural frequency modes of the acoustic duct
243241
244242
Run harmonic analysis using Krylov method
245243
-----------------------------------------
244+
Perform the following steps to run the harmonic analysis using the
245+
frequency-sweep Krylov method.
246246

247-
**Step 1**: Generate full file.
247+
**Step 1**: Generate FULL file and initialize the ``Krylov`` class object.
248248

249249
.. code:: ipython3
250250
251251
mapdl.run('/SOLU')
252-
mapdl.antype('HARMIC') # HARMONIC ANALYSIS
252+
mapdl.antype('HARMIC') # Set options for harmonic analysis
253253
mapdl.hropt('KRYLOV')
254254
mapdl.eqslv('SPARSE')
255-
mapdl.harfrq(0,1000) # set beginning and ending frequency
256-
mapdl.nsubst(100) # set the number of frequency increments
257-
mapdl.wrfull(1) # GENERATE .FULL FILE AND STOP
255+
mapdl.harfrq(0,1000) # Set beginning and ending frequency
256+
mapdl.nsubst(100) # Set the number of frequency increments
257+
mapdl.wrfull(1) # Generate FULL file and stop
258258
mapdl.solve()
259259
mapdl.finish()
260260
261-
262-
263-
Initialize Krylov class object.
264-
265-
.. code:: ipython3
266-
267-
dd = mapdl.krylov
261+
dd = mapdl.krylov # Initialize Krylov class object
268262
269263
**Step 2**: Generate a Krylov subspace of size/dimension 10 at frequency
270264
500 Hz for model reduction.
@@ -273,7 +267,8 @@ Initialize Krylov class object.
273267
274268
Qz = dd.gensubspace(10, 500, check_orthogonality=True)
275269
276-
The shape of the generated subspace.
270+
271+
Obtain the shape of the generated subspace.
277272

278273
.. code:: ipython3
279274
@@ -292,7 +287,7 @@ from 0 Hz to 1000 Hz with ramped loading.
292287
293288
Yz = dd.solve(0, 1000, 100, ramped_load=True)
294289
295-
The shape of the reduced solution generated is.
290+
Obtain the shape of the reduced solution generated.
296291

297292
.. code:: ipython3
298293
@@ -308,9 +303,9 @@ The shape of the reduced solution generated is.
308303

309304
.. code:: ipython3
310305
311-
result = dd.expand(residual_computation=True, residual_algorithm="l2")
306+
result = dd.expand(residual_computation=True, residual_algorithm="l2", return_solution = True)
312307
313-
Results: Pressure distribution as a function of length
308+
Plot the pressure distribution as a function of length
314309
------------------------------------------------------
315310

316311
Plot the pressure distribution over the length of the duct on nodes where Y, Z coordinates are zero.
@@ -334,13 +329,13 @@ Load the last result substep to get the pressure for each of the selected nodes.
334329
substep_index = 99
335330
336331
def get_pressure_at(node, step=1):
337-
"""Get the pressure at a given node at a given step (by default first step)"""
332+
"""Get pressure at a given node at a given step (by default first step)"""
338333
index_num = np.where(result[step]['node'] == node)
339334
return result[step][index_num]
340335
341336
for each_node, loc in zip(ind, coords):
342337
# Get pressure at the node
343-
pressure = get_pressure(each_node, substep_index)['x'][0]
338+
pressure = get_pressure_at(each_node, substep_index)['x'][0]
344339
345340
#Calculate amplitude at 60 deg
346341
magnitude = abs(pressure)
@@ -351,13 +346,13 @@ Load the last result substep to get the pressure for each of the selected nodes.
351346
x_data.append(loc[0]) # X-Coordenate
352347
y_data.append(pressure_a) # Nodal pressure at 60 degrees
353348
354-
Sort the results according to the X-coordinate:
349+
Sort the results according to the X coordinate.
355350

356351
.. code:: ipython3
357352
358353
sorted_x_data, sorted_y_data = zip(*sorted(zip(x_data, y_data)))
359354
360-
Plot the calculated data:
355+
Plot the calculated data.
361356

362357
.. code:: ipython3
363358
@@ -378,11 +373,11 @@ Plot the calculated data:
378373
.. image:: ../../../examples/extended_examples/Krylov/Harmonic_Analysis_using_krylov_pymapdl_files/Harmonic_Analysis_using_krylov_pymapdl_36_1.png
379374

380375

381-
Results: Plot frequency response function
382-
------------------------------------------
376+
Plot the frequency response function
377+
------------------------------------
383378

384379
Plot the frequency response function of any node along the length of the cylindrical duct.
385-
For example, let us plot the frequency response function for a node along 0.2 in X-direction of the duct.
380+
This code plots the frequency response function for a node along 0.2 in the X direction of the duct.
386381

387382
.. code:: ipython3
388383
@@ -391,7 +386,7 @@ For example, let us plot the frequency response function for a node along 0.2 in
391386
392387
393388
Get the response of the system for the selected node
394-
over a range of frequencies [0-1000 Hz]:
389+
over a range of frequencies, such as 0 to 1000 Hz.
395390

396391
.. code:: python3
397392
@@ -402,13 +397,13 @@ over a range of frequencies [0-1000 Hz]:
402397
dic = {}
403398
404399
for freq in range (0,num_steps):
405-
pressure = get_pressure(node_number, freq)['x']
400+
pressure = get_pressure_at(node_number, freq)['x']
406401
abs_pressure = abs(pressure)
407402
408403
dic[start_freq] = abs_pressure
409404
start_freq += step_val
410405
411-
Sort the results:
406+
Sort the results.
412407

413408
.. code:: python3
414409
@@ -418,15 +413,15 @@ Sort the results:
418413
419414
420415
421-
Plot the frequency response function for the selected node:
416+
Plot the frequency response function for the selected node.
422417

423418
.. code:: python3
424419
425420
plt.plot(frf_x, frf_y, linewidth= 3.0, color='b')
426421
427422
# Plot the natural frequency as vertical lines on the FRF graph
428423
for itr in range(0,6):
429-
plt.axvline(x=ev[itr], ymin=0,ymax=2, color='r', linestyle='dotted', linewidth=1)
424+
plt.axvline(x=eigenvalues[itr], ymin=0,ymax=2, color='r', linestyle='dotted', linewidth=1)
430425
431426
# Name the graph and the x-axis and y-axis
432427
plt.title("Frequency Response Function")

doc/source/links.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
.. _ansys_installation_and_licensing: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/prod_page.html?pn=Installation%20and%20Licensing&pid=InstallationAndLicensing&lang=en
4444
.. _ansys_parallel_computing_guide: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v222/en/ans_dan/dantoc.html
4545

46+
.. # Ansys Structural Guide links:
47+
.. _ansys_krylov_sweep_harmonic_analysis: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v222/en/ans_str/str_Krysweep.html
48+
4649
.. #Ansys learning
4750
.. _course_intro_python: https://courses.ansys.com/index.php/courses/intro-to-python/
4851
.. _course_getting_started_pymapdl: https://courses.ansys.com/index.php/courses/getting-started-with-pymapdl/

0 commit comments

Comments
 (0)