CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Meshing & Mesh Conversion

[blockMesh] Creating blockMeshDict from python

Register Blogs Community New Posts Updated Threads Search

Like Tree22Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 3, 2020, 03:33
Default Creating blockMeshDict from python
  #1
Senior Member
 
kandelabr's Avatar
 
Nejc
Join Date: Feb 2017
Location: Slovenia
Posts: 196
Rep Power: 9
kandelabr is on a distinguished road
Hello.
I've been using Python and jinja2 to calculate points and create blockMeshDict files with it.
I've shared the script with a few examples here: https://github.com/damogranlabs/classyBlocks
https://damogranlabs.com/2020/02/cla...for-blockmesh/

So far it proved useful to me. Feel free to use it, any comments and suggestions are most welcome.

Thanks!
rmaries, jherb, lebc and 6 others like this.
__________________
www.damogranlabs.com
kandelabr is offline   Reply With Quote

Old   June 9, 2020, 14:47
Default
  #2
Senior Member
 
kandelabr's Avatar
 
Nejc
Join Date: Feb 2017
Location: Slovenia
Posts: 196
Rep Power: 9
kandelabr is on a distinguished road
Just a bump, I made some massive updates to mentioned scripts. Now you can (almost) easily create pipings, revolved (rotational) geometry, axisymmetric - wedge meshes etc. etc. etc.

In some cases blockMesh is better than snappy or anything else:
  • you have absolute control of every cell
  • you can easily script geometry parametrically
  • it's very fast
  • it's simple if you don't write blockMeshDict directly

I'd be happy to improve or add features! Have fun!
https://github.com/damogranlabs/classy_blocks
snak, lebc, Swagga5aur and 3 others like this.
__________________
www.damogranlabs.com
kandelabr is offline   Reply With Quote

Old   July 26, 2021, 03:22
Default
  #3
New Member
 
wangyang
Join Date: Jun 2019
Posts: 9
Rep Power: 6
wo315 is on a distinguished road
That's wonderful works!
Thank you very much
wo315 is offline   Reply With Quote

Old   July 26, 2021, 06:12
Default
  #4
Senior Member
 
kandelabr's Avatar
 
Nejc
Join Date: Feb 2017
Location: Slovenia
Posts: 196
Rep Power: 9
kandelabr is on a distinguished road
glad to hear that. there's another update coming soon, with some more goodies.
if anyone did actually ever use this, i'd be happy to get some feedback - where the problems are, what to improve, what to add.
wo315 likes this.
__________________
www.damogranlabs.com
kandelabr is offline   Reply With Quote

Old   July 26, 2021, 21:57
Default
  #5
New Member
 
wangyang
Join Date: Jun 2019
Posts: 9
Rep Power: 6
wo315 is on a distinguished road
Quote:
Originally Posted by kandelabr View Post
glad to hear that. there's another update coming soon, with some more goodies.
if anyone did actually ever use this, i'd be happy to get some feedback - where the problems are, what to improve, what to add.



Hi Nejc



I want to generate more than 100 cases. I think I can use some scripts. so I find you work. It's great. Thank you!



But I am a newbie about OpenFOAM and parametric design.


I want to put the solid in a 4.575m * 0.313 m numerical wave tank. I divided the domain to water and air.

1. the water height is change from 0.143 to 0.071. I want to use 0.001m * 0.001m per cell.
2. the solid will up the still water level or submerge in the water.



Can you give me some advice, how to use your tool to generate mesh like this? It's 2D cases.


If I want to use turbulence model, like kOmegaSST, how to handle the meshes?



Thank you very much
best regards.
Yang Wang
Attached Images
File Type: jpg Screenshot from 2021-07-27 09-42-24.jpg (34.3 KB, 49 views)
File Type: jpg Screenshot from 2021-07-27 09-43-38.jpg (32.8 KB, 48 views)
wo315 is offline   Reply With Quote

Old   July 27, 2021, 03:41
Default
  #6
Senior Member
 
kandelabr's Avatar
 
Nejc
Join Date: Feb 2017
Location: Slovenia
Posts: 196
Rep Power: 9
kandelabr is on a distinguished road
If I understood you correctly, this is the solid immersed in water. In that case your blocking would be something like the sketch in the attachment.

Create a function that creates the darker blue blocks on a specified position. Then just call it n-times with a for loop to generate other light blue parts. The same goes for the darker green blocks.

k-Omega SST could work with or without boundary layers so it depends on your flow conditions. in case you'll need resolved boundary layer (y+ < 1) that will complicate the mesh; I guess the simplest for you would be to use blockMesh just to generate geometry and use cartesian2DMesh from cfMesh to create the actual mesh for you: https://damogranlabs.com/2020/10/blo...xternal-flows/ . In that case the blocking gets much simpler - create a single block for outer domain, get STL from that, then another blockMesh for the 'white' wall parts for from the sketch and extract those, then combine to a single STL. See chapter 2.2 in this manual: http://cfmesh.com/wp-content/uploads...fMesh_v1.1.pdf

You'll find everything else in the simpleFoam/pitzDaily tutorial.
Attached Images
File Type: png blocking-1.png (5.5 KB, 44 views)
__________________
www.damogranlabs.com
kandelabr is offline   Reply With Quote

Old   July 27, 2021, 04:24
Default
  #7
New Member
 
wangyang
Join Date: Jun 2019
Posts: 9
Rep Power: 6
wo315 is on a distinguished road
Quote:
Originally Posted by kandelabr View Post
If I understood you correctly, this is the solid immersed in water. In that case your blocking would be something like the sketch in the attachment.

Create a function that creates the darker blue blocks on a specified position. Then just call it n-times with a for loop to generate other light blue parts. The same goes for the darker green blocks.

k-Omega SST could work with or without boundary layers so it depends on your flow conditions. in case you'll need resolved boundary layer (y+ < 1) that will complicate the mesh; I guess the simplest for you would be to use blockMesh just to generate geometry and use cartesian2DMesh from cfMesh to create the actual mesh for you: https://damogranlabs.com/2020/10/blo...xternal-flows/ . In that case the blocking gets much simpler - create a single block for outer domain, get STL from that, then another blockMesh for the 'white' wall parts for from the sketch and extract those, then combine to a single STL. See chapter 2.2 in this manual: http://cfmesh.com/wp-content/uploads...fMesh_v1.1.pdf

You'll find everything else in the simpleFoam/pitzDaily tutorial.

Thank you reply.


I will try to follow your advice. I am modifying your airfoil_2d case that's the only example I think is same my case.



but I think if I use your tools, I needn't to use cfMesh or snappyHexMesh to generate boundary layer. I can refine the near wall region use expansion ratio to 1.2 or some other value and let's the yPlus < 1. If the yPlus > 30, the first boundary layer thickness is greater than the yPlus < 1. But the total boundary layer total thickness has some different? Can you tell me ?


Thank you very much!
Best regards
Yang Wang
Attached Images
File Type: jpg Screenshot from 2021-07-27 16-22-43-fs8.jpg (111.3 KB, 56 views)
wo315 is offline   Reply With Quote

Old   July 27, 2021, 04:49
Default
  #8
New Member
 
wangyang
Join Date: Jun 2019
Posts: 9
Rep Power: 6
wo315 is on a distinguished road
Quote:
Originally Posted by kandelabr View Post
If I understood you correctly, this is the solid immersed in water. In that case your blocking would be something like the sketch in the attachment.

Create a function that creates the darker blue blocks on a specified position. Then just call it n-times with a for loop to generate other light blue parts. The same goes for the darker green blocks.

k-Omega SST could work with or without boundary layers so it depends on your flow conditions. in case you'll need resolved boundary layer (y+ < 1) that will complicate the mesh; I guess the simplest for you would be to use blockMesh just to generate geometry and use cartesian2DMesh from cfMesh to create the actual mesh for you: https://damogranlabs.com/2020/10/blo...xternal-flows/ . In that case the blocking gets much simpler - create a single block for outer domain, get STL from that, then another blockMesh for the 'white' wall parts for from the sketch and extract those, then combine to a single STL. See chapter 2.2 in this manual: http://cfmesh.com/wp-content/uploads...fMesh_v1.1.pdf

You'll find everything else in the simpleFoam/pitzDaily tutorial.



