Personal tools
You are here: Home Forum Use Meshing using different hypothesis/algos in if else scenario

Meshing using different hypothesis/algos in if else scenario

Up to Use

Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 17. 2020

Hello all,

I am meshing a complex geometry in TUI. Is it possible to generate a mesh in the following way:

1. Try to mesh the surfaces using 'NETGEN' algo --> if succesful, go to next mesh, otherwise step 2.

2. Try with a different algo(already defined in the code), for e.g.:MEFISTO --> if succesful, go to next mesh, otherwise next step.

3. Try a different algo/hypothesis till mesh is generated.

 

Generally, I have been able to mesh using MEFISTO or NETGEN in GUI, but I cant determine that in TUI, what works for what. So, I want to use this if-else-if scenario, if possible.

Thanks

Re: Meshing using different hypothesis/algos in if else scenario

Posted by SMESH expert at February 17. 2020

Hello

You can use method Mesh.GetFailedShapes() to get sub-shapes on which a current algorithm failed and define a sub-mesh on them using another algorithm.

Best regards

Edward

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 17. 2020

Thank you, thats a great idea. Will do that

It so happens in some cases, that SALOME keeps on trying and trying. Is there a way to time out the meshing process and break the meshing?

Re: Meshing using different hypothesis/algos in if else scenario

Posted by SMESH expert at February 17. 2020

I used the following code for that.

def StartCancelClock( theMesh ):
    """
    Start a timer to cancel meshing in some time
    """
    def cancelMeshing( theMesh ):
        smesh = theMesh.GetEngine()
        mesh  = theMesh.GetMesh()
        smesh.CancelCompute( mesh, None )
        return

    from threading import Timer
    timer = Timer( theMeshingTimeLimit, cancelMeshing, args=( theMesh, ))
    timer.start()
    return timer
   
timer = StartCancelClock( myMesh ) # avoid hanging up in myMesh.Compute()
ok = myMesh.Compute()
timer.cancel()

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 17. 2020

Great! I will have a go with this code. Thank you so much! :)

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 18. 2020

Hello again,

what would be the best way to check if meshing was successful or unsuccessful? I found some information on Using 'Meshname.GetComputeErrors()' but I cant seem to make it work.

Could you please help?

Thanks!

Re: Meshing using different hypothesis/algos in if else scenario

Posted by SMESH expert at February 18. 2020

Hello 

Mesh.Compute() returns a success flag.

Best regards

Edward

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 18. 2020

Thankyou! You are a saviour!

Previously SMESH expert wrote:

Hello 

Mesh.Compute() returns a success flag.

Best regards

Edward

 

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 19. 2020

Hello Edward,

if i use the Mesh.Compute() in an if statement, and the meshing was unsuccessful earlier, would it trigger meshing again?

Thanks

chhavi

 

Re: Meshing using different hypothesis/algos in if else scenario

Posted by SMESH expert at February 19. 2020

Hello Chhavi

Mesh.Compute() will recompute provided that meshing parameters change since the last Compute().

Best regards

Edward

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 19. 2020

Somehow my mesh is being computed over and over again(and failing over and over again :) ). I am unable to figure out why.

Here is the snippet of my code that does this. Could you please give me some tips?

while i < 10:
    name_sm.append(functions.NETGEN_2D(blade_mesh, name_g[i],i))
    timer, flag = functions.StartCancelClock(name_sm[i], timelimit)
    isDone = name_sm[i].Compute()
    print(i)
    #print(name_sm[i].Compute())
    timer.cancel()
    if name_sm[i].Compute() != True or flag ==1:
        name_sm.append(functions.MEFISTO_2D_fine(blade_mesh, name_g[i],i))
        timer, flag = functions.StartCancelClock(name_sm[i], timelimit)
        isDone = name_sm[i].Compute()
        print(i)
        #print(name_sm[i].Compute())
        timer.cancel()

    else:
        pass

 

Function used are:

def StartCancelClock( theMesh, theMeshingTimeLimit ):
    """
    Start a timer to cancel meshing in some time
    """
    flag = 0
    def cancelMeshing( theMesh ):
        smesh = theMesh.GetEngine()
        mesh  = theMesh.GetMesh()
        smesh.CancelCompute( mesh, None )
        flag = 1
        return

    from threading import Timer
    timer = Timer( theMeshingTimeLimit, cancelMeshing, args=( theMesh, ))
    timer.start()
    return timer, flag

def NETGEN_2D( blade_mesh,name,i ):
    """
    Defining NETGEN_2D algo and local length hypothesis with 1e-4 local length
    """
    CompositeSegment_1D_NG = blade_mesh.Segment(algo=smeshBuilder.COMPOSITE,geom=name)
    Local_len_NG = CompositeSegment_1D_NG.LocalLength(0.0001,None,1e-07)
    NETGEN_2D = blade_mesh.Triangle(algo=smeshBuilder.MEFISTO,geom=name)
    Length_From_Edges_NG = NETGEN_2D.LengthFromEdges()
    submesh = NETGEN_2D.GetSubMesh()
    return submesh
    #writing the algo, hypothesis and submesh to file
    smesh.SetName(NETGEN_2D.GetAlgorithm(), 'NETGEN_2D')
    smesh.SetName(CompositeSegment_1D_NG.GetAlgorithm(), 'CompositeSegment_1D_NG')
    smesh.SetName(Local_len_NG, 'Local_len_NG')
    smesh.SetName(Length_From_Edges_NG, 'Length From Edges_NG')
    name_sb = 'submesh_%02d' %i
    smesh.SetName(submesh, name_sb)

 

