Skip to content

I want to access node coordinate in cmesh #780

Closed

Description

@shusaku625

I'm studying how to use t8code in finite element method.
When I create matrix, I have to acces node coordinate in each element.
Please tell me how to access each node coordinate in cmesh.

Activity

  1. jmark commented on Oct 5, 2023

    @jmark
    Collaborator

    Hello @syusaku625,

    I recommend to check out this tutorial https://github.com/DLR-AMR/t8code/wiki/Step-6-Computing-stencils and associated source code https://github.com/DLR-AMR/t8code/blob/main/tutorials/general/t8_step6_stencil.cxx .

    This shows how to access information like volume, centroid, etc per element. For node coordinates there are the following functions:

    /** Compute the coordinates of a given vertex of an element if a geometry
     * for this tree is registered in the forest's cmesh.
     * \param [in]      forest     The forest.
     * \param [in]      ltree_id   The forest local id of the tree in which the element is.
     * \param [in]      element    The element.
     * \param [in]      corner_number The corner number, in Z-order, of the vertex which should be computed.
     * \param [out]     coordinates On input an allocated array to store 3 doubles, on output
     *                             the x, y and z coordinates of the vertex.
     */
    void
    t8_forest_element_coordinate (t8_forest_t forest, t8_locidx_t ltree_id, const t8_element_t *element, int corner_number,
                                  double *coordinates);
    
    /** Compute the coordinates of a point inside an element inside a tree.
     *  The point is given in reference coordinates inside the element and gets
     *  converted to reference coordinates inside the tree. After that, the point
     *  is converted to global coordinates inside the domain. If needed, the element
     *  is stretched by the given stretch factors (the resulting mesh is then 
     *  no longer non-overlapping).
     * 
     * \param [in]      forest            The forest.
     * \param [in]      ltreeid           The forest local id of the tree in which the element is.
     * \param [in]      element           The element.
     * \param [in]      ref_coord         The reference coordinates of the point inside the element.
     * \param [in]      num_coords        The number of coordinate sets in ref_coord (dimension x double).
     * \param [out]     coords_out        On input an allocated array to store 3 doubles, on output
     *                                    the x, y and z coordinates of the point inside the domain.
     * \param [in]      stretch_factors   An element-wise array with d (dimension) doubles per element, 
     *                                    which are used to stretch the element beyond its original boundary.
     *                                    The array must be of length forest->local_num_elements * d.
     *                                    If NULL, no stretching is applied.
     */
    void
    t8_forest_element_from_ref_coords (t8_forest_t forest, t8_locidx_t ltreeid, const t8_element_t *element,
                                       const double *ref_coord, const size_t num_coords, double *coords_out,
                                       sc_array_t *stretch_factors);
    

    If you are only interested in node coordinates on cmesh level then I suggest to initialize a uniform forest on your cmesh with level set to 0.

    Does this answer your question?

  2. locked and limited conversation to collaborators on Oct 5, 2023
  3. converted this issue into a discussion #781 on Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions