In [1]:
from dolfin import *
nn = 4
mesh = RectangleMesh(0, 0, 1, 1, nn, nn,'crossed')
order = 1
Magnetic = FunctionSpace(mesh, "N1curl", order)
Lagrange = FunctionSpace(mesh, "CG", order)
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.
In [49]:
v = Function(Lagrange)
import numpy as np
Lagrange.dim()
x = np.zeros((Lagrange.dim(),1))
x[0] = 1
x[:,0]
Out[49]:
array([ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0.])
In [50]:
v.vector()[:] = x[:,0].T
In [51]:
uu = grad(v)
In [62]:
uu.
Out[62]:
(Coefficient(FiniteElement('Lagrange', Domain(Cell('triangle', 2), 'triangle_multiverse', 2, 2), 1, None), 17),)
In [72]:
q = TestFunction(Lagrange)
N = FacetNormal(mesh)
t = as_vector((-N[0], N[1]))
v = Function(Lagrange)
uu = inner(grad(v),t)*dS
In [73]:
assemble(uu)
Form argument must be restricted.
ERROR:UFL:Form argument must be restricted.
---------------------------------------------------------------------------
UFLException Traceback (most recent call last)
<ipython-input-73-c683c9c880fa> in <module>()
----> 1 assemble(uu)
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/dolfin/fem/assembling.pyc in assemble(form, tensor, mesh, coefficients, function_spaces, cell_domains, exterior_facet_domains, interior_facet_domains, reset_sparsity, add_values, finalize_tensor, keep_diagonal, backend, form_compiler_parameters, bcs)
166 coefficients=coefficients,
167 form_compiler_parameters=form_compiler_parameters,
--> 168 common_cell=common_cell)
169
170 # Set mesh if specified (important for functionals without a function spaces)
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/dolfin/fem/form.pyc in __init__(self, form, function_spaces, coefficients, subdomains, form_compiler_parameters, common_cell)
54 self._compiled_form, module, self.form_data, prefix \
55 = jit(form, form_compiler_parameters,
---> 56 common_cell)
57
58 elif isinstance(form, ufc.form):
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/dolfin/compilemodules/jit.pyc in mpi_jit(*args, **kwargs)
58 # Just call JIT compiler when running in serial
59 if MPI.num_processes() == 1:
---> 60 return local_jit(*args, **kwargs)
61
62 # Compile first on process 0
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/dolfin/compilemodules/jit.pyc in jit(form, form_compiler_parameters, common_cell)
120 raise RuntimeError, "Form compiler must implement the jit function."
121
--> 122 return jit_compile(form, parameters=p, common_cell=common_cell)
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ffc/jitcompiler.pyc in jit(ufl_object, parameters, common_cell)
76 return jit_element(ufl_object, parameters)
77 else:
---> 78 return jit_form(ufl_object, parameters, common_cell)
79
80 def _auto_select_degree(elements):
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ffc/jitcompiler.pyc in jit_form(form, parameters, common_cell)
167 # Compute form metadata and extract preprocessed form
168 form_data = form.compute_form_data(common_cell=common_cell,
--> 169 element_mapping=element_mapping)
170
171 # Wrap input
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/form.pyc in compute_form_data(self, object_names, common_cell, element_mapping)
122 object_names=object_names,
123 common_cell=common_cell,
--> 124 element_mapping=element_mapping)
125 # Always validate arguments, keeping sure that the validation works
126 self._form_data.validate(object_names=object_names,
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/algorithms/preprocess.pyc in preprocess(form, object_names, common_cell, element_mapping)
116
117 # Propagate restrictions of interior facet integrals to the terminal nodes
--> 118 form = propagate_restrictions(form) # INTEGRAL, EXPR
119
120 # --- BEGIN DOMAIN SPLITTING AND JOINING
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/algorithms/propagate_restrictions.pyc in propagate_restrictions(expression)
109 def propagate_restrictions(expression):
110 "Propagate restriction nodes to wrap terminal objects directly."
--> 111 return apply_transformer(expression, RestrictionPropagator(), domain_type=Measure.INTERIOR_FACET)
112
113 def check_restrictions(expression, require_restriction):
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/algorithms/transformer.pyc in apply_transformer(e, transformer, domain_type)
275 def _transform(expr):
276 return transformer.visit(expr)
--> 277 return transform_integrands(e, _transform, domain_type)
278
279 def ufl2ufl(e):
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/algorithms/transformer.pyc in transform_integrands(form, transform, domain_type)
250 integrand = itg.integrand()
251 if domain_type is None or domain_type == itg.domain_type():
--> 252 integrand = transform(integrand)
253 if not isinstance(integrand, Zero):
254 newitg = itg.reconstruct(integrand)
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/algorithms/transformer.pyc in _transform(expr)
274 expression in form, or to form if it is an Expr."""
275 def _transform(expr):
--> 276 return transformer.visit(expr)
277 return transform_integrands(e, _transform, domain_type)
278
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/algorithms/transformer.pyc in visit(self, o)
99 if visit_children_first:
100 # Yes, visit all children first and then call h.
--> 101 r = h(o, *map(self.visit, o.operands()))
102 else:
103 # No, this is a handler that handles its own children
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/algorithms/transformer.pyc in visit(self, o)
99 if visit_children_first:
100 # Yes, visit all children first and then call h.
--> 101 r = h(o, *map(self.visit, o.operands()))
102 else:
103 # No, this is a handler that handles its own children
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/algorithms/transformer.pyc in visit(self, o)
99 if visit_children_first:
100 # Yes, visit all children first and then call h.
--> 101 r = h(o, *map(self.visit, o.operands()))
102 else:
103 # No, this is a handler that handles its own children
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/algorithms/transformer.pyc in visit(self, o)
99 if visit_children_first:
100 # Yes, visit all children first and then call h.
--> 101 r = h(o, *map(self.visit, o.operands()))
102 else:
103 # No, this is a handler that handles its own children
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/algorithms/transformer.pyc in visit(self, o)
103 # No, this is a handler that handles its own children
104 # (arguments self and o, where self is already bound)
--> 105 r = h(o)
106
107 # Update stack and return
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/algorithms/propagate_restrictions.pyc in form_argument(self, o)
67
68 def form_argument(self, o):
---> 69 ufl_assert(self.current_restriction is not None, "Form argument must be restricted.")
70 #if self.current_restriction is None:
71 # return o
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/assertions.pyc in ufl_assert(condition, *message)
35 def ufl_assert(condition, *message):
36 "Assert that condition is true and otherwise issue an error with given message."
---> 37 if not condition: error(*message)
38
/home/mwathen/Work/FEniCS/lib/python2.7/site-packages/ufl/log.pyc in error(self, *message)
152 "Write error message and raise an exception."
153 self._log.error(*message)
--> 154 raise self._exception_type(self._format_raw(*message))
155
156 def begin(self, *message):
UFLException: Form argument must be restricted.
In [76]:
dofs=Magnetic.dofmap()
In [85]:
dofs.tabulate_coordinates?
In [92]:
from dolfin import *
import numpy as np
nn = 4
mesh = RectangleMesh(0, 0, 1, 1, nn, nn,'crossed')
order = 1
Magnetic = FunctionSpace(mesh, "N1curl", order)
Lagrange = FunctionSpace(mesh, "CG", order)
L= FunctionSpace(mesh, "DG", order-1)
u = Function(Lagrange)
uu = grad(u)
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.
DEBUG:UFL:No integrals left after transformation, returning empty form.
DEBUG:FFC:Reusing form from cache.
In [103]:
np.one((Lagrange.dim(),1))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-103-ebfa083e8838> in <module>()
----> 1 np.one((Lagrange.dim(),1))
AttributeError: 'module' object has no attribute 'one'
In [ ]:
u.vector().array() = np.one
In [99]:
u.vector().array()
Out[99]:
array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0.])
In [89]:
Magnetic.dim()
Out[89]:
104
Content source: wathen/PhD
Similar notebooks: