• 边界条件

• 网格生成

• 求解

• 后处理

## 二、SALOME Mesh

SALOME Mesh模块(简称SMESH)提供了网格生成、网格修改、网格数据交换等功能。基于Meshing Plug-in模块，可以将开源或商业网格生成程序嵌入到SMESH。

 开源 Netgen、Gmsh 商业 MeshGems

SMESH_GenSMESH_MeshSMDS_MeshSMESHDS_MeshSMESH_Hypothesis等类构成了整个SALOME Mesh的核心。

### 2.1 网格生成技术概述

 结构化网格 代数方法、保角变换法、偏微分方程法 非结构化网格 阵面推进法、Delaunay法、四叉树/八叉树法 混合网格 层推进法

Timothy, J, Baker. Mesh generation: Art or science?. Progress in Aerospace Sciences, 2005, 41(1):29-63.

Thompson J F , Warsi Z , Mastin C W . Numerical grid generation:foundations and applications, 1985.

Baker, T. J. .Mesh generation: Art or science? Progress in Aerospace Sciences, 2005, 41(1), 29–63.

Gordon W J , Thiel L C . Transfinite mappings and their application to grid generation[J]. Applied Mathematics & Computation, 1982, 10(none):171-233.

Godunov S K , Prokopov G P . On the computation of conformal transformations and the construction of difference meshes[J]. Ussr Computational Mathematics & Mathematical Physics, 1967, 7(5):89-124.

Eiseman P R , Erlebacher G . Grid generation for the solution of partial differential equations[J]. 1989.

### 2.2 hypotheses

Refs. from SALOME Mesh =====================================================

Hypotheses specify constraints to be taken into account by the chosen meshing algorithms.

Hypotheses represent boundary conditions which will be taken into account by meshing algorithms. The hypotheses allow you to manage the level of detail of the resulting mesh: when applying different hypotheses with different parameters you can preset the quantity or size of elements which will compose your mesh.

=====================================================Refs. from SALOME Mesh

## 三、Netgen

Netgen是一个开源、跨平台的三维自动网格剖分工具。Netgen最早为奥地利科学家Joachim Schoberl编写的网格剖分程序，是网格划分技术中极为先进与完善的，在3D网格划分领域更是具有极大的优势。

Refs. from Netgen ===========================================================

NETGEN is an automatic 3d tetrahedral mesh generator. It accepts input from constructive solid geometry (CSG) or boundary representation (BRep) from STL file format. The connection to a geometry kernel allows the handling of IGES and STEP files. NETGEN contains modules for mesh optimization and hierarchical mesh refinement. Netgen 6.x supports scripting via a Python interface. Netgen is open source based on the LGPL license. It is available for Unix/Linux, Windows, and OSX.

===========================================================Refs. from Netgen

## 五、核心组件

### 5.1 Constraint及其子类

Fem::Constraint的子类（Fem::ConstraintDisplacement、Fem::ConstraintForce、Fem::ConstraintTemperature等）则定义了各种具体的边界条件类型。

### 5.2 FemMesh

FemMesh用于生成计算网格数据，不仅提供了与Nastran、Abaqus、Z88等软件网格地数据交换功能，而且实现了基于SMESH_Mesh的网格生成功能。

### 5.4 FemPostObject及其子类

FemPostObject用于存储经过VTK Filter流水线的最终数据。

``````//poly data is the only data we can visualize, hence every post processing object needs to expose it
class AppFemExport FemPostObject : public App::GeoFeature
{

public:
/// Constructor
FemPostObject(void);
virtual ~FemPostObject();

Fem::PropertyPostDataObject Data;

vtkBoundingBox getBoundingBox();
};``````

FemPostFilter用于存储VTK Filter流水线；

``````class AppFemExport FemPostFilter : public Fem::FemPostObject
{

public:
/// Constructor
FemPostFilter(void);
virtual ~FemPostFilter();

virtual App::DocumentObjectExecReturn* execute(void);

protected:
vtkDataObject* getInputData();

//pipeline handling for derived filter
struct FilterPipeline {
vtkSmartPointer<vtkAlgorithm>                    source, target;
vtkSmartPointer<vtkProbeFilter>                  filterSource, filterTarget;
std::vector<vtkSmartPointer<vtkAlgorithm> >      algorithmStorage;
};

void addFilterPipeline(const FilterPipeline& p, std::string name);
void setActiveFilterPipeline(std::string name);
FilterPipeline& getFilterPipeline(std::string name);
private:
//handling of multiple pipelines which can be the filter
std::map<std::string, FilterPipeline> m_pipelines;
std::string m_activePipeline;
};``````

