Plugin WindLab ErgodicityCheckTool

From LabRPS Documentation
Jump to navigation Jump to search

Generic plugin icon. Create your personal icon with the same name of the plugin Ergodicity Check Tool Plugin

Description
This plugin assesses the ergodicity of the simulated wind velocities in terms of power spectral density.

Plugin version: 1.0
Last modified: 2024-04-15
LabRPS version: All
Author: Koffi Daniel
Author
Koffi Daniel
Download
None
Features
Ergodicity Check Tool
Plugin Version
1.0
Date last modified
2024-04-15
LabRPS Version(s)
All
Default shortcut
None
See also
None

Introduction

This plugin assesses the ergodicity of the simulated wind velocity by analyzing its power spectral density function. It calculates the power spectral density function of the simulated wind velocity and compares it with the power spectral density function derived from the target power spectral density function used to simulate the wind velocities.

Plugin WindLab ErgodicityCheckTool Screenshot 1.png.png

Plugin WindLab ErgodicityCheckTool Screenshot 2.png.png

Ergodicity Check Tool

This is the only RPS feature that the plugin implements. It belongs to the table tool group. This feature uses the simulated wind velocity to compute the the power spectral density function. Therefore, you need to make sure you simulate random wind velocity first. You can also import the wind velocity from file. Note that if you use the mouse (GUI mode) to run this feature, you have to make sure the active window is the window containing the wind velocity data for which you want to compute the temporal correlation.

Properties

  • DatafftPointsNumber: This number of DFT points used during the computation.
  • DataWindowLength: The length of the window used to divide the two wind processes into segments and perform windowing.
  • DataOverLap: The number of overlapped samples, specified as a positive integer.
  • DataWindowType: This is the type of windowing.

Scripting

import LabRPS
import WindLabObjects
import WindLabGui
import WindLab
import GeneralToolsGui

# Before you run this macro, simulation must be run and there  must be a table containing the simulated wind velocities.
def checkResult():
    # Install the ergodicity checking tool
    installResuslt = WindLab.installPlugin("ErgodicityCheckToolPlugin")
    if not installResuslt:
        LabRPS.Console.PrintError("The installation of the ErgodicityCheckToolPlugin has failed.\n")
        return None

    # Get the active simulation which as this time has been run already.   
    sim = WindLabGui.getActiveSimulation()

    # get the simulation data as list assuming that a wind simulation is run and 
    # the result is shown in an AlphaPlot table called "table". Please, edit this table name
    # according to the name of the table where your simulated data are stored.
    velocities = GeneralToolsGui.GeneralToolsPyTool.getTableByName("table")

    # create new table tool
    psdErgo = WindLabObjects.makeFeature("psdErgo", sim.Name, "Ergodicity Check Tool", "Table Tool")
    
    # check if the created randomness provider feature
    if not psdErgo:
        LabRPS.Console.PrintError("The creation of the table tool was not successuful.\n")
        return None
    psdErgo.WindowType = "Hamming window"
    sim.setActiveFeature(psdErgo)        
    psdErgoRest = sim.tableToolCompute(velocities)

    # if we are in Gui mode, show the plot
    if LabRPS.GuiUp:
       
        import numpy
        import matplotlib.pyplot as plt

        # convert the list to numpy array
        array = numpy.asarray(psdErgoRest)

        locationJ = sim.LocationIndexJ + 1
        locationK = sim.LocationIndexK + 1
        str1 = "{:d}".format(locationJ)
        str2 = " and {:d}".format(locationK)
        str = "Cross Spectrum between Locations " + str1 + str2
        fig, ax = plt.subplots()
        ax.set_title(str)
        f = sim.getSimulationData().numberOfFrequency - 1 
        fftl = psdErgo.fftPointsNumber//2
        ax.plot(array[0:f,0], array[0:f,1], color='red')
        ax.plot(array[0:fftl,2], array[0:fftl,3], linestyle='dashed')
        ax.set_xlabel('Frequency (rad/s)')
        ax.set_ylabel('Power Spectrum Density ($m^2$/s)')
        # ax.grid(True)
        ax.legend(["Target", "Simulated"], loc="upper right", frameon=False)
        ax.set_xscale("log")
        ax.set_yscale("log")
        fig.tight_layout()
        plt.show()

checkResult()