Engee 文档
Notebook

加载 STL 文件并计算涡轮叶片载荷状态

在本脚本中,我们将举例说明 Engee 环境是如何实现以下功能的:

  1. 从 STL 格式加载零件的 3D 模型
  2. 可视化该模型的网格 使用 MATLAB 命令计算零件的加载状态。

要打开 CAD 文件(STL 格式),我们将使用 [Meshes.jl] 库(https://juliageometry.github.io/Meshes.jl/stable/)。它允许使用多种不同的 CAD 格式和计算网格,并能为进一步操作准备一个已保存的物体 3D 模型。

在可视化方面,我们首先使用 Engee 内置的标准 Plots 库,然后使用高级库 Makie。您可以访问 Makie's Plots Gallery,评估其功能。

</p

在第三部分中,我们将演示如何使用 Engee 进行涡轮叶片所受机械载荷的示例计算,并将图形放大。

加载三维模型

首先,让我们为这一步连接必要的库

In [ ]:
Pkg.add(["CairoMakie", "Makie", "Animations", "Meshes", "MeshIO"])
In [ ]:
import Pkg; Pkg.add(["Meshes", "MeshIO"], io=devnull);
using Meshes, MeshIO, FileIO, Plots
#plotly();
gr();

指定一个工作文件夹,用于今后的所有文件操作。

In [ ]:
cd( @__DIR__ )

现在让我们加载模型,并使用独立的三角形在图形上显示计算网格,每个三角形都可以以任何方式单独设置样式。

In [ ]:
obj = load( "Blade.stl" );

p = plot()
for i in obj
    m = Matrix([i[1] i[2] i[3] i[1]])'
    plot!( p, m[:,1], m[:,2], m[:,3], lc=:black, label=:none, lw=.1 )
end
plot!( camera=(120, 30), axis=nothing, border=:none, aspect_ratio=:equal, projection_type=:persp )
display(p)

我们为什么不绘制该部件旋转的三维动画呢?

In [ ]:
Pkg.add( "Animations", io=devnull );
using Animations
In [ ]:
obj = load( "Blade.stl" );

@gif for az in 0:10:359
    p = plot()
    for i in obj
        m = Matrix([i[1] i[2] i[3] i[1]])'
        plot!( p, m[:,1], m[:,2], m[:,3], lc=:black, label=:none, lw=.1 )
    end
    plot!( camera = (az, 30), axis=nothing, border=:none, aspect_ratio=:equal )
end
[ Info: Saved animation to /user/start/examples/math_and_optimization/turbine_blade/tmp.gif
Out[0]:
No description has been provided for this image

为了演示处理模型的高级方法,让我们连接可视化库Makie ,并选择合适的工具包进行快速图形绘制 (CairoMakie)。浏览器支持的另一个选项是软件包WGLMakie ,它需要更复杂的设置。其他软件包 (GLMakieRPRMakie) 需要额外的窗口,Engee尚不支持。

In [ ]:
import Pkg; Pkg.add(["Makie", "CairoMakie"], io=devnull);
using Makie, CairoMakie
WARNING: using Makie.plot in module Main conflicts with an existing identifier.
WARNING: using Makie.plot! in module Main conflicts with an existing identifier.

用单线可视化模型。

在加载 Makie 库后立即首次执行该单元格可能需要一分钟以上。

In [ ]:
Makie.wireframe( obj, linewidth=.2 )
Out[0]:
No description has been provided for this image

让我们使用 MATLAB 内核执行计算

对于有限元计算,通常需要使用成熟的外部工具。这方面有许多优秀的研究软件包。例如,将网格划分为多边形的软件包 (tetgen,gmsh) 中的 Julia shells 可以插入 Engee 进行计算。

如果您在 MATLAB 中已有一个项目,或者找到了与您所需非常相似的演示代码,Engee 将允许您运行它并将结果保存到云中。

In [ ]:
using MATLAB

让我们设置一个计算问题并加载零件的三维模型。

连接 MATLAB 库后立即首次执行该单元格可能需要超过一分钟____________________________________________。

In [ ]:
mat"cd $(@__DIR__)"

outp = mat"""
smodel = createpde('structural','static-solid');
g = importGeometry(smodel, 'Blade.stl');

figure;
p = pdegplot( smodel, 'FaceLabels', 'on', 'FaceAlpha',0.5);
axis off;
view( [133.027 16.056] );

saveas( gcf, 'Blade.png' );
""";
>> >> >> >> >> >> >> >> [Warning: MATLAB has disabled some advanced graphics rendering features by
switching to software OpenGL. For more information, click <a
href="matlab:opengl('problems')">here</a>.] 
Fontconfig warning: "/usr/share/fontconfig/conf.avail/05-reset-dirs-sample.conf", line 6: unknown element "reset-dirs"
Fontconfig warning: "/usr/share/fontconfig/conf.avail/05-reset-dirs-sample.conf", line 6: unknown element "reset-dirs"

让我们在 Engee 环境中使用 EngeeImages 中内置的load 命令显示保存的图像。

In [ ]:
using Images
img = Images.load( "Blade.png" )
Out[0]:
No description has been provided for this image

下载的文件只包含曲面的描述。现在让我们在该曲面内创建一个三维计算网格。

In [ ]:
outp = mat"""
msh = generateMesh(smodel,'Hmax',0.01);

figure
p1 = pdemesh(msh, 'FaceAlpha', 1)
view([133.027 16.056])

saveas( gcf, "Blade_mesh.png" )
""";
>> >> >> >> >> >> [Warning: Cannot set Renderer to OpenGL on this figure.] 
[> In pdeplot3D (line 276)
In pdemesh (line 129)] 

p1 = 

  Patch with properties:

    FaceColor: [0 1 1]
    FaceAlpha: 1
    EdgeColor: [0 0 0]
    LineStyle: '-'
        Faces: [5488x3 double]
     Vertices: [2744x3 double]

  Use GET to show all properties

In [ ]:
img = Images.load( "Blade_mesh.png" )
Out[0]:
No description has been provided for this image

第三,我们需要设置问题的参数(计算参数和物理参数),尤其是边界条件。

让我们使用函数solve 计算叶片的变形,并输出三维图形,其中零件的机械变形将被放大数百倍,颜色信息将显示零件给定点圆周上的机械应力程度。

In [ ]:
outp = mat"""
E = 227E9; % in Pa
CTE = 12.7E-6; % in 1/K
nu = 0.27;

s1 = structuralProperties(smodel,'YoungsModulus',E, ...
                            'PoissonsRatio',nu, ...
                            'CTE',CTE);

s2 = structuralBC(smodel,'Face',3,'Constraint','fixed');

p1 = 5e5; %in Pa
p2 = 4.5e5; %in Pa

s3 = structuralBoundaryLoad(smodel,'Face',11,'Pressure',p1); % Pressure side
s4 = structuralBoundaryLoad(smodel,'Face',10,'Pressure',p2);  % Suction side

Rs = solve(smodel);

figure
p2 = pdeplot3D(smodel,'ColorMapData',Rs.VonMisesStress, ...
                 'Deformation',Rs.Displacement, ...
                 'DeformationScaleFactor',100);
%view([116,25]);
view( [133.027 16.056] );

saveas(gcf, "Blade_solved.png");
""";

让我们在同一投影中显示两幅图:第一幅图显示我们设置了边界条件的叶片区域的分布。第二张图显示了变形模型,并标注了高机械应力区域。

In [ ]:
img_topo = Images.load( "Blade.png" );
img_mesh = Images.load( "Blade_mesh.png" );
img_solved = Images.load( "Blade_solved.png" );
mosaic(img_topo, img_mesh, img_solved; nrow=1)
Out[0]:
No description has been provided for this image