ModelicaStandardLibrary icon indicating copy to clipboard operation
ModelicaStandardLibrary copied to clipboard

Improve inheritance in MultiBody using selective model extension

Open tobolar opened this issue 2 years ago • 9 comments

A first draft for #3739 using "selective model extension" introduced in ModelicaSpec 3.6. See also comment https://github.com/modelica/ModelicaStandardLibrary/pull/4091#issuecomment-1801329028.

The approach implemented here is to reduce the number of possible base classes for variants of connector interfaces by introducing just one (or significantly less number of) extended base class containing more/all the concerned connectors at once and to disable selected unused connectors in extending classes.

This PR-draft is about MultiBody library. It introduces base classes

  • Interfaces.PartialTwoFramesResolve (which can be renamed for final PR): it contains connectors frame_a, frame_b and frame_resolve, and the "world".
  • Interfaces.PartialFrameResolveConditional: since several classes utilizes conditional frame_resolve connector, the idea is to disable the non-conditional frame_resolve in the inherited PartialTwoFramesResolve and to inherite PartialFrameResolveConditional additionally as follows
    import Modelica.Mechanics.MultiBody.Types.ResolveInFrameB;
    
    extends Interfaces.PartialTwoFramesResolve(
     break frame_resolve);
    extends Interfaces.PartialFrameResolveConditional(
     final enableFrameResolve = resolveInFrame==ResolveInFrameB.frame_resolve);
    
    parameter ResolveInFrameB resolveInFrame = ResolveInFrameB.world
     "Frame in which input u is resolved";
    

Some notes:

  1. Hopefully, this approach will lead to elimination of base classes like Interfaces.PartialOneFrame_a and Interfaces.PartialOneFrame_b.
  2. In this PR, the approach is implemented in parts for multibody Forces and Sensors. After the proof-of-concept, it shall be extended to other multibody classes as well.
  3. There is a lot of commits in order to enable simply cherry-picking - if needed later on.
  4. Icon: in some cases, like for Forces.WorldTorque, the diagram and icon layout was changed, since in the PartialTwoFramesResolve the frame_resolve connector is placed at the icon's bottom boundary (instead of the top).
  5. Icon: text "a" beneath the connector frame_a was deleted. Similarly for "b" and frame_b.
  6. The cardinality assertion like assert(cardinality(frame_a) > 0,...) is no more used.

tobolar avatar Nov 13 '23 09:11 tobolar

It seems MapleSim's moparser can yet not deal with the "selective model extension". ;-) https://github.com/modelica/ModelicaStandardLibrary/actions/runs/6848246047/job/18618044784

tobolar avatar Nov 13 '23 11:11 tobolar

The new version of MapleSim's moparser allows it. But I do not know how to upload it. The github page for it was archived. I sent an email to @dietmarw.

eshmoylova avatar Nov 15 '23 16:11 eshmoylova

The new version of MapleSim's moparser allows it. But I do not know how to upload it. The github page for it was archived. I sent an email to @dietmarw.

PRs are now accepted again. Thanks! It is appreciated.

beutlich avatar Nov 15 '23 17:11 beutlich

Syntax checks still fail with MapleSim Stand-Alone Modelica Parser 3.6 (after branch rebase).

beutlich avatar Nov 18 '23 08:11 beutlich

@beutlich what version of moparser is used for the checks? It works for me. To double check, I downloaded the latest version from the github page and the files from this PR. Tested on Linux64 and Windows 64. Both returned no errors. Note that 32 bit platforms are no longer built, so the files were not updated (only 3.4 grammar) and just moved to the Obsolete folder.

eshmoylova avatar Nov 20 '23 17:11 eshmoylova

what version of moparser is used for the checks

MapleSim Stand-Alone Modelica Parser 3.6, see https://github.com/modelica/ModelicaStandardLibrary/actions/runs/6912730662/job/18808801660?pr=4231

beutlich avatar Nov 20 '23 20:11 beutlich

If you click on the triangle next to "Run echo "::add-matcher::./.github/moparser.json"" in that link, it looks like the version for moparser is explicitly set the version to 3.4:

 ModelicaSyntaxChecker/Linux64/moparser -v 3.4 -r Complex.mo Modelica ModelicaReference ModelicaServices ModelicaTest ModelicaTestConversion4.mo 
image

The workflow would need to be updated to call -v 3.6 or completely remove -v option, to rely on the default version.

eshmoylova avatar Nov 21 '23 14:11 eshmoylova

If you click on the triangle next to "Run echo "::add-matcher::./.github/moparser.json"" in that link,

The confusing is, MapleSim reports in right that link that it is 3.6:

MapleSim Stand-Alone Modelica Parser 3.6 Copyright (c) 2023 by Maplesoft. May be freely used for library ...

tobolar avatar Nov 21 '23 16:11 tobolar

If you click on the triangle next to "Run echo "::add-matcher::./.github/moparser.json"" in that link, it looks like the version for moparser is explicitly set the version to 3.4:

 ModelicaSyntaxChecker/Linux64/moparser -v 3.4 -r Complex.mo Modelica ModelicaReference ModelicaServices ModelicaTest ModelicaTestConversion4.mo 
image

The workflow would need to be updated to call -v 3.6 or completely remove -v option, to rely on the default version.

Thanks, see #4235.

beutlich avatar Nov 21 '23 16:11 beutlich