.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_5_postprocforcefft.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_5_postprocforcefft.py: Time series of postProcessing coefficient force =============================================== This example reads and plots one postProcessing coefficient force and compute and plot the fft of the lift coefficient force .. GENERATED FROM PYTHON SOURCE LINES 10-16 Read the postProcessing files ----------------------------- .. note:: In this example it reads one postProcessing file for the statistically steady state of the flow around a rectangular cylinder. .. GENERATED FROM PYTHON SOURCE LINES 16-63 .. code-block:: Python from fluidfoam.readpostpro import readforce import numpy as np # ****************Selection of case, repository and parameters*************** # rep = '../output_samples/' case = 'ascii' time = '100' # Simulation start time for fft force_file_name = 'coefficient' # Variable on which fft is applied index_Cl = 2 # Lift force index_Cd = 1 # Drag force n0 = 0 # Start point for the fft nfft = 500 # Number of point for the fft calculdeltat = 0.01 # Delta t used in the calculation fftdeltat = 0.2 # Sampling Delta t for the fft, note that Tfft = nfft * fftdeltat =< Ttot = endTime - time timestart = 0 # Start time for sampling from time display_temp = True # *************************************************************************** # # reading Data force = readforce(rep + case, namepatch = 'forces', time_name = time, name = force_file_name) timevec = np.zeros(len(force)) varC = np.zeros((len(force),2)) for i in range(len(force)): timevec[i] = force[i,0] varC[i,0] = force[i,index_Cl] varC[i,1] = force[i,index_Cd] # Sampling i = 0 varCi = np.zeros((nfft,2)) vart = np.zeros(nfft) while i < nfft: for k in range(2): varCi[i,k] = varC[int(i*fftdeltat/calculdeltat+timestart/calculdeltat), k] vart[i] = timevec[int(i*fftdeltat/calculdeltat+timestart/calculdeltat)] i += 1 # fft calculation y1 = np.zeros((nfft,2),dtype = np.complex128) for k in range(2): # Division by nfft to correct the spectral amplitude y1[:, k] = np.fft.fft(varCi[n0:n0+nfft,k] - np.mean(varCi[n0:n0+nfft,k]))/nfft .. GENERATED FROM PYTHON SOURCE LINES 64-67 Now plots the lift and drag coefficient forces --------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 67-96 .. code-block:: Python import matplotlib.pyplot as plt plt.rcParams.update({'font.size': 20}) # Temporal plot section colorList = ['r', 'b'] labelList = ['Lift', 'Drag'] if display_temp: for k in range(2): plt.plot(vart[n0:n0+nfft], varCi[n0:n0+nfft,k], color = colorList[k], label = labelList[k]) plt.legend(loc='best') plt.xlabel('time (s)') plt.ylabel('Coefficient (-)') plt.show() # frequency plot section f = np.arange(nfft)*1/(fftdeltat*nfft) plt.figure(figsize=(16, 8)) for k in range(2): plt.semilogy(f[n0:n0+nfft], abs(y1[n0:n0+nfft,k]), color = colorList[k], label = labelList[k]) plt.axis([0.0, 1/(2*fftdeltat), 1e-5, 2*np.max(abs(y1[n0:n0+nfft]))]) plt.grid() plt.legend(loc='upper right') plt.xlabel(r'f (Hz)') plt.ylabel(r'Amplitude ($m^2/s^2$)') plt.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_plot_5_postprocforcefft_001.png :alt: plot 5 postprocforcefft :srcset: /auto_examples/images/sphx_glr_plot_5_postprocforcefft_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_5_postprocforcefft_002.png :alt: plot 5 postprocforcefft :srcset: /auto_examples/images/sphx_glr_plot_5_postprocforcefft_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.475 seconds) .. _sphx_glr_download_auto_examples_plot_5_postprocforcefft.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_5_postprocforcefft.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_5_postprocforcefft.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_5_postprocforcefft.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_