Jump to content

Recommended Posts

Folks,

 

Is there a possibility to control FRIENDSHIP System software externally or link it to other inhouse software? I am planning to pilot it from Matlab (feed in some parameters, test some algorithms), read the results and link it to other inhosue software. Much appreciate your thoughts on this.

 

 

Cheers,

Sabah Alwan

Share this post


Link to post
Share on other sites

Hi Saban,

In general, CAESES-FFW does not provide a COM-interface or anything similar to interact with it from another program at runtime.

Matlab provides methodes to execute system calls (check here) so you might want to run CAESES-FFW with a script file as argument.

 

So you could, have Matlab generate such a script file (*.fsc). Inside the script, you can use the command interface of CAESES-FFW (i.e. openProject("path_to_project"), set values, export geometry or generate custom exports within features).

 

For a short introduction to the script files, start CAESES-FFW, open the "Global Commands" page in the Documentation Browser and look for the "source(FString)" command (e.g. Ctrl+F, type "source(F").

 

Cheers,

Stefan

Share this post


Link to post
Share on other sites

Hello Sabah,

I've already done it in the past.
Basically I run a configuration m-file that open the Framework in batch mode.
Then I use another file to control it using the send.keys commands (in Windows).

I will send you the files. Just ask me if you need.

Cheers,

Humberto

 

1st the configuration file

%% Configuration of the Matlab to run Friendship on Batch Mode

% Configure Matlab Classes
configuration

% Desactivate warning messages
warning('off')

% Import Power Shell Class
h = actxserver('WScript.Shell');

% Open Framework on batch
% dos('FrameworkBatch.bat&');
% pause(20)

global control
% Create the object to Control the FFramework
control = ControlFFramework();

% Open Project
h.AppActivate('C:\Windows\system32\cmd.exe');
command = ['openProject{(}{"}' control.ffFile '{"}{)}{enter}'];
h.SendKeys(command);

global design
design = PlaningShip_v11();
design.Bmax = 2*1.985;
design.Vk = 31;
design.CG = [0 1.406];
design.f = 0.578;
design.eps = 8;
design.Hs = 0.55;
design.Loa = 12.37;
design.Lpp = 12.37;
design.opCond = 'oper';
design.calcSlam = false;
design.Dp = 0.63;
design.P_D = 1.238;
design.EAR = 0.85;
design.Z = 4;
design.Np = 2;
design.propSeries = 'SeriesB';
design.useRaw = false;
design.etaR = 0.95;
design.cavCriteria = 'BackCav10';
design.Nwtb = 2;
design.waterCap = 500;
design.fuelCap = 1100;
design.nPas = 14;
design.useEngine = true;
design.engName = 'VolvoD6_435';

% Ap0 = 33;
% Dt0 = 0.457;
% intVol0 = 53.5;
% LCB0 = 0.4588;
% BxMaxDeck = 1.98;
% LOA = 12.37;

And now the Framework Controller

%------------------------------------------------------------------------
%                        ControlFFramework
%
%------------------------------------------------------------------------
% Makes the comunication between Matlab and the FRIENDSHIP-Framework.

