I am trying to define a user-expression to define a domain with multiple materials (2, in this case). The domain looks something like this.
And the 0.05.txt
file looks something like the following (a 248 x 2
array of xy-coordinates):
6.028109416615006211e-01 5.515052548117607145e-01
9.596400633462656149e-01 4.778156527123709196e-01
.....
.....
5.210369931266580767e-01 7.947431392353718760e-01
Basically, I am creating a C++ string to define an Expression
that takes value 0. inside the red circles and 1. otherwise. But the code fails to compile producing the following output (a sample snapshot of the error.log
).
/tmp/tmpx2m4o8hv/dolfin_subdomain_2eb89048041746e695cf85fd8a456902.cpp: In member function āvirtual bool dolfin::dolfin_subdomain_2eb89048041746e695cf85fd8a456902::inside(Eigen::Ref<const Eigen::Matrix<double, -1, 1> >, bool) constā:
/tmp/tmpx2m4o8hv/dolfin_subdomain_2eb89048041746e695cf85fd8a456902.cpp:63:0: error: lvalue required as decrement operand
return pow(x[0]-0.602810941662,2)+pow(x[1]-0.551505254812,2) < 0.000132629119243 || pow(x[0]-0.959640063346,2) ...............
................
................
................ || pow(x[0]-0.521036993127,2)+pow(x[1]-0.794743139235,2) < 0.000132629119243;
/tmp/tmpx2m4o8hv/dolfin_subdomain_2eb89048041746e695cf85fd8a456902.cpp:63:0: error: lvalue required as decrement operand
MWE:
from dolfin import *
import numpy as np
import os
def generateCirclerandom(fname,rad):
arr_circles = np.loadtxt(fname) #fname contains the coordinates of the centres of the circles
circ_strng = []
for i in range(arr_circles.shape[0]):
circle_i = arr_circles[i]
circ_strng.append('pow(x[0]-'+str(circle_i[0])+',2)+pow(x[1]-'+str(circle_i[1])+',2) < '+str(rad**2))
tot_string = ' || '.join(u for u in circ_strng)
return circ_strng, tot_string
L = 1.
fo = 0.05
nps = 120
p0 = Point(0.,0.)
p1 = Point(L,L)
msh=RectangleMesh.create(comm,[p0,p1],[400,400],CellType.Type.quadrilateral)
r_xy = L*np.sqrt(fo/np.pi/nps)
list_string, tot_string = generateCirclerandom('0.05.txt',r_xy)
Estring = tot_string + ' ? ' + str(0.) +' : '+str(1.)
Evals = Expression(Estring,degree=2)
# ************ Also tried the following **********************
# omega_holes = CompiledSubDomain(tot_string,mpi_comm = MPI.comm_world)
# Evals = MeshFunction('double',msh,2)
# Evals.set_all(1.)
# omega_holes.mark(Evals,0.)
with XDMFFile(MPI.comm_world,'trial.xdmf') as wfil:
wfil.write(Evals)