How to refine an existing triangular or tetrahedral mesh

From KratosWiki
Jump to: navigation, search

Refining a mesh of simplicial elements

The kratos provides the possibility of "easily" adapting an existing FE mesh (of simplex elements)

This possibility is provided by the two functions

Local_Refine_Tetrahedra_Mesh

Local_Refine_Triangle_Mesh

which are implemented in the KratosMeshingApplication.

The elements to be refined can be specified by setting the value of SPLIT_ELEMENT on the element.

A small example

the following Python code performs the refinement of a 3D mesh. The code selects all of the elements whose barycenter has a Z between -5 and 5, and refines them

 ###mark the elements to be splitted (if they have barycenter with z between -5 and 5)
 for elem in fluid_model_part.Elements:
   xc = 0.0
   yc = 0.0
   zc = 0.0
   for node in elem.GetNodes():
       xc += node.X
       yc += node.Y
       zc += node.Z   
   size = float(len(elem.GetNodes()))
   xc /= size
   yc /= size
   zc /= size  
   if( zc > -5  and zc < 5 ):
       elem.SetValue(SPLIT_ELEMENT,True)
 
 ###compute the nodal neighbours on the initial mesh
 number_of_avg_elems = 20
 number_of_avg_nodes = 20
 nodal_neighbour_search = FindNodalNeighboursProcess(fluid_model_part,number_of_avg_elems,number_of_avg_nodes)
 nodal_neighbour_search.Execute()
 
 ###perform the refinement
 Refine = LocalRefineTetrahedraMesh(fluid_model_part)
 refine_on_reference = False;
 interpolate_internal_variables = False;
 Refine.LocalRefineMesh(refine_on_reference,interpolate_internal_variables)    
  
 ###recompute the neighbours since they changed due to the creation of new nodes
 nodal_neighbour_search.ClearNeighbours()
 nodal_neighbour_search.Execute()
Personal tools
Categories