Quiet@Remove["Global`*"];
$HistoryLength=2;
SetDirectory[NotebookDirectory[]];

cm=0.01;
d=5cm;
To=20;
Ts=60;
v=20;
Pr=0.7;
(*forced convection across cylinder correlations*)
Nu[re_]:=0.93*(re^0.4)*(Pr^0.4)/;5<re≤80;
Nu[re_]:=0.715*(re^0.46)*(Pr^0.4)/;80<re≤500;
Nu[re_]:=0.226*(re^0.6)*(Pr^0.4)/;500<re;
(*LogLogPlot[Nu[re],{re,5,50000}]*)

Dchar=d;
Tdef=((Ts+To)/2);
Print["Tdef= ",Tdef," °C"]

ν=16.92*(10^(-6));
Rey=v*(Dchar/ν);
Print["Re= ",Rey," -"]

nuOld=Nu[Rey];
Print["Nu po staru= ",nuOld]

NuNew[re_]:=0.3+((0.62*(re^0.5)*(Pr^(1/3)))/(((1+((((0.4/Pr)))^(2/3))))^(1/4)))*(((1+((((re/282000)))^(5/8))))^(4/5));
LogLogPlot[{Nu[re],NuNew[re]},{re,5,50000},PlotStyle->{Red,Blue}];

nunew=NuNew[Rey];
Print["Nu po novu= ",nunew," -"]

λ=27.35*(10^(-3));
α=nuOld*(λ/Dchar);
Print["α= ",α," W.(m^(-1)).(K^(-1))"]

SJedenM=Pi*d;
Pconv1m=SJedenM*α*(Ts-To);
Print["Pc= ",Pconv1m," W"]

ϵ=0.9;
σ=5.67*(10^(-8));
Prad=SJedenM*ϵ*σ*((((Ts+273))^4)-(((To+273))^4));
Print["Pr= ",Prad," W"]

Skolmy=((Pi*(d^2))/4);
γ=37*(10^6);
R1m=(1/(γ*Skolmy));
Solve[R1m*(proud^2)==Pconv1m][[2]]

(*samovolna konvekce, v=0*)
nuVolne[grpr_]:=1.18*(grpr^(1/8))/;0.001<grpr≤500;
nuVolne[grpr_]:=0.54*(grpr^(1/4))/;500<grpr≤2*(10^7);
nuVolne[grpr_]:=0.135*(grpr^(1/3))/;2*(10^7)<grpr;
LogLogPlot[nuVolne[grpr],{grpr,0.001,3*(10^10)}];
β=(1/(Tdef+273.));
g=9.81;
Gr=((β*g*(Ts-To)*(Dchar^3))/(ν^2));
Print["Gr*Pr= ",grpr=Gr*Pr," -"]
Print["Nu= ",nuu=nuVolne[grpr]," -"]
αVolne=nuu*(λ/Dchar);
Print["αVolne= ",αVolne," W.(m^(-1)).(K^(-1))"]

Pconv1mVolne=SJedenM*αVolne*(Ts-To);
Print["PcVolne= ",Pconv1mVolne," W"]
Solve[R1m*(proud^2)==Pconv1mVolne+Prad][[2]]

(*prepocet vymeniku*)
Quiet@Remove["Global`*"];
Twin=90;
Twout=70.;
cw=4186;
P=50000;
Tain=15;
ca=1000;
Vasteckou=1.;
ρain=(349./(273+Tain));
ma=Vasteckou*ρain;
dos1=Solve[{P==cw*mw*(Twin-Twout),P==ca*ma*(Taout-Tain)}][[1]];
Δ1=Twin-Taout/.dos1;
Δ2=Twout-Tain;
dos2=Solve[P==kS*((Δ1-Δ2)/(Log[((Δ1)/(Δ2))]))][[1]];
Print["kS= ",kS/.dos2," W/K"]

(*novy stav*)
TainN=20;
TwinN=45;
Δ1N=TwinN-TaoutN;
Δ2N=TwoutN-TainN;
rce={PN==kS*((Δ1N-Δ2N)/(Log[((Δ1N)/(Δ2N))])),PN==cw*mw*(TwinN-TwoutN),PN==ca*ma*(TaoutN-TainN)}/.Union[dos1,dos2];
FindRoot[rce,{{TaoutN,40},{TwoutN,24},{PN,15000}}]

rceLin={PN==kS*((Δ1N+Δ2N)/2),PN==cw*mw*(TwinN-TwoutN),PN==ca*ma*(TaoutN-TainN)}/.Union[dos1,dos2];
solLin=Solve[rceLin][[1]]
solLin/.Rule->List
(*solLin/.(name_->val_):>{name,val}*)
FindRoot[rce,solLin/.Rule->List]

Rule[a,b]
List[a,b]

60*0.75*((1/0.3)-1)

(*dva vymeniky s vodnim meziobvodem*)

