Found an issue with the book? Report it on Github.

전파(Propagation)

전파(Propagation)

하위 시스템 모델을 구축할 때 하위 시스템이 파라미터를 포함하는 것이 매우 일반적이며, 이 파라미터는 해당 구성 요소로 전파되거나 종속됩니다.예를 들어, 기본 회전 구성요소(Basic Rotational Components) 에 대한 논의에서 사용된 다음 시스템 모델을 살펴 보겠습니다.

within ModelicaByExample.Components.Rotational.Examples;
model SMD
  Components.Damper damper2(d=1);
  Components.Ground ground;
  Components.Spring spring2(c=5);
  Components.Inertia inertia2(J=1,
    phi(fixed=true, start=1),
    w(fixed=true, start=0));
  Components.Damper damper1(d=0.2);
  Components.Spring spring1(c=11);
  Components.Inertia inertia1(
    J=0.4,
    phi(fixed=true, start=0),
    w(fixed=true, start=0));
equation
  // ...
end SMD;

d 와 같은 구성 요소 파라미터의 값이 다를 수 있는 다른 컨텍스트에서 이 모델을 사용하려면 d 를 하위 시스템 수준에서 파라미터로 만든 다음 전파할 수 있으며, 수정을 통해서 각 계층 구조로 내려갑니다.결과는 다음과 같습니다.

within ModelicaByExample.Components.Rotational.Examples;
model SMD
  import Modelica.SIunits.*;
  parameter RotationalDampingConstant d;
  Components.Damper damper2(d=d);
  // ...

여기에 하나의 종합적인 문제가 있습니다.``SMD`` 모델에서 d 파라미터를 수정하는 대신 사용자가 와서 damper2.d 값을 변경할 수 있습니다. d 파라미터와 damper2.d 파라미터가 동기화되지 않는 것(다른 값을 가짐)을 방지하기 위해 final 한정자를 사용하여 영구적으로 바인딩할 수 있습니다.

within ModelicaByExample.Components.Rotational.Examples;
model SMD
  import Modelica.SIunits.*;
  parameter RotationalDampingConstant d;
  Components.Damper damper2(final d=d);
  // ...

final 한정자를 추가하여 damper2.d 값을 더 이상 수정할 수 없음을 나타냅니다.모든 수정은 d 에만 적용되어야 합니다.

SMD 모델의 모든 "하드 와이어드(hard-wired)" 숫자 값을 동일하게 처리하면 다음과 같이 재사용 가능성이 높은 모델이 됩니다.

within ModelicaByExample.Components.Rotational.Examples;
model SMD
  import Modelica.SIunits.*;

  parameter RotationalDampingConstant d1, d2;
  parameter RotationalSpringConstant c1, c2;
  parameter Inertia J1, J2;
  parameter Angle phi1_init=0, phi2_init=0;
  parameter AngularVelocity w1_init=0, w2_init=0;

  Components.Damper damper2(final d=d2);
  Components.Ground ground;
  Components.Spring spring2(final c=c2);
  Components.Inertia inertia2(
    final J=J2,
    phi(fixed=true, final start=phi2_init),
    w(fixed=true, final start=w2_init));
  Components.Damper damper1(final d=d1);
  Components.Spring spring1(final c=c1);
  Components.Inertia inertia1(
    final J=J1,
    phi(fixed=true, final start=phi1_init),
    w(fixed=true, final start=w1_init));
equation
  // ...
end SMD;

특정 파라미터 값 집합을 사용하려는 경우 두 가지 방법 중 하나로 수행할 수 있습니다.한 가지 방법은 위의 파라미터화된 모델을 확장하고 extends 문에 수정 사항을 포함하는 것입니다. 를 들면 아래와 같습니다.

model SpecificSMD
  extends SMD(d2=1, c2=5, J2=1,
              d1=0.5, c1=11, J1=0.4,
              phi1_init=1);

phi2_init, w1_initw2_init 값에 대한 수정 사항을 포함할 필요가 없는데, 이러한 파라미터는 기본값으로 선언되었기 때문입니다. 일반적으로 파라미터의 기본값은 대부분의 경우에 해당 기본값이 합리적인 경우에만 사용해야 합니다. 그 이유는 파라미터에 기본값이 없으면 대부분의 모델리카 컴파일러가 값이 필요하다는 경고를 생성하기 때문입니다. 그러나 기본값이 있으면 자동으로 기본값을 사용합니다. 해당 기본값이 합리적이거나 일반적이지 않은 경우 모델에 비합리적인 값을 자동으로 적용 합니다.

전파 주제로 돌아가서 사용할 수 있는 다른 접근 방식은 SMD 모델의 인스턴스를 인스턴스화하고 선언된 변수에 대한 수정을 사용하여 파라미터 값을 지정하는 것입니다.

SMD mysmd(d2=1, c2=5, J2=1,
          d1=0.5, c1=11, J1=0.4,
          phi1_init=1);

이러한 접근 방식 중 어느 것이 더 나은지에 대한 논의는 아키텍처(Architectures) 에 대한 다음 장으로 미룰 것입니다.