LutzGross / esys-escript.github.io

Other
30 stars 13 forks source link

NonlinearPDE Class: Sympy not installed, AttributeError and TypeError #3

Closed n1ck94 closed 3 years ago

n1ck94 commented 4 years ago

Not sure if it is meant to or not but Sympy isn't being installed when installing escript via conda install -c conda-forge esys-escript. So upon attempting to solve a PDE with the NonlinearPDE class the following RuntimeError is raised:

RuntimeError: Trying to instantiate a Symbol but sympy not available

this is easily fixed by installing Sympy however.

Running the following code

from esys.escript import * from esys.finley import Rectangle from esys.weipa import saveSilo dom = Rectangle(l0=1.,l1=1.,n0=100, n1=100) y=dom.getX()[1] u = Symbol('u',(), dim=2) X = Symbol('X',(2,), dim=2)#setting the shape to (2,) makes X a vector phi = 1 + y*2 h=1 + y X[0]=0 X[1]=grad(u)[1]phi Y = yu # this is the Non linear functionf from the pde Y1 = hgrad(u)[1]-Y #this is the onle that we put into the non linear pde class print(Y1) p = NonlinearPDE(dom, u, debug=NonlinearPDE.DEBUG0) gammaD=whereZero(y) p.setValue(X=X,q=gammaD,Y=Y1,r=1) v = p.getSolution(u=0)

which was extracted from LaunchPad question 256021 (nonlinear pde with nonconstant coefficients) raises the following AttributeError:

AttributeError: 'list' object has no attribute 'is_Float'

Running the 'plain_strain.py' example script from the escript user guide raises the following IndexError

IndexError: too many indices for array: array is 0-dimensional, but 2 were indexed

Not sure of a fix/work around for the AttributeError and IndexError so any assistance is appreciated.

esys-escript commented 4 years ago

@n1ck94 which version of sympy is installed in your conda environment?

n1ck94 commented 4 years ago

Sympy version 1.6.2

esys-escript commented 4 years ago

@n1ck94 unforunately, escript only supports sympy version 1.1 and lower. Could you please try installing sympy version 1.1 in your conda environment and see if this resolves your error?

n1ck94 commented 4 years ago

Ok thanks. The conda specifications indicate that escript requires python versions 2.7 or 3.8 but sympy version 1.1 is only compatible with python version <3.8. Leaving only python version 2.7. Is this correct? I'm currently trying to install escript via conda in a python 2.7 environment but it's getting stuck on "Solving Environment". Is it only for later python versions that escript can be installed via conda?

n1ck94 commented 4 years ago

With python version 2.7.18, sympy version 1.1.1 and escript version 5.4 I'm still getting the IndexError as I mentioned above when I run the plain_strain.py example script (copied below):

from esys.escript import *
from esys.finley import Rectangle
mydomain = Rectangle(l0=1.,l1=1.,n0=10, n1=10)
u = Symbol('u',(2,), dim=2)
q = Symbol('q', (2,2))
sigma = Symbol('sigma',(2,2))
theta = Symbol('theta')
q[0,0]=cos(theta)
q[0,1]=-sin(theta)
q[1,0]=sin(theta)
q[1,1]=cos(theta)
x = Function(mydomain).getX()
q=q.subs(theta,(3.14/4)*whereNonNegative(x[1]-.30)*whereNegative(x[1]-.70))
epsilon0 = symmetric(grad(u))
epsilon = matrixmult(matrixmult(q,epsilon0),q.transpose(1))
c00 = 10
c01 = 8; c11 = 10
c05 = 0; c15 = 0; c55 = 1
sigma[0,0] = c00*epsilon[0,0]+c01*epsilon[1,1]+c05*2*epsilon[1,0]
sigma[1,1] = c01*epsilon[0,0]+c11*epsilon[1,1]+c15*2*epsilon[1,0]
sigma[0,1] = c05*epsilon[0,0]+c15*epsilon[1,1]+c55*2*epsilon[1,0]
sigma[1,0] = sigma[0,1]
sigma0=matrixmult(matrixmult(q.transpose(1),sigma),q)
x=mydomain.getX()
gammaD=whereZero(x[1])*[1,1]
yconstraint = FunctionOnBoundary(mydomain).getX()[1]
p = NonlinearPDE(mydomain, u, debug=NonlinearPDE.DEBUG0)
p.setValue(X=sigma0,q=gammaD,y=[-50,0]*whereZero(yconstraint-1),r=[1,1])
v = p.getSolution(u=[0,0])

The error output is as follows:

Traceback (most recent call last):
  File "esNLTest.py", line 19, in <module>
    q=q.subs(theta,(3.14/4)*whereNonNegative(x[1]-.30)*whereNegative(x[1]-.70))
  File "escriptcore/py_src/symbolic/symbol.py", line 412, in subs
IndexError: too many indices for array

Are the package version I have installed correct? Thanks.