# [blockMesh] Parametrizing BlockMesh (preferably without m4)

 Register Blogs Members List Search Today's Posts Mark Forums Read

October 1, 2021, 04:19
Parametrizing BlockMesh (preferably without m4)
#1
New Member

Join Date: Dec 2016
Posts: 23
Rep Power: 7
Hi everyone,

I have a tricky, maybe even impossible question.

The goal is to mesh a quarter (axisymmetric) cylinder with fixed length and radius L and R.
The cylinder wall is divided into N patches of equal length L/N (see the attached figure for N=5).

Right now I create vertices and blocks manually. You can imagine that if N becomes large, I can spend the entire day making a single mesh. Therefore, I'd like to parametrize N and let the script do it for me. The problem is that loops are not a thing in the BlockMeshDict (at least not to my knowing).

I know about m4 but the documentation is marginal. What is the best approach here?

Attached Images
 qcylinder.PNG (21.5 KB, 5 views)

 October 1, 2021, 04:28 #2 Senior Member   Domenico Lahaye Join Date: Dec 2013 Posts: 457 Blog Entries: 1 Rep Power: 13

 October 1, 2021, 07:55 #3 Senior Member   Gerhard Holzinger Join Date: Feb 2012 Location: Austria Posts: 316 Rep Power: 26 If you only want to use variable parameters, and don't need the entire magic that Python-scripting has to offer, you can also use OpenFOAM's on-board tools, i.e., using variables in dictionaries, the code-stream magic. A parametric blockMeshDict from the tutorials dlahaye likes this.

October 4, 2021, 05:53
#4
New Member

Join Date: Dec 2016
Posts: 23
Rep Power: 7
I downloaded the git and tried to run the "from_points" example, but python throws me a "raise AttributeError(f"Unknown edge type: {self.type}") on line 132 of primitives.py.

I installed and prioritized python 3.8 so not really sure where the error is originating from.

Quote:
 If you only want to use variable parameters, and don't need the entire magic that Python-scripting has to offer, you can also use OpenFOAM's on-board tools, i.e., using variables in dictionaries, the code-stream magic. A parametric blockMeshDict from the tutorials
I am considering this as well:

Code:
```radius 			0.0005;
Len 			0.001;
nSegments 		5.0;

minY            #calc "-1.0*\$y";
segmentLength	#calc "\$Len / \$nSegments";

codeStream
#{
std::array<float, \$nSegments> lenarray;
for (int i=1;i<\$nSegments;i++)
{
lenarray[i] = \$segmentLength*i;
}
#};```
Passing variables like "nSegments" into the codestream works fine, but how exactly can you return variables or other data like "lenarray" back to the regular code?

 Tags blockmeshdict