Tuesday, September 04, 2012

Monitor ansys solves using matlab

prep/post of Workbench has improved in helping you monitor solves with better charting. I wrote a matlab script to monitor solves when workbench was still rudimentary in this functionality that I still use because I dont want to tie up a preppost license just to mionitor a job. It is pasted below and perhaps can be of use to other ansys users too. It is setup to poll solve.out every 15 sec -- you can change it to any other convenient interval on the pause instruction.

-------------


clear; clc; clf;
startTime = tic;

solvePath = 'C:\fea\pr1\_ProjectScratch\ScrF95A\'; % path  to folder where solve.out is being written.
jobName = 'blah'; % title you want to display on your monitor window.




inFile = fullfile(solvePath, 'solve.out');
dispHist = 200;
fileNum = rand(1,1);
% !erase monitorFile*.txt
while true
    scratchFile = ['monitorFile' num2str(fileNum) '.txt'];
    copyfile (inFile, scratchFile);
 
 
    fileHandle = fopen(scratchFile);
    tLine = fgetl(fileHandle);
    forceConvergence = [];
    momentConvergence = [];
    dispConvergence = [];
    timeStep = [];
    getInitialTime = true;
    while ischar(tLine)
     
        if getInitialTime
            k1 = strfind(tLine, 'CURRENT JOBNAME=');
            k2 = strfind(tLine, 'CP=');
            if ~isempty(k1) && ~isempty(k2)
                b1 = sscanf(tLine, ' CURRENT JOBNAME=file%sCP=%*f')';
                if length(b1) == 3
                    timeStep = [timeStep; b1];
                end
                b1='';
                getInitialTime = false;
            end
         
        end
     
     
        k = strfind(tLine, 'FORCE CONVERGENCE VALUE');
        if ~isempty(k)
            b1 = sscanf(tLine, '%*s%*s%*s%*s %f %*s %f')';
            if length(b1) == 2
                forceConvergence = [forceConvergence; b1];
            end
            b1='';
        end
        k = strfind(tLine, 'MOMENT CONVERGENCE VALUE');
        if ~isempty(k)
            b1 = sscanf(tLine, '%*s%*s%*s%*s %f %*s %f')';
            if length(b1) == 2
                momentConvergence = [momentConvergence; b1];
            end
            b1='';
        end
     
     
        k = strfind(tLine, 'DISP CONVERGENCE VALUE');
        if ~isempty(k)
            b1 = sscanf(tLine, '%*s%*s%*s%*s %f %*s %f')';
            if length(b1) == 2
                dispConvergence = [dispConvergence; b1];
            end
            b1='';
        end
        k1 = strfind(tLine, 'TIME =');
        k2 = strfind(tLine, 'TIME INC =');
        if ~isempty(k1) && ~isempty(k2)
            b1 = sscanf(tLine, '%*s %*s %*s %f %*s %*s %*s %f')';
            if length(b1) == 2
                timeStep = [timeStep; b1];
            end
            b1='';
        end
        k = strfind(tLine, 'ANSYS RUN COMPLETED');
        if ~isempty(k)
            subplot(411), title(['AC / ', jobName, ', ', datestr(now) ', ET: ' num2str(round(toc(startTime)/60)) ' min']);
            msgbox(['Analysis Complete: ', jobName]);
            return;
        end
     
        tLine = fgetl(fileHandle);
    end
 
    fclose(fileHandle);
    subplot(411)
    semilogy(forceConvergence(:, 1), 'b'); grid on; hold on;
    semilogy(forceConvergence(:, 2), 'm');
    %     legend('ForceConvergence', 'Criterion', 'Location', 'Best');
    title([jobName ': ' datestr(now) '     ET: ' num2str(round(toc(startTime)/60))  ' min']);
    [numRows, numCols] = size(forceConvergence);
    if numRows > dispHist
        axis([numRows-dispHist  numRows min(min(forceConvergence)) max(max(forceConvergence))]);
    end
 
        if ~isempty(momentConvergence)
            subplot(412)
            semilogy(momentConvergence(:, 1), 'b'); grid on; hold on;
            semilogy(momentConvergence(:, 2), 'm');
    %         legend('MomentConvergence', 'Criterion');
    title('Moment Convergence');
            [numRows, numCols] = size(momentConvergence);
            if numRows > dispHist
                axis([numRows-dispHist numRows min(min(momentConvergence)) max(max(momentConvergence))]);
            end
        end
 
    if ~isempty(dispConvergence)
        subplot(413)
        semilogy(dispConvergence(:, 1), 'b'); grid on; hold on;
        semilogy(dispConvergence(:, 2), 'm');
        %        legend('dispConvergence', 'Criterion');
        title('Disp Convergence');
        [numRows, numCols] = size(dispConvergence);
        if numRows > dispHist
            axis([numRows-dispHist numRows min(min(dispConvergence)) max(max(dispConvergence))]);
        end
    end
 
 
    if ~isempty(timeStep())
        subplot(414)
        plot(timeStep(:, 1), timeStep(:, 2), 'b-*'); grid on; hold on;
        ylabel([num2str(max(timeStep(:, 1))), ': Time step [s]']);
        xlabel('Time [s]');
        axis([0 max(timeStep(:, 1)) 0 1.2*max(timeStep(:, 2))])
    end
 
 
    pause(15)
 
end

Labels: , , , , , , ,