0

I am a newbie for Fipy. I'm dying to know how to judge the value on the specified boundary and then assign a new value to the specified boundary conditions?"

I creat a CellVariable"psi", and a specified boudary "BSCfaces". I'd like to apply a new value to the "BSCfaces" acorrding to the "psi" faceValue. Now I used frist code, but mean(B1) is a temporary solution. So I test the second code, but It is not work well, especially when the mesh is a little large (i.e. 10*10 does not work).

# First code I used now
from fipy import CellVariable, Grid2D, Viewer, TransientTerm, DiffusionTerm
nx = 100
ny = 100
Lx=0.20
Ly=0.15
dx = Lx/nx 
dy = Ly/ny 
mesh = Grid2D(dx=dx, dy=dy, nx=nx, ny=ny)

# create a CellVariable and initialize it
psi = CellVariable(name="pressure head (m)",
                  mesh=mesh,
                  value=-0.513949,
                  hasOld=1)


BSC=[Lx / 4,3*Lx / 4]
BSCfaces= (mesh.facesTop & (X >= BSC[0]) & (X <= BSC[1]))
B1=psi.faceValue[BSCfaces.value].value 
psi_min=-1000
import numpy as np
if (np.mean(B1)<psi_min):
    psi.constrain(psi_min,BSCfaces)




# Second code I want to modify.
from fipy import CellVariable, Grid2D, Viewer, TransientTerm, DiffusionTerm
nx = 100
ny = 100
Lx=0.20
Ly=0.15
dx = Lx/nx 
dy = Ly/ny 
mesh = Grid2D(dx=dx, dy=dy, nx=nx, ny=ny)

# create a CellVariable and initialize it
psi = CellVariable(name="pressure head (m)",
                  mesh=mesh,
                  value=-0.513949,
                  hasOld=1)


BSC=[Lx / 4,3*Lx / 4]
BSCfaces= (mesh.facesTop & (X >= BSC[0]) & (X <= BSC[1]))
B=psi.faceValue.value
psi_min=-1000
import numpy as np
x1=mesh.faceCenters.value[0][np.where(B>psi_min)]
y1=mesh.faceCenters.value[1][np.where(B>psi_min)]
if (x1.size!=0):
    BSC1=BSCfaces & (x1,y1) #I think probably here is the problem!!!!
    psi.constrain(psi_min,BSC1)

The first code work, but it is a temporary solution. The second code work not well, and showed that "TypeError: ufunc 'bitwise_and' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''"

Liu
  • 3
  • 2
  • Can you please explain in math what you're trying to do with `BSC1=BSCfaces & (x1,y1)`? – jeguyer Oct 22 '19 at 13:20
  • this step is used to add/remove faces that fit the value – Liu Oct 23 '19 at 07:56
  • I apologize for taking so long to respond, but I really don't understand what you're trying to do. Since psi is initialized to -0.513949, all boundaries are >= psi_min, so I don't understand how the constraint intended to vary with time. Please use MATH to describe your boundary conditions as a function of time. Don't try to explain it with FiPy. Please write down your equations, boundary conditions, and initial conditions as a mathematical problem. – jeguyer Nov 22 '19 at 16:47

0 Answers0