DoubleBlockContinuousSystem.java
/**
* $Id$
*
* Copyright (C) 2004-2005 Koga Laboratory. All rights reserved.
*/
package org.mklab.tool.control.system.continuous;
import java.util.ArrayList;
import java.util.List;
import org.mklab.nfc.matrix.DoubleMatrix;
import org.mklab.nfc.ode.SolverStopException;
import org.mklab.tool.control.DoubleLinearSystem;
import org.mklab.tool.control.system.DoubleBlockSystem;
import org.mklab.tool.control.system.DoubleDynamicSystem;
import org.mklab.tool.control.system.DoubleLinearSystemOperator;
import org.mklab.tool.control.system.DoubleStaticSystem;
import org.mklab.tool.control.system.DoubleSystemOperator;
/**
* 連続な方程式で表現されるブロック連続時間システムを表わすクラスです。
*
* @author koga
* @version $Revision$
*/
public abstract class DoubleBlockContinuousSystem extends DoubleBlockSystem {
/** ノードの値を求める時刻 */
private double time;
/** 連続時間動的システムのリスト */
protected List<DoubleContinuousDynamicSystem> continuousDynamicSystems = new ArrayList<>();
/**
* 新しく生成された<code>BlockContinuousSystem</code>オブジェクトを初期化します。
*
* @param elements 隣接行列
* @param inputNodes 入力ノードの番号のリスト(番号は1から始まります)
* @param outputNodes 出力ノードの番号のリスト(番号は1から始まります)
*/
public DoubleBlockContinuousSystem(final DoubleSystemOperator[][] elements, final List<Integer> inputNodes, final List<Integer> outputNodes) {
super(elements, inputNodes, outputNodes);
setupContinuousDynamicSystems();
separateDirectFeedthroughAndNonDirectFeedthrough();
}
/**
* 連続時間動的システムのリストを設定します。
*/
private void setupContinuousDynamicSystems() {
this.continuousDynamicSystems.clear();
final int size = getNodeSize();
for (int row = 0; row < size; row++) {
for (int column = 0; column < size; column++) {
final DoubleSystemOperator system = getSystemOperator(row, column);
if (system instanceof DoubleContinuousDynamicSystem) {
this.continuousDynamicSystems.add((DoubleContinuousDynamicSystem)system);
}
}
}
}
/**
* ノードの値を計算します。
*
* @param t 時刻
* @exception SolverStopException ソルバーが停止された場合
*/
protected void calcNodeValue(final double t) throws SolverStopException {
this.time = t;
calcNodeValue();
}
/**
* {@inheritDoc}
*/
@Override
protected DoubleMatrix calcOutputOfDirectFeedthroughSystem(final DoubleSystemOperator system, final DoubleMatrix u) throws SolverStopException {
if (system instanceof DoubleDynamicSystem) {
final DoubleDynamicSystem dSystem = (DoubleDynamicSystem)system;
return dSystem.outputEquation(this.time, dSystem.getState(), u);
}
return ((DoubleStaticSystem)system).outputEquation(this.time, u);
}
/**
* {@inheritDoc}
*/
@Override
protected DoubleMatrix calcOutputOfNonDirectFeedthroughSystem(final DoubleSystemOperator system) throws SolverStopException {
if (system == null) throw new NullPointerException();
if (system instanceof DoubleDynamicSystem) {
final DoubleDynamicSystem dSystem = (DoubleDynamicSystem)system;
return dSystem.outputEquation(this.time, dSystem.getState());
}
return ((DoubleStaticSystem)system).outputEquation(this.time);
}
/**
* {@inheritDoc}
*/
@Override
protected DoubleSystemOperator createStrictlyProperLinearDynamicSystem(final DoubleSystemOperator system) {
final DoubleLinearSystem linearSystem = ((DoubleLinearSystemOperator)system).getLinearSystem();
final DoubleMatrix a = linearSystem.getA();
final DoubleMatrix b = linearSystem.getB();
final DoubleMatrix c = linearSystem.getC();
final DoubleContinuousLinearDynamicSystem newSystem = new DoubleContinuousLinearDynamicSystem(a, b, c);
newSystem.setInitialState(((DoubleContinuousLinearDynamicSystem)system).getInitialState());
return newSystem;
}
/**
* {@inheritDoc}
*/
@Override
protected boolean replaceDynamicSystemList(final DoubleSystemOperator oldSystem, final DoubleSystemOperator newSystem) {
final int index = this.continuousDynamicSystems.indexOf((DoubleContinuousDynamicSystem)oldSystem);
if (index == -1) {
return false;
}
this.continuousDynamicSystems.set(index, (DoubleContinuousDynamicSystem)newSystem);
return true;
}
}