Personal tools
You are here: Home Forum Install & build Compound for Meshing ?

Compound for Meshing ?

Up to Install & build

Compound for Meshing ?

Posted by Markus Gruber at April 11. 2013

I am running a script and salome is doing a new study for me , but i don't want to have this , because the script is afterwards not able to do my submeshes.How to handle this behaviour or even how to prevent this i am able to mesh my geometry at the gui without any compound for mesh , so why is salomne doing this new study at my scripts,i am not adding this and especially i don't want this behaviour

 

best regards

 

 

Re: Compound for Meshing ?

Posted by Saint Michael at April 11. 2013

Is it possible to look at your script?

St.Michael

Re: Compound for Meshing ?

Posted by Markus Gruber at April 11. 2013

Here we go , it's just a snapeshoot , i cut it , for working in the gui , but it's the same problem

import geompy
import salome
import sys, os
import inspect
import math
import platform
import medmem

print sys.argv

salome.salome_init()
theStudy = salome.myStudy

fullfile_path=inspect.getfile(inspect.currentframe()) # script filename (usually with path)
filepath=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # script directory
os.chdir(filepath)
gg = salome.ImportComponentGUI("GEOM")

#########

if(len(sys.argv))> 1:
 file_name=sys.argv[1]
else:
 file_name='makegeo/_sim2/__B_100__S_32__R_15_0__V_0.txt'

if(len(sys.argv))>2:
 file_name=sys.argv[2]
else:
 file_name_log='makemesh.log'

if(len(sys.argv))>3:
 dir_out=sys.argv[3]
else:
 dir_out="/makemesh"

if(platform.uname()[0]=="Linux"):
 _char="/"
 file_name=file_name.replace("\\","/")
 dir_out=dir_out.replace("\\","/")
else:
 _char="\\"
 file_name=file_name.replace("/","\\")
 dir_out=dir_out.replace("/","\\")

name=file_name.split(_char)
name=name[len(name)-1]
name=name.split('.')[0]

#########

#drawing spehre in salomne
def f_s(x,y,z,r,name):

    sphere2 = geompy.MakeSphere(x, y, z, r)

    # add objects in the study
    id_sphere2 = geompy.addToStudy(sphere2,name)

    # display spheres
    gg.createAndDisplayGO(id_sphere2)
    gg.setDisplayMode(id_sphere2,1)
   
    return id_sphere2,sphere2

#drawing block in salomne
def f_b(x,y,z,name):

    # create boxes
    box1 = geompy.MakeBoxDXDYDZ(x, y, z)

    # add objects in the study
    id_box1 = geompy.addToStudy(box1,name)

    # display the boxes
    gg.createAndDisplayGO(id_box1)
    gg.setDisplayMode(id_box1,1)
   
    return id_box1,box1


#checking output file
if not os.path.exists(filepath+_char+dir_out):
    os.system("mkdir "+filepath+_char+dir_out)

#checking logging file
if not os.path.exists(file_name_log):
    f=open(file_name_log,'w+')
    f.write("Filename "+
            "Block_Volume(total) "+
            "Sphere_Volume "+
            "Volume_Ratio "+
            "C_Spheres_F "+
            "C_Spheres_M "+
            "R_Avr_F "+
            "R_Avr_M "+
            "R_Var_F "+
            "R_Var_M " +
            "Finished\n")

#checking input file
if not os.path.exists(file_name):
    print "Input File not found"
    f=open(file_name_log,'a+')
    f.readlines()
    f.write(name+" "+
    str(0)+" "+
    str(0)+" "+
    str(0)+" "+
    str(0)+" " +
    str(0)+" " +
    str(0)+" " +
    str(0)+" " +
    str(0)+" " +
    str(0)+" " +
    "FILE_NOT_FOUND\n")
    f.close()
    raise SystemExit
else:

