ohymosj
クラス SimpleDam

java.lang.Object
  拡張ohymosj.OhObject
      拡張ohymosj.OhElement
          拡張ohymosj.SimpleDam

public class SimpleDam
extends OhElement

SimpleDam. Simple dam model.

バージョン:
$Revision: 1.29 $ $Date: 2004/03/08 17:03:02 $
作成者:
satoh

フィールドの概要
protected  double[] _cRp
           
protected  int _dt
           
protected  int _numberOfRp
           
protected  double _qCrnt
           
protected  double _qInCrnt
           
protected  double _qInNext
           
protected  double _qNext
           
protected  double _qPass
           
protected  double _ratio
           
protected  OhReceiveDouble[] _rP
           
protected  OhSendDouble _sP0
           
protected  OhSendDouble _sP1
           
protected  double _storageCrnt
           
protected  double _storageNext
           
 
クラス ohymosj.OhElement から継承したフィールド
_calReqP, _currentTime, _dataString, _fixedTime, _initialWorkDoneP, _numberOfObjects, _numberOfReceivePorts, _numberOfSendPorts, _objectArray, _objectList, _receivePortArray, _sendPortArray, _shareInfoDoneP, _targetTime, _timeStep
 
クラス ohymosj.OhObject から継承したフィールド
_className, _objectName, _objectNumber, _owner, NEWLINE
 
コンストラクタの概要
SimpleDam()
           
SimpleDam(java.lang.String aObjName, int aObjNum, java.lang.String aDataStr, int aNrp)
           
 
メソッドの概要
 boolean calculate()
           1ステップ分の計算手続きを定義します。
 long calculateTimeStep()
           タイムステップの計算を行ないます。
 boolean canYouCalculate()
           計算開始の可・不可の判断をします。
 boolean init(java.lang.String aObjName, int aObjNum, OhBufferedReader aBr)
           構成要素のクラス名をファイルから読みとってつくりあげる部分系モデルで利用される コンストラクタの補助メソッドです。
 boolean init(java.lang.String aObjName, int aObjNum, java.lang.String aDataStr, int aNrp)
           
 boolean initialOutput()
           初期の出力を行ないます。
 void registerReceivePorts()
           派生クラスの全受信端子を登録します。
 void registerSendPorts()
           派生クラスの全送信端子を登録します。
 void saveParameter(java.io.PrintWriter aPw)
           
 void saveTerminalState(java.io.PrintWriter aPw)
           要素の最終状態を出力ストリーム os で指定されるファイルに書き込む作業をするメソッドです。
 void setInitialState(OhBufferedReader aBr)
           初期状態量を設定するメソッドを、各派生クラスに応じて定義します。
 void setParameter(OhBufferedReader aBr)
           パラメタを設定するメソッドを、各派生クラスに応じて定義します。
 boolean work()
           _currentime から OhTotalSystem.
 
クラス ohymosj.OhElement から継承したメソッド
areYouReady, calculateIterationStep, calReq, canYouCalculate0, canYouCalculate1, canYouGetDataString, canYouRenewCurrentTime, canYouSetObjectArray, canYouShareInfo, canYouSwitch, clearDataString, construct, create, doInitialWork, doShareInfo, doYouConverge, doYouReachTargetTime, flushData, getComponent, getComponent, getComponent, getComponent, getCurrentTime, getFixedTime, getFromArray, getFromArray, getFromList, getFromList, getInitialState, getMediumTermTargetTime, getNecessaryTimeFrom, getNecessaryTimeTo, getNextTime, getObject, getObject, getParameter, getReceivePort, getReceivePort, getReceivePort, getReceivePort, getSendPort, getSendPort, getSendPort, getSendPort, getTargetTime, getTerminalTime, getTimeStep, init, init, init, init, initializeTargetTime, initialWork, isInitialTime, makeObjectArray, printConnection, printConnection, printConnection, printConnection, printObjects, printReceivePorts, printReceivePorts, printReceivePorts, printReceivePorts, printSendPorts, printSendPorts, printSendPorts, printSendPorts, printStatus, recordStatus, reduceDataPackStock, register, register, renewFixedTime, renewTargetTime, restoreSendPortStock, rewindCurrentTime, saveSendPortStock, sendStockedData, setCur2Fix2Tar, setDataPackArray, terminalState, work0, work1, work2
 
