Main Content

Specifying Initial Target Values for Member Variables

Member components have to be declared with ExternalAccess=observe, and therefore their variables do not appear in the Initial Targets section of the top-level block dialog box. However, if a certain member component variable is important for initialization, you can tie its value to an initialization parameter in the top-level parameters declaration block. In this case, the block user will be able to adjust the initial target value of the member component variable from the top-level block dialog box when building and simulating a model.

Note

The block user cannot change the initialization priority of the member component variable. You specify the variable initialization priority when you declare the member component. The syntax is the same as described in Variable Priority for Model Initialization.

For example, you have a composite DC Motor block (similar to the one described in Composite Component — DC Motor) and want the block user to specify the initial target value for the inductor current, with low priority. The following code includes a Foundation library Inductor block in your custom component file, with the ability to control its inductance at the top level (by using the Rotor Inductance block parameter) and also to specify a low-priority initial target for the inductor current variable:

component DCMotor2
[...]
  parameters
     rotor_inductance = { 12e-6, 'H' };    % Rotor Inductance
     i0 = { 0, 'A' };  % Initial current target for Rotor Inductor
     [...]
  end
  components(ExternalAccess=observe)
     rotorInductor = foundation.electrical.elements.inductor(l = rotor_inductance, 
                                      i_L = {value = i0, priority = priority.low});
     [...]
  end
[...]
end

In this case, the block user can specify a value for the Initial current target for Rotor Inductor parameter, which appears in the block dialog box of the composite component. This value gets assigned as the initial target to variable i_L (Initial current variable of the member Inductor block), with low initialization priority. Depending on the results of the solve, the target may or may not be satisfied when the solver computes the initial conditions for simulation. For more information, see Block-Level Variable Initialization.

You can use an alternative syntax that lets you assign the variable value and priority data fields separately, using the dot notation. For example, the following statement:

      rotorInductor = foundation.electrical.elements.inductor(l = rotor_inductance, 
                                      i_L.value = i0, i_L.priority = priority.low);
     

is equivalent to the Inductor component declaration from the previous example.

Related Examples

More About