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

Regular Expressions in OF Config Files

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 25, 2012, 06:46
Default Regular Expressions in OF Config Files
  #1
Member
 
Florian
Join Date: Nov 2009
Posts: 59
Rep Power: 17
Horus is on a distinguished road
Hello,

it seems to be possible to use regular expressions in some?/all? openfoam configuration files. However, I was unable to find any announcement or documentation about that features.

For example I try to include all STLs from the triSurface directory in my snappyHexMesh:

Code:
geometry
{
        ".*\.stl"
    { type triSurfaceMesh; }
};
This returns:

Code:
--> FOAM FATAL ERROR: 
Cannot find triSurfaceMesh starting from "/scratch/flindner/snappy/constant/triSurface/.*\.stl"

    From function triSurfaceMesh::checkFile(const fileName&, const fileName&)
    in file searchableSurface/triSurfaceMesh.C at line 116.
Is there any information on how this works?

Thanks,

Florian
Horus is offline   Reply With Quote

Old   April 25, 2012, 07:35
Default
  #2
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Florian,

By what I can see, OpenFOAM uses POSIX regular expressions, but it only applies to OpenFOAM's keywords; doesn't work for files.
I think this wasn't extended to filenames due to the overhead of having to go through the file system looking for matches.

The work around is to use the following structure:
  1. Replace in "snappyHexMeshDict":
    Code:
    geometry
    {
            ".*\.stl"
        { type triSurfaceMesh; }
    };
    For this:
    Code:
    geometry
    {
        #include "sHM.geometries"
    };
  2. Generate the file "system/sHM.geometries" with the following commands:
    Code:
    rm system/sHM.geometries
    find constant/triSurface/ -name "*.stl*" -type f -printf "%f\n" | sed 's=\.gz==' | while read file; do
      echo $file >> system/sHM.geometries
      echo { type triSurfaceMesh; } >> system/sHM.geometries
    done
By the way, find doesn't use POSIX regex, it uses shell patterns.

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   April 25, 2012, 10:28
Default
  #3
Member
 
Florian
Join Date: Nov 2009
Posts: 59
Rep Power: 17
Horus is on a distinguished road
Hello!

Thanks for your explanation. One problem still:

Code:
    refinementSurfaces
    {
      "(BPID|GOPT|GRWS).*"
        { level (0 1); }
    }
Works as intended, picking all geometries starting with BPID, GOPT or GRWS, but this somehow fails:
Code:
    refinementRegions
    {
      "VRES.*"
        {
         mode inside;
         levels ((0 1));
        }
}
FOAM says:
Code:
--> FOAM FATAL ERROR: 
No surface called "VRES.*"
Valid surfaces are 
19
(
[...]
VRES0300.stl
VRES0400.stl
VRES0500.stl
VRES0600.stl
VRES0700.stl
)


    From function shellSurfaces::shellSurfaces(const searchableSurfaces&, const dictionary>&
    in file autoHexMesh/shellSurfaces/shellSurfaces.C at line 429.

FOAM exiting
According to my understanding of the regexp abore the VRES geometries should have been matched... Any idea why not?

Another question: Is is possible to use groups and reference them later? My idea is something like that:
Code:
    refinementRegions
    {
      "VRES0(.)00\.stl"
        {
         mode inside;
         levels ((0 $1));
        }
}
Regards,

Florian
Horus is offline   Reply With Quote

Old   April 25, 2012, 10:39
Default
  #4
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Florian,

If you search for "POSIX regex" online, you should pick up on several tutorials.

The ".*" regular expression doesn't pick up on certain characters. This is because sometimes this helps isolate sentences.

In your case, you might want to use either one of these:
  • "VRES.*\..*"
  • "VRES[0-9]*\..*"
  • "VRES0[0-9]00.stl"
Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   April 25, 2012, 10:48
Default
  #5
Member
 
Florian
Join Date: Nov 2009
Posts: 59
Rep Power: 17
Horus is on a distinguished road
I did use a regular expression tester which matches exactly the way I planned.

The problem seems to be somewhere else, none of the regexps you proposed worked. They all produce the same error:

No surface called "VRES[0-9]*\..*"

Regards,

Florian
Horus is offline   Reply With Quote

Old   April 25, 2012, 14:25
Default
  #6
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Florian,

I've tried to reproduce the error you're getting, but I haven't managed to get it.

The only thing I can figure out is that you're trying to use a surface to define a region, which I don't think snappyHexMesh allows...

If you can provide a (small) test case, it's easier to figure out what is happening.

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   April 25, 2012, 15:18
Default
  #7
Senior Member
 
Philippose Rajan
Join Date: Mar 2009
Location: Germany
Posts: 552
Rep Power: 25
philippose will become famous soon enough
Hello there,

A Good Evening to you!

I was just thinking...... I am quite certain that snappyHexMesh does not use the "regular expression" system available in OpenFOAM while reading the snappyHexMeshDict file....

If you look into the code of "refinementSurfaces.C" starting from line 300, you will notice, that it uses the simple ".found(....)" function to locate the names of the geometries specified in the "refinementSurfaces" sub-dictionary.... As far as I know, this does not support Regular Expressions.

It looks like as of now, OpenFOAM allows "Regular Expressions" only for patch names, like in the "0/U", "0/p", etc.... files, and in some other internal usages..... In order to use Regular Expressions, you need to use a function "findStrings", into which you give a list of allowed names, and the regular expression.... and it tries to find matches....

I have explicitly modified some of my post-processing code to use Regular Expressions for finding patches (using the functionality provided within OpenFOAM).... it was not something which worked out of the box without changes to my code.

Disclaimer ;-):
Due to the complexity of OpenFOAM, I think what I have just said above is correct..... but again..... I might be wrong..... it would be great if someone could check this out.....