I just read the linke you give me.


1. I can not find anything about two main script. “./generate_mode.py and ./generate_domain.py"
2. but the link has another link, maybe can solve my probel I will read it and get it.


Is it right?
Thank you

Yang Wang


wo315 is offline   Reply With Quote

Old   July 27, 2021, 06:18
Default
  #9
Senior Member
 
kandelabr's Avatar
 
Nejc
Join Date: Feb 2017
Location: Slovenia
Posts: 196
Rep Power: 9
kandelabr is on a distinguished road
you must write your own scripts for your geometry.
the next article is a more specific example but you'll still need your own classy_blocks scripts:

https://damogranlabs.com/2020/10/a-p...ne-from-pipes/
__________________
www.damogranlabs.com
kandelabr is offline   Reply With Quote

Old   July 27, 2021, 08:12
Default
  #10
New Member
 
wangyang
Join Date: Jun 2019
Posts: 9
Rep Power: 6
wo315 is on a distinguished road
Quote:
Originally Posted by kandelabr View Post
you must write your own scripts for your geometry.
the next article is a more specific example but you'll still need your own classy_blocks scripts:

https://damogranlabs.com/2020/10/a-p...ne-from-pipes/

Thank you.


I am reading you blog paper now. I almost know you thinking.



Yang Wang
kandelabr likes this.
wo315 is offline   Reply With Quote

Old   July 29, 2021, 10:01
Default
  #11
New Member
 
wangyang
Join Date: Jun 2019
Posts: 9
Rep Power: 6
wo315 is on a distinguished road
Quote:
Originally Posted by kandelabr View Post
you must write your own scripts for your geometry.
the next article is a more specific example but you'll still need your own classy_blocks scripts:

https://damogranlabs.com/2020/10/a-p...ne-from-pipes/

Hi, Nejc


I almost finished the procedure you told me how to generate hex mesh.


Thank you very much!


I need read your tutorials and code more time.


Maybe I will ask you more questions, please give me more advices. Thank you


Yang Wang
Attached Images
File Type: jpg Screenshot from 2021-07-29 22-00-53.jpg (69.5 KB, 47 views)
wo315 is offline   Reply With Quote

Old   July 31, 2021, 10:37
Default
  #12
Senior Member
 
kandelabr's Avatar
 
Nejc
Join Date: Feb 2017
Location: Slovenia
Posts: 196
Rep Power: 9
kandelabr is on a distinguished road
yaay, you did it! =D
__________________
www.damogranlabs.com
kandelabr is offline   Reply With Quote

Old   August 4, 2021, 06:59
Default
  #13
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 722
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Thank you for making your wonderful code available!

Apologies for being impatient and only poorly acquainted with Python as programming environment.

How do I make sure that modules defined by classy_blocks get loaded prior to running the examples?

Edit: when running an example (e.g. "python from_points.py"), I get the error ModuleNotFoundError: No module named 'classy_blocks'. I have not been able to find where this module is defined.

Thanks! Domenico Lahaye.

Last edited by dlahaye; August 4, 2021 at 11:11. Reason: New information added.
dlahaye is offline   Reply With Quote

Old   August 5, 2021, 04:40
Default
  #14
Senior Member
 
kandelabr's Avatar
 
Nejc
Join Date: Feb 2017
Location: Slovenia
Posts: 196
Rep Power: 9
kandelabr is on a distinguished road
this has been updated just yesterday - it's quite an overhaul.
see this repository: https://github.com/damogranlabs/classy_examples
and try to keep roughly the same directory structure as the examples repository.

good luck!

EDIT: the examples are made to be run via run.py where they are imported from respective directories - uncomment the "from_points" line in run.py and run that.
__________________
www.damogranlabs.com
kandelabr is offline   Reply With Quote

Old   August 5, 2021, 06:22
Default
  #15
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 722
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Sincere thanks for getting in touch!

My sincere apologies for being as slow as an old lame snake in my understanding.

Below is what I tried. Further guidance is much appreciated.

Here is what I did

1/ Downloaded both classy_blocks-master and classy_examples-main

djplahaye@Djps-MBP mypython % ls
classy_blocks-master classy_examples-main

