I wrote a code to solve the 1D diffusion equation using the Crank Nicholson method. However, when I try to output my solution values they continually overwrite the previous ones, so I only get values at the last time step. How can I fix this problem (my code is below)? Thanks
I ammended that part of the code to look like:
//time loop
for (int t=0; t<iNT; t++)
{DX2(dVRHS,dVSol,dLBC,dRBC,dCNGamma);
tridag(dVSub,dVDiag,dVSupd,dVRHS,dVSol);}
char case1out[]="1ddiffoutput.csv";
ofstream outfile(case1out,ios::app);
for (int i=0; i<iNP; i++)
for (int j=0; j<iNT; j++)
outfile<<double(i+1)*dDX<<","<<double(j+1)*dDT<<","<<dVSol[i,j]<<'\n';
outfile.close();
I got an error moving only ofstream outfile(case1out,ios::app); out of the for loop, so I had to move char case1out[]="1ddiffoutput.csv"; out as well. I still have the same problem with the output file in that only the values from the last time step print.