算例出处:http://libmesh.sourceforge.net/systems_of_equations_ex1.php
11 int main(int argc char** argv)
12
13 {
14 LibMeshInit init(argc, argv);
15 Mesh mesh(init.comm());
16 /*libMesh::Mesh
17 * http://libmesh.sourceforge.net/doxygen/classlibMesh_1_1Mesh.php
18 */
19 MeshTools::Generation::build_square(mesh,
20 15, 15,
21 0., 1.,
22 0., 1.,
23 QUAD9);
24 /*
25 * libMesh::MeshTools:Generation
26 * http://libmesh.sourceforge.net/doxygen/namespacelibMesh_1_1MeshTools_1_1Generation.php
27 * 几何生成函数(点,线,面,块,球)
28 * build_point, build_line, build_square
29 * build_cube, build_sphere
30 * build_extrusion, build_delaunay_square
31 */
32
33 EquationSystems equation_systems(mesh);
34 /*
35 *libMesh::EquationSystems
*http://libmesh.sourceforge.net/doxygen/classlibMesh_1_1EquationSystems.php
37 * 共有函数:构造/析构, clear(), init(), update, has_system(), get_system()
38 * matrix(); add_system(), delete_system(), n_vars(), n_active_dofs(), solve(), get_solution(), get_mesh(), get_info
39 */
40
41 LinearImplicitSystem &system = equation_systems.add_system<LinearImplicitSystem> ("Stokes");
42 /*
43 * libMesh::LinearImplicitSystem
44 * http://libmesh.sourceforge.net/doxygen/classlibMesh_1_1LinearImplicitSystem.php
45 * add_variable(), attach_assemble_function()
46 */
47
48 system.add_variable("u",SECOND);
52 system.attach_assemble_function(assemble_stokes);
53
54 equation_systems.init();
56 equation_systems.parameters.set<unsigned int>("linear solver maximum iterations") = 250;
58 equation_systems.get_system("Stokes").solve();
59 }
60
61 void assemble_stokes(EquationSystems& es, const std::string& system_name)
62 {
63 const MeshBase& mesh = es.get_mesh();
64 const unsigned int dim=mesh.mesh_dimension();
65 LinearImplicitSystem& system=es.get_system<LinearImplicitSystem>("Stokes");
66 const unsigned int u_var = system.variable_number("u");
FEType fe_vel_type = system.variable_type(u_var);
69 FEType fe_pres_type = system.variable_type(p_var);
70 /*libMesh::FEType
71 * http://libmesh.sourceforge.net/doxygen/classlibMesh_1_1FEType.php
72 */
73
74 /*libMesh::FEGeneraicBase
75 * http://libmesh.sourceforge.net/doxygen/classlibMesh_1_1FEGenericBase.php
76 * 函数:get_phi(), get_dphi(), attach_quadrature_rule(); build(); reinit(); get_xyz(); get_JxW(); get_tangents();get_type(); n_shape_functions(); print_info()
77 */
78
79 /*libMesh::AutoPtr
80 * http://libmesh.sourceforge.net/doxygen/classlibMesh_1_1AutoPtr.php#details
81 * std::AutoPtr, an AutoPtr owns the object it holds a pointer to, copying an AutoPtr copies the pointer and transfers owners hip to the destination
82 */
83 AutoPtr<FEBase> fe_pres(FEBase::build(dim,fe_pres_type));
84
85 QGauss qrule(dim, fe_vel_type.default_quadrature_order());
86
87 fe_vel->attach_quadrature_rule(&qrule);
88 fe_pres->attach_quadrature_rule(&qrule);
89
90 /* libMesh::DofMap
91 * http://libmesh.sourceforge.net/doxygen/classlibMesh_1_1DofMap.php
92 * 函数:variable_type(), n_dofs()
93 */
94 const DofMap& dof_map = system.get_dof_map();
95
结尾
libmesh内容非常庞大,相比oofem,可以大概理解这些类。
libmesh::mesh == oofem::domain -> dof,单元数据管理(底层)
libmesh::equationsystem == oofem::engmodel -> 物理问题(映射)到有限元空间(平台)
libmesh::linearimplicitsystem == oofem::linearstatic -> 特定有限元空间数值解(实现层)
其他,smart指针设计,单元迭代器,数值积分类,矩阵计算,自适应网格模块等等。
本文大致介绍下libmesh中经常用到的类,当然还有非常多,瞬态问题,非线性问题等等求解器类都非常丰富,使用中继续学习。后文继续介绍该问题的libmesh(有限元)实现思路。