3D Acoustic Analysis#

This example shows how to perform an acoustic analysis using PyMAPDL and FLUID elements.

Launch PyMAPDL#

Launch PyMAPDL and load matplotlib.

from matplotlib import pyplot as plt

from ansys.mapdl.core import launch_mapdl

mapdl = launch_mapdl()

mapdl.clear()
mapdl.prep7()
mapdl.units("SI")  # SI - International system (m, kg, s, K).
SI UNITS SPECIFIED FOR INTERNAL
  LENGTH        (l)  = METER (M)
  MASS          (M)  = KILOGRAM (KG)
  TIME          (t)  = SECOND (SEC)
  TEMPERATURE   (T)  = KELVIN (K)
  TOFFSET            = 0.0 KELVIN
  CHARGE        (Q)  = COULOMB
  FORCE         (f)  = NEWTON (N) (KG-M/SEC2)
  HEAT               = JOULE (N-M)

  PRESSURE           = PASCAL (NEWTON/M**2)
  ENERGY        (W)  = JOULE (N-M)
  POWER         (P)  = WATT (N-M/SEC)
  CURRENT       (i)  = AMPERE (COULOMBS/SEC)
  CAPACITANCE   (C)  = FARAD
  INDUCTANCE    (L)  = HENRY
  MAGNETIC FLUX      = WEBER
  RESISTANCE    (R)  = OHM
  ELECTRIC POTENTIAL = VOLT

 INPUT  UNITS ARE ALSO SET TO SI

Element and Material Properties#

Define the FLUID30 and FLUID130 element types.

mapdl.et(1, "FLUID30", kop1=2)


# Define the material properties
mapdl.mp("SONC", 1, 1500)  # sonc in m/s
mapdl.mp("DENS", 1, 1000)  # Density in kg/m3
print(mapdl.mplist())


# Define the real const
mapdl.r("1", "1e-6")  # Reference pressure for R set 1
print(mapdl.rlist())
LIST MATERIALS        1 TO        1 BY        1
  PROPERTY= ALL

 MATERIAL NUMBER        1

      TEMP        DENS
                1000.000

      TEMP        SONC
                1500.000
*** MAPDL - ENGINEERING ANALYSIS SYSTEM  RELEASE                  24.2     ***
 Ansys Mechanical Enterprise Academic Student
 01055371  VERSION=LINUX x64     10:03:36  OCT 04, 2024 CP=    164.993





 LIST REAL SETS        1 TO        1 BY        1

 REAL CONSTANT SET        1  ITEMS   1 TO   6
   0.10000E-05   0.0000       0.0000       0.0000       0.0000       0.0000

Geometry Definition#

Create a simple sphere.

vnum = mapdl.sphere(rad1=0.5, rad2=1.0)
mapdl.vsbw("all")
mapdl.vplot(show_area_numbering=True)
  • acoustic analysis
  • acoustic analysis
  • acoustic analysis

Geometry Meshing#

First select the material and elements.

mapdl.type(itype=1)
mapdl.real(nset=1)
mapdl.mat(mat=1)
mapdl.mshape(1, "3D")
PRODUCE ALL TETRAHEDRAL ELEMENTS IN 3D.

 *** WARNING ***                         CP =     167.089   TIME= 10:03:39
 Structural elements without mid nodes usually produce much more
 accurate results in quad or brick shape.

Then choose the element size and perform the mesh.

mapdl.esize(0.25)
mapdl.vmesh("all")
mapdl.eplot(show_node_numbering=False)
acoustic analysis

Boundary Conditions#

Add surface boundary condition to the nodes using Mapdl.sf() and the option SHLD for Surface normal velocity or acceleration.

mapdl.csys(2)
mapdl.asel("s", "loc", "x", 0.5)
mapdl.csys(0)
mapdl.nsla("S", 1)
mapdl.sf("all", "SHLD", 5)
mapdl.allsel()
SELECT ALL ENTITIES OF TYPE= ALL  AND BELOW

Solve the model#

Using Mapdl.solve()

mapdl.allsel()
mapdl.run("/SOLU")
mapdl.antype(3)
mapdl.harfrq(freqb=200, freqe=1000)
mapdl.autots("off")
mapdl.nsubst(40)
mapdl.kbc(0)

mapdl.outres("erase")  # Save less data in order to reduce the size of .rst file
mapdl.outres("all", "none")  # NOTE that other output like stresses is not saved
mapdl.outres("nsol", "all")  # Save pressure and displacement
mapdl.outres("fgrad", "all")  # Save velocities
mapdl.outres("misc", "all")  # For post processing calculations

mapdl.solve()
*** NOTE ***                            CP =     169.316   TIME= 10:03:42
 The automatic domain decomposition logic has selected the FREQ domain
 decomposition method with 1 processes per frequency solution.

 *****  MAPDL SOLVE    COMMAND  *****



   D I S T R I B U T E D   D O M A I N   D E C O M P O S E R

 ...Number of frequency solutions:  40
 ...Decompose to 2 frequency domains (with 1 processes per domain)


 *** NOTE ***                            CP =     169.383   TIME= 10:03:42
 There is no title defined for this analysis.

 *** MAPDL - ENGINEERING ANALYSIS SYSTEM  RELEASE                  24.2     ***
 Ansys Mechanical Enterprise Academic Student
 01055371  VERSION=LINUX x64     10:03:42  OCT 04, 2024 CP=    169.389





                       S O L U T I O N   O P T I O N S

   PROBLEM DIMENSIONALITY. . . . . . . . . . . . .3-D
   DEGREES OF FREEDOM. . . . . . UX   UY   UZ   PRES
   ANALYSIS TYPE . . . . . . . . . . . . . . . . .HARMONIC
      SOLUTION METHOD. . . . . . . . . . . . . . .AUTO
   COMPLEX DISPLACEMENT PRINT OPTION . . . . . . .REAL AND IMAGINARY
   GLOBALLY ASSEMBLED MATRIX . . . . . . . . . . .SYMMETRIC

 *** WARNING ***                         CP =     169.390   TIME= 10:03:42
 No constraints have been defined using the D command.

 *** WARNING ***                         CP =     169.391   TIME= 10:03:42
 Load amplitudes will be ramped over the frequency range.  Use the KBC,1
 command to use a step change.

 *** NOTE ***                            CP =     169.391   TIME= 10:03:42
 The step data was checked and warning messages were found.
  Please review output or errors file ( /jobs/file0.err ) for these
 warning messages.

 *** NOTE ***                            CP =     169.391   TIME= 10:03:42
 The Solution Control Option is only valid for single field structural,
 single field thermal, single field diffusion, coupled
 thermal-diffusion analyses and coupled-field analyses with structural
 degrees of freedom.  The SOLCONTROL,ON command (if present) has been
 de-activated.

                      L O A D   S T E P   O P T I O N S

   LOAD STEP NUMBER. . . . . . . . . . . . . . . .     1
   FREQUENCY RANGE . . . . . . . . . . . . . . . .  200.00     TO   1000.0
   NUMBER OF SUBSTEPS. . . . . . . . . . . . . . .    40
   STEP CHANGE BOUNDARY CONDITIONS . . . . . . . .   YES
   PRINT OUTPUT CONTROLS . . . . . . . . . . . . .NO PRINTOUT
   DATABASE OUTPUT CONTROLS
      ITEM     FREQUENCY   COMPONENT
       ALL       NONE
      NSOL        ALL
      FGRA        ALL
      MISC        ALL

   AUTO SELECTION OF VT FOR FREQUENCY SWEEP. . . .YES

 *** WARNING ***                         CP =     169.455   TIME= 10:03:42
 No constraints have been defined using the D command.

 *** WARNING ***                         CP =     169.455   TIME= 10:03:42
 Load amplitudes will be ramped over the frequency range.  Use the KBC,1
 command to use a step change.



            **** CENTER OF MASS, MASS, AND MASS MOMENTS OF INERTIA ****

  CALCULATIONS ASSUME ELEMENT MASS AT ELEMENT CENTROID

  TOTAL MASS =   3585.5

                           MOM. OF INERTIA         MOM. OF INERTIA
  CENTER OF MASS            ABOUT ORIGIN        ABOUT CENTER OF MASS

  XC = -0.40695E-03      IXX =    1531.          IXX =    1531.
  YC =  0.48812E-04      IYY =    1535.          IYY =    1535.
  ZC = -0.30309E-04      IZZ =    1528.          IZZ =    1528.
                         IXY =  -0.3614          IXY =  -0.3615
                         IYZ =   0.4602          IYZ =   0.4602
                         IZX =   0.1969          IZX =   0.1970


  *** MASS SUMMARY BY ELEMENT TYPE ***

  TYPE      MASS
     1   3585.52

 Range of element maximum matrix coefficients in global coordinates
 Maximum = 0.229393189 at element 1092.
 Minimum = 4.10733557E-02 at element 1152.

   *** ELEMENT MATRIX FORMULATION TIMES
     TYPE    NUMBER   ENAME      TOTAL CP  AVE CP

        1      1566  FLUID30       0.172   0.000110
 Time at end of element matrix formulation CP = 169.639999.






   *** ELEMENT RESULT CALCULATION TIMES
     TYPE    NUMBER   ENAME      TOTAL CP  AVE CP

        1      1566  FLUID30       0.052   0.000033

   *** NODAL LOAD CALCULATION TIMES
     TYPE    NUMBER   ENAME      TOTAL CP  AVE CP

        1      1566  FLUID30       0.009   0.000006


















 *** LOAD STEP     1   SUBSTEP     1  COMPLETED.  FREQUENCY=   220.000
 *** LOAD STEP     1   SUBSTEP     2  COMPLETED.  FREQUENCY=   240.000
 *** LOAD STEP     1   SUBSTEP     3  COMPLETED.  FREQUENCY=   260.000
 *** LOAD STEP     1   SUBSTEP     4  COMPLETED.  FREQUENCY=   280.000
 *** LOAD STEP     1   SUBSTEP     5  COMPLETED.  FREQUENCY=   300.000
 *** LOAD STEP     1   SUBSTEP     6  COMPLETED.  FREQUENCY=   320.000
 *** LOAD STEP     1   SUBSTEP     7  COMPLETED.  FREQUENCY=   340.000
 *** LOAD STEP     1   SUBSTEP     8  COMPLETED.  FREQUENCY=   360.000
 *** LOAD STEP     1   SUBSTEP     9  COMPLETED.  FREQUENCY=   380.000
 *** LOAD STEP     1   SUBSTEP    10  COMPLETED.  FREQUENCY=   400.000
 *** LOAD STEP     1   SUBSTEP    11  COMPLETED.  FREQUENCY=   420.000
 *** LOAD STEP     1   SUBSTEP    12  COMPLETED.  FREQUENCY=   440.000
 *** LOAD STEP     1   SUBSTEP    13  COMPLETED.  FREQUENCY=   460.000
 *** LOAD STEP     1   SUBSTEP    14  COMPLETED.  FREQUENCY=   480.000
 *** LOAD STEP     1   SUBSTEP    15  COMPLETED.  FREQUENCY=   500.000
 *** LOAD STEP     1   SUBSTEP    16  COMPLETED.  FREQUENCY=   520.000
 *** LOAD STEP     1   SUBSTEP    17  COMPLETED.  FREQUENCY=   540.000
 *** LOAD STEP     1   SUBSTEP    18  COMPLETED.  FREQUENCY=   560.000
 *** LOAD STEP     1   SUBSTEP    19  COMPLETED.  FREQUENCY=   580.000
 *** LOAD STEP     1   SUBSTEP    20  COMPLETED.  FREQUENCY=   600.000
 *** LOAD STEP     1   SUBSTEP    21  COMPLETED.  FREQUENCY=   620.000
 *** LOAD STEP     1   SUBSTEP    22  COMPLETED.  FREQUENCY=   640.000
 *** LOAD STEP     1   SUBSTEP    23  COMPLETED.  FREQUENCY=   660.000
 *** LOAD STEP     1   SUBSTEP    24  COMPLETED.  FREQUENCY=   680.000
 *** LOAD STEP     1   SUBSTEP    25  COMPLETED.  FREQUENCY=   700.000
 *** LOAD STEP     1   SUBSTEP    26  COMPLETED.  FREQUENCY=   720.000
 *** LOAD STEP     1   SUBSTEP    27  COMPLETED.  FREQUENCY=   740.000
 *** LOAD STEP     1   SUBSTEP    28  COMPLETED.  FREQUENCY=   760.000
 *** LOAD STEP     1   SUBSTEP    29  COMPLETED.  FREQUENCY=   780.000
 *** LOAD STEP     1   SUBSTEP    30  COMPLETED.  FREQUENCY=   800.000
 *** LOAD STEP     1   SUBSTEP    31  COMPLETED.  FREQUENCY=   820.000
 *** LOAD STEP     1   SUBSTEP    32  COMPLETED.  FREQUENCY=   840.000
 *** LOAD STEP     1   SUBSTEP    33  COMPLETED.  FREQUENCY=   860.000
 *** LOAD STEP     1   SUBSTEP    34  COMPLETED.  FREQUENCY=   880.000
 *** LOAD STEP     1   SUBSTEP    35  COMPLETED.  FREQUENCY=   900.000
 *** LOAD STEP     1   SUBSTEP    36  COMPLETED.  FREQUENCY=   920.000
 *** LOAD STEP     1   SUBSTEP    37  COMPLETED.  FREQUENCY=   940.000
 *** LOAD STEP     1   SUBSTEP    38  COMPLETED.  FREQUENCY=   960.000
 *** LOAD STEP     1   SUBSTEP    39  COMPLETED.  FREQUENCY=   980.000
 *** LOAD STEP     1   SUBSTEP    40  COMPLETED.  FREQUENCY=   1000.00


 *** MAPDL BINARY FILE STATISTICS
  BUFFER SIZE USED= 16384
       20.125 MB WRITTEN ON ELEMENT MATRIX FILE: file0.emat
        1.188 MB WRITTEN ON ELEMENT SAVED DATA FILE: file0.esav
        0.312 MB WRITTEN ON ASSEMBLED MATRIX FILE: file0.full
       17.250 MB WRITTEN ON RESULTS FILE: file0.rst

