演習1:システム定義の作成と使用

本演習では、元のシステムMDLファイルからシステム定義を生成する方法について学習します。

演習では下記のMDLステートメントを使用します:
  • *DefineSystem()
  • *System()
  • *SetSystem()
  • *Attachment()
本演習では、これらのアクションを実施します:
  • チュートリアルMV-1060:MDLステートメントを用いた振子モデルの構築からの振子モデルを修正し、sys_pendu_mdlというシステム定義を作成します。
  • このシステム定義を使って、別の振子をモデルに追加し、図 1に示すような二重振子のモデルを作成します。
  • ベースモデルをdoublependulum.mdlとして保存します。
  • 過渡応答の動力学シミュレーションを実行し、アニメーションを表示させます。


図 1. 二重振子の詳細図


図 2. 二重振子のプロパティ一覧

システム定義の作成

このステップでは、チュートリアルMV-1060:MDLステートメントを用いた振子モデルの構築からのMDLモデルファイルを使ってシステム定義を作成します。

システム定義の構造はMDLモデルファイルに類似しているため、別のチュートリアルからの振子モデルファイルを再使用して、より汎用化されたシステム定義を生成します。
  1. mbd_modeling\mdlフォルダーにあるpendulum.mdlファイルを、自身の<作業ディレクトリ>にコピーします。
    以下が、以前のチュートリアルの振子モデルについてのMDLサンプルファイルです:
    //Pendulum Model
    //05/31/XX
    *BeginMDL(pendulum, "Pendulum Model")
    //Topology information
    //declaration of entities
    //Points
    *Point(p_pendu_pivot, "Pivot Point")
    *Point( p_pendu_cm, "Pendulum CM")
    //Bodies
    *Body(b_link, "Ball", p_pendu_cm)
    //Graphics
    *Graphic(gr_sphere, "pendulum sphere graphic", SPHERE, b_link,
    p_pendu_cm, 1)
    *Graphic(gr_link, "pendulum link graphic", CYLINDER, b_link,
    p_pendu_pivot, POINT, p_pendu_cm, 0.5, CAPBOTH)
    //Revolute Joint
    *RevJoint(j_joint, "New Joint", B_Ground, b_link, p_pendu_pivot,
    VECTOR, V_Global_X)
    //Output
    *Output(o_pendu, "Disp Output", DISP, BODY, b_link)
    //End Topology
    // Property Information
    *SetPoint(p_pendu_pivot, 0, 5, 5)
    *SetPoint(p_pendu_cm, 0, 10, 10)
    *SetBody( b_link, 1, 1000, 1000, 1000, 0, 0, 0)
    *EndMDL()
    このMDLファイルは、多少の変更を加えることによって、システム定義に変換することができます。
    重要: この変換は、すべてのケースで適用できるわけではありません。いくつかの条件(本チュートリアル内で後ほど説明)に気を付ける必要があります。
  2. *BeginMDL()および*EndMDL()ステートメントをそれぞれ*DefineSystem()および*EndDefine()ステートメントで置き換えます。システム定義について、適切な変数名を指定します。
  3. ステートメントatt_pointおよびatt_bodyを使って、システムがどこで結合するか(アタッチメントポイントまたはピボットポイント)、およびどのボディに結合するか(アタッチメントボディ)を指定します。
  4. これらの変数を*DefineSystem ()ステートメントで使用します。
    *DefineSystem (sys_def_pendulum, att_point, att_body)
    注: 先に述べたとおり、アタッチメントエンティティは、任意のMDLエンティティでかまいません。したがって、変数が表わすエンティティタイプを指定する必要があります。例えば、att_pointはPOINTエンティティを表わします。
  5. *Attachment()ステートメントを使って、各変数が表わすエンティティタイプを指定します。
    *Attachment (att_point, "Pivot Point", POINT, "Attachment point where
    the pendulum definition gets attached")
    *Attachment (att_body, "Attachment body" , BODY, " Any body to which the
    pendulum definition gets attached")
    注: オリジナルモデルの変数p_pendu_pivotは、ピボットポイントを表わしていました。振子モデルを振子システム定義に変換する際、ピボットポイントはアタッチメントポイントとして与えられます。
    ポイントp_pendu_pivotはアタッチメントとして渡されます。したがって、ピボットポイントを定義する必要はありません。
  6. ステートメント*Point (p_pendu_pivot, "Pivot Point")を削除します。
  7. 振子の重心ポイント、および*Body()ステートメントを保持します。
  8. *RevJoint()ステートメントで、B_groundatt_bodyに、p_pendu_pivotatt_pointに置き換えます。
  9. 球の*Graphic()ステートメントを保持します。
  10. 円筒の*Graphic()ステートメント内で、p_pendu_pivotatt_pointに置き換えます。
    注: スクリプト全体で、適用可能な箇所では、アタッチメント変数で元の変数を置き換える必要があります。
  11. *Output()ステートメントを保持します。
    これにより、モデル内の各振子ボディの変位出力が取得できます。
  12. *setpoint(p_pendu_pivot, 0, 5, 5)を削除します。
  13. *Setpoint()ステートメント内で、ステートメント(att_point.y+5, att_point.z+5)を用いてシステム内のポイントをパラメータ化します。
    これにより、重心点がアタッチメントポイントから5ユニット離れた所に設定されます。
    注: 以下はサンプルシステム定義(system.mdl)です:
    // system.mdl
    // created on:
    *DefineSystem(sys_def_pendulum, att_point, att_body)
    //Topology Data
    // Declaration of Entities
    //Attachments
    *Attachment (att_point, "Pivot Point", Point, "Attachment
    point where the pendulum definition gets attached")
    *Attachment (att_body, "Attachment body" , Body, " Any body
    to which the pendulum definition gets attached")
    //Points
    *Point( p_pendu_cm, "Pendulum CM")
    //Bodies
    *Body(b_link, "Ball", p_pendu_cm)
    //Joints
    *RevJoint(j_joint, "New Joint", att_body, b_link, att_point,
    VECTOR, V_Global_X)
    //Output
    *Output(o_pendu, "Disp Output", DISP, BODY, b_link)
    //Graphics
    *Graphic(gr_sphere, "pendulum sphere graphic", SPHERE,
    b_link, p_pendu_cm, 1 )
    *Graphic(gr_link, "pendulum link graphic", CYLINDER, b_link,
    att_point, POINT, p_pendu_cm, 0.5, CAPBOTH )
    // Property Data
    *SetPoint(p_pendu_cm, 0, att_point.y+5, att_point.z+5)
    *SetBody(b_link, 1, 1000, 1000, 1000, 0, 0, 0)
    *EndDefine()
    
  14. ファイルをsys_pendu.mdlとして保存します。

MDLファイルの手動によるオーサリングでシステム定義を追加

このステップでは、システム定義を含むMDLファイルを書き、それを数度にわたってインスタンス化します。

  1. テキストエディタで新しい空のファイルを作成します。
  2. モデルファイルを*BeginMDL()ステートメントで開始します。
  3. sys_pendu.mdlファイルから、テキストを*DefineSystem()から*EndDefine()までを、*BeginMDL()ステートメントの下の新規ファイルにコピーします。
  4. *System()ステートメントを使って、1つ目の振子システムをインスタンス化します:
    *System(system1, "First Pendulum System", sys_def_pendulum, P_Global_Origin, B_Ground)
    注: シンタックスについては、MDL Language Referenceオンラインヘルプをご参照ください。
    要確認: システムをインスタンス化する際は、次の点に注意が必要です。
    • *System()ステートメント内で、システム定義を、3番目の引数として変数名を指定することにより参照します。システム定義の変数名は、対応する *DefineSystem()ステートメントで指定したものと同じものを使用します。上の例では、system1はシステム定義sys_def_pendulumを使用します。
    • 適用可能な場合、システム定義内のアタッチメントを指定します。例えば、sys_def_pendulumは、*RevJoint()ステートメント内のbody_2を参照するアタッチメントatt_bodyを含みます。system1で、振子ボディb_linkはグラウンドボディB_Groundに結合されています。したがって、B_Ground*System()ステートメント内でアタッチメントボディとして指定されます。
    • 必須ではありませんが、*DefineSystem()の後ろに*System()ステートメントを追加することが推奨されます。
  5. 適切な変更を加えて手順4を繰り返し、2つ目の振子システムを作成します。
    1. システムインスタンスには異なる変数名system2を与えます。
    2. アタッチメントとして1つ目のシステムからPendulum CM (p_pendu_cm)とPendulum Body (b_link)を使用します。
      以下と全く同じステートメントを使用してください:
      *System(system2, "Second Pendulum System", sys_def_pendulum,
      system1.p_pendu_cm, system1.b_link )
  6. *EndMDL()ステートメントでファイルを閉じます。
    モデルファイルの例を以下に示します:
    *BeginMDL(model, "MODEL")
    *System(system1, "First Pendulum System", sys_def_pendulum,
    P_Global_Origin, B_Ground)
    *System(system2, "Second Pendulum System", sys_def_pendulum,
    system1.p_pendu_cm, system1.b_link )
    *DefineSystem(sys_def_pendulum, att_point, att_body)
    //Topology Data
    // Declaration of Entities
    //Attachments
    *Attachment (att_point, "Pivot Point", Point, "Attachment point
    where the pendulum definition gets attached")
    *Attachment (att_body, "Attachment body" , Body, " Any body to which
    the pendulum definition gets attached")
    //Points
    *Point( p_pendu_cm, "Pendulum CM")
    //Bodies
    *Body(b_link, "Pendulum Body", p_pendu_cm)
    //Joints
    *RevJoint(j_pivot, " Revolute Joint at Pivot Point ", b_link,
    att_body, att_point, VECTOR, V_Global_X)
    //Output
    *Output(o_pendu, "Disp Output", DISP, BODY, b_link)
    //Graphics
    *Graphic(gr_sphere, "pendulum sphere graphic", SPHERE, b_link,
    p_pendu_cm, 1 )
    *Graphic(gr_link, "pendulum link graphic", CYLINDER, b_link,
    att_point, POINT, p_pendu_cm, 0.5, CAPBOTH )
    // Property Data
    *SetPoint(p_pendu_cm, 0, att_point.y+5, att_point.z+5)
    *SetBody(b_link, 1, 1000, 1000, 1000, 0, 0, 0)
    *EndDefine()
    *EndMDL()
  7. モデルをdoublependulum.mdlとして保存します。
  8. MotionViewでMDLファイルを開きます。特に、Projectブラウザ内にリストされているFirst Pendulum SystemファイルとSecond Pendulum Systemファイルに着目してモデルを確認します。
    (System)アイコンの下に、小さな'手'のマークが付いています。これは、両方のシステムが単一の定義を有しているShared Definition(共有定義)と呼ばれる特徴です。


    図 3.
    システム定義が共有されている際、いずれか1つに加えられた変更を、他の全てのインスタンス内で反映させることが可能です。
  9. すべてのインスタンスに変更を加えます。
    1. メニューバーで、Tools > Optionsをクリックします。
    2. OptionsダイアログでBuild Model(ツリーの下部)をクリックします。


      図 4.
    3. Legacy Supportの下のCreate separate definitions when modifying a shared instanceオプションのチェックマークを外します。
      これで、インスタンスに変更を加えた際、別の定義を作成しなくても、その変更がすべてのインスタンスで反映されるようになります。
  10. OKをクリックします。
  11. MotionSolveの実行と結果のポスト処理を行います。
    1. (Run)パネルボタンをクリックします。
    2. パネル内で、End timeを1.0に、Print intervalを0.01と指定します。
    3. Run ボタンをクリックします。