Yes sorry here is a part of my code and it reproduces the error that I was mentioning :
from dolfin import *
import numpy as np
# Define mesh
nx = 100
ny = 2500
mesh = RectangleMesh(Point(0., 0.), Point(0.002, 0.001), nx, ny, "crossed") #2D
# Reading input data file composed by y position on the boundary and associated pressure
path = 'SCB_outputs/SCB_wall_pressure_double00001.data'
p_SCB = np.loadtxt(path, usecols=1, unpack='True')
y_SCB = np.loadtxt(path, usecols=0, unpack='True')
def left(x, on_boundary):
return near(x[0], 0.) and on_boundary
#Subdomain creation to then define the boundary step size dss
boundary_subdomains = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
force_boundary = AutoSubDomain(left)
force_boundary.mark(boundary_subdomains, 3)
class LeftBoundary(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0.0)
#Necessary to define W functionspace associated to the left boundary
leftboundary = LeftBoundary()
boundarymesh = BoundaryMesh(mesh, 'exterior')
left_mesh = SubMesh(boundarymesh, leftboundary)
V = VectorFunctionSpace(mesh, "CG", 1)
W = FunctionSpace(left_mesh, "CG", 1)
u_ = TestFunction(V)
p = Function(W, name='loading')
# vertical position indices
ind2 = [iind2 for iind2 in range (len(y_SCB))]
dof_coords = W.tabulate_dof_coordinates()
# W degrees of freedom indices
ind = np.lexsort((dof_coords[:, 1], dof_coords[:, 0]))
for (in_index, p_index) in zip(ind2, ind):
p.vector()[p_index] = p_SCB[in_index]
# Define measure for boundary condition integral
dss = ds(subdomain_data=boundary_subdomains)
# Work of external forces
def Wext(u_):
return u_[0]*p*dss(3)
error = Wext(u_) #error occurs when computing Wext(u_)
I read a data file to determine the pressure load on the left boundary. This data file is composed of 2500 lines. That is why ny = 2500
in order to first avoid to interpolate the input datas on the mesh that I am using with fenics but you can reproduce the error with any data file and replacing ny
by the lines number of the data file.
(I get the following error:
Traceback (most recent call last):
File "dokken.py", line 56, in <module>
error = Wext(u_) #error occurs when calculating Wext(u_)
File "dokken.py", line 54, in Wext
return u_[0]*p*dss(3)
File "/home/menezl/anaconda3/envs/fenics/lib/python3.8/site-packages/ufl/measure.py", line 437, in __rmul__
domains = extract_domains(integrand)
File "/home/menezl/anaconda3/envs/fenics/lib/python3.8/site-packages/ufl/domain.py", line 355, in extract_domains
return sorted(join_domains(domainlist))
TypeError: '<' not supported between instances of 'Mesh' and 'Mesh'
)