更新SourceData
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
function probe_ansys_official_example
|
||||
% Run the Ansys-installed Simulink coupling example as a control test.
|
||||
|
||||
projectDir = fileparts(mfilename('fullpath'));
|
||||
artifactDir = fullfile(projectDir, 'analysis_artifacts');
|
||||
cacheDir = fullfile(artifactDir, 'ansys_example_cache');
|
||||
codeDir = fullfile(artifactDir, 'ansys_example_codegen');
|
||||
if ~isfolder(artifactDir)
|
||||
mkdir(artifactDir);
|
||||
end
|
||||
if ~isfolder(cacheDir)
|
||||
mkdir(cacheDir);
|
||||
end
|
||||
if ~isfolder(codeDir)
|
||||
mkdir(codeDir);
|
||||
end
|
||||
|
||||
ansysEmRoot = getenv('ANSYSEM_ROOT252');
|
||||
ansoftMatlabDir = fullfile(ansysEmRoot, 'cpl', 'matlab', 'r2024a');
|
||||
exampleDir = fullfile(ansysEmRoot, 'Examples', 'Twin Builder', ...
|
||||
'Components', 'Interfaces', 'Simulink');
|
||||
modelFile = fullfile(exampleDir, 'synchronous_drive.mdl');
|
||||
projectFile = fullfile(exampleDir, 'simulink.aedt');
|
||||
|
||||
assert(isfile(modelFile), 'Official example model not found: %s', modelFile);
|
||||
assert(isfile(projectFile), 'Official example project not found: %s', projectFile);
|
||||
assert(isfolder(ansoftMatlabDir), 'Ansys MATLAB interface not found: %s', ansoftMatlabDir);
|
||||
|
||||
addpath(ansoftMatlabDir, '-begin');
|
||||
addpath(exampleDir, '-begin');
|
||||
rehash;
|
||||
Simulink.fileGenControl('set', 'CacheFolder', cacheDir, ...
|
||||
'CodeGenFolder', codeDir, 'createDir', true);
|
||||
|
||||
fprintf('CONTROL_MODEL\t%s\n', modelFile);
|
||||
fprintf('CONTROL_PROJECT\t%s\n', projectFile);
|
||||
fprintf('ANSOFT_SFUNCTION\t%s\n', which('AnsoftSFunction'));
|
||||
|
||||
in = Simulink.SimulationInput('synchronous_drive');
|
||||
in = in.setModelParameter('SimulationMode', 'normal');
|
||||
try
|
||||
out = sim(in);
|
||||
catch ME
|
||||
fprintf('CONTROL_STATUS\tFAIL\n');
|
||||
fprintf('ERROR_ID\t%s\n', ME.identifier);
|
||||
couplingVars = {'Simulink_Coupling_Error', ...
|
||||
'Simulink_Coupling_InstanceName', 'DSDEActiveDesignName'};
|
||||
for k = 1:numel(couplingVars)
|
||||
varName = couplingVars{k};
|
||||
if evalin('base', sprintf('exist(''%s'', ''var'')', varName))
|
||||
value = evalin('base', varName);
|
||||
fprintf('BASE_VAR\t%s\t%s\n', varName, string(value));
|
||||
end
|
||||
end
|
||||
errorFile = fullfile(artifactDir, 'ansys_official_example_error.txt');
|
||||
fid = fopen(errorFile, 'w', 'n', 'UTF-8');
|
||||
fprintf(fid, '%s\n', getReport(ME, 'extended', 'hyperlinks', 'off'));
|
||||
fclose(fid);
|
||||
rethrow(ME);
|
||||
end
|
||||
|
||||
fprintf('CONTROL_STATUS\tPASS\n');
|
||||
fprintf('CONTROL_OUTPUTS\t%s\n', strjoin(who(out), ', '));
|
||||
end
|
||||
Reference in New Issue
Block a user