feature request: Viewing and editing OpenFOAM blockMeshDict in FreeCAD?
Moderator: oliveroxtoby
Forum rules
and Helpful information for the FEM forum
and Helpful information for the FEM forum
feature request: Viewing and editing OpenFOAM blockMeshDict in FreeCAD?
Hello Everyone,
Following this reddit post I was advised to ask feature request here in the forum.
It would be great if we could have a plugin like CadQuery's module where on one panel we could edit the blockMeshDict source code and then update the view. And there could be a live preview option to render when an edit is applied. Also some menu options to add point, line, circle... like the ones in Gmsh GUI.
Best,
Foad
Following this reddit post I was advised to ask feature request here in the forum.
It would be great if we could have a plugin like CadQuery's module where on one panel we could edit the blockMeshDict source code and then update the view. And there could be a live preview option to render when an edit is applied. Also some menu options to add point, line, circle... like the ones in Gmsh GUI.
Best,
Foad
Re: feature request: Viewing and editing OpenFOAM blockMeshDict in FreeCAD?
since I even not know what is the feature request about I move it to cfd. May be the guys there know more about this.
bernd
bernd
Re: feature request: Viewing and editing OpenFOAM blockMeshDict in FreeCAD?
Thanks. I did not know about the CFD section. The feature I'm requesting is to import and modify OpenFOAM's blockMeshDict as explained here.
Re: feature request: Viewing and editing OpenFOAM blockMeshDict in FreeCAD?
First step we can implement a simple Python 2.7 script which reads the blockMeshDict file, looks for vertices keyword (which shouldn't be after // or in between /* ... */) and reads the list of tuples (x,y,z) in the parentheses after the keyword. Then creates points, for example in Draft workbench, labeling them consequently. The last part I'm trying to implement here.
Re: feature request: Viewing and editing OpenFOAM blockMeshDict in FreeCAD?
why not import it as a FEM mesh object? We have some mesh importer already. Have a look here: https://github.com/FreeCAD/FreeCAD/tree ... m/feminout The point numbers could be drawn with Draft anyway.
Re: feature request: Viewing and editing OpenFOAM blockMeshDict in FreeCAD?
There is no mesh yet. The issue is that usually blockMesh is not able to compile the blockMeshDict files. visualisation helps to see the problems.
So far I'm able to read the blockMeshDict file by:
now I'm trying to print out the content in the parentheses in the line after vertices keyword with:
But it does not work! I posted the problem here in StackOverflow. Hopefully I can solve this.
So far I'm able to read the blockMeshDict file by:
Code: Select all
import os
os.chdir(os.path.dirname(__file__))
with open("blockMeshDict", "r") as f:
s=f.read()
Code: Select all
import re
r1=re.search(r'vertices\n\((.*?)\)', s)
print r1.group(1)
- oliveroxtoby
- Posts: 840
- Joined: Fri Dec 23, 2016 9:43 am
- Location: South Africa
Re: feature request: Viewing and editing OpenFOAM blockMeshDict in FreeCAD?
That would be cool, but I think it's unlikely that I or other current developers would feel it is a priority. But if you want to have a crack at it and issue us a pull request, that would be great!
Please provide all the information requested in this post before reporting problems with CfdOF.
Re: feature request: Viewing and editing OpenFOAM blockMeshDict in FreeCAD?
thanks to this post I'm now able to import the vertices as tuples with
Code: Select all
r1 = re.search(r'vertices\s*\(\s*(.*)\s*\)', s, re.DOTALL)
vertices = [(float(v[0]),float(v[1]),float(v[2]))
for v in re.findall(r'\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)', r1.group(1))]
print(vertices)
Re: feature request: Viewing and editing OpenFOAM blockMeshDict in FreeCAD?
With the help of other guys I made this script which imports the vertices from a blockMeshDict file and displays them:
I will keep follow this issue on this GitHub Gist
Code: Select all
#the script must be in the same folder as blockMeshDict file
#changing the active directory to the location of script
import os
os.chdir(os.path.dirname(__file__))
#read the file and import it as a string
with open("blockMeshDict", "r") as f:
s=f.read()
import re
#clean up the C/C++ comments
def stripcomments(text):
return re.sub('//.*?(\r\n?|\n)|/\*.*?\*/', '', text, flags=re.S)
s=stripcomments(s)
#extract the vertices into a list of tuples
r1 = re.search(r'vertices\s*\(\s*(.*)\s*\)', s, re.DOTALL)
vertices = [(float(v[0]),float(v[1]),float(v[2]))
for v in re.findall(r'\(\s*([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s*\)', r1.group(1))]
#display the point and labels
App.newDocument("step")
Gui.activateWorkbench("DraftWorkbench")
import Draft
for vertexNum, vertex in enumerate(vertices):
p=Draft.makePoint(vertex[0],vertex[1],vertex[2])
p.Label=str(vertexNum)
Draft.makeText([str(vertexNum)],point=FreeCAD.Vector(vertex[0],vertex[1],vertex[2]))