forked from ValckenaersPaul/TAGP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heatExchangerInst.erl
33 lines (25 loc) · 1.46 KB
/
heatExchangerInst.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-module(heatExchangerInst).
-export([create/4, init/4, temp_influence/1]).
% HeatExchanger is a pipe and more; this pipe instance is passed to the create function.
% HeatExchangers have a HE_link to, typically, another HeatExchanger. The link provides
% a function that models the mutual effect on the temperature of the flows on either side.
create(Host, HeatExchangerTyp_Pid, PipeInst_Pid, HE_link_spec) -> {ok, spawn(?MODULE, init, [Host, HeatExchangerTyp_Pid, PipeInst_Pid, HE_link_spec])}.
init(Host, HeatExchangerTyp_Pid, PipeInst_Pid, HE_link_spec) ->
{ok, State} = apply(resource_type, get_initial_state, [HeatExchangerTyp_Pid, self(), PipeInst_Pid]),
% get_initial_state (ResTyp_Pid, ResInst_Pid, TypeOptions)
survivor:entry({ pumpInst_created, State }),
loop(Host, State, HeatExchangerTyp_Pid, PipeInst_Pid, HE_link_spec).
temp_influence(HeatExchangerInst_Pid) ->
msg:get(HeatExchangerInst_Pid, get_temp_influence).
loop(Host, State, HeatExchangerTyp_Pid, PipeInst_Pid, HE_link_spec) ->
receive
{get_type, ReplyFn} ->
ReplyFn(HeatExchangerTyp_Pid),
loop(Host, State, HeatExchangerTyp_Pid, PipeInst_Pid, HE_link_spec);
{get_temp_influence, ReplyFn} ->
ReplyFn(heatExchangeLink:get_temp_influence(HE_link_spec)),
loop(Host, State, HeatExchangerTyp_Pid, PipeInst_Pid, HE_link_spec);
OtherMessage ->
PipeInst_Pid ! OtherMessage,
loop(Host, State, HeatExchangerTyp_Pid, PipeInst_Pid, HE_link_spec)
end.