I’m trying to run the following code to use LagrangeInterpolator
import unittest
import numpy
from dolfin import *
class Quadratic2D(UserExpression):
def eval(self, values, x):
values[0] = x[0]*x[0] + x[1]*x[1] + 1.0
class Quadratic3D(UserExpression):
def eval(self, values, x):
values[0] = x[0]*x[0] + x[1]*x[1] + x[2]*x[2] + 1.0
class LagrangeInterpolatorTest(unittest.TestCase):
def test_functional2D(self):
"""Test integration of function interpolated in non-matching meshes"""
f = Quadratic2D()
ll = LagrangeInterpolator()
# Interpolate quadratic function on course mesh
mesh0 = UnitSquareMesh(8, 8)
V0 = FunctionSpace(mesh0, "Lagrange", 2)
u0 = Function(V0)
ll.interpolate(u0, f)
# Interpolate FE function on finer mesh
mesh1 = UnitSquareMesh(31, 31)
V1 = FunctionSpace(mesh1, "Lagrange", 2)
u1 = Function(V1)
ll.interpolate(u1, u0)
self.assertAlmostEqual(assemble(u0*dx), assemble(u1*dx), 10)
mesh1 = UnitSquareMesh(30, 30)
V1 = FunctionSpace(mesh1, "Lagrange", 2)
u1 = Function(V1)
ll.interpolate(u1, u0)
self.assertAlmostEqual(assemble(u0*dx), assemble(u1*dx), 10)
def test_functional3D(self):
"""Test integration of function interpolated in non-matching meshes"""
f = Quadratic3D()
ll = LagrangeInterpolator()
# Interpolate quadratic function on course mesh
mesh0 = UnitCubeMesh(4, 4, 4)
V0 = FunctionSpace(mesh0, "Lagrange", 2)
u0 = Function(V0)
ll.interpolate(u0, f)
# Interpolate FE function on finer mesh
mesh1 = UnitCubeMesh(11, 11, 11)
V1 = FunctionSpace(mesh1, "Lagrange", 2)
u1 = Function(V1)
ll.interpolate(u1, u0)
self.assertAlmostEqual(assemble(u0*dx), assemble(u1*dx), 10)
mesh1 = UnitCubeMesh(10, 11, 10)
V1 = FunctionSpace(mesh1, "Lagrange", 2)
u1 = Function(V1)
ll.interpolate(u1, u0)
self.assertAlmostEqual(assemble(u0*dx), assemble(u1*dx), 10)
if __name__ == "__main__":
unittest.main()
Then I get this error. Look like it can not find the dolfin.cpp.function.LagrangeInterpolator.
WARNING: user expression has not supplied value_shape method or an element. Assuming scalar element.
EWARNING: user expression has not supplied value_shape method or an element. Assuming scalar element.
E
======================================================================
ERROR: test_functional2D (__main__.LagrangeInterpolatorTest)
Test integration of function interpolated in non-matching meshes
----------------------------------------------------------------------
Traceback (most recent call last):
File "/media/xuanquang/Gaumap Lab data/01_Project/Homo/20210118_RB/References/LagrangeInterpolator.py", line 42, in test_functional2D
ll = LagrangeInterpolator()
TypeError: dolfin.cpp.function.LagrangeInterpolator: No constructor defined!
======================================================================
ERROR: test_functional3D (__main__.LagrangeInterpolatorTest)
Test integration of function interpolated in non-matching meshes
----------------------------------------------------------------------
Traceback (most recent call last):
File "/media/xuanquang/Gaumap Lab data/01_Project/Homo/20210118_RB/References/LagrangeInterpolator.py", line 68, in test_functional3D
ll = LagrangeInterpolator()
TypeError: dolfin.cpp.function.LagrangeInterpolator: No constructor defined!
----------------------------------------------------------------------
Ran 2 tests in 0.008s
FAILED (errors=2)
This is the path when I import dolfin: “/usr/lib/petsc/lib/python3/dist-packages/dolfin/__init__.py”
Unfortunately, there is no “cpp” folder inside “dolfin” folder.
I tried to find the related find, I have only this: “/usr/include/dolfin/function/LagrangeInterpolator.h”
This is pip3 list:
fenics-dijitso 2019.2.0.dev0
fenics-dolfin 2019.2.0.dev0
fenics-ffc 2019.2.0.dev0
fenics-fiat 2019.2.0.dev0
fenics-ufl 2019.2.0.dev0
This is my intalled package list related to FEniCS, RBniCS:
python3-petsc4py-real/focal,now 3.12.0-4build1 amd64 [installed,automatic]
python3-petsc4py/focal,focal,now 3.12.0-4build1 all [installed,automatic]
python3-slepc4py-real/focal,now 3.12.0-4build1 amd64 [installed,automatic]
python3-slepc4py/focal,focal,now 3.12.0-4build1 all [installed,automatic]
python3-dolfin-real/focal,now 2019.2.0~git20200629.946dbd3-2~ppa1~focal3 amd64 [installed,automatic]
python3-dolfin/focal,now 2019.2.0~git20200629.946dbd3-2~ppa1~focal3 amd64 [installed,automatic]
python3-ffc/focal,focal,now 2019.2.0~git20200123.6b621eb-3~ppa1~focal3 all [installed,automatic]
python3-fiat/focal,focal,now 2019.2.0~git20200919.42ceef3-1~ppa1~focal2 all [installed,automatic]
Please give me some help.