[S8477] Script for calculating and graphing induced voltage (dφ/dt)

 

I want to calculate the induced voltage (dφ/dt) using a script and display a graph.

The following is an example in Python script.
# -*- coding: utf-8 -*-

import csv

#Output destination path for calculated induced voltage results

CSVpath = u"D:/WorkFolder/PythonTest/Vu noload.csv"

#Names of datasets and graphs to be created

Name = u"Vu noload"

#[Coil Flux-Linkage] Obtain result data object

CoilFlux = app.GetCurrentStudy().GetResultTable().GetData("FEMCoilFlux")

#Specify the column ID of the [Coil Flux-Linkage] data you want to refer to.

col_CoilFlux = 0

app = designer.GetApplication()

#Get the [Step Interval Definition Type] setting for [Step Control].

flg = app.GetCurrentStudy().GetStep().GetFlagAsString(u"StepType")

#If [Step Interval Definition Type] is “Regular Intervals,” perform the induced voltage calculation process. If not, perform error processing.

if flg == u"Uniform":

   #Get the number of calculation steps

   steps = app.GetCurrentStudy().GetStep().GetValue("Step")

   #Get [Divisions] from [Step Control]

   stepdiv = app.GetCurrentStudy().GetStep().GetValue("StepDivision")

   #Get the [End Time] of [Step Control]

   stepend = app.GetCurrentStudy().GetStep().GetValueWithUnit("EndPoint",u"s")

   #Calculate time intervals

   dt = stepend / stepdiv

   #Calculate the induced voltage for each step.

   for i in range(1,int(steps+1)):

       #Since dt=0 in the first step, substitute Ind=0 for the induced voltage.

       if i == 1:

           Ind = 0

       #From the second step onwards, the induced voltage Ind is calculated based on the chained magnetic flux results

       else:

           Fai1 = CoilFlux.GetValue(i-2, col_CoilFlux) #Obtain the Coil Flux-Linkage results for the (i-1)-th step.

           Fai2 = CoilFlux.GetValue(i-1, col_CoilFlux) #Obtain the Coil Flux-Linkage results for the i-th step.

           Ind = (Fai2 - Fai1) / dt #Calculate induced voltage

       now_time = dt * (i-1) #Calculate the time of the i-th step

       #Open CSV file in append mode

       with open(CSVpath,mode='a', newline='') as f:

           writer = csv.writer(f)

           #Write the calculation results of step i to csv.

           writer.writerow([now_time, Ind])

   #Create a dataset from the output CSV file

   dataset = app.GetDataManager().CreateFromFile(CSVpath,Name, u"Time, s", u"InducedVoltage, V")

   #Create graphs from the created dataset

   app.GetDataManager().CreateGraphModel(dataset, Name)

   #Display the created graph

   app.GetDataManager().Show(Name)

else:

   print(u"The induced voltage cannot be calculated because the [Step Control] settings are not set in [End Time] and [Divisions].")
*Note 

・In order to calculate the induced voltage, [Step Control] must specify [End Time] and [Divisions].

・The following checks must be performed before executing this sample.

  ・The CSV file specified in "CSVpath" does not exist.

  ・The dataset and graph specified in "Name" do not exist.

How to use script file

Use the JMAG Script Library after reading and agreeing to the following terms of use.