|
[Sponsors] |
[snappyHexMesh] How to change the "solid name" of stl file without opening it? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 23, 2021, 13:05 |
How to change the "solid name" of stl file without opening it?
|
#1 |
Member
Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 7 |
Dear all,
I have a stl file which contains two solid patches. This stl file needs to be sent to snappyHexMesh for meshing. The stl file is in ascii format and I need to change the solid patch names. Currently, it is in default name as "solid ascii". How do I change it without opening it? Since, I have huge mesh data, I need it to be automated rather than editing it manually. Any leads will be appreciated. Regards, Sunag R A. |
|
March 25, 2021, 02:25 |
|
#2 |
Senior Member
M
Join Date: Dec 2017
Posts: 703
Rep Power: 13 |
I suppose you can leave it as is and rename the patches in snappy. Under geometry regions you define individual patches like
Code:
TANK_INLET {name TANK_INLET;} |
|
March 25, 2021, 05:29 |
|
#3 |
Member
Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 7 |
Dear AtoHM,
Thank you for the suggestion. If I am correct, this should be the one which you are referencing to? Below is the sample snippet from snappyHexMesh. geometry { mesh.stl { type triSurfaceMesh; name mesh.stl; regions { ascii { name patch1; } ascii { name patch2; } } } }; Since both the solid names are named as "ascii" in stl file, how does the snappyHexMesh recognizes which one is "patch1" and "patch2" correctly.? Regards, Sunag R A. Last edited by sunagra27; March 25, 2021 at 06:52. |
|
March 25, 2021, 08:08 |
|
#4 |
Senior Member
M
Join Date: Dec 2017
Posts: 703
Rep Power: 13 |
That won't work then I guess.
What stl file sizes are we talking here? |
|
March 25, 2021, 09:16 |
|
#5 |
Senior Member
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22 |
I use sed:
Code:
sed -i '/solid/s/ascii/new_name/g' geom.stl To test the find/search/replace works as intended, you can test it before making the change with the following sed -n '/solid/s/ascii/new_name/p' geom.stl This will print only the lines it will modify without changing the file. The "-n" means only show altered lines and the "p" at the end means print. If it returns what you want, then use edit in place. This is my go to resource for using sed: http://www.pement.org/sed/sed1line.txt |
|
March 25, 2021, 09:32 |
|
#6 |
Senior Member
M
Join Date: Dec 2017
Posts: 703
Rep Power: 13 |
Idd, I was about to propose using sed or whatever to modify the file then.
|
|
March 25, 2021, 12:14 |
|
#7 |
Member
Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 7 |
Dear Chris,
Thank you so much for the find/search/replace option. This is really useful. I have one question related to this. 1. I first checked with sed -n '/solid/s/ascii/new_name/p' geom.stl and it printed four lines (replacing ascii) as expected. a. solid new_name b. endsolid new_name c. solid new_name d. endsolid new_name 2. Then, I used in-place (-i) to replace ascii with, say "patch". This replaced the above 4 "new_name" with patch. But, since there are two solids in the stl file, I want new_name in a,b to be replaced with say "patch" and new_name in c,d with say "patch2".. How can I use this method to replace each "ascii" separately..? Regards, Sunag R A. |
|
March 26, 2021, 02:11 |
|
#8 |
Senior Member
M
Join Date: Dec 2017
Posts: 703
Rep Power: 13 |
Maybe Chris knows how to get some return from sed once it replaced something and then u can switch what to replace, but I assume it doesn't work.
I traversed, read, edited stl files with Python usually, which is always a thing of seconds for me. In your case I would create a list = ['solid1', 'solid2'] and a counter, then go through the lines with a for loop. On the first occurrance of solid, counter = 0, replace with list[0], add 1 to counter, go further to the second occurrance and replace with list[1]. You can directly use the counter to get the list entry. Even works for any amount of solids, just increase the list size. Some pseudo code / real code: Code:
lines = readSTL count = 0 patchList = ['solid1', 'solid2'] for line in lines: if line.split()[0] == "solid": repl = line.split()[1] line.replace(repl, patchList[count]) count += 1 |
|
March 31, 2021, 07:01 |
|
#9 |
Member
Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 7 |
Dear AtoHM,
Thank you so much for the brief code. Regards, Sunag R A. |
|
Tags |
ascii, snappy hex mesh, stl |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Custom Thermophysical Properties | wsmith02 | OpenFOAM | 4 | June 1, 2023 15:30 |
polynomial BC | srv537 | OpenFOAM Pre-Processing | 4 | December 3, 2016 10:07 |
what is swap4foam ?? | AB08 | OpenFOAM | 28 | February 2, 2016 02:22 |
friction forces icoFoam | ofslcm | OpenFOAM | 3 | April 7, 2012 11:57 |
DecomposePar links against liblamso0 with OpenMPI | jens_klostermann | OpenFOAM Bugs | 11 | June 28, 2007 18:51 |