Post1: Time step results#

Listing the results

mapdl.post1()
print(mapdl.set("LIST"))
*****  INDEX OF DATA SETS ON RESULTS FILE  *****

     SET   TIME/FREQ    LOAD STEP   SUBSTEP  CUMULATIVE
       1  220.00000             1         1         1
       2  220.00000             1         1         1
       3  240.00000             1         2         2
       4  240.00000             1         2         2
       5  260.00000             1         3         3
       6  260.00000             1         3         3
       7  280.00000             1         4         4
       8  280.00000             1         4         4
       9  300.00000             1         5         5
      10  300.00000             1         5         5
      11  320.00000             1         6         6
      12  320.00000             1         6         6
      13  340.00000             1         7         7
      14  340.00000             1         7         7
      15  360.00000             1         8         8
      16  360.00000             1         8         8
      17  380.00000             1         9         9
      18  380.00000             1         9         9
      19  400.00000             1        10        10
      20  400.00000             1        10        10
      21  420.00000             1        11        11
      22  420.00000             1        11        11
      23  440.00000             1        12        12
      24  440.00000             1        12        12
      25  460.00000             1        13        13
      26  460.00000             1        13        13
      27  480.00000             1        14        14
      28  480.00000             1        14        14
      29  500.00000             1        15        15
      30  500.00000             1        15        15
      31  520.00000             1        16        16
      32  520.00000             1        16        16
      33  540.00000             1        17        17
      34  540.00000             1        17        17
      35  560.00000             1        18        18
      36  560.00000             1        18        18
      37  580.00000             1        19        19
      38  580.00000             1        19        19
      39  600.00000             1        20        20
      40  600.00000             1        20        20
      41  620.00000             1        21        21
      42  620.00000             1        21        21
      43  640.00000             1        22        22
      44  640.00000             1        22        22
      45  660.00000             1        23        23
      46  660.00000             1        23        23
      47  680.00000             1        24        24
      48  680.00000             1        24        24
      49  700.00000             1        25        25
      50  700.00000             1        25        25
      51  720.00000             1        26        26
      52  720.00000             1        26        26
      53  740.00000             1        27        27
      54  740.00000             1        27        27
      55  760.00000             1        28        28
      56  760.00000             1        28        28
      57  780.00000             1        29        29
      58  780.00000             1        29        29
      59  800.00000             1        30        30
      60  800.00000             1        30        30
      61  820.00000             1        31        31
      62  820.00000             1        31        31
      63  840.00000             1        32        32
      64  840.00000             1        32        32
      65  860.00000             1        33        33
      66  860.00000             1        33        33
      67  880.00000             1        34        34
      68  880.00000             1        34        34
      69  900.00000             1        35        35
      70  900.00000             1        35        35
      71  920.00000             1        36        36
      72  920.00000             1        36        36
      73  940.00000             1        37        37
      74  940.00000             1        37        37
      75  960.00000             1        38        38
      76  960.00000             1        38        38
      77  980.00000             1        39        39
      78  980.00000             1        39        39
      79  1000.0000             1        40        40
      80  1000.0000             1        40        40

Post26: Time dependent results#

Getting results for specific nodes

mapdl.post26()
freqs = mapdl.post_processing.time_values[::2]
node = 276

# Getting results
node_pressure = mapdl.nsol(3, node, "spl")
node_sound_pressure_level = mapdl.nsol(4, node, "SPLA")

# Plotting
fig, ax = plt.subplots(1, 2)

ax[0].plot(freqs, node_pressure)
ax[0].set_xlabel("Frequencies (Hz)")
ax[0].set_ylabel("Sound pressure level (Pa)")

ax[1].plot(freqs, node_sound_pressure_level, label="Nodal Sound Pressure")
ax[1].set_xlabel("Frequencies (Hz)")
ax[1].set_ylabel("A-weighted sound\npressure level (dBA)")

fig.suptitle(f"Node {node} Results")
fig.tight_layout()
fig.show()
Node 276 Results

Stop MAPDL

mapdl.exit()
/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/ansys/mapdl/core/launcher.py:818: UserWarning: The environment variable 'PYMAPDL_START_INSTANCE' is set, hence the argument 'start_instance' is overwritten.
  warnings.warn(

Total running time of the script: (0 minutes 10.053 seconds)