バックナンバーはこちら。
https://www.simulationroom999.com/blog/model-based-of-minimum-2-backnumber/
はじめに
Modelicaのプログラミング言語としての簡単な説明。
モデル定義についてさらに掘り下げる。
extends、partialなどのキーワードが使用されており、
オブジェクト指向的性質が垣間見れる。
剛体であれば、剛体モデルから派生。など。
登場人物
博識フクロウのフクさん

イラストACにて公開の「kino_k」さんのイラストを使用しています。
https://www.ac-illust.com/main/profile.php?id=iKciwKA9&area=1
エンジニア歴8年の太郎くん

イラストACにて公開の「しのみ」さんのイラストを使用しています。
https://www.ac-illust.com/main/profile.php?id=uCKphAW2&area=1
Modelicaのモデル定義の掘り下げ

前回Modelicaのモデル定義について説明したが、
もうちょっと説明しておこう。

まだなんかあるんか・・・。

前回のMassモデルをもう一回貼っておこう。
model Mass "Sliding mass with inertia"
parameter SI.Mass m(min=0, start=1) "Mass of the sliding mass";
parameter StateSelect stateSelect=StateSelect.default;
extends Translational.Interfaces.PartialRigid(L=0,s(start=0, stateSelect=stateSelect));
SI.Velocity v(start=0, stateSelect=stateSelect)
"Absolute velocity of component";
SI.Acceleration a(start=0) "Absolute acceleration of component";
equation
v = der(s);
a = der(v);
m*a = flange_a.f + flange_b.f;
end Mass;

この中でextendsというキーワードがある。

ホントだ。

これはなに?
Modelicaのモデル定義のextends

extendsはいわゆる継承の機能になる。

いきなりオブジェクト指向プログラム的な用語が!!

まぁオブジェクト指向的な要素はどうしても入るね。
今回の場合は、Translational.Interfaces.PartialRigidってModelを継承している。
というわけでTranslational.Interfaces.PartialRigidの定義を見ると、
Modelicaのモデル定義のpartial
partial model PartialRigid
"Rigid connection of two translational 1D flanges"
SI.Position s
"Absolute position of center of component (s = flange_a.s + L/2 = flange_b.s - L/2)";
parameter SI.Length L(start=0)
"Length of component, from left flange to right flange (= flange_b.s - flange_a.s)";
Flange_a flange_a "Left flange of translational component" annotation (
Placement(transformation(extent={{-110,-10},{-90,10}})));
Flange_b flange_b "Right flange of translational component" annotation (
Placement(transformation(extent={{90,-10},{110,10}})));
equation
flange_a.s = s - L/2;
flange_b.s = s + L/2;
end PartialRigid;

modelキーワードの前にpartialってキーワードがあるね?
これはなに?

partialは「部分的な」って意味なんだけど、
このModelは「部分的」で「不完全」なModelなんで、継承以外では使用できないよ。
って意味になる。

OOPの抽象クラスみたいなもんか。

そうそう。

で、このPartialRigidってなに?

Partialは先のPartialキーワード由来の名称で、
Rigidは多分「剛体」って意味だな。
つまり、剛体を定義する際に継承すべきModelってことになるね。

なるほどー。

あとは、Flange_a、Flange_bについての説明がいるのだけど、
それは次回だ。
まとめ

まとめだよ。
- Massモデルの中にあるextendsは継承を示すキーワード。
- PartialキーワードはModelの不完全性を示しており、継承以外の利用ができないよう制約を掛けている。
- OOPの抽象class的なもの。
- PartialRigidモデルは剛体モデル。
- 直線運動する剛体モデルを作る際はこのモデルを継承すると吉。
バックナンバーはこちら。
コメント