TAGGED: ansys-maxwell, design-optimization, matlab, optislang
-
-
July 2, 2024 at 5:56 pmWenqin SongSubscriber
Hello all,
I am doing an electric machine optimization using both Maxwell and Optislang, I have already set up Maxwell parametric solver in Optislang. But I need to add a Matlab script into the workflow so that Matlab could calculate an output variable for me that Maxwell itself could not achieve. I am trying to let Matlab run fft from the output csv file directly from Maxwell. This is how the workflow looks like:
Basically I want this Matlab node to read the csv file from the simulation result on Maxwell. The quantity I am trying to calculate in Matlab is the Total Harmonic Distortion (THD) of the stator voltage waveform obtained from Fourier analysis, and register it as a reponse used for further work (sensitivity analysis) . Here is the Matlab code:
I have a local function called "spectrum_THD" defined in the same script, and this code is able to run in Matlab with the csv file(phase_B_stator_voltage) ready in the Matlab directory. However, when I add the Matlab solver wizard into the workflow, the THD expression is not written in full by Optislang and it is in string variable type, so I could not register THD as a response in the integration panel.
I am guessing it has something to do with Matlab reading the csv files from Maxwell in Optislang environment. Another thing is it might has something to do with outputting Maxwell reponses to Matlab in csv format. I haven't figure out how exactly Matlab and Maxwell communicate with each other in Optislang. What I can do to fix this issue?
-
July 31, 2024 at 8:10 amVeit BayerAnsys Employee
Dear Wenqin Song,
when you setup the MATLAB node in optiSLang, it first reads and tries to parse the script. But it cannot resolve dependencies, e.g.
a=1
b=a
results in b as STRING “a” because a is unknown.Under the script there is a pulldown “Detect assignments”. Change this to "Test run". The MATLAB script is executed once, then in the list below the text you’ll find all variables with correct type and initial value.
Important hint on initial values: you want your script to run outside optiSLang, too, so you assign values, like A=1. But if A is a parameter to be varied by optiSLang, any parameter variation will be overwritten by this assignment. To prevent this, we typically use the following code to “register” parameters:
% Check if MATLAB is called outside optiSLang
if ~exist('OSL_REGULAR_EXECUTION','var')
clear all;
close all;
OSL_REGULAR_EXECUTION = false;
end
% Inputs (define reference variables)
if OSL_REGULAR_EXECUTION == false
X1 = 1.0;
X2 = 1.0;
X3 = 1.0;
X4 = 1.0;
X5 = 1.0;
endPlease have close look at this tutorial and the corresponding script: Sensitivity Analysis of a Coupled Function in MATLAB (ansys.com)
Regards,
Veit
-
- You must be logged in to reply to this topic.
- Maxwell & Matlab integration with Optislang in electric generator optimization
- MotorCAD LAB Module for thermal envelop
- Matlab integration in Optislang
- URGENT what this error means and how to fix it
- How to adjust design variables to get response values based on MOP model?
- Multi-Objective Shape Optimisation of Tesla Valve
- Optslang – ERROR: Object not known
- Creating Fluent Web Apps using optiSLang 2021R2.mp4
- Using pyFluent with Workbench in an optimization case
- Results of Gradient-based Optimization
-
456
-
205
-
194
-
177
-
162
© 2024 Copyright ANSYS, Inc. All rights reserved.