diff --git a/src/h5core/h5t_store.c b/src/h5core/h5t_store.c index 39f77b7..594d255 100644 --- a/src/h5core/h5t_store.c +++ b/src/h5core/h5t_store.c @@ -296,55 +296,6 @@ h5t_mark_entity ( H5_CORE_API_RETURN (h5priv_insert_idlist (&t->marked_entities, entity_id, -1)); } -/* - When calling this function, we know the number of elements to refine. But - we don't now the number of new vertices we will get. We have to compute - this number or just to guess it. - - Let n be the number of elements to refine and l the number of disconnected - areas to be refined. - - For triangle grids the upper limit of new vertices is 3n and the lower limit - 2n + 1. The exact number is 2n + l. - - For tetrahedral grids the upper limit is 6n and the lower limit is 3n+3. - The exact number is 3n + 3l. - - To get the real number of vertices to add, we either have to compute the - number of disconnected areas (which is quiet expensive), try to guess it - (which is impossible) or just set a limit. In most cases the number of - disconnected areas will be "small". - - For the time being we set the maximum number of disconnected areas to 64. - */ -h5_err_t -h5t_pre_refine ( - h5_file_t* const f - ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* const t = f->t; - unsigned int num_elems_to_refine = t->marked_entities->num_items; - unsigned int num_elems_to_add = 0; - unsigned int num_vertices_to_add = 0; - - switch (t->mesh_type) { - case H5_OID_TETRAHEDRON: - num_vertices_to_add = num_elems_to_refine*3 + 192; - num_elems_to_add = num_elems_to_refine*8; - break; - case H5_OID_TRIANGLE: - num_vertices_to_add = num_elems_to_refine*2 + 64; - num_elems_to_add = num_elems_to_refine*4; - break; - default: - H5_CORE_API_LEAVE (h5_error_internal ()); - } - TRY (h5t_begin_store_vertices (f, num_vertices_to_add)); - TRY (h5t_begin_store_elems (f, num_elems_to_add)); - - H5_CORE_API_RETURN (H5_SUCCESS); -} - /* Refine previously marked elements. */ @@ -372,7 +323,6 @@ h5t_post_refine ( H5_CORE_API_RETURN (h5priv_free_idlist (&t->marked_entities)); } - h5_err_t h5t_begin_refine_elems ( h5_file_t* const f @@ -388,7 +338,6 @@ h5t_begin_refine_elems ( H5_CORE_API_RETURN (H5_SUCCESS); } - h5_err_t h5t_end_refine_elems ( h5_file_t* const f diff --git a/src/h5core/h5t_store_private.h b/src/h5core/h5t_store_private.h index cabf254..a86547b 100644 --- a/src/h5core/h5t_store_private.h +++ b/src/h5core/h5t_store_private.h @@ -3,6 +3,7 @@ struct h5t_store_methods { h5_err_t (*alloc_elems)(h5_file_t* const, const size_t, const size_t); + h5_err_t (*pre_refine)(h5_file_t* const); h5_loc_idx_t (*refine_elem)(h5_file_t* const, const h5_loc_idx_t); h5_err_t (*end_store_elems)(h5_file_t* const); h5_err_t (*get_direct_children_of_edge)( @@ -33,6 +34,13 @@ h5tpriv_alloc_elems ( return (*f->t->methods.store->alloc_elems) (f, cur, new); } +static inline h5_err_t +h5tpriv_pre_refine ( + h5_file_t* const f + ) { + return f->t->methods.store->pre_refine (f); +} + static inline h5_loc_idx_t h5tpriv_refine_elem ( h5_file_t * const f, diff --git a/src/h5core/h5t_store_tetm.c b/src/h5core/h5t_store_tetm.c index 2d47329..a5b28de 100644 --- a/src/h5core/h5t_store_tetm.c +++ b/src/h5core/h5t_store_tetm.c @@ -127,6 +127,38 @@ bisect_edge ( H5_PRIV_FUNC_RETURN (h5t_store_vertex (f, -1, P)); // return idx of new vertex } +/* + When calling this function, we know the number of elements to refine. But + we don't now the number of new vertices we will get. We have to compute + this number or just to guess it. + + Let n be the number of elements to refine and l the number of disconnected + areas to be refined. + + For triangle grids the upper limit of new vertices is 3n and the lower limit + 2n + 1. The exact number is 2n + l. + + For tetrahedral grids the upper limit is 6n and the lower limit is 3n+3. + The exact number is 3n + 3l. + + To get the real number of vertices to add, we either have to compute the + number of disconnected areas (which is quiet expensive), try to guess it + (which is impossible) or just set a limit. In most cases the number of + disconnected areas will be "small". + + For the time being we set the maximum number of disconnected areas to 64. + */ +static h5_err_t +pre_refine_tet ( + h5_file_t* const f + ) { + H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); + unsigned int num_elems_to_refine = f->t->marked_entities->num_items; + TRY (h5t_begin_store_vertices (f, num_elems_to_refine*3 + 192)); + TRY (h5t_begin_store_elems (f, num_elems_to_refine*8)); + H5_CORE_API_RETURN (H5_SUCCESS); +} + /*! Refine tetrahedron \c elem_idx @@ -311,6 +343,7 @@ end_store_elems ( struct h5t_store_methods h5tpriv_tetm_store_methods = { alloc_tets, + pre_refine_tet, refine_tet, end_store_elems, get_direct_children_of_edge diff --git a/src/h5core/h5t_store_trim.c b/src/h5core/h5t_store_trim.c index dabe972..62c5ff8 100644 --- a/src/h5core/h5t_store_trim.c +++ b/src/h5core/h5t_store_trim.c @@ -120,6 +120,21 @@ bisect_edge ( H5_PRIV_FUNC_RETURN (h5t_store_vertex (f, -1, P)); } +/* + Please read note about number of new vertices in tetrahedral + mesh implementation. + */ +static h5_err_t +pre_refine_triangle ( + h5_file_t* const f + ) { + H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); + unsigned int num_elems_to_refine = f->t->marked_entities->num_items; + TRY (h5t_begin_store_vertices (f, num_elems_to_refine*2 + 64)); + TRY (h5t_begin_store_elems (f, num_elems_to_refine*4)); + H5_CORE_API_RETURN (H5_SUCCESS); +} + /*! Refine triangle \c local_eid @@ -271,6 +286,7 @@ end_store_elems ( struct h5t_store_methods h5tpriv_trim_store_methods = { alloc_triangles, + pre_refine_triangle, refine_triangle, end_store_elems, get_direct_children_of_edge