Quiet@Remove["Global`*"];
proud=1*(Sqrt[2])*Sin[ω*t];
(proud^2)//TrigReduce

Quiet@Remove["Global`*"];
cA=1000.;
cW=4186.;
Δ11=Ta1-Tw2;
Δ12=Ta2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ryNelin/.{prom_,val_}:>prom;
solLn=FindRoot[rceLn,oboryNelin];
{solLn,solLin}
];
vydej[0.1]

vydej[mW_]:=Module[{rcelin,solLin,oboryNelin,nezname,rceLn,solLn},rceLin={cA*ma1*(Ta1-Ta2)==cW*mW*(Tw2-Tw1),
cW*mW*(Tw2-Tw1)==cA*ma2*(Ta3-Ta4),
P==kS1*((Δ11+Δ12)/2),
P==kS2*((Δ21+Δ22)/2),
P==cA*ma2*(Ta3-Ta4),
P==kSv*((Δ1v+Δ2v)/2)};
rceLn={cA*ma1*(Ta1-Ta2)==cW*mW*(Tw2-Tw1),
cW*mW*(Tw2-Tw1)==cA*ma2*(Ta3-Ta4),
P==kS1*((Δ11-Δ12)/(Log[((Δ11)/(Δ12))])),
P==kS2*((Δ21-Δ22)/(Log[((Δ21)/(Δ22))])),
P==cA*ma2*(Ta3-Ta4),
P==kSv*((Δ1v-Δ2v)/(Log[((Δ1v)/(Δ2v))]))};
solLin=Quiet@Solve[rceLin][[1]];
oboryNelin=solLin/.Rule[a_,b_]:>List[a,b+Random[]];
nezname=oboryNelin/.{prom_,val_}:>prom;
solLn=Quiet@FindRoot[rceLn,oboryNelin];
(rceLn/.Equal[a_,b_]:>((Abs[a-b])/(0.5*(Abs[a]+Abs[b]))))/.solLn
];
vydej[10]

Quiet@Remove["Global`*"];
(*dve tepelna cerpadla seriove*)
ϵ1=k1*(T2/(T2-T1));
ϵ2=k2*(T3/(T3-T2));
rce={Qout==ϵ2*Pel2,Qpom==ϵ1*Pel1,Pin+Pel1==Qpom,Qout==Qpom+Pel2};
sol=Solve[rce,{Qout,Qpom,Pel1,Pel2}][[1]];
pom=Simplify[(Qout/(Pel1+Pel2))/.sol]
Simplify[pom/.{k1->1,k2->1}]

pom2=Simplify[(pom/(-(T3/(T1-T3))))/.{k1->(1/2),k2->(1/2),T1->300,T3->350}];
NMaximize[pom2,{T2}]

Quiet@Remove["Global`*"];
(*ohrev vody TC s predehrevem vymenikem*)
c=4186.;
ms=10;
Ts1=40;
Tw1=5;
Tw2=55;
mc=2;
mo=1;
Pz=1000;
ϵ=0.5*((Tw2+273)/(Tw2-Ts2));
Δ1=Ts1-Tw4;
Δ2=Ts2-Tw1;
kS=5000;
rce={mc*c*Tw2==Pz+mc*c*Tw3,
(mc-mo)*c*Tw3+mo*c*Tw4==mc*c*Tw5,
PTC==Pel*ϵ,
PTC==mc*c*(Tw2-Tw5),
ms*c*Ts2+mc*c*Tw5+Pel==ms*c*Ts3+mc*c*Tw2,
ms*c*Ts1+mo*c*Tw1==ms*c*Ts2+mo*c*Tw4,
PKS==ms*c*Ts1-ms*c*Ts2,
PKS==kS*((Δ1+Δ2)/2)
};
{Length[rce],
Length[Cases[rce,_Symbol,All]//Union]};
Quiet@(pom3=Solve[rce][[1]])
((Δ1)/(Δ2))/.pom3

kS=8000;
rceBV={mc*c*Tw2==Pz+mc*c*Tw3,
(mc-mo)*c*Tw3+mo*c*Tw4==mc*c*Tw5,
PTC==Pel*ϵ,
PTC==mc*c*(Tw2-Tw5),
ms*c*Ts2+mc*c*Tw5+Pel==ms*c*Ts3+mc*c*Tw2,
ms*c*Ts1+mo*c*Tw1==ms*c*Ts2+mo*c*Tw4,
PKS==ms*c*Ts1-ms*c*Ts2
};
rceLin=Union[rceBV,{PKS==kS*((Δ1+Δ2)/2)}];
Quiet@(pom3=Solve[rceLin][[1]]);
obory=pom3/.Rule->List;
rceLn=Union[rceBV,{PKS==kS*((Δ1-Δ2)/(Log[((Δ1)/(Δ2))]))}];

PTC+PKS/.pom3
FindRoot[rceLn,obory]