(*zvec contains the poles of the tranmission in the upper complex half plane,γ=Γ0L Γ0R>0 is the prefactor of the transmission, compare (C.12) in Martensen paper *)
transmission[γ_,zvec_,w_]:=Re[γ/Product[(w-zvec[[i]])(w-Conjugate[zvec[[i]]]),{i,1,Length[zvec]}]];
mcurrentn[γ_,zvec_,BL_,BR_,ML_,MR_]:=Module[{len,splist},
len=Length[zvec];
splist=Sort[Re[DeleteDuplicates[Join[{ML,MR},zvec]]]];
1/(2Pi) NIntegrate[γ/Product[Abs[(w-zvec[[i]])]^2,{i,1,len}]*(1/(Exp[BL(w-ML)]+1)-1/(Exp[BR(w-MR)]+1)),Join[{w,-Infinity},splist,{+Infinity}],MaxRecursion->100]
];
mcurrentp[γ_,zvec_,BL_,BR_,ML_,MR_]:=Module[{len,ret,vars,vara,n},
len=Length[zvec];
ret=I (Sum[γ/((zvec[[i]]-Conjugate[zvec[[i]]])*Product[Which[j≠i,(zvec[[i]]-zvec[[j]])(zvec[[i]]-Conjugate[zvec[[j]]]),True,1],{j,1,len}]) (1/(Exp[BL(zvec[[i]]-ML)]+1)-1/(Exp[BR(zvec[[i]]-MR)]+1)),{i,1,len}]);
(*CAUTION: Mathematica appears to have problems with the numerical evaluation of sums ranging to infinity*)
vars=0.0;(*-I/BL Sum[γ/Product[(ML+I(2n+1)Pi/BL-zvec[[i]])(ML+I(2n+1)Pi/BL-Conjugate[zvec[[i]]]),{i,1,len}],{n,0,Infinity}];*)
vara=1.0;
n=0;
While[Abs[vara]>1.0*10^(-20),
vara=-I/BL γ/Product[(ML+I(2n+1)Pi/BL-zvec[[i]])(ML+I(2n+1)Pi/BL-Conjugate[zvec[[i]]]),{i,1,len}];
vars+= vara;
++n;
];
ret += vars;
vars=0.0;
vara=1.0;
n=0;
While[Abs[vara]>1.0*10^(-20),
vara=+I/BR γ/Product[(MR+I(2n+1)Pi/BR-zvec[[i]])(MR+I(2n+1)Pi/BR-Conjugate[zvec[[i]]]),{i,1,len}];
vars+=vara;
++n;
];
ret += vars;
Re[ret] (*just to remove spurious imaginary parts*)
];
ecurrentn[γ_,zvec_,BL_,BR_,ML_,MR_]:=Module[{len,splist},
len=Length[zvec];
splist=Sort[Re[DeleteDuplicates[Join[{ML,MR},zvec]]]];
1/(2Pi) NIntegrate[w γ/Product[Abs[(w-zvec[[i]])]^2,{i,1,len}]*(1/(Exp[BL(w-ML)]+1)-1/(Exp[BR(w-MR)]+1)),Join[{w,-Infinity},splist,{+Infinity}],MaxRecursion->100]
];
ecurrentp[γ_,zvec_,BL_,BR_,ML_,MR_]:=Module[{len,ret,vars,vara,n},
len=Length[zvec];
ret=I (Sum[zvec[[i]]γ/((zvec[[i]]-Conjugate[zvec[[i]]])*Product[Which[j≠i,(zvec[[i]]-zvec[[j]])(zvec[[i]]-Conjugate[zvec[[j]]]),True,1],{j,1,len}])(1/(Exp[BL(zvec[[i]]-ML)]+1)-1/(Exp[BR(zvec[[i]]-MR)]+1)),{i,1,len}]);
vars=0.0;
vara=1.0;
n=0;
While[Abs[vara]>1.0*10^(-20),
vara=-I/BL (ML+I(2n+1)Pi/BL)γ/Product[(ML+I(2n+1)Pi/BL-zvec[[i]])(ML+I(2n+1)Pi/BL-Conjugate[zvec[[i]]]),{i,1,len}];
vars+=vara;
++n;
];
ret+=vars;
vars=0.0;
vara=1.0;
n=0;
While[Abs[vara]>1.0*10^(-20),
vara=I/BR (MR+I(2n+1)Pi/BR)γ/Product[(MR+I(2n+1)Pi/BR-zvec[[i]])(MR+I(2n+1)Pi/BR-Conjugate[zvec[[i]]]),{i,1,len}];
vars+=vara;
++n;
];
ret += vars;
Re[ret]
];
heatcurL[γ_?NumericQ,zvec_?(VectorQ[#,NumericQ]&),BL_?NumericQ,BR_?NumericQ,ML_?NumericQ,MR_?NumericQ]:=ecurrentp[γ,zvec,BL,BR,ML,MR]-ML mcurrentp[γ,zvec,BL,BR,ML,MR];
heatcurR[γ_?NumericQ,zvec_?(VectorQ[#,NumericQ]&),BL_?NumericQ,BR_?NumericQ,ML_?NumericQ,MR_?NumericQ]:=-(ecurrentp[γ,zvec,BL,BR,ML,MR]-MR mcurrentp[γ,zvec,BL,BR,ML,MR]);
power[γ_?NumericQ,zvec_?(VectorQ[#,NumericQ]&),BL_?NumericQ,BR_?NumericQ,ML_?NumericQ,MR_?NumericQ]:=-(ML-MR)Re[mcurrentp[γ,zvec,BL,BR,ML,MR]]; 
heatcurLn[γ_?NumericQ,zvec_?(VectorQ[#,NumericQ]&),BL_?NumericQ,BR_?NumericQ,ML_?NumericQ,MR_?NumericQ]:=Re[ecurrentn[γ,zvec,BL,BR,ML,MR]-ML mcurrentn[γ,zvec,BL,BR,ML,MR]];
heatcurRn[γ_?NumericQ,zvec_?(VectorQ[#,NumericQ]&),BL_?NumericQ,BR_?NumericQ,ML_?NumericQ,MR_?NumericQ]:=Re[-(ecurrentn[γ,zvec,BL,BR,ML,MR]-MR mcurrentn[γ,zvec,BL,BR,ML,MR])]; 
powern[γ_?NumericQ,zvec_?(VectorQ[#,NumericQ]&),BL_?NumericQ,BR_?NumericQ,ML_?NumericQ,MR_?NumericQ]:=-(ML-MR)mcurrentn[γ,zvec,BL,BR,ML,MR];
heatcurLid[wmin_?NumericQ,wmax_?NumericQ,BL_?NumericQ,BR_?NumericQ,ML_?NumericQ,MR_?NumericQ]:=1/(2Pi)NIntegrate[(w-ML)*(1/(Exp[BL(w-ML)]+1)-1/(Exp[BR(w-MR)]+1)),{w,wmin,wmax},MaxRecursion->100,MinRecursion->10];
powerid[wmin_?NumericQ,wmax_?NumericQ,BL_?NumericQ,BR_?NumericQ,ML_?NumericQ,MR_?NumericQ]:=-(ML-MR)/(2Pi)NIntegrate[(1/(Exp[BL(w-ML)]+1)-1/(Exp[BR(w-MR)]+1)),{w,wmin,wmax},MaxRecursion->100,MinRecursion->10];

-2 mcurrentn[1.0^2,{I 1.},10.,1.,0.01,-.01]

NMaximize[{powern[g^2,{I g},10.,1.,mb+V/2,mb-V/2],g>0 && mb<0 && V>0},{g,mb,V}]

(*the power shows a turnover as a function of coupling strength*)
Plot[powern[g^2,{I g},10.,1.,-1.4+0.6,-1.4-0.6],{g,0,1},PlotRange->{0,All}]

0.1^2*(0.049994665951021644*0.03906491048141686*0.03724940890641742*0.03662739511289903*0.03633510695480543*0.03618974522950204)^4*10^26
0.1^2*(0.049994665951021644*0.03906491048141686*0.03724940890641742*0.03662739511289903*0.03633510695480543)^4*10^22
0.1^2*(0.049994665951021644*0.03906491048141686*0.03724940890641742*0.03662739511289903)^4*10^18
0.1^2*(0.049994665951021644*0.03906491048141686*0.03724940890641742)^4*10^14
0.1^2*(0.049994665951021644*0.03906491048141686)^4*10^10
0.1^2*(0.049994665951021644)^4*10^6

(*Tilmanns parameters for a chain with 13,11,9,7,5,3 dots and Γ0=0.1, scaled to Γ0=1*)
Plot[{transmission[1.507271778169777`*^-10,10{-0.06722279506715508`+0.0041515722519025675` I,0.0672227950671549` +0.004151572251902657` I,-0.04746244225013107`+0.008990508858564575` I,0.0474624422501291` +0.008990508858563907` I,-0.017086422376499745`+0.01185791888953065` I,0.017086422376501917` +0.01185791888953565` I,-0.07139533403306063`+0.001420544840018246` I,0.07139533403306038` +0.0014205448400182754` I,-0.03320950419552712`+0.010743388702000974` I,0.05900452346564712` +0.00671676583697003` I,3.510194467644447`*^-15+0.012238601242018067` I,0.03320950419552376` +0.010743388702003781` I,-0.059004523465646996`+0.006716765836970629` I},w],transmission[8.787178823266184`*^-9,10{-0.06547894350168432`+0.005785086515072126` I,0.06547894350168425` +0.005785086515072048` I,-0.038712814673174535`+0.012004438044102764` I,0.038712814673170955` +0.01200443804410438` I,3.666225319691539`*^-15+0.014420950881648688` I,-0.054204880905291436`+0.009212358199346082` I,0.0712778727231097` +0.0019939983170310944` I,-0.020137087810394277`+0.013793643483634899` I,0.05420488090534879` +0.009212358199331092` I,0.020137087810395266` +0.013793643483639921` I,-0.07127787272316805`+0.0019939983170169217` I},w],transmission[5.0413133557885`*^-7,10{-0.06248782805662744`+0.008567488971716055` I,0.06248782805662735` +0.008567488971716091` I,-0.024530653254517365`+0.016432511028283876` I,0.02453065325451746` +0.016432511028283983` I,-0.0710828077955814`+0.0029899253446339417` I,0.07108280779558136` +0.0029899253446339265` I,4.369764930394141`*^-17+0.01753360746873406` I,0.046167699460222256` +0.01324327092099908` I,-0.046167699460222256`+0.013243270920998997` I},w],transmission[0.000028010416041124287`,10{-0.05671685428094213`+0.013803042018102346` I,0.056716854280942045` +0.013803042018102427` I,8.264942415996409`*^-17+0.022393915963795228` I,-0.070695783688365`+0.0049521909637789945` I,0.07069578368836495` +0.004952190963779001` I,0.03129082602637339` +0.020047809036221064` I,-0.03129082602637332`+0.02004780903622094` I},w],transmission[0.001454929726874729`,10{-0.04329511085046724`+0.02499999999999994` I,0.04329511085046724` +0.025000000000000064` I,-0.06976681936776287`+0.00961586688624272` I,0.06976681936775563` +0.00961586688624249` I,7.238898969656931`*^-15+0.030768266227514794` I},w],
transmission[0.0624733340226165`,10{0.` +0.05` I,-0.0661357183911121`+0.02499999999999998` I,0.0661357183911121` +0.02500000000000002` I},w]},{w,-1,+1},PlotPoints->1000]

(*we have perfect agreement, and the semianalytical method is actually much faster*)
Plot[transmission[1.,{2.+I,3.+I,4.+2I},w],{w,-5,+15},PlotRange->All]
Timing[mcurrentn[1.,{2.+I,3.+I,4.+2I},10.,1.,+2.,-2.]]
Timing[mcurrentp[1.,{2.+I,3.+I,4.+2I},10.,1.,+2.,-2.]]
Timing[ecurrentn[1.,{2.+I,3.+I,4.+2I},10.,1.,+2.,-2.]]
Timing[ecurrentp[1.,{2.+I,3.+I,4.+2I},10.,1.,+2.,-2.]]

Plot[{heatcurL[1.,{2.+I,3.+I,4.+2I},10.,1.,+V/2,-V/2.],heatcurLn[1.,{2.+I,3.+I,4.+2I},10.,1.,+V/2.,-V/2.]},{V,-10,+10}]

(*we now look at the particular transmission from Eq. (27) of Martensen 2019 for Γ0=1 and ϵ=0*)
NSolve[w^10+(123-55 Sqrt[5])/2^11,w]
N[(123-55 Sqrt[5])/2^11]

(*stretching the transmission can be achieved with modifying its parameters accordingly*)Plot[{transmission[7.940057378690024`*^-6,{-0.29389262614621936`+0.09549150281252068` I,-0.1816356320013296`+0.24999999999998535` I,0.` +0.3090169943749293` I,0.18163563200132957` +0.24999999999998537` I,0.29389262614621936` +0.0954915028125207` I},w/2],0.1+transmission[7.940057378690024`*^-6*2^10,2*{-0.29389262614621936`+0.09549150281252068` I,-0.1816356320013296`+0.24999999999998535` I,0.` +0.3090169943749293` I,0.18163563200132957` +0.24999999999998537` I,0.29389262614621936` +0.0954915028125207` I},w]},{w,-2,+2},PlotRange->All]

NSolve[0.5==transmission[7.940057378690024`*^-6,{-0.29389262614621936`+0.09549150281252068` I,-0.1816356320013296`+0.24999999999998535` I,0.` +0.3090169943749293` I,0.18163563200132957` +0.24999999999998537` I,0.29389262614621936` +0.0954915028125207` I},w],w,Reals]

mcurrentp[7.940057378690024`*^-6,{-0.29389262614621936`+0.09549150281252068` I,-0.1816356320013296`+0.24999999999998535` I,0.` +0.3090169943749293` I,0.18163563200132957` +0.24999999999998537` I,0.29389262614621936` +0.0954915028125207` I},10.,1.,1.,-1.]
ecurrentp[7.940057378690024`*^-6,{-0.29389262614621936`+0.09549150281252068` I,-0.1816356320013296`+0.24999999999998535` I,0.` +0.3090169943749293` I,0.18163563200132957` +0.24999999999998537` I,0.29389262614621936` +0.0954915028125207` I},10.,1.,1.,-1.]

(*find at which voltage we hit the optimal point*)
Solve[MB+1/2(BL+BR)/(BL-BR) V == -0.3090169943749221`,V]/.{MB->-1,BL->10,BR->1}
(*find at which voltage and at which MB we get optimal cooling*)
Solve[MB+V/2==-0.3090169943749221` && MB+BL BR/(2(BL-BR)) V==0.3090169943749221,{MB,V}]/.{BL->10,BR->1}

(*get the maximum power bound*)
((BL-BR)/(BL BR))^2*0.31635/(2 Pi)/.{BL->10,BR->1}
(*get maximum cooling current*)
Pi/(24*BL^2)/.{BL->10.}

NMaximize[{powern[1.507271778169777`*^-10 5^26,5 10{-0.06722279506715508`+0.0041515722519025675` I,0.0672227950671549` +0.004151572251902657` I,-0.04746244225013107`+0.008990508858564575` I,0.0474624422501291` +0.008990508858563907` I,-0.017086422376499745`+0.01185791888953065` I,0.017086422376501917` +0.01185791888953565` I,-0.07139533403306063`+0.001420544840018246` I,0.07139533403306038` +0.0014205448400182754` I,-0.03320950419552712`+0.010743388702000974` I,0.05900452346564712` +0.00671676583697003` I,3.510194467644447`*^-15+0.012238601242018067` I,0.03320950419552376` +0.010743388702003781` I,-0.059004523465646996`+0.006716765836970629` I},10.,1.,mb+V/2,mb-V/2],V>0.0 && mb<0},{V,mb}]

Export["test.dat",Monitor[Table[{V,powern[5^2,{I 5.0},10.,1.,-4.236673372397121`+V/2,-4.236673372397121`-V/2]},{V,-0.1,+2.,0.01}],V]]

ListPlot[{Monitor[Table[{V,powern[0.0624733340226165` 5^6,5 10{0.` +0.05` I,-0.0661357183911121`+0.02499999999999998` I,0.0661357183911121` +0.02500000000000002` I},10.,1.,-4.236673372397121`+V/2,-4.236673372397121`-V/2]},{V,-0.1,+2.,0.01}],V],Monitor[Table[{V,powern[0.001454929726874729` 5^10,5 10{-0.04329511085046724`+0.02499999999999994` I,0.04329511085046724` +0.025000000000000064` I,-0.06976681936776287`+0.00961586688624272` I,0.06976681936775563` +0.00961586688624249` I,7.238898969656931`*^-15+0.030768266227514794` I},10.,1.,-4.236673372397121`+V/2,-4.236673372397121`-V/2]},{V,-0.1,+2.,0.01}],V],Monitor[Table[{V,powern[0.000028010416041124287` 5^14,5 10{-0.05671685428094213`+0.013803042018102346` I,0.056716854280942045` +0.013803042018102427` I,8.264942415996409`*^-17+0.022393915963795228` I,-0.070695783688365`+0.0049521909637789945` I,0.07069578368836495` +0.004952190963779001` I,0.03129082602637339` +0.020047809036221064` I,-0.03129082602637332`+0.02004780903622094` I},10.,1.,-4.236673372397121`+V/2,-4.236673372397121`-V/2]},{V,-0.1,+2.,0.01}],V],Monitor[Table[{V,powern[5.0413133557885`*^-7 5^18,5 10{-0.06248782805662744`+0.008567488971716055` I,0.06248782805662735` +0.008567488971716091` I,-0.024530653254517365`+0.016432511028283876` I,0.02453065325451746` +0.016432511028283983` I,-0.0710828077955814`+0.0029899253446339417` I,0.07108280779558136` +0.0029899253446339265` I,4.369764930394141`*^-17+0.01753360746873406` I,0.046167699460222256` +0.01324327092099908` I,-0.046167699460222256`+0.013243270920998997` I},10.,1.,-4.236673372397121`+V/2,-4.236673372397121`-V/2]},{V,-0.1,+2.,0.01}],V],Monitor[Table[{V,powern[8.787178823266184`*^-9 5^22,5 10{-0.06547894350168432`+0.005785086515072126` I,0.06547894350168425` +0.005785086515072048` I,-0.038712814673174535`+0.012004438044102764` I,0.038712814673170955` +0.01200443804410438` I,3.666225319691539`*^-15+0.014420950881648688` I,-0.054204880905291436`+0.009212358199346082` I,0.0712778727231097` +0.0019939983170310944` I,-0.020137087810394277`+0.013793643483634899` I,0.05420488090534879` +0.009212358199331092` I,0.020137087810395266` +0.013793643483639921` I,-0.07127787272316805`+0.0019939983170169217` I},10.,1.,-4.236673372397121`+V/2,-4.236673372397121`-V/2]},{V,-0.1,+2.,0.01}],V],
Monitor[Table[{V,powern[1.507271778169777`*^-10 5^26,5 10{-0.06722279506715508`+0.0041515722519025675` I,0.0672227950671549` +0.004151572251902657` I,-0.04746244225013107`+0.008990508858564575` I,0.0474624422501291` +0.008990508858563907` I,-0.017086422376499745`+0.01185791888953065` I,0.017086422376501917` +0.01185791888953565` I,-0.07139533403306063`+0.001420544840018246` I,0.07139533403306038` +0.0014205448400182754` I,-0.03320950419552712`+0.010743388702000974` I,0.05900452346564712` +0.00671676583697003` I,3.510194467644447`*^-15+0.012238601242018067` I,0.03320950419552376` +0.010743388702003781` I,-0.059004523465646996`+0.006716765836970629` I},10.,1.,-4.236673372397121`+V/2,-4.236673372397121`-V/2]},{V,-0.1,+2.,0.01}],V]},PlotRange->{0,All}]

NMaximize[{powerid[wmin,wmin+7.5,10.,1.,-4.236673372397121`+V/2,-4.236673372397121`-V/2],V>0},{wmin,V}]

Export["test.dat",Table[{V,powerid[-3.6070047297992924,-3.6070047297992924+7.5,10.,1.,-4.236673372397121`+V/2,-4.236673372397121`-V/2]},{V,-0.1,+2.,0.01}]]

Plot[powerid[-3.6070047297992924,-3.6070047297992924+7.5,10.,1.,-4.236673372397121`+V/2,-4.236673372397121`-V/2],{V,-0.1,2.}]

NMaximize[{heatcurLn[1.507271778169777`*^-10 5^26,5 10{-0.06722279506715508`+0.0041515722519025675` I,0.0672227950671549` +0.004151572251902657` I,-0.04746244225013107`+0.008990508858564575` I,0.0474624422501291` +0.008990508858563907` I,-0.017086422376499745`+0.01185791888953065` I,0.017086422376501917` +0.01185791888953565` I,-0.07139533403306063`+0.001420544840018246` I,0.07139533403306038` +0.0014205448400182754` I,-0.03320950419552712`+0.010743388702000974` I,0.05900452346564712` +0.00671676583697003` I,3.510194467644447`*^-15+0.012238601242018067` I,0.03320950419552376` +0.010743388702003781` I,-0.059004523465646996`+0.006716765836970629` I},10.,1.,mb+V/2,mb-V/2],mb<0 && mb>-20 && V>0 && V<50},{V,mb},MaxIterations->1000]

Export["test.dat",Monitor[Table[{V,heatcurLn[1.507271778169777`*^-10 5^26,5 10{-0.06722279506715508`+0.0041515722519025675` I,0.0672227950671549` +0.004151572251902657` I,-0.04746244225013107`+0.008990508858564575` I,0.0474624422501291` +0.008990508858563907` I,-0.017086422376499745`+0.01185791888953065` I,0.017086422376501917` +0.01185791888953565` I,-0.07139533403306063`+0.001420544840018246` I,0.07139533403306038` +0.0014205448400182754` I,-0.03320950419552712`+0.010743388702000974` I,0.05900452346564712` +0.00671676583697003` I,3.510194467644447`*^-15+0.012238601242018067` I,0.03320950419552376` +0.010743388702003781` I,-0.059004523465646996`+0.006716765836970629` I},10.,1.,-19.27396578502566`+V/2,-19.27396578502566`-V/2]},{V,29,+32,0.01}],V]]

ListPlot[{Monitor[Table[{V,heatcurLn[0.0624733340226165` 5^6,5 10{0.` +0.05` I,-0.0661357183911121`+0.02499999999999998` I,0.0661357183911121` +0.02500000000000002` I},10.,1.,-19.27396578502566`+V/2,-19.27396578502566`-V/2]},{V,29,+32,0.01}],V],Monitor[Table[{V,heatcurLn[0.001454929726874729` 5^10,5 10{-0.04329511085046724`+0.02499999999999994` I,0.04329511085046724` +0.025000000000000064` I,-0.06976681936776287`+0.00961586688624272` I,0.06976681936775563` +0.00961586688624249` I,7.238898969656931`*^-15+0.030768266227514794` I},10.,1.,-19.27396578502566`+V/2,-19.27396578502566`-V/2]},{V,29,+32,0.01}],V],Monitor[Table[{V,heatcurLn[0.000028010416041124287` 5^14,5 10{-0.05671685428094213`+0.013803042018102346` I,0.056716854280942045` +0.013803042018102427` I,8.264942415996409`*^-17+0.022393915963795228` I,-0.070695783688365`+0.0049521909637789945` I,0.07069578368836495` +0.004952190963779001` I,0.03129082602637339` +0.020047809036221064` I,-0.03129082602637332`+0.02004780903622094` I},10.,1.,-19.27396578502566`+V/2,-19.27396578502566`-V/2]},{V,29,+32,0.01}],V],Monitor[Table[{V,heatcurLn[5.0413133557885`*^-7 5^18,5 10{-0.06248782805662744`+0.008567488971716055` I,0.06248782805662735` +0.008567488971716091` I,-0.024530653254517365`+0.016432511028283876` I,0.02453065325451746` +0.016432511028283983` I,-0.0710828077955814`+0.0029899253446339417` I,0.07108280779558136` +0.0029899253446339265` I,4.369764930394141`*^-17+0.01753360746873406` I,0.046167699460222256` +0.01324327092099908` I,-0.046167699460222256`+0.013243270920998997` I},10.,1.,-19.27396578502566`+V/2,-19.27396578502566`-V/2]},{V,29,+32,0.01}],V],Monitor[Table[{V,heatcurLn[8.787178823266184`*^-9 5^22,5 10{-0.06547894350168432`+0.005785086515072126` I,0.06547894350168425` +0.005785086515072048` I,-0.038712814673174535`+0.012004438044102764` I,0.038712814673170955` +0.01200443804410438` I,3.666225319691539`*^-15+0.014420950881648688` I,-0.054204880905291436`+0.009212358199346082` I,0.0712778727231097` +0.0019939983170310944` I,-0.020137087810394277`+0.013793643483634899` I,0.05420488090534879` +0.009212358199331092` I,0.020137087810395266` +0.013793643483639921` I,-0.07127787272316805`+0.0019939983170169217` I},10.,1.,-19.27396578502566`+V/2,-19.27396578502566`-V/2]},{V,29,+32,0.01}],V],
Monitor[Table[{V,heatcurLn[1.507271778169777`*^-10 5^26,5 10{-0.06722279506715508`+0.0041515722519025675` I,0.0672227950671549` +0.004151572251902657` I,-0.04746244225013107`+0.008990508858564575` I,0.0474624422501291` +0.008990508858563907` I,-0.017086422376499745`+0.01185791888953065` I,0.017086422376501917` +0.01185791888953565` I,-0.07139533403306063`+0.001420544840018246` I,0.07139533403306038` +0.0014205448400182754` I,-0.03320950419552712`+0.010743388702000974` I,0.05900452346564712` +0.00671676583697003` I,3.510194467644447`*^-15+0.012238601242018067` I,0.03320950419552376` +0.010743388702003781` I,-0.059004523465646996`+0.006716765836970629` I},10.,1.,-19.27396578502566`+V/2,-19.27396578502566`-V/2]},{V,29,+32,0.01}],V]},PlotRange->{0,All}]

NMaximize[{heatcurLid[wmin,wmin+7.5,10.,1.,-19.27396578502566+V/2,-19.27396578502566-V/2],V>29 && V<32 && wmin>-5. && wmin<+0.},{wmin,V}]

(*if we shift the transmission a bit, we get the same maximum, just at a different position*)
NMaximize[{heatcurLid[-3.6070047297992924,-3.6070047297992924+7.5,10.,1.,-19.27396578502566+V/2,-19.27396578502566-V/2],V>29 && V<32},{V}]

-3.9490749319712166+0.333

(*we shift the transmission a bit, this merely alters the voltage window*)
Export["test.dat",Table[{V,heatcurLid[-3.6070047297992924,-3.6070047297992924+7.5,10.,1.,-19.27396578502566+V/2,-19.27396578502566-V/2]},{V,29.0,32.0,0.01}]]

Plot[heatcurLid[-3.9490749319712166+0.25,-3.9490749319712166+7.5+0.25,10.,1.,-19.27396578502566+V/2,-19.27396578502566-V/2],{V,29.0,32.0},PlotRange->{0,All}]

ListPlot[Monitor[Table[{V,heatcurL[7.940057378690024`*^-6,{-0.29389262614621936`+0.09549150281252068` I,-0.1816356320013296`+0.24999999999998535` I,0.` +0.3090169943749293` I,0.18163563200132957` +0.24999999999998537` I,0.29389262614621936` +0.0954915028125207` I},10.,1.,-10+V/2,-10-V/2]},{V,18.,+19.9,0.01}],V],PlotRange->{0,All}]

(*compare Carnot efficiency (blue), calculated efficiency at max power (orange) and Curzon-Ahlborn efficiency (green)*)
Plot[{1-x,(1-x)/(1+0.93593(1+x)),1-Sqrt[x]},{x,0,1}]