CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Community Contributions

[PyFoam] Merge and Stitch meshes using pyFoam libraries

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 19, 2018, 08:04
Default Merge and Stitch meshes using pyFoam libraries
  #1
Member
 
Shailesh BG
Join Date: Aug 2017
Location: Bangalore
Posts: 39
Rep Power: 9
shaileshbg is on a distinguished road
Hello Foamers,

Newbie to python and pyFoam, I am looking to automate my simulation using pyFoam libraries.
Problem Statement: I have two different bodies which I have meshed but I want to merge and then stitch the two meshes.

The meshing of my two regions muscle and tissue is successful:
Code:
# Muscle Meshing
orig = SolutionDirectory(path.expandvars("muscle"), archive=None, paraviewLink=False)
work = orig.cloneCase("muscle1")

blockRun = BasicRunner(argv=["blockMesh", "-case", work.name], silent=True, server=False, writeState=False)
blockRun.start()
if not blockRun.runOK():
    error("There was a problem with blockMesh")

snapRun = BasicRunner(argv=["snappyHexMesh", "-case", work.name], silent=True, server=False, writeState=False)
snapRun.start()
if not snapRun.runOK():
    error("There was a problem with snappyHexMesh")

# Tissue Meshing
orig = SolutionDirectory(path.expandvars("tissue"), archive=None, paraviewLink=False)
work = orig.cloneCase("tissue1")

blockRun = BasicRunner(argv=["blockMesh", "-case", work.name], silent=True, server=False, writeState=False)
blockRun.start()
if not blockRun.runOK():
    error("There was a problem with blockMesh")

snapRun = BasicRunner(argv=["snappyHexMesh", "-case", work.name], silent=True, server=False, writeState=False)
snapRun.start()
if not snapRun.runOK():
    error("There was a problem with snappyHexMesh")
The bash equivalent of what I want to do:
Code:
runApplication mergeMeshes -overwrite . ../tissue/              # Merge tissue mesh onto the muscle mesh
runApplication stitchMesh -partial -toleranceDict toleranceDict -overwrite muscle_ext muscle_int   # partial stitch muscle patches per tolerance
cd 0
rm  meshPhi                           # remove meshPhi
cd ..
rm log.*                             # remove current merge and stitch logs
cd constant/polyMesh/                # move to constant polymesh to remove current zones
rm *Zones                            # remove all current zone files
rm meshModifiers                     # remove mesh modifiers
Any help would be greatly appreciated.
__________________
Regards,
Shailesh
shaileshbg is offline   Reply With Quote

Old   February 25, 2018, 12:56
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by shaileshbg View Post
Hello Foamers,

Newbie to python and pyFoam, I am looking to automate my simulation using pyFoam libraries.
Problem Statement: I have two different bodies which I have meshed but I want to merge and then stitch the two meshes.

The meshing of my two regions muscle and tissue is successful:
Code:
# Muscle Meshing
orig = SolutionDirectory(path.expandvars("muscle"), archive=None, paraviewLink=False)
work = orig.cloneCase("muscle1")

blockRun = BasicRunner(argv=["blockMesh", "-case", work.name], silent=True, server=False, writeState=False)
blockRun.start()
if not blockRun.runOK():
    error("There was a problem with blockMesh")

snapRun = BasicRunner(argv=["snappyHexMesh", "-case", work.name], silent=True, server=False, writeState=False)
snapRun.start()
if not snapRun.runOK():
    error("There was a problem with snappyHexMesh")

# Tissue Meshing
orig = SolutionDirectory(path.expandvars("tissue"), archive=None, paraviewLink=False)
work = orig.cloneCase("tissue1")

blockRun = BasicRunner(argv=["blockMesh", "-case", work.name], silent=True, server=False, writeState=False)
blockRun.start()
if not blockRun.runOK():
    error("There was a problem with blockMesh")

snapRun = BasicRunner(argv=["snappyHexMesh", "-case", work.name], silent=True, server=False, writeState=False)
snapRun.start()
if not snapRun.runOK():
    error("There was a problem with snappyHexMesh")
The bash equivalent of what I want to do:
Code:
runApplication mergeMeshes -overwrite . ../tissue/              # Merge tissue mesh onto the muscle mesh
runApplication stitchMesh -partial -toleranceDict toleranceDict -overwrite muscle_ext muscle_int   # partial stitch muscle patches per tolerance
cd 0
rm  meshPhi                           # remove meshPhi
cd ..
rm log.*                             # remove current merge and stitch logs
cd constant/polyMesh/                # move to constant polymesh to remove current zones
rm *Zones                            # remove all current zone files
rm meshModifiers                     # remove mesh modifiers
Any help would be greatly appreciated.
You mean how to go on from the stuff you already did in PyFoam?um First problem I see is that you assigned both SolutionDirectories to the same variable: work. So lets assume you assigned them to muscleWork and tissueWork. Then something like
Code:
mergeRun=BasicRunner(argv=['mergeMeshes','-overwrite',muscleWork.name,tissueWork.name])
might do the trick (not sure whether the -case option is needed with this utility). The shell commands you can either encapsulate in os.system or emulate with os.unlink
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   March 2, 2018, 07:01
Default
  #3
Member
 
Shailesh BG
Join Date: Aug 2017
Location: Bangalore
Posts: 39
Rep Power: 9
shaileshbg is on a distinguished road
Hi Bernhard,

Thank you very much for your reply, this is working perfectly.
Alternatively, I am using subprocess to call in the bash functions directly in python.
__________________
Regards,
Shailesh
shaileshbg is offline   Reply With Quote

Reply

Tags
merge meshes, pyfoam, python script, snappyhexmesh, stitchmesh


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge and Stitch meshes using pyFoam libraries shaileshbg OpenFOAM Programming & Development 1 February 19, 2018 02:30
[blockMesh] How to merge blocks? Match, merge or stitch? gerritgroot OpenFOAM Meshing & Mesh Conversion 0 November 13, 2015 21:59
[blockMesh] Struggling to stitch or merge these blocks Jabo OpenFOAM Meshing & Mesh Conversion 1 November 7, 2014 05:39


All times are GMT -4. The time now is 19:11.