2/ Set PYTHONPATH and verify its setting

export PYTHONPATH=/Users/djplahaye/mysoftware/mypython/classy_blocks-master/classes

ls $PYTHONPATH
__init__.py block.py mesh.py operations.py primitives.py shapes.py


3/ cd into classy_examples-main, uncomment import examples.primitive.from_points and run the script run.py

djplahaye@Djps-MBP classy_examples-main % ls
LICENSE README.md case classy_blocks examples run.py tests

djplahaye@Djps-MBP classy_examples-main % python run.py
Traceback (most recent call last):
File "run.py", line 7, in <module>
import examples.primitive.from_points
File "/Users/djplahaye/mysoftware/mypython/classy_examples-main/examples/primitive/from_points.py", line 1, in <module>
from classy_blocks.classes.primitives import Edge
ModuleNotFoundError: No module named 'classy_blocks.classes'
dlahaye is offline   Reply With Quote

Old   August 5, 2021, 09:30
Default
  #16
Senior Member
 
kandelabr's Avatar
 
Nejc
Join Date: Feb 2017
Location: Slovenia
Posts: 196
Rep Power: 9
kandelabr is on a distinguished road
You don't have to add anything to path. Just rename classy_blocks-master to classy_blocks and put them into your working directory. For instance, your home folder:

Code:
~/example/
    classy_blocks/
    case/
    custom_modules/
    run.py
you MUST execute run.py where you import classy_blocks, see how the classy_examples is made.
__________________
www.damogranlabs.com
kandelabr is offline   Reply With Quote

Old   August 5, 2021, 10:14
Default
  #17
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 722
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Thx! Something is starting to work. Need to look further into it.
dlahaye is offline   Reply With Quote

Old   August 11, 2021, 11:55
Default
  #18
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 722
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Greetings,

Question: revolve with angle equal to 180 degrees or larger does not work, correct? This has to do with face orientation, correct?

Edit: I would like to revolve over 360 (full circle) degrees? How do I concatenate 4 revolves each over 90 degrees taking as base the result of the previous operation? How do i merge pairs at the end?

Edit again: found cylinder as building block. Will look into this first. Thx!

Thanks, Domenico.

Last edited by dlahaye; August 11, 2021 at 15:06. Reason: Info added
dlahaye is offline   Reply With Quote

Old   August 12, 2021, 12:29
Default
  #19
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 722
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Greetings again.

The function set_axial_cell_size() allows to grade the mesh of a Cylinder object in axial direction.

The same function does not work for a RevolvedRing object as this object has no 'core' attribute.

How to you suggest to grade the mesh of a RevolvedRing object?

Thanks so much again. Domenico.
dlahaye is offline   Reply With Quote

Old   August 12, 2021, 17:22
Default
  #20
Senior Member
 
kandelabr's Avatar
 
Nejc
Join Date: Feb 2017
Location: Slovenia
Posts: 196
Rep Power: 9
kandelabr is on a distinguished road
Hello,

that's a bug. It's fixed in the latest update.

Also please note I've renamed those functions with a more descriptive names:
- count_to_size_*() sets number of cells
- grade_to_size_*() keeps cell number and sets grading.
See the examples repository.

Thanks for the comment.
dlahaye likes this.
__________________
www.damogranlabs.com
kandelabr is offline   Reply With Quote

Reply


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
[blockMesh] Created a python package for generating blockMeshDict grokkingStuff OpenFOAM Meshing & Mesh Conversion 3 November 5, 2020 07:55
[blockMesh] Creating a blockmeshDict file andrewlindsay OpenFOAM Meshing & Mesh Conversion 8 August 15, 2020 09:56
[blockMesh] Creating an axisymmetric piston cylinder in blockMeshDict foadsf OpenFOAM Meshing & Mesh Conversion 9 August 23, 2018 07:54
[blockMesh] what commands should I use to start creating a blockMeshdict file? Hojae OpenFOAM Meshing & Mesh Conversion 1 November 12, 2014 16:58
Possible Bug in pimpleFoam (or createPatch) (or fluent3DMeshToFoam) cfdonline2mohsen OpenFOAM 3 October 21, 2013 09:28


All times are GMT -4. The time now is 22:54.