c*********************************************************************** c dualfoil.f (version 5.1) April 7, 2008 c Dual lithium ion insertion cell c Copyright Marc Doyle and John Newman 1998. c You may make a copy of this program which you may c personally and freely use in its unaltered form. c You may distribute this program subject to the c conditions that it be made freely available and c that any duplication of this program must be c essentially unaltered and must include this notice. c c We make no warranties, express or implied, that c this program is free of errors or that it will c meet the requirements of your application. The c author and publisher disclaim all liablility for c direct or consequential damages resulting from c use of this program. c c Note: For lflag=0, the model works only for initially zero current. c c*********************************************************************** c Based on the original articles: c Marc Doyle, Thomas F. Fuller, and John Newman, c J. Electrochem. Soc., 140 (1993), 1526-1533. c Thomas F. Fuller, Marc Doyle, and John Newman, c J. Electrochem. Soc., 141 (1994), 1-10. c Thomas F. Fuller, Marc Doyle, and John Newman, c J. Electrochem. Soc., 141 (1994), 982-990. c This program was developed for lithium and lithium-ion c batteries, with the flexibility that a number of positive c and negative active materials of the insertion or intercalation c type can be selected or added, in addition to a lithium foil c electrode. Several electrolytes are also provided, and c these can be added to by providing properties in subroutine c prop. An aqueous system, such as a nickel/metal hydride c battery in a KOH solution, could also be added, since it c follows the pattern of being a dual-insertion system. Primary c cells, as well as rechargeable cells, can be simulated with c this program. c This program should be very similar to Marc c Doyle's impedance program of 1995 to 1998. c See Doyle, Meyers, Darling, Newman, JES, 147 (2000), c 99-110 and 147 (2000), 2930-2940. c The program has been modified to include a c zero time step in order to get the potentials c and currents correct and to have the impedance c independent of the initial values set in c subroutine guess. It should run even with c a nonzero current density, but this is not c recommended and is not proper in the sense c of having a steady state as a basis for the c impedance simulation (one of the criteria for c the validity of the Kramers-Kronig relations). c The program has been cleaned up a lot by c rearranging equations ii2, i2div, and kp1 and c simplifying the impedance statements. c c Includes FOIL and impedance option 7-1-95 c Some modifications made to Bellcore stuff on 1-12-96 c Error in EIS b.c.'s for eqns i2div and ip1 fixed 1-23-96 c Some additional changes up to 7/96 incl. film resistance c c Modified impedance section by Newman on 4/4/98 c HALF-CELL version: split off from impnew1.f on 4/19/98 c Current newest version June 29, 1998 c Has Jeremy Meyers modifications 6/98 c c Revised June, 1998, to include double-layer capacitance in c each electrode and to correct a factor of two in Ohm's law. c See J. Electrochem. Soc., 146 (1999), 4360-4365. c c Revised by Karen Thomas, Feb. 12, 1999: c - if n1 = 0, then code treats the negative electrode as metal foil. c - To run, simply type "dualfoil", then enter c input and output file names when prompted. c - double-layer capacitance is not currently calculated at c a foil electrode c July 16, 2000: c - Program modified to be compatible with g77 fortran compiler. c July 6, 2001: c - Prints total and irreversible heat generation; positive heat c is exothermic c August 2002: c - corrected double precision, added graphite, LiCoO2, and LiNi0.8Co0.2O2 c May 2003: c - made compatible with Compaq visual fortran compiler, other minor changes c April, 2005: c -The version of Dualfoil dated (July 15, 2003) used a single cutoff c potential, which caused problems when a user attempted to charge the cell c following a discharge. For example, if the global cutoff potential was c set to 3.0 V and the cell discharged beneath that value, upon charging the c cutoff potential would be triggered when the cell potential exceeded 3.0 V. c The revised version of dualfoil.f uses two global cutoff potentials, c one that serves as an upper bound and one that serves as a lower bound. c dualfoil.in has been modified to allow the user to specify two cutoff c potentials. c July, 2007: c -A series of major modifications have been made since the April, 2005 version. c See the guide posted on this page for more information. Note that c all previous functionality is maintained by the current version. Following is c an abbreviated list of the changes that have been made: c - Addition of specified load and power modes c - Ability to specify an upper and lower cutoff potential for each segment c - Addition of NiMH materials (MH anode, NiOOH cathode, KOH electrolyte) c - Addition of side reactions to model gas-phase recombination in NiMH system c or side reactions in another system (e.g., solvent reduction in a Li-ion cell). c - Ability to use a variable solid-phase diffusion coefficient in a c "pseudo-2d" arrangement c - Use of a new input file with activation energies for temperature dependences c of the transport properties (solid and electrolyte diffusion, electrolyte c conductivity), rate constants, and film resistances. Where appropriate c there is a separate activation energy in each electrode. The activation c energies are stored in the input file ebar.in c - Detailed profiles are now written as the program goes along (rather c than after the code has finished running) to a separate file, called c profiles.out, if the user selects il1=1 c - A problem with the identity/capacity/density of the cathode in the c default input file has been corrected c - The unused subroutine util has been removed c - An additional equation has been added to improve convergence c when running constant potential, power, and load. c - The ability to have up to five particles per electrode has been added c - The variables and equations have been given names rather than numbers c - The energy balance is now done according to the method given c in Rao and Newman, J. Electrochem. Soc., 144 (1997), 2697-2704. c Cp(dT/dt)-Q=-Integral(sum over reactions (a*in,i*Uh,i))dx-IV c February, 2008: c The following changes have been made in going from version 5.0 to 5.1 c - Subroutine guess has been removed c - Convergence has been improved and the dV/dt trigger has been removed c - fj(j) for cutting off part of the electrode has been removed c - The variables have been renamed c - A grid resistance, RG, has been added c - An error in the impedance calculation for anode and cathode has c been corrected; the original full-cell impedance was correct c - The equation structure for impedance mode has been made general, c facilitating future additions c - We have improved the output formatting c - We have improved the logic of the multiple-particle selection section c*********************************************************************** implicit real*8(a-h,o-z) character *30 filin, filout parameter(maxt=900) common /n/ tmmax,imp,ji,nx,nt,n1,n2,nj,n3,nconv,npa,iSk3,kj3 &,ii2,ki2,kj,i2div,ip2,kp2,ip1,kp1,imb2,kS2,imb1,kS1,iSk1,kj1 &,iSk2,kj2 common/activ/ EbarD,Ebarkap,Ebarka,Ebarkc,Ebarr1,Ebarr3, &Ebars1,Ebars3,Ebarks1a,Ebarks1c,Ebarks2a,Ebarks2c, &Ebarks3a,Ebarks3c common /calc/ ai(maxt,5),ai2(maxt,5),ts(maxt),h,h1,h2,h3,hcn, 1hcp,rr,rrmax,cuL,sumpa(5,221),Rad1pa(5),Rad3pa(5),area1pa(5) &,area3pa(5),mcL common/pindiv/pwfindiv(5,221),pwfindiv_d(5,221),vf1(5),vf3(5),izfl common/const/ fc,r,t,frt,cur,ep3,ep2,pi,ep1,epf3,epf1, &epp1,epp2,epp3,shape3,shape1,capp1,capp3,nneg,nprop,npos common/power/ ed,Vold,ranodesave,rcathdesave,heat,qlosstot common/ssblock/ xp0(16),xx0(16,221),term(221) common/var/ xp(16),xx(17,221),xt(16,221,maxt) common/imp/ vreal(110),vimag(110),phi(110),zmag(110),omega(510), 1vreala(110),vrealc(110),vimaga(110),vimagc(110), 1phia(110),phic(110),zmaga(110),zmagc(110) common/cprop/ sig3,area3,rka3,rka3save,ct3,dfs3,Rad3,cap1,cap3, 1sig1,area1,rka1,rka1save,ct1,dfs1,Rad1,tw,dfs1save,dfs3save common/tprop/df(221),cd(221),tm(221),ddo2(221),ddh2(221), 1ddf(221),dcd(221),dtm(221),dfu(221),d2fu(221),do2(221),dh2(221) common/temp/ thk,htc,dudt,Cp,dens,tam,g0,qq,qloss,residm,ncell,lht common/side/rksc1,c1init,c2init,rksa1,term_s1(221),vol, &rksa2,rksa3,rksc3,rksc2,UsO2,UsH2,cn2,term_s2(221),nside COMMON /vdc/ aa(1,1),bb(1,1),cc(1,150),dd(1,3),gg(1),xxx(1,1), 1yy(1,1),hha,hhc,cssold(220,150),css(220,150),utz(5,221), &dsold(220,150),ds(220,150),time,nn,nnj,np,mvdc1,mvdc3,lims common/gas/ epg1,epg2,epg3 common /maxpow/ lcount common/RG/ RG,RGn,RGp,RGext dimension terms(221),tt(200),cu(200),tot(200),mc(200),taper(200) dimension vcutlo(200),vcuthi(200) dimension term_s1s(221) dimension rad1paf(5),rad3paf(5) 44 format(/' mass = ',f7.4,' kg/m2') 45 format(' specific energy whole run = ',f8.2,' W-h/kg') 46 format(' specific power whole run = ',f8.2,' W/kg') 47 format(' total heat = ', f15.4,' W-h/m2') 48 format(' specific energy segment = ', f8.2,' W-h/kg') 49 format(' specific power segment = ', f8.2,' W/kg') 57 format(e15.6,', ',e15.6,', ',e15.6) 89 format(f8.1,',',f8.1,',',f8.1,',',i3,',',g10.5,',',f5.2) 90 format (g10.3,',') c open(3,file='halfcells.out',status='unknown') write (3,*) ' Time (min) V neg V pos Cur (A/m2) ' &,' Temp (C) Heat Gen (W/m3)' c print *, 'Enter input file name, press return' c read *, filin open (1, FILE = 'dualfoil5.in', status = 'old') c open (1, FILE = filin, status = 'old') c print *, 'Enter output file name, press return' c read *, filout open (2, file = 'dualfoil5.out', status = 'unknown') c open (2, file = filout, status = 'unknown') open (4,file='profiles.out',status='unknown') ! for detailed profiles open (5,file='li-ion-ebar.in', status='old') ! activation energies open (6,file='resistances.out',status='unknown') ! for cell resistance open (7,file='solidprof.out',status='unknown') ! for profile inside solid c data fc/96487.0d0/, r/8.314d0/, pi/3.141592653589d0/ data ed/0.d0/, Vold/0.d0/ npa=1 ! Number of particle sizes if (npa.ne.1.and.imp.eq.1) print *,'npa must be 1 for imp=1' ii2=3+npa ! equation number for current density i2 ki2=3+npa ! variable number for current density i2 i2div=4+npa ! equation number for current balance. kj=4+npa ! variable number for transfer current (flux density). ip1=5+npa ! equation number for Ohm's law in the matrix. kp1=5+npa ! variable number for PHI_1, matrix potential. ip2=2 ! equation number for Ohm's law in solution. kp2=2 ! variable number for PHI_2, solution potential. imb1=6+npa ! equation number (side reaction 1 matl balance) kS1=6+npa ! variable number (side reaction 1 matl balance) iSk1=7+npa ! equation number (side reaction 1 kinetics) kj1=7+npa ! variable number (side reaction 1 kinetics) iSk2=8+npa ! equation number (side reaction 2 kinetics) kj2=8+npa ! variable number (side reaction 2 kinetics) imb2=9+npa ! equation number (side reaction 2 matl balance) kS2=9+npa ! variable number (side reaction 2 matl balance) iSk3=10+npa ! equation number (side reaction 3 kinetics) kj3=10+npa ! variable number (side reaction 3 kinetics) lim2=100 ! limit for iterations to converge load/power/poten c Split of RG into its components. WHT RG=5.0d-3 !total resistance in foils, leads, and contacts, ohm-m2 WHT RG=0.0d0 RGn=RG/3.0d0 ! resistance affecting negative half cell RGp=RG-RGn ! resistance affecting positive half cell RGext=0.0d0 ! resistance outside cell c c*********************************************************************** c read in parameters and boundary conditions c read (1,*) lim !limit on number of iterations read (1,*) h1 !thickness of negative electrode (m) read (1,*) h2 !thickness of separator (m) read (1,*) h3 !thickness of positive electrode (m) read (1,*) hcn !thickness of negative electrode current collector (m) read (1,*) hcp !thickness of positive electrode current collector (m) thk=h1+h2+h3 read (1,*) n1 !number of nodes in negative electrode c If negative electrode is metal foil, let n1 = 0 read (1,*) n2 !number of nodes in separator read (1,*) n3 !number of nodes in positive electrode read (1,*) n4 !number of nodes in solid particle read (1,*) mvdc1 !flag for variable solid diff coeff, anode read (1,*) mvdc3 !flag for variable solid diff coeff, cathode read (1,*) lims !limit on number of iterations in solid phase read (1,*) t !temperature (K) write (2,1101) lim,1.d6*h1,1.d6*h2,1.d6*h3,1.d6*hcn,1.d6*hcp &,n1,n2,n3,t n2=n2+1 nj=n1+n2+n3 nnj=n4 c read (1,*) xx(1,n1+2) ! initial concentration (mol/m3) read (1,*) csx !initial stochiometric parameter for negative read (1,*) csy !initial stochiometric parameter for positive read (1,*) tmmax !maximum time step size (s) read (1,*) dfs1 !diffusion coefficient in negative solid (m2/s) read (1,*) dfs3 !diffusion coefficient in positive solid (m2/s) dfs1save=dfs1 !save the original values because of temp dependence dfs3save=dfs3 read (1,*) Rad1 !radius of negative particles (m) read (1,*) Rad3 !radius of positive particles (m) write (2,1102) xx(1,n1+2),csx,csy,tmmax,dfs1,dfs3, &1.d6*Rad1,1.d6*Rad3 c If negative electrode is metal foil, let ep1=epp1=epf1=0.0 read (1,*) ep1 !volume fraction of electrolyte in negative electrode read (1,*) epp1 !volume fraction of polymer phase in negative electrode read (1,*) epf1 !volume fraction of inert filler in negative electrode read (1,*) epg1 !volume fraction of gas in negative read (1,*) ep2 !volume fraction of electrolyte in separator read (1,*) epp2 !volume fraction of polymer phase in separator read (1,*) epg2 !volume fraction gas in separator read (1,*) ep3 !volume fraction of electrolyte in positive electrode read (1,*) epp3 !volume fraction of polymer phase in positive electrode read (1,*) epf3 !volume fraction of inert filler in positive electrode read (1,*) epg3 !volume fraction of gas in positive read (1,*) sig1 !conductivity of solid negative matrix (S/m) read (1,*) sig3 !conductivity of solid positive matrix (S/m) read (1,*) rka1 !reaction rate constant for negative reaction read (1,*) rka3 !reaction rate constant for positive reaction rka1save=rka1 rka3save=rka3 read (1,*) ranode !anode film resistance (out of place) read (1,*) rcathde !cathode film resistance (out of place) ranodesave=ranode rcathdesave=rcathde read (1,*) cot1 !coulombic capacity of negative material (mAh/g) read (1,*) cot3 !coulombic capacity of positive material (mAh/g) write (2,1103) ep1,epp1,epf1,ep2,epp2,ep3,epp3,epf3,sig1, & sig3,cot1, cot3,rka1,rka3 read (1,*) re ! density of electrolyte (kg/m3) read (1,*) rs1 ! density of negative insertion material (kg/m3) read (1,*) rs3 ! density of positive insertion material (kg/m3) read (1,*) rf ! density of inert filler (kg/m3) read (1,*) rpl ! density of polymer phase (kg/m3) read (1,*) rc ! density of separator material (kg/m3) read (1,*) rcn ! density of negative current collector (kg/m3) read (1,*) rcp ! density of positive current collector (kg/m3) write (2,1104) re,rs1,rs3,rf,rpl,rc,rcn,rcp read (1,*) htc !heat-transfer coefficient with external medium (W/m2K) read (1,*) Cp !heat capacity of cell (J/kgK) read (1,*) Tam !ambient temperature (K) read (1,*) ncell !number of cells in a cell stack read (1,*) lht !0 uses htc, 1 calcs htc, 2 isothermal read (1,*) il1 !1 for long print-out 0 for short print-out read (1,*) il2 !1/il2 = fraction of nodes in long print-out read (1,*) il3 !1/il3 = fraction of time steps in long print-out read (1,*) lflag ! 0 for electrolyte in separator only, 1 for uniform read (1,*) imp ! 0 for no impedance, 1 for impedance read (1,*) capp1 ! capacitance of negative material (F/m2) read (1,*) capp3 ! capacitance of positive material (F/m2) read (1,*) lpow ! 0 for no power peaks, 1 for power peaks read (1,*) jsol ! calculate solid profiles if 10 if((mvdc1.eq.1.and.j.le.n1+1).or. &(mvdc3.eq.1.and.j.ge.n1+n2)) then ! Variable diffusion coefficient mpa=1 ! only one size for variable solid-phase diffusion coefficient if(j.gt.n1+1 .and. j.lt.n1+n2) then b(2+mpa,kj)=1.0d0 g(2+mpa)=-c(kj,j) ! zero transfer current in separator else call ekin(j,kk,0,0.0d0,1,mvdc1,mvdc3) if(j.eq.n1+n2) Uc=g0 if(j.eq.1) Ua=g0 endif else !using superposition do mpa=1,npa if(j.gt.n1+1 .and. j.lt.n1+n2) then !separator if (imp.eq.0) then b(2+mpa,2+mpa)=1.0d0 g(2+mpa)=-c(2+mpa,j) ! zero solid concentration in separator else b(2+mpa,kj)=1.0d0 g(2+mpa)=-c(kj,j) endif else call ekin(j,kk,0,0.0d0,mpa,mvdc1,mvdc3) if(j.eq.n1+n2 .and. mpa.eq.1) Uc=g0 if(j.eq.1 .and. mpa.eq.1) Ua=g0 if(j.le.n1+1) then g(2+mpa)=g(2+mpa)+xx(kj,j)-Rad1pa(mpa)*(-sumpa(mpa,j) & +ai2(1,mpa)/rr*omi*(xt(2+mpa,j,kk-1+kadd)-c(2+mpa,j))) b(2+mpa,2+mpa)=b(2+mpa,2+mpa)-Rad1pa(mpa)*ai2(1,mpa)/rr*omi if (imp.eq.0) b(2+mpa,kj)=b(2+mpa,kj)-1.d0 elseif(j.ge.n1+n2) then g(2+mpa)=g(2+mpa)+xx(kj,j)-Rad3pa(mpa)*(-sumpa(mpa,j) & +ai(1,mpa)/rr*omi*(xt(2+mpa,j,kk-1+kadd)-c(2+mpa,j))) b(2+mpa,2+mpa)=b(2+mpa,2+mpa)-Rad3pa(mpa)*ai(1,mpa)/rr*omi if (imp.eq.0) b(2+mpa,kj)=b(2+mpa,kj)-1.d0 endif endif enddo ! mpa endif endif mpa=1 ! only one size for impedance if (imp.eq.1) g(2+mpa)=0.0d0 if(imp.eq.1) g(2+mpa+n)=0.0d0 c ________________________________________________ c Equation iSk1. Side reaction 1 kinetics c This is set up for oxygen evolution (Tafel) and c recombination (concentration driven) for the NiMH system. c We also have a sample side reaction for solvent reduction/oxidation c in a Li-ion system. Tafel kinetics is used at each electrode. c For this reaction, we recommend setting rksa1=1.0d-9 and rksac1=1.0d-9 c in the input file. if (nside.ge.1) then rksa1_save=rksa1 rksc1_save=rksc1 ti0n=dexp((Ebarks1a)*(t-298.0d0)/(t*298.0d0)) ti0p=dexp((Ebarks1c)*(t-298.0d0)/(t*298.0d0)) rksa1=rksa1*ti0n rksc1=rksc1*ti0p alphasO2=1.17d0 UsO2=0.25d0 if (j.le.n1+1) then !recombination at the anode g(iSk1)=-c(kj1,j)+rksa1*c(kS1,j) b(iSk1,kj1)=1.0d0 b(iSk1,kS1)=-rksa1 c Sample kinetics for side reaction in a Li-ion system: comment out c the above and uncomment the below. We use an alpha value of 0.5 c and use a value of 1.0 V for the "equilibrium" potential of c solvent reduction c g(iSk1)=-c(kj1,j)-rksa1*expg(0.5d0*frt*(c(kp1,j)-c(kp2,j)-1.d0)) c b(iSk1,kj1)=1.0d0 c b(iSk1,kp1)=rksa1*0.5d0*frt*expg(0.5d0*frt*(c(kp1,j)-c(kp2,j) c &-1.d0)) c b(iSk1,kp2)=-b(iSk1,kp1) elseif (j.ge.n1+n2) then !evolution at the cathode g(iSk1)=-c(kj1,j)-rksc1*expg(alphasO2*frt*(c(kp1,j)-c(kp2,j) &-UsO2)) b(iSk1,kj1)=1.0d0 b(iSk1,kp1)=rksc1*alphasO2*frt*expg(alphasO2*frt* &(c(kp1,j)-c(kp2,j)-UsO2)) b(iSk1,kp2)=-b(iSk1,kp1) c Sample kinetics for side reaction in a Li-ion system: comment out c the above and uncomment the below. We use an alpha value of 0.5 c and use a value of 4.4 V for the "equilibrium" potential of c solvent oxidation c g(iSk1)=-c(kj1,j)-rksc1*expg(0.5d0*frt*(c(kp1,j)-c(kp2,j)-4.d0)) c b(iSk1,kj1)=1.0d0 c b(iSk1,kp1)=rksc1*0.5d0*frt*expg(0.5d0*frt*(c(kp1,j)- c 1c(kp2,j)-4.d0)) c b(iSk1,kp2)=-b(iSk1,kp1) else !in the separator g(iSk1)=c(kj1,j) b(iSk1,kj1)=-1.0d0 endif else g(iSk1)=0.0d0 endif rksa1=rksa1_save rksc1=rksc1_save c ________________________________________________ c Equation iSk2. Side reaction 2 kinetics c This is set up for hydrogen evolution from the negative electrode c of the NiMH system. if (nside.ge.2) then alphasH2=1.0d0 UsH2=-0.98d0 rksa2_save=rksa2 rksc2_save=rksc2 ti0n=dexp((Ebarks3a)*(t-298.0d0)/(t*298.0d0)) ti0p=dexp((Ebarks3c)*(t-298.0d0)/(t*298.0d0)) rksa2=rksa2*ti0n rksc2=rksc2*ti0p if (j.le.n1+1) then c H2 evolution from the negative electrode only. g(iSk2)=c(kj2,j)-rksa2*expg(-alphasH2*frt*(c(kp1,j) &-c(kp2,j)-UsH2)) b(iSk2,kj2)=-1.0d0 b(iSk2,kp1)=-rksa2*alphasH2*frt* &expg(-alphasH2*frt*(c(kp1,j)-c(kp2,j)-UsH2)) b(iSk2,kp2)=-b(iSk2,kp1) else !in the separator or the positive g(iSk2)=c(kj2,j) b(iSk2,kj2)=-1.0d0 endif else if(imp.eq.1) g(3+n)=0.0d0 endif rksa2=rksa2_save rksc2=rksc2_save c ________________________________________________ c Equation iSk3. Side reaction 3 kinetics c This is set up for hydrogen absorption/desorption in the c negative electrode of the NiMH system. c Positive j is H leaving the solid phase if (nside.eq.3) then rksa3_save=rksa3 rksc3_save=rksc3 ti0e=dexp((Ebarks2a)*(t-298.0d0)/(t*298.0d0)) ti0r=dexp((Ebarks2c)*(t-298.0d0)/(t*298.0d0)) rksa3=rksa3*ti0e rksc3=rksc3*ti0r mpa=1 ! only one size with side reactions if (j.le.n1+1) then c H2 absorption, using an equilibrium isotherm from the literature g(iSk3)=c(kj3,j)+rksa3*(c(kS2,j)*t*8.206d-5- &(5.d0+4.9999d0*dtanh((c(2+mpa,j)/ct1-1.04d0)/0.11d0))) b(iSk3,kS2)=-rksa3*t*8.2d-5 b(iSk3,2+mpa)=-rksa3*4.9999d0* &((dcosh((c(2+mpa,j)/ct1-1.04d0)/0.11d0))**(-2))*1.0d0/0.11d0/ct1 b(iSk3,kj3)=-1.0d0 elseif (j.ge.n1+n2) then !reaction at the positive electrode g(iSk3)=c(kj3,j) b(iSk3,kj3)=-1.0d0 else !in the separator g(iSk3)=c(kj3,j) b(iSk3,kj3)=-1.0d0 endif else mpa=1 ! only one size for impedance if(imp.eq.1) g(5+n)=0.0d0 endif rksa3=rksa3_save rksc3=rksc3_save c ________________________________________________ c Equation ip1, Ohm's law in solid c if(j.eq.1) then if (n1 .eq. 0) then ! foil electrode g(ip1) = cur - fc*c(kj,j) b(ip1,kj) = fc if(imp.eq.1) then g(ip1) = 1.d0 c area1 is mult by L here so aL is 1 in double-layer charging term: b(ip1,kp2+n)=omega(ji)*capp1 b(ip1,kp1+n)=-omega(ji)*capp1 b(ip1+n,kp2)=-omega(ji)*capp1 b(ip1+n,kp1)=omega(ji)*capp1 endif ! impedance section (j=1, a) else b(ip1,kp1)=-1.0d0/h1 ! not a foil electrode d(ip1,kp1)= 1.0d0/h1 b(ip1,ki2)=-1.0d0/sig1 c next statement requires that cur be the current in the separator g(ip1)=-cur/sig1+c(ki2,j)/sig1-(c(kp1,j+1)-c(kp1,j))/h1 if(imp.eq.1) g(ip1)=-1.0d0/sig1 endif elseif(j.lt.n1+1) then ! anode b(ip1,kp1)=-1.0d0/h1 d(ip1,kp1)= 1.0d0/h1 b(ip1,ki2)=-1.0d0/sig1 g(ip1)=-cur/sig1+c(ki2,j)/sig1-(c(kp1,j+1)-c(kp1,j))/h1 if(imp.eq.1) g(ip1)=-1.0d0/sig1 elseif(j.eq.n1+1) then c This is the current boundary condition. if(mcL.eq.-3) then ! constant load g(ip1)=(xx(nx+1,j+1)-xx(nx+1,j))/xx(ki2,j)-cuL-RG !WHT 1-11-08 d(ip1,nx+1)=-1.d0/xx(ki2,j) b(ip1,nx+1)=1.d0/xx(ki2,j) b(ip1,ki2)=(xx(nx+1,j+1)-xx(nx+1,j))/xx(ki2,j)**2 elseif(mcL.eq.0) then ! constant potential g(ip1)=xx(nx+1,j+1)-xx(nx+1,j)-cuL-RG*xx(ki2,j) !WHT 1-11-08 d(ip1,nx+1)=-1.d0 b(ip1,nx+1)=1.d0 b(ip1,ki2)=RG !WHT 1-11-08 elseif(mcL.eq.-2) then ! constant power g(ip1)=(xx(nx+1,j+1)-xx(nx+1,j))*xx(ki2,j)-cuL-RG*xx(ki2,j)**2 !WHT 1-11-08 d(ip1,nx+1)=-xx(ki2,j) b(ip1,nx+1)=xx(ki2,j) b(ip1,ki2)=-(xx(nx+1,j+1)-xx(nx+1,j))+2.d0*RG*xx(ki2,j) !WHT 1-11-08 elseif(mcL.eq.-4) then ! maximum power g(ip1)=xx(nx+1,j+1)-xx(nx+1,j)-xx(ki2,j)*Rint !RG*something d(ip1,nx+1)=-1.d0 b(ip1,nx+1)=1.d0 b(ip1,ki2)=Rint cu0=(xx(nx+1,j+1)-xx(nx+1,j))*xx(ki2,j) else ! constant current b(ip1,ki2)=1.0d0 g(ip1)=cur-xx(ki2,j) endif if(imp.eq.1) g(ip1)=1.0d0 elseif(j.lt.n1+n2) then b(ip1,kp1)=1.0d0 ! separator, set phi1=0 g(ip1)=-c(kp1,j) if(imp.eq.1) g(ip1)=0.0d0 elseif(j.lt.nj) then ! cathode d(ip1,kp1)=1.0d0/h3 b(ip1,kp1)=-1.0d0/h3 b(ip1,ki2)=-1.0d0/sig3 g(ip1)=-cur/sig3+c(ki2,j)/sig3-(c(kp1,j+1)-c(kp1,j))/h3 if(imp.eq.1) g(ip1)=-1.0d0/sig3 else ! j=nj b(ip1,ki2)=1.0d0 g(ip1)=-c(ki2,j) ! i2 is no longer used at j=nj if(imp.eq.1) g(ip1)=0.d0 endif if(imp.eq.1) g(12)=0.0d0 c ________________________________________________ c Equation n+1. Carry end potentials. This equation is added to c permit handling constant load, etc. without an extra loop. if (imp.eq.0) then if(j.eq.1) then g(nx+1)=xx(kp1,1)-xx(nx+1,1) ! pick up negative potential b(nx+1,kp1)=-1.d0 b(nx+1,nx+1)=1.d0 elseif(j.eq.nj) then g(nx+1)=xx(kp1,nj)-xx(nx+1,nj) ! pick up positive potential b(nx+1,kp1)=-1.d0 b(nx+1,nx+1)=1.d0 elseif(j.le.n1+1) then g(nx+1)=xx(nx+1,j)-xx(nx+1,j-1) ! carry negative potential b(nx+1,nx+1)=-1.d0 a(nx+1,nx+1)=1.d0 else ! if(j.ge.n1+n2) then g(nx+1)=xx(nx+1,j)-xx(nx+1,j+1) ! carry positive potential b(nx+1,nx+1)=-1.d0 d(nx+1,nx+1)=1.d0 endif endif c ________________________________________________ c c Equation i2div. Current balance if(j.gt.n1+1 .and. j.lt.n1+n2) then ! separator g(i2div)=xx(ki2,j-1)-xx(ki2,j) if (imp.eq.0) a(i2div,ki2)=-1.d0 b(i2div,ki2)=1.d0 if (imp.eq.1) then ! impedance section c Set perturbation current = 1 purely real: b(i2div,ki2)=1.0d0 g(i2div)=1.0d0 endif ! end of impedance section (n1+10 if (li.eq.1) then kadd=0 do mpa=1,npa if (j.le.n1+1) then pwfindiv(mpa,j)=(ai2(1,mpa)*(xt(2+mpa,j,kk-1+kadd)-xx(2+mpa,j)) &/rr-sumpa(mpa,j))*Rad1pa(mpa) if (mvdc1.eq.1) pwfindiv(mpa,j)=xx(kj,j) pwfindiv_d(mpa,j)=-Rad1pa(mpa)*ai2(1,mpa)/rr utz(mpa,j)=utz(mpa,j)-pwfindiv(mpa,j)*rr*area1pa(mpa) &/(1.0d0-ep1-epp1-epf1-epg1)/ct1/vf1(mpa) elseif (j.ge.n1+n2) then pwfindiv(mpa,j)=(ai(1,mpa)*(xt(2+mpa,j,kk-1+kadd)-xx(2+mpa,j)) &/rr-sumpa(mpa,j))*Rad3pa(mpa) if (mvdc3.eq.1) pwfindiv(mpa,j)=xx(kj,j) pwfindiv_d(mpa,j)=-Rad3pa(mpa)*ai(1,mpa)/rr utz(mpa,j)=utz(mpa,j)-pwfindiv(mpa,j)*rr*area3pa(mpa)/ &(1.0d0-ep3-epp3-epf3-epg3)/ct3/vf3(mpa) else pwfindiv(mpa,j)=0.0d0 pwfindiv_d(mpa,j)=0.0d0 endif enddo ! mpa endif ! li endif ! time step check enddo ! j c Material and current balance tests: c Current balance - integrate the current balance equation sum=0.0d0 !mat balance on electrolyte sum1=0.0d0 !current neg elec, main sum1_s1=0.0d0 !side current neg elec, side reaction 1 sum3=0.0d0 !main current pos elec sum3_s1=0.0d0 !side current pos elec, side reaction 1 sum1_s2=0.0d0 !side current neg elec, side reaction 2 sum3_s2=0.0d0 !side current pos elec, side reaction 2 sum1_s3=0.0d0 !side current neg elec, side reaction 3 sum3_s3=0.0d0 !side current pos elec, side reaction 3 sum4=0.0d0 !mat balance oxygen sum5=0.0d0 !mat balance hydrogen if (n1 .gt. 2) then do 85 j=2,n1 sum1_s1=sum1_s1+area1*fc*h1*xx(kj1,j) sum1_s2=sum1_s2+area1*fc*h1*xx(kj2,j) sum1_s3=sum1_s3+area1*h1*xx(kj3,j) sum1=sum1+area1*fc*h1*xx(kj,j) !j main sum4=sum4+xx(kS1,j)*h1*epg1 !conc O2 sum5=sum5+xx(kS2,j)*h1*epg1 !conc H2 85 sum=sum+xx(1,j)*(ep1+epp1)*h1 !conc elec endif sum=sum+(xx(1,1)+xx(1,n1+1))*(ep1+epp1)*h1/2.0d0 sum1=sum1+area1*fc*h1*(xx(kj,1)+xx(kj,n1+1))/2.0d0 sum1_s1=sum1_s1+area1*fc*h1*(xx(kj1,1)+xx(kj1,n1+1)) & /2.0d0 sum1_s2=sum1_s2+area1*fc*h1*(xx(kj2,1)+xx(kj2,n1+1)) & /2.0d0 sum1_s3=sum1_s3+area1*h1*(xx(kj3,1)+xx(kj3,n1+1))/2.0d0 sum4=sum4+h1*(xx(kS1,1)+xx(kS1,n1+1))/2.0d0*epg1 sum5=sum5+h1*(xx(kS2,1)+xx(kS2,n1+1))/2.0d0*epg1 do 86 j=n1+2,n2+n1-1 sum4=sum4+h2*xx(kS1,j)*epg2 sum5=sum5+h2*xx(kS2,j)*epg2 86 sum=sum+xx(1,j)*(ep2+epp2)*h2 sum=sum+(xx(1,n1+1)+xx(1,n2+n1))*(ep2+epp2)*h2/2.0d0 sum4=sum4+h2*(xx(kS1,n1+1)+xx(kS1,n1+n2))/2.0d0*epg2 sum5=sum5+h2*(xx(kS2,n1+1)+xx(kS2,n1+n2))/2.0d0*epg2 do 87 j=n2+n1+1,nj-1 sum3=sum3+area3*fc*xx(kj,j)*h3 sum3_s1=sum3_s1+area3*fc*xx(kj1,j)*h3 sum3_s2=sum3_s2+area3*fc*xx(kj2,j)*h3 sum3_s3=sum3_s3+area3*fc*xx(kj3,j)*h3 sum4=sum4+h3*xx(kS1,j)*epg3 sum5=sum5+h3*xx(kS2,j)*epg3 87 sum=sum+xx(1,j)*(ep3+epp3)*h3 sum3=sum3+area3*fc*(xx(kj,n1+n2)+xx(kj,nj)) & *h3/2.0d0 sum3_s1=sum3_s1+area3*fc*(xx(kj1,n1+n2)+xx(kj1,nj)) & *h3/2.0d0 sum3_s2=sum3_s2+area3*fc*(xx(kj2,n1+n2)+xx(kj2,nj)) & *h3/2.0d0 sum3_s3=sum3_s3+area3*fc*(xx(kj3,n1+n2)+xx(kj3,nj)) & *h3/2.0d0 sum=sum+(xx(1,n1+n2)+xx(1,nj))*h3*(ep3+epp3)/2.0d0 sum4=sum4+h3*(xx(kS1,n1+n2)+xx(kS1,nj))/2.0d0*epg3 sum5=sum5+h3*(xx(kS2,n1+n2)+xx(kS2,nj))/2.0d0*epg3 sum4=sum4/thk !adjusts to average concentration sum5=sum5/thk c calculate total salt in cell from initial profile: w=xt(1,n1+2,1)*(dble(n2-1)*(ep2+epp2)*h2+dble(n1)*(ep1+epp1)*h1 1+dble(n3)*(ep3+epp3)*h3) if(lflag.eq.0) w=w-(xt(1,n1+2,1)-xt(1,1,1))*(dble(n1)* 1(ep1+epp1)*h1+dble(n3)*(ep3+epp3)*h3) if(lflag.eq.0) w=w-(xt(1,n1+2,1)-xt(1,1,1))*(ep2+epp2)*h2 c material-balance parameter should be ca=1.00 ca=sum/w c Calculate cell potential from dif of solid-phase potentials: v=xt(kp1,nj,kk)-xt(kp1,1,kk)-RG*cur !WHT 1-11-08 c Calculate the resistances in the cell, R=V/I mpa=1 ! only one size for resistance calculation xxsave=xx(2+mpa,n1+1) call ekin(n1+1,kk,0,0.0d0,mpa,mvdc1,mvdc3) xx(2+mpa,n1+1)=xxsave Ua_end=g0 xxsave=xx(2+mpa,n1+n2) call ekin(n1+n2,kk,0,0.0d0,mpa,mvdc1,mvdc3