2929
3030! This module contains code and variables common to all the GMSH I/O routines
3131
32+ #include " fdebug.h"
3233
3334module gmsh_common
3435
36+ use iso_c_binding
37+ use fields
38+
39+ implicit none
40+
3541 character (len= 3 ), parameter :: GMSHVersionStr = " 2.1"
3642 integer , parameter :: asciiFormat = 0
3743 integer , parameter :: binaryFormat = 1
@@ -58,6 +64,151 @@ module gmsh_common
5864 integer , pointer :: tags(:), nodeIDs(:)
5965 end type GMSHelement
6066
67+ interface
68+ subroutine cgmsh_initialise () bind(c)
69+ end subroutine cgmsh_initialise
70+ end interface
71+
72+ interface
73+ subroutine cgmsh_finalise (gmodel ) bind(c)
74+ use iso_c_binding
75+ type (c_ptr) :: gmodel
76+ end subroutine cgmsh_finalise
77+ end interface
78+
79+ interface
80+ subroutine cread_gmsh_file (gmodel , filename ) bind(c)
81+ use iso_c_binding
82+ type (c_ptr) :: gmodel
83+ character (c_char) :: filename(* )
84+ end subroutine cread_gmsh_file
85+ end interface
86+
87+ interface
88+ subroutine cmesh_gmsh_file (gmodel , view_name ) bind(c)
89+ use iso_c_binding
90+ type (c_ptr) :: gmodel
91+ character (c_char) :: view_name(* )
92+ end subroutine cmesh_gmsh_file
93+ end interface
94+
95+ interface
96+ subroutine cread_gmsh_sizes (gmodel , numNodes , numFaces , numElements ,&
97+ haveRegionIDs , haveBounds , haveElementOwners , &
98+ haveColumns , dim , loc , sloc ) bind(c)
99+ use iso_c_binding
100+ type (c_ptr) :: gmodel
101+ integer (c_int) :: numNodes, numFaces, numElements, dim, loc, sloc
102+ logical (c_bool) :: haveRegionIDs, haveBounds, &
103+ haveElementOwners, haveColumns
104+ end subroutine cread_gmsh_sizes
105+ end interface
106+
107+ interface
108+ subroutine cread_gmsh_element_connectivity (gmodel , numElements , loc ,&
109+ ndglno , regionIDs ) bind(c)
110+ use iso_c_binding
111+ type (c_ptr) :: gmodel
112+ integer (c_int) :: numElements, loc
113+ integer (c_int) :: ndglno(numElements* loc), regionIDs(numElements)
114+ end subroutine cread_gmsh_element_connectivity
115+ end interface
116+
117+ interface
118+ subroutine cread_gmsh_points (gmodel , dim , numNodes , val ) bind(c)
119+ use iso_c_binding
120+ type (c_ptr) :: gmodel
121+ integer (c_int) :: dim, numNodes
122+ real (c_double) :: val(* )
123+ end subroutine cread_gmsh_points
124+ end interface
125+
126+ interface
127+ subroutine cread_gmsh_face_connectivity (gmodel , numFaces , &
128+ sloc , sndglno , &
129+ haveBounds , boundaryIDs , &
130+ haveElementOwners , faceOwner ) bind(c)
131+ use iso_c_binding
132+ type (c_ptr) :: gmodel
133+ integer (c_int) :: numFaces, sloc
134+ logical (c_bool) :: haveBounds, haveElementOwners
135+ integer (c_int) :: sndglno(* ), boundaryIDs(* ), faceOwner(* )
136+ end subroutine cread_gmsh_face_connectivity
137+ end interface
138+
139+ interface
140+ function cgmsh_count_physical_names (gm , dim ) bind(c)
141+ use iso_c_binding
142+ type (c_ptr), intent (in ) :: gm
143+ integer (c_int) :: dim
144+ integer (c_int) :: cgmsh_count_physical_names
145+ end function cgmsh_count_physical_names
146+ end interface
147+
148+ interface
149+ function cget_gmsh_physical_name (gm , it , dim , idx , c_string ) bind(c)
150+ use iso_c_binding
151+ type (c_ptr), intent (in ) :: gm
152+ type (c_ptr), intent (inout ) :: it
153+ integer (c_int) :: dim, idx
154+ type (c_ptr), intent (out ) :: c_string
155+ logical (c_bool) :: cget_gmsh_physical_name
156+ end function cget_gmsh_physical_name
157+ end interface
158+
159+ interface
160+ subroutine cread_gmsh_node_data (gmodel , name , data , step ) bind(c)
161+ use iso_c_binding
162+ type (c_ptr), intent (in ) :: gmodel
163+ character (c_char), intent (in ) :: name (* )
164+ real (c_double), intent (out ) :: data (* )
165+ integer (c_int), intent (in ) :: step
166+ end subroutine cread_gmsh_node_data
167+ end interface
168+
169+ interface
170+ subroutine cmesh_to_gmodel (gmodel , numNodes ,&
171+ numElements , numFaces , loc , sloc , gdim , pdim , val ,&
172+ etype , eles , ftype , faces , ele_ids , face_ids , ele_owners ) bind(c)
173+ use iso_c_binding
174+ type (c_ptr) :: gmodel
175+ integer (c_int) :: numNodes, numElements, numFaces,&
176+ loc, sloc, gdim, pdim, etype, ftype
177+ real (c_double) :: val(gdim* numNodes)
178+ integer (c_int) :: eles(numElements* loc), faces(numFaces* sloc)
179+ type (c_ptr), value :: ele_ids, face_ids, ele_owners
180+ end subroutine cmesh_to_gmodel
181+ end interface
182+
183+ interface
184+ subroutine cwrite_gmsh_file (gmodel , binary , filename ) bind(c)
185+ use iso_c_binding
186+ type (c_ptr) :: gmodel
187+ logical (c_bool) :: binary
188+ character (c_char) :: filename(* )
189+ end subroutine cwrite_gmsh_file
190+ end interface
191+
192+ interface
193+ subroutine cdata_to_pview_node_data (gm , pvdata , &
194+ numNodes , data , &
195+ name , numComponents ) bind(c)
196+ use iso_c_binding
197+ type (c_ptr) :: gm, pvdata
198+ integer (c_int) :: numNodes, numComponents
199+ real (c_double) :: data (* )
200+ character (c_char) :: name (* )
201+ end subroutine cdata_to_pview_node_data
202+ end interface
203+
204+ interface
205+ subroutine cwrite_gmsh_data_file (pvdata , binary , filename ) bind(c)
206+ use iso_c_binding
207+ type (c_ptr) :: pvdata
208+ logical (c_bool) :: binary
209+ character (c_char) :: filename(* )
210+ end subroutine cwrite_gmsh_data_file
211+ end interface
61212
62213contains
63214
@@ -128,7 +279,7 @@ end subroutine binary_formatting
128279 subroutine toFluidityElementNodeOrdering ( oldList , elemType )
129280 integer , pointer :: oldList(:)
130281 integer , dimension (size (oldList)) :: nodeOrder, flNodeList
131- integer i, elemType
282+ integer i, elemType, numNodes
132283
133284 numNodes = size (oldList)
134285
@@ -162,7 +313,7 @@ end subroutine toFluidityElementNodeOrdering
162313 subroutine toGMSHElementNodeOrdering ( oldList , elemType )
163314 integer , pointer :: oldList(:)
164315 integer , dimension (size (oldList)) :: nodeOrder, gmshNodeList
165- integer i, elemType
316+ integer i, elemType, numNodes
166317
167318 numNodes = size (oldList)
168319
@@ -206,4 +357,117 @@ subroutine deallocateElementList( elements )
206357
207358 end subroutine deallocateElementList
208359
360+ #ifdef HAVE_LIBGMSH
361+
362+ subroutine position_to_gmodel (positions , gmodel )
363+ type (vector_field), intent (in ) :: positions
364+ type (c_ptr), intent (out ) :: gmodel
365+
366+ integer :: numNodes, numElements, numFaces, sloc, &
367+ loc, dim, pdim, i
368+ integer , allocatable , dimension (:) :: sndglno
369+ integer , allocatable , dimension (:), target :: owners
370+ logical needs_element_owners
371+
372+ type (c_ptr) :: bnd_ids, reg_ids, ele_owners
373+
374+ numNodes = node_count(positions)
375+ numElements = element_count(positions)
376+ numFaces = unique_surface_element_count(positions% mesh)
377+ needs_element_owners = has_discontinuous_internal_boundaries(positions% mesh)
378+
379+ dim = mesh_dim(positions)
380+ pdim = size (positions% val,1 )
381+ loc = ele_loc(positions, 1 )
382+ sloc = 1
383+ if (numFaces> 0 ) sloc = face_loc(positions, 1 )
384+
385+ allocate (sndglno(numFaces* sloc))
386+ call getsndgln(positions% mesh, sndglno)
387+
388+ if (associated (positions% mesh% region_ids)) then
389+ reg_ids = c_loc(positions% mesh% region_ids(1 ))
390+ else
391+ reg_ids = c_null_ptr
392+ end if
393+ if (associated (positions% mesh% faces% boundary_ids)) then
394+ if (size (positions% mesh% faces% boundary_ids)>0 ) &
395+ bnd_ids = c_loc(positions% mesh% faces% boundary_ids(1 ))
396+ else
397+ bnd_ids = c_null_ptr
398+ end if
399+ if (needs_element_owners) then
400+ allocate (owners(numFaces))
401+ do i= 1 , numFaces
402+ owners(i) = face_ele(positions% mesh,i)
403+ end do
404+ ele_owners = c_loc(owners(1 ))
405+ else
406+ ele_owners = c_null_ptr
407+ end if
408+
409+ call cmesh_to_gmodel(gmodel, numNodes,&
410+ numElements, numFaces, loc, sloc,&
411+ dim, pdim, positions% val, &
412+ gmsh_type(loc, dim), positions% mesh% ndglno,&
413+ gmsh_type(sloc, dim-1 ), sndglno, reg_ids,&
414+ bnd_ids, ele_owners)
415+
416+ deallocate (sndglno)
417+
418+ contains
419+
420+ function gmsh_type (loc , dim )
421+
422+ integer , intent (in ) :: loc, dim
423+ integer gmsh_type
424+
425+
426+ if (loc .eq. dim+1 ) then
427+ select case (dim)
428+ case (0 )
429+ gmsh_type = 15
430+ case (1 )
431+ gmsh_type = 1
432+ case (2 )
433+ gmsh_type = 2
434+ case (3 )
435+ gmsh_type = 4
436+ end select
437+ else
438+ select case (dim)
439+ case (2 )
440+ gmsh_type = 3
441+ case (3 )
442+ gmsh_type = 5
443+ end select
444+ end if
445+
446+ end function gmsh_type
447+
448+ end subroutine position_to_gmodel
449+
450+ subroutine tensor_field_to_pview (gmodel , tfield )
451+ type (c_ptr) :: gmodel
452+ type (tensor_field) :: tfield
453+
454+ type (c_ptr) :: pvdata
455+
456+ real , dimension (3 ,3 ,node_count(tfield)) :: data
457+ integer :: dim
458+
459+ data = 0
460+ data (1 ,1 ,:)= 1.0
461+ data (2 ,2 ,:)= 1.0
462+ data (3 ,3 ,:)= 1.0
463+ dim = size (tfield% val,1 )
464+ data (1 :dim,1 :dim,:) = tfield% val
465+
466+ call cdata_to_pview_node_data(gmodel, pvdata, &
467+ node_count(tfield), data , trim (tfield% name)// c_null_char,9 )
468+
469+ end subroutine tensor_field_to_pview
470+
471+ #endif
472+
209473end module gmsh_common
0 commit comments