#reading from file
 l_spheres=[]
 l_id_spheres=[]
 volume_spheres=0.0
 volume_block=0.0
 r_avr_f=0.0
 r_avr_m=0.0
 r_var_f=0.0
 r_var_m=0.0
 c_spheres_f=0
 c_spheres_m=0
 name_in="Sphere"

 f = open(file_name,'r')
 line=f.readline()

 line=line.rstrip('\n\r ')
 line=line.rstrip(' ')
 line=line.rstrip(',')
 liste=line.split(' ')
 liste=line.split()

 c_spheres_f=float(liste[0])
 r_avr_f=float(liste[1])
 r_var_f=float(liste[2])

 line=f.readline()
 line=line.rstrip('\n\r ')
 line=line.rstrip(' ')
 line=line.rstrip(',')
 liste=line.split(' ')
 liste=line.split()

#drawing a block
 x=float(liste[0])
 y=float(liste[1])
 z=float(liste[2])
 [id_block1,block_1]=f_b(x,y,z,"Block")
 volume_block=x*y*z

#translate the block
 trans_block = geompy.MakeTranslation(block_1, -x/2, -y/2, -z/2)
 id_translation1 = geompy.addToStudy(trans_block , "Block_Translated")
 gg.createAndDisplayGO(id_translation1)
 gg.setDisplayMode(id_translation1,1)

 for line in f:
   
    line=line.rstrip('\n\r ')
    line=line.rstrip(' ')
    line=line.rstrip(',')
    liste=line.split(' ')
 
    if len(liste) > 4:
        liste=liste[1:5]
    if len(liste) < 4:
        continue
    x=float(liste[0])
    y=float(liste[1])
    z=float(liste[2])
    r=float(liste[3])

    volume_spheres=volume_spheres+4.0/3.0 * math.pi * r**3
    r_avr_m=r_avr_m+r
    [id_s,s]=f_s(x,y,z,r,name_in+str(c_spheres_m))
    l_spheres.append(s)
    l_id_spheres.append(id_s)
    c_spheres_m=c_spheres_m+1
    r_var_m=r_var_m+(r_avr_f-r)**2
   
 f.close()
 print c_spheres_m
 r_avr_m=r_avr_m/float(c_spheres_m)

 print "From FILE:"
 print "Got "+str(len(l_spheres))+" Spheres"
 print "Volume(Spheres): "+str(volume_spheres)
 print "Radius(AVG): " + str(r)
 print "Volume(Block): "+str(volume_block)
 print "Ratio: "+str(volume_spheres/volume_block)

 f=open(file_name_log,'a+')
 f.readlines()
 f.write(name+" "+
 str(volume_block)+" "+
 str(volume_spheres)+" "+
 str(volume_spheres/volume_block)+" "+
 str(c_spheres_f)+" " +
 str(c_spheres_m)+" " +
 str(r_avr_f)+" " +
 str(r_avr_m)+" " +
 str(r_var_f)+" " +
 str(r_var_m)+" " +
 "NO\n")
 f.close()

###

 
 if len(l_spheres) > 1 :
  #check shapes if self intersected
  ls_spheres=[]  
  for i in range(len(l_spheres)-1):
      s=l_spheres[i]
      for d in range(i+1,len(l_spheres)):
        if geompy.MinDistance(l_spheres[i], l_spheres[d]) < 0.005:
            s=geompy.MakeFuse(s, l_spheres[d])
      ls_spheres.append(s)

  l_spheres=ls_spheres   
  #####Partion for spheres
  part_spheres = geompy.MakePartition(l_spheres, [], [], [], geompy.ShapeType["SOLID"], 0, [], 0)     
  id_part_spheres = geompy.addToStudy(part_spheres, "Partition_Spheres")
  gg.createAndDisplayGO(id_part_spheres)
 
  part_spheres=geompy.MakeCommon(trans_block,part_spheres)
  id_part_spheres_cut = geompy.addToStudy(part_spheres, "Partition_Spheres_Cut")
  gg.createAndDisplayGO(id_part_spheres_cut)

 #####
 
  inter_block=geompy.MakeCut(trans_block , part_spheres )
 
  # add objects in the study
  id_inter_block = geompy.addToStudy(inter_block, "Intersected_Block_with_Spheres")

  gg.createAndDisplayGO(id_inter_block)
  gg.setTransparency(id_inter_block,0.45)
  gg.setDisplayMode(id_inter_block,1)
  gg.setColor(id_inter_block,0,0,255)

