|
|
MATLAB interface: Running models |
To open an existing OrcaFlex file from within MATLAB you can either create a new ofxModel object with a file name as a constructor parameter:
model = ofxModel('MyFile.dat')
or use an existing ofxModel instance and open a data or simulation file like this:
model = ofxModel
model.LoadData('MyFile.dat')
model.LoadSimulation('MyFile.sim')
To run a simulation (which also calculates statics if the model is in 'Reset' state), use:
model.RunSimulation
To calculate statics only use the call:
model.CalculateStatics
You can determine what state the Model is in by reading the state property of ofxModel:
modelstate = model.state
The return value, modelstate, will be equal to one of the following constants:
ofx.msReset
ofx.msCalculatingStatics
ofx.msInStaticState
ofx.msSimulationStopped
ofx.msSimulationStoppedUnstable
To save a simulation or data file use the following calls:
model.SaveSimulation('MyFile.sim')
model.SaveData('MyFile.dat')
Results can now be extracted from the ofxModel object, see MATLAB interface: Results
Normally using the OrcaFlex spreadsheet is the most effective way of creating and running batch scripts and post-processing the results, but this can also be done through MATLAB if neccessary. Use the ProcessBatchScript command of the ofxModel object, for example:
model.ProcessBatchScript('MyScript.txt')
model.LoadSimulation('GeneratedModel.sim')
Progress handlers can be set for statics, dynamics, processing batch scripts and other TOrcFxAPIHandle running operations, see ProgressHandlers. The progress handler also gives the opportunity to cancel a long running operation, and the dynamics progress handler allows the operation to be paused. The following example sets a dynamics progress handler:
% Define a function which will handle the progress callback:
function cancel = DynamicsProgressHandler(model, time, start, stop)
cancel = false;
% Do something with the progress information, such as report it
DoSomethingWithProgressInfo(time, start, stop);
% Call your function to check if pausing is required
if TestForPause
model.PauseSimulation;
end
% Call your function to check if the operation should be cancelled
cancel = TestForCancel;
end
% Code to set the progress handler and run it
model.dynamicsProgressHandler = @DynamicsProgressHandler
model.LoadData('LongRunningModel.dat')
model.RunSimulation