带有Expression()的C ++编译问题

问题描述 投票:0回答:1

[我是一名初学者,我正在尝试用边界条件来解析泊松方程,该边界条件是Python库opensimplex产生的Perlin噪声。

我正在尝试通过Expression()定义边界条件f。

我尝试过Expression('function(x[0],x[1],x[2])'),其中function (x,y,z)=opensimplex.tmp.noise3d(x,y,z))。但是,由于此opensimplex函数不受C ++管理,因此出现编译错误。 Compilation failed!

是否有解决此错误的解决方案?

python c++ fenics
1个回答
0
投票

在开始使用FEniCS中的瞬态流时,我遇到了类似的问题。在定义变体形式之前,为UserExpression定义一个子类应启用编译。

    from dolfin import *
    parameters["reorder_dofs_serial"] = True

### (Here you add your domain generation and FunctionSpace definition)

    class Expression(SubDomain):
      def inside(self,a,on_boundary):
         return (x[0]) and (x[1]) and (x[2]) and on_boundary

    f=MyExpression(2.0)
    print(assemble(f*dx(domain=UnitIntervalMesh(1))))


如果仍然不能进行编译,请附加代码的相关部分,我们可以尝试解决它们。

如果您有固定的尺寸顺序(例如2-D),则可能还需要在对自由度进行重新排序后添加此顺序:

parameters["form_compiler"]["quadrature_degree"]=2 

祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.