查看: 104|回复: 0|关注: 0

[未答复] MATLAB-HFSS-API报错HFSS Execution returned an error status

[复制链接]

入门

136 麦片

财富积分


50500


12

主题

85

帖子

7

最佳答案
发表于 2019-9-11 17:27:18 | 显示全部楼层 |阅读模式
本帖最后由 木木木林 于 2019-9-12 14:51 编辑

使用HFSS-MATLAB-API报错:警告: HFSS Execution returned an error status !
> In hfssExecuteScript at 112
  In pixel1 at 108
Solution Completed. Plotting Results for this Iteration ...
未定义函数或变量 'f'。

出错 pixel1 (line 115)
plot(f/1e9, 20*log10(abs(S)), pltCols(mod(iIters, nCols) + 1));
请问有知道如何解决的吗?


%
% ---------------------------------------------
%
clc;clear all;close all;
%
% --------------------------------------------------------
addpath('E:\project\MATLAB\hfssmat\hfssapi\hfssapi\3dmodeler\');
addpath('E:\project\MATLAB\hfssmat\hfssapi\hfssapi\general\');
addpath('E:\project\MATLAB\hfssmat\hfssapi\hfssapi\analysis\');
addpath('E:\project\MATLAB\hfssmat\hfssapi\hfssapi\boundary\');
% 天线参数
% -------
fC=1e9;         % 感兴趣的频率
Wv=3e8/fC;      % 波长
L = Wv/2;         % Antenna Length.
Lgnd=40e-3;     % 地面的长度
Wgnd=65e-3;     % 地面的宽度
Rpixel=3e-3;    % 像素的边长
L1=Rpixel;      % 像素之间连线的长度
W1=Rpixel/4;    % 像素之间连线的宽度
h1=0.035e-3;
hsub=0.508e-3;
% 仿真参数
% -------
fLow=0.5e9;     
fHigh=2.5e9;
nPoints=201;
% 空气盒子参数
% -----------
AirX=Wv/2+Lgnd;
AirY=Wv/2+Wgnd+Rpixel*2+L1*2;
AirZ=Wv/2+hsub+h1;
% 指定文件的路径
% -------------
tmpPath = 'E:\project\MATLAB\pixel1';
tmpPrjFile = [tmpPath '\tmppixel.hfss'];
tmpScriptFile = [tmpPath '\pixel_example.vbs'];
% HFSS的版本和路径
% ---------------
hfssExePath = 'D:\work\HFSS\HFSS13.0\hfss.exe';
% 曲线颜色设置
% -----------
pltCols = ['b', 'r', 'k', 'g', 'm', 'c', 'y'];
nCols = length(pltCols);
% 优化停止状态。
% ------------
maxIters = 1;        % max # of iterations.
Accuracy = 0.01;    % accuracy required (1%).
hasConverged = false;
disp(sprintf('The Initial Length is %.2f meter ...', L));

for iIters = 1:maxIters
% 创建数据文件
% -----------
tmp = num2str(iIters);
tmpDataFile = [tmpPath '\temData' tmp '.m'];
tmpFid = fopen(tmpDataFile,'wt');
fclose(tmpFid);  
% ------------
disp(sprintf('Running iteration #%d ...', iIters));
disp('Creating the Script File ...');
% 创建临时的HFSS脚本文件。
% ----------------------
fid = fopen(tmpScriptFile, 'wt');
% 创建HFSS工程。
% ------------
hfssNewProject(fid);
hfssInsertDesign(fid, 'pixelconfi');
% 建模
% ---

% hfssBox(fid,'pixel',[0,(Wgnd+L1+Rpixel/2)-(Wgnd+L1*2+Rpixel*2)/2,...
%     h1/2],[Rpixel,Rpixel,h1],'meter');
% hfssBox(fid,'gnd',[0,Wgnd/2-(Wgnd+L1*2+Rpixel*2)/2,h1/2],...
%     [Wgnd,Lgnd,h1],'meter');
% hfssBox(fid,'sub',[0,0,-hsub/2],[Lgnd+Rpixel*2,Wgnd+Rpixel*4+L1*2,...
%     hsub],'meter');
%     
% hfssAssignMaterial(fid, 'pixel', 'cooper');
% hfssAssignMaterial(fid, 'gnd', 'cooper');
% hfssAssignMaterial(fid, 'sub', 'Rogers RO4003(tm)');

% hfssDuplicateAlongLine(fid,'pixel',[-L1-Rpixel,L1+Rpixel,0],1,'meter');
% hfssDuplicateAlongLine(fid,'pixel',[0,L1+Rpixel,0],1,'meter');
% hfssDuplicateAlongLine(fid,'pixel',[L1+Rpixel,L1+Rpixel,0],1,'meter');
% 设置源
hfssRectangle(fid,'source','Z',[-W1/2,Wgnd-(Wgnd+L1*2+Rpixel*2)/2,h1/2],...
    W1,L1,'meter');
hfssAssignLumpedPort(fid, 'LumpedPort', 'source',[0,Wgnd-(Wgnd+L1*2+Rpixel*2)/2,...
    h1/2],[0,Wgnd-(Wgnd+L1*2+Rpixel*2)/2+L1,h1/2],'meter');
% ------
hfssBox(fid,'airbox',[0,0,0],[AirX,AirY,AirZ],'meter');
hfssAssignRadiation(fid, 'ABC', 'airbox');

% 设置解决方案
hfssInsertSolution(fid, 'Setup1GHz', fC/1e9);
hfssInterpolatingSweep(fid, 'Sweep0.5to2.5GHz', 'Setup1GHz', ...
    fLow/1e9, fHigh/1e9, nPoints);
% 将项目保存到临时文件并解决它。
hfssSolveSetup(fid, 'Setup1GHz');
hfssSaveProject(fid, tmpPrjFile, true);
% 将网络数据导出为m文件。
hfssExportNetworkData(fid, tmpDataFile, 'Setup1GHz', 'Sweep0.5to2.5GHz');
% 关闭HFSS脚本文件。
fclose(fid);
% 通过启动HFSS执行脚本
disp('Solving using HFSS ..');
hfssExecuteScript(hfssExePath, tmpScriptFile);
% 通过运行导出的matlab文件加载数据。
run(tmpDataFile);
% 绘图
disp('Solution Completed. Plotting Results for this Iteration ...');
figure(1);
hold on;
plot(f/1e9, 20*log10(abs(S)), pltCols(mod(iIters, nCols) + 1));
hold on;
xlabel('Frequency (MHz) ->');
ylabel('S_{11} (dB) ->');
axis([fLow/1e9, fHigh/1e9, -20, 0]);
% ------------------------------------
[Smin, iMin] = min(S);
fActual = f(iMin);
disp(sprintf('Simulated Resonance Frequency: %.2f GHz', fActual/1e9));

% Check if the required accuracy is met.
if (abs((fC - fActual)/fC) < Accuracy)
    disp('Required Accuracy is met !!');
    disp(sprintf('Optimized Antenna Length is %.2f meter.', L));
    hasConverged = true;
    break;
end;
% Adjust the antenna length in accordance with the discrepancy between
% the estimated and desired resonance frequency.
L = L*fActual/fC;
% Loop all over again ...
disp('Required accuracy not yet met ...');
disp(sprintf('The new estimate for the dipole length is %.2f meter', L));
system(sprintf('del %s',tmpDataFile));
% ----------------------
% % Loop all over again ...
% disp('Required accuracy not yet met ...');
% disp(sprintf('The new estimate for the dipole length is %.2f meter', L));
% system(sprintf('del %s',tmpDataFile));
end
if (~hasConverged)
    disp('Max Iterations exceeded. Optimization did NOT converge ...');
end;

% remove all the added paths.
rmpath('E:\project\MATLAB\hfssmat\hfssapi\hfssapi\3dmodeler\');
rmpath('E:\project\MATLAB\hfssmat\hfssapi\hfssapi\general\');
rmpath('E:\project\MATLAB\hfssmat\hfssapi\hfssapi\analysis\');
rmpath('E:\project\MATLAB\hfssmat\hfssapi\hfssapi\boundary\');


您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

快速回复 返回顶部 返回列表