Hon Fai Choi - 2013-08-04

Hello,
I am trying to modify the potentialFlux solver to incorporate a source term, but I have problems to get it to work properly. I am trying to define a problem in which a unit rectangular domain contains a small source in the middle and has an outflow at one side. After searching through the OpenFoam forums I have tried the following solution :

xpos = mesh.C().component(ref.vector.X)
ypos = mesh.C().component(ref.vector.Y)
source_term = ref.fvc.div(phi)
for ind in range(source_term.size()):
     if ((np.abs(ypos[ind]-0.5) <= 0.05) and (np.abs(xpos[ind]-0.5) <= 0.05)):
        source_term[ind] = 0.01
     else:   
        source_term[ind] = 0.0

I have added this code after the call to '_createFields(runTime, mesh, potentialFlow, args)'.
I then modify the equation as:

for nonOrth in range(nNonOrthCorr + 1):
   pEqn = ( ref.fvm.laplacian(unity_term, p) == source_term + ref.fvc.div(phi) )
   pEqn.setReference( pRefCell, pRefValue )
   pEqn.solve()

The solution converges, but if I plot the distribution of p, it seems that the source is not in the middle but shifted to one side. I also tried:

for nonOrth in range(nNonOrthCorr + 1):
   pEqn = ( ref.fvm.laplacian(unity_term, p) == source_term )
   pEqn.setReference( pRefCell, pRefValue )
   pEqn.solve()

but that gave me the same result. Does anyone know what I am doing wrong? Is what I am doing the proper way to add an explicit source term or should I do this differently?

thanks for any feedback,

Hon Fai