FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecmw_api_local_mesh.f90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
2 ! Copyright (c) 2026 FrontISTR Commons
3 ! This software is released under the MIT License, see LICENSE.txt
4 !-------------------------------------------------------------------------------
5 
7  use iso_c_binding
9  implicit none
10 
11 contains
12 
15  function hecmw_api_mesh_new() bind(C,name='hecmw_api_mesh_new')
16  use hecmw_util, only : hecmw_nullify_mesh
17  implicit none
18  type(c_ptr) :: hecmw_api_mesh_new
19  type(hecmwst_local_mesh), target, save :: hecmesh
20  call hecmw_nullify_mesh(hecmesh)
21  allocate( hecmesh%node_group%grp_index(0:0) )
22  hecmesh%node_group%grp_index(0) = 0
23  allocate( hecmesh%surf_group%grp_index(0:0) )
24  hecmesh%surf_group%grp_index(0) = 0
25  allocate( hecmesh%elem_group%grp_index(0:0) )
26  hecmesh%elem_group%grp_index(0) = 0
27  hecmw_api_mesh_new = c_loc(hecmesh)
28  end function
29 
32  subroutine hecmw_api_mesh_delete(mesh) bind(C,name='hecmw_api_mesh_delete')
34  implicit none
35  type(c_ptr), value :: mesh
36  type(hecmwst_local_mesh), pointer :: hecMESH
37  call c_f_pointer(cptr=mesh, fptr=hecmesh)
38  call hecmw_dist_free(hecmesh)
39  end subroutine
40 
45  subroutine hecmw_api_mesh_set_node(mesh,nnode,node) bind(C,name='hecmw_api_mesh_set_node')
46  implicit none
47  type(c_ptr), value :: mesh
48  integer(c_int), value, intent(in) :: nnode
49  real(c_double), intent(in) :: node(3*nnode)
50 
51  integer :: i
52  type(hecmwst_local_mesh), pointer :: hecMESH
53  call c_f_pointer(cptr=mesh, fptr=hecmesh)
54 
55  hecmesh%n_node = nnode
56  hecmesh%n_node_gross = nnode
57  hecmesh%nn_middle = nnode
58  hecmesh%nn_internal = nnode
59  allocate(hecmesh%node(3*nnode))
60  allocate(hecmesh%node_ID(2*nnode))
61  allocate(hecmesh%node_internal_list(nnode))
62  allocate(hecmesh%global_node_ID(nnode))
63 
64  do i=1, nnode
65  hecmesh%node_internal_list(i) = i
66  hecmesh%node_ID(2*i-1) = i
67  hecmesh%node_ID(2*i) = 0
68  hecmesh%global_node_ID(i) = i
69  hecmesh%node(3*i-2) = node(3*i-2)
70  hecmesh%node(3*i-1) = node(3*i-1)
71  hecmesh%node(3*i-0) = node(3*i-0)
72  enddo
73 
74  end subroutine
75 
79  function hecmw_api_mesh_n_node(mesh) bind(C,name='hecmw_api_mesh_n_node')
80  implicit none
81  type(c_ptr), value :: mesh
82  type(hecmwst_local_mesh), pointer :: hecmesh
83  integer(c_int) hecmw_api_mesh_n_node
84  call c_f_pointer(cptr=mesh, fptr=hecmesh)
85  hecmw_api_mesh_n_node = hecmesh%n_node
86  end function
87 
92  function hecmw_api_mesh_get_node(mesh) bind(C,name='hecmw_api_mesh_get_node')
93  implicit none
94  type(c_ptr), value :: mesh
95  type(hecmwst_local_mesh), pointer :: hecmesh
96  type(c_ptr) :: hecmw_api_mesh_get_node
97  call c_f_pointer(cptr=mesh, fptr=hecmesh)
98  hecmw_api_mesh_get_node = c_loc(hecmesh%node)
99  end function
100 
104  subroutine hecmw_api_mesh_set_n_dof(mesh,ndof) bind(C,name='hecmw_api_mesh_set_n_dof')
105  implicit none
106  type(c_ptr), value :: mesh
107  integer(c_int), value, intent(in) :: ndof
108  type(hecmwst_local_mesh), pointer :: hecMESH
109  call c_f_pointer(cptr=mesh, fptr=hecmesh)
110  hecmesh%n_dof = ndof
111  end subroutine
112 
116  function hecmw_api_mesh_get_n_dof(mesh) bind(C,name='hecmw_api_mesh_get_n_dof')
117  implicit none
118  type(c_ptr), value :: mesh
119  type(hecmwst_local_mesh), pointer :: hecmesh
120  integer(c_int) :: hecmw_api_mesh_get_n_dof
121  call c_f_pointer(cptr=mesh, fptr=hecmesh)
122  hecmw_api_mesh_get_n_dof = hecmesh%n_dof
123  end function
124 
131  subroutine hecmw_api_mesh_set_element(mesh,nelem,elemtype,element,sectionID) bind(C,name='hecmw_api_mesh_set_element')
132  use hecmw_etype, only : hecmw_get_max_node
133  implicit none
134  type(c_ptr), value :: mesh
135  integer(c_int), value, intent(in) :: nelem
136  integer(c_int), intent(in) :: element(*)
137  integer(c_int), intent(in) :: elemtype(nelem)
138  integer(c_int), intent(in) :: sectionID(nelem)
139 
140  type(hecmwst_local_mesh), pointer :: hecMESH
141  integer :: i, j, ncon, n, ii, jj, off
142  integer, parameter :: etypes(35) = [ &
143  111, 112, &
144  231, 232, 2322, 241, 242, &
145  301, 341, 3414, 342, 3422, 351, 352, 361, 362, 363, &
146  511, &
147  611, 612, 641, &
148  732, 733, 731, 741, 742, 743, 761, 781, &
149  881, 891, &
150  1031, 1032, 1041, 1042 &
151  ]
152  integer :: etype_counter(35)
153 
154  call c_f_pointer(cptr=mesh, fptr=hecmesh)
155 
156  hecmesh%n_elem = nelem
157  hecmesh%n_elem_gross = nelem
158  hecmesh%ne_internal = nelem
159  allocate(hecmesh%elem_internal_list(nelem))
160  allocate(hecmesh%elem_ID(2*nelem))
161  allocate(hecmesh%global_elem_ID(nelem))
162  allocate(hecmesh%elem_node_index(0:nelem))
163  allocate(hecmesh%elem_type(nelem))
164  allocate(hecmesh%section_ID(nelem))
165 
166  ! 要素の型ごとの個数を調べる
167  etype_counter(:) = 0
168  do i=1, nelem
169  do j=1, 35
170  if (elemtype(i) == etypes(j)) then
171  etype_counter(j) = etype_counter(j) + 1
172  end if
173  end do
174  end do
175  ! 存在する型は何種類あるか
176  n = 0
177  do j=1, 35
178  if (etype_counter(j) > 0) then
179  n = n + 1
180  end if
181  end do
182 
183  hecmesh%n_elem_type = n
184  allocate(hecmesh%elem_type_index(0:n))
185  allocate(hecmesh%elem_type_item(n))
186 
187  ! 型ごとに要素がいくつあるかを記録
188  i = 1
189  n = 0
190  hecmesh%elem_type_index(0) = n
191  do j=1, 35
192  if (etype_counter(j) > 0) then
193  n = n + etype_counter(j)
194  hecmesh%elem_type_item(i) = etypes(j)
195  hecmesh%elem_type_index(i) = n
196  i = i + 1
197  end if
198  end do
199 
200  ! elem_node_item の個数を調べる
201  ncon = 0
202  do i=1, nelem
203  n = hecmw_get_max_node(elemtype(i))
204  ncon = ncon + n
205  end do
206  allocate(hecmesh%elem_node_item(ncon))
207 
208  ! 要素の型ごとに並び替えて代入
209  ncon = 0 ! elem_node_item のオフセット
210  hecmesh%elem_node_index(0) = ncon
211  ii = 0
212  do j=1, 35
213  if (etype_counter(j) == 0) continue
214  n = hecmw_get_max_node(etypes(j))
215  off = 0 ! 入力配列のオフセット
216  do i=1, nelem
217  if (elemtype(i)==etypes(j)) then
218  hecmesh%elem_node_item(ncon+1:ncon+n) = element(off+1:off+n)
219  ncon = ncon + n
220  ii = ii + 1
221  hecmesh%elem_node_index(ii) = ncon
222  hecmesh%elem_ID(2*ii-1) = i
223  hecmesh%elem_ID(2*ii) = 0
224  hecmesh%global_elem_ID(ii) = i
225  hecmesh%elem_internal_list(ii) = i
226  hecmesh%elem_type(ii) = elemtype(i)
227  hecmesh%section_ID(ii) = sectionid(i)
228  end if
229  off = off + hecmw_get_max_node(elemtype(i))
230  end do
231  end do
232 
233  ! n_sect を調べる
234  hecmesh%section%n_sect = 0
235  do i=1, nelem
236  if (hecmesh%section%n_sect < hecmesh%section_ID(i)) then
237  hecmesh%section%n_sect = hecmesh%section_ID(i)
238  end if
239  end do
240 
241  end subroutine
242 
246  function hecmw_api_mesh_get_elem_type(mesh) bind(C,name='hecmw_api_mesh_get_elem_type')
247  implicit none
248  type(c_ptr), value :: mesh
249  type(hecmwst_local_mesh), pointer :: hecmesh
250  type(c_ptr) :: hecmw_api_mesh_get_elem_type
251  call c_f_pointer(cptr=mesh, fptr=hecmesh)
252  hecmw_api_mesh_get_elem_type = c_loc(hecmesh%elem_type(1))
253  end function
254 
258  function hecmw_api_mesh_get_elem_node_item(mesh) bind(C,name='hecmw_api_mesh_get_elem_node_item')
259  implicit none
260  type(c_ptr), value :: mesh
261  type(hecmwst_local_mesh), pointer :: hecmesh
262  type(c_ptr) :: hecmw_api_mesh_get_elem_node_item
263  call c_f_pointer(cptr=mesh, fptr=hecmesh)
264  hecmw_api_mesh_get_elem_node_item = c_loc(hecmesh%elem_node_item(1))
265  end function
266 
270  function hecmw_api_mesh_get_section_id(mesh) bind(C,name='hecmw_api_mesh_get_section_id')
271  implicit none
272  type(c_ptr), value :: mesh
273  type(hecmwst_local_mesh), pointer :: hecmesh
274  type(c_ptr) :: hecmw_api_mesh_get_section_id
275  call c_f_pointer(cptr=mesh, fptr=hecmesh)
276  hecmw_api_mesh_get_section_id = c_loc(hecmesh%section_ID(1))
277  end function
278 
282  function hecmw_api_mesh_n_elem(mesh) bind(C,name='hecmw_api_mesh_n_elem')
283  implicit none
284  type(c_ptr), value :: mesh
285  type(hecmwst_local_mesh), pointer :: hecmesh
286  integer(c_int) hecmw_api_mesh_n_elem
287  call c_f_pointer(cptr=mesh, fptr=hecmesh)
288  hecmw_api_mesh_n_elem = hecmesh%n_elem
289  end function
290 
294  function hecmw_api_mesh_n_elem_node_item(mesh) bind(C,name='hecmw_api_mesh_n_elem_node_item')
295  implicit none
296  type(c_ptr), value :: mesh
297  type(hecmwst_local_mesh), pointer :: hecmesh
298  integer(c_int) hecmw_api_mesh_n_elem_node_item
299  call c_f_pointer(cptr=mesh, fptr=hecmesh)
300  hecmw_api_mesh_n_elem_node_item = hecmesh%elem_node_index(hecmesh%n_elem)
301  end function
302 
307  function hecmw_api_mesh_n_ngrp(mesh) bind(C,name='hecmw_api_mesh_n_ngrp')
308  implicit none
309  type(c_ptr), value :: mesh
310  type(hecmwst_local_mesh), pointer :: hecmesh
311  integer(c_int) hecmw_api_mesh_n_ngrp
312  call c_f_pointer(cptr=mesh, fptr=hecmesh)
313  hecmw_api_mesh_n_ngrp = hecmesh%node_group%n_grp
314  end function
315 
321  subroutine hecmw_api_mesh_append_ngrp(mesh,grp_name,count,list) bind(C,name='hecmw_api_mesh_append_ngrp')
322  use hecmw_api_common, only : c_f_str_copy
323  use hecmw_util, only : hecmw_name_len
324  use hecmw, only: kint
326  implicit none
327  type(c_ptr), value, intent(in) :: mesh
328  type(c_ptr), value, intent(in) :: grp_name
329  integer(c_int), value, intent(in) :: count
330  integer(c_int), intent(in) :: list(count)
331  type(hecmwst_local_mesh), pointer :: hecMESH
332  character(kind=c_char), pointer :: char_array(:) => null()
333  character(len=HECMW_NAME_LEN) :: grp_name_f
334  integer(kind=kint) :: grp_id
335 
336  call c_f_pointer(cptr=mesh, fptr=hecmesh)
337  call c_f_pointer(grp_name, char_array, [hecmw_name_len])
338  call c_f_str_copy(char_array, grp_name_f, hecmw_name_len)
339  call append_new_group(hecmesh, 'node_grp', grp_name_f, count, list, grp_id)
340  end subroutine
341 
347  subroutine hecmw_api_mesh_get_ngrp_name(mesh,i,buf,buflen) bind(C,name='hecmw_api_mesh_get_ngrp_name')
348  use hecmw_api_common, only : f_c_str_copy
349  implicit none
350  type(c_ptr), value :: mesh
351  type(hecmwst_local_mesh), pointer :: hecMESH
352  integer(c_int), value, intent(in) :: i
353  character(kind=c_char), intent(inout) :: buf(*)
354  integer(c_int), value, intent(in) :: buflen
355  call c_f_pointer(cptr=mesh, fptr=hecmesh)
356  call f_c_str_copy(hecmesh%node_group%grp_name(i),buf,buflen)
357  end subroutine
358 
364  subroutine hecmw_api_mesh_get_ngrp(mesh,i,array,count) bind(C,name='hecmw_api_mesh_get_ngrp')
365  implicit none
366  type(c_ptr), value :: mesh
367  integer(c_int), value, intent(in) :: i
368  type(c_ptr), intent(out) :: array
369  integer(c_int), intent(out) :: count
370  type(hecmwst_local_mesh), pointer :: hecMESH
371  integer :: is, ie
372 
373  call c_f_pointer(cptr=mesh, fptr=hecmesh)
374  is = hecmesh%node_group%grp_index(i-1)+1
375  ie = hecmesh%node_group%grp_index(i)
376  array = c_loc(hecmesh%node_group%grp_item(is))
377  count = ie - is + 1
378  end subroutine
379 
383  function hecmw_api_mesh_n_sgrp(mesh) bind(C,name='hecmw_api_mesh_n_sgrp')
384  implicit none
385  type(c_ptr), value :: mesh
386  type(hecmwst_local_mesh), pointer :: hecmesh
387  integer(c_int) hecmw_api_mesh_n_sgrp
388  call c_f_pointer(cptr=mesh, fptr=hecmesh)
389  hecmw_api_mesh_n_sgrp = hecmesh%surf_group%n_grp
390  end function
391 
397  subroutine hecmw_api_mesh_append_sgrp(mesh,grp_name,count,list) bind(C,name='hecmw_api_mesh_append_sgrp')
398  use hecmw_api_common, only : c_f_str_copy
399  use hecmw_util, only : hecmw_name_len
400  use hecmw, only: kint
402  implicit none
403  type(c_ptr), value, intent(in) :: mesh
404  type(c_ptr), value, intent(in) :: grp_name
405  integer(c_int), value, intent(in) :: count
406  integer(c_int), intent(in) :: list(count)
407  type(hecmwst_local_mesh), pointer :: hecMESH
408  character(kind=c_char), pointer :: char_array(:) => null()
409  character(len=HECMW_NAME_LEN) :: grp_name_f
410  integer(kind=kint) :: grp_id
411 
412  call c_f_pointer(cptr=mesh, fptr=hecmesh)
413  call c_f_pointer(grp_name, char_array, [hecmw_name_len])
414  call c_f_str_copy(char_array, grp_name_f, hecmw_name_len)
415 
416  call append_new_group(hecmesh, 'surf_grp', grp_name_f, count, list, grp_id)
417  end subroutine
418 
424  subroutine hecmw_api_mesh_get_sgrp_name(mesh,i,buf,buflen) bind(C,name='hecmw_api_mesh_get_sgrp_name')
425  use hecmw_api_common, only : f_c_str_copy
426  implicit none
427  type(c_ptr), value :: mesh
428  type(hecmwst_local_mesh), pointer :: hecMESH
429  integer(c_int), value, intent(in) :: i
430  character(kind=c_char), intent(inout) :: buf(*)
431  integer(c_int), value, intent(in) :: buflen
432  call c_f_pointer(cptr=mesh, fptr=hecmesh)
433  call c_f_pointer(cptr=mesh, fptr=hecmesh)
434  call f_c_str_copy(hecmesh%surf_group%grp_name(i),buf,buflen)
435  end subroutine
436 
442  subroutine hecmw_api_mesh_get_sgrp(mesh,i,array,count) bind(C,name='hecmw_api_mesh_get_sgrp')
443  implicit none
444  type(c_ptr), value :: mesh
445  integer(c_int), value, intent(in) :: i
446  type(c_ptr), intent(out) :: array
447  integer(c_int), intent(out) :: count
448  type(hecmwst_local_mesh), pointer :: hecMESH
449  integer :: is, ie
450 
451  call c_f_pointer(cptr=mesh, fptr=hecmesh)
452  is = hecmesh%surf_group%grp_index(i-1)+1
453  ie = hecmesh%surf_group%grp_index(i)
454  array = c_loc(hecmesh%surf_group%grp_item(is))
455  count = ie - is + 1
456  end subroutine
457 
462  function hecmw_api_mesh_n_egrp(mesh) bind(C,name='hecmw_api_mesh_n_egrp')
463  implicit none
464  type(c_ptr), value :: mesh
465  type(hecmwst_local_mesh), pointer :: hecmesh
466  integer(c_int) hecmw_api_mesh_n_egrp
467  call c_f_pointer(cptr=mesh, fptr=hecmesh)
468  hecmw_api_mesh_n_egrp = hecmesh%elem_group%n_grp
469  end function
470 
476  subroutine hecmw_api_mesh_append_egrp(mesh,grp_name,count,list) bind(C,name='hecmw_api_mesh_append_egrp')
477  use hecmw_api_common, only : c_f_str_copy
478  use hecmw_util, only : hecmw_name_len
479  use hecmw, only: kint
481  implicit none
482  type(c_ptr), value, intent(in) :: mesh
483  type(c_ptr), value, intent(in) :: grp_name
484  integer(c_int), value, intent(in) :: count
485  integer(c_int), intent(in) :: list(count)
486  type(hecmwst_local_mesh), pointer :: hecMESH
487  character(kind=c_char), pointer :: char_array(:) => null()
488  character(len=HECMW_NAME_LEN) :: grp_name_f
489  integer(kind=kint) :: grp_id
490 
491  call c_f_pointer(cptr=mesh, fptr=hecmesh)
492  call c_f_pointer(grp_name, char_array, [hecmw_name_len])
493  call c_f_str_copy(char_array, grp_name_f, hecmw_name_len)
494 
495  call append_new_group(hecmesh, 'elem_grp', grp_name_f, count, list, grp_id)
496  end subroutine
497 
503  subroutine hecmw_api_mesh_get_egrp_name(mesh,i,buf,buflen) bind(C,name='hecmw_api_mesh_get_egrp_name')
504  use hecmw_api_common, only : f_c_str_copy
505  implicit none
506  type(c_ptr), value :: mesh
507  type(hecmwst_local_mesh), pointer :: hecMESH
508  integer(c_int), value, intent(in) :: i
509  character(kind=c_char), intent(inout) :: buf(*)
510  integer(c_int), value, intent(in) :: buflen
511  call c_f_pointer(cptr=mesh, fptr=hecmesh)
512  call f_c_str_copy(hecmesh%elem_group%grp_name(i),buf,buflen)
513  end subroutine
514 
520  subroutine hecmw_api_mesh_get_egrp(mesh,i,array,count) bind(C,name='hecmw_api_mesh_get_egrp')
521  implicit none
522  type(c_ptr), value :: mesh
523  integer(c_int), value, intent(in) :: i
524  type(c_ptr), intent(out) :: array
525  integer(c_int), intent(out) :: count
526  type(hecmwst_local_mesh), pointer :: hecMESH
527  integer :: is, ie
528 
529  call c_f_pointer(cptr=mesh, fptr=hecmesh)
530  is = hecmesh%elem_group%grp_index(i-1)+1
531  ie = hecmesh%elem_group%grp_index(i)
532  array = c_loc(hecmesh%elem_group%grp_item(is))
533  count = ie - is + 1
534  end subroutine
535 
536 end module
subroutine f_c_str_copy(f_str, c_str, c_len)
subroutine c_f_str_copy(c_str, f_str, f_len)
subroutine hecmw_api_mesh_append_ngrp(mesh, grp_name, count, list)
節点グループを追加
subroutine hecmw_api_mesh_append_egrp(mesh, grp_name, count, list)
要素グループを追加
integer(c_int) function hecmw_api_mesh_n_sgrp(mesh)
面グループのグループ数
subroutine hecmw_api_mesh_append_sgrp(mesh, grp_name, count, list)
面グループを追加
subroutine hecmw_api_mesh_get_ngrp(mesh, i, array, count)
節点グループの節点番号の配列
subroutine hecmw_api_mesh_get_egrp_name(mesh, i, buf, buflen)
要素グループの名前
type(c_ptr) function hecmw_api_mesh_get_elem_type(mesh)
要素型の取得
subroutine hecmw_api_mesh_get_sgrp(mesh, i, array, count)
面グループの要素番号、面番号の配列
subroutine hecmw_api_mesh_get_ngrp_name(mesh, i, buf, buflen)
節点グループの名前
subroutine hecmw_api_mesh_set_n_dof(mesh, ndof)
節点自由度の設定
type(c_ptr) function hecmw_api_mesh_get_section_id(mesh)
セクション番号配列の取得
subroutine hecmw_api_mesh_get_egrp(mesh, i, array, count)
要素グループの要素番号の配列
type(c_ptr) function hecmw_api_mesh_get_elem_node_item(mesh)
節点テーブルの取得
integer(c_int) function hecmw_api_mesh_n_node(mesh)
節点数の取得
integer(c_int) function hecmw_api_mesh_n_elem(mesh)
要素数の取得
subroutine hecmw_api_mesh_set_element(mesh, nelem, elemtype, element, sectionID)
要素の設定
integer(c_int) function hecmw_api_mesh_n_egrp(mesh)
要素グループのグループ数
subroutine hecmw_api_mesh_delete(mesh)
メッシュハンドラの破棄
type(c_ptr) function hecmw_api_mesh_get_node(mesh)
節点座標配列の取得
integer(c_int) function hecmw_api_mesh_n_elem_node_item(mesh)
要素節点配列の大きさの取得
integer(c_int) function hecmw_api_mesh_get_n_dof(mesh)
節点自由度の取得
integer(c_int) function hecmw_api_mesh_n_ngrp(mesh)
節点グループのグループ数
type(c_ptr) function hecmw_api_mesh_new()
メッシュハンドラの生成
subroutine hecmw_api_mesh_set_node(mesh, nnode, node)
節点配列の設定
subroutine hecmw_api_mesh_get_sgrp_name(mesh, i, buf, buflen)
面グループの名前
I/O and Utility.
subroutine, public hecmw_dist_free(mesh)
I/O and Utility.
integer(kind=kint) function hecmw_get_max_node(etype)
This module contains auxiliary functions in calculation setup.
subroutine append_new_group(hecMESH, grp_type_name, name, count, list, grp_id)
I/O and Utility.
Definition: hecmw_util_f.F90:7
subroutine hecmw_nullify_mesh(P)
integer(kind=kint), parameter hecmw_name_len
Definition: hecmw.f90:6