クラス ohymosj.OhObject から継承したメソッド
cPrint, getAbsName, getClassName, getObjectName, getObjectNumber, getOwner, getTopOwner, objCompare, objCompare, objCompare, oPrint, setOwner
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

_rP

protected OhReceiveDouble[] _rP

_sP0

protected OhSendDouble _sP0

_sP1

protected OhSendDouble _sP1

_numberOfRp

protected int _numberOfRp

_qPass

protected double _qPass

_ratio

protected double _ratio

_dt

protected int _dt

_cRp

protected double[] _cRp

_storageCrnt

protected double _storageCrnt

_qCrnt

protected double _qCrnt

_storageNext

protected double _storageNext

_qNext

protected double _qNext

_qInCrnt

protected double _qInCrnt

_qInNext

protected double _qInNext
コンストラクタの詳細

SimpleDam

public SimpleDam()
          throws OhError

SimpleDam

public SimpleDam(java.lang.String aObjName,
                 int aObjNum,
                 java.lang.String aDataStr,
                 int aNrp)
          throws OhError
メソッドの詳細

init

public boolean init(java.lang.String aObjName,
                    int aObjNum,
                    java.lang.String aDataStr,
                    int aNrp)
             throws OhError
例外:
OhError

init

public boolean init(java.lang.String aObjName,
                    int aObjNum,
                    OhBufferedReader aBr)
             throws OhError
クラス OhElement の記述:
構成要素のクラス名をファイルから読みとってつくりあげる部分系モデルで利用される コンストラクタの補助メソッドです。 引数無しのコンストラクタで作成したあとに呼ばれることを想定しています。 例えば、className, objectName, objectNumber がファイルから読み取られているとし、 対象とするファイルのストリームを br とするとき、
  (OhElement)elm = (OhElement)Class.forName("ohymosj." + className).newInstance();
  elm.init(objectName, objectNum, br);
 
のようにして構成要素を割り当てます。

構成要素のクラス名をファイルから読みとってつくりあげる部分系モデルで 利用されるようにするためには、 このメソッドを定義しておく必要があります。

init(aObjName, aObjNum, aBr) が未定義の構成要素が呼ばれたときには、 例外 OhError が投げられます。

Initialization with the information which is given through a file.

オーバーライド:
クラス OhElement 内の init
パラメータ:
aObjName - a String value
aObjNum - an int value
aBr - an OhBufferedReader value
戻り値:
a boolean value
例外:
OhError - if an error occurs

registerReceivePorts

public void registerReceivePorts()
                          throws OhError
クラス OhElement の記述:
派生クラスの全受信端子を登録します。

このメソッドは、派生クラスの全受信端子を OhElement.register(Object) OhElement.register(Object, int) により登録します。

登録されていない端子は接続できないので送受信に利用できません。

例えば、派生クラスで受信端子 abc を定義した場合、

  public void registerReceivePort() {
    register((Object) abc);
  }
 
とすれば、abc を受信端子として登録できます。

Declares method registerReceivePorts() as abstract method. In classes derived from class Element, its definition should be given.

"registerReceivePorts()" registers all the receiving ports of an inherited class, and all sending ports by OhElement.register(Object) OhElement.register(Object, int).

The port which is not registered is not applicable to sending and receiving, since it is not connectable.
For example, when an inherited class defines the receiving port "abc", if it is performed as follows, "abc" can be registered as a receiving terminal.

   void registerReceivePort() {
     register((Object)abc);
   }
 

定義:
クラス OhElement 内の registerReceivePorts
例外:
OhError - if an error occurs

registerSendPorts

public void registerSendPorts()
                       throws OhError
クラス OhElement の記述:
派生クラスの全送信端子を登録します。

このメソッドは、派生クラスの全送信端子を OhElement.register(Object) OhElement.register(Object, int) により登録します。

登録されていない端子は接続できないので送受信に利用できません。

例えば、派生クラスで送信端子 abc を定義した場合、

  public void registerSendPort() {
    register((Object) abc);
  }
 
とすれば、abc を送信端子として登録できます。

Declares method "registerSendPorts() as abstract method. In classes derived from class Element, its definition should be given.

"registerSendPorts()" registers all the receiving ports of an inherited class, and all sending ports by OhElement.register(Object) OhElement.register(Object, int).

The port which is not registered is not applicable to sending and receiving, since it is not connectable. For example, when an inherited class defines the receiving port "abc", if it is performed as follows, "abc" can be registered as a receiving terminal.

   void registerSendPort() {
     register((Object)abc);
   }
 

定義:
クラス OhElement 内の registerSendPorts
例外:
OhError - if an error occurs

setParameter

public void setParameter(OhBufferedReader aBr)
                  throws OhError
クラス OhElement の記述:
パラメタを設定するメソッドを、各派生クラスに応じて定義します。 入力ストリーム aBr で指定されるファイルからデータを読みとってパラメタを設定します。

Declares method "setParameter()" as abstract method. In classes derived from class Element, its definition should be given.

Parameters are read in the input stream "aBr". It is necessary to create an element model according to each inherited class. Data is read in the file specified by the input stream "aBr", and the amount of initial states is set up.

Please have the program and consistency which save the last state at a file.

定義:
クラス OhElement 内の setParameter
パラメータ:
aBr - a OhBufferedReader value
例外:
OhError - if an error occurs

saveParameter

public void saveParameter(java.io.PrintWriter aPw)

setInitialState

public void setInitialState(OhBufferedReader aBr)
                     throws OhError
クラス OhElement の記述:
初期状態量を設定するメソッドを、各派生クラスに応じて定義します。 入力ストリーム aBr で指定されるファイルからデータを読みとって初期状態量を設定します。

最終状態をファイルに保存するプログラムとつじつまがあうようにしてください。

Declares method "setInitialState()" as abstract method. In classes derived from class Element, its definition should be given.

The method which sets up the amount of initial states is defined according to each inherited class.

定義:
クラス OhElement 内の setInitialState
パラメータ:
aBr - a OhBufferedReader value
例外:
OhError - if an error occurs

saveTerminalState

public void saveTerminalState(java.io.PrintWriter aPw)
クラス OhElement の記述:
要素の最終状態を出力ストリーム os で指定されるファイルに書き込む作業をするメソッドです。 ユーザが定義する要素モデルでは、このメソッドを必ず定義しなければなりません。

最終状態を書き込む仕様は次のようにしてください。

 (data_string)
 

This is the method which does the work which writes the last state of an element in the file specified by the output stream "aBr".

In classes derived from class Element, its definition should be given.

定義:
クラス OhElement 内の saveTerminalState
パラメータ:
aPw - a PrintWriter value

initialOutput

public boolean initialOutput()
                      throws OhError
クラス OhElement の記述:
初期の出力を行ないます。

初期状態量を決めた直後に、_currentTime での出力を定義します。 送信端子に時刻と出力値を書き込みます。 _currnetTime での出力が計算できた場合は true を返します。 必要な入力データが得られていないなどして、 _currentTime の出力が計算できなかった場合は false を返します。

要素によっては、setInitialState() の中で 初期の出力をするようにした方が都合がよいかも知れません。 たとえば、初期値設定のために与えられる文字列によって、 初期の出力のやり方を変えたりする場合などです。 そうした場合は、initialOutput() は何もしないように定義して、 setInitialState() で初期の出力をするように定義しても構いません。

An initial output. In classes derived from class Element, its definition should be given.

The output in "_currentTime" is defined immediately after deciding the amount of initial states. Time and an output value are written in a sending port. "true" is returned when the output in "_currentTime" is able to be calculated. "false" is returned when the output of "_currentTime" is not able to be calculated by required input data not being obtained.

定義:
クラス OhElement 内の initialOutput
戻り値:
a boolean value
例外:
OhError - if an error occurs

calculateTimeStep

public long calculateTimeStep()
                       throws OhError
クラス OhElement の記述:
タイムステップの計算を行ないます。

各派生クラスでモデルに応じて _timeStep [sec] を計算し、 戻り値として返すメソッドを定義して下さい。

つまり、_timeStep をどのような条件下で、どのような値にするかを定義します。

例えば、_timeStep を一定値 3600 [sec] に設定する場合、

  public long calculateTimeStep() {
    return 3600;
  }
 
と定義して下さい。

また、下記のようにメンバ変数 _k の値により _timeStep を変更することもできます。

  public long calculateTimeStep() {
    return (_k > 0) ? 360 : 60;
  }

  public long calculateTimeStep() {
    return 360 * pow(10, _k);
  }
 
_timeStep は、work() の中で設定されるので、
  public long calculateTimeStep() {
    _timeStep = 1;
    return 1;
  }
 
のように、このメソッドの中で変更しないでください。

抽象メソッドなので、派生クラスで必ず定義して下さい。

戻り値: 次回の計算のタイムステップ。[sec]

Calculation of a time step. In classes derived from class Element, its definition should be given.

Please calculate "_timeStep" according to a model in each inherited class, and define the method which returns it as a return value. That is, it defines under what conditions "_timeStep" is made into what value.

定義:
クラス OhElement 内の calculateTimeStep
戻り値:
a long value
例外:
OhError - if an error occurs

canYouCalculate

public boolean canYouCalculate()
                        throws OhCannotGetDataError,
                               OhError
クラス OhElement の記述:
計算開始の可・不可の判断をします。

まず、_currentTime が _terminalTime 以上の場合、計算済みと判断し false を返します。

次に、全ての所有受信端子が getNecessaryTimeFrom(), getNecessaryTimeTo() 間の データパックを取得可能であることを確認します。 取得可能な場合、計算実行可能と判断して true を返します。 取得不可能な場合、計算実行不可と判断して false を返します。

データが取得不可能であると返事をしてきた受信端子に対して計算要求を出します。 具体的には、受信端子に calReq() メッセージを送ります。

 [戻り値]
  ・true --> 計算実行可能の場合。
  ・false -> 計算実行不可能の場合、または計算済みの場合。
 

Judgment whether calculation can be started or not. In classes derived from class Element, its definition should be given.

First, when "_currentTime" is more than "_terminalTime", it is judged that calculation has finished, and "false" is returned.

Next, it checks that all possession receiving ports can acquire the data pack between "getNecessaryTimeFrom" and "getNecessaryTimeTo". It is judged that calculation execution is possible the case of being acquirable, "true" is returned. It is judged that calculation execution is impossible the case of being unacquirable, "false" is returned.

A calculation request is advanced to the receiving port which will have replied that data is unacquirable. In particular, a calculation request message is sent to a receiving port.

 [RETURN]
  ・true --> When calculation execution is possible.
  ・false -> When calculation execution is impossible.
              When calculation has finished.
 

定義:
クラス OhElement 内の canYouCalculate
戻り値:
a boolean value
例外:
OhCannotGetDataError - if an error occurs
OhError - if an error occurs

work

public boolean work()
             throws OhCannotGetDataError,
                    OhError
クラス OhElement の記述:
_currentime から OhTotalSystem._terminalTime 間の計算アルゴリズムを定義します。

calculate(), calculateTimeStep() などを用いて、_terminalTime までの計算を実行します。

