-
Notifications
You must be signed in to change notification settings - Fork 1
/
gmsh.py
6815 lines (6021 loc) · 266 KB
/
gmsh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Gmsh - Copyright (C) 1997-2020 C. Geuzaine, J.-F. Remacle
#
# See the LICENSE.txt file for license information. Please report all
# issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
# This file defines the Gmsh Python API (v4.7.0).
#
# Do not edit it directly: it is automatically generated by `api/gen.py'.
#
# By design, the Gmsh Python API is purely functional, and only uses elementary
# Python types (as well as `numpy' arrays if `numpy' is available). See
# `tutorial/python' and `demos/api' for examples.
from ctypes import *
from ctypes.util import find_library
import signal
import os
import platform
from math import pi
GMSH_API_VERSION = "4.7.0"
GMSH_API_VERSION_MAJOR = 4
GMSH_API_VERSION_MINOR = 7
GMSH_API_VERSION_PATCH = 0
__version__ = GMSH_API_VERSION
oldsig = signal.signal(signal.SIGINT, signal.SIG_DFL)
libdir = os.path.dirname(os.path.realpath(__file__))
if platform.system() == "Windows":
libpath = os.path.join(libdir, "gmsh-4.7.dll")
elif platform.system() == "Darwin":
libpath = os.path.join(libdir, "libgmsh.dylib")
else:
libpath = os.path.join(libdir, "libgmsh.so")
if not os.path.exists(libpath):
libpath = find_library("gmsh")
lib = CDLL(libpath)
use_numpy = False
try:
import numpy
try:
from weakref import finalize as weakreffinalize
except:
from backports.weakref import finalize as weakreffinalize
use_numpy = True
except:
pass
# Utility functions, not part of the Gmsh Python API
def _ostring(s):
sp = s.value.decode("utf-8")
lib.gmshFree(s)
return sp
def _ovectorpair(ptr, size):
v = list((ptr[i * 2], ptr[i * 2 + 1]) for i in range(size//2))
lib.gmshFree(ptr)
return v
def _ovectorint(ptr, size):
if use_numpy:
if size == 0 :
lib.gmshFree(ptr)
return numpy.ndarray((0,),numpy.int32)
v = numpy.ctypeslib.as_array(ptr, (size, ))
weakreffinalize(v, lib.gmshFree, ptr)
else:
v = list(ptr[i] for i in range(size))
lib.gmshFree(ptr)
return v
def _ovectorsize(ptr, size):
if use_numpy:
if size == 0 :
lib.gmshFree(ptr)
return numpy.ndarray((0,),numpy.uintp)
v = numpy.ctypeslib.as_array(ptr, (size, ))
weakreffinalize(v, lib.gmshFree, ptr)
else:
v = list(ptr[i] for i in range(size))
lib.gmshFree(ptr)
return v
def _ovectordouble(ptr, size):
if use_numpy:
if size == 0 :
lib.gmshFree(ptr)
return numpy.ndarray((0,),numpy.float64)
v = numpy.ctypeslib.as_array(ptr, (size, ))
weakreffinalize(v, lib.gmshFree, ptr)
else:
v = list(ptr[i] for i in range(size))
lib.gmshFree(ptr)
return v
def _ovectorstring(ptr, size):
v = list(_ostring(cast(ptr[i], c_char_p)) for i in range(size))
lib.gmshFree(ptr)
return v
def _ovectorvectorint(ptr, size, n):
v = [_ovectorint(pointer(ptr[i].contents), size[i]) for i in range(n.value)]
lib.gmshFree(size)
lib.gmshFree(ptr)
return v
def _ovectorvectorsize(ptr, size, n):
v = [_ovectorsize(pointer(ptr[i].contents), size[i]) for i in range(n.value)]
lib.gmshFree(size)
lib.gmshFree(ptr)
return v
def _ovectorvectordouble(ptr, size, n):
v = [_ovectordouble(pointer(ptr[i].contents), size[i]) for i in range(n.value)]
lib.gmshFree(size)
lib.gmshFree(ptr)
return v
def _ovectorvectorpair(ptr, size, n):
v = [_ovectorpair(pointer(ptr[i].contents), size[i]) for i in range(n.value)]
lib.gmshFree(size)
lib.gmshFree(ptr)
return v
def _ivectorint(o):
if use_numpy:
array = numpy.ascontiguousarray(o, numpy.int32)
if(len(o) and array.ndim != 1):
raise Exception("Invalid data for input vector of integers")
ct = array.ctypes
ct.array = array
return ct, c_size_t(len(o))
else:
return (c_int * len(o))(*o), c_size_t(len(o))
def _ivectorsize(o):
if use_numpy:
array = numpy.ascontiguousarray(o, numpy.uintp)
if(len(o) and array.ndim != 1):
raise Exception("Invalid data for input vector of sizes")
ct = array.ctypes
ct.array = array
return ct, c_size_t(len(o))
else:
return (c_size_t * len(o))(*o), c_size_t(len(o))
def _ivectordouble(o):
if use_numpy:
array = numpy.ascontiguousarray(o, numpy.float64)
if(len(o) and array.ndim != 1):
raise Exception("Invalid data for input vector of doubles")
ct = array.ctypes
ct.array = array
return ct, c_size_t(len(o))
else:
return (c_double * len(o))(*o), c_size_t(len(o))
def _ivectorpair(o):
if use_numpy:
array = numpy.ascontiguousarray(o, numpy.int32)
if(len(o) and (array.ndim != 2 or array.shape[1] != 2)):
raise Exception("Invalid data for input vector of pairs")
ct = array.ctypes
ct.array = array
return ct, c_size_t(len(o) * 2)
else:
if(len(o) and len(o[0]) != 2):
raise Exception("Invalid data for input vector of pairs")
return ((c_int * 2) * len(o))(*o), c_size_t(len(o) * 2)
def _ivectorstring(o):
return (c_char_p * len(o))(*(s.encode() for s in o)), c_size_t(len(o))
def _ivectorvectorint(os):
n = len(os)
parrays = [_ivectorint(o) for o in os]
sizes = (c_size_t * n)(*(a[1] for a in parrays))
arrays = (POINTER(c_int) * n)(*(cast(a[0], POINTER(c_int)) for a in parrays))
arrays.ref = [a[0] for a in parrays]
size = c_size_t(n)
return arrays, sizes, size
def _ivectorvectorsize(os):
n = len(os)
parrays = [_ivectorsize(o) for o in os]
sizes = (c_size_t * n)(*(a[1] for a in parrays))
arrays = (POINTER(c_size_t) * n)(*(cast(a[0], POINTER(c_size_t)) for a in parrays))
arrays.ref = [a[0] for a in parrays]
size = c_size_t(n)
return arrays, sizes, size
def _ivectorvectordouble(os):
n = len(os)
parrays = [_ivectordouble(o) for o in os]
sizes = (c_size_t * n)(*(a[1] for a in parrays))
arrays = (POINTER(c_double) * n)(*(cast(a[0], POINTER(c_double)) for a in parrays))
arrays.ref = [a[0] for a in parrays]
size = c_size_t(n)
return arrays, sizes, size
def _iargcargv(o):
return c_int(len(o)), (c_char_p * len(o))(*(s.encode() for s in o))
# Gmsh Python API begins here
def initialize(argv=[], readConfigFiles=True):
"""
gmsh.initialize(argv=[], readConfigFiles=True)
Initialize Gmsh API. This must be called before any call to the other
functions in the API. If `argc' and `argv' (or just `argv' in Python or
Julia) are provided, they will be handled in the same way as the command
line arguments in the Gmsh app. If `readConfigFiles' is set, read system
Gmsh configuration files (gmshrc and gmsh-options). Initializing the API
sets the options "General.Terminal" to 1 and "General.AbortOnError" to 2.
"""
api_argc_, api_argv_ = _iargcargv(argv)
ierr = c_int()
lib.gmshInitialize(
api_argc_, api_argv_,
c_int(bool(readConfigFiles)),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
def finalize():
"""
gmsh.finalize()
Finalize the Gmsh API. This must be called when you are done using the Gmsh
API.
"""
ierr = c_int()
lib.gmshFinalize(
byref(ierr))
if oldsig is not None:
signal.signal(signal.SIGINT, oldsig)
if ierr.value != 0:
raise Exception(logger.getLastError())
def open(fileName):
"""
gmsh.open(fileName)
Open a file. Equivalent to the `File->Open' menu in the Gmsh app. Handling
of the file depends on its extension and/or its contents: opening a file
with model data will create a new model.
"""
ierr = c_int()
lib.gmshOpen(
c_char_p(fileName.encode()),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
def merge(fileName):
"""
gmsh.merge(fileName)
Merge a file. Equivalent to the `File->Merge' menu in the Gmsh app.
Handling of the file depends on its extension and/or its contents. Merging
a file with model data will add the data to the current model.
"""
ierr = c_int()
lib.gmshMerge(
c_char_p(fileName.encode()),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
def write(fileName):
"""
gmsh.write(fileName)
Write a file. The export format is determined by the file extension.
"""
ierr = c_int()
lib.gmshWrite(
c_char_p(fileName.encode()),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
def clear():
"""
gmsh.clear()
Clear all loaded models and post-processing data, and add a new empty
model.
"""
ierr = c_int()
lib.gmshClear(
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
class option:
"""
Option handling functions
"""
@staticmethod
def setNumber(name, value):
"""
gmsh.option.setNumber(name, value)
Set a numerical option to `value'. `name' is of the form "category.option"
or "category[num].option". Available categories and options are listed in
the Gmsh reference manual.
"""
ierr = c_int()
lib.gmshOptionSetNumber(
c_char_p(name.encode()),
c_double(value),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
@staticmethod
def getNumber(name):
"""
gmsh.option.getNumber(name)
Get the `value' of a numerical option. `name' is of the form
"category.option" or "category[num].option". Available categories and
options are listed in the Gmsh reference manual.
Return `value'.
"""
api_value_ = c_double()
ierr = c_int()
lib.gmshOptionGetNumber(
c_char_p(name.encode()),
byref(api_value_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return api_value_.value
@staticmethod
def setString(name, value):
"""
gmsh.option.setString(name, value)
Set a string option to `value'. `name' is of the form "category.option" or
"category[num].option". Available categories and options are listed in the
Gmsh reference manual.
"""
ierr = c_int()
lib.gmshOptionSetString(
c_char_p(name.encode()),
c_char_p(value.encode()),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
@staticmethod
def getString(name):
"""
gmsh.option.getString(name)
Get the `value' of a string option. `name' is of the form "category.option"
or "category[num].option". Available categories and options are listed in
the Gmsh reference manual.
Return `value'.
"""
api_value_ = c_char_p()
ierr = c_int()
lib.gmshOptionGetString(
c_char_p(name.encode()),
byref(api_value_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ostring(api_value_)
@staticmethod
def setColor(name, r, g, b, a=255):
"""
gmsh.option.setColor(name, r, g, b, a=255)
Set a color option to the RGBA value (`r', `g', `b', `a'), where where `r',
`g', `b' and `a' should be integers between 0 and 255. `name' is of the
form "category.option" or "category[num].option". Available categories and
options are listed in the Gmsh reference manual, with the "Color." middle
string removed.
"""
ierr = c_int()
lib.gmshOptionSetColor(
c_char_p(name.encode()),
c_int(r),
c_int(g),
c_int(b),
c_int(a),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
@staticmethod
def getColor(name):
"""
gmsh.option.getColor(name)
Get the `r', `g', `b', `a' value of a color option. `name' is of the form
"category.option" or "category[num].option". Available categories and
options are listed in the Gmsh reference manual, with the "Color." middle
string removed.
Return `r', `g', `b', `a'.
"""
api_r_ = c_int()
api_g_ = c_int()
api_b_ = c_int()
api_a_ = c_int()
ierr = c_int()
lib.gmshOptionGetColor(
c_char_p(name.encode()),
byref(api_r_),
byref(api_g_),
byref(api_b_),
byref(api_a_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return (
api_r_.value,
api_g_.value,
api_b_.value,
api_a_.value)
class model:
"""
Model functions
"""
@staticmethod
def add(name):
"""
gmsh.model.add(name)
Add a new model, with name `name', and set it as the current model.
"""
ierr = c_int()
lib.gmshModelAdd(
c_char_p(name.encode()),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
@staticmethod
def remove():
"""
gmsh.model.remove()
Remove the current model.
"""
ierr = c_int()
lib.gmshModelRemove(
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
@staticmethod
def list():
"""
gmsh.model.list()
List the names of all models.
Return `names'.
"""
api_names_, api_names_n_ = POINTER(POINTER(c_char))(), c_size_t()
ierr = c_int()
lib.gmshModelList(
byref(api_names_), byref(api_names_n_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ovectorstring(api_names_, api_names_n_.value)
@staticmethod
def getCurrent():
"""
gmsh.model.getCurrent()
Get the name of the current model.
Return `name'.
"""
api_name_ = c_char_p()
ierr = c_int()
lib.gmshModelGetCurrent(
byref(api_name_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ostring(api_name_)
@staticmethod
def setCurrent(name):
"""
gmsh.model.setCurrent(name)
Set the current model to the model with name `name'. If several models have
the same name, select the one that was added first.
"""
ierr = c_int()
lib.gmshModelSetCurrent(
c_char_p(name.encode()),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
@staticmethod
def getEntities(dim=-1):
"""
gmsh.model.getEntities(dim=-1)
Get all the entities in the current model. If `dim' is >= 0, return only
the entities of the specified dimension (e.g. points if `dim' == 0). The
entities are returned as a vector of (dim, tag) integer pairs.
Return `dimTags'.
"""
api_dimTags_, api_dimTags_n_ = POINTER(c_int)(), c_size_t()
ierr = c_int()
lib.gmshModelGetEntities(
byref(api_dimTags_), byref(api_dimTags_n_),
c_int(dim),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ovectorpair(api_dimTags_, api_dimTags_n_.value)
@staticmethod
def setEntityName(dim, tag, name):
"""
gmsh.model.setEntityName(dim, tag, name)
Set the name of the entity of dimension `dim' and tag `tag'.
"""
ierr = c_int()
lib.gmshModelSetEntityName(
c_int(dim),
c_int(tag),
c_char_p(name.encode()),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
@staticmethod
def getEntityName(dim, tag):
"""
gmsh.model.getEntityName(dim, tag)
Get the name of the entity of dimension `dim' and tag `tag'.
Return `name'.
"""
api_name_ = c_char_p()
ierr = c_int()
lib.gmshModelGetEntityName(
c_int(dim),
c_int(tag),
byref(api_name_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ostring(api_name_)
@staticmethod
def getPhysicalGroups(dim=-1):
"""
gmsh.model.getPhysicalGroups(dim=-1)
Get all the physical groups in the current model. If `dim' is >= 0, return
only the entities of the specified dimension (e.g. physical points if `dim'
== 0). The entities are returned as a vector of (dim, tag) integer pairs.
Return `dimTags'.
"""
api_dimTags_, api_dimTags_n_ = POINTER(c_int)(), c_size_t()
ierr = c_int()
lib.gmshModelGetPhysicalGroups(
byref(api_dimTags_), byref(api_dimTags_n_),
c_int(dim),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ovectorpair(api_dimTags_, api_dimTags_n_.value)
@staticmethod
def getEntitiesForPhysicalGroup(dim, tag):
"""
gmsh.model.getEntitiesForPhysicalGroup(dim, tag)
Get the tags of the model entities making up the physical group of
dimension `dim' and tag `tag'.
Return `tags'.
"""
api_tags_, api_tags_n_ = POINTER(c_int)(), c_size_t()
ierr = c_int()
lib.gmshModelGetEntitiesForPhysicalGroup(
c_int(dim),
c_int(tag),
byref(api_tags_), byref(api_tags_n_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ovectorint(api_tags_, api_tags_n_.value)
@staticmethod
def getPhysicalGroupsForEntity(dim, tag):
"""
gmsh.model.getPhysicalGroupsForEntity(dim, tag)
Get the tags of the physical groups (if any) to which the model entity of
dimension `dim' and tag `tag' belongs.
Return `physicalTags'.
"""
api_physicalTags_, api_physicalTags_n_ = POINTER(c_int)(), c_size_t()
ierr = c_int()
lib.gmshModelGetPhysicalGroupsForEntity(
c_int(dim),
c_int(tag),
byref(api_physicalTags_), byref(api_physicalTags_n_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ovectorint(api_physicalTags_, api_physicalTags_n_.value)
@staticmethod
def addPhysicalGroup(dim, tags, tag=-1):
"""
gmsh.model.addPhysicalGroup(dim, tags, tag=-1)
Add a physical group of dimension `dim', grouping the model entities with
tags `tags'. Return the tag of the physical group, equal to `tag' if `tag'
is positive, or a new tag if `tag' < 0.
Return an integer value.
"""
api_tags_, api_tags_n_ = _ivectorint(tags)
ierr = c_int()
api_result_ = lib.gmshModelAddPhysicalGroup(
c_int(dim),
api_tags_, api_tags_n_,
c_int(tag),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return api_result_
@staticmethod
def removePhysicalGroups(dimTags=[]):
"""
gmsh.model.removePhysicalGroups(dimTags=[])
Remove the physical groups `dimTags' from the current model. If `dimTags'
is empty, remove all groups.
"""
api_dimTags_, api_dimTags_n_ = _ivectorpair(dimTags)
ierr = c_int()
lib.gmshModelRemovePhysicalGroups(
api_dimTags_, api_dimTags_n_,
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
@staticmethod
def setPhysicalName(dim, tag, name):
"""
gmsh.model.setPhysicalName(dim, tag, name)
Set the name of the physical group of dimension `dim' and tag `tag'.
"""
ierr = c_int()
lib.gmshModelSetPhysicalName(
c_int(dim),
c_int(tag),
c_char_p(name.encode()),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
@staticmethod
def removePhysicalName(name):
"""
gmsh.model.removePhysicalName(name)
Remove the physical name `name' from the current model.
"""
ierr = c_int()
lib.gmshModelRemovePhysicalName(
c_char_p(name.encode()),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
@staticmethod
def getPhysicalName(dim, tag):
"""
gmsh.model.getPhysicalName(dim, tag)
Get the name of the physical group of dimension `dim' and tag `tag'.
Return `name'.
"""
api_name_ = c_char_p()
ierr = c_int()
lib.gmshModelGetPhysicalName(
c_int(dim),
c_int(tag),
byref(api_name_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ostring(api_name_)
@staticmethod
def getBoundary(dimTags, combined=True, oriented=True, recursive=False):
"""
gmsh.model.getBoundary(dimTags, combined=True, oriented=True, recursive=False)
Get the boundary of the model entities `dimTags'. Return in `outDimTags'
the boundary of the individual entities (if `combined' is false) or the
boundary of the combined geometrical shape formed by all input entities (if
`combined' is true). Return tags multiplied by the sign of the boundary
entity if `oriented' is true. Apply the boundary operator recursively down
to dimension 0 (i.e. to points) if `recursive' is true.
Return `outDimTags'.
"""
api_dimTags_, api_dimTags_n_ = _ivectorpair(dimTags)
api_outDimTags_, api_outDimTags_n_ = POINTER(c_int)(), c_size_t()
ierr = c_int()
lib.gmshModelGetBoundary(
api_dimTags_, api_dimTags_n_,
byref(api_outDimTags_), byref(api_outDimTags_n_),
c_int(bool(combined)),
c_int(bool(oriented)),
c_int(bool(recursive)),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
@staticmethod
def getEntitiesInBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax, dim=-1):
"""
gmsh.model.getEntitiesInBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax, dim=-1)
Get the model entities in the bounding box defined by the two points
(`xmin', `ymin', `zmin') and (`xmax', `ymax', `zmax'). If `dim' is >= 0,
return only the entities of the specified dimension (e.g. points if `dim'
== 0).
Return `tags'.
"""
api_tags_, api_tags_n_ = POINTER(c_int)(), c_size_t()
ierr = c_int()
lib.gmshModelGetEntitiesInBoundingBox(
c_double(xmin),
c_double(ymin),
c_double(zmin),
c_double(xmax),
c_double(ymax),
c_double(zmax),
byref(api_tags_), byref(api_tags_n_),
c_int(dim),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ovectorpair(api_tags_, api_tags_n_.value)
@staticmethod
def getBoundingBox(dim, tag):
"""
gmsh.model.getBoundingBox(dim, tag)
Get the bounding box (`xmin', `ymin', `zmin'), (`xmax', `ymax', `zmax') of
the model entity of dimension `dim' and tag `tag'. If `dim' and `tag' are
negative, get the bounding box of the whole model.
Return `xmin', `ymin', `zmin', `xmax', `ymax', `zmax'.
"""
api_xmin_ = c_double()
api_ymin_ = c_double()
api_zmin_ = c_double()
api_xmax_ = c_double()
api_ymax_ = c_double()
api_zmax_ = c_double()
ierr = c_int()
lib.gmshModelGetBoundingBox(
c_int(dim),
c_int(tag),
byref(api_xmin_),
byref(api_ymin_),
byref(api_zmin_),
byref(api_xmax_),
byref(api_ymax_),
byref(api_zmax_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return (
api_xmin_.value,
api_ymin_.value,
api_zmin_.value,
api_xmax_.value,
api_ymax_.value,
api_zmax_.value)
@staticmethod
def getDimension():
"""
gmsh.model.getDimension()
Get the geometrical dimension of the current model.
Return an integer value.
"""
ierr = c_int()
api_result_ = lib.gmshModelGetDimension(
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return api_result_
@staticmethod
def addDiscreteEntity(dim, tag=-1, boundary=[]):
"""
gmsh.model.addDiscreteEntity(dim, tag=-1, boundary=[])
Add a discrete model entity (defined by a mesh) of dimension `dim' in the
current model. Return the tag of the new discrete entity, equal to `tag' if
`tag' is positive, or a new tag if `tag' < 0. `boundary' specifies the tags
of the entities on the boundary of the discrete entity, if any. Specifying
`boundary' allows Gmsh to construct the topology of the overall model.
Return an integer value.
"""
api_boundary_, api_boundary_n_ = _ivectorint(boundary)
ierr = c_int()
api_result_ = lib.gmshModelAddDiscreteEntity(
c_int(dim),
c_int(tag),
api_boundary_, api_boundary_n_,
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return api_result_
@staticmethod
def removeEntities(dimTags, recursive=False):
"""
gmsh.model.removeEntities(dimTags, recursive=False)
Remove the entities `dimTags' of the current model. If `recursive' is true,
remove all the entities on their boundaries, down to dimension 0.
"""
api_dimTags_, api_dimTags_n_ = _ivectorpair(dimTags)
ierr = c_int()
lib.gmshModelRemoveEntities(
api_dimTags_, api_dimTags_n_,
c_int(bool(recursive)),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
@staticmethod
def removeEntityName(name):
"""
gmsh.model.removeEntityName(name)
Remove the entity name `name' from the current model.
"""
ierr = c_int()
lib.gmshModelRemoveEntityName(
c_char_p(name.encode()),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
@staticmethod
def getType(dim, tag):
"""
gmsh.model.getType(dim, tag)
Get the type of the entity of dimension `dim' and tag `tag'.
Return `entityType'.
"""
api_entityType_ = c_char_p()
ierr = c_int()
lib.gmshModelGetType(
c_int(dim),
c_int(tag),
byref(api_entityType_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ostring(api_entityType_)
@staticmethod
def getParent(dim, tag):
"""
gmsh.model.getParent(dim, tag)
In a partitioned model, get the parent of the entity of dimension `dim' and
tag `tag', i.e. from which the entity is a part of, if any. `parentDim' and
`parentTag' are set to -1 if the entity has no parent.
Return `parentDim', `parentTag'.
"""
api_parentDim_ = c_int()
api_parentTag_ = c_int()
ierr = c_int()
lib.gmshModelGetParent(
c_int(dim),
c_int(tag),
byref(api_parentDim_),
byref(api_parentTag_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return (
api_parentDim_.value,
api_parentTag_.value)
@staticmethod
def getPartitions(dim, tag):
"""
gmsh.model.getPartitions(dim, tag)
In a partitioned model, return the tags of the partition(s) to which the
entity belongs.
Return `partitions'.
"""
api_partitions_, api_partitions_n_ = POINTER(c_int)(), c_size_t()
ierr = c_int()
lib.gmshModelGetPartitions(
c_int(dim),
c_int(tag),
byref(api_partitions_), byref(api_partitions_n_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ovectorint(api_partitions_, api_partitions_n_.value)
@staticmethod
def getValue(dim, tag, parametricCoord):
"""
gmsh.model.getValue(dim, tag, parametricCoord)
Evaluate the parametrization of the entity of dimension `dim' and tag `tag'
at the parametric coordinates `parametricCoord'. Only valid for `dim' equal
to 0 (with empty `parametricCoord'), 1 (with `parametricCoord' containing
parametric coordinates on the curve) or 2 (with `parametricCoord'
containing pairs of u, v parametric coordinates on the surface,
concatenated: [p1u, p1v, p2u, ...]). Return triplets of x, y, z coordinates
in `coord', concatenated: [p1x, p1y, p1z, p2x, ...].
Return `coord'.
"""
api_parametricCoord_, api_parametricCoord_n_ = _ivectordouble(parametricCoord)
api_coord_, api_coord_n_ = POINTER(c_double)(), c_size_t()
ierr = c_int()
lib.gmshModelGetValue(
c_int(dim),
c_int(tag),
api_parametricCoord_, api_parametricCoord_n_,
byref(api_coord_), byref(api_coord_n_),
byref(ierr))
if ierr.value != 0:
raise Exception(logger.getLastError())
return _ovectordouble(api_coord_, api_coord_n_.value)
@staticmethod
def getDerivative(dim, tag, parametricCoord):
"""
gmsh.model.getDerivative(dim, tag, parametricCoord)
Evaluate the derivative of the parametrization of the entity of dimension
`dim' and tag `tag' at the parametric coordinates `parametricCoord'. Only
valid for `dim' equal to 1 (with `parametricCoord' containing parametric
coordinates on the curve) or 2 (with `parametricCoord' containing pairs of
u, v parametric coordinates on the surface, concatenated: [p1u, p1v, p2u,
...]). For `dim' equal to 1 return the x, y, z components of the derivative