Beispiel #1
0
data.vdco = (1.0/(data.dy**2))*KV0
pdata = ctypes.pointer(data)

SetInitialProfiles(u, data.dx, data.dy)
abstol= cvodes.realtype(1.0e-5*100)
reltol= cvodes.realtype(1.0e-5)

cvode_mem = cvodes.CVodeCreate(cvodes.CV_BDF, cvodes.CV_NEWTON)
cvodes.CVodeSetFdata(cvode_mem, ctypes.pointer(data))
cvodes.CVodeMalloc(cvode_mem, f, T0, u, cvodes.CV_SS, reltol, abstol)
cvodes.CVSpgmr(cvode_mem, cvodes.PREC_LEFT, 0)
cvodes.CVSpilsSetGSType(cvode_mem, cvodes.MODIFIED_GS)
cvodes.CVSpilsSetPreconditioner(cvode_mem, Precond, PSolve, pdata)

print " \n2-species diurnal advection-diffusion problem\n"
iout = 1
tout = TWOHR
while iout <= NOUT:
	cvodes.CVode(cvode_mem, tout, u, ctypes.byref(t), cvodes.CV_NORMAL)
	PrintOutput(cvode_mem, u, t)
	iout += 1
	tout += TWOHR

PrintFinalStats(cvode_mem)

for jx in range(MX):
	for jy in range(MY):
		cvodes.denfree(data.P[jx][jy])
		cvodes.denfree(data.Jbd[jx][jy])
		cvodes.denfreepiv(data.pivot[jx][jy])
Beispiel #2
0
cvodes.CVSpilsSetPreconditioner(cvode_mem, Precond, PSolve, ctypes.pointer(wdata))

print "\nAllocate global memory"
cvadj_mem = cvodes.CVadjMalloc(cvode_mem, NSTEPS, cvodes.CV_HERMITE)
wdata.cvadj_mem = cvadj_mem;

print "\nForward integration"
cvodes.CVodeF(cvadj_mem, TOUT, c, ctypes.byref(t), cvodes.CV_NORMAL, ctypes.byref(ncheck))

print "\n   g = int_x int_y c%d(Tfinal,x,y) dx dy = %f \n"%(ISPEC, c[NEQ])

cB = cvodes.NVector([0]*NEQ)
CbInit(cB, ISPEC, wdata)

print "\nCreate and allocate CVODES memory for backward run"
cvodes.CVodeCreateB(cvadj_mem, cvodes.CV_BDF, cvodes.CV_NEWTON)
cvodes.CVodeSetFdataB(cvadj_mem, ctypes.pointer(wdata))
cvodes.CVodeMallocB(cvadj_mem, fB, TOUT, cB, cvodes.CV_SS, RTOL, ATOL)

cvodes.CVSpgmrB(cvadj_mem, cvodes.PREC_LEFT, 0)
cvodes.CVSpilsSetPreconditionerB(cvadj_mem, PrecondB, PSolveB, ctypes.pointer(wdata))

print "\nBackward integration"
cvodes.CVodeB(cvadj_mem, T0, cB, ctypes.byref(t), cvodes.CV_NORMAL)

PrintOutput(cB, NS, MXNS, wdata)

for i in range(wdata.ngrp):
	cvodes.denfree(wdata.P[i])
	cvodes.denfreepiv(wdata.pivot[i])