まず、 OhElement.canYouCalculate() の戻り値が false ならば、計算開始不可と判断し、false を返します。

戻り値が true の場合は、 true である限り、 OhElement.calculate(), _currentTime.add(_timeStep) を繰り返し実行します。

最後に、 OhElement.setDataPackArray(), を実行し、true を返します。

 
 [戻り値]
  ・true --> 計算を実行した場合。
  ・false -> 計算不可能の場合、または計算済みの場合。
 

Calculate between "_currentTime" and "_terminalTime". In classes derived from class Element, its definition should be given.

Calculation by "_terminalTime" is performed using "calculate()", "calculateTimeStep()", etc.

First, if return value of "canYouCalculate()" becomes "false", it will be judged that a calculation start is impossible, "false" is returned.

When the return value is "true", "calculate()" and "_currentTime += _timeStep" are repeated and performed, as long as the return value of "canYouCalculate" is "true".

Finally, "setDataPackArray()" and "reportToSender()" are performed and "true" is returned.

 [RETURN]
  ・true --> When calculation was performed.
  ・false -> When calculation is impossible.
              When calculation has finished.
 

定義:
クラス OhElement 内の work
戻り値:
a boolean value
例外:
OhCannotGetDataError - if an error occurs
OhError - if an error occurs

calculate

public boolean calculate()
                  throws OhError
クラス OhElement の記述:
1ステップ分の計算手続きを定義します。

各ユーザが独自の要素モデルを作成する際、1ステップ分の計算手続きを定義して下さい。 一般的な要素では、

  • 最初、各状態量には _currentTime における値が格納されている。
  • ここでは _currentTime + _timeStep における状態量, 出力値を計算する。
  • このメソッド終了後、状態量は _currentTime + _timeStep における値に更新されている。
の3点を満足するように、下記の (1) から (4) を順に記述して下さい。
  (1) 受信端子からの入力。
  (2) 数理計算。
  (3) 送信端子への出力。
  (4) 状態量の更新。
 
(2) では、パラメータ、_currentTime における状態量、受信端子からの入力を用い、 _currentTime + _timeStep における状態量、送信すべき出力値を計算する数理モデルの1ステップ分を 具体的に定義して下さい。

このメソッドの中で _currentTime, _timeStep を変更しないで下さい。 必要ならば _timeStep を更に細かい時間区分に分割して計算できますが、 この時は作業用変数を用い、_currentTime, _timeStep を変更しないように注意して下さい。

計算に必要な全ての数値は、データメンバ及び所有受信端子からの入力として取得できます。 従って引数は不要です。

予定通り計算できた場合は、true を返します。 calculate() の内部で計算時間ステップを計算し、 その計算時間ステップ分のデータを取得できないなどして、 計算を進めることができなかった場合は、false を返します。

抽象メソッドなので、派生クラスで必ず定義して下さい。

 [ACCIDENT]
  ・このメソッドの中で _currentTime, _timeStep が変更された場合。
 

Calculation procedure for 1 step. In classes derived from class Element, its definition should be given.

In a general element, Please describe following (1) to (4) in order to fulfill these 3 points.
  (1) the input from a receiving port.
  (2) numerical computation.
  (3) the output to a sending port.
  (4) updating of the amount of states.
 
At (2), by using parameters, the amount of states in "_currentTime" , and the input from a receiving ports, please define concretely one step of a numerical model which calculate the amount of states and the output value which should be transmitted in "_currentTime + _timeStep".

In this method, please do not change "_currentTime" and "_timeStep".

All numerical values required for calculation are acquirable as instance variable and input from a possession receiving port. Therefore, arguments are unnecessary.

The case where it is calculable as planned, "true" is returned. When a calculation time step is calculated inside "calculate()", the data for the calculation time step cannot be acquired and calculation is not able to be advanced, "false" is returned.

定義:
クラス OhElement 内の calculate
戻り値:
a boolean value
例外:
OhError - if an error occurs