Main Content

simscape.op.create

Create operating point by extracting data from model or from logged simulation data

Description

example

op = simscape.op.create(simlog,t) creates an OperatingPoint object op by extracting variable targets from logged simulation data at time t. If the set of times recorded in the simulation data log simlog contains an exact match for time t, then the function extracts these variable target values into the operating point data. If there is no exact match, but t is between the minimum and maximum times of simlog, then the function uses linear interpolation to determine the target values. If t is less than the minimum time, then the function extracts the first value for each variable in simlog. Similarly, if t is greater than the maximum time, then the function extracts the last value in simlog.

When you log simulation data in the Simulation Data Inspector, the simulation log does not contain private Simscape™ language data. Therefore, if you extract an operating point from data logged using the Simulation Data Inspector, private data is not included. For all other methods of creating an operating point, whether from a model or from simulation data logged to memory or disk, private data is included by default.

example

op = simscape.op.create(block,simPhase) creates an OperatingPoint object op by extracting variable targets from the whole model, or from a specific block or subsystem, at the specified model simulation phase.

example

op = simscape.op.create(block,simPhase, true) creates an OperatingPoint object op by extracting cached values of variable targets from a model that has been previously initialized or simulated. This method lets you save time by avoiding repeated initialization of the model if the data that you want to extract has not changed. The function returns an error if the model has not been updated, initialized, or simulated earlier in the session.

Examples

collapse all

Open the Permanent Magnet DC Motor example model, which already has data logging enabled. Run the simulation to create the simulation log variable simlog_PermanentMagnetDCMotor (as specified by the Workspace variable name model configuration parameter) in your current workspace:

openExample('simscape/PermanentMagnetDCMotorExample')
sim('PermanentMagnetDCMotor');

Create an OperatingPoint object named op1 from logged simulation data at 0.1 seconds after the start of simulation:

op1 = simscape.op.create(simlog_PermanentMagnetDCMotor, 0.1)
op1 = 

  OperatingPoint with children:

  OperatingPoints:

   ChildId         Size
   ______________  ____

   'DC Motor'       1x1
   'DC Voltage'     1x1
   'ERef'           1x1
   'Load Torque'    1x1
   'MRRef Motor'    1x1
   'MRRef Torque'   1x1
   'Sensing'        1x1
   'Step Input'     1x1

Open the Permanent Magnet DC Motor example model and create an OperatingPoint object named op2 using the Start values from the model:

openExample('simscape/PermanentMagnetDCMotorExample')
op2 = simscape.op.create(gcs, 'Start')
op2 = 

  OperatingPoint with children:

  OperatingPoints:

   ChildId         Size
   ______________  ____

   'DC Motor'       1x1
   'DC Voltage'     1x1
   'ERef'           1x1
   'Load Torque'    1x1
   'MRRef Motor'    1x1
   'MRRef Torque'   1x1
   'Sensing'        1x1
   'Step Input'     1x1

Initializing a model takes time. If you work with a large model, you can avoid unnecessary repeated initialization by using cached values of variable targets.

Open the Permanent Magnet DC Motor example model and simulate it:

openExample('simscape/PermanentMagnetDCMotorExample')
sim('PermanentMagnetDCMotor');

Create an OperatingPoint object named op3 using the Start values for the DC Motor subsystem without reinitializing the model:

op3 = simscape.op.create('PermanentMagnetDCMotor/DC Motor', 'Start', true)
op3 = 

  OperatingPoint with children:

  OperatingPoints:

   ChildId                                   Size
   ________________________________________  ____

   'Friction'                                 1x1
   'Inertia'                                  1x1
   'Rotational Electromechanical Converter'   1x1
   'Rotor Inductance'                         1x1
   'Rotor Resistance'                         1x1

When you extract operating point data for a block or subsystem in a model, you cannot immediately use this operating point to initialize that block or subsystem, because of the mismatch in the data structure hierarchy. Use the relativePath function to determine the correct location, and then add the necessary layers for inserting this data in the operating point for the current model.

Open the Permanent Magnet DC Motor example model.

openExample('simscape/PermanentMagnetDCMotorExample')

Open the DC Motor subsystem, select the Inductor block, and create an OperatingPoint object named opRI using the Start values from the model:

opRI = simscape.op.create(gcb, 'Start')
opRI = 

  OperatingPoint with children:

  Targets:

   ChildId       Value  Unit  Priority
   _______  __________  ____  ________

   'i'      1.5000e-09  'A'     'None'
   'i_L'             0  'A'     'High'
   'v'          1.5000  'V'     'None'

  OperatingPoints:

   ChildId  Size
   _______  ____

   'n'       1x1
   'p'       1x1

Change the initialization target for the Inductor current variable, i_L:

t = simscape.op.Target(1.5, 'A', 'High');
opRI = set(opRI, 'i_L', t)
opRI = 
  OperatingPoint with children:

  Targets:

   ChildId       Value  Unit  Priority
   _______  __________  ____  ________

   'i'      1.5000e-09  'A'     'None'
   'i_L'        1.5000  'A'     'High'
   'v'          1.5000  'V'     'None'

  OperatingPoints:

   ChildId  Size
   _______  ____

   'n'       1x1
   'p'       1x1

To use the new target for block initialization, you need to create an operating point for the whole model and insert the block operating point at the correct location.

Create an empty OperatingPoint object named opModel:

opModel = simscape.op.OperatingPoint
opModel = 

  OperatingPoint with no children.

Set the Identifier property of the OperatingPoint object to match the name of the model and find the relative path for the Inductor block:

opModel.Identifier = bdroot(gcb);
relPath = relativePath(opModel, gcb)
relPath =

    'DC Motor/Rotor Inductance'

Add the OperatingPoint object opRI to the OperatingPoint object opModel:

opModel = set(opModel, relPath, opRI)
opModel = 

  OperatingPoint with children:

  OperatingPoints:

   ChildId     Size
   __________  ____

   'DC Motor'   1x1

The command inserted the data at the location defined by relPath, adding the nodes to the data tree, as necessary.

You can now use the opModel operating point to initialize the model and apply the new target to the Inductor block.

Input Arguments

collapse all

Simulation log workspace variable that contains the logged model simulation data, or a node of this variable, specified as a simscape.logging.Node object. You specify the name of the simulation log variable by using the Workspace variable name parameter in the Simscape pane of the Configuration Parameters dialog box.

Simulation time for data extraction, specified as a real number.

Data Types: double

Block, subsystem, or model name or identifier, specified as a handle, model name, full path to a block or subsystem in the model, Simulink.Block object, or a valid Simulink identifier (SID).

Data Types: double | char | string

Model simulation phase for data extraction, specified as one of:

  • 'Start' — The function initializes the root model and extracts the variable targets for the whole model, or for the specified block or subsystem, into the operating point data. These targets correspond to Start values in the Variable Viewer.

  • 'Prestart' — The function updates the root model and extracts the target values for the whole model, or for the specified block or subsystem, before initializing the model. These targets correspond to Prestart values in the Variable Viewer.

If the model already uses an operating point for initialization, then the function applies the targets in that OperatingPoint to the model during both of these phases, and reflects the results in the extracted OperatingPoint, op.

Data Types: char

Output Arguments

collapse all

Operating point in the base workspace, returned as an OperatingPoint object, with variable initialization data extracted from the model or from logged simulation data.

Version History

Introduced in R2017b