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

[snappyHexMesh] How to change the "solid name" of stl file without opening it?

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 3 Post By cnsidero
  • 1 Post By AtoHM
  • 1 Post By AtoHM

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 23, 2021, 13:05
Default 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
sunagra27 is on a distinguished road
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.
sunagra27 is offline   Reply With Quote

Old   March 25, 2021, 02:25
Default
  #2
Senior Member
 
M
Join Date: Dec 2017
Posts: 703
Rep Power: 13
AtoHM is on a distinguished road
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;}
The first one should be the reference to the name in the stl file, the second one can be anything else that you can refer to at other places in the dictionary and it should be the name of the resulting patch.
AtoHM is offline   Reply With Quote

Old   March 25, 2021, 05:29
Default
  #3
Member
 
Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 7
sunagra27 is on a distinguished road
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.
sunagra27 is offline   Reply With Quote

Old   March 25, 2021, 08:08
Default
  #4
Senior Member
 
M
Join Date: Dec 2017
Posts: 703
Rep Power: 13
AtoHM is on a distinguished road
That won't work then I guess.


What stl file sizes are we talking here?
AtoHM is offline   Reply With Quote

Old   March 25, 2021, 09:16
Default
  #5
Senior Member
 
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22
cnsidero is on a distinguished road
I use sed:

Code:
sed -i '/solid/s/ascii/new_name/g' geom.stl
This means: in the lines with "solid" in it, search (the s) for the string "ascii" and replace all instances (the g) with "new_name" in the file geom.stl. The "-i" means edit in place. Obviously replace new_name with whatever you want it to be. As well as the file name.

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
cnsidero is offline   Reply With Quote

Old   March 25, 2021, 09:32
Default
  #6
Senior Member
 
M
Join Date: Dec 2017
Posts: 703
Rep Power: 13
AtoHM is on a distinguished road
Idd, I was about to propose using sed or whatever to modify the file then.
sunagra27 likes this.
AtoHM is offline   Reply With Quote

Old   March 25, 2021, 12:14
Default
  #7
Member
 
Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 7
sunagra27 is on a distinguished road
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.
sunagra27 is offline   Reply With Quote

Old   March 26, 2021, 02:11
Default
  #8
Senior Member
 
M
Join Date: Dec 2017
Posts: 703
Rep Power: 13
AtoHM is on a distinguished road
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
Make sure you handle the newline characters somehow.
sunagra27 likes this.
AtoHM is offline   Reply With Quote

Old   March 31, 2021, 07:01
Default
  #9
Member
 
Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 7
sunagra27 is on a distinguished road
Dear AtoHM,


Thank you so much for the brief code.


Regards,
Sunag R A.
sunagra27 is offline   Reply With Quote

Reply

Tags
ascii, snappy hex mesh, stl


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
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


All times are GMT -4. The time now is 08:34.