#####

 else:
   
####intersect spheres with block
  l_spheres[0]=geompy.MakeCommon(trans_block,l_spheres[0])
  id_part_spheres_cut = geompy.addToStudy(l_spheres[0], "Partition_Spheres_Cut")
  gg.createAndDisplayGO(id_part_spheres_cut)
    
  inter_block = geompy.MakeCut(trans_block, l_spheres[0])
  #inter_block=  geompy.MakeCompound([inter_block])
  id_inter_block = geompy.addToStudy(inter_block, "Intersected_Block_with_Spheres")

  gg.createAndDisplayGO(id_inter_block)
  gg.setTransparency(id_inter_block,0.45)
  gg.setDisplayMode(id_inter_block,1)
  gg.setColor(id_inter_block,0,0,255)

##

 if len(l_spheres) > 1:
  partiton_block_spheres = geompy.MakePartition([part_spheres,inter_block], [], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
  id_partiton_block_spheres = geompy.addToStudy(partiton_block_spheres , "Partition_Intersected_Block_and_Spheres")
  gg.createAndDisplayGO(id_partiton_block_spheres)
 else:
  partiton_block_spheres = geompy.MakePartition([l_spheres[0],inter_block], [], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
  id_partiton_block_spheres = geompy.addToStudy(partiton_block_spheres , "Partition_Intersected_Block_and_Spheres")
  gg.createAndDisplayGO(id_partiton_block_spheres)


###make SubGroupes
 if len(l_spheres) > 1:
  #Intersected Block
  inter_block_ss = geompy.GetInPlaceByHistory(partiton_block_spheres, inter_block)
  id_block_ss = geompy.addToStudyInFather(partiton_block_spheres,inter_block_ss, "1")

  #interected Spheres
  part_spheres_ss = geompy.GetInPlaceByHistory(partiton_block_spheres, part_spheres)
  id_block_ss = geompy.addToStudyInFather(partiton_block_spheres,part_spheres_ss, "2")
 
 else:
  inter_block_ss = geompy.GetInPlaceByHistory(partiton_block_spheres, inter_block)
  id_block_ss = geompy.addToStudyInFather(partiton_block_spheres,inter_block_ss, "1")

  part_spheres_ss = geompy.GetInPlaceByHistory(partiton_block_spheres, l_spheres[0])
  id_block_ss = geompy.addToStudyInFather(partiton_block_spheres,part_spheres_ss, "2")
###

 print " "
 print "From Salomne(Shape):"
 print "Volume(intersected block) " + str(geompy.BasicProperties(inter_block_ss)[2])
 print "Volume(inserted spheres) " + str(geompy.BasicProperties(part_spheres_ss)[2])

 #repair the Shahpe
 # process the Shape
 Operators = ["FixShape"]
 Parameters = ["FixShape.Tolerance3d"]
 Values = ["1e-7"]
 partiton_block_spheres = geompy.ProcessShape(partiton_block_spheres, Operators, Parameters, Values)
 inter_block_ss= geompy.ProcessShape(inter_block_ss, Operators, Parameters, Values)
 part_spheres_ss= geompy.ProcessShape(part_spheres_ss, Operators, Parameters, Values)
 
# check the shape at the beginning
 print "Before ProcessShape:"
 isValid = geompy.CheckShape(partiton_block_spheres)
 if isValid == 0:
     print "The shape is not valid"
 else:
     print "The shape seems to be valid"
 
 # check the shape at the beginning
 print "Before ProcessShape:"
 isValid = geompy.CheckShape(inter_block_ss)
 if isValid == 0:
     print "The shape is not valid"
 else:
     print "The shape seems to be valid"

  # check the shape at the beginning
 print "Before ProcessShape:"
 isValid = geompy.CheckShape(part_spheres_ss)
 if isValid == 0:
     print "The shape is not valid"
 else:
     print "The shape seems to be valid"
  
#################################
 import smesh, SMESH, SALOMEDS

 smesh.SetCurrentStudy(theStudy)
 import NETGENPlugin

###############################


############################################################################

#Create Mesh of Partition_Intersected_Block_and_Spheres

############################################################################

 #start values for Meshing
 MaxSize=5
 MinSize=0.5

 NETGEN_2D3D = smesh.CreateHypothesis('NETGEN_2D3D', 'libNETGENEngine.so')
 NETGEN_3D = smesh.CreateHypothesis('NETGEN_3D', 'NETGENEngine')
 NETGEN_3D_Parameters = smesh.CreateHypothesis('NETGEN_Parameters', 'NETGENEngine')
 NETGEN_3D_Parameters.SetMaxSize( MaxSize )
 NETGEN_3D_Parameters.SetSecondOrder( 0 )
 NETGEN_3D_Parameters.SetOptimize( 1 )
 NETGEN_3D_Parameters.SetFineness( 2 )
 NETGEN_3D_Parameters.SetMinSize( MinSize )
 mesh_int_block = smesh.Mesh(partiton_block_spheres)
 status = mesh_int_block.AddHypothesis(NETGEN_3D_Parameters)
 status = mesh_int_block.AddHypothesis(NETGEN_2D3D)
 isDone = mesh_int_block.Compute()
 

Re: Compound for Meshing ?

Posted by Markus Gruber at April 11. 2013

one again , sorry missed uploading

Attachments

Re: Compound for Meshing ?

Posted by Markus Gruber at April 11. 2013

if u want to have the input file , plz but the directory into the same directory  as  the script

Attachments

Re: Compound for Meshing ?

Posted by Saint Michael at April 11. 2013

I tried to run your script 2 possible ways, (1) execfile("script.py"), (2) import script. No new study is created. The script fails at meshing.

St.Michael

Re: Compound for Meshing ?

Posted by Markus Gruber at April 11. 2013

look at the study manager i think there must a new study with compound_xx_for_meshing ,salomne should be able to do the main mesh (from compound,but not from the right study object),but not the submeshes

Previously Saint Michael wrote:

I tried to run your script 2 possible ways, (1) execfile("script.py"), (2) import script. No new study is created. The script fails at meshing.

St.Michael

 

 

Re: Compound for Meshing ?

Posted by Saint Michael at April 11. 2013

After running the script 3 times I see only one study.
Menu File / Connect ... proposes no unloaded studies.

>>> salome.myStudyManager.GetOpenStudies()

['Study1']

St.Michael

Re: Compound for Meshing ?

Posted by Markus Gruber at April 11. 2013

ok sorry , my failure but ,only one study but a new object , i put one picture one it, the mesh should come from Partion_Intersected_Block_Spheres and not from COMPOUND_40 ,so i don't know where it comes from , at my script there is no defintion of COMPOUND_40, it does salome not my script

 

https://www.dropbox.com/s/616nrvlav8d1got/pic1.bmp

Re: Compound for Meshing ?

Posted by SMESH expert at April 11. 2013

Hello Markus

To have mesh data persistent (namely to keep reference between a mesh and a shape it's built on) when a study is stored/restored, the shape should be published. As in your case partiton_block_spheres is not published in the study, SALOME publishes it automatically with a random name, e.g. COMPOUND_40.

Best regards

Edward

Powered by Ploneboard
Document Actions