Hi,
I am new to GAMS and I am trying to solve a problem in which I use block decomposition to solve a heat exchanger network optimization problem using MLP. I am getting a sqrt error in which when calculating TLM(i,j,k) it is becoming the square root of a negative. Is there a way to fix TLM so it only calculates if the square root is positive. Thanks in advance and sorry if this isn't fully clear.
Sets
i hot streams / H1, H2 /
j cold streams / C1, C2, C3 /
k block / B1, B2, B3 /
Parameters
T1hot(i,k) entering temperature of hot stream i in block k (k)
/ H1.B1 473.15, H2.B1 473.15,
H1.B2 334.53, H2.B2 334.53,
H1.B3 313.15, H2.B3 313.15 /
T2hot(i,k) leaving temperature of hot stream i in block k (k)
/ H1.B1 334.53, H2.B1 334.53,
H1.B2 313.15, H2.B2 313.15
H1.B3 308.15, H2.B3 293.15 /
T1cold(j,k) entering temperature of cold stream j in block k (k)
/C1.B1 453.15, C2.B1 324.15, C3.B1 453.15,
C1.B2 323.15, C2.B2 323.15, C3.B2 323.15,
C1.B3 303.15, C3.B3 303.15/
T2cold(j,k) leaving temperature of cold stream j in block k (k)
/ C1.B1 323.15, C2.B1 323.15, C3.B1 323.15,
C1.B2 303.15, C3.B2 303.15,
C1.B3 303.15, C3.B3 283.15 /
CPhot(i) flowrate heat capacity for cold stream i (kW per K)
/ H1 3.8, H2 2 /
CPcold(j) flowrate heat capacity for hot stream j (kW per K)
/ C1 4, C2 532, C3 2.2 /
U Overall heat transfer coefficient (kW per m^2K) / 1 /
;
Parameter TLM(i,j,k) log mean temperature (pattersons approximation);
TLM(i,j,k) = (2/3*(sqrt(((T1hot(i,k)-T1cold(j,k))*(T2hot(i,k)-T2cold(j,k)))))) + (1/3*((T1hot(i,k)-T1cold(j,k))+(T2hot(i,k)-T2cold(j,k))/2)) ;
Variables
q(i,j,k) heat load for match for hot stream i in cold stream j in block k
y(i,j,k) binary variable to activate or deactivate match. 1 if activated 0 otherwise
z objective
;
Positive Variable
q(i,j,k)
;
Binary Variable
y(i,j,k)
;
Equations
hotduty(i,k) duty on hot stream i in block k
coldduty(j,k) duty on cold stream j in block k
hotbinary(i,j,k) binary constraint on hot stream i
coldbinary(i,j,k) binary constraint on cold stream j
obj objective function to minimize total annualised cost of HEN
;
hotduty(i,k).. (T1hot(i,k) - T2hot(i,k))*CPhot(i) =e= sum(j,q(i,j,k));
coldduty(j,k).. (T1cold(j,k)-T2cold(j,k))*CPcold(j) =e= sum(i, q(i,j,k));
hotbinary(i,j,k).. 10 =l= (T1hot(i,k)-T1cold(j,k)) + (1-y(i,j,k));
coldbinary(i,j,k).. 10 =l= (T2hot(i,k)-T2cold(j,k)) + (1-y(i,j,k));
obj.. z =e= sum((k,i,j), (2000*y(i,j,k)) + 84*(q(i,j,k)/(TLM(i,j,k))));
;
option MIP = CPLEX;
option optcr = 0;
Model verticalcoursework /ALL/;
Solve verticalcoursework minimizing z using MIP;
Display z.l, y.l, q.l;
Sqrt domain x < 0 error
Re: Sqrt domain x < 0 error
Not sure how to make this more abvious. The log says "*** Error at line 31: sqrt: FUNC DOMAIN: x < 0", the source echo of line 31 reads:
There is a single sqrt in the expression. So just look where the argument becomes negative:
The abort gives you:
-Michael
Code: Select all
31 TLM(i,j,k) = (2/3*(sqrt(((T1hot(i,k)-T1cold(j,k))*(T2hot(i,k)-T2cold(j,k)))))) + (1/3*((T1hot(i,k)-T1cold(j,k))+(T2hot(i,k)-T2cold(j,k))/2)) ;
Code: Select all
Parameter TLM(i,j,k) log mean temperature (pattersons approximation), TLMTest(i,j,k);
TLMTest(i,j,k) = ((T1hot(i,k)-T1cold(j,k))*(T2hot(i,k)-T2cold(j,k)));
TLMTest(i,j,k) = min(0,TLMTest(i,j,k));
abort$card(TLMTest) TLMTest;
TLM(i,j,k) = (2/3*(sqrt(((T1hot(i,k)-T1cold(j,k))*(T2hot(i,k)-T2cold(j,k)))))) + (1/3*((T1hot(i,k)-T1cold(j,k))+(T2hot(i,k)-T2cold(j,k))/2)) ;
Code: Select all
---- 33 PARAMETER TLMTest
B3
H2.C1 -100.000
-
- User
- Posts: 2
- Joined: 5 years ago
Re: Sqrt domain x < 0 error
Hi ,
Thank you for your response. I understand why it goes negative, for example T1hot(H1, B3) - T1cold(C1, B1) = 313.15 - 453.15 = -140 and therefore the square root becomes negative. What I am trying to ask if there anyway to pass these errors and ignore the result they produce, or alternatively is there a way to set my parameter equation for TLM(i,j,k) so it only calculates TLM for i and j that are in the SAME block k.
Thanks
Thank you for your response. I understand why it goes negative, for example T1hot(H1, B3) - T1cold(C1, B1) = 313.15 - 453.15 = -140 and therefore the square root becomes negative. What I am trying to ask if there anyway to pass these errors and ignore the result they produce, or alternatively is there a way to set my parameter equation for TLM(i,j,k) so it only calculates TLM for i and j that are in the SAME block k.
Thanks
bussieck wrote: ↑5 years ago Not sure how to make this more abvious. The log says "*** Error at line 31: sqrt: FUNC DOMAIN: x < 0", the source echo of line 31 reads:
There is a single sqrt in the expression. So just look where the argument becomes negative:Code: Select all
31 TLM(i,j,k) = (2/3*(sqrt(((T1hot(i,k)-T1cold(j,k))*(T2hot(i,k)-T2cold(j,k)))))) + (1/3*((T1hot(i,k)-T1cold(j,k))+(T2hot(i,k)-T2cold(j,k))/2)) ;
The abort gives you:Code: Select all
Parameter TLM(i,j,k) log mean temperature (pattersons approximation), TLMTest(i,j,k); TLMTest(i,j,k) = ((T1hot(i,k)-T1cold(j,k))*(T2hot(i,k)-T2cold(j,k))); TLMTest(i,j,k) = min(0,TLMTest(i,j,k)); abort$card(TLMTest) TLMTest; TLM(i,j,k) = (2/3*(sqrt(((T1hot(i,k)-T1cold(j,k))*(T2hot(i,k)-T2cold(j,k)))))) + (1/3*((T1hot(i,k)-T1cold(j,k))+(T2hot(i,k)-T2cold(j,k))/2)) ;
-MichaelCode: Select all
---- 33 PARAMETER TLMTest B3 H2.C1 -100.000