Hello FEniCSx users,
I am trying to implement a simple vibroacoustics model where a cuboid shaped air domain interacts with a plate, which is a rectangular surface of the cuboid.
The problem is that I have encountered a cpp compilation error that I haven’t been able to figure out its cause.
The error rises at fem.form( inner(grad(pf),grad(w_)) * ds,entity_maps=entity_maps)
, where pf is the trial function in air domain, w_ is the test function in plate domain, and ds is defined over the plate.
When I remove both grad, it runs fine, so I believe it’s not about the wrong choice of integration measure…
I might be missing something fairly basic here, but I would appreciate it if someone could give me an advice.
Thank you in advance.
Below is the MWE follwed by its error
from dolfinx.fem import dirichletbc,Function, FunctionSpace, assemble_scalar, form, functionspace, assemble_vector, locate_dofs_geometrical, locate_dofs_topological
from dolfinx.fem import petsc, Constant
from dolfinx.io import gmshio, XDMFFile
from dolfinx import fem, mesh, default_scalar_type, plot, cpp, io
import ufl
import bempp.api
from mpi4py import MPI
from petsc4py import PETSc
from dolfinx.fem.petsc import LinearProblem
from ufl import TrialFunction, TestFunction, dx, grad, dot, inner, div, ds, as_vector, Measure, conj, sym
import typing
import gmsh
import numpy.typing
import sys
import numpy as np
from basix.ufl import element
import basix
import vtk
from dolfinx.fem.petsc import assemble_matrix_block, assemble_vector_block
from dolfinx import plot
def CreateModel(X=0.5,Y=0.5,xd=8,yd=8,sweep=2):
pht={'Air':31, 'Bottom':20, 'Plate':21}
gmsh.initialize(sys.argv)
gmsh.model.add('Plate')
gmsh.option.setString('Geometry.OCCTargetUnit','M') # Unit is now in meter, instead of mm
gmsh.option.setNumber("General.Verbosity", 0)
btm=gmsh.model.occ.addRectangle(0, 0, 0, X, Y, 1)
gmsh.model.occ.synchronize()
edges = gmsh.model.getEntities(dim=1)
btm_srf = gmsh.model.getEntities(dim=2)
for idx in [idx for (dim, idx) in edges if dim == 1]:
if idx%2:
gmsh.model.mesh.setTransfiniteCurve(idx, xd) # Bottom edge
else:
gmsh.model.mesh.setTransfiniteCurve(idx, yd) # Bottom edge
gmsh.model.mesh.setTransfiniteSurface(btm)
gmsh.model.mesh.setRecombine(2, btm)
air=gmsh.model.occ.extrude([btm_srf[0]],0,0,0.5,[sweep],recombine=True)
Nair=[idx for (dim, idx) in air if dim == 3]
Nplate=[[idx for (dim, idx) in air if dim == 2][0]]
gmsh.model.occ.synchronize()
gmsh.model.addPhysicalGroup(3, Nair, pht['Air'], 'Air') # ID No3 in 3D(Volume)
gmsh.model.addPhysicalGroup(2, Nplate, pht['Plate'], 'Plate')
gmsh.model.addPhysicalGroup(2, [btm], pht['Bottom'], 'Bottom')
gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(3)
model_rank = 0
gdim = 3
partitioner = cpp.mesh.create_cell_partitioner(
mesh.GhostMode.shared_facet
)
domain, ct, ft = io.gmshio.model_to_mesh(
gmsh.model, MPI.COMM_WORLD, model_rank, gdim=gdim, partitioner=partitioner
)
gmsh.finalize()
return domain,ct,ft,pht
# Create mesh(cube) and submesh(rectangular), pht is a physical tag
domain,ct,ft,pht=CreateModel(X=0.5,Y=0.5,xd=4,yd=4,sweep=2)
tdim = domain.topology.dim
fdim = tdim-1
domain.topology.create_connectivity(tdim - 1, tdim)
plate_mesh, plate_cell_map, plate_vertex_map, _ = mesh.create_submesh(domain,2,ft.find(pht['Plate']))
# Create entity_maps
facet_imap = domain.topology.index_map(ft.dim)
num_facets = facet_imap.size_local + facet_imap.num_ghosts
domain_to_plate = np.full(num_facets, -1)
domain_to_plate[plate_cell_map] = np.arange(len(plate_cell_map))
entity_maps = {plate_mesh: domain_to_plate}
#Create function spaces
deg=2
elw = element("Lagrange", plate_mesh.topology.cell_name(), deg)
Vpw = fem.functionspace(plate_mesh, elw)
ela = element("Lagrange", domain.topology.cell_name(), deg)
Va = fem.functionspace(domain, ela)
V=ufl.MixedFunctionSpace(Vpw,Va)
w,pf=ufl.TrialFunctions(V)
w_,pf_=ufl.TestFunctions(V)
ds = ufl.Measure('ds',domain=domain,subdomain_id=pht['Plate'], subdomain_data=ft)
#OK
fem.form( inner(pf,w_) * ds,entity_maps=entity_maps)
#NG
fem.form( inner(ufl.grad(pf),ufl.grad(w_)) * ds,entity_maps=entity_maps)
libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c:11149:10: error: redefinition of 'J_c4'
11149 | double J_c4 = 0.0;
| ^
libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c:11146:10: note: previous definition is here
11146 | double J_c4 = 0.0;
| ^
libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c:11151:10: error: redefinition of 'J_c5'
11151 | double J_c5 = 0.0;
| ^
libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c:11148:10: note: previous definition is here
11148 | double J_c5 = 0.0;
| ^
libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c:11153:10: error: redefinition of 'J_c0'
11153 | double J_c0 = 0.0;
| ^
libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c:11144:10: note: previous definition is here
11144 | double J_c0 = 0.0;
| ^
libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c:11154:10: error: redefinition of 'J_c3'
11154 | double J_c3 = 0.0;
| ^
libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c:11147:10: note: previous definition is here
11147 | double J_c3 = 0.0;
| ^
libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c:11156:10: error: redefinition of 'J_c1'
11156 | double J_c1 = 0.0;
| ^
libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c:11143:10: note: previous definition is here
11143 | double J_c1 = 0.0;
| ^
libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c:11157:10: error: redefinition of 'J_c2'
11157 | double J_c2 = 0.0;
| ^
libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c:11145:10: note: previous definition is here
11145 | double J_c2 = 0.0;
| ^
6 errors generated.
---------------------------------------------------------------------------
CalledProcessError Traceback (most recent call last)
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/_distutils/spawn.py:70, in spawn(cmd, search_path, verbose, dry_run, env)
69 try:
---> 70 subprocess.check_call(cmd, env=_inject_macos_ver(env))
71 except OSError as exc:
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/subprocess.py:421, in check_call(*popenargs, **kwargs)
420 cmd = popenargs[0]
--> 421 raise CalledProcessError(retcode, cmd)
422 return 0
CalledProcessError: Command '['/opt/homebrew/Caskroom/miniconda/base/envs/fenics/bin/arm64-apple-darwin20.0.0-clang', '-ftree-vectorize', '-fPIC', '-fstack-protector-strong', '-O2', '-pipe', '-isystem', '/opt/homebrew/Caskroom/miniconda/base/envs/fenics/include', '-D_FORTIFY_SOURCE=2', '-isystem', '/opt/homebrew/Caskroom/miniconda/base/envs/fenics/include', '-I/opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/ffcx/codegeneration', '-I/opt/homebrew/Caskroom/miniconda/base/envs/fenics/include/python3.13', '-c', 'libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.c', '-o', './libffcx_forms_bc63abba973c607dacd574e4c13e4fb24ea727f1.o', '-std=c17', '-O2', '-g0']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
DistutilsExecError Traceback (most recent call last)
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/_distutils/unixccompiler.py:200, in UnixCCompiler._compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts)
199 else:
--> 200 self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
201 except DistutilsExecError as msg:
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/_distutils/ccompiler.py:1052, in CCompiler.spawn(self, cmd, **kwargs)
1051 def spawn(self, cmd, **kwargs):
-> 1052 spawn(cmd, dry_run=self.dry_run, **kwargs)
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/_distutils/spawn.py:76, in spawn(cmd, search_path, verbose, dry_run, env)
75 except subprocess.CalledProcessError as err:
---> 76 raise DistutilsExecError(
77 f"command {_debug(cmd)!r} failed with exit code {err.returncode}"
78 ) from err
DistutilsExecError: command '/opt/homebrew/Caskroom/miniconda/base/envs/fenics/bin/arm64-apple-darwin20.0.0-clang' failed with exit code 1
During handling of the above exception, another exception occurred:
CompileError Traceback (most recent call last)
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/cffi/ffiplatform.py:48, in _build(tmpdir, ext, compiler_verbose, debug)
47 set_verbosity(compiler_verbose)
---> 48 dist.run_command('build_ext')
49 cmd_obj = dist.get_command_obj('build_ext')
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/dist.py:999, in Distribution.run_command(self, command)
996 # Postpone defaults until all explicit configuration is considered
997 # (setup() args, config files, command line and plugins)
--> 999 super().run_command(command)
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/_distutils/dist.py:1002, in Distribution.run_command(self, command)
1001 cmd_obj.ensure_finalized()
-> 1002 cmd_obj.run()
1003 self.have_run[command] = True
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/command/build_ext.py:99, in build_ext.run(self)
98 old_inplace, self.inplace = self.inplace, False
---> 99 _build_ext.run(self)
100 self.inplace = old_inplace
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/_distutils/command/build_ext.py:365, in build_ext.run(self)
364 # Now actually compile and link everything.
--> 365 self.build_extensions()
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/_distutils/command/build_ext.py:481, in build_ext.build_extensions(self)
480 else:
--> 481 self._build_extensions_serial()
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/_distutils/command/build_ext.py:507, in build_ext._build_extensions_serial(self)
506 with self._filter_build_errors(ext):
--> 507 self.build_extension(ext)
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/command/build_ext.py:264, in build_ext.build_extension(self, ext)
263 self.compiler = self.shlib_compiler
--> 264 _build_ext.build_extension(self, ext)
265 if ext._needs_stub:
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/_distutils/command/build_ext.py:562, in build_ext.build_extension(self, ext)
560 macros.append((undef,))
--> 562 objects = self.compiler.compile(
563 sources,
564 output_dir=self.build_temp,
565 macros=macros,
566 include_dirs=ext.include_dirs,
567 debug=self.debug,
568 extra_postargs=extra_args,
569 depends=ext.depends,
570 )
572 # XXX outdated variable, kept here in case third-part code
573 # needs it.
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/_distutils/ccompiler.py:607, in CCompiler.compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends)
606 continue
--> 607 self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
609 # Return *all* object filenames, not just the ones we just built.
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/setuptools/_distutils/unixccompiler.py:202, in UnixCCompiler._compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts)
201 except DistutilsExecError as msg:
--> 202 raise CompileError(msg)
CompileError: command '/opt/homebrew/Caskroom/miniconda/base/envs/fenics/bin/arm64-apple-darwin20.0.0-clang' failed with exit code 1
During handling of the above exception, another exception occurred:
VerificationError Traceback (most recent call last)
Cell In[1], line 101
99 fem.form( inner(pf,w_) * ds,entity_maps=entity_maps)
100 #NG
--> 101 fem.form( inner(ufl.grad(pf),ufl.grad(w_)) * ds,entity_maps=entity_maps)
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/dolfinx/fem/forms.py:337, in form(form, dtype, form_compiler_options, jit_options, entity_maps)
334 else:
335 return form
--> 337 return _create_form(form)
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/dolfinx/fem/forms.py:331, in form.<locals>._create_form(form)
329 return None
330 else:
--> 331 return _form(form)
332 elif isinstance(form, collections.abc.Iterable):
333 return list(map(lambda sub_form: _create_form(sub_form), form))
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/dolfinx/fem/forms.py:254, in form.<locals>._form(form)
252 if mesh is None:
253 raise RuntimeError("Expecting to find a Mesh in the form.")
--> 254 ufcx_form, module, code = jit.ffcx_jit(
255 mesh.comm, form, form_compiler_options=form_compiler_options, jit_options=jit_options
256 )
258 # For each argument in form extract its function space
259 V = [arg.ufl_function_space()._cpp_object for arg in form.arguments()]
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/dolfinx/jit.py:62, in mpi_jit_decorator.<locals>.mpi_jit(comm, *args, **kwargs)
58 @functools.wraps(local_jit)
59 def mpi_jit(comm, *args, **kwargs):
60 # Just call JIT compiler when running in serial
61 if comm.size == 1:
---> 62 return local_jit(*args, **kwargs)
64 # Default status (0 == ok, 1 == fail)
65 status = 0
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/dolfinx/jit.py:212, in ffcx_jit(ufl_object, form_compiler_options, jit_options)
210 # Switch on type and compile, returning cffi object
211 if isinstance(ufl_object, ufl.Form):
--> 212 r = ffcx.codegeneration.jit.compile_forms([ufl_object], options=p_ffcx, **p_jit)
213 elif isinstance(ufl_object, ufl.Mesh):
214 r = ffcx.codegeneration.jit.compile_coordinate_maps([ufl_object], options=p_ffcx, **p_jit)
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/ffcx/codegeneration/jit.py:225, in compile_forms(forms, options, cache_dir, timeout, cffi_extra_compile_args, cffi_verbose, cffi_debug, cffi_libraries, visualise)
223 except Exception:
224 pass
--> 225 raise e
227 obj, module = _load_objects(cache_dir, module_name, form_names)
228 return obj, module, (decl, impl)
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/ffcx/codegeneration/jit.py:205, in compile_forms(forms, options, cache_dir, timeout, cffi_extra_compile_args, cffi_verbose, cffi_debug, cffi_libraries, visualise)
202 for name in form_names:
203 decl += form_template.format(name=name)
--> 205 impl = _compile_objects(
206 decl,
207 forms,
208 form_names,
209 module_name,
210 p,
211 cache_dir,
212 cffi_extra_compile_args,
213 cffi_verbose,
214 cffi_debug,
215 cffi_libraries,
216 visualise=visualise,
217 )
218 except Exception as e:
219 try:
220 # remove c file so that it will not timeout next time
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/ffcx/codegeneration/jit.py:380, in _compile_objects(decl, ufl_objects, object_names, module_name, options, cache_dir, cffi_extra_compile_args, cffi_verbose, cffi_debug, cffi_libraries, visualise)
378 root_logger.handlers = [logging.StreamHandler(f)]
379 with redirect_stdout(f):
--> 380 ffibuilder.compile(tmpdir=cache_dir, verbose=True, debug=cffi_debug)
381 s = f.getvalue()
382 if cffi_verbose:
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/cffi/api.py:727, in FFI.compile(self, tmpdir, verbose, target, debug)
725 raise ValueError("set_source() must be called before compile()")
726 module_name, source, source_extension, kwds = self._assigned_source
--> 727 return recompile(self, module_name, source, tmpdir=tmpdir,
728 target=target, source_extension=source_extension,
729 compiler_verbose=verbose, debug=debug, **kwds)
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/cffi/recompiler.py:1581, in recompile(ffi, module_name, preamble, tmpdir, call_c_compiler, c_file, source_extension, extradir, compiler_verbose, target, debug, uses_ffiplatform, **kwds)
1579 print('%s %r' % (msg, os.path.abspath(tmpdir)))
1580 os.chdir(tmpdir)
-> 1581 outputfilename = ffiplatform.compile('.', ext,
1582 compiler_verbose, debug)
1583 finally:
1584 os.chdir(cwd)
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/cffi/ffiplatform.py:20, in compile(tmpdir, ext, compiler_verbose, debug)
18 saved_environ = os.environ.copy()
19 try:
---> 20 outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
21 outputfilename = os.path.abspath(outputfilename)
22 finally:
23 # workaround for a distutils bugs where some env vars can
24 # become longer and longer every time it is used
File /opt/homebrew/Caskroom/miniconda/base/envs/fenics/lib/python3.13/site-packages/cffi/ffiplatform.py:54, in _build(tmpdir, ext, compiler_verbose, debug)
52 set_threshold(old_level)
53 except (CompileError, LinkError) as e:
---> 54 raise VerificationError('%s: %s' % (e.__class__.__name__, e))
55 #
56 return soname
VerificationError: CompileError: command '/opt/homebrew/Caskroom/miniconda/base/envs/fenics/bin/arm64-apple-darwin20.0.0-clang' failed with exit code 1