Exemplo n.º 1
0
def Precond(tn, y, fy, jok, jcurPtr, gamma, P_data, vtemp1, vtemp2, vtemp3):
	data = ctypes.cast(P_data, PUserData).contents
	
	if jok:
		for jz in range(MZ):
			for jx in range(MZ):
				cvodes.dencopy(data.Jbd[jx][jz], data.P[jx][jz], NUM_SPECIES, NUM_SPECIES)
		jcurPtr.contents.value = 0
	else:
		q4coef = data.q4
		delz = data.dz
		verdco = data.vdco
		hordco = data.hdco
		
		for jz in range(MZ):
			zdn = ZMIN + (jz - 0.5)*delz
			zup = zdn + delz
			czdn = verdco*math.exp(0.2*zdn)
			czup = verdco*math.exp(0.2*zup)
			diag = -(czdn + czup + 2.0*hordco)
			for jx in range(MX):
				c1 = y[1-1 + (jx)*NUM_SPECIES + (jz)*NSMX]
				c2 = y[2-1 + (jx)*NUM_SPECIES + (jz)*NSMX]
				j = data.Jbd[jx][jz]
				a = data.P[jx][jz]
				j[0][0] = (-data.p[0]*data.p[2] - data.p[1]*c2) + diag
				j[1][0] = -data.p[1]*c1 + q4coef
				j[0][1] = data.p[0]*data.p[2] - data.p[1]*c2
				j[1][1] = (-data.p[1]*c1 - q4coef) + diag
				cvodes.dencopy(j, a, NUM_SPECIES, NUM_SPECIES)
		jcurPtr.contents.value = 1
	
	for jz in range(MZ):
		for jx in range(MX):
			cvodes.denscale(-gamma, data.P[jx][jz], NUM_SPECIES, NUM_SPECIES)
	
	for jx in range(MX):
		for jz in range(MZ):
			cvodes.denaddI(data.P[jx][jz], NUM_SPECIES)
			ier = cvodes.denGETRF(data.P[jx][jz], NUM_SPECIES, NUM_SPECIES, data.pivot[jx][jz])
			if ier != 0:
				return 1
	
	return 0
Exemplo n.º 2
0
def Precond(tn, u, fu, jok, jcurPtr, gamma, P_data, vtemp1, vtemp2, vtemp3):
	data = ctypes.cast(P_data, PUserData).contents
	
	if jok:
		for jy in range(MY):
			for jx in range(MX):
				cvodes.dencopy(data.Jbd[jx][jy], data.P[jx][jy], NUM_SPECIES, NUM_SPECIES)
		jcurPtr.contents.value = 0
	else:
		q4coef = data.q4
		dely = data.dy
		verdco = data.vdco
		hordco = data.hdco
		
		for jy in range(MY):
			ydn = YMIN + (jy - 0.5)*dely
			yup = ydn + dely
			cydn = verdco*math.exp(0.2*ydn)
			cyup = verdco*math.exp(0.2*yup)
			diag = -(cydn + cyup + 2.0*hordco)
			for jx in range(MX):
				c1 = u[1-1 + (jx)*NUM_SPECIES + (jy)*NSMX]
				c2 = u[2-1 + (jx)*NUM_SPECIES + (jy)*NSMX]
				j = data.Jbd[jx][jy]
				a = data.P[jx][jy]
				j[0][0] = (-Q1*C3 - Q2*c2) + diag
				j[1][0] = -Q2*c1 + q4coef
				j[0][1] = Q1*C3 - Q2*c2
				j[1][1] = (-Q2*c1 - q4coef) + diag
				cvodes.dencopy(j, a, NUM_SPECIES, NUM_SPECIES)
		jcurPtr.contents.value = 1
	
	for jy in range(MY):
		for jx in range(MX):
			cvodes.denscale(-gamma, data.P[jx][jy], NUM_SPECIES, NUM_SPECIES)
	
	for jx in range(MX):
		for jy in range(MY):
			cvodes.denaddI(data.P[jx][jy], NUM_SPECIES)
			ier = cvodes.denGETRF(data.P[jx][jy], NUM_SPECIES, NUM_SPECIES, data.pivot[jx][jy])
			if ier != 0:
				return 1
	
	return 0
Exemplo n.º 3
0
def PrecondB(t, c, cB, fcB, jok, jcurPtr, gamma, P_data, vtemp1, vtemp2, vtemp3):
	wdata = ctypes.cast(P_data, PWebData).contents
	cvode_mem = cvodes.CVadjGetCVodeBmem(wdata.cvadj_mem)
	rewt = nvecserial.NVector(wdata.rewt)
	cvodes.CVodeGetErrWeights(cvode_mem, rewt)
	
	uround = nvecserial.UNIT_ROUNDOFF
	
	fac = fcB.wrmsnorm(rewt)
	r0 = 1000.0*abs(gamma)*uround*NEQ*fac
	if r0 == 0.0:
		r0 = 1.0
	
	for igy in range(wdata.ngy):
		jy = wdata.jyr[igy]
		if00 = jy*wdata.mxmp
		for igx in range(wdata.ngx):
			jx = wdata.jxr[igx]
			if0 = if00 + jx*wdata.mp
			ig = igx + igy*wdata.ngx
			for j in range(wdata.mp):
				jj = if0 + j
				save = c[jj]
				r = max([wdata.srur*abs(save),r0/rewt[jj]])
				c[jj] += r
				fac = -gamma/r
				fblock (t, c, jx, jy, vtemp1, wdata)
				for i in range(wdata.mp):
					wdata.P[ig][j][i] = (vtemp1[i] - wdata.fsave[if0+i])*fac
				c[jj] = save
	
	for ig in range(wdata.ngrp):
		cvodes.denaddI(wdata.P[ig], wdata.mp)
		ier = cvodes.denGETRF(wdata.P[ig], wdata.mp, wdata.mp, wdata.pivot[ig])
		if ier != 0:
			return 1
	
	jcurPtr.contents.value = 1
	return 0