Engee 文档
Notebook

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

在这个脚本中,我们将展示一个如何使用Engee环境的例子。:

  1. 从STL格式上传零件的三维模型
  2. 可视化此模型的网格
  3. 使用MATLAB命令计算零件的加载状态

要打开CAD文件(STL格式),我们将使用库[Meshes.jl](https://juliageometry.github.io/Meshes ...jl/稳定/)。 它允许您使用许多不同的CAD格式和计算网格,并可以准备一个保存的对象三维模型进行进一步的操作。

对于可视化,我们首先使用Engee内置的标准Plots库,然后使用更高级别的[Makie]库(https://docs.makie.org/stable /)。 您可以通过访问[Makie图形库](http://juliaplots.org/MakieReferenceImages/gallery/index.html )。

在第三部分中,我们将演示如何在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]:

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

要使用有限元方法进行计算,通常需要使用成熟的外部工具。 在这个领域有很多优秀的研究包。 例如,用于将网格划分为多边形的包(tetgen, gmsh)Julia中有shell可以连接到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环境中显示保存的图像 load 内置工程师图书馆 Images.

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