Using multiple rollups in a single part definition

Hello,

I’ve got a somewhat complex example here of using multiple rollups in a single part definition. Since in a real use case I expect that you would typically have more than one attribute to roll up (e.g., mass, cost, power), this is my attempt to achieve that by re-using a single rollup definition in several specializations. If this is the totally wrong way to go about this, please let me know.

See the attached files with the model and python code:

multi_rollup.sysml (1.6 KB)

multi_rollup.py.txt (2.7 KB)

The output of my python script becomes:

{'subsystem1': {'cost': 1000,
                'mass': 1,
                'power': 10,
                'totalCost': <syside.core.AttributeUsage object at 0x7df7a3a5ee90>,
                'totalMass': <syside.core.AttributeUsage object at 0x7df7a3a5ecf0>,
                'totalPower': <syside.core.AttributeUsage object at 0x7df7a3a5ee70>},
 'subsystem2': {'cost': 2000,
                'mass': 2,
                'power': 20,
                'totalCost': <syside.core.AttributeUsage object at 0x7df7a3a5ee90>,
                'totalMass': <syside.core.AttributeUsage object at 0x7df7a3a5ecf0>,
                'totalPower': <syside.core.AttributeUsage object at 0x7df7a3a5ee70>},
 'system': {'cost': 10000,
            'mass': 10,
            'power': 0,
            'totalCost': <syside.core.AttributeUsage object at 0x7df7a3a5ee90>,
            'totalMass': <syside.core.AttributeUsage object at 0x7df7a3a5ecf0>,
            'totalPower': <syside.core.AttributeUsage object at 0x7df7a3a5ee70>}}

I think something is breaking when the totalValue attribute gets renamed, like in attribute totalMass redefines totalValue.

When I tried this with SystemProduct only specializing MassedCompositeThing and without renaming totalValue to totalMass, the rollup still worked even after renaming value to mass. But once the line attribute totalMass redefines totalValue; is added, the totalMass attribute no longer correctly evaluates to a number like you see in the printed output above.

I expect something could also be going wrong with the system::components attribute since components is being inherited 3 times (from each Rollup being specialized) and I don’t know how that’s getting handled in the background.

Any thoughts on what is going on here?

Hi Axel,

This looks like a typical case of multiple-inheritance gone wrong, especially when combined with redefinitions. Conceptually, redefinitions do not create new features, they instead overwrite them. So when your SystemProduct inherits multiple renamed values, all mass, power, and cost actually point to the same inherited value feature. SysML hides this catastrophic error by allowing redefining features to have different names. (Not to mention that this requires linear search for specific features when evaluating them on a type instead of looking them up by name in constant time like in all other sane languages.)

Hi Daumantas,

Ok that sounds pretty bad. But how does that interpretation fit with the observation that mass, cost and power (not the totals) have distinct values even though you say they are all pointing to the same attribute from the rollup package? It’s just the total calculation that fails, and this failure already appears once the totalValue attribute gets renamed by the redefine, even if SystemProduct is only inheriting from one part definition.

If this approach really is doomed, do you have any ideas about how to make this kind of use case possible to implement? Is there really no way to roll up multiple values with the rollup pattern extracted as a generic package?

But how does that interpretation fit with the observation that mass, cost and power (not the totals) have distinct values even though you say they are all pointing to the same attribute from the rollup package?

That is the hidden problem - they are technically not distinct even if no analysers/specification catch it yet.

If this approach really is doomed, do you have any ideas about how to make this kind of use case possible to implement? Is there really no way to roll up multiple values with the rollup pattern extracted as a generic package?

Rather than redefining the same features multiple times, make the features distinct. For example,

part def CompositeThing {
    part components : CompositeThing [*] default null;
}

part def MassedCompositeThing specializes CompositeThing {
    attribute mass : Real default 0;
    attribute totalMass = mass + NumericalFunctions::sum(components.totalMass);
}
part def PoweredCompositeThing specializes CompositeThing {
    attribute power : Real default 0;
    attribute totalPower = power + NumericalFunctions::sum(components.totalPower);
}
part def CostlyCompositeThing specializes CompositeThing {
    attribute cost : Real default 0;
    attribute totalCost = cost + NumericalFunctions::sum(components.totalCost);
}

A little boiler-platy but not by that much given that the attributes were redefined previously. Ideally, there would be generics in SysML that would make this much easier.