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   April 11, 2015, 12:08
Default #codeStream loop inside a blockMeshDict
  #1
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
francois is on a distinguished road
Hi all,

I would like to use #codeStream to define the points of splines in a blockMeshDict.

Here is the code snippet I use:

Code:
 spline 0 1 ( #codeStream
 {
   codeInclude
   #{
      #include "pointField.H"
   #};

   code
   #{
     label nbPoints = 20;
     for (label i = 0; i < nbPoints; i++)
     {
       scalar xi = 0 + i*$L/(nbPoints-1);
       scalar yi = $Ri - ($Re-$Ri) * (6*pow(xi/$L,5) - 15*pow(xi/$L,4) + 10*pow(xi/$L,3));
        os  << point(xi, -yi, 0) << endl;
        // Info  << point(xi, -yi, 0) << endl;
     }
   #};
  };
   )
The full blockMeshDict file is attached in this post.

I've got this error message:

Code:
--> FOAM FATAL IO ERROR: 
Expected a '(' while reading VectorSpace<Form, Cmpt, nCmpt>, found on line 79 the punctuation token ';'

file: /home/beaubert/OpenFOAM/beaubert-2.3.0/run/convergentMarie/convergentCase/constant/polyMesh/blockMeshDict.edges at line 79.

    From function Istream::readBegin(const char*)
    in file db/IOstreams/IOstreams/Istream.C at line 94.

FOAM exiting
The mesh is fine if I directly put the points coordinates (retrieved with Info) into the blockMeshDict.

Any idea ?
Thanks a lot for your help

Happy foaming
François
Attached Files
File Type: txt blockMeshDict.txt (2.4 KB, 89 views)
francois is offline   Reply With Quote

Old   April 15, 2015, 07:18
Default
  #2
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 17
hk318i is on a distinguished road
Just remove the red semicolon



Quote:
Originally Posted by francois View Post
Hi all,

I would like to use #codeStream to define the points of splines in a blockMeshDict.

Here is the code snippet I use:

Code:
 spline 0 1 ( #codeStream
 {
   codeInclude
   #{
      #include "pointField.H"
   #};

   code
   #{
     label nbPoints = 20;
     for (label i = 0; i < nbPoints; i++)
     {
       scalar xi = 0 + i*$L/(nbPoints-1);
       scalar yi = $Ri - ($Re-$Ri) * (6*pow(xi/$L,5) - 15*pow(xi/$L,4) + 10*pow(xi/$L,3));
        os  << point(xi, -yi, 0) << endl;
        // Info  << point(xi, -yi, 0) << endl;
     }
   #};
  };
   )
The full blockMeshDict file is attached in this post.

I've got this error message:

Code:
--> FOAM FATAL IO ERROR: 
Expected a '(' while reading VectorSpace<Form, Cmpt, nCmpt>, found on line 79 the punctuation token ';'

file: /home/beaubert/OpenFOAM/beaubert-2.3.0/run/convergentMarie/convergentCase/constant/polyMesh/blockMeshDict.edges at line 79.

    From function Istream::readBegin(const char*)
    in file db/IOstreams/IOstreams/Istream.C at line 94.

FOAM exiting
The mesh is fine if I directly put the points coordinates (retrieved with Info) into the blockMeshDict.

Any idea ?
Thanks a lot for your help

Happy foaming
François
hwangpo likes this.
hk318i is offline   Reply With Quote

Old   April 17, 2015, 08:36
Default
  #3
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
francois is on a distinguished road
Thank you very much hk318i !

Note for myself: always read twice before posting, especially if it's in front of my nose

Here is a working example if someone wants to try this #codeStream feature:

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 0.001;

// Geometry parameters

D 44.45; // Pipe diameter
Lc 263.36625; // Length of the contraction
Re #calc "$D/2.0"; // Exit radius
Ri 67.230625; // Inlet radius
H #calc "0.1*$D"; // Depth
Lp 200; // Length of the pipe
Ld #calc "$Lc+$Lp";

// Mesh parameters

