31
31
#
32
32
# The names of the block and the entities types must match the ones given during the definition of the class mesh on this file :
33
33
# Below :
34
- # class mesh(object, mesh_tools):
34
+ # class mesh(mesh_tools):
35
35
# """ A class to store the mesh """
36
36
# def __init__(self):
37
37
#
38
38
#!! Warning : a block in cubit != quad !! A block is a group of something (quads, edges, volumes, surfaces...)
39
39
# On this case the blocks are used to gather faces corresponding to different materials and edges corresponding to free surfaces,
40
40
# absorbing surfaces, topography or axis
41
41
from __future__ import print_function
42
- import cubit
42
+ import sys
43
+
44
+ try :
45
+ import cubit
46
+ except :
47
+ print ('error importing cubit' )
48
+ sys .exit ()
49
+
50
+ try :
51
+ set
52
+ except NameError :
53
+ from sets import Set as set
43
54
44
55
class mtools (object ):
45
56
"""docstring for mtools"""
@@ -70,7 +81,7 @@ def mesh_it(self):
70
81
command = "mesh surf " + str (surf )
71
82
cubit .cmd (command )
72
83
73
- class block_tools :
84
+ class block_tools ( object ) :
74
85
def __int__ (self ):
75
86
pass
76
87
def create_blocks (self ,mesh_entity ,list_entity = None ,):
@@ -251,10 +262,12 @@ def sorter(x, y):
251
262
print (self .ddt ,self .dr )
252
263
print ('Deltat minimum => edge:' + str (self .ddt [0 ][0 ])+ ' dt: ' + str (self .ddt [0 ][1 ]))
253
264
print ('Minimum frequency resolved => edge:' + str (self .dr [0 ][0 ])+ ' frequency: ' + str (self .dr [0 ][1 ]))
265
+ cubit .cmd ('set info on' )
266
+ cubit .cmd ('set echo on' )
254
267
return self .ddt [0 ],self .dr [0 ]
255
268
256
269
257
- class mesh (object , mesh_tools ):
270
+ class mesh (mesh_tools ):
258
271
""" A class to store the mesh """
259
272
def __init__ (self ):
260
273
super (mesh , self ).__init__ ()
@@ -309,12 +322,13 @@ def block_definition(self):
309
322
name = cubit .get_exodus_entity_name ('block' ,block ) # Contains the name of the blocks
310
323
ty = cubit .get_block_element_type (block ) # Contains the block element type (QUAD4...)
311
324
if ty == self .face : # If we are dealing with a block containing faces
325
+ print ("block: " ,name ," contains faces" )
312
326
nAttributes = cubit .get_block_attribute_count (block )
313
327
if (nAttributes != 1 and nAttributes != 6 ):
314
328
print ('Blocks not properly defined, 2d blocks must have one attribute (material id) or 6 attributes' )
315
329
return None ,None ,None ,None ,None ,None ,None ,None
316
330
flag = int (cubit .get_block_attribute_value (block ,0 )) # Fetch the first attribute value (containing material id)
317
- print ("nAttributes : " ,nAttributes )
331
+ print (" nAttributes : " ,nAttributes )
318
332
if nAttributes == 6 :
319
333
self .write_nummaterial_velocity_file = True
320
334
velP = cubit .get_block_attribute_value (block ,1 ) # Fetch the first attribute value (containing P wave velocity)
@@ -343,21 +357,26 @@ def block_definition(self):
343
357
# # (index 0 : pml_x_acoust, index 1 : pml_z_acoust, index 2 : pml_xz_acoust,
344
358
# # index 3 : pml_x_elast, index 4 : pml_z_elast, index 5 : pml_xz_elast)
345
359
elif ty == self .edge : # If we are dealing with a block containing edges
360
+ print ("block: " ,name ," contains edges" )
346
361
block_bc_flag .append (2 ) # Append "2" to block_bc_flag
347
362
block_bc .append (block ) # Append block id to block_bc
348
363
bc [name ] = 2 # Associate the name of the block with its connectivity : an edge has connectivity = 2
349
364
if name == self .topo :
350
365
self .topo_mesh = True
366
+ print (" topo_mesh: " ,self .topo_mesh )
351
367
topography = block # If the block considered refered to topography store its id in "topography"
352
368
if name in self .forcing_boun_name :
353
369
self .forcing_mesh = True
370
+ print (" forcing_mesh: " ,self .forcing_mesh )
354
371
forcing_boun [self .forcing_boun_name .index (name )] = block
355
372
# -> Put it at the correct position in abs_boun (index 0 : bottom, index 1 : right, index 2 : top, index 3 : left)
356
373
if name == self .axisname :
357
374
self .axisymmetric_mesh = True
375
+ print (" axisymmetric_mesh: " ,self .axisymmetric_mesh )
358
376
axisId = block # AXISYM If the block considered refered to the axis store its id in "axisId"
359
377
if name in self .abs_boun_name : # If the block considered refered to one of the boundaries
360
378
self .abs_mesh = True
379
+ print (" abs_mesh: " ,self .abs_mesh )
361
380
abs_boun [self .abs_boun_name .index (name )] = block
362
381
# -> Put it at the correct position in abs_boun (index 0 : bottom, index 1 : right, index 2 : top, index 3 : left)
363
382
else :
@@ -415,6 +434,8 @@ def mesh_write(self,mesh_name):
415
434
""" Write mesh (quads ids with their corresponding nodes ids) on file : mesh_name """
416
435
meshfile = open (mesh_name ,'w' )
417
436
print ('Writing ' + mesh_name + '.....' )
437
+ cubit .cmd ('set info off' ) # Turn off return messages from Cubit commands
438
+ cubit .cmd ('set echo off' ) # Turn off echo of Cubit commands
418
439
num_elems = cubit .get_quad_count () # Store the number of elements
419
440
toWritetoFile = ["" ]* (num_elems + 1 )
420
441
toWritetoFile [0 ] = str (num_elems )+ '\n '
@@ -433,10 +454,14 @@ def mesh_write(self,mesh_name):
433
454
meshfile .writelines (toWritetoFile )
434
455
meshfile .close ()
435
456
print ('Ok num elements/write =' ,str (num_elems ), str (num_write ))
457
+ cubit .cmd ('set info on' )
458
+ cubit .cmd ('set echo on' )
436
459
def material_write (self ,mat_name ):
437
460
""" Write quads material on file : mat_name """
438
461
mat = open (mat_name ,'w' )
439
462
print ('Writing ' + mat_name + '.....' )
463
+ cubit .cmd ('set info off' ) # Turn off return messages from Cubit commands
464
+ cubit .cmd ('set echo off' ) # Turn off echo of Cubit commands
440
465
num_elems = cubit .get_quad_count () # Store the number of elements
441
466
toWritetoFile = ["" ]* num_elems
442
467
print ('block_mat:' ,self .block_mat )
@@ -450,12 +475,14 @@ def material_write(self,mat_name):
450
475
mat .writelines (toWritetoFile )
451
476
mat .close ()
452
477
print ('Ok' )
478
+ cubit .cmd ('set info on' )
479
+ cubit .cmd ('set echo on' )
453
480
def pmls_write (self ,pml_name ):
454
481
""" Write pml elements on file : mat_name """
455
- cubit .cmd ('set info off' ) # Turn off return messages from Cubit commands
456
- cubit .cmd ('set echo off' ) # Turn off echo of Cubit commands
457
482
pml_file = open (pml_name ,'w' )
458
483
print ('Writing ' + pml_name + '.....' )
484
+ cubit .cmd ('set info off' ) # Turn off return messages from Cubit commands
485
+ cubit .cmd ('set echo off' ) # Turn off echo of Cubit commands
459
486
npml_elements = 0
460
487
#id_element = 0 # Global id
461
488
indexFile = 1
@@ -493,6 +520,8 @@ def nodescoord_write(self,nodecoord_name):
493
520
""" Write nodes coordinates on file : nodecoord_name """
494
521
nodecoord = open (nodecoord_name ,'w' )
495
522
print ('Writing ' + nodecoord_name + '.....' )
523
+ cubit .cmd ('set info off' ) # Turn off return messages from Cubit commands
524
+ cubit .cmd ('set echo off' ) # Turn off echo of Cubit commands
496
525
node_list = cubit .parse_cubit_list ('node' ,'all' ) # Import all the nodes of the model
497
526
num_nodes = len (node_list ) # Total number of nodes
498
527
nodecoord .write ('%10i\n ' % num_nodes ) # Write the number of nodes on the first line
@@ -502,26 +531,27 @@ def nodescoord_write(self,nodecoord_name):
502
531
nodecoord .write (txt ) # Write x and z coordinates on the file -> Model must be in x,z coordinates. TODO
503
532
nodecoord .close ()
504
533
print ('Ok' )
534
+ cubit .cmd ('set info on' ) # Turn on return messages from Cubit commands
535
+ cubit .cmd ('set echo on' ) # Turn on echo of Cubit commands
505
536
def free_write (self ,freename ): #freename = None):
506
537
""" Write free surface on file : freename """
507
- cubit .cmd ('set info off' ) # Turn off return messages from Cubit commands
508
- cubit .cmd ('set echo off' ) # Turn off echo of Cubit commands
509
- cubit .cmd ('set journal off' ) # Do not save journal file
510
- from sets import Set
511
538
# if not freename: freename = self.freename
512
539
freeedge = open (freename ,'w' )
513
540
print ('Writing ' + freename + '.....' )
541
+ cubit .cmd ('set info off' ) # Turn off return messages from Cubit commands
542
+ cubit .cmd ('set echo off' ) # Turn off echo of Cubit commands
543
+ cubit .cmd ('set journal off' ) # Do not save journal file
514
544
if self .topo_mesh :
515
545
for block ,flag in zip (self .block_bc ,self .block_bc_flag ): # For each 1D block
516
546
if block == self .topography : # If the block correspond to topography
517
- edges_all = Set (cubit .get_block_edges (block )) # Import all topo edges id as a Set
547
+ edges_all = set (cubit .get_block_edges (block )) # Import all topo edges id as a Set
518
548
toWritetoFile = [] #[""]*(len(edges_all)+1)
519
549
toWritetoFile .append ('%10i\n ' % len (edges_all )) # Print the number of edges on the free surface
520
550
for block ,flag in zip (self .block_mat ,self .block_flag ): # For each 2D block
521
551
print (block ,flag )
522
552
quads = cubit .get_block_faces (block ) # Import quads id
523
553
for quad in quads : # For each quad
524
- edges = Set (cubit .get_sub_elements ("face" , quad , 1 )) # Get the lower dimension entities associated with a higher dimension entities.
554
+ edges = set (cubit .get_sub_elements ("face" , quad , 1 )) # Get the lower dimension entities associated with a higher dimension entities.
525
555
# Here it gets the 1D edges associates with the face of id "quad". Store it as a Set
526
556
intersection = edges & edges_all # Contains the edges of the considered quad that is on the free surface
527
557
if len (intersection ) != 0 : # If this quad touch the free surface
@@ -550,19 +580,18 @@ def free_write(self,freename): #freename = None):
550
580
cubit .cmd ('set echo on' ) # Turn on echo of Cubit commands
551
581
def forcing_write (self ,forcname ):
552
582
""" Write forcing surfaces on file : forcname """
583
+ forceedge = open (forcname ,'w' )
584
+ print ('Writing ' + forcname + '.....' )
553
585
cubit .cmd ('set info off' ) # Turn off return messages from Cubit commands
554
586
cubit .cmd ('set echo off' ) # Turn off echo of Cubit commands
555
587
cubit .cmd ('set journal off' ) # Do not save journal file
556
- from sets import Set
557
- forceedge = open (forcname ,'w' )
558
- print ('Writing ' + forcname + '.....' )
559
- edges_forc = [Set ()]* self .nforc # edges_forc[0] will be a Set containing the nodes describing the forcing boundary
588
+ edges_forc = [set ()]* self .nforc # edges_forc[0] will be a Set containing the nodes describing the forcing boundary
560
589
# (index 0 : bottom, index 1 : right, index 2 : top, index 3 : left)
561
590
nedges_all = 0 # To count the total number of forcing edges
562
591
for block ,flag in zip (self .block_bc ,self .block_bc_flag ): # For each 1D block
563
592
for iforc in range (0 , self .nforc ): # iforc = 0,1,2,3 : for each forcing boundaries
564
593
if block == self .forcing_boun [iforc ]: # If the block considered correspond to the boundary
565
- edges_forc [iforc ] = Set (cubit .get_block_edges (block )) # Store each edge on edges_forc
594
+ edges_forc [iforc ] = set (cubit .get_block_edges (block )) # Store each edge on edges_forc
566
595
nedges_all = nedges_all + len (edges_forc [iforc ]) # add the number of edges to nedges_all
567
596
toWritetoFile = ["" ]* (nedges_all + 1 )
568
597
toWritetoFile [0 ] = '%10i\n ' % nedges_all # Write the total number of forcing edges to the first line of file
@@ -574,7 +603,7 @@ def forcing_write(self,forcname):
574
603
quads = cubit .get_block_faces (block ) # Import quads id
575
604
for quad in quads : # For each quad
576
605
#id_element = id_element+1 # id of this quad
577
- edges = Set (cubit .get_sub_elements ("face" , quad , 1 )) # Get the lower dimension entities associated with a higher dimension entities.
606
+ edges = set (cubit .get_sub_elements ("face" , quad , 1 )) # Get the lower dimension entities associated with a higher dimension entities.
578
607
# Here it gets the 1D edges associates with the face of id "quad". Store it as a Set
579
608
for iforc in range (0 ,self .nforc ): # iforc = 0,1,2,3 : for each forcing boundaries
580
609
intersection = edges & edges_forc [iforc ] # Contains the edges of the considered quad that is on the forcing boundary considered
@@ -605,20 +634,19 @@ def forcing_write(self,forcname):
605
634
cubit .cmd ('set echo on' ) # Turn on echo of Cubit commands
606
635
def abs_write (self ,absname ):
607
636
""" Write absorbing surfaces on file : absname """
608
- cubit .cmd ('set info off' ) # Turn off return messages from Cubit commands
609
- cubit .cmd ('set echo off' ) # Turn off echo of Cubit commands
610
- cubit .cmd ('set journal off' ) # Do not save journal file.
611
- from sets import Set
612
637
# if not absname: absname = self.absname
613
638
absedge = open (absname ,'w' )
614
639
print ('Writing ' + absname + '.....' )
615
- edges_abs = [Set ()]* self .nabs # edges_abs[0] will be a Set containing the nodes describing bottom adsorbing boundary
640
+ cubit .cmd ('set info off' ) # Turn off return messages from Cubit commands
641
+ cubit .cmd ('set echo off' ) # Turn off echo of Cubit commands
642
+ cubit .cmd ('set journal off' ) # Do not save journal file.
643
+ edges_abs = [set ()]* self .nabs # edges_abs[0] will be a Set containing the nodes describing bottom adsorbing boundary
616
644
# (index 0 : bottom, index 1 : right, index 2 : top, index 3 : left)
617
645
nedges_all = 0 # To count the total number of absorbing edges
618
646
for block ,flag in zip (self .block_bc ,self .block_bc_flag ): # For each 1D block
619
647
for iabs in range (0 , self .nabs ): # iabs = 0,1,2,3 : for each absorbing boundaries
620
648
if block == self .abs_boun [iabs ]: # If the block considered correspond to the boundary
621
- edges_abs [iabs ] = Set (cubit .get_block_edges (block )) # Store each edge on edges_abs
649
+ edges_abs [iabs ] = set (cubit .get_block_edges (block )) # Store each edge on edges_abs
622
650
nedges_all = nedges_all + len (edges_abs [iabs ]); # add the number of edges to nedges_all
623
651
toWritetoFile = ["" ]* (nedges_all + 1 )
624
652
toWritetoFile [0 ] = '%10i\n ' % nedges_all # Write the total number of absorbing edges to the first line of file
@@ -630,7 +658,7 @@ def abs_write(self,absname):
630
658
quads = cubit .get_block_faces (block ) # Import quads id
631
659
for quad in quads : # For each quad
632
660
#id_element = id_element+1 # id of this quad
633
- edges = Set (cubit .get_sub_elements ("face" , quad , 1 )) # Get the lower dimension entities associated with a higher dimension entities.
661
+ edges = set (cubit .get_sub_elements ("face" , quad , 1 )) # Get the lower dimension entities associated with a higher dimension entities.
634
662
# Here it gets the 1D edges associates with the face of id "quad". Store it as a Set
635
663
for iabs in range (0 ,self .nabs ): # iabs = 0,1,2,3 : for each absorbing boundaries
636
664
intersection = edges & edges_abs [iabs ] # Contains the edges of the considered quad that is on the absorbing boundary considered
@@ -656,15 +684,14 @@ def abs_write(self,absname):
656
684
cubit .cmd ('set echo on' ) # Turn on echo of Cubit commands
657
685
def axis_write (self ,axis_name ):
658
686
""" Write axis on file """
687
+ axisedge = open (axis_name ,'w' )
688
+ print ('Writing ' + axis_name + '.....' )
659
689
cubit .cmd ('set info off' ) # Turn off return messages from Cubit commands
660
690
cubit .cmd ('set echo off' ) # Turn off echo of Cubit commands
661
691
cubit .cmd ('set journal off' ) # Do not save journal file
662
- from sets import Set
663
- axisedge = open (axis_name ,'w' )
664
- print ('Writing ' + axis_name + '.....' )
665
692
for block ,flag in zip (self .block_bc ,self .block_bc_flag ): # For each 1D block
666
693
if block == self .axisId : # If the block correspond to the axis
667
- edges_all = Set (cubit .get_block_edges (block )) # Import all axis edges id as a Set
694
+ edges_all = set (cubit .get_block_edges (block )) # Import all axis edges id as a Set
668
695
toWritetoFile = ["" ]* (len (edges_all )+ 1 )
669
696
toWritetoFile [0 ] = '%10i\n ' % len (edges_all ) # Write the number of edges on the axis
670
697
#axisedge.write('%10i\n' % len(edges_all)) # Write the number of edges on the axis
@@ -675,7 +702,7 @@ def axis_write(self,axis_name):
675
702
quads = cubit .get_block_faces (block ) # Import quads id
676
703
for quad in quads : # For each quad
677
704
#id_element = id_element+1 # id of this quad
678
- edges = Set (cubit .get_sub_elements ("face" , quad , 1 )) # Get the lower dimension entities associated with a higher dimension entities.
705
+ edges = set (cubit .get_sub_elements ("face" , quad , 1 )) # Get the lower dimension entities associated with a higher dimension entities.
679
706
# Here it gets the 1D edges associates with the face of id "quad". Store it as a Set
680
707
intersection = edges & edges_all # Contains the edges of the considered quad that are on the axis
681
708
if len (intersection ) != 0 : # If this quad touch the axis
@@ -710,11 +737,11 @@ def rec_write(self,recname):
710
737
print ('Ok' )
711
738
def write (self ,path = '' ):
712
739
""" Write mesh in specfem2d format """
713
- print ('Writing ' + self . recname + '.....' )
740
+ print ('Writing ' + path + '.....' )
714
741
import os
715
- cubit .cmd ('set info off' ) # Turn off return messages from Cubit commands
716
- cubit .cmd ('set echo off' ) # Turn off echo of Cubit commands
717
- cubit .cmd ('set journal off' ) # Do not save journal file
742
+ # cubit.cmd('set info off') # Turn off return messages from Cubit commands
743
+ # cubit.cmd('set echo off') # Turn off echo of Cubit commands
744
+ # cubit.cmd('set journal off') # Do not save journal file
718
745
if len (path ) != 0 : # If a path is supplied add a / at the end if needed
719
746
if path [- 1 ] != '/' : path = path + '/'
720
747
else :
@@ -736,8 +763,8 @@ def write(self,path = ''):
736
763
if self .receivers :
737
764
self .rec_write (path + self .recname ) # If receivers has been set (as nodeset) write receiver file as well
738
765
print ('Mesh files has been writen in ' + path )
739
- cubit .cmd ('set info on' ) # Turn on return messages from Cubit commands
740
- cubit .cmd ('set echo on' ) # Turn on echo of Cubit commands
766
+ # cubit.cmd('set info on') # Turn on return messages from Cubit commands
767
+ # cubit.cmd('set echo on') # Turn on echo of Cubit commands
741
768
742
769
def export2SPECFEM2D (path_exporting_mesh_SPECFEM2D = '.' ):
743
770
# reads in mesh from cubit
@@ -747,7 +774,7 @@ def export2SPECFEM2D(path_exporting_mesh_SPECFEM2D='.'):
747
774
print ("END SPECFEM2D exporting process......" )
748
775
749
776
# gets executed when run as script within cubit
750
- export2SPECFEM2D ()
777
+ # export2SPECFEM2D()
751
778
752
779
753
780
0 commit comments