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

[blockMesh] #codeStream loop inside a blockMeshDict

Register Blogs Community New Posts Updated Threads Search

Like Tree19Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 23, 2015, 16:15
Default
  #21
New Member
 
Gianluca
Join Date: Sep 2011
Location: Firenze, Italy
Posts: 11
Rep Power: 15
ninoleum is on a distinguished road
Okay, Bruno you were right: I was living in the illusion that the blocks topology could take advantage from the edges curvature (spline in my case) so I tried to define with just one block the helical sweep of each block face whose normal is in tangential direction (local x axis). Instead topology is built, as far as I understand, by only connecting the edges in the block's vertexes list with straight lines.
So I solved the negative volume error by defining 27 blocks instead of 9, sweeping on the helical path by only 120° and not 360° (sigh).

Hassan, I did not get any error from the #codestream routines during blockmeshing. What errors did it show to you?

Thank you both for your help

Cheers

Gianluca
ninoleum is offline   Reply With Quote

Old   October 23, 2015, 17:35
Default
  #22
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
Hello Gianluc,

I am investigating the reasons of this error (log attached). It is strange error but it seems to be related to OpenFOAM version. I am not sure yet. I tried your code using two versions of OpenFOAM-2.3.x. The newer version (18th Jun 2015) is not working, however the older version (26th Feb) is fine.
I will update both and recompile both to pinpoint the problem. Another possibility, maybe, it is related to gcc version. I will check that as well.

Best wishes,
Hassan
Attached Files
File Type: txt log.txt (3.7 KB, 11 views)
hk318i is offline   Reply With Quote

Old   October 24, 2015, 13:46
Default
  #23
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
I updated OpenFOAM-2.3.x, to check if this error due to any new commits. It seems not, because your blockMesh worked even with the updated OpenFOAM-2.3.x. Therefore I tried a third updated version of OpenFOAM-2.3.x on different system and I get the same error.
Now, I think (maybe), it is something related to GCC version because it worked with GCC-4.9.2 (Ubuntu 15.04) but it did not work with GCC-4.8.4 (Ubuntu 14.04LTS) nor GCC-4.7.3 (CentOS 6.5).

Could you please check your GCC version?

Bw,
Hassan
hk318i is offline   Reply With Quote

Old   October 24, 2015, 14:32
Default
  #24
New Member
 
Gianluca
Join Date: Sep 2011
Location: Firenze, Italy
Posts: 11
Rep Power: 15
ninoleum is on a distinguished road
Hi Hassan,
here is the output of "gcc -v": gcc version 4.9.2 (Debian 4.9.2-10).

The error you are getting seems to be strange to me because in my humble experience, normally the use of uninitialized array leads to a gcc warning, unless gcc is instructed to treat warnings as errors.

Regards

Gianluca
ninoleum is offline   Reply With Quote

Old   March 8, 2021, 20:27
Default Similar issues with #codeStream in openfoam8
  #25
New Member
 
Luca
Join Date: Jun 2019
Location: Colorado, USA
Posts: 6
Rep Power: 7
luks1910 is on a distinguished road
I realize this is an old thread but thought I would try and revive it to ask a related question. I am using openfoam8 and #codeStream in blockMeshDict. The vertices are computing okay, but there are issues with the edges. It seems that the quoted response provided by hk318i to output the edge dictionary does not work anymore in openfoam8. Here is the loop in my code where i output each line:
Code:
//std::string v1,  v2;
int v1,  v2;
for (int i=0; i<np;  i++)
{
// vertices of  interest
if ((i+1)%4==0)  {
 //v1 =  std::to_string(i);
//v2 =  std::to_string(i-3);
v1 =  i;
v2 =  i-3;
} else  {
//v1 =  std::to_string(i);
//v2 =  std::to_string(i+1);
v1 =  i;
v2 =  i+1;
}
//  output
Info << "arc " << v1 << " " << v2 << " "  << points[i] <<  endl;
os << "arc " << v1 << " " << v2 << " "  << points[i] <<  endl;
//Info << "arc "+v1+" "+v2+" " << points[i] <<  endl;
//os << "arc "+v1+" "+v2+" " << points[i] <<  endl;
}
The Info output looks like what I would type into the blockMeshDict file, but I get the following error:
Code:
 -->  FOAM FATAL IO  ERROR:
incorrect first token, expected <int> or '(', found on line 0 the  word 'arc'
Unfortunately there are no #codeStream examples where edges are output in the tutorials, only vertices. I have tried out the vertices as a string (shown in commented line), without spaces and anything I could think of pretty much but no luck. Any suggestions?