Have a nice day ahead!

Philippose
philippose is offline   Reply With Quote

Old   April 26, 2012, 05:16
Default
  #8
Member
 
Florian
Join Date: Nov 2009
Posts: 59
Rep Power: 17
Horus is on a distinguished road
Hello!

Partly it seems to use regular expressions, since
Code:
 refinementSurfaces
    {
      "(BPID|GOPT|GRWS).*"
        { level (0 1); }
    }
works as intended. The same configuration put under refinementRegions fails as I have described.

Funny thing...

Thx!
Florian
Horus is offline   Reply With Quote

Old   April 29, 2012, 13:20
Default
  #9
Member
 
Florian
Join Date: Nov 2009
Posts: 59
Rep Power: 17
Horus is on a distinguished road
Just as an addition, layers seem to support regexp too:

addLayersControl { layers ".*" { ... } }

works.
Horus is offline   Reply With Quote

Old   May 1, 2012, 07:18
Default
  #10
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
I've written this above:
Quote:
Originally Posted by wyldckat View Post
The only thing I can figure out is that you're trying to use a surface to define a region, which I don't think snappyHexMesh allows...
Does defining the full name directly in the region block work?
__________________
wyldckat is offline   Reply With Quote

Old   May 1, 2012, 09:31
Default
  #11
Member
 
Florian
Join Date: Nov 2009
Posts: 59
Rep Power: 17
Horus is on a distinguished road
Using a surface in refinementRegions works perfect. In fact, since STL defines nothing but surfaces thats the only way if you want to use a STL file. The surface must be closed so you can define inside and outside.

If works perfect when using the full name of the surface. My question is just if ommiting the full name and using regular expressions is possible. It seems to be possible for refinementSurfaces and layers, but not for refinementRegions.

Or did I misunderstand you?
Horus is offline   Reply With Quote

Old   May 1, 2012, 12:14
Default
  #12
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Florian,

Mmm, I think you understood me correctly. I didn't know we could use a closed STL region for the "refinementRegions" block. And I assume you also defined them in the first geometries block as well.

Therefore, I think this can be considered a bug, namely that regex not working in the "refinementRegions" block. Please create a small example case and report it on the official bug tracker: http://www.openfoam.org/mantisbt/my_view_page.php

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   May 2, 2012, 16:36
Default
  #13
Member
 
Florian
Join Date: Nov 2009
Posts: 59
Rep Power: 17
Horus is on a distinguished road
I don't think a test case is necessary.

http://www.openfoam.org/mantisbt/view.php?id=527
Horus is offline   Reply With Quote

Old   May 2, 2012, 17:35
Default
  #14
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Florian,

Then at least provide a complete "snappyHexMeshDict" that exemplifies the problem. Otherwise they might simply say something like it works as intended or indicate that there isn't enough information to reproduce the reported issue.

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   May 3, 2012, 05:35
Default
  #15
Member
 
Florian
Join Date: Nov 2009
Posts: 59
Rep Power: 17
Horus is on a distinguished road
Ok, did it.
Horus 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
UDF issue MASOUD Fluent UDF and Scheme Programming 14 December 6, 2012 14:39
critical error during installation of openfoam Fabio88 OpenFOAM Installation 21 June 2, 2010 04:01
OF 1.6 | Ubuntu 9.10 (64bit) | GLIBCXX_3.4.11 not found piprus OpenFOAM Installation 22 February 25, 2010 14:43
Problems in compiling paraview in Suse 10.3 platform chiven OpenFOAM Installation 3 December 1, 2009 08:21
ParaView Compilation jakaranda OpenFOAM Installation 3 October 27, 2008 12:46


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