def MEFISTO_2D_fine( blade_mesh,name,i ):
    """
    Defining MEFISTO algo and local length hypothesis with 1e-4 local length
    """
    CompositeSegment_1D = blade_mesh.Segment(algo=smeshBuilder.COMPOSITE,geom=name)
    Local_len_fine = CompositeSegment_1D.LocalLength(0.0002,None,1e-07)
    MEFISTO_2D = blade_mesh.Triangle(algo=smeshBuilder.MEFISTO,geom=name)
    Length_From_Edges = MEFISTO_2D.LengthFromEdges()
    submesh = CompositeSegment_1D.GetSubMesh()
    return submesh
    #writing the algo, hypothesis and submesh to file
    smesh.SetName(MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D')
    smesh.SetName(CompositeSegment_1D.GetAlgorithm(), 'CompositeSegment_1D')
    smesh.SetName(Local_len_fine, 'Local_len_fine')
    smesh.SetName(Length_From_Edges, 'Length From Edges_1')
    name_sb = 'submesh_%02d' %i
    smesh.SetName(submesh, name_sb)

 

Re: Meshing using different hypothesis/algos in if else scenario

Posted by SMESH expert at February 19. 2020

The bug is that both NETGEN_2D() and MEFISTO_2D_fine() assign MEFISTO.

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 19. 2020

oh man! thankyou so much! testing it now :)

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 21. 2020

Hi Edward,

I have an error message when I try to use this below code: AttributeError: 'submeshProxy' object has no attribute 'GetEngine'. It happens when the cancelMeshing function is called and at the first line.

I couldnt find any documentation to understand this. Could you please help me?

Thanks

Chhavi

Previously SMESH expert wrote:

I used the following code for that.

def StartCancelClock( theMesh ):
    """
    Start a timer to cancel meshing in some time
    """
    def cancelMeshing( theMesh ):
        smesh = theMesh.GetEngine()
        mesh  = theMesh.GetMesh()
        smesh.CancelCompute( mesh, None )
        return

    from threading import Timer
    timer = Timer( theMeshingTimeLimit, cancelMeshing, args=( theMesh, ))
    timer.start()
    return timer
   
timer = StartCancelClock( myMesh ) # avoid hanging up in myMesh.Compute()
ok = myMesh.Compute()
timer.cancel()

 

Re: Meshing using different hypothesis/algos in if else scenario

Posted by SMESH expert at February 25. 2020

GetEngine() is available since v9.3.0.

Best regards

Edward

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 25. 2020

I am already using v9.3.0. Could there be any other issues?

Re: Meshing using different hypothesis/algos in if else scenario

Posted by SMESH expert at February 25. 2020

I see an error now. You pass to StartCancelClock(theMesh) a sub-mesh instead of a mesh.

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 25. 2020

Oh, i have to do this for my submeshes only. any other way please?

Re: Meshing using different hypothesis/algos in if else scenario

Posted by SMESH expert at February 25. 2020

The only case where computing sub-mesh could be useful is to impose a certain order of sub-mesh computation which can't be achieved by setting the sub-mesh order. If you compute a sub-mesh because you want just to re-compute only sub-meshes that failed, you can compute the whole mesh. Sub-meshes that are already successfully computed won't be re-computed if you call Mesh.Compute() several times.

Best regards

Edward

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 25. 2020

Thank you, then I need to rethink my program.

As I am creating my submeshes in a loop, do you have any tips to set the submesh priority in loop?#

I have this, but it doesnt work:

while i<no_of_submeshes-1:

    isDone = blade_mesh.SetMeshOrder( [ [name_sm[i]], [name_sm[i+1]] ] )

    i+=1

 

 

 

Re: Meshing using different hypothesis/algos in if else scenario

Posted by SMESH expert at February 25. 2020

You can remain your program as is, but pass your mesh to StartCancelClock().

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 25. 2020

you mean the main mesh, right? Yes, I will do that. Thankyou!

 

Any tips on setting the submesh order?

Re: Meshing using different hypothesis/algos in if else scenario

Posted by SMESH expert at February 25. 2020

Sub-mesh order is useful when there is a choice which of several different available hypotheses to apply to some entity, say edge. Is it your case?

 

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 25. 2020

yes, it would be the case. I have different submeshes, sharing several edges.

Re: Meshing using different hypothesis/algos in if else scenario

Posted by SMESH expert at February 25. 2020

SetMeshOrder() does not accumulate given sub-meshes. I mean it is necessary to form a list of all sub-meshes and call SetMeshOrder() once.

Re: Meshing using different hypothesis/algos in if else scenario

Posted by Chhavi Kusum at February 25. 2020

Okay, i get it. Thank you so much for your patience and time!

P.S: i might come back with more questions :)

regards

chhavi

Powered by Ploneboard
Document Actions