OpenModelicaのBuildingsライブラリを学ぶ_その2
概要
OpenModelicaでLBNLのBuildingsライブラリを使う。初心者なのでいろいろ教えていただけるとありがたい。
チュートリアル SpaceCoolingの続きをやる。(あまりチュートリアル関係ないかも)
使用バージョン
-OpenModelica1.12.0 →たぶんModelica標準ライブラリ3.2.2
-Buildings 5.0.1
チュートリアル SpaceCoolingのSystem1の続き
前回は.moファイルを眺めてなんとなくの書き方を把握した。今回はもう少し理解を深める。
チュートリアル SpaceCoolingのSystem1は4つのモデルがコネクトされているモデルである。
* vol室(Buildings.Fluid.MixingVolumes.MixingVolume)
* theCon熱コンダクタンス(Modelica.Thermal.HeatTransfer.Components.ThermalConductor)
* TOut外気(Modelica.Thermal.HeatTransfer.Sources.FixedTemperature)
* preHea熱流(Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow)
室(vol)の中で発熱があり(preHea)、壁の熱伝導とか表面の熱伝達とか込みの熱コンダクタンスtheConを通して外気(TOut)へ熱が逃げているというモデルだと思う。 さらにvol以外はModelica標準ライブラリを使用している。ということでvolは後回しにして先に他のモデルを見る。
theCon
↓Modelica.Thermal.HeatTransfer.Components.ThermalConductor
model ThermalConductor "Lumped thermal element transporting heat without storing it" extends Interfaces.Element1D; parameter Modelica.SIunits.ThermalConductance G "Constant thermal conductance of material"; equation Q_flow = G*dT; annotation (省略);
熱コンダクタンスと温度差の乗算で熱流が求まるということだと思うがなんとなくしか分からない。
extends Interfaces.Element1Dとあり、Modelica.Thermal.HeatTransfer.Interfaces.Element1Dを継承しているようである。
Element1Dをみてみる。
↓Modelica.Thermal.HeatTransfer.Interfaces.Element1D
partial model Element1D "Partial heat transfer element with two HeatPort connectors that does not store energy" Modelica.SIunits.HeatFlowRate Q_flow "Heat flow rate from port_a -> port_b"; Modelica.SIunits.TemperatureDifference dT "port_a.T - port_b.T"; public HeatPort_a port_a annotation (Placement(transformation(extent={{-110,-10}, {-90,10}}))); HeatPort_b port_b annotation (Placement(transformation(extent={{90,-10},{ 110,10}}))); equation dT = port_a.T - port_b.T; port_a.Q_flow = Q_flow; port_b.Q_flow = -Q_flow; annotation (省略); end Element1D;
partial model Element1Dのpartialがよくわからないが、継承専用の型のモデルということだろうか。 変数はQ_flow、dT、port_a、port_b。publicってどういう要素なのだろう。書かなくても計算結果はみれるし、ポートだから必要というわけでもなさそうだし、他のモデルからコネクト以外のところで値を参照されるとわけがわからなくなりそうだし。とりあえず各要素をもう少し詳しく見る。 ↓Modelica.SIunits.HeatFlowRate
type HeatFlowRate = Real (final quantity="Power", final unit="W");
↓Modelica.SIunits.TemperatureDifference
type TemperatureDifference = Real ( final quantity="ThermodynamicTemperature", final unit="K") annotation(absoluteValue=false);
↓Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a
connector HeatPort_a "Thermal port for 1-dim. heat transfer (filled rectangular icon)" extends HeatPort; annotation(省略); end HeatPort_a;
↓Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_b
connector HeatPort_b "Thermal port for 1-dim. heat transfer (unfilled rectangular icon)" extends HeatPort; annotation(省略); end HeatPort_b;
↓Modelica.Thermal.HeatTransfer.Interfaces.HeatPort
partial connector HeatPort "Thermal port for 1-dim. heat transfer" Modelica.SIunits.Temperature T "Port temperature"; flow Modelica.SIunits.HeatFlowRate Q_flow "Heat flow rate (positive if flowing from outside into the component)"; annotation (省略); end HeatPort;
HeatPortの作りがややこしいけれどこういう書き方をするものなのか。aとbは色以外の違いが分からないと思っていたがどうやらそのようらしい。aが入力でbが出力みたいに使って計算の流れをつかみやすくしているだけで、たぶんbから入力するプログラムを作っても正常に動作はするのだろう。
あとポートの熱流は外からモデルの中へ向かう方向が正となるようにしましょうということらしい。熱流の方向はよく忘れるのですぐに確認出来るようにしたい。
基本的に変数は名称(final quantity)と単位(final unit)を指定しているだけと思っていたが温度はもう少し細かい設定があった。
Modelica.SIunits.Temperatureはtype Temperature = ThermodynamicTemperature;
となっており
↓Modelica.SIunits.ThermodynamicTemperature
type ThermodynamicTemperature = Real ( final quantity="ThermodynamicTemperature", final unit="K", min = 0.0, start = 288.15, nominal = 300, displayUnit="degC") "Absolute temperature (use type TemperatureDifference for relative temperatures)" annotation(absoluteValue=true);
最小値、初期値、デフォルト値?表示上の単位の切り替え選択肢を設定しているようである。単位の切り替えは図のようにできる。
TOut
↓Modelica.Thermal.HeatTransfer.Sources.FixedTemperature
model FixedTemperature "Fixed temperature boundary condition in Kelvin" parameter Modelica.SIunits.Temperature T "Fixed temperature at port"; Interfaces.HeatPort_b port annotation (Placement(transformation(extent={{90, -10},{110,10}}))); equation port.T = T; annotation (省略); end FixedTemperature;
port.TにTを固定値として設定してやるというシンプルなもの。
やはりbのポートは出力用、aのポートは入力用として使おうという暗黙の了解が感じられる。
port.Q_flowはリンク先の熱流をそのまま返すのだろうか。
preHea
↓Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow
model FixedHeatFlow "Fixed heat flow boundary condition" parameter Modelica.SIunits.HeatFlowRate Q_flow "Fixed heat flow rate at port"; parameter Modelica.SIunits.Temperature T_ref=293.15 "Reference temperature"; parameter Modelica.SIunits.LinearTemperatureCoefficient alpha=0 "Temperature coefficient of heat flow rate"; Interfaces.HeatPort_b port annotation (Placement(transformation(extent={{90, -10},{110,10}}))); equation port.Q_flow = -Q_flow*(1 + alpha*(port.T - T_ref)); annotation
↓Modelica.SIunits.LinearTemperatureCoefficient
type LinearTemperatureCoefficient = Real(final quantity = "LinearTemperatureCoefficient", final unit="1/K");
熱流はモデルから外へ出ていく方向が正になるように設定する。内容はTOutとだいたい同じかと思いきや違った。HeatPort_bにQ_flowを固定値として設定してやるだけでなくLinearTemperatureCoefficientのalphaとport.TとT_refとで熱流量に補正?をいれられるらしい。port.Tはリンク先の温度をそのまま返すのだろうか。あとT_ref=293.15はあとで打ちかえられるようなので定数ではなくデフォルト値という扱いである。
今日はここまで。Buildingsライブラリに全く触れずに標準ライブラリのモデルを見ているだけだった。ポートの仕様がよくわからんなぁ。。。それぞれのモデルで固定値を渡してしまったり、どちらも計算してなくて値が定義されなくなったりとか、エラーの元になる気がするんだがそういう場合は繋げないとかなってるのだろうか。もう少し細かい指定が出来ても良い気はした。
個々のモデルの作りがちょっと分かったような気がするがまだまだ理解が甘い。でもマニュアルゴリゴリ読むのはモチベーションが足りないのでなんとなく触りながら理解していく方針でがんばる。もう少し理解が進んだらいろいろ動作確認しないとだなぁ。
次はBuildings.Fluid.MixingVolumes.MixingVolumeの中身をみる予定。