FemPostPipeline是一个FemPostFilter容器。作为FemPostFilter的容器，FemPostPipeline支持“Serial”、“Parallel”等两种工作模式。通常来说，大部分场景使用“Serial”模式即可，这也是FemPostPipeline的默认值。根据需要，可以创建多个FemPostPipeline对象，用于容纳不同的后处理流水线。

``````class AppFemExport FemPostPipeline : public Fem::FemPostFilter
{

public:
/// Constructor
FemPostPipeline(void);
virtual ~FemPostPipeline();

App::PropertyEnumeration    Mode;

short mustExecute(void) const;
virtual App::DocumentObjectExecReturn* execute(void);
PyObject* getPyObject();

virtual const char* getViewProviderName(void) const {
return "FemGui::ViewProviderFemPostPipeline";
}

//Pipeline handling
FemPostObject* getLastPostObject();
bool           holdsPostObject(FemPostObject* obj);

protected:
virtual void onChanged(const App::Property* prop);

private:
static const char* ModeEnums[];

}
};``````

## 七、拓展：流体有限元

CBS(Characterictic-Based Split)算法是已故国际计算力学大师Zienkiewicz在上世纪90年代提出的一种求解计算流体力学问题的有限单元法。

## 八、讨论

Q1. 对于SMDS_Mesh，以下成员函数返回不同的迭代器，这些迭代器有何区别？

``````virtual SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator     (bool idInceasingOrder=false) const;
virtual SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator     (bool idInceasingOrder=false) const;
virtual SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator     (bool idInceasingOrder=false) const;
virtual SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator   (bool idInceasingOrder=false) const;

virtual SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator(SMDSAbs_ElementType type=SMDSAbs_All) const;
virtual SMDS_ElemIteratorPtr SMDS_Mesh::elementGeomIterator(SMDSAbs_GeometryType type) const;
virtual SMDS_ElemIteratorPtr SMDS_Mesh::elementEntityIterator(SMDSAbs_EntityType type) const;``````

Q2. 在SMDS_Mesh中，myGrid、myNodes、myCells用于存储网格的几何拓扑信息，三者之间有着怎样的联系呢？

``````  //! actual nodes coordinates, cells definition and reverse connectivity are stored in a vtkUnstructuredGrid
SMDS_UnstructuredGrid*      myGrid;

//! SMDS_MeshNodes refer to vtk nodes (vtk id = index in myNodes),store reference to this mesh, and sub-shape
SetOfNodes             myNodes;

//! SMDS_MeshCells refer to vtk cells (vtk id != index in myCells),store reference to this mesh, and sub-shape
SetOfCells             myCells;``````

Q3. 请阐述SMDS_MeshSMESH_MeshSMESHDS_Mesh的区别与联系？

Q4. 试就FEM模块中几何模型生成、添加边界条件、网格生成、求解器调用、后处理等关键流程进行代码分析。

Q5. 请整理FEM模块中嵌入第三方网格划分代码的操作步骤。

Q6. 请整理FEM模块中嵌入第三方求解器的操作步骤。

Q7. 在现有FEM框架下，如何增加残差、监测数据等曲线绘制？

## 参考资料

3. O. C. Zienkiewicz. The Finite Element Method for Solid and Structural Mechanics (6th Edition).  Butterworth-Heinemann, 2005.
4. O. C. Zienkiewicz. The Finite Element Method for Fluid Dynamics(6th Edition). Butterworth-Heinemann, 2005.
5. 王勖成. 有限单元法. 清华大学出版社, 2003.
6. 张来平. 计算流体力学网格生成技术. 科学出版社，2017.
7. 张正科. 计算流体力学网格生成方法. 科学出版社, 2020.
8. SALOME
9. Gmsh
10. Netgen
11. 3D Precise Mesh
12. NNW-GridStar
13. CalculiX
14. Code_Aster
15. Z88OS
16. Elmer
17. FEniCS
18. OOFEM
19. VTK开发精要：数据与管线机制