当前位置: 首页>>代码示例>>C++>>正文


C++ TriangleMesh::read_file_msh方法代码示例

本文整理汇总了C++中TriangleMesh::read_file_msh方法的典型用法代码示例。如果您正苦于以下问题:C++ TriangleMesh::read_file_msh方法的具体用法?C++ TriangleMesh::read_file_msh怎么用?C++ TriangleMesh::read_file_msh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TriangleMesh的用法示例。


在下文中一共展示了TriangleMesh::read_file_msh方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
  // Try to read mesh contents from a .msh file (for information about the
  // structure of these files, see FreeFem++ documentation).
  TriangleMesh mesh;
  try {
    mesh.read_file_msh("squared-mesh-2x2.msh"); }
  catch (...) {
    std::cerr << "Error reading mesh file" << std::endl;
    exit(1); }

  // Define quadrature rule with nodes located at vertices of the reference triangle
  VerticesQuadRule quad_rule;

  // Define a finite element space on current mesh
  P1_FE_Space fe_space(mesh, quad_rule);

  // Start chronometer
  auto start = std::chrono::high_resolution_clock::now();

  // Repeat several times (to increase computation time)
  for (int num=0; num<20; ++num) {

    // For each cell, r:
    for (Index r=0; r<mesh.get_ncel(); ++r)
      {
	std::cout << "###### Cell: r=" << r << std::endl << std::endl;

	// In C++11, one can use "auto" instead of "FiniteElement"
	auto fe = fe_space.get_element(r); // Build a finite element on cell r

	// Get x-derivatives of all the shape functions on curent element.
	//
	// The get_dx_phi() member function returns (a const reference
	// to) a vector containng FE_Functions (one for each dof). A
	// FE_Function objetct contains the values resulting from the
	// evaluation of the corresponding shape function on the
	// quadrature points.
	//
	// You can use "auto" instead of "std::vector<FE_Function>",
	// but performance seems better using references ("auto&")
	auto& dx_phi = fe.get_dx_phi();

	// Get also y-derivatives of shape functions
	auto& dy_phi = fe.get_dy_phi();

	Index ndofs = fe.get_ndofs();

	// For each degree of freedom, i:
	for (Index i = 0; i < ndofs; ++i)
	  {
	    // For each degree of freedom, j:
	    for (Index j = 0; j < ndofs; ++j)
	      {
		// Compute integral of product of x-derivatives
		Real Kx_ij = fe.integrate(dx_phi[i], dx_phi[j]);
		std::cout << "Kx[" << i << "][" << j << "]=" << Kx_ij << std::endl;

		// Compute integral of product of y-derivatives
		Real Ky_ij = fe.integrate(dy_phi[i], dy_phi[j]);
		std::cout << "Ky[" << i << "][" << j << "]=" << Ky_ij << std::endl;

		// Compute integral on element r of gradient(phi_i)*gradient(phi_j),
		// i.e. dx(phi_i)*dx(phi_j) + dy(phi_i)*dy(phi_j)
		Real K_ij = Kx_ij + Ky_ij;
		std::cout << "K[" << i << "][" << j << "]=" << K_ij << std::endl;

		std::cout << std::endl;
	      }
	  }
      }
  }

  // Store final time and print elapsed time
  auto end = std::chrono::high_resolution_clock::now();
  std::cout << "Elapsed time: " <<
    std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count() <<
    " miliseconds" << std::endl;
}
开发者ID:rrgalvan,项目名称:shfem,代码行数:79,代码来源:integrate.cpp


注:本文中的TriangleMesh::read_file_msh方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。