├── .gitignore ├── AirHeatExchanger.m ├── Boiler.m ├── Bridge.m ├── Chiller.m ├── Constant.m ├── FanCoil.m ├── HeatExchanger.m ├── LICENSE ├── Mixer.m ├── Pipe.m ├── README.md ├── Radiator.m ├── Same.m ├── SetpointController.m ├── Solver.m ├── Zone.m └── docs ├── airheatexchanger └── eqs.png ├── boiler ├── eqs.png └── schematic.png ├── chiller └── eqs.png ├── fancoil └── eqs.png ├── heatexchanger └── eqs.png ├── mixer ├── eqs.png └── schematic.png ├── pipe ├── eqs.png └── schematic.png ├── radiator ├── eqs.png └── schematic.png ├── solver └── eqs.png └── zone └── eqs.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows default autosave extension 2 | *.asv 3 | 4 | # OSX / *nix default autosave extension 5 | *.m~ 6 | 7 | # Compiled MEX binaries (all platforms) 8 | *.mex* 9 | 10 | # Packaged app and toolbox files 11 | *.mlappinstall 12 | *.mltbx 13 | 14 | # Generated helpsearch folders 15 | helpsearch*/ 16 | 17 | # Simulink code generation folders 18 | slprj/ 19 | sccprj/ 20 | 21 | # Matlab code generation folders 22 | codegen/ 23 | 24 | # Simulink autosave extension 25 | *.autosave 26 | 27 | # Simulink cache files 28 | *.slxc 29 | 30 | # Octave session info 31 | octave-workspace 32 | 33 | # App 34 | *.mlapp 35 | 36 | # others 37 | main.m 38 | HeatingClass.m -------------------------------------------------------------------------------- /AirHeatExchanger.m: -------------------------------------------------------------------------------- 1 | classdef AirHeatExchanger 2 | properties 3 | iteration 4 | id_supply_inlet 5 | id_supply_outlet 6 | id_exhaust_inlet 7 | id_exhaust_outlet 8 | time_step 9 | matrix_size 10 | matrix_coefficients 11 | right_hand_side_vector 12 | number_of_equations 13 | 14 | specific_heat_capacity_supply 15 | specific_heat_capacity_exhaust 16 | mass_flow_rate_supply_nominal 17 | mass_flow_rate_supply 18 | mass_flow_rate_exhaust 19 | sensible_effectiveness_75 20 | sensible_effectiveness_100 21 | latent_effectiveness_75 22 | latent_effectiveness_100 23 | 24 | ratio_air_flow_rate_to_nominal 25 | operating_sensible_effectiveness 26 | operating_latent_effectiveness 27 | heating_capacitance_flows_supply 28 | heating_capacitance_flows_exhaust 29 | heating_capacitance_flows_minimum 30 | 31 | temperature_supply_inlet 32 | temperature_supply_outlet 33 | temperature_exhaust_inlet 34 | temperature_exhaust_outlet 35 | 36 | end 37 | 38 | methods 39 | function obj = AirHeatExchanger(id_supply_inlet, id_supply_outlet, id_exhaust_inlet, id_exhaust_outlet, solver, mass_flow_rate_supply_nominal, specific_heat_capacity_supply, specific_heat_capacity_exhaust, mass_flow_rate_supply, mass_flow_rate_exhaust, sensible_effectiveness_75, sensible_effectiveness_100, latent_effectiveness_75, latent_effectiveness_100) 40 | if nargin > 0 41 | obj.id_supply_inlet = id_supply_inlet; 42 | obj.id_supply_outlet = id_supply_outlet; 43 | obj.id_exhaust_inlet = id_exhaust_inlet; 44 | obj.id_exhaust_outlet = id_exhaust_outlet; 45 | obj.time_step = solver.time_step; 46 | obj.matrix_size = solver.matrix_size; 47 | obj.specific_heat_capacity_supply = specific_heat_capacity_supply; 48 | obj.specific_heat_capacity_exhaust = specific_heat_capacity_exhaust; 49 | obj.mass_flow_rate_supply_nominal = mass_flow_rate_supply_nominal; 50 | obj.mass_flow_rate_supply = mass_flow_rate_supply; 51 | obj.mass_flow_rate_exhaust = mass_flow_rate_exhaust; 52 | obj.sensible_effectiveness_75 = sensible_effectiveness_75; 53 | obj.sensible_effectiveness_100 = sensible_effectiveness_100; 54 | obj.latent_effectiveness_75 = latent_effectiveness_75; 55 | obj.latent_effectiveness_100 = latent_effectiveness_100; 56 | 57 | obj.ratio_air_flow_rate_to_nominal = mean(obj.mass_flow_rate_supply, obj.mass_flow_rate_exhaust)/obj.mass_flow_rate_supply_nominal; 58 | obj.operating_sensible_effectiveness = obj.sensible_effectiveness_75 + (obj.sensible_effectiveness_100 - obj.sensible_effectiveness_75)*(obj.ratio_air_flow_rate_to_nominal - 0.75)/0.25; 59 | obj.operating_latent_effectiveness = obj.latent_effectiveness_75 + (obj.latent_effectiveness_100 - obj.latent_effectiveness_75)*(obj.ratio_air_flow_rate_to_nominal - 0.75)/0.25; 60 | obj.heating_capacitance_flows_supply = obj.specific_heat_capacity_supply*obj.mass_flow_rate_supply; 61 | obj.heating_capacitance_flows_exhaust = obj.specific_heat_capacity_exhaust*obj.mass_flow_rate_exhaust; 62 | obj.heating_capacitance_flows_minimum = min(obj.heating_capacitance_flows_supply, obj.heating_capacitance_flows_exhaust); 63 | 64 | obj.iteration = 0; 65 | obj.number_of_equations = 2; 66 | obj.matrix_coefficients = zeros(obj.number_of_equations,solver.matrix_size); 67 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 68 | 69 | obj.temperature_supply_inlet = solver.temperatures(id_supply_inlet); 70 | obj.temperature_supply_outlet = solver.temperatures(id_supply_outlet); 71 | obj.temperature_exhaust_inlet = solver.temperatures(id_exhaust_inlet); 72 | obj.temperature_exhaust_outlet = solver.temperatures(id_exhaust_outlet); 73 | end 74 | end 75 | 76 | function c = c_tsi1(obj) 77 | c = 1 - obj.operating_sensible_effectiveness*obj.heating_capacitance_flows_minimum/obj.heating_capacitance_flows_supply; 78 | end 79 | 80 | function c = c_tso1(~) 81 | c = - 1; 82 | end 83 | 84 | function c = c_tei1(obj) 85 | c = obj.operating_sensible_effectiveness*obj.heating_capacitance_flows_minimum/obj.heating_capacitance_flows_supply; 86 | end 87 | 88 | function c = c_tsi2(obj) 89 | c = obj.heating_capacitance_flows_supply/obj.heating_capacitance_flows_exhaust; 90 | end 91 | 92 | function c = c_tso2(obj) 93 | c = obj.heating_capacitance_flows_supply/obj.heating_capacitance_flows_exhaust; 94 | end 95 | 96 | function c = c_tei2(~) 97 | c = 1; 98 | end 99 | 100 | function c = c_teo2(~) 101 | c = -1; 102 | end 103 | 104 | % create matrix of coefficients and right-hand side vector 105 | function obj = create(obj, solver) 106 | obj.iteration = obj.iteration + 1; 107 | obj.matrix_coefficients = zeros(obj.number_of_equations,obj.matrix_size); 108 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 109 | obj.temperature_supply_inlet = solver.temperatures(obj.id_supply_inlet); 110 | obj.temperature_supply_outlet = solver.temperatures(obj.id_supply_outlet); 111 | obj.temperature_exhaust_inlet = solver.temperatures(obj.id_exhaust_inlet); 112 | obj.temperature_exhaust_outlet = solver.temperatures(obj.id_exhaust_outlet); 113 | obj.matrix_coefficients(1,obj.id_supply_inlet) = obj.c_tsi1(); 114 | obj.matrix_coefficients(1,obj.id_supply_outlet) = obj.c_tso1(); 115 | obj.matrix_coefficients(1,obj.id_exhaust_inlet) = obj.c_tei1(); 116 | obj.matrix_coefficients(2,obj.id_supply_inlet) = obj.c_tsi2(); 117 | obj.matrix_coefficients(2,obj.id_supply_outlet) = obj.c_tso2(); 118 | obj.matrix_coefficients(2,obj.id_exhaust_inlet) = obj.c_tei2(); 119 | obj.matrix_coefficients(2,obj.id_exhaust_outlet) = obj.c_teo2(); 120 | end 121 | 122 | end 123 | end -------------------------------------------------------------------------------- /Boiler.m: -------------------------------------------------------------------------------- 1 | classdef Boiler 2 | properties 3 | iteration 4 | id_inlet 5 | id_outlet 6 | time_step 7 | matrix_size 8 | matrix_coefficients 9 | right_hand_side_vector 10 | number_of_equations 11 | 12 | specific_heat_capacity 13 | mass 14 | specific_heat_capacity_fluid 15 | mass_fluid 16 | power 17 | temperature_inlet 18 | temperature_outlet 19 | mass_flow_rate 20 | status 21 | end 22 | 23 | methods 24 | function obj = Boiler(id_inlet, id_outlet, solver, specific_heat_capacity, mass, specific_heat_capacity_fluid, mass_fluid, power, mass_flow_rate, status) 25 | if nargin > 0 26 | obj.id_inlet = id_inlet; 27 | obj.id_outlet = id_outlet; 28 | obj.time_step = solver.time_step; 29 | obj.matrix_size = solver.matrix_size; 30 | 31 | obj.specific_heat_capacity = specific_heat_capacity; 32 | obj.mass = mass; 33 | obj.specific_heat_capacity_fluid = specific_heat_capacity_fluid; 34 | obj.mass_fluid = mass_fluid; 35 | obj.power = power; 36 | obj.mass_flow_rate = mass_flow_rate; 37 | obj.status = status; 38 | 39 | obj.iteration = 0; 40 | obj.number_of_equations = 1; 41 | obj.matrix_coefficients = zeros(obj.number_of_equations,solver.matrix_size); 42 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 43 | obj.temperature_inlet = solver.temperatures(obj.id_inlet); 44 | obj.temperature_outlet = solver.temperatures(obj.id_outlet); 45 | end 46 | end 47 | 48 | % coefficient of inlet temperature of boiler (return fluid) 49 | function c = c_ti(obj) 50 | c = (obj.mass*obj.specific_heat_capacity+obj.mass_fluid*obj.specific_heat_capacity_fluid)/(2*obj.time_step)-obj.mass_flow_rate*obj.specific_heat_capacity_fluid; 51 | end 52 | 53 | % coefficient of outlet temperature of boiler (supply fluid) 54 | function c = c_to(obj) 55 | c = (obj.mass*obj.specific_heat_capacity+obj.mass_fluid*obj.specific_heat_capacity_fluid)/(2*obj.time_step)+obj.mass_flow_rate*obj.specific_heat_capacity_fluid; 56 | end 57 | 58 | % right-hand coefficient of boiler 59 | function c = c_r(obj) 60 | c = obj.power + (obj.mass*obj.specific_heat_capacity+obj.mass_fluid*obj.specific_heat_capacity_fluid)/(2*obj.time_step)*(obj.temperature_inlet + obj.temperature_outlet); 61 | end 62 | 63 | % create matrix of coefficients and right-hand side vector 64 | function obj = create(obj, solver) 65 | obj.iteration = obj.iteration + 1; 66 | obj.temperature_inlet = solver.temperatures(obj.id_inlet); 67 | obj.temperature_outlet = solver.temperatures(obj.id_outlet); 68 | obj.matrix_coefficients = zeros(obj.number_of_equations,obj.matrix_size); 69 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 70 | obj.right_hand_side_vector = obj.c_r(); 71 | obj.matrix_coefficients(obj.id_inlet) = obj.c_ti(); 72 | obj.matrix_coefficients(obj.id_outlet) = obj.c_to(); 73 | end 74 | 75 | function obj = switch_off(obj) 76 | obj.status = 0; 77 | end 78 | 79 | function obj = switch_on(obj) 80 | obj.status = 1; 81 | end 82 | 83 | end 84 | end 85 | 86 | -------------------------------------------------------------------------------- /Bridge.m: -------------------------------------------------------------------------------- 1 | classdef Bridge 2 | properties 3 | iteration 4 | id 5 | id_bridge 6 | solver 7 | solver_bridge 8 | 9 | time_step 10 | matrix_size 11 | matrix_coefficients 12 | right_hand_side_vector 13 | number_of_equations 14 | 15 | end 16 | 17 | methods 18 | function obj = Bridge(id, id_bridge, solver, solver_bridge) 19 | if nargin > 0 20 | obj.id = id; 21 | obj.id_bridge = id_bridge; 22 | obj.solver = solver; 23 | obj.solver_bridge = solver_bridge; 24 | obj.time_step = solver.time_step; 25 | obj.matrix_size = solver.matrix_size; 26 | 27 | obj.iteration = 0; 28 | obj.number_of_equations = 1; 29 | obj.matrix_coefficients = zeros(obj.number_of_equations,solver.matrix_size); 30 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 31 | 32 | end 33 | end 34 | 35 | % create matrix of coefficients and right-hand side vector 36 | function obj = create(obj, solver) 37 | obj.iteration = obj.iteration + 1; 38 | obj.matrix_coefficients = zeros(obj.number_of_equations,obj.matrix_size); 39 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 40 | obj.right_hand_side_vector = obj.solver_bridge.temperatures(obj.id_bridge); 41 | obj.matrix_coefficients(obj.id) = 1; 42 | end 43 | 44 | end 45 | end -------------------------------------------------------------------------------- /Chiller.m: -------------------------------------------------------------------------------- 1 | classdef Chiller 2 | properties 3 | iteration 4 | id_condenser_inlet 5 | id_condenser_outlet 6 | id_evaporator_inlet 7 | id_evaporator_outlet 8 | time_step 9 | matrix_size 10 | matrix_coefficients 11 | right_hand_side_vector 12 | number_of_equations 13 | 14 | specific_heat_capacity_fluid 15 | power 16 | coefficient_of_performance 17 | mass_flow_rate_condenser 18 | mass_flow_rate_evaporator 19 | temperature_condenser_inlet 20 | temperature_condenser_outlet 21 | temperature_evaporator_inlet 22 | temperature_evaporator_outlet 23 | status 24 | end 25 | 26 | methods 27 | function obj = Chiller(id_condenser_inlet, id_condenser_outlet, id_evaporator_inlet, id_evaporator_outlet, solver, specific_heat_capacity_fluid, power, coefficient_of_performance, mass_flow_rate_condenser, mass_flow_rate_evaporator, status) 28 | if nargin > 0 29 | obj.id_condenser_inlet = id_condenser_inlet; 30 | obj.id_condenser_outlet = id_condenser_outlet; 31 | obj.id_evaporator_inlet = id_evaporator_inlet; 32 | obj.id_evaporator_outlet = id_evaporator_outlet; 33 | obj.time_step = solver.time_step; 34 | obj.matrix_size = solver.matrix_size; 35 | 36 | obj.specific_heat_capacity_fluid = specific_heat_capacity_fluid; 37 | obj.power = power; 38 | obj.mass_flow_rate_condenser = mass_flow_rate_condenser; 39 | obj.mass_flow_rate_evaporator = mass_flow_rate_evaporator; 40 | obj.coefficient_of_performance = coefficient_of_performance; 41 | obj.status = status; 42 | 43 | obj.iteration = 0; 44 | obj.number_of_equations = 2; 45 | obj.matrix_coefficients = zeros(obj.number_of_equations,solver.matrix_size); 46 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 47 | obj.temperature_condenser_inlet = solver.temperatures(obj.id_condenser_inlet); 48 | obj.temperature_condenser_outlet = solver.temperatures(obj.id_condenser_outlet); 49 | obj.temperature_evaporator_inlet = solver.temperatures(obj.id_evaporator_inlet); 50 | obj.temperature_evaporator_outlet = solver.temperatures(obj.id_evaporator_outlet); 51 | end 52 | end 53 | 54 | % evaporator inlet temperature coefficient (Eq 1) 55 | function c = c_tei1(obj) 56 | c = obj.mass_flow_rate_evaporator*obj.specific_heat_capacity_fluid; 57 | end 58 | 59 | % evaporator outlet temperature coefficient (Eq 1) 60 | function c = c_teo1(obj) 61 | c = - obj.mass_flow_rate_evaporator*obj.specific_heat_capacity_fluid; 62 | end 63 | 64 | % right-hand coefficient (Eq 1) 65 | function c = c_r1(obj) 66 | c = obj.power*obj.coefficient_of_performance; 67 | end 68 | 69 | % condenser inlet temperature coefficient (Eq 2) 70 | function c = c_tci2(obj) 71 | c = - obj.mass_flow_rate_condenser*obj.specific_heat_capacity_fluid; 72 | end 73 | 74 | % condenser outlet temperature coefficient (Eq 2) 75 | function c = c_tco2(obj) 76 | c = obj.mass_flow_rate_condenser*obj.specific_heat_capacity_fluid; 77 | end 78 | 79 | % right-hand coefficient (Eq 2) 80 | function c = c_r2(obj) 81 | c = obj.power*(1+obj.coefficient_of_performance); 82 | end 83 | 84 | % create matrix of coefficients and right-hand side vector 85 | function obj = create(obj, solver) 86 | obj.iteration = obj.iteration + 1; 87 | obj.temperature_condenser_inlet = solver.temperatures(obj.id_condenser_inlet); 88 | obj.temperature_condenser_outlet = solver.temperatures(obj.id_condenser_outlet); 89 | obj.temperature_evaporator_inlet = solver.temperatures(obj.id_evaporator_inlet); 90 | obj.temperature_evaporator_outlet = solver.temperatures(obj.id_evaporator_outlet); 91 | obj.matrix_coefficients = zeros(obj.number_of_equations,obj.matrix_size); 92 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 93 | obj.matrix_coefficients(1,obj.id_evaporator_inlet) = obj.c_tsi1(); 94 | obj.matrix_coefficients(1,obj.id_evaporator_outlet) = obj.c_tso1(); 95 | obj.matrix_coefficients(2,obj.id_condenser_inlet) = obj.c_tdi2(); 96 | obj.matrix_coefficients(2,obj.id_condenser_outlet) = obj.c_tdo2(); 97 | obj.right_hand_side_vector(1) = obj.c_r1(); 98 | obj.right_hand_side_vector(2) = obj.c_r2(); 99 | end 100 | 101 | end 102 | end 103 | 104 | -------------------------------------------------------------------------------- /Constant.m: -------------------------------------------------------------------------------- 1 | classdef Constant 2 | properties 3 | iteration 4 | id 5 | temperature 6 | 7 | time_step 8 | matrix_size 9 | matrix_coefficients 10 | right_hand_side_vector 11 | number_of_equations 12 | 13 | end 14 | 15 | methods 16 | function obj = Constant(id, solver, temperature) 17 | if nargin > 0 18 | obj.id = id; 19 | obj.temperature = temperature; 20 | obj.time_step = solver.time_step; 21 | obj.matrix_size = solver.matrix_size; 22 | 23 | obj.iteration = 0; 24 | obj.number_of_equations = 1; 25 | obj.matrix_coefficients = zeros(obj.number_of_equations,solver.matrix_size); 26 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 27 | 28 | end 29 | end 30 | 31 | % right-hand coefficient 32 | function c = c_r(obj) 33 | c = obj.temperature; 34 | end 35 | 36 | % create matrix of coefficients and right-hand side vector 37 | function obj = create(obj, solver) 38 | obj.iteration = obj.iteration + 1; 39 | obj.matrix_coefficients = zeros(obj.number_of_equations,obj.matrix_size); 40 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 41 | obj.right_hand_side_vector = obj.c_r(); 42 | obj.matrix_coefficients(obj.id) = 1; 43 | end 44 | 45 | end 46 | end -------------------------------------------------------------------------------- /FanCoil.m: -------------------------------------------------------------------------------- 1 | classdef FanCoil 2 | properties 3 | iteration 4 | id_heating_inlet 5 | id_heating_outlet 6 | id_cooling_inlet 7 | id_cooling_outlet 8 | id_air_inlet 9 | id_air_outlet 10 | id_zone 11 | time_step 12 | matrix_size 13 | matrix_coefficients 14 | right_hand_side_vector 15 | number_of_equations 16 | 17 | specific_heat_capacity_air 18 | specific_heat_capacity_cooling 19 | specific_heat_capacity_heating 20 | mass_flow_rate_air 21 | mass_flow_rate_cooling 22 | mass_flow_rate_heating 23 | status_heating 24 | status_cooling 25 | heat_transfer_coefficient_heating 26 | heat_transfer_coefficient_cooling 27 | surface_heating 28 | surface_cooling 29 | 30 | heating_capacitance_flows_air 31 | heating_capacitance_flows_water 32 | heating_capacitance_flows_min 33 | heating_capacitance_flows_max 34 | heating_capacitance_flows_ratio 35 | heating_number_of_transfer_unit 36 | heating_eta 37 | heating_effectiveness 38 | 39 | temperature_heating_inlet 40 | temperature_heating_outlet 41 | temperature_cooling_inlet 42 | temperature_cooling_outlet 43 | temperature_air_inlet 44 | temperature_air_outlet 45 | temperature_zone 46 | 47 | end 48 | 49 | methods 50 | function obj = FanCoil(id_heating_inlet, id_heating_outlet, id_cooling_inlet, id_cooling_outlet, id_air_inlet, id_air_outlet, id_zone, solver, specific_heat_capacity_air, specific_heat_capacity_cooling, specific_heat_capacity_heating, mass_flow_rate_air, mass_flow_rate_cooling, mass_flow_rate_heating, status_heating, status_cooling, heat_transfer_coefficient_heating, heat_transfer_coefficient_cooling, surface_heating, surface_cooling) 51 | 52 | if nargin > 0 53 | obj.id_heating_inlet = id_heating_inlet; 54 | obj.id_heating_outlet = id_heating_outlet; 55 | obj.id_cooling_inlet = id_cooling_inlet; 56 | obj.id_cooling_outlet = id_cooling_outlet; 57 | obj.id_air_inlet = id_air_inlet; 58 | obj.id_air_outlet = id_air_outlet; 59 | obj.id_zone = id_zone; 60 | obj.time_step = solver.time_step; 61 | obj.matrix_size = solver.matrix_size; 62 | 63 | obj.specific_heat_capacity_air = specific_heat_capacity_air; 64 | obj.specific_heat_capacity_cooling = specific_heat_capacity_cooling; 65 | obj.specific_heat_capacity_heating = specific_heat_capacity_heating; 66 | obj.mass_flow_rate_air = mass_flow_rate_air; 67 | obj.mass_flow_rate_cooling = mass_flow_rate_cooling; 68 | obj.mass_flow_rate_heating = mass_flow_rate_heating; 69 | obj.status_heating = status_heating; 70 | obj.status_cooling = status_cooling; 71 | obj.heat_transfer_coefficient_heating = heat_transfer_coefficient_heating; 72 | obj.heat_transfer_coefficient_cooling = heat_transfer_coefficient_cooling; 73 | obj.surface_heating = surface_heating; 74 | obj.surface_cooling = surface_cooling; 75 | 76 | % heating 77 | obj.heating_capacitance_flows_air = obj.specific_heat_capacity_air*obj.mass_flow_rate_air; 78 | obj.heating_capacitance_flows_water = obj.specific_heat_capacity_heating*obj.mass_flow_rate_heating; 79 | obj.heating_capacitance_flows_min = min(obj.heating_capacitance_flows_air, obj.heating_capacitance_flows_water); 80 | obj.heating_capacitance_flows_max = max(obj.heating_capacitance_flows_air, obj.heating_capacitance_flows_water); 81 | obj.heating_capacitance_flows_ratio = obj.heating_capacitance_flows_min / obj.heating_capacitance_flows_max; 82 | obj.heating_number_of_transfer_unit = obj.heat_transfer_coefficient_heating*obj.surface_heating/obj.heating_capacitance_flows_min; 83 | obj.heating_eta = obj.heating_number_of_transfer_unit^(-0.22); 84 | obj.heating_effectiveness = 1 - exp((exp(-obj.heating_number_of_transfer_unit*obj.heating_capacitance_flows_ratio*obj.heating_eta)-1)/obj.heating_capacitance_flows_ratio*obj.heating_eta); 85 | 86 | obj.iteration = 0; 87 | obj.number_of_equations = 3; 88 | obj.matrix_coefficients = zeros(obj.number_of_equations,solver.matrix_size); 89 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 90 | 91 | obj.temperature_heating_inlet = solver.temperatures(obj.id_heating_inlet); 92 | obj.temperature_heating_outlet = solver.temperatures(obj.id_heating_outlet); 93 | obj.temperature_cooling_inlet = solver.temperatures(obj.id_cooling_inlet); 94 | obj.temperature_cooling_outlet = solver.temperatures(obj.id_cooling_outlet); 95 | obj.temperature_air_inlet = solver.temperatures(obj.id_air_inlet); 96 | obj.temperature_air_outlet = solver.temperatures(obj.id_air_outlet); 97 | obj.temperature_zone = solver.temperatures(obj.id_zone); 98 | end 99 | end 100 | 101 | function h = enthalpy(~, dry_bulb_temperature, humidity_ratio) 102 | humidity_ratio = max(humidity_ratio, 10^-5); 103 | h = 1004.84*dry_bulb_temperature + humidity_ratio*(2500940 + 1858.95*dry_bulb_temperature); 104 | end 105 | 106 | function c = c_tai1(obj) 107 | c = 1-obj.heating_effectiveness*obj.heating_capacitance_flows_min/obj.heating_capacitance_flows_air; 108 | end 109 | 110 | function c = c_tao1(~) 111 | c = - 1; 112 | end 113 | 114 | function c = c_thi1(~) 115 | c = obj.heating_effectiveness*obj.heating_capacitance_flows_min/obj.heating_capacitance_flows_air; 116 | end 117 | 118 | function c = c_r1(~) 119 | c = 0; 120 | end 121 | 122 | function c = c_thi2(~) 123 | c = 1; 124 | end 125 | 126 | function c = c_tho2(~) 127 | c = - 1; 128 | end 129 | 130 | function c = c_tai2(obj) 131 | c = obj.heating_capacitance_flows_air/obj.heating_capacitance_flows_water; 132 | end 133 | 134 | function c = c_tao2(obj) 135 | c = obj.heating_capacitance_flows_air/obj.heating_capacitance_flows_water; 136 | end 137 | 138 | function c = c_r2(~) 139 | c = 0; 140 | end 141 | 142 | % create matrix of coefficients and right-hand side vector 143 | function obj = create(obj, solver) 144 | obj.iteration = obj.iteration + 1; 145 | 146 | obj.temperature_heating_inlet = solver.temperatures(obj.id_heating_inlet); 147 | obj.temperature_heating_outlet = solver.temperatures(obj.id_heating_outlet); 148 | obj.temperature_cooling_inlet = solver.temperatures(obj.id_cooling_inlet); 149 | obj.temperature_cooling_outlet = solver.temperatures(obj.id_cooling_outlet); 150 | obj.temperature_air_inlet = solver.temperatures(obj.id_air_inlet); 151 | obj.temperature_air_outlet = solver.temperatures(obj.id_air_outlet); 152 | obj.temperature_zone = solver.temperatures(obj.id_zone); 153 | 154 | obj.matrix_coefficients = zeros(obj.number_of_equations,obj.matrix_size); 155 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 156 | if(obj.status_heating) 157 | obj.matrix_coefficients(1,obj.id_air_inlet) = obj.c_tai1(); 158 | obj.matrix_coefficients(1,obj.id_air_outlet) = obj.c_tao1(); 159 | obj.matrix_coefficients(1,obj.id_heating_inlet) = obj.c_thi1(); 160 | obj.matrix_coefficients(2,obj.id_air_inlet) = obj.c_tai2(); 161 | obj.matrix_coefficients(2,obj.id_air_outlet) = obj.c_tao2(); 162 | obj.matrix_coefficients(2,obj.id_heating_inlet) = obj.c_thi2(); 163 | obj.matrix_coefficients(2,obj.id_heating_oulet) = obj.c_tho2(); 164 | elseif(obj.status_cooling) 165 | 166 | else 167 | 168 | end 169 | 170 | end 171 | 172 | 173 | 174 | end 175 | end -------------------------------------------------------------------------------- /HeatExchanger.m: -------------------------------------------------------------------------------- 1 | classdef HeatExchanger 2 | properties 3 | iteration 4 | id_supply_inlet 5 | id_supply_outlet 6 | id_demand_inlet 7 | id_demand_outlet 8 | temperature_supply_inlet 9 | temperature_supply_outlet 10 | temperature_demand_inlet 11 | temperature_demand_outlet 12 | time_step 13 | matrix_size 14 | matrix_coefficients 15 | right_hand_side_vector 16 | number_of_equations 17 | 18 | specific_heat_capacity_supply 19 | specific_heat_capacity_demand 20 | mass_flow_rate_supply 21 | mass_flow_rate_demand 22 | heat_transfer_coefficient 23 | surface 24 | 25 | heat_transfer_minimum 26 | heat_transfer_maximum 27 | capacity_ratio 28 | number_of_transfer_units 29 | effectiveness 30 | end 31 | 32 | methods 33 | function obj = HeatExchanger(id_supply_inlet, id_supply_outlet, id_demand_inlet, id_demand_outlet, solver, specific_heat_capacity_supply, specific_heat_capacity_demand, mass_flow_rate_supply, mass_flow_rate_demand, heat_transfer_coefficient, surface) 34 | if nargin > 0 35 | obj.id_supply_inlet = id_supply_inlet; 36 | obj.id_supply_outlet = id_supply_outlet; 37 | obj.id_demand_inlet = id_demand_inlet; 38 | obj.id_demand_outlet = id_demand_outlet; 39 | obj.time_step = solver.time_step; 40 | obj.matrix_size = solver.matrix_size; 41 | obj.specific_heat_capacity_supply = specific_heat_capacity_supply; 42 | obj.specific_heat_capacity_demand = specific_heat_capacity_demand; 43 | obj.mass_flow_rate_supply = mass_flow_rate_supply; 44 | obj.mass_flow_rate_demand = mass_flow_rate_demand; 45 | obj.heat_transfer_coefficient = heat_transfer_coefficient; 46 | obj.surface = surface; 47 | 48 | obj.iteration = 0; 49 | obj.number_of_equations = 2; 50 | obj.matrix_coefficients = zeros(obj.number_of_equations,solver.matrix_size); 51 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 52 | obj.temperature_supply_inlet = solver.temperatures(id_supply_inlet); 53 | obj.temperature_supply_outlet = solver.temperatures(id_supply_outlet); 54 | obj.temperature_demand_inlet = solver.temperatures(id_demand_inlet); 55 | obj.temperature_demand_outlet = solver.temperatures(id_demand_outlet); 56 | 57 | obj.heat_transfer_minimum = min(mass_flow_rate_supply*specific_heat_capacity_supply, mass_flow_rate_demand*specific_heat_capacity_demand); 58 | obj.heat_transfer_maximum = max(mass_flow_rate_supply*specific_heat_capacity_supply, mass_flow_rate_demand*specific_heat_capacity_demand); 59 | obj.capacity_ratio = obj.heat_transfer_minimum / obj.heat_transfer_maximum; 60 | obj.number_of_transfer_units = heat_transfer_coefficient * surface / obj.heat_transfer_minimum; 61 | obj.effectiveness = (1 - exp(-obj.number_of_transfer_units*(1+obj.capacity_ratio)))/(1+obj.capacity_ratio); 62 | end 63 | end 64 | 65 | % coefficient of supply inlet - first equation 66 | function c = c_tsi1(obj) 67 | c = 1 - obj.effectiveness*obj.heat_transfer_minimum/(obj.specific_heat_capacity_supply*obj.mass_flow_rate_supply); 68 | end 69 | 70 | % coefficient of supply outlet - first equation 71 | function c = c_tso1(~) 72 | c = - 1; 73 | end 74 | 75 | % coefficient of demand inlet - first equation 76 | function c = c_tdi1(obj) 77 | c = obj.effectiveness*obj.heat_transfer_minimum/(obj.specific_heat_capacity_supply*obj.mass_flow_rate_supply); 78 | end 79 | 80 | % coefficient of demand inlet - second equation 81 | function c = c_tdi2(obj) 82 | c = 1 - obj.effectiveness*obj.heat_transfer_minimum/(obj.specific_heat_capacity_demand*obj.mass_flow_rate_demand); 83 | end 84 | 85 | % coefficient of demand outlet - second equation 86 | function c = c_tdo2(~) 87 | c = - 1; 88 | end 89 | 90 | % coefficient of supply inlet - second equation 91 | function c = c_tsi2(obj) 92 | c = obj.effectiveness*obj.heat_transfer_minimum/(obj.specific_heat_capacity_demand*obj.mass_flow_rate_demand); 93 | end 94 | 95 | % create matrix of coefficients and right-hand side vector 96 | function obj = create(obj, solver) 97 | obj.iteration = obj.iteration + 1; 98 | obj.matrix_coefficients = zeros(obj.number_of_equations,obj.matrix_size); 99 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 100 | obj.temperature_supply_inlet = solver.temperatures(obj.id_supply_inlet); 101 | obj.temperature_supply_outlet = solver.temperatures(obj.id_supply_outlet); 102 | obj.temperature_demand_inlet = solver.temperatures(obj.id_demand_inlet); 103 | obj.temperature_demand_outlet = solver.temperatures(obj.id_demand_outlet); 104 | obj.matrix_coefficients(1,obj.id_supply_inlet) = obj.c_tsi1(); 105 | obj.matrix_coefficients(1,obj.id_supply_outlet) = obj.c_tso1(); 106 | obj.matrix_coefficients(1,obj.id_demand_inlet) = obj.c_tdi1(); 107 | obj.matrix_coefficients(2,obj.id_demand_inlet) = obj.c_tdi2(); 108 | obj.matrix_coefficients(2,obj.id_demand_outlet) = obj.c_tdo2(); 109 | obj.matrix_coefficients(2,obj.id_supply_inlet) = obj.c_tsi2(); 110 | end 111 | 112 | end 113 | end -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /Mixer.m: -------------------------------------------------------------------------------- 1 | classdef Mixer 2 | properties 3 | iteration 4 | id_inlets 5 | id_outlets 6 | time_step 7 | matrix_size 8 | matrix_coefficients 9 | right_hand_side_vector 10 | number_of_equations 11 | 12 | specific_heat_capacity_inlets 13 | temperature_inlets 14 | temperature_outlets 15 | mass_flow_rate_inlets 16 | fracrion_outlets 17 | 18 | specific_heat_capacity_outlets 19 | mass_flow_rate_outlets 20 | end 21 | 22 | methods 23 | function obj = Mixer(id_inlets, id_outlets, solver, specific_heat_capacity_inlets, mass_flow_rate_inlets, fracrion_outlets) 24 | if nargin > 0 25 | obj.id_inlets = id_inlets; 26 | obj.id_outlets = id_outlets; 27 | obj.time_step = solver.time_step; 28 | obj.matrix_size = solver.matrix_size; 29 | 30 | obj.specific_heat_capacity_inlets = specific_heat_capacity_inlets; 31 | obj.mass_flow_rate_inlets = mass_flow_rate_inlets; 32 | obj.fracrion_outlets = fracrion_outlets; 33 | 34 | obj.iteration = 0; 35 | obj.number_of_equations = length(id_outlets); 36 | obj.matrix_coefficients = zeros(obj.number_of_equations,solver.matrix_size); 37 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 38 | 39 | for i=1:length(obj.id_inlets) 40 | obj.temperature_inlets(i) = solver.temperatures(obj.id_inlets(i)); 41 | end 42 | for i=1:length(obj.id_outlets) 43 | obj.temperature_outlets(i) = solver.temperatures(obj.id_outlets(i)); 44 | obj.mass_flow_rate_outlets(i) = fracrion_outlets(i)*sum(obj.mass_flow_rate_inlets); 45 | obj.specific_heat_capacity_outlets(i) = sum(obj.specific_heat_capacity_inlets.*obj.mass_flow_rate_inlets)/sum(obj.mass_flow_rate_inlets); 46 | end 47 | end 48 | end 49 | 50 | % coefficient of inlets temperature 51 | function c = c_ti(obj,i) 52 | c = obj.mass_flow_rate_inlets(i)*obj.specific_heat_capacity_inlets(i); 53 | end 54 | 55 | % coefficient of outlets temperature 56 | function c = c_to(obj,i) 57 | c = - obj.mass_flow_rate_outlets(i)*obj.specific_heat_capacity_outlets(i); 58 | end 59 | 60 | % create matrix of coefficients and right-hand side vector 61 | function obj = create(obj, solver) 62 | obj.iteration = obj.iteration + 1; 63 | obj.matrix_coefficients = zeros(obj.number_of_equations,obj.matrix_size); 64 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 65 | for i=1:length(obj.id_inlets) 66 | obj.temperature_inlets(i) = solver.temperatures(obj.id_inlets(i)); 67 | obj.matrix_coefficients(1,obj.id_inlets(i)) = obj.c_ti(i); 68 | end 69 | for i=1:length(obj.id_outlets) 70 | obj.temperature_outlets(i) = solver.temperatures(obj.id_outlets(i)); 71 | obj.matrix_coefficients(1,obj.id_outlets(i)) = obj.c_to(i); 72 | end 73 | for i=2:obj.number_of_equations 74 | obj.matrix_coefficients(i, obj.id_outlets(1)) = 1; 75 | obj.matrix_coefficients(i, obj.id_outlets(i)) = -1; 76 | end 77 | end 78 | 79 | end 80 | end -------------------------------------------------------------------------------- /Pipe.m: -------------------------------------------------------------------------------- 1 | classdef Pipe 2 | properties 3 | iteration 4 | id_inlet 5 | id_outlet 6 | id_zone 7 | time_step 8 | matrix_size 9 | matrix_coefficients 10 | right_hand_side_vector 11 | number_of_equations 12 | 13 | %input 14 | specific_heat_capacity 15 | density 16 | specific_heat_capacity_fluid 17 | density_fluid 18 | temperature_inlet 19 | temperature_outlet 20 | temperature_zone 21 | mass_flow_rate 22 | thermal_conductivity 23 | thermal_conductivity_fluid 24 | radius_inner 25 | radius_outer 26 | length 27 | dynamic_viscosity_fluid 28 | dynamic_viscosity_air 29 | density_air 30 | thermal_conductivity_air 31 | specific_heat_capacity_air 32 | prandtl_number_outer = 0.71; 33 | gravitational_acceleration = 9.8; 34 | 35 | %calculated 36 | surface_inner 37 | heat_transfer_coefficient 38 | mass 39 | mass_fluid 40 | end 41 | 42 | methods 43 | function obj = Pipe(id_inlet, id_outlet, id_zone, solver, specific_heat_capacity, density, specific_heat_capacity_fluid, density_fluid, mass_flow_rate,thermal_conductivity,thermal_conductivity_fluid,radius_inner,radius_outer,length,dynamic_viscosity_fluid,dynamic_viscosity_air,density_air,specific_heat_capacity_air,thermal_conductivity_air) 44 | if nargin > 0 45 | obj.id_inlet = id_inlet; 46 | obj.id_outlet = id_outlet; 47 | obj.id_zone = id_zone; 48 | obj.time_step = solver.time_step; 49 | obj.matrix_size = solver.matrix_size; 50 | 51 | obj.specific_heat_capacity = specific_heat_capacity; 52 | obj.density = density; 53 | obj.specific_heat_capacity_fluid = specific_heat_capacity_fluid; 54 | obj.density_fluid = density_fluid; 55 | obj.mass_flow_rate = mass_flow_rate; 56 | obj.thermal_conductivity = thermal_conductivity; 57 | obj.thermal_conductivity_fluid = thermal_conductivity_fluid; 58 | obj.radius_inner = radius_inner; 59 | obj.radius_outer = radius_outer; 60 | obj.length = length; 61 | obj.dynamic_viscosity_fluid = dynamic_viscosity_fluid; 62 | obj.dynamic_viscosity_air = dynamic_viscosity_air; 63 | obj.specific_heat_capacity_air = specific_heat_capacity_air; 64 | obj.thermal_conductivity_air = thermal_conductivity_air; 65 | obj.density_air = density_air; 66 | 67 | obj.iteration = 0; 68 | obj.number_of_equations = 1; 69 | obj.matrix_coefficients = zeros(obj.number_of_equations,solver.matrix_size); 70 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 71 | obj.temperature_inlet = solver.temperatures(obj.id_inlet); 72 | obj.temperature_outlet = solver.temperatures(obj.id_outlet); 73 | obj.temperature_zone = solver.temperatures(obj.id_zone); 74 | 75 | % calculation 76 | obj.surface_inner = obj.calculate_surface_inner(); 77 | obj.heat_transfer_coefficient = obj.calculate_heat_transfer_coefficient(); 78 | obj.mass = obj.calculate_mass(); 79 | obj.mass_fluid = obj.calculate_mass_fluid(); 80 | end 81 | end 82 | 83 | % inner area of pipe 84 | function A = calculate_surface_inner(obj) 85 | A = 2*pi*obj.radius_inner*obj.length; 86 | end 87 | 88 | % equivalent heat transfer coefficient of pipe 89 | function U = calculate_heat_transfer_coefficient(obj) 90 | h_in = obj.calculate_heat_transfer_coefficient_inner(); 91 | h_out = obj.calculate_heat_transfer_coefficient_outer(); 92 | U = 1/(1/h_in+(obj.radius_inner*log(obj.radius_outer/obj.radius_inner))/obj.thermal_conductivity+obj.radius_inner/(obj.radius_outer*h_out)); 93 | end 94 | 95 | % heat transfer coefficient of the inner pipe 96 | function h = calculate_heat_transfer_coefficient_inner(obj) 97 | nu = obj.calculate_nusselt_number_inner(); 98 | h = nu*obj.thermal_conductivity/(2*obj.radius_inner); 99 | end 100 | 101 | % Nusselt number of the inner pipe 102 | function nu = calculate_nusselt_number_inner(obj) 103 | pr = obj.calculate_prandtl_number_inner(); 104 | re = obj.calculate_reynolds_number_inner(); 105 | nu = 4.36 + 0.086 * (re * pr * (2*obj.radius_inner) / obj.length)^1.33/( 1 + pr * (re * (2*obj.radius_inner) / obj.length)^0.83); 106 | end 107 | 108 | % Reynolds number 109 | function re = calculate_reynolds_number_inner(obj) 110 | re = 2 * obj.mass_flow_rate / (pi * obj.radius_inner * obj.dynamic_viscosity_fluid); 111 | end 112 | 113 | % Prandtl number 114 | function pr = calculate_prandtl_number_inner(obj) 115 | pr = obj.specific_heat_capacity_fluid * obj.dynamic_viscosity_fluid / obj.thermal_conductivity_fluid; 116 | end 117 | 118 | % heat transfer coefficient of the outer pipe 119 | function h = calculate_heat_transfer_coefficient_outer(obj) 120 | nu = obj.calculate_nusselt_number_outer(); 121 | h = nu*obj.thermal_conductivity/(2*obj.radius_outer); 122 | end 123 | 124 | % Nusselt number of the outer pipe 125 | function nu = calculate_nusselt_number_outer(obj) 126 | pr = obj.prandtl_number_outer(); 127 | ra = obj.calculate_rayleigh_number_outer(); 128 | nu = (0.6 + 0.387 * ra^(1/6) / (1 + (0.559 / pr)^(9/16))^(8/27))^2; 129 | end 130 | 131 | % Rayleigh number 132 | function ra = calculate_rayleigh_number_outer(obj) 133 | beta = obj.thermal_expansion_coefficient_outer(); 134 | t_p = (obj.temperature_inlet + obj.temperature_outlet) / 2; 135 | ra = obj.gravitational_acceleration * beta * (t_p - obj.temperature_zone) * (obj.radius_outer * 2)^3 / (obj.dynamic_viscosity_air/obj.density_air)^2; 136 | end 137 | 138 | % Thermal Expansion Coefficient of Outer 139 | function beta = thermal_expansion_coefficient_outer(obj) 140 | t_p = (obj.temperature_inlet + obj.temperature_outlet) / 2; 141 | t = (t_p + obj.temperature_zone) / 2; 142 | beta = 1 / t; 143 | end 144 | 145 | % Prandtl number 146 | function pr = calculate_prandtl_number_outer(obj) 147 | pr = obj.specific_heat_capacity_air * obj.dynamic_viscosity_air / obj.thermal_conductivity_air; 148 | end 149 | 150 | % weight of pipe 151 | function m = calculate_mass(obj) 152 | m = pi*obj.density*(obj.radius_outer^2-obj.radius_inner^2)*obj.length; 153 | end 154 | 155 | % weight of fluid inside pipe 156 | function m = calculate_mass_fluid(obj) 157 | m = pi*obj.density_fluid*obj.radius_inner^2*obj.length; 158 | end 159 | 160 | % coefficient of inlet temperature 161 | function c = c_ti(obj) 162 | c = (obj.mass*obj.specific_heat_capacity+obj.mass_fluid*obj.specific_heat_capacity_fluid)/(2*obj.time_step)-obj.mass_flow_rate*obj.specific_heat_capacity_fluid+obj.heat_transfer_coefficient*obj.surface_inner/2; 163 | end 164 | 165 | % coefficient of outlet temperature 166 | function c = c_to(obj) 167 | c = (obj.mass*obj.specific_heat_capacity+obj.mass_fluid*obj.specific_heat_capacity_fluid)/(2*obj.time_step)+obj.mass_flow_rate*obj.specific_heat_capacity_fluid+obj.heat_transfer_coefficient*obj.surface_inner/2; 168 | end 169 | 170 | % coefficient of zone temperature 171 | function c = c_tz(obj) 172 | c = obj.heat_transfer_coefficient*obj.surface_inner; 173 | end 174 | 175 | % right-hand coefficient 176 | function c = c_r(obj) 177 | c = (obj.mass*obj.specific_heat_capacity+obj.mass_fluid*obj.specific_heat_capacity_fluid)*(obj.temperature_inlet+obj.temperature_outlet)/(2*obj.time_step); 178 | end 179 | 180 | % create matrix of coefficients and right-hand side vector 181 | function obj = create(obj, solver) 182 | obj.iteration = obj.iteration + 1; 183 | obj.temperature_inlet = solver.temperatures(obj.id_inlet); 184 | obj.temperature_outlet = solver.temperatures(obj.id_outlet); 185 | obj.temperature_zone = solver.temperatures(obj.id_zone); 186 | obj.matrix_coefficients = zeros(obj.number_of_equations,obj.matrix_size); 187 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 188 | obj.right_hand_side_vector = obj.c_r(); 189 | obj.matrix_coefficients(obj.id_inlet) = obj.c_ti(); 190 | obj.matrix_coefficients(obj.id_outlet) = obj.c_to(); 191 | obj.matrix_coefficients(obj.id_zone) = obj.c_tz(); 192 | end 193 | 194 | end 195 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Building Energy Model (MATLAB) # 2 | It is a small software which is developed by MATLAB for modeling the energy system of a building or a HVAC system. 3 | 4 | ## Method of Solution ## 5 | In this code, the temperatures are considered variables of the problem, which are solved implicitly by solving a system of linear equations based on energy equations of each element. 6 | 7 | ## Elements Classes ## 8 | 9 | ### Boiler ### 10 | The boiler contains an inlet fluid pipe, an outlet fluid pipe, a fluid tank which is heated up, and the rest. The class of boiler receives input values including the id of the inlet, the id of outlet, the solver, the specific heat capacity of the rest, the mass of the rest, specific heat capacity of the fluid, mass of the fluid, the boiler power, the mass flow rate, and the status. The inlet and outlet should be outlet and inlet of pipes which are connected to the boiler respectively. The solver is the class of the solver that is used. Next, there are specific heat capacity and mass of the boiler except containing fluid. Then, there are those of the fluid. The next argument is the power of the boiler. The mass flow rate also should be given as an input value. The status works as a switch in the boiler which can be controlled by the smart controller in the next stages of the project. 11 | 12 | #### Equations #### 13 | ![Schematic](docs/boiler/schematic.png) 14 | ![Equations](docs/boiler/eqs.png) 15 | 16 | #### Variables #### 17 | 18 | | Symbol | Description | Unit | 19 | | --- | --- | --- | 20 | | *m* | Mass | *kg* | 21 | | *C* | Specific Heat Capacity | *J/(K.kg)* | 22 | | *T* | Temperature | *K* | 23 | | *E.* | Energy Rate | *W* | 24 | 25 | | Subscript | Description | 26 | | --- | --- | 27 | | *b* | Boiler | 28 | | *f* | fluid | 29 | | *b,f* | Fluid inside Boiler | 30 | | *b,i* | Boiler Inlet | 31 | | *b,o* | Boiler Outlet | 32 | 33 | #### Code #### 34 | ##### Construction ###### 35 | ```Matlab 36 | boiler = Boiler(id_inlet, id_outlet, solver, specific_heat_capacity, mass, specific_heat_capacity_fluid, mass_fluid, power, mass_flow_rate, status); 37 | ``` 38 | 39 | | Input | Description | Type | Unit | 40 | | --- | --- | --- | --- | 41 | | `id_inlet` | Boiler Inlet ID | `integer` | - | 42 | | `id_outlet` | Boiler Outlet ID | `integer` | - | 43 | | `solver` | Class of the Solver | `solver` | - | 44 | | `specific_heat_capacity` | Specific Heat Capacity of the Boiler (without fluid) | `double` | *J/(K.kg)* | 45 | | `mass` | Mass of the Boiler (without fluid) | `double` | *kg* | 46 | | `specific_heat_capacity_fluid` | Specific Heat Capacity of the Fluid | `double` | *J/(K.kg)* | 47 | | `mass_fluid` | Mass of Fluid inside the Boiler | `double` | *kg* | 48 | | `power` | Power of the Boiler | `double` | *W* | 49 | | `mass_flow_rate` | Mass Flow Rate of the Boiler | `double` | *kg/s* | 50 | | `status` | Status of the Boiler (ON/OFF) | `boolean` | - | 51 | 52 | ##### Create Matrix ##### 53 | ```Matlab 54 | create(solver) 55 | ``` 56 | 57 | | Input | Description | Type | Unit | 58 | | --- | --- | --- | --- | 59 | | `solver` | Class of the Solver | `solver` | - | 60 | 61 | --- 62 | 63 | ### Pipe ### 64 | Another element in the model is the pipe. The input values of the pipe class are the id of inlet, the id of outlet, the id of zone, the solver, specific heat capacity of the pipe wall, density of the pipe wall, specific heat capacity of the fluid, density of the fluid, mass flow rate of the fluid, inner heat transfer coefficient, outer heat transfer coefficient, thermal conductivity of the tube wall, inner radius of the pipe, outer radius of the pipe, and length of the pipe. The inlet and outlet of the pipe are the elements which are connected to the pipe. The zone which is in contact with the outer side of the pipe is also the argument of the class. 65 | 66 | #### Equations #### 67 | ![Schematic](docs/pipe/schematic.png) 68 | ![Equations](docs/pipe/eqs.png) 69 | 70 | #### Variables #### 71 | 72 | | Symbol | Description | Unit | 73 | | --- | --- | --- | 74 | | *h* | Heat Transfer Coefficient | *W/(m2K)* | 75 | | *r* | Radius | *m* | 76 | | *D* | Diameter | *m* | 77 | | *k* | Thermal Conductivity | *W.m-1.K-1* | 78 | | *L* | Length | *m* | 79 | | *U* | equivalent heat transfer coefficient | *W/(m2K)* | 80 | | *Nu* | Nusselt Number | - | 81 | | *Re* | Reynolds Number | - | 82 | | *Pr* | Prandtl Number | - | 83 | | *Ra* | Rayleigh Number | - | 84 | | *g* | Gravitational Acceleration | m/s2 | 85 | | *&‌beta;* | Coefficient of Volume Expansion | 1/K | 86 | | *&‌nu;* | Kinematic Viscosity | m2/s | 87 | | *&‌mu;* | Dynamic Viscosity | kg·m−1·s−1 | 88 | 89 | 90 | | Subscript | Description | 91 | | --- | --- | 92 | | *t* | Pipe | 93 | | *t,f* | Fluid inside Pipe | 94 | | *t,i* | Pipe Inlet | 95 | | *t,o* | Pipe Outlet | 96 | | *t,in* | Pipe Inner Side | 97 | | *t,out* | Pipe Outer Side | 98 | 99 | #### Code #### 100 | ##### Construction ###### 101 | ```Matlab 102 | pipe = Pipe(id_inlet, id_outlet, id_zone, solver, specific_heat_capacity, density, specific_heat_capacity_fluid, density_fluid, mass_flow_rate,thermal_conductivity,thermal_conductivity_fluid,radius_inner,radius_outer,length,dynamic_viscosity_fluid,dynamic_viscosity_air,density_air,specific_heat_capacity_air,thermal_conductivity_air); 103 | ``` 104 | 105 | | Input | Description | Type | Unit | 106 | | --- | --- | --- | --- | 107 | | `id_inlet` | Pipe Inlet ID | `integer` | - | 108 | | `id_outlet` | Pipe Outlet ID | `integer` | - | 109 | | `id_zone` | Zone ID | `integer` | - | 110 | | `solver` | Class of the Solver | `solver` | - | 111 | | `specific_heat_capacity` | Specific Heat Capacity of the Pipe (without fluid) | `double` | *J/(K.kg)* | 112 | | `density` | Density of the Pipe (without fluid) | `double` | *kg/m3* | 113 | | `specific_heat_capacity_fluid` | Specific Heat Capacity of the Fluid | `double` | *J/(K.kg)* | 114 | | `density_fluid` | Density of Fluid inside the Pipe | `double` | *kg/m3* | 115 | | `mass_flow_rate` | Mass Flow Rate of the Pipe | `double` | *kg/s* | 116 | | `thermal_conductivity` | Thermal Conductivity of the Pipe | `double` | *W.m-1.K-1* | 117 | | `thermal_conductivity_fluid` | Thermal Conductivity of the Fluid | `double` | *W.m-1.K-1* | 118 | | `radius_inner` | Inner Radius of the Pipe | `double` | *m* | 119 | | `radius_outer` | Outer Radius of the Pipe | `double` | *m* | 120 | | `length` | Length of the Pipe | `double` | *m* | 121 | | `dynamic_viscosity_fluid` | Dynamic Viscosity of the Fluid | `double` | *N·s/m2* | 122 | | `dynamic_viscosity_air` | Dynamic Viscosity of the Air | `double` | *N·s/m2* | 123 | | `density_air` | Density of the Air | `double` | *kg/m3* | 124 | | `specific_heat_capacity_air` | Specific Heat Capacity of the Air | `double` | *J/(K.kg)* | 125 | | `thermal_conductivity_air` | Thermal Conductivity of the Air | `double` | *W.m-1.K-1* | 126 | 127 | ##### Create Matrix ##### 128 | ```Matlab 129 | create(solver) 130 | ``` 131 | 132 | | Input | Description | Type | Unit | 133 | | --- | --- | --- | --- | 134 | | `solver` | Class of the Solver | `solver` | - | 135 | 136 | --- 137 | 138 | ### Radiator ### 139 | The input values of the radiator class are the id of inlet, the id of outlet, the id of zone, the solver, specific heat capacity of the radiator except containing fluid, mass of the radiator except containing fluid, specific heat capacity of the fluid, mass of fluid, mass flow rate of the fluid, heat transfer coefficient of the radiator to the zone, the surface of the radiator which is in contact to the air of the zone. 140 | 141 | #### Equations #### 142 | ![Schematic](docs/radiator/schematic.png) 143 | ![Equations](docs/radiator/eqs.png) 144 | 145 | #### Variables #### 146 | 147 | | Subscript | Description | 148 | | --- | --- | 149 | | *r* | Radiator | 150 | | *r,f* | Fluid inside Radiator | 151 | | *r,i* | Radiator Inlet | 152 | | *r,o* | Radiator Outlet | 153 | | *z* | Zone | 154 | 155 | #### Code #### 156 | ##### Construction ###### 157 | ```Matlab 158 | radiator = Radiator(id_inlet, id_outlet, id_zone, solver, specific_heat_capacity, mass, specific_heat_capacity_fluid, mass_fluid, mass_flow_rate,heat_transfer_coefficient,surface); 159 | ``` 160 | 161 | | Input | Description | Type | Unit | 162 | | --- | --- | --- | --- | 163 | | `id_inlet` | Radiator Inlet ID | `integer` | - | 164 | | `id_outlet` | Radiator Outlet ID | `integer` | - | 165 | | `id_zone` | Zone ID | `integer` | - | 166 | | `solver` | Class of the Solver | `solver` | - | 167 | | `specific_heat_capacity` | Specific Heat Capacity of the Radiator (without fluid) | `double` | *J/(K.kg)* | 168 | | `mass` | Mass of the Radiator (without fluid) | `double` | *kg* | 169 | | `specific_heat_capacity_fluid` | Specific Heat Capacity of the Fluid | `double` | *J/(K.kg)* | 170 | | `mass_fluid` | Mass of Fluid inside the Radiator | `double` | *kg* | 171 | | `mass_flow_rate` | Mass Flow Rate of the Radiator | `double` | *kg/s* | 172 | | `heat_transfer_coefficient` | Heat Transfer Coefficient of the Radiator | `double` | *W/(m2K)* | 173 | | `surface` | Surface of the Radiator | `double` | *m2* | 174 | 175 | ##### Create Matrix ##### 176 | ```Matlab 177 | create(solver) 178 | ``` 179 | 180 | | Input | Description | Type | Unit | 181 | | --- | --- | --- | --- | 182 | | `solver` | Class of the Solver | `solver` | - | 183 | 184 | --- 185 | 186 | ### Mixer ### 187 | The mixer is an element that works as a mixer or manifold. It can mix multiple flowing fluids to multiple outlets. For the input arguments of the related class, there are the ids of inlets, the ids outlets, the solver, specific heat capacities of the inlets, mass flow rates of the inlets, and the fractions of outlets. 188 | 189 | #### Equations #### 190 | ![Schematic](docs/mixer/schematic.png) 191 | ![Equations](docs/mixer/eqs.png) 192 | 193 | #### Variables #### 194 | 195 | | Subscript | Description | 196 | | --- | --- | 197 | 198 | #### Code #### 199 | ##### Construction ###### 200 | ```Matlab 201 | mixer = Mixer(id_inlets, id_outlets, solver, specific_heat_capacity_inlets, mass_flow_rate_inlets, fracrion_outlets); 202 | ``` 203 | 204 | | Input | Description | Type | Unit | 205 | | --- | --- | --- | --- | 206 | | `id_inlets` | Array of Mixer Inlet ID | `array(integer)` | - | 207 | | `id_outlets` | Array of Mixer Outlet ID | `array(integer)` | - | 208 | | `solver` | Class of the Solver | `solver` | - | 209 | | `specific_heat_capacity_inlets` | Specific Heat Capacity of the Mixer Inlets | `array(double)` | *J/(K.kg)* | 210 | | `mass_flow_rate_inlets` | Mass Flow Rate of the Mixer Inlets | `array(double)` | *kg/s* | 211 | | `fracrion_outlets` | Heat Transfer Coefficient of the Radiator | `array(double)` | *W/(m2K)* | 212 | 213 | ##### Create Matrix ##### 214 | ```Matlab 215 | create(solver) 216 | ``` 217 | 218 | | Input | Description | Type | Unit | 219 | | --- | --- | --- | --- | 220 | | `solver` | Class of the Solver | `solver` | - | 221 | 222 | --- 223 | 224 | ### Zone ### 225 | The zone class contains arguments including the id of the zone, the ids of neighbor zones as an array, the ids of radiators inlets as an array, the ids radiators outlets as an array, the solver, thickness of walls as an array, surface of the walls as an array, thickness of the windows as an array, surface of the windows as an array, surface of radiators as an array, heat transfer coefficient radiators as an array, density of the air, volume of the air, specific heat capacity of the air, density of the wall, volume of the wall, specific heat capacity of the wall, mass of the equipment, specific heat capacity of the equipment, thermal conductivity of the wall, thermal conductivity of the window. 226 | 227 | #### Equations #### 228 | ![Equations](docs/zone/eqs.png) 229 | 230 | #### Variables #### 231 | 232 | | Subscript | Description | 233 | | --- | --- | 234 | 235 | #### Code #### 236 | ##### Construction ###### 237 | ```Matlab 238 | zone = Zone(id_zone, id_zones, id_radiator_inlets, id_radiator_outlets, solver, thickness_walls, surface_walls, thickness_windows, surface_windows, surface_radiators, heat_transfer_coefficient_radiators, density_air, volume_air, specific_heat_capacity_air, density_wall, volume_wall, specific_heat_capacity_wall, mass_equipment, specific_heat_capacity_equipment, thermal_conductivity_wall, thermal_conductivity_window); 239 | ``` 240 | 241 | | Input | Description | Type | Unit | 242 | | --- | --- | --- | --- | 243 | | `id_zone` | Zone ID | `integer` | - | 244 | | `id_zones` | Array of Neigthbors' Zones IDs | `array(integer)` | - | 245 | | `id_radiator_inlets` | Array of Radiators Inlets IDs | `array(integer)` | - | 246 | | `id_radiator_outlets` | Array of Radiators Outlets IDs | `array(integer)` | - | 247 | | `solver` | Class of the Solver | `solver` | - | 248 | | `thickness_walls` | Array of Walls Thicknesses | `array(double)` | *m* | 249 | | `surface_walls` | Array of Walls Surfaces | `array(double)` | *m2* | 250 | | `thickness_windows` | Array of Windows Thicknesses | `array(double)` | *m* | 251 | | `surface_windows` | Array of Windows Surfaces | `array(double)` | *m2* | 252 | | `surface_radiators` | Array of Radiators Surfaces | `array(double)` | *m2* | 253 | | `heat_transfer_coefficient_radiators` | Array of Heat Transfer Coefficient of Radiators | `array(double)` | *W/(m2K)* | 254 | | `density_air` | Air Density | `double` | *kg/m3* | 255 | | `volume_air` | Volume of the Air | `double` | *m3* | 256 | | `specific_heat_capacity_air` | Air Specific Heat Capacity | `double` | *J/(K.kg)* | 257 | | `density_wall` | Wall Density | `double` | *kg/m3* | 258 | | `volume_wall` | Volume of the Wall | `double` | *m3* | 259 | | `specific_heat_capacity_wall` | Wall Heat Transfer Coefficient | `double` | *J/(K.kg)* | 260 | | `mass_equipment` | Mass of Equipment | `double` | *kg* | 261 | | `specific_heat_capacity_equipment` | Equipment Specific Heat Capacity | `double` | *J/(K.kg)* | 262 | | `thermal_conductivity_wall` | Wall Thermal Conductivity | `double` | *W.m-1.K-1* | 263 | | `thermal_conductivity_window` | Window Thermal Conductivity | `double` | *W.m-1.K-1* | 264 | 265 | ##### Create Matrix ##### 266 | ```Matlab 267 | create(solver) 268 | ``` 269 | 270 | | Input | Description | Type | Unit | 271 | | --- | --- | --- | --- | 272 | | `solver` | Class of the Solver | `solver` | - | 273 | 274 | --- 275 | 276 | ### Same ### 277 | #### Code #### 278 | ##### Construction ###### 279 | ```Matlab 280 | same = Same(id_1, id_2, solver); 281 | ``` 282 | 283 | | Input | Description | Type | Unit | 284 | | --- | --- | --- | --- | 285 | | `id_1` | First Element ID | `integer` | - | 286 | | `id_2` | Second Element ID | `integer` | - | 287 | | `solver` | Class of the Solver | `solver` | - | 288 | 289 | ##### Create Matrix ##### 290 | ```Matlab 291 | create(solver) 292 | ``` 293 | 294 | | Input | Description | Type | Unit | 295 | | --- | --- | --- | --- | 296 | | `solver` | Class of the Solver | `solver` | - | 297 | 298 | --- 299 | 300 | ### HeatExchanger ### 301 | The class of heat exchanger contains the id of supply inlet, the id of supply outlet, the id of demand inlet, the id of demand outlet, the solver, specific heat capacity of the supply, specific heat capacity of the demand, mass flow rate of the supply, mass flow rate of the demand, heat transfer coefficient of the heat exchanger, and contact surface of the heat exchanger as inputs. 302 | 303 | #### Equations #### 304 | ![Equations](docs/heatexchanger/eqs.png) 305 | 306 | #### Variables #### 307 | 308 | | Variable | Description | 309 | | --- | --- | 310 | | *Rc* | Capacity Ratio | 311 | | *NTU* | Number of Transfer Units | 312 | | *?* | Effectiveness | 313 | 314 | | Subscript | Description | 315 | | --- | --- | 316 | | *s* | Supply | 317 | | *d* | Demand | 318 | | *i* | Inlet | 319 | | *o* | Outlet | 320 | | *min* | Minimum | 321 | | *max* | Maximum | 322 | 323 | #### Code #### 324 | ##### Construction ###### 325 | ```Matlab 326 | heatExchanger = HeatExchanger(id_supply_inlet, id_supply_outlet, id_demand_inlet, id_demand_outlet, solver, specific_heat_capacity_supply, specific_heat_capacity_demand, mass_flow_rate_supply, mass_flow_rate_demand, heat_transfer_coefficient, surface); 327 | ``` 328 | 329 | | Input | Description | Type | Unit | 330 | | --- | --- | --- | --- | 331 | | `id_supply_inlet` | Supply Inlet Element ID | `integer` | - | 332 | | `id_supply_outlet` | Supply Outlet Element ID | `integer` | - | 333 | | `id_demand_inlet` | Demand Inlet Element ID | `integer` | - | 334 | | `id_demand_outlet` | Demand Outlet Element ID | `integer` | - | 335 | | `solver` | Class of the Solver | `solver` | - | 336 | | `specific_heat_capacity_supply` | Specific Heat Capacity of the Supply | `double` | *J/(K.kg)* | 337 | | `specific_heat_capacity_demand` | Specific Heat Capacity of the Demand | `double` | *J/(K.kg)* | 338 | | `mass_flow_rate_supply` | Mass Flow Rate of the Supply | `double` | *kg/s* | 339 | | `mass_flow_rate_demand` | Mass Flow Rate of the Demand | `double` | *kg/s* | 340 | | `heat_transfer_coefficient` | Heat Transfer Coefficient of the Heat Exchanger | `double` | *W/(m2K)* | 341 | | `surface` | Surface of the Heat Exchanger | `double` | *m2* | 342 | 343 | 344 | ##### Create Matrix ##### 345 | ```Matlab 346 | create(solver) 347 | ``` 348 | 349 | | Input | Description | Type | Unit | 350 | | --- | --- | --- | --- | 351 | | `solver` | Class of the Solver | `solver` | - | 352 | 353 | --- 354 | 355 | ### Chiller ### 356 | The chiller class needs the following arguments as input: the id of condenser inlet, the id of condenser outlet, the id evaporator inlet, the id of evaporator outlet, the solver, specific heat capacity of the fluid, the cooling power, the coefficient of performance, mass flow rate of the condenser, mass flow rate of the evaporator, and the status of chiller. 357 | 358 | #### Equations #### 359 | ![Equations](docs/chiller/eqs.png) 360 | 361 | #### Variables #### 362 | 363 | | Variable | Description | 364 | | --- | --- | 365 | | *Q.* | Heat Transfer Rate | 366 | | *P* | Electrical Power (input) | 367 | | *COP* | Coefficient of Performance | 368 | | *C* | Water Specific Heat Capacity | 369 | 370 | | Subscript | Description | 371 | | --- | --- | 372 | | *e* | Evaporator | 373 | | *c* | Condenser | 374 | | *i* | Inlet | 375 | | *o* | Outlet | 376 | 377 | #### Code #### 378 | ##### Construction ###### 379 | ```Matlab 380 | chiller = Chiller(id_condenser_inlet, id_condenser_outlet, id_evaporator_inlet, id_evaporator_outlet, solver, specific_heat_capacity_fluid, power, coefficient_of_performance, mass_flow_rate_condenser, mass_flow_rate_evaporator, status); 381 | ``` 382 | 383 | | Input | Description | Type | Unit | 384 | | --- | --- | --- | --- | 385 | | `id_condenser_inlet` | Condenser Inlet Element ID | `integer` | - | 386 | | `id_condenser_outlet` | Condenser Outlet Element ID | `integer` | - | 387 | | `id_evaporator_inlet` | Evaporator Inlet Element ID | `integer` | - | 388 | | `id_evaporator_outlet` | Evaporator Outlet Element ID | `integer` | - | 389 | | `solver` | Class of the Solver | `solver` | - | 390 | | `specific_heat_capacity_fluid` | Specific Heat Capacity of Water | `double` | *J/(K.kg)* | 391 | | `power` | Electrical Power | `double` | *W* | 392 | | `coefficient_of_performance` | Coefficient of Performance | `double` | - | 393 | | `mass_flow_rate_condenser` | Mass Flow Rate of the Condenser | `double` | *kg/s* | 394 | | `mass_flow_rate_evaporator` | Mass Flow Rate of the Evaporator | `double` | *kg/s* | 395 | 396 | 397 | ##### Create Matrix ##### 398 | ```Matlab 399 | create(solver) 400 | ``` 401 | 402 | | Input | Description | Type | Unit | 403 | | --- | --- | --- | --- | 404 | | `solver` | Class of the Solver | `solver` | - | 405 | 406 | --- 407 | 408 | ### FanCoil ### 409 | The fan coil class contains the id of heating inlet, the id of heating outlet, the id of cooling inlet, the id of cooling outlet, the id of air inlet, the id of air outlet, the id of zone which under effect, the solver, specific heat capacity of the air, specific heat capacity of the cooling fluid, specific heat capacity of the heating fluid, mass flow rate of the air, mass flow rate of the cooling, mass flow rate of the heating, status of the heating system, status of the cooling system, heat transfer coefficient of the heating coil, heat transfer coefficient of the cooling coil, surface of the heating coil, and surface of the cooling coil. 410 | 411 | #### Equations #### 412 | ![Equations](docs/fancoil/eqs.png) 413 | 414 | #### Variables #### 415 | 416 | | Variable | Description | 417 | | --- | --- | 418 | | *C.* | Capacitance Flows | 419 | | *Z* | Capacitance Flows Ratio | 420 | | *NTU* | Number of Transfer Unit | 421 | | *?* | Effectiveness | 422 | 423 | | Subscript | Description | 424 | | --- | --- | 425 | | *a* | Air | 426 | | *w* | Heating Water | 427 | | *min* | Minimum | 428 | | *max* | Maximum | 429 | | *i* | Inlet | 430 | | *o* | Outlet | 431 | 432 | #### Code #### 433 | ##### Construction ###### 434 | ```Matlab 435 | fanCoil = FanCoil(id_heating_inlet, id_heating_outlet, id_cooling_inlet, id_cooling_outlet, id_air_inlet, id_air_outlet, id_zone, solver, specific_heat_capacity_air, specific_heat_capacity_cooling, specific_heat_capacity_heating, mass_flow_rate_air, mass_flow_rate_cooling, mass_flow_rate_heating, status_heating, status_cooling, heat_transfer_coefficient_heating, heat_transfer_coefficient_cooling, surface_heating, surface_cooling); 436 | ``` 437 | 438 | | Input | Description | Type | Unit | 439 | | --- | --- | --- | --- | 440 | 441 | 442 | ##### Create Matrix ##### 443 | ```Matlab 444 | create(solver) 445 | ``` 446 | 447 | | Input | Description | Type | Unit | 448 | | --- | --- | --- | --- | 449 | | `solver` | Class of the Solver | `solver` | - | 450 | 451 | --- 452 | 453 | ### AirHeatExchanger ### 454 | Next, air heat exchanger class needs data of the id of supply inlet, the id of supply outlet, the id of exhaust inlet, the id of exhaust outlet, the solver, nominal mass flow rate of the supply, specific heat capacity of the supply, specific heat capacity of the exhaust, mass flow rate of the supply, mass flow rate of the exhaust, sensible effectiveness of 75%, sensible effectiveness of 100%, latent effectiveness of 75%, and latent effectiveness of 100% as inputs. 455 | 456 | #### Equations #### 457 | ![Equations](docs/airheatexchanger/eqs.png) 458 | 459 | #### Variables #### 460 | 461 | | Variable | Description | 462 | | --- | --- | 463 | | *C.* | Capacitance Flows | 464 | | *HX* | Average Operating Volumetric to Nominal Supply Air Flow Rate | 465 | | *?* | Effectiveness | 466 | | *avg* | Average | 467 | | *Q.* | Heat Transfer Rate | 468 | 469 | | Subscript | Description | 470 | | --- | --- | 471 | | *sensible* | Sensible | 472 | | *operating* | Operating | 473 | | *75% flow* | 75% Flow Rate | 474 | | *100% flow* | 100% Flow Rate | 475 | | *s* | Supply | 476 | | *e* | Exhaust | 477 | | *i* | Inlet | 478 | | *o* | Outlet | 479 | | *min* | Minimum | 480 | 481 | #### Code #### 482 | ##### Construction ###### 483 | ```Matlab 484 | airHeatExchanger = AirHeatExchanger(id_supply_inlet, id_supply_outlet, id_exhaust_inlet, id_exhaust_outlet, solver, mass_flow_rate_supply_nominal, specific_heat_capacity_supply, specific_heat_capacity_exhaust, mass_flow_rate_supply, mass_flow_rate_exhaust, sensible_effectiveness_75, sensible_effectiveness_100, latent_effectiveness_75, latent_effectiveness_100); 485 | ``` 486 | 487 | | Input | Description | Type | Unit | 488 | | --- | --- | --- | --- | 489 | 490 | 491 | ##### Create Matrix ##### 492 | ```Matlab 493 | create(solver) 494 | ``` 495 | 496 | | Input | Description | Type | Unit | 497 | | --- | --- | --- | --- | 498 | | `solver` | Class of the Solver | `solver` | - | 499 | 500 | --- 501 | 502 | ### Constant ### 503 | 504 | 505 | #### Equations #### 506 | 507 | #### Variables #### 508 | 509 | | Variable | Description | 510 | | --- | --- | 511 | 512 | | Subscript | Description | 513 | | --- | --- | 514 | 515 | #### Code #### 516 | ##### Construction ###### 517 | ```Matlab 518 | constant = Constant(id, solver, temperature); 519 | ``` 520 | 521 | | Input | Description | Type | Unit | 522 | | --- | --- | --- | --- | 523 | | `id` | Element ID | `integer` | - | 524 | | `solver` | Class of the Solver | `solver` | - | 525 | | `temperature` | The Constant Temperature | `double` | K | 526 | 527 | 528 | ##### Create Matrix ##### 529 | ```Matlab 530 | create(solver) 531 | ``` 532 | 533 | | Input | Description | Type | Unit | 534 | | --- | --- | --- | --- | 535 | | `solver` | Class of the Solver | `solver` | - | 536 | 537 | ## Controllers Classes ## 538 | 539 | ### SetpointController ### 540 | 541 | #### Code #### 542 | ##### Construction ###### 543 | ```Matlab 544 | setpointController = SetpointController(minimum, maximum, mode, status); 545 | ``` 546 | 547 | | Input | Description | Type | Unit | 548 | | --- | --- | --- | --- | 549 | | `minimum` | Minimum Temperature | `double` | K | 550 | | `minimum` | Maximum Temperature | `double` | K | 551 | | `mode` | Heating (=1) or Cooling (=2) Modes | `integer` | - | 552 | | `status` | Status of the Controller | `boolean` | - | 553 | 554 | ##### Check ##### 555 | ```Matlab 556 | status = check(obj, temperature); 557 | ``` 558 | 559 | | Input | Description | Type | Unit | 560 | | --- | --- | --- | --- | 561 | | `temperature` | Temperature | `double` | K | 562 | | `status` | Status of the Controller | `boolean` | - | 563 | 564 | 565 | ## Solvers Classes ## 566 | 567 | ### Solver ### 568 | The solver class inputs include time step, matrix size, and initial temperature. There is a freedom of use of multiple solvers for the model in order to solve the equations in different implicit level. For instance, in this project for each water loop separate solver will be considered. 569 | 570 | #### Equations #### 571 | ![Equations](docs/solver/eqs.png) 572 | 573 | #### Code #### 574 | ##### Construction ###### 575 | ```Matlab 576 | Solver(time_step, matrix_size, initial_temperature) 577 | ``` 578 | 579 | | Input | Description | Type | Unit | 580 | | --- | --- | --- | --- | 581 | | `time_step` | Time Step | `double` | s | 582 | | `matrix_size` | Number of Variables of System of Linear Equations | `integer` | - | 583 | | `initial_temperature` | Array of Initial Temperatures | `array(double)` | K | 584 | 585 | ##### Iterate ##### 586 | ```Matlab 587 | [solver, boilers, pipes, radiators, mixers, zones, sames, heatExchangers, chillers, fanCoils] = solver.iterate(boilers, pipes, radiators, mixers, zones, sames, heatExchangers, chillers, fanCoils); 588 | ``` 589 | 590 | --- 591 | 592 | ### Bridge ### 593 | This class connects two different elements in different solvers, which has same temperatures. 594 | 595 | #### Code #### 596 | ##### Construction ###### 597 | ```Matlab 598 | bridge = Bridge(id, id_bridge, solver, solver_bridge); 599 | ``` 600 | 601 | | Input | Description | Type | Unit | 602 | | --- | --- | --- | --- | 603 | | `id` | Element ID in the first solver | `integer` | - | 604 | | `id_bridge` | Element ID in the second solver | `integer` | - | 605 | | `solver` | Class of the first Solver | `solver` | - | 606 | | `solver_bridge` | Class of the second Solver | `solver` | - | 607 | 608 | 609 | ##### Create Matrix ##### 610 | ```Matlab 611 | create(solver) 612 | ``` 613 | 614 | | Input | Description | Type | Unit | 615 | | --- | --- | --- | --- | 616 | | `solver` | Class of the first Solver | `solver` | - | 617 | 618 | ## License ## 619 | GNU GENERAL PUBLIC LICENSE 620 | Version 2, June 1991 621 | -------------------------------------------------------------------------------- /Radiator.m: -------------------------------------------------------------------------------- 1 | classdef Radiator 2 | properties 3 | iteration 4 | id_inlet 5 | id_outlet 6 | id_zone 7 | time_step 8 | matrix_size 9 | matrix_coefficients 10 | right_hand_side_vector 11 | number_of_equations 12 | 13 | specific_heat_capacity 14 | mass 15 | specific_heat_capacity_fluid 16 | mass_fluid 17 | temperature_zone 18 | temperature_inlet 19 | temperature_outlet 20 | mass_flow_rate 21 | heat_transfer_coefficient 22 | surface 23 | end 24 | 25 | methods 26 | function obj = Radiator(id_inlet, id_outlet, id_zone, solver, specific_heat_capacity, mass, specific_heat_capacity_fluid, mass_fluid, mass_flow_rate,heat_transfer_coefficient,surface) 27 | if nargin > 0 28 | obj.id_inlet = id_inlet; 29 | obj.id_outlet = id_outlet; 30 | obj.id_zone = id_zone; 31 | obj.time_step = solver.time_step; 32 | obj.matrix_size = solver.matrix_size; 33 | 34 | obj.specific_heat_capacity = specific_heat_capacity; 35 | obj.mass = mass; 36 | obj.specific_heat_capacity_fluid = specific_heat_capacity_fluid; 37 | obj.mass_fluid = mass_fluid; 38 | obj.mass_flow_rate = mass_flow_rate; 39 | obj.heat_transfer_coefficient = heat_transfer_coefficient; 40 | obj.surface = surface; 41 | 42 | obj.iteration = 0; 43 | obj.number_of_equations = 1; 44 | obj.matrix_coefficients = zeros(obj.number_of_equations,solver.matrix_size); 45 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 46 | obj.temperature_inlet = solver.temperatures(obj.id_inlet); 47 | obj.temperature_outlet = solver.temperatures(obj.id_outlet); 48 | obj.temperature_zone = solver.temperatures(obj.id_zone); 49 | end 50 | end 51 | 52 | % coefficient of inlet temperature of radiator 53 | function c = c_ti(obj) 54 | c = (obj.mass*obj.specific_heat_capacity+obj.mass_fluid*obj.specific_heat_capacity_fluid)/(2*obj.time_step)-obj.mass_flow_rate*obj.specific_heat_capacity_fluid+obj.heat_transfer_coefficient*obj.surface/2; 55 | end 56 | 57 | % coefficient of outlet temperature of radiator 58 | function c = c_to(obj) 59 | c = (obj.mass*obj.specific_heat_capacity+obj.mass_fluid*obj.specific_heat_capacity_fluid)/(2*obj.time_step)+obj.mass_flow_rate*obj.specific_heat_capacity_fluid+obj.heat_transfer_coefficient*obj.surface/2; 60 | end 61 | 62 | % coefficient of zone temperature of radiator 63 | function c = c_tz(obj) 64 | c = -obj.heat_transfer_coefficient*obj.surface; 65 | end 66 | 67 | % right-hand coefficient of radiator 68 | function c = c_r(obj) 69 | c = (obj.mass*obj.specific_heat_capacity+obj.mass_fluid*obj.specific_heat_capacity_fluid)*(obj.temperature_inlet+obj.temperature_outlet)/(2*obj.time_step); 70 | end 71 | 72 | % create matrix of coefficients and right-hand side vector 73 | function obj = create(obj, solver) 74 | obj.iteration = obj.iteration + 1; 75 | obj.temperature_inlet = solver.temperatures(obj.id_inlet); 76 | obj.temperature_outlet = solver.temperatures(obj.id_outlet); 77 | obj.temperature_zone = solver.temperatures(obj.id_zone); 78 | obj.matrix_coefficients = zeros(obj.number_of_equations,obj.matrix_size); 79 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 80 | obj.right_hand_side_vector = obj.c_r(); 81 | obj.matrix_coefficients(obj.id_inlet) = obj.c_ti(); 82 | obj.matrix_coefficients(obj.id_outlet) = obj.c_to(); 83 | obj.matrix_coefficients(obj.id_zone) = obj.c_tz(); 84 | end 85 | 86 | 87 | 88 | end 89 | end -------------------------------------------------------------------------------- /Same.m: -------------------------------------------------------------------------------- 1 | classdef Same 2 | properties 3 | iteration 4 | id_1 5 | id_2 6 | temperature_1 7 | temperature_2 8 | time_step 9 | matrix_size 10 | matrix_coefficients 11 | right_hand_side_vector 12 | number_of_equations 13 | end 14 | 15 | methods 16 | function obj = Same(id_1, id_2, solver) 17 | if nargin > 0 18 | obj.id_1 = id_1; 19 | obj.id_2 = id_2; 20 | obj.time_step = solver.time_step; 21 | obj.matrix_size = solver.matrix_size; 22 | 23 | obj.iteration = 0; 24 | obj.number_of_equations = 1; 25 | obj.matrix_coefficients = zeros(obj.number_of_equations,solver.matrix_size); 26 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 27 | obj.temperature_1 = solver.temperatures(id_1); 28 | obj.temperature_2 = solver.temperatures(id_2); 29 | 30 | end 31 | end 32 | 33 | % create matrix of coefficients and right-hand side vector 34 | function obj = create(obj, solver) 35 | obj.iteration = obj.iteration + 1; 36 | obj.matrix_coefficients = zeros(obj.number_of_equations,obj.matrix_size); 37 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 38 | obj.temperature_1 = solver.temperatures(obj.id_1); 39 | obj.temperature_2 = solver.temperatures(obj.id_2); 40 | obj.matrix_coefficients(obj.id_1) = 1; 41 | obj.matrix_coefficients(obj.id_2) = -1; 42 | end 43 | 44 | end 45 | end -------------------------------------------------------------------------------- /SetpointController.m: -------------------------------------------------------------------------------- 1 | classdef SetpointController 2 | properties 3 | minimum 4 | maximum 5 | mode % 1=heating, 2=cooling 6 | status 7 | end 8 | 9 | methods 10 | function obj = SetpointController(minimum, maximum, mode, status) 11 | obj.minimum = minimum; 12 | obj.maximum = maximum; 13 | obj.mode = mode; 14 | obj.status = status; 15 | end 16 | 17 | function status = check(obj, temperature) 18 | if(((obj.mode==1)&&(temperature<=obj.minimum))||((obj.mode==2)&&(temperature>=obj.maximum))) 19 | obj.status = 1; 20 | elseif(((obj.mode==1)&&(temperature>=obj.maximum))||((obj.mode==2)&&(temperature<=obj.minimum))) 21 | obj.status = 0; 22 | end 23 | status = obj.status; 24 | end 25 | end 26 | end 27 | 28 | -------------------------------------------------------------------------------- /Solver.m: -------------------------------------------------------------------------------- 1 | classdef Solver 2 | properties 3 | iteration 4 | time_step 5 | matrix_size 6 | temperatures 7 | matrix_coefficients 8 | right_hand_side_vector 9 | number_of_equations 10 | end 11 | 12 | methods 13 | function obj = Solver(time_step, matrix_size, initial_temperature) 14 | if nargin > 0 15 | obj.time_step = time_step; 16 | obj.matrix_size = matrix_size; 17 | obj.temperatures = initial_temperature*ones(matrix_size,1); 18 | obj.matrix_coefficients = zeros(matrix_size,matrix_size); 19 | obj.right_hand_side_vector = zeros(matrix_size,1); 20 | 21 | obj.iteration = 0; 22 | end 23 | end 24 | function [obj, elements] = get_matrices(obj, elements) 25 | for i=1:length(elements) 26 | elements(i) = elements(i).create(obj); 27 | for j=1:elements(i).number_of_equations 28 | obj.number_of_equations = obj.number_of_equations + 1; 29 | obj.matrix_coefficients(obj.number_of_equations, :) = elements(i).matrix_coefficients(j,:); 30 | obj.right_hand_side_vector(obj.number_of_equations, 1) = elements(i).right_hand_side_vector(j,1); 31 | end 32 | end 33 | end 34 | function [obj, boilers, pipes, radiators, mixers, zones, sames, heatExchangers, chillers, fanCoils, constants, bridges] = iterate(obj, boilers, pipes, radiators, mixers, zones, sames, heatExchangers, chillers, fanCoils, constants, bridges) 35 | obj.iteration = obj.iteration + 1; 36 | obj.number_of_equations = 0; 37 | [obj, boilers] = obj.get_matrices(boilers); 38 | [obj, pipes] = obj.get_matrices(pipes); 39 | [obj, radiators] = obj.get_matrices(radiators); 40 | [obj, mixers] = obj.get_matrices(mixers); 41 | [obj, zones] = obj.get_matrices(zones); 42 | [obj, sames] = obj.get_matrices(sames); 43 | [obj, heatExchangers] = obj.get_matrices(heatExchangers); 44 | [obj, chillers] = obj.get_matrices(chillers); 45 | [obj, fanCoils] = obj.get_matrices(fanCoils); 46 | [obj, constants] = obj.get_matrices(constants); 47 | [obj, bridges] = obj.get_matrices(bridges); 48 | if(obj.number_of_equations~=obj.matrix_size) 49 | disp('Error: The number of equations and variables should be same.'); 50 | fprintf('Number of Variables: %d - Number of Equations: %d', obj.matrix_size, obj.number_of_equations); 51 | else 52 | fprintf('Iteration: %d | Time: %d s\n', obj.iteration, obj.iteration*obj.time_step); 53 | end 54 | obj.temperatures = obj.matrix_coefficients\obj.right_hand_side_vector; 55 | end 56 | end 57 | end 58 | 59 | -------------------------------------------------------------------------------- /Zone.m: -------------------------------------------------------------------------------- 1 | classdef Zone 2 | properties 3 | iteration 4 | id_zone 5 | id_zones 6 | id_radiator_inlets 7 | id_radiator_outlets 8 | thickness_walls 9 | surface_walls 10 | thickness_windows 11 | surface_windows 12 | surface_radiators 13 | heat_transfer_coefficient_radiators 14 | temperature_zone 15 | 16 | density_air 17 | volume_air 18 | specific_heat_capacity_air 19 | density_wall 20 | volume_wall 21 | specific_heat_capacity_wall 22 | mass_equipment 23 | specific_heat_capacity_equipment 24 | thermal_conductivity_wall 25 | thermal_conductivity_window 26 | 27 | time_step 28 | matrix_size 29 | matrix_coefficients 30 | right_hand_side_vector 31 | number_of_equations 32 | 33 | thermal_resistance_inner_wall 34 | thermal_resistance_outer_wall 35 | thermal_resistance_inner_window 36 | thermal_resistance_outer_window 37 | thermal_resistance_gap_window 38 | 39 | heat_transfer_walls 40 | heat_transfer_windows 41 | 42 | end 43 | 44 | methods 45 | function obj = Zone(id_zone, id_zones, id_radiator_inlets, id_radiator_outlets, solver, thickness_walls, surface_walls, thickness_windows, surface_windows, surface_radiators, heat_transfer_coefficient_radiators, density_air, volume_air, specific_heat_capacity_air, density_wall, volume_wall, specific_heat_capacity_wall, mass_equipment, specific_heat_capacity_equipment, thermal_conductivity_wall, thermal_conductivity_window) 46 | if nargin > 0 47 | obj.id_zone = id_zone; 48 | obj.id_zones = id_zones; 49 | obj.id_radiator_inlets = id_radiator_inlets; 50 | obj.id_radiator_outlets = id_radiator_outlets; 51 | obj.time_step = solver.time_step; 52 | obj.matrix_size = solver.matrix_size; 53 | obj.thickness_walls = thickness_walls; 54 | obj.surface_walls = surface_walls; 55 | obj.thickness_windows = thickness_windows; 56 | obj.surface_windows = surface_windows; 57 | obj.surface_radiators = surface_radiators; 58 | obj.heat_transfer_coefficient_radiators = heat_transfer_coefficient_radiators; 59 | 60 | obj.density_air = density_air; 61 | obj.volume_air = volume_air; 62 | obj.specific_heat_capacity_air = specific_heat_capacity_air; 63 | obj.density_wall = density_wall; 64 | obj.volume_wall = volume_wall; 65 | obj.specific_heat_capacity_wall = specific_heat_capacity_wall; 66 | obj.mass_equipment = mass_equipment; 67 | obj.specific_heat_capacity_equipment = specific_heat_capacity_equipment; 68 | obj.thermal_conductivity_wall = thermal_conductivity_wall; 69 | obj.thermal_conductivity_window = thermal_conductivity_window; 70 | 71 | obj.thermal_resistance_inner_wall = 0.13; 72 | obj.thermal_resistance_outer_wall = 0.04; 73 | obj.thermal_resistance_inner_window = 0.13; 74 | obj.thermal_resistance_outer_window = 0.04; 75 | obj.thermal_resistance_gap_window = 0.127; 76 | 77 | for i=1:length(obj.id_zones) 78 | obj.heat_transfer_walls(i) = obj.calculate_wall_heat_transfer(thickness_walls(i)); 79 | obj.heat_transfer_windows(i) = obj.calculate_window_heat_transfer(thickness_windows(i)); 80 | end 81 | 82 | obj.iteration = 0; 83 | obj.number_of_equations = 1; 84 | obj.matrix_coefficients = zeros(obj.number_of_equations,solver.matrix_size); 85 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 86 | obj.temperature_zone = solver.temperatures(obj.id_zone); 87 | 88 | end 89 | end 90 | 91 | % equivalent heat transfer coefficient of wall 92 | function U = calculate_wall_heat_transfer(obj, thickness_wall) 93 | U = 1/(obj.thermal_resistance_outer_wall+thickness_wall/obj.thermal_conductivity_wall+obj.thermal_resistance_inner_wall); 94 | end 95 | 96 | % equivalent heat transfer coefficient of window 97 | function U = calculate_window_heat_transfer(obj, thickness_window) 98 | U = 1/(obj.thermal_resistance_outer_window+thickness_window/obj.thermal_conductivity_window+obj.thermal_resistance_gap_window+obj.thermal_resistance_inner_window); 99 | end 100 | 101 | % coefficient of radiator inlet temperature 102 | function c = c_tri(obj, i) 103 | c = -obj.heat_transfer_coefficient_radiators(i)*obj.surface_radiators(i)/2; 104 | end 105 | 106 | % coefficient of radiator outlet temperature 107 | function c = c_tro(obj, i) 108 | c = -obj.heat_transfer_coefficient_radiators(i)*obj.surface_radiators(i)/2; 109 | end 110 | 111 | % coefficient of zone temperature 112 | function c = c_tz(obj) 113 | c = (obj.density_air*obj.volume_air*obj.specific_heat_capacity_air+obj.density_wall*obj.volume_wall*obj.specific_heat_capacity_wall)/obj.time_step + sum(obj.heat_transfer_coefficient_radiators.*obj.surface_radiators) + sum(obj.heat_transfer_walls.*obj.surface_walls + obj.heat_transfer_windows.*obj.surface_windows); 114 | end 115 | % coefficient of neigthbors' zones temperature 116 | function c = c_tzj(obj, i) 117 | c = - obj.heat_transfer_walls(i)*obj.surface_walls(i) - obj.heat_transfer_windows(i)*obj.surface_windows(i); 118 | end 119 | 120 | % right-hand coefficient 121 | function c = c_r(obj) 122 | c = ((obj.density_air*obj.volume_air*obj.specific_heat_capacity_air+obj.density_wall*obj.volume_wall*obj.specific_heat_capacity_wall)/obj.time_step)*obj.temperature_zone; 123 | end 124 | 125 | % create matrix of coefficients and right-hand side vector 126 | function obj = create(obj, solver) 127 | obj.iteration = obj.iteration + 1; 128 | obj.matrix_coefficients = zeros(obj.number_of_equations,obj.matrix_size); 129 | obj.right_hand_side_vector = zeros(obj.number_of_equations,1); 130 | obj.right_hand_side_vector = obj.c_r(); 131 | obj.temperature_zone = solver.temperatures(obj.id_zone); 132 | obj.matrix_coefficients(obj.id_zone) = obj.c_tz(); 133 | for i=1:length(obj.id_zones) 134 | obj.matrix_coefficients(obj.id_zones(i)) = obj.c_tzj(i); 135 | end 136 | for i=1:length(obj.id_radiator_inlets) 137 | obj.matrix_coefficients(obj.id_radiator_inlets(i)) = obj.c_tri(i); 138 | obj.matrix_coefficients(obj.id_radiator_outlets(i)) = obj.c_tro(i); 139 | end 140 | end 141 | 142 | end 143 | end -------------------------------------------------------------------------------- /docs/airheatexchanger/eqs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/airheatexchanger/eqs.png -------------------------------------------------------------------------------- /docs/boiler/eqs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/boiler/eqs.png -------------------------------------------------------------------------------- /docs/boiler/schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/boiler/schematic.png -------------------------------------------------------------------------------- /docs/chiller/eqs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/chiller/eqs.png -------------------------------------------------------------------------------- /docs/fancoil/eqs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/fancoil/eqs.png -------------------------------------------------------------------------------- /docs/heatexchanger/eqs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/heatexchanger/eqs.png -------------------------------------------------------------------------------- /docs/mixer/eqs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/mixer/eqs.png -------------------------------------------------------------------------------- /docs/mixer/schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/mixer/schematic.png -------------------------------------------------------------------------------- /docs/pipe/eqs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/pipe/eqs.png -------------------------------------------------------------------------------- /docs/pipe/schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/pipe/schematic.png -------------------------------------------------------------------------------- /docs/radiator/eqs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/radiator/eqs.png -------------------------------------------------------------------------------- /docs/radiator/schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/radiator/schematic.png -------------------------------------------------------------------------------- /docs/solver/eqs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/solver/eqs.png -------------------------------------------------------------------------------- /docs/zone/eqs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armancodv/building-energy-model-matlab/e34767048b7a48ea49de4c7b57a12ba734a2f7b9/docs/zone/eqs.png --------------------------------------------------------------------------------