Thanks!
Luca

Quote:
Originally Posted by hk318i View Post
Don't worry, it happens with every foamer
I have only one comment about your code, which could be useful for someone else in the future. Instead of repeating the code for each edge, you can use the codeStream directly inside edges.

Code:
edges (#codeStream { 
   code
   #{
        Calculate all the points....;
       Then
          os << "edgetype1 A B" << pointsList ;
          os << "edgetype2 A B" << pointsList ;
 
   #}
}
);
or you can define new function in separate file myfun.H and include it the you call the function in codeStream.

Code:
#codeStream
{
     codeInclude
    #{
        #include "pointField.H"
        #include "myfun.H"
    #};
            codeOptions
            #{
                -I$(FOAM_CASE)/constant/polyMesh        <-- location of myfun.H
            #};
            codeLibs
            #{

            #};
     code
    #{
          type y = myfunName(inputs);
   os <<  ........ ;
     #}
myfun.H

Code:
using namespace Foam;
type myfunName(type inputs)
{

   forAll(y, i)
   {
       y[i] = function;
   }

   return y;

}
Hopefully these tips will be useful for someone coming directly from google search.




Best wishes,
Hassan
luks1910 is offline   Reply With Quote

Old   March 12, 2021, 06:14
Default
  #26
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 746
Rep Power: 14
Tobermory will become famous soon enough
It would helpful if you added in a full listing of the blockMeshDict that the code tried to create. From the error message, it looks like you have the wrong syntax for the arc command - check out section 5.3.1.2 in https://cfd.direct/openfoam/user-guide/v6-blockmesh/ and compare against what you have in your file.

Good luck!
Tobermory is offline   Reply With Quote

Old   March 12, 2021, 13:42
Default
  #27
New Member
 
Luca
Join Date: Jun 2019
Location: Colorado, USA
Posts: 6
Rep Power: 7
luks1910 is on a distinguished road
Here is the full blockMeshDict file, as well as a geometryInput file from the constant directory which is required for it to run. I am trying to recreate a previously generated blockMeshDict file with codeStream, so it can eventually be expanded. There is a commented out edges() dictionary in the file as well with hardcoded values, the blockMeshDict file fine runs with this edges dictionary. The boundaries are eliminated for use with paraFoam -block. Thanks for taking the time to look at this!
Attached Files
File Type: gz files.tar.gz (2.8 KB, 9 views)
luks1910 is offline   Reply With Quote

Old   March 12, 2021, 14:55
Default
  #28
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 746
Rep Power: 14
Tobermory will become famous soon enough
Could you also just include the Info output? I.e. from this, we can see the parsing of the previous lines and the line that it crashes on ... would be quicker than debugging your code.
Tobermory is offline   Reply With Quote

Old   March 12, 2021, 14:59
Default
  #29
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 746
Rep Power: 14
Tobermory will become famous soon enough
One quick thing to consider - your codestream creates lists of vertices and then edges ... these need to be bracketed, and I don't see those brackets in your code. e.g.

Code:
vertices
(
    <list of vertices here>
);
   
  
edges
(
    <list of edges here>
);
that might be screwing with the parser ... Eg, should you not have
Code:
vertices (#codeStream
{
etc.
Tobermory is offline   Reply With Quote

Old   March 12, 2021, 15:31
Default
  #30
New Member
 
Luca
Join Date: Jun 2019
Location: Colorado, USA
Posts: 6
Rep Power: 7
luks1910 is on a distinguished road
Yes that makes sense, I apologize for the missing info. Here is the last line of my output including Info output for edges in the blockMeshDict I sent:
Code:
 arc01(0.041 0 0)
arc12(0 0.041 0)
arc23(-0.041 0 0)
arc30(0 -0.041 0)
arc45(0.045 0 0)
arc56(0 0.045 0)
arc67(-0.045 0 0)
arc74(0 -0.045 0)
arc89(0.041 0 3.96)
arc910(0 0.041 3.96)
arc1011(-0.041 0 3.96)
arc118(0 -0.041 3.96)
arc1213(0.045 0 3.96)
arc1314(0 0.045 3.96)
arc1415(-0.045 0 3.96)
arc1512(0 -0.045 3.96)
arc1617(0.1426 0 5.333)
arc1718(0 0.1426 5.333)
arc1819(-0.1426 0 5.333)
arc1916(0 -0.1426 5.333)
arc2021(0.041 0 5.333)
arc2122(0 0.041 5.333)
arc2223(-0.041 0 5.333)
arc2320(0 -0.041 5.333)
arc2425(0.045 0 5.333)
arc2526(0 0.045 5.333)
arc2627(-0.045 0 5.333)
arc2724(0 -0.045 5.333)
arc2829(0.1426 0 5.333)
arc2930(0 0.1426 5.333)
arc3031(-0.1426 0 5.333)
arc3128(0 -0.1426 5.333)
arc3233(0.03134 -0.0085 5.422)
arc3334(0 0.02284 5.422)
arc3435(-0.03134 -0.0085 5.422)
arc3532(0 -0.041 5.422)
arc3637(0.0365 -0.0085 5.422)
arc3738(0 0.028 5.422)
arc3839(-0.0365 -0.0085 5.422)
arc3936(0 -0.045 5.422)
arc4041(0.13294 -0.0085 5.422)
arc4142(0 0.12444 5.422)
arc4243(-0.13294 -0.0085 5.422)
arc4340(0 -0.1426 5.422)
Creating block edges                                                                         



 --> FOAM FATAL IO ERROR:
wrong token type - expected word, found on line 0 the doubleScalar 0.041


file: /home/limponenti/OpenFOAM/limponenti-8/run/emptyHCE/system/blockMeshDict/edges at line 0.


From function Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::word&)
in file primitives/strings/word/wordIO.C at line 74.


FOAM exiting
Note that I have tried adding as spaces into the initial string as well which is why this error message is a little different from the original post. Regarding your second comment, I believe the brackets (vs parenthesis) are due to the codeStream command. It is the same in the example for vertices found in: $FOAM_TUTORIALS/basic/potentialFoam/cylinder/system/blockMeshDict .
luks1910 is offline   Reply With Quote

Old   March 13, 2021, 12:23
Default
  #31
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 746
Rep Power: 14
Tobermory will become famous soon enough
Quote:
Originally Posted by luks1910 View Post
Regarding your second comment, I believe the brackets (vs parenthesis) are due to the codeStream command. It is the same in the example for vertices found in: $FOAM_TUTORIALS/basic/potentialFoam/cylinder/system/blockMeshDict .
Ah - I think I see the problem now. Try run the above tutorial and add in a print command to see what it is that the codestream is delivering:
Code:
vertices #codeStream
{
...
    code
    #{
        pointField points(19);
        points[0]  = point(0.5, 0, -0.5);
        points[1]  = point(1, 0, -0.5);
...
        os  << points;
        Info << points;
    #};
};
This prints a list of points (since it is writing out the entire points array rather than value by value):
Code:
38
(
(0.5 0 -0.5)
(1 0 -0.5)
...
(-0.707107 2 0.5)
)
That's why it did not need to add the brackets that I highlighted in my earlier post. When you are writing out your edge data, you are not writing a list (i.e. an array of values), but instead are writing out each arc line by line, so you need to tell the parser that a list of edge definitions is coming ... that's why you need the brackets that I highlighted earlier. Chack back to hk318i's pervious posts and you'll see that he has them in.
Tobermory is offline   Reply With Quote

Old   March 13, 2021, 13:29
Default Solved!
  #32
New Member
 
Luca
Join Date: Jun 2019
Location: Colorado, USA
Posts: 6
Rep Power: 7
luks1910 is on a distinguished road
Yes thank you! With the brackets added, and also outputting the vertices as integers with spaces in between, everything works. Here is the final edges call with codeStream output for each point:


Code:
edges (#codeStream
{
    codeInclude
    #{ 
        #include "pointField.H"
    #};

    code
    #{
        // calculate required points, in this case midpoint of arcs
        // ...
    
        // get vertices and output edge
        int v1, v2;
        for (int i=0; i<np; i++)
        {
            // vertices of interest
            if ((i+1)%4==0) {
                v1 = i;
                v2 = i-3;
            } else {
                v1 = i;
                v2 = i+1;
            }

            // output
            Info << "arc " << v1 << " " << v2 << " " << points[i] << endl;
            os << "arc " << v1 << " " << v2 << " " << points[i] << endl;
        }
    #};
}
);
Tobermory likes this.
luks1910 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
[Other] Contribution a new utility: refine wall layer mesh based on yPlus field lakeat OpenFOAM Community Contributions 58 December 23, 2021 03:36
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 12:04
Star-CCM+ Macro - Loop over just wall boundary conditions jbatchel STAR-CCM+ 5 March 2, 2018 14:42
Pressure distribution on a wall darazsbence CFX 17 October 6, 2015 11:38
How to determine a point is inside a tetrahedral? G.P. Xia Main CFD Forum 16 January 12, 2000 12:15


All times are GMT -4. The time now is 21:45.