classdef ControlFFramework
    
    %% Public properties
    properties
        
        % Variables vector
        % v(1) - alphaCenter
        % v(2) - Dstern
        % v(3) - Dbow
        % v(4) - xBase
        % v(5) - alphaChine
        % v(6) - BxLin
        % v(7) - Bxt
        % v(8) - CAp
        % v(9) - Dt
        % v(10) - ie
        % v(11) - xLin
        % v(12) - alphaBotF
        % v(13) - alphaBot0
        % v(14) - xPos
        % v(15) - deadxLin
        % v(16) - deadt
        % v(17) - deadLp
        % v(18) - H
        % v(19) - Lp
        % v(20) - sca0
        % v(21) - scaF
        varVec
        
    end
    
    %% Calculated Properties
    properties (SetAccess = private)
        
        FFParameters
        FFConstraints
        
        % FFramework file
        ffFile
    end
    
    %% Private porperties
    properties (SetAccess = private, GetAccess = public)
        % Frienship Server
        ffServer
        
        % Result file template
        resultTemplate
        constTemplate
        dummyFile
        varTemplate
        
        
        % Basys ship variables
        basysVarVec = [41 0.10 2.0106 9.1 11 3.339 3.118 0.905 0.457 40 4.664 25 0 7.5 15.55 11.54 45 0.875 11.44 0.9 0.9];
        
    end
    
    %% Constructor
    methods
        function obj = ControlFFramework(myVarVec)
            % Creates an ControlFFramework object
            % function obj = ControlFFramework(myVarVec)
            % - myVarVec: variables vector
            
            if nargin == 1
                obj.varVec = myVarVec;
            else
                
                obj.varVec = zeros(1,21);
            end
            
            obj.ffServer = actxserver('WScript.Shell');
            
            [name, patch] = uigetfile({'*.fdb'},'Select the FFramework file');
            obj.ffFile = [patch name];
            obj.varTemplate = [patch 'variables.txt'];
            
            aux = [patch regexprep(name,'.fdb','') '\manual_results\baseline'];
            
            obj.resultTemplate = [aux '\results.txt'];
            
            obj.constTemplate = [aux '\constraints.txt'];
            
            obj.dummyFile = [aux '\finished.txt'];
            
        end
    end
    
    %% Setters and Getters
    methods
        
        function obj = set.varVec(obj,myVarVec)
            
            test = size(myVarVec);
            if test(1) == 21 || test(2) == 21
                obj.varVec = myVarVec;
            else
                warning('Parameters:WrongRange','The size of varVec is not correct!')
            end
            
        end
        
    end
    
    %% Public Methods
    methods
        
        function result = sendVarVec(obj)
            % function result = obj.sendVarVec()
            % Export the variabkes to the FFramewor and force to project to
            % update
            
            % Delete template files
            delete(obj.resultTemplate)
            delete(obj.constTemplate)
            delete(obj.dummyFile)
            
            % export variables File
            saveVarVec(obj.varVec,obj.varTemplate);
                                  
            obj.ffServer.AppActivate('C:\Windows\system32\cmd.exe');
            
            obj.ffServer.SendKeys('|variables.run{(}{)}{enter}');
            obj.ffServer.SendKeys('|export.run{(}{)}{enter}');
            obj.ffServer.SendKeys('getCurrentVariant{(}{)}.reduce{(}{)}{enter}');
            
            result = 'completed';
        end
        
        function closeProject(obj)
            % function result = obj.sendVarVec()
            % Export the variabkes to the FFramewor and force to project to
            % update
            
            obj.ffServer.AppActivate('C:\Windows\system32\cmd.exe');
            
            obj.ffServer.SendKeys('closeProject{(}{)}{enter}');
            obj.ffServer.SendKeys('n{enter}');
            obj.ffServer.SendKeys('exit{enter}');
            pause(10);
            obj.ffServer.SendKeys('exit{enter}');
        end
        
        function obj = readResultFiles(obj)
            % function obj = obj.readResultFile()
            % Reads the geometric and hydrostatic result file create by the
            % FFramework. Also read the file with the constraints calculate
            % by the FF.
            
            fid = -1;
            
            while fid == -1
                
                fid = fopen(obj.dummyFile);
            end
            
            fclose(fid);
            
            obj.FFParameters = readFile(obj.resultTemplate);
            obj.FFConstraints = readFile(obj.constTemplate);
            
        end
        
        function obj = setBasysHull(obj)
            % function obj = setBasysHull(obj)
            % Set the basys hull variables
            
            obj.varVec = obj.basysVarVec;
            obj.sendVarVec();
            
        end
    end
    
end

function read = readFile(fileName)
% function read = readFile(fileName)
% Read the file fileName

fid = fopen(fileName);
read = '';

% Positionate the file pointer
while ~strcmp(read,'Start')
    read = fscanf(fid,'%s',1);
end

% Read parameters
read = fscanf(fid,'%f',inf);

% Close file
fclose(fid);

end

function saveVarVec(varVec, fileName)
    
    label = 'alphaCenter Dstern Dbow xBase alphaChine BxLin Bxt CAp Dt ie xLin alphaBotF alphaBot0 xPos deadxLin deadt deadLp H Lp sca0 scaF';
    fid = fopen(fileName,'w');
    fprintf(fid,'%s\n\n',label);
    
    fprintf(fid,'%g ',varVec);
    fclose(fid);

end

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...