Skip to content
Snippets Groups Projects
Select Git revision
  • 060734c4c96669a6609db2aa7f7aaf9e346b8bb7
  • master default protected
  • dof-renumbering
  • gdemesy-master-patch-30528
  • eval-space-time
  • oscillating_multiharm
  • MH_movement
  • axisqu
  • write_vtu_and_ensight_formats
  • movingband
  • CP_1972_add_vtu_file_writing
  • mortar
  • fast_freq_sweep_Resolution
  • applyresolvent_again
  • marteaua-master-patch-54323
  • patch-1
  • binde-master-patch-08072
  • binde-master-patch-52461
  • BCGSL
  • resolvent
  • TreeElementsOf
  • getdp_3_5_0
  • getdp_3_4_0
  • getdp_3_3_0
  • getdp_3_2_0
  • getdp_3_1_0
  • getdp_3_0_4
  • getdp_3_0_3
  • getdp_3_0_2
  • getdp_3_0_1
  • getdp_3_0_0
  • onelab_mobile_2.1.0
  • getdp_2_11_3 protected
  • getdp_2_11_2 protected
  • getdp_2_11_1 protected
  • getdp_2_11_0 protected
  • getdp_2_10_0 protected
  • getdp_2_9_2 protected
  • getdp_2_9_1 protected
  • getdp_2_9_0 protected
  • getdp_2_8_0 protected
41 results

DofData.cpp

Blame
  • x6.cpp 3.66 KiB
    // -----------------------------------------------------------------------------
    //
    //  Gmsh C++ extended tutorial 6
    //
    //  Additional mesh data: integration points, Jacobians and basis functions
    //
    // -----------------------------------------------------------------------------
    
    #include <iostream>
    #include <gmsh.h>
    
    int main(int argc, char **argv)
    {
      gmsh::initialize(argc, argv);
      gmsh::model::add("x6");
    
      // The API provides access to all the elementary building blocks required to
      // implement finite-element-type numerical methods. Let's create a simple 2D
      // model and mesh it:
      gmsh::model::occ::addRectangle(0, 0, 0, 1, 0.1);
      gmsh::model::occ::synchronize();
      gmsh::model::mesh::setTransfiniteAutomatic();
      gmsh::model::mesh::generate(2);
    
      // Set the element order and the desired interpolation order:
      int elementOrder = 1, interpolationOrder = 2;
      gmsh::model::mesh::setOrder(elementOrder);
    
      auto pp = [](const std::string &label, const std::vector<double> &v, int mult)
      {
        std::cout << " * " << v.size() / mult << " " << label << ": ";
        for(auto c : v) std::cout << c << " ";
        std::cout << "\n";
      };
    
      // Iterate over all the element types present in the mesh:
      std::vector<int> elementTypes;
      gmsh::model::mesh::getElementTypes(elementTypes);
      for(auto t : elementTypes) {
        // Retrieve properties for the given element type
        std::string elementName;
        int dim, order, numNodes, numPrimNodes;
        std::vector<double> localNodeCoord;
        gmsh::model::mesh::getElementProperties
          (t, elementName, dim, order, numNodes, localNodeCoord, numPrimNodes);
        std::cout << "\n** " << elementName << " **\n\n";
    
        // Retrieve integration points for that element type, enabling exact
        // integration of polynomials of order "interpolationOrder". The "Gauss"
        // integration family returns the "economical" Gauss points if available,
        // and defaults to the "CompositeGauss" (tensor product) rule if not.
        std::vector<double> localCoords, weights;
        gmsh::model::mesh::getIntegrationPoints
          (t, "Gauss" + std::to_string(interpolationOrder), localCoords, weights);
        pp("integration points to integrate order " +
           std::to_string(interpolationOrder) + " polynomials", localCoords, 3);
    
        // Return the basis functions evaluated at the integration points. Selecting
        // "Lagrange" and "GradLagrange" returns the isoparamtric basis functions
        // and their gradient (in the reference space of the given element type). A
        // specific interpolation order can be requested using "LagrangeN" and
        // "GradLagrangeN" with N = 1, 2, ... Other supported function spaces
        // include "H1LegendreN", "GradH1LegendreN", "HcurlLegendreN",
        // "CurlHcurlLegendreN".
        int numComponents, numOrientations;
        std::vector<double> basisFunctions;
        gmsh::model::mesh::getBasisFunctions
          (t, localCoords, "Lagrange", numComponents, basisFunctions,
           numOrientations);
        pp("basis functions at integration points", basisFunctions, 1);
        gmsh::model::mesh::getBasisFunctions
          (t, localCoords, "GradLagrange", numComponents, basisFunctions,
           numOrientations);
        pp("basis function gradients at integration points", basisFunctions, 3);
    
        // Compute the Jacobians (and their determinants) at the integration points
        // for all the elements of the given type in the mesh. Beware that the
        // Jacobians are returned "by column": see the API documentation for
        // details.
        std::vector<double> jacobians, determinants, coords;
        gmsh::model::mesh::getJacobians
          (t, localCoords, jacobians, determinants, coords);
        pp("Jacobian determinants at integration points", determinants, 1);
      }
    
      gmsh::finalize();
      return 0;
    }