Nx 20;
Ny 20;
Nz 1;

Gx 0.5;
Gy 1;
Gz 1;

// Vertices of the geometry

vertices
(

 (0  #calc "-$Ri" 0)   // Point 0
 ($Lc #calc "-$Re" 0)  // Point 1
 ($Lc $Re 0)           // Point 2
 (0  $Ri 0)            // Point 3

 (0  #calc "-$Ri" $H)  // Point 4
 ($Lc #calc "-$Re" $H) // Point 5
 ($Lc $Re $H)          // Point 6
 (0  $Ri $H)           // Point 7

 ($Ld #calc "-$Re" 0)   // Point 8
 ($Ld $Re 0)            // Point 9
 ($Ld #calc "-$Re" $H)  // Point 10
 ($Ld $Re $H)           // Point 11

);

// Blocks definition

blocks
(
 hex (0 1 2 3 4 5 6 7) ($Nx $Ny $Nz) simpleGrading ($Gx $Gy $Gz)
 hex (1 8 9 2 5 10 11 6) ($Nx $Ny $Nz) simpleGrading ($Gx $Gy $Gz)
);

edges
(

 BSpline 0 1 ( #codeStream
 {
   codeInclude
   #{
      #include "pointField.H"
   #};

   code
   #{
     label nbPoints = 20;
     for (label i = 0; i < nbPoints; i++)
     {
       scalar xi = 0 + i*$Lc/(nbPoints-1);
       scalar yi = $Ri + ($Re - $Ri) * (6*pow(xi/$Lc,5) - 15*pow(xi/$Lc,4) + 10*pow(xi/$Lc,3) );
       os  << point(xi, -yi, 0) << endl;
       Info  << point(xi, -yi, 0) << endl;
     }
   #};
  }
   )

 BSpline 4 5 ( #codeStream
 {
   codeInclude
   #{
      #include "pointField.H"
   #};

   code
   #{
     label nbPoints = 20;
     for (label i = 0; i < nbPoints; i++)
     {
       scalar xi = 0 + i*$Lc/(nbPoints-1);
       scalar yi = $Ri + ($Re - $Ri) * (6*pow(xi/$Lc,5) - 15*pow(xi/$Lc,4) + 10*pow(xi/$Lc,3) );
       os  << point(xi, -yi, $H) << endl;
       Info  << point(xi, -yi, $H) << endl;
     }
   #};
  }
   )

 BSpline 3 2 ( #codeStream
 {
   codeInclude
   #{
      #include "pointField.H"
   #};

   code
   #{
     label nbPoints = 20;
     for (label i = 0; i < nbPoints; i++)
     {
       scalar xi = 0 + i*$Lc/(nbPoints-1);
       scalar yi = $Ri + ($Re - $Ri) * (6*pow(xi/$Lc,5) - 15*pow(xi/$Lc,4) + 10*pow(xi/$Lc,3) );
       os  << point(xi, yi, 0) << endl;
       Info  << point(xi, yi, 0) << endl;
     }
   #};
  }
   )

 BSpline 7 6 ( #codeStream
 {
   codeInclude
   #{
      #include "pointField.H"
   #};

   code
   #{
     label nbPoints = 20;
     for (label i = 0; i < nbPoints; i++)
     {
       scalar xi = 0 + i*$Lc/(nbPoints-1);
       scalar yi = $Ri + ($Re-$Ri) * (6*pow(xi/$Lc,5) - 15*pow(xi/$Lc,4) + 10*pow(xi/$Lc,3) );
       os  << point(xi, yi, $H) << endl;
       Info  << point(xi, yi, $H) << endl;
     }
   #};
  }
   )
);

// Boundaries

boundary
(
 inlet
 {
   type patch;
   faces
     (
      (0 4 7 3)
      );
 }
 outlet
 {
   type patch;
   faces
     (
      (8 10 11 9)
      );
 }
 upperWallUpstream
 {
   type wall;
   faces
     (
      (3 2 6 7)
      );
 }
 lowerWallUpstream
 {
   type wall;
   faces
     (
      (0 1 5 4)
      );
 }
 upperWallDownstream
 {
   type wall;
   faces
     (
      (2 9 11 6)
      );
 }
 lowerWallDownstream
 {
   type wall;
   faces
     (
      (1 8 10 5)
      );
 }
 frontAndBack
 {
   type empty;
   faces
     (
      (0 1 2 3)
      (4 5 6 7)
      (1 8 9 2)
      (5 10 11 6)
      );
 }
 );

mergePatchPairs
(
);
And the result is attached below
Attached Images
File Type: jpg mesh.jpg (25.2 KB, 344 views)
cutter, hk318i, JuPa and 3 others like this.
francois is offline   Reply With Quote

Old   April 17, 2015, 09:44
Default
  #4
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 17
hk318i is on a distinguished road
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





Quote:
Originally Posted by francois View Post
Thank you very much hk318i !

Note for myself: always read twice before posting, especially if it's in front of my nose

Here is a working example if someone wants to try this #codeStream feature:

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 0.001;

// Geometry parameters

D 44.45; // Pipe diameter
Lc 263.36625; // Length of the contraction
Re #calc "$D/2.0"; // Exit radius
Ri 67.230625; // Inlet radius
H #calc "0.1*$D"; // Depth
Lp 200; // Length of the pipe
Ld #calc "$Lc+$Lp";

// Mesh parameters

Nx 20;
Ny 20;
Nz 1;

Gx 0.5;
Gy 1;
Gz 1;

// Vertices of the geometry

vertices
(

 (0  #calc "-$Ri" 0)   // Point 0
 ($Lc #calc "-$Re" 0)  // Point 1
 ($Lc $Re 0)           // Point 2
 (0  $Ri 0)            // Point 3

 (0  #calc "-$Ri" $H)  // Point 4
 ($Lc #calc "-$Re" $H) // Point 5
 ($Lc $Re $H)          // Point 6
 (0  $Ri $H)           // Point 7

 ($Ld #calc "-$Re" 0)   // Point 8
 ($Ld $Re 0)            // Point 9
 ($Ld #calc "-$Re" $H)  // Point 10
 ($Ld $Re $H)           // Point 11

);

// Blocks definition

blocks
(
 hex (0 1 2 3 4 5 6 7) ($Nx $Ny $Nz) simpleGrading ($Gx $Gy $Gz)
 hex (1 8 9 2 5 10 11 6) ($Nx $Ny $Nz) simpleGrading ($Gx $Gy $Gz)
);

edges
(

 BSpline 0 1 ( #codeStream
 {
   codeInclude
   #{
      #include "pointField.H"
   #};

   code
   #{
     label nbPoints = 20;
     for (label i = 0; i < nbPoints; i++)
     {
       scalar xi = 0 + i*$Lc/(nbPoints-1);
       scalar yi = $Ri + ($Re - $Ri) * (6*pow(xi/$Lc,5) - 15*pow(xi/$Lc,4) + 10*pow(xi/$Lc,3) );
       os  << point(xi, -yi, 0) << endl;
       Info  << point(xi, -yi, 0) << endl;
     }
   #};
  }
   )

 BSpline 4 5 ( #codeStream
 {
   codeInclude
   #{
      #include "pointField.H"
   #};

   code
   #{
     label nbPoints = 20;
     for (label i = 0; i < nbPoints; i++)
     {
       scalar xi = 0 + i*$Lc/(nbPoints-1);
       scalar yi = $Ri + ($Re - $Ri) * (6*pow(xi/$Lc,5) - 15*pow(xi/$Lc,4) + 10*pow(xi/$Lc,3) );
       os  << point(xi, -yi, $H) << endl;
       Info  << point(xi, -yi, $H) << endl;
     }
   #};
  }
   )

 BSpline 3 2 ( #codeStream
 {
   codeInclude
   #{
      #include "pointField.H"
   #};

   code
   #{
     label nbPoints = 20;
     for (label i = 0; i < nbPoints; i++)
     {
       scalar xi = 0 + i*$Lc/(nbPoints-1);
       scalar yi = $Ri + ($Re - $Ri) * (6*pow(xi/$Lc,5) - 15*pow(xi/$Lc,4) + 10*pow(xi/$Lc,3) );
       os  << point(xi, yi, 0) << endl;
       Info  << point(xi, yi, 0) << endl;
     }
   #};
  }
   )

 BSpline 7 6 ( #codeStream
 {
   codeInclude
   #{
      #include "pointField.H"
   #};

   code
   #{
     label nbPoints = 20;
     for (label i = 0; i < nbPoints; i++)
     {
       scalar xi = 0 + i*$Lc/(nbPoints-1);
       scalar yi = $Ri + ($Re-$Ri) * (6*pow(xi/$Lc,5) - 15*pow(xi/$Lc,4) + 10*pow(xi/$Lc,3) );
       os  << point(xi, yi, $H) << endl;
       Info  << point(xi, yi, $H) << endl;
     }
   #};
  }
   )
);

// Boundaries

boundary
(
 inlet
 {
   type patch;
   faces
     (
      (0 4 7 3)
      );
 }
 outlet
 {
   type patch;
   faces
     (
      (8 10 11 9)
      );
 }
 upperWallUpstream
 {
   type wall;
   faces
     (
      (3 2 6 7)
      );
 }
 lowerWallUpstream
 {
   type wall;
   faces
     (
      (0 1 5 4)
      );
 }
 upperWallDownstream
 {
   type wall;
   faces
     (
      (2 9 11 6)
      );
 }
 lowerWallDownstream
 {
   type wall;
   faces
     (
      (1 8 10 5)
      );
 }
 frontAndBack
 {
   type empty;
   faces
     (
      (0 1 2 3)
      (4 5 6 7)
      (1 8 9 2)
      (5 10 11 6)
      );
 }
 );

mergePatchPairs
(
);
And the result is attached below
cutter, hwangpo, ykanani and 2 others like this.
hk318i is offline   Reply With Quote

Old   April 17, 2015, 10:03
Default
  #5
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
francois is on a distinguished road
Thanks Hassan for your kind and very relevant suggestions.

I was thinking myself of refactoring the code which was submitted here only as proof of concept for myself or other newcomers to #codeStream.

Anyway, those are indeed very nice additions to put into the code, thanks !
I may put all this stuff on the wiki when I'll find the time.

You're a good example that illustrates why I like so much the OpenFOAM community.
Happy foaming
hk318i likes this.
francois is offline   Reply With Quote

Old   April 29, 2015, 13:25
Default
  #6
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 17
hk318i is on a distinguished road
Hello!
I hit one of the codeStream limitations today. I would like to share it with everyone here.
Code:
string "
         int N = 100;
         scalar cw = $cw*$ftTom; // chord
         scalar..."
    is too long (max. 8000 characters)
Although I used the method which I mentioned above, I had to write a very very long codeStream. Fortunately, I found a solution for this problem which is dividing the code stream to many .H files and includes directly inside the code not as a header file.

Code:
    code
    #{
#include "myLongCode.H"
     #};
BUT, there is a drawback for this method, you cannot use the macro substitutions ($parameter). I desperately tried "#inputMode merge" but it doesn't work.
So to read any variable from the blockMeshDict in this case, you have to lookup it.

Code:
scalar a = readScalar(dict.lookup("a"));
Next time, I have to FOAM responsibly
hk318i is offline   Reply With Quote

Old   October 1, 2015, 07:07
Default
  #7
Senior Member
 
ArielJ
Join Date: Aug 2015
Posts: 127
Rep Power: 10
arieljeds is on a distinguished road
On using codestream... I understand the syntax to duplicate points but I want to then see the points so I can construct the blocks... Maybe this is a stupid question but I'm very very new to CFD and meshing so I don't understand how, once I've duplicated the points, I "know" where each one is and how the block structure should be using the new points... can anyone advise on the best practice for this?
arieljeds is offline   Reply With Quote

Old   October 1, 2015, 09:09
Default
  #8
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 17
hk318i is on a distinguished road
Quote:
Originally Posted by arieljeds View Post
On using codestream... I understand the syntax to duplicate points but I want to then see the points so I can construct the blocks... Maybe this is a stupid question but I'm very very new to CFD and meshing so I don't understand how, once I've duplicated the points, I "know" where each one is and how the block structure should be using the new points... can anyone advise on the best practice for this?
You can use
Code:
paraFoam -block
It shows the points so you could create the blocks which is really helpful.
I am not sure if that what you are looking for or not. Maybe you mean if you have list called points and you want use points[5] in blocks.
In this case, based on my experience, you cannot do that directly because the variables are limited to codeStream scope.

BUT there is a way around this problem which is including the blocks section inside the same codeStream as points. Then use os stream to print blocks as well. Or you can write a script (using python or octave or m4 .) to create blockMesh file.
hk318i is offline   Reply With Quote

Old   October 1, 2015, 09:18
Default
  #9
Senior Member
 
ArielJ
Join Date: Aug 2015
Posts: 127
Rep Power: 10
arieljeds is on a distinguished road
Hi there,

Thanks for that. Actually I wasn't sure if that would work without running blockMesh first...

Ok just tried and how is it possible to do this without first building the blocks? Or do I just put:

Code:
blocks
(
);
And leave the blocks blank?
arieljeds is offline   Reply With Quote

Old   October 1, 2015, 09:26
Default
  #10
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 17
hk318i is on a distinguished road
It works without executing blockMesh, just make sure that boundary is empty as well. It will show you the points and edges
hk318i is offline   Reply With Quote

Old   October 1, 2015, 09:28
Default
  #11
Senior Member
 
ArielJ
Join Date: Aug 2015
Posts: 127
Rep Power: 10
arieljeds is on a distinguished road
perfect! Thanks for that... very difficult to find something so simple online!
arieljeds is offline   Reply With Quote

Old   October 1, 2015, 09:55
Default
  #12
Senior Member
 
ArielJ
Join Date: Aug 2015
Posts: 127
Rep Power: 10
arieljeds is on a distinguished road
Sorry, last question.. say I'm trying to duplicate both the z points (as done in the cylinder tutorial) and the y points. I tried to just include a second loop as follows:

Code:
label sy = points.size();
points.setSize(2*sy);
for (label i = 0; i < sy; i++)
{
     const point& pt = points[i];
     points[i+sy] = point(pt.x(), -pt.y(), pt.z());
}

os << points;
But this (perhaps obviously) didn't work... Can you offer any guidance on the correct syntax to use?
arieljeds is offline   Reply With Quote

Old   March 8, 2021, 19:27
Default Similar issues with #codeStream in openfoam8
  #13
New Member
 
Luca
Join Date: Jun 2019
Location: Colorado, USA
Posts: 6
Rep Power: 6
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, 05:14
Default
  #14
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 670
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, 12:42
Default
  #15
New Member
 
Luca
Join Date: Jun 2019
Location: Colorado, USA
Posts: 6
Rep Power: 6
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, 13:55
Default
  #16
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 670
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, 13:59
Default
  #17
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 670
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, 14:31
Default
  #18
New Member
 
Luca
Join Date: Jun 2019
Location: Colorado, USA
Posts: 6
Rep Power: 6
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, 11:23
Default
  #19
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 670
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, 12:29
Default Solved!
  #20
New Member
 
Luca
Join Date: Jun 2019
Location: Colorado, USA
Posts: 6
Rep Power: 6
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 02:36
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 11:04
Star-CCM+ Macro - Loop over just wall boundary conditions jbatchel STAR-CCM+ 5 March 2, 2018 13:42
Pressure distribution on a wall darazsbence CFX 17 October 6, 2015 10:38
How to determine a point is inside a tetrahedral? G.P. Xia Main CFD Forum 16 January 12, 2000 11:15


All times are GMT -4. The time now is 12:02.