Ticket #3754: a.mo

File a.mo, 5.3 KB (added by Martin Sjölund, 10 years ago)
Line 
1package Modelica
2 package Media
3 package Interfaces
4 partial package PartialMedium
5 extends Modelica.Media.Interfaces.Types;
6 constant Boolean reducedX = true;
7 constant MassFraction[nX] reference_X = fill(1 / nX, nX);
8 constant Temperature T_default = 20;
9 constant MassFraction[nX] X_default = reference_X;
10 final constant Integer nS = 2;
11 constant Integer nX = 2;
12 constant Integer nXi = if reducedX then nS - 1 else nS;
13
14 replaceable record ThermodynamicState end ThermodynamicState;
15
16 replaceable partial function setState_pTX
17 input AbsolutePressure p;
18 input Temperature T;
19 input MassFraction[:] X = reference_X;
20 output ThermodynamicState state;
21 end setState_pTX;
22 end PartialMedium;
23
24 partial package PartialMixtureMedium
25 extends PartialMedium;
26
27 redeclare replaceable record extends ThermodynamicState
28 AbsolutePressure p;
29 Temperature T;
30 MassFraction[nX] X;
31 end ThermodynamicState;
32 end PartialMixtureMedium;
33
34 partial package PartialCondensingGases
35 extends PartialMixtureMedium;
36 end PartialCondensingGases;
37
38 package Types
39 type AbsolutePressure = .Modelica.SIunits.AbsolutePressure(min = 0, max = 1.e8, nominal = 1.e5, start = 1.e5);
40 type MassFraction = Real(quantity = "MassFraction", final unit = "kg/kg", min = 0, max = 1, nominal = 0.1);
41 type Temperature = .Modelica.SIunits.Temperature(min = 1, max = 1.e4, nominal = 300, start = 300);
42 type ExtraProperty = Real(min = 0.0, start = 1.0);
43 end Types;
44 end Interfaces;
45
46 package Air
47 package MoistAir
48 extends .Modelica.Media.Interfaces.PartialCondensingGases(final reducedX = true, reference_X = {0.01, 0.99});
49
50 redeclare function setState_pTX
51 input AbsolutePressure p;
52 input Temperature T;
53 input MassFraction[:] X = reference_X;
54 output ThermodynamicState state;
55 algorithm
56 state := if size(X, 1) == nX then ThermodynamicState(p = p, T = T, X = X) else ThermodynamicState(p = p, T = T, X = cat(1, X, {1 - sum(X)}));
57 end setState_pTX;
58 end MoistAir;
59 end Air;
60 end Media;
61
62 package SIunits
63 type Volume = Real(final quantity = "Volume", final unit = "m3");
64 type Pressure = Real(final quantity = "Pressure", final unit = "Pa", displayUnit = "bar");
65 type AbsolutePressure = Pressure(min = 0.0, nominal = 1e5);
66 type MassFlowRate = Real(quantity = "MassFlowRate", final unit = "kg/s");
67 type ThermodynamicTemperature = Real(final quantity = "ThermodynamicTemperature", final unit = "K", min = 0.0, start = 288.15, nominal = 300, displayUnit = "degC");
68 type Temperature = ThermodynamicTemperature;
69 type MassFraction = Real(final quantity = "MassFraction", final unit = "1", min = 0, max = 1);
70 end SIunits;
71end Modelica;
72
73package Buildings
74 package Fluid
75 package MixingVolumes
76 model MixingVolume
77 extends Buildings.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume;
78 end MixingVolume;
79
80 package BaseClasses
81 partial model PartialMixingVolume
82 extends Buildings.Fluid.Interfaces.LumpedVolumeDeclarations;
83 parameter Boolean homotopyInitialization = true annotation(Evaluate = true);
84 parameter Modelica.SIunits.Volume V;
85 parameter Boolean prescribedHeatFlowRate = false annotation(Evaluate = true);
86 Modelica.SIunits.Temperature T;
87 Modelica.SIunits.Pressure p;
88 Modelica.SIunits.MassFraction[Medium.nXi] Xi;
89 protected
90 parameter Medium.ThermodynamicState state_start = Medium.setState_pTX(T = T_start, p = p_start, X = X_start[1:Medium.nXi]);
91 end PartialMixingVolume;
92 end BaseClasses;
93 end MixingVolumes;
94
95 package Interfaces
96 record LumpedVolumeDeclarations
97 replaceable package Medium = Modelica.Media.Interfaces.PartialMedium;
98 parameter Medium.AbsolutePressure p_start = 100;
99 parameter Medium.Temperature T_start = Medium.T_default;
100 parameter Medium.MassFraction[Medium.nX] X_start = Medium.X_default;
101 end LumpedVolumeDeclarations;
102 end Interfaces;
103 end Fluid;
104
105 package Media
106 package GasesPTDecoupled
107 package MoistAirUnsaturated
108 extends Modelica.Media.Interfaces.PartialCondensingGases(reference_X = {0.01, 0.99});
109
110 redeclare function setState_pTX
111 extends Buildings.Media.PerfectGases.MoistAir.setState_pTX;
112 end setState_pTX;
113 end MoistAirUnsaturated;
114 end GasesPTDecoupled;
115
116 package PerfectGases
117 package MoistAir
118 extends Modelica.Media.Interfaces.PartialCondensingGases(reference_X = {0.01, 0.99});
119
120 redeclare function setState_pTX
121 extends Modelica.Media.Air.MoistAir.setState_pTX;
122 end setState_pTX;
123 end MoistAir;
124 end PerfectGases;
125 end Media;
126
127 package Examples
128 package Tutorial
129 package Boiler
130 model System2
131 replaceable package MediumA = Buildings.Media.GasesPTDecoupled.MoistAirUnsaturated;
132 Fluid.MixingVolumes.MixingVolume vol(redeclare package Medium = MediumA);
133 end System2;
134 end Boiler;
135 end Tutorial;
136 end Examples;
137end Buildings;
138
139model System2_total
140 extends Buildings.Examples.Tutorial.Boiler.System2;
141end System2_total;