Hello,
I am getting error in assemble_scalar. I am using DOLFINx version: 0.8.0. Please find the MWE.
from dolfinx.fem.petsc import LinearProblem, assemble_matrix
from mpi4py import MPI
import numpy as np
import dolfinx
import basix
from dolfinx.fem import form, petsc, Function, functionspace, locate_dofs_topological, apply_lifting, set_bc
from ufl import as_vector, dot, Cell, as_tensor, SpatialCoordinate, dx
from dolfinx import fem
import petsc4py.PETSc
from dolfinx.io import gmshio
from mpi4py import MPI
import ufl
gdim = 1
shape = "interval"
deg = 1
cell = Cell(shape)
elem= basix.ufl.element("Lagrange", "interval", deg, shape=(1, ))
domain = ufl.Mesh(elem)
x = np.array([-4,-3,-2]) # Reference 0
cells = np.array([[0,1],[1,2]])
dom = dolfinx.mesh.create_mesh(MPI.COMM_WORLD, cells, x, domain)
dx = Measure('dx')(domain=dom)
########################################################
x = SpatialCoordinate(dom)
Eps2=as_tensor([(1,0,0,0,0,0),
(0,1,0,0,1,0),
(0,0,0,0,0,0),
(0,0,1,0,0,0),
(0,0,0,x[0],0,0),
(0,0,1,0,0,x[0])])
E1,E2,E3=3.4400E+03, 3.4400E+03, 3.4400E+03
G12,G13,G23= 1.3230E+03, 1.3230E+03, 1.3230E+03
v12,v13,v23 = 0.3,0.3,0.3
S=np.zeros((6,6))
S[0,0], S[1,1], S[2,2]=1/E1, 1/E2, 1/E3
S[0,1], S[0,2]= -v12/E1, -v13/E1
S[1,0], S[1,2]= -v12/E1, -v23/E2
S[2,0], S[2,1]= -v13/E1, -v23/E2
S[3,3], S[4,4], S[5,5]= 1/G23, 1/G13, 1/G12
C=as_tensor(np.linalg.inv(S))
DD=np.zeros((6,6))
for s in range(6):
for k in range(6):
f=fem.form(sum([dot(Eps2.T,dot(C,Eps2))[s,k]*dx]))
DD[s,k]=fem.assemble_scalar(f)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[5], line 49
47 for s in range(6):
48 for k in range(6):
---> 49 f=fem.form(sum([dot(Eps2.T,dot(C,Eps2))[s,k]*dx]))
50 DD[s,k]=fem.assemble_scalar(f)
File /usr/lib/petsc/lib/python3/dist-packages/dolfinx/fem/forms.py:249, in form(form, dtype, form_compiler_options, jit_options, entity_maps)
246 return list(map(lambda sub_form: _create_form(sub_form), form))
247 return form
--> 249 return _create_form(form)
File /usr/lib/petsc/lib/python3/dist-packages/dolfinx/fem/forms.py:244, in form.<locals>._create_form(form)
241 """Recursively convert ufl.Forms to dolfinx.fem.Form, otherwise
242 return form argument"""
243 if isinstance(form, ufl.Form):
--> 244 return _form(form)
245 elif isinstance(form, collections.abc.Iterable):
246 return list(map(lambda sub_form: _create_form(sub_form), form))
File /usr/lib/petsc/lib/python3/dist-packages/dolfinx/fem/forms.py:186, in form.<locals>._form(form)
184 if mesh is None:
185 raise RuntimeError("Expecting to find a Mesh in the form.")
--> 186 ufcx_form, module, code = jit.ffcx_jit(
187 mesh.comm, form, form_compiler_options=form_compiler_options, jit_options=jit_options
188 )
190 # For each argument in form extract its function space
191 V = [arg.ufl_function_space()._cpp_object for arg in form.arguments()]
File /usr/lib/petsc/lib/python3/dist-packages/dolfinx/jit.py:51, in mpi_jit_decorator.<locals>.mpi_jit(comm, *args, **kwargs)
47 @functools.wraps(local_jit)
48 def mpi_jit(comm, *args, **kwargs):
49 # Just call JIT compiler when running in serial
50 if comm.size == 1:
---> 51 return local_jit(*args, **kwargs)
53 # Default status (0 == ok, 1 == fail)
54 status = 0
File /usr/lib/petsc/lib/python3/dist-packages/dolfinx/jit.py:201, in ffcx_jit(ufl_object, form_compiler_options, jit_options)
199 # Switch on type and compile, returning cffi object
200 if isinstance(ufl_object, ufl.Form):
--> 201 r = ffcx.codegeneration.jit.compile_forms([ufl_object], options=p_ffcx, **p_jit)
202 elif isinstance(ufl_object, ufl.AbstractFiniteElement):
203 r = ffcx.codegeneration.jit.compile_elements([ufl_object], options=p_ffcx, **p_jit)
File /usr/lib/python3/dist-packages/ffcx/codegeneration/jit.py:276, in compile_forms(forms, options, cache_dir, timeout, cffi_extra_compile_args, cffi_verbose, cffi_debug, cffi_libraries, visualise)
274 except Exception:
275 pass
--> 276 raise e
278 obj, module = _load_objects(cache_dir, module_name, form_names)
279 return obj, module, (decl, impl)
File /usr/lib/python3/dist-packages/ffcx/codegeneration/jit.py:256, in compile_forms(forms, options, cache_dir, timeout, cffi_extra_compile_args, cffi_verbose, cffi_debug, cffi_libraries, visualise)
253 for name in form_names:
254 decl += form_template.format(name=name)
--> 256 impl = _compile_objects(
257 decl,
258 forms,
259 form_names,
260 module_name,
261 p,
262 cache_dir,
263 cffi_extra_compile_args,
264 cffi_verbose,
265 cffi_debug,
266 cffi_libraries,
267 visualise=visualise,
268 )
269 except Exception as e:
270 try:
271 # remove c file so that it will not timeout next time
File /usr/lib/python3/dist-packages/ffcx/codegeneration/jit.py:383, in _compile_objects(decl, ufl_objects, object_names, module_name, options, cache_dir, cffi_extra_compile_args, cffi_verbose, cffi_debug, cffi_libraries, visualise)
379 libraries = _libraries + cffi_libraries if cffi_libraries is not None else _libraries
381 # JIT uses module_name as prefix, which is needed to make names of all struct/function
382 # unique across modules
--> 383 _, code_body = ffcx.compiler.compile_ufl_objects(
384 ufl_objects, prefix=module_name, options=options, visualise=visualise
385 )
387 ffibuilder = cffi.FFI()
389 ffibuilder.set_source(
390 module_name,
391 code_body,
(...)
394 libraries=libraries,
395 )
File /usr/lib/python3/dist-packages/ffcx/compiler.py:118, in compile_ufl_objects(ufl_objects, options, object_names, prefix, visualise)
116 # Stage 3: code generation
117 cpu_time = time()
--> 118 code = generate_code(ir, options)
119 _print_timing(3, time() - cpu_time)
121 # Stage 4: format code
File /usr/lib/python3/dist-packages/ffcx/codegeneration/codegeneration.py:58, in generate_code(ir, options)
54 code_finite_elements = [
55 finite_element_generator(element_ir, options) for element_ir in ir.elements
56 ]
57 code_dofmaps = [dofmap_generator(dofmap_ir, options) for dofmap_ir in ir.dofmaps]
---> 58 code_integrals = [integral_generator(integral_ir, options) for integral_ir in ir.integrals]
59 code_forms = [form_generator(form_ir, options) for form_ir in ir.forms]
60 code_expressions = [
61 expression_generator(expression_ir, options) for expression_ir in ir.expressions
62 ]
File /usr/lib/python3/dist-packages/ffcx/codegeneration/codegeneration.py:58, in <listcomp>(.0)
54 code_finite_elements = [
55 finite_element_generator(element_ir, options) for element_ir in ir.elements
56 ]
57 code_dofmaps = [dofmap_generator(dofmap_ir, options) for dofmap_ir in ir.dofmaps]
---> 58 code_integrals = [integral_generator(integral_ir, options) for integral_ir in ir.integrals]
59 code_forms = [form_generator(form_ir, options) for form_ir in ir.forms]
60 code_expressions = [
61 expression_generator(expression_ir, options) for expression_ir in ir.expressions
62 ]
File /usr/lib/python3/dist-packages/ffcx/codegeneration/C/integrals.py:41, in generator(ir, options)
38 ig = IntegralGenerator(ir, backend)
40 # Generate code ast for the tabulate_tensor body
---> 41 parts = ig.generate()
43 # Format code as string
44 CF = CFormatter(options["scalar_type"])
File /usr/lib/python3/dist-packages/ffcx/codegeneration/integral_generator.py:166, in IntegralGenerator.generate(self)
162 all_preparts += self.generate_piecewise_partition(rule)
164 # Generate code to integrate reusable blocks of final
165 # element tensor
--> 166 all_quadparts += self.generate_quadrature_loop(rule)
168 # Collect parts before, during, and after quadrature loops
169 parts += all_preparts
File /usr/lib/python3/dist-packages/ffcx/codegeneration/integral_generator.py:271, in IntegralGenerator.generate_quadrature_loop(self, quadrature_rule)
268 definitions, intermediates_0 = self.generate_varying_partition(quadrature_rule)
270 # Generate dofblock parts, some of this will be placed before or after quadloop
--> 271 tensor_comp, intermediates_fw = self.generate_dofblock_partition(quadrature_rule)
272 assert all([isinstance(tc, L.Section) for tc in tensor_comp])
274 # Check if we only have Section objects
File /usr/lib/python3/dist-packages/ffcx/codegeneration/integral_generator.py:385, in IntegralGenerator.generate_dofblock_partition(self, quadrature_rule)
383 intermediates = []
384 for blockmap in block_groups:
--> 385 block_quadparts, intermediate = self.generate_block_parts(
386 quadrature_rule, blockmap, block_groups[blockmap]
387 )
388 intermediates += intermediate
390 # Add computations
File /usr/lib/python3/dist-packages/ffcx/codegeneration/integral_generator.py:504, in IntegralGenerator.generate_block_parts(self, quadrature_rule, blockmap, blocklist)
500 assert all(isinstance(o, L.Symbol) for o in output)
502 intermediates += [L.VariableDecl(fw, fw_rhs)]
--> 504 var = fw if isinstance(fw, L.Symbol) else fw.array
505 vars += [var]
506 assert not blockdata.transposed, "Not handled yet"
AttributeError: 'LiteralFloat' object has no attribute 'array'
I don’t understand how to remove the Literal Form error. However, assembling constant matrix C doesn’t make error.
Q2. How can I add subdomain data for the above interval mesh. The MeshFunction is not supoorted in dolfinx.
Any help is greatly appreciated.