In [2]:
from dolfin import *
import numpy as np
import scipy.sparse as sp
import numpy
nn = 8
mesh = RectangleMesh(0, 0, 1, 1, nn, nn,'left')
order = 1
Magnetic = FunctionSpace(mesh, "N2curl", order)
Lagrange = FunctionSpace(mesh, "CG", order)
C = sp.csr_matrix((Magnetic.dim(),Lagrange.dim()))
parameters['linear_algebra_backend'] = 'Epetra'
u = Function(Lagrange)
for i in range(0, Lagrange.dim() ):
zero = np.zeros((Lagrange.dim(),1))[:,0]
zero[i] = 1
u.vector()[:] = zero
uu = grad(u)
Pv = project(uu,Magnetic,solver_type = "lu")
P = Pv.vector().array()
index = P.nonzero()
index = index[0]
for x in range(0,len(index)):
if np.abs(P[index[x]]) < 1e-3:
P[index[x]] = 0
print P.shape, C.shape
pn = P.nonzero()[0]
for j in range(0,len(pn)):
C[pn[j],i] = P[pn[j]]
del P
DEBUG:UFL:No integrals left after transformation, returning empty form.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Level 25:FFC:Calling FFC just-in-time (JIT) compiler, this may take some time.
INFO:FFC:Compiling form ffc_form_fe1303c2cadf573d8cccaba26c1138a29a2d5461
INFO:FFC:Compiler stage 1: Analyzing form(s)
INFO:FFC:-----------------------------------
INFO:FFC:
INFO:FFC: Name: ''
Cell: <triangle cell in 2D>
Topological dimension: 2
Geometric dimension: 2
Rank: 1
Number of coefficients: 0
Arguments: '[v_{-2}]'
Coefficients: '[]'
Argument names: '[v0]'
Coefficient names: '[]'
Unique elements: 'N2curl1(?)'
Unique sub elements: 'N2curl1(?)'
Domains: (Domain(Cell('triangle', 2), 'triangle_multiverse', 2, 2),
)
Top level domains: (Domain(Cell('triangle', 2), 'triangle_multiverse', 2, 2),
)
INFO:FFC: Extracting monomial form representation from UFL form
INFO:FFC: Transforming monomial form to reference element
DEBUG:FFC: Reusing element from cache
DEBUG:FFC: Estimated cost of tensor representation: 1
INFO:FFC: representation: auto --> tensor
DEBUG:FFC: Selecting quadrature degree based on total polynomial degree of integrand: 1
INFO:FFC: quadrature_degree: auto --> 1
INFO:FFC: quadrature_rule: auto --> default
INFO:FFC:
INFO:FFC:Compiler stage 1 finished in 0.0587881 seconds.
INFO:FFC:Compiler stage 2: Computing intermediate representation
INFO:FFC:-------------------------------------------------------
INFO:FFC: Computing representation of 1 elements
DEBUG:FFC: Reusing element from cache
DEBUG:FFC: Reusing element from cache
INFO:FFC: Computing representation of 1 dofmaps
DEBUG:FFC: Reusing element from cache
INFO:FFC: Computing representation of integrals
INFO:FFC: Computing tensor representation
INFO:FFC: Extracting monomial form representation from UFL form
INFO:FFC: Transforming monomial form to reference element
DEBUG:FFC: Reusing element from cache
DEBUG:FFC: Reusing element from cache
DEBUG:FFC: Reusing element from cache
INFO:FFC: Precomputing integrals on reference element
DEBUG:FFC: Reusing element from cache
DEBUG:FFC: 12 entries computed in 0.0029 seconds
DEBUG:FFC: Shape of reference tensor: (6, 2)
DEBUG:FFC: Primary multi index: rank = 1 dims = [6] indices = [[0], [1], [2], [3], [4], [5]]
DEBUG:FFC: Secondary multi index: rank = 1 dims = [2] indices = [[0], [1]]
DEBUG:FFC: Internal multi index: rank = 0 dims = [] indices = [[]]
DEBUG:FFC: Secondary multi index: rank = 1 dims = [2] indices = [[0], [1]]
DEBUG:FFC: External multi index: rank = 0 dims = [] indices = [[]]
INFO:FFC: Computing representation of forms
INFO:FFC:
INFO:FFC:Compiler stage 2 finished in 0.05004 seconds.
INFO:FFC:Compiler stage 3: Optimizing intermediate representation
INFO:FFC:--------------------------------------------------------
INFO:FFC: Skipping optimizations, add -O to optimize
INFO:FFC:
INFO:FFC:Compiler stage 3 finished in 0.00168109 seconds.
INFO:FFC:Compiler stage 4: Generating code
INFO:FFC:---------------------------------
INFO:FFC: Generating code for 1 element(s)
DEBUG:FFC: Removing unused variable: tmp2
DEBUG:FFC: Removing unused variable: tmp1
DEBUG:FFC: Removing unused variable: tmp7
DEBUG:FFC: Removing unused variable: tmp6
DEBUG:FFC: Removing unused variable: tmp5
DEBUG:FFC: Removing unused variable: tt
DEBUG:FFC: Removing unused variable: ss
DEBUG:FFC: Removing unused variable: rr
DEBUG:FFC: Removing unused variable: tmp2
DEBUG:FFC: Removing unused variable: tmp1
DEBUG:FFC: Removing unused variable: tmp7
DEBUG:FFC: Removing unused variable: tmp6
DEBUG:FFC: Removing unused variable: tmp5
DEBUG:FFC: Removing unused variable: tt
DEBUG:FFC: Removing unused variable: ss
DEBUG:FFC: Removing unused variable: rr
DEBUG:FFC: Removing unused variable: tmp2
DEBUG:FFC: Removing unused variable: tmp1
DEBUG:FFC: Removing unused variable: tmp7
DEBUG:FFC: Removing unused variable: tmp6
DEBUG:FFC: Removing unused variable: tmp5
DEBUG:FFC: Removing unused variable: tt
DEBUG:FFC: Removing unused variable: ss
DEBUG:FFC: Removing unused variable: rr
DEBUG:FFC: Removing unused variable: tmp2
DEBUG:FFC: Removing unused variable: tmp1
DEBUG:FFC: Removing unused variable: tmp7
DEBUG:FFC: Removing unused variable: tmp6
DEBUG:FFC: Removing unused variable: tmp5
DEBUG:FFC: Removing unused variable: tt
DEBUG:FFC: Removing unused variable: ss
DEBUG:FFC: Removing unused variable: rr
DEBUG:FFC: Removing unused variable: tmp2
DEBUG:FFC: Removing unused variable: tmp1
DEBUG:FFC: Removing unused variable: tmp7
DEBUG:FFC: Removing unused variable: tmp6
DEBUG:FFC: Removing unused variable: tmp5
DEBUG:FFC: Removing unused variable: tt
DEBUG:FFC: Removing unused variable: ss
DEBUG:FFC: Removing unused variable: rr
DEBUG:FFC: Removing unused variable: tmp2
DEBUG:FFC: Removing unused variable: tmp1
DEBUG:FFC: Removing unused variable: tmp7
DEBUG:FFC: Removing unused variable: tmp6
DEBUG:FFC: Removing unused variable: tmp5
DEBUG:FFC: Removing unused variable: tt
DEBUG:FFC: Removing unused variable: ss
DEBUG:FFC: Removing unused variable: rr
DEBUG:FFC: Removing unused variable: tmp2
DEBUG:FFC: Removing unused variable: tmp1
DEBUG:FFC: Removing unused variable: tmp7
DEBUG:FFC: Removing unused variable: tmp6
DEBUG:FFC: Removing unused variable: tmp5
DEBUG:FFC: Removing unused variable: tt
DEBUG:FFC: Removing unused variable: ss
DEBUG:FFC: Removing unused variable: rr
DEBUG:FFC: Removing unused variable: tmp2
DEBUG:FFC: Removing unused variable: tmp1
DEBUG:FFC: Removing unused variable: tmp7
DEBUG:FFC: Removing unused variable: tmp6
DEBUG:FFC: Removing unused variable: tmp5
DEBUG:FFC: Removing unused variable: tt
DEBUG:FFC: Removing unused variable: ss
DEBUG:FFC: Removing unused variable: rr
DEBUG:FFC: Removing unused variable: tmp2
DEBUG:FFC: Removing unused variable: tmp1
DEBUG:FFC: Removing unused variable: tmp7
DEBUG:FFC: Removing unused variable: tmp6
DEBUG:FFC: Removing unused variable: tmp5
DEBUG:FFC: Removing unused variable: tt
DEBUG:FFC: Removing unused variable: ss
DEBUG:FFC: Removing unused variable: rr
DEBUG:FFC: Removing unused variable: tmp2
DEBUG:FFC: Removing unused variable: tmp1
DEBUG:FFC: Removing unused variable: tmp7
DEBUG:FFC: Removing unused variable: tmp6
DEBUG:FFC: Removing unused variable: tmp5
DEBUG:FFC: Removing unused variable: tt
DEBUG:FFC: Removing unused variable: ss
DEBUG:FFC: Removing unused variable: rr
DEBUG:FFC: Removing unused variable: tmp2
DEBUG:FFC: Removing unused variable: tmp1
DEBUG:FFC: Removing unused variable: tmp7
DEBUG:FFC: Removing unused variable: tmp6
DEBUG:FFC: Removing unused variable: tmp5
DEBUG:FFC: Removing unused variable: tt
DEBUG:FFC: Removing unused variable: ss
DEBUG:FFC: Removing unused variable: rr
DEBUG:FFC: Removing unused variable: tmp2
DEBUG:FFC: Removing unused variable: tmp1
DEBUG:FFC: Removing unused variable: tmp7
DEBUG:FFC: Removing unused variable: tmp6
DEBUG:FFC: Removing unused variable: tmp5
DEBUG:FFC: Removing unused variable: tt
DEBUG:FFC: Removing unused variable: ss
DEBUG:FFC: Removing unused variable: rr
INFO:FFC: Generating code for 1 dofmap(s)
INFO:FFC: Generating code for integrals
INFO:FFC: Generating code for forms
INFO:FFC:
INFO:FFC:Compiler stage 4 finished in 0.241565 seconds.
INFO:FFC:Compiler stage 4.1 finished in 1.00136e-05 seconds.
INFO:FFC:Compiler stage 5: Formatting code
INFO:FFC:---------------------------------
INFO:FFC: Output written to ./ffc_form_fe1303c2cadf573d8cccaba26c1138a29a2d5461.h.
INFO:FFC:
INFO:FFC:Compiler stage 5 finished in 0.0167611 seconds.
INFO:FFC:FFC finished in 0.377531 seconds.
DEBUG:FFC:Compiling and linking Python extension module, this may take some time.
DEBUG:UFL:No integrals left after transformation, returning empty form.
DEBUG:FFC:Reusing form from cache.
DEBUG:UFL:No integrals left after transformation, returning empty form.
DEBUG:FFC:Reusing form from cache.
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-2-66ca248a9b6e> in <module>()
13 C = sp.csr_matrix((Magnetic.dim(),Lagrange.dim()))
14
---> 15 parameters['linear_algebra_backend'] = 'Epetra'
16
17 u = Function(Lagrange)
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dolfin/cpp/common.py in __setitem__(self, key, value)
2036 par._assign_bool(value)
2037 else:
-> 2038 par._assign(value)
2039
2040 def update(self, other):
RuntimeError:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** fenics@fenicsproject.org
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to assign parameter value.
*** Reason: Illegal value for parameter "linear_algebra_backend". Allowed values are: [PETSc, STL, uBLAS].
*** Where: This error was encountered inside Parameter.cpp.
*** Process: 0
***
*** DOLFIN version: 1.3.0
*** Git changeset:
*** -------------------------------------------------------------------------
In [4]:
import matplotlib.pylab as plt
plt.spy(C)
plt.show()
In [ ]:
Content source: wathen/PhD
Similar notebooks: