Documentation

simscape.op.create

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

Syntax

op = simscape.op.create(simlog,t)
op = simscape.op.create(block,simPhase)
op = simscape.op.create(block,simPhase, true)

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.

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_ssc_dcmotor (as specified by the Workspace variable name model configuration parameter) in your current workspace:

ssc_dcmotor
sim('ssc_dcmotor');

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

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

  OperatingPoint with children:
  -----------------------------
   DC Motor
   DC Voltage
   ERef
   Load Torque
   MRRef Motor
   MRRef Torque
   Sensing
  -----------------------------

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

ssc_dcmotor
op2 = simscape.op.create(gcs, 'Start')
op2 = 

  OperatingPoint with children:
  -----------------------------
   DC Motor
   DC Voltage
   ERef
   Load Torque
   MRRef Motor
   MRRef Torque
   Sensing
  -----------------------------

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:

ssc_dcmotor
sim('ssc_dcmotor');

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

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

  OperatingPoint with children:
  ----------------------------------------
   Friction
   Inertia
   Rotational Electromechanical Converter
   Rotor Inductance
   Rotor Resistance
  ----------------------------------------

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.

ssc_dcmotor

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:
  -----------------------------
   i    1.5000e-09|'A'  None
   i_L           0|'A'  High
   v        1.5000|'V'  None
  -----------------------------
   n
   p
  -----------------------------

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:
  -----------------------------
   i    1.5000e-09|'A'  None
   i_L      1.5000|'A'  High
   v        1.5000|'V'  None
  -----------------------------
   n
   p
  -----------------------------

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:
  -----------------------------
   DC Motor
  -----------------------------

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

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.

Introduced in R2017b

Was this topic helpful?