Export to Modelica and execution of the SysML/SysPhS block ConnectedTanks

Gallery
Tutorial
Click on the image to view it full size

The export of block ConnectedTanks from the MagicDraw SysML Plugin or Magic Cyber-Systems Engineer® (Cameo Systems Modeler®) gives:

model ConnectedTanks
  ConnectedTanks _ConnectedTanks;
  model ConnectedTanks
    Tank fluidReservoir1(fluidLevel.start=40.0,fluidLevel.fixed=true,tankSurfaceArea.start=4.0,tankSurfaceArea.fixed=true);
    Tank fluidReservoir2(fluidLevel.start=15.0,fluidLevel.fixed=true,tankSurfaceArea.start=4.0,tankSurfaceArea.fixed=true);
    Pipe pipe(dynamicViscosity.start=2.0,dynamicViscosity.fixed=true,pipeLength.start=10.0,pipeLength.fixed=true,radius.start=0.5,radius.fixed=true);
  equation
    connect(fluidReservoir1.tankOpening,pipe.pipeOpening1);
    connect(pipe.pipeOpening2,fluidReservoir2.tankOpening);
  end ConnectedTanks;
  model Tank
    VolumeFlowElement tankOpening;
    Length fluidLevel;
    parameter Area tankSurfaceArea;
    parameter Acceleration gravity(start=9.8,fixed=true);
    parameter Density fluidDensity(start=10.0,fixed=true);
  equation
    tankOpening.p=gravity*fluidLevel*fluidDensity;
    der(fluidLevel)=-tankOpening.q/tankSurfaceArea;
  end Tank;
  model Pipe
    VolumeFlowElement pipeOpening1;
    VolumeFlowElement pipeOpening2;
    ViscousResistance resistance;
    VolumeFlowRate fluidFlow;
    Pressure fluidPressureDiff;
    parameter Length pipeLength;
    parameter Length radius;
    parameter Viscosity dynamicViscosity;
  equation
    resistance=(8*dynamicViscosity*pipeLength)/(3.1416*(radius^4));
    fluidFlow=fluidPressureDiff/resistance;
    fluidPressureDiff=pipeOpening2.p-pipeOpening1.p;
    pipeOpening1.q+pipeOpening2.q=0;
    fluidFlow=pipeOpening1.q;
  end Pipe;
  connector VolumeFlowElement
    flow VolumeFlowRate q;
    Pressure p;
  end VolumeFlowElement;
  type Length=Real(unit="m");
  type Area=Real(unit="m²");
  type Acceleration=Real(unit="m/s²");
  type Density=Real(unit="kg/m³");
  type ViscousResistance=Real(unit="N·s/m⁵");
  type VolumeFlowRate=Real(unit="m³/s");
  type Pressure=Real(unit="Pa");
  type Viscosity=Real(unit="Pa·s");
end ConnectedTanks;
Notice how the start values for "shared" parameters gravity and fluidDensity (common to both tanks) are only provided in Tank

  model Tank
    VolumeFlowElement tankOpening;
    Length fluidLevel;
    parameter Area tankSurfaceArea;
    parameter Acceleration gravity(start=9.8,fixed=true);
    parameter Density fluidDensity(start=10.0,fixed=true);

They thus respect (at least better than the spec version) the Single Source of Truth (SSOT) and Don't Repeat Yourself (DRY) principles, under the assumption that both tanks experience the same gravity and the system involves a fluid of known constant fluid density. Recall that they were provided using the basic Property::defaultValue mechanism on the value properties within block Tanks, rather than using Context-Specific Values per tank within block ConnectedTanks.

Compare with these per-tank start values for fluidLevel and tankSurfaceArea (where the areas could indeed be different):


  model ConnectedTanks
    Tank fluidReservoir1(fluidLevel.start=40.0,fluidLevel.fixed=true,tankSurfaceArea.start=4.0,tankSurfaceArea.fixed=true);
    Tank fluidReservoir2(fluidLevel.start=15.0,fluidLevel.fixed=true,tankSurfaceArea.start=4.0,tankSurfaceArea.fixed=true);
Validation passes and gives:

Validation of model ConnectedTanks 
Warning: Parameter _ConnectedTanks.fluidReservoir1.tankSurfaceArea has no value, and is fixed during initialization (fixed = true), using available start value (start = 4.0) as default value.
Warning: Parameter _ConnectedTanks.fluidReservoir1.gravity has no value, and is fixed during initialization (fixed = true), using available start value (start = 9.800000000000001) as default value.
Warning: Parameter _ConnectedTanks.fluidReservoir1.fluidDensity has no value, and is fixed during initialization (fixed = true), using available start value (start = 10.0) as default value.
Warning: Parameter _ConnectedTanks.fluidReservoir2.tankSurfaceArea has no value, and is fixed during initialization (fixed = true), using available start value (start = 4.0) as default value.
Warning: Parameter _ConnectedTanks.fluidReservoir2.gravity has no value, and is fixed during initialization (fixed = true), using available start value (start = 9.800000000000001) as default value.
Warning: Parameter _ConnectedTanks.fluidReservoir2.fluidDensity has no value, and is fixed during initialization (fixed = true), using available start value (start = 10.0) as default value.
Warning: Parameter _ConnectedTanks.pipe.pipeLength has no value, and is fixed during initialization (fixed = true), using available start value (start = 10.0) as default value.
Warning: Parameter _ConnectedTanks.pipe.radius has no value, and is fixed during initialization (fixed = true), using available start value (start = 0.5) as default value.
Warning: Parameter _ConnectedTanks.pipe.dynamicViscosity has no value, and is fixed during initialization (fixed = true), using available start value (start = 2.0) as default value.
Validation of model ConnectedTanks completed successfully.
The model is globally balanced with 7 variables and 7 equations.
Among these, 7 equations are trivial.
The plot shows the fluid level in each tank from a typical simulation execution in Wolfram SystemModeler.
Up next
Next trail section
Notes
Snippets (quotes/extracts)
Visit also
Visit also (backlinks)
Related slides (includes other tutorials)
Related slides (backlinks, includes other tutorials)