CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Native Meshers: blockMesh

Writing a blockMeshDict file with variables

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree6Likes
  • 3 Post By alexeym
  • 2 Post By alexeym
  • 1 Post By Antimony

Reply
 
LinkBack Thread Tools Display Modes
Old   December 23, 2015, 08:39
Default Writing a blockMeshDict file with variables
  #1
Senior Member
 
ArielJ
Join Date: Aug 2015
Posts: 127
Rep Power: 4
arieljeds is on a distinguished road
Sponsored Links
Hi there,
I'm trying to write a blockmesh file using variables for the vertices and the number of cells but I'm not quite sure how to do this. At the moment, I'm trying this:

Code:
convertToMeters 1;

x   20.0;	// Length of tank
y1  -3.0;	// Width of tank/2
y2   3.0;	// Width of tank/2
zf  -0.4;	// Water depth 
za   0.2;    	// Distance above free surface
L    3.6942;    // Wavelength 
n    5;	        // Number of cells per wavelength 

xn   ($x/$L)*$n;	// Calculating the number of cells
//yn    
//zn 

vertices        
(
    ( 0   $y1  $zf )	 // 0		
    ( $x  $y1  $zf )     // 1
    ( $x  $y2  $zf )	 // 2
    ( 0   $y2  $zf )	 // 3
   
    ( 0   $y1  $za )	 // 4 
    ( $x  $y1  $za )	 // 5
    ( $x  $y2  $za )	 // 6
    ( 0   $y2  $za )	 // 7    
);

blocks 
         
(
  hex (0 1 2 3 4 5 6 7) ($xn 10 10) simpleGrading (1 1 1) //(1 10 0.1)
);

edges           
(
);

boundary         
( 
   inlet
   {
       type patch;
       faces
   	(
       	 ( 0 3 7 4 )
   	);
   }
   
   outlet
   {
       type patch; 
       faces
   	(
          ( 1 2 6 5 )
   	);
   }
   
   atmosphere
   {
       type patch;
       faces
   	(
          ( 4 5 6 7 )
   	);
   }
   
   front
   {
       type symmetryPlane;
       faces
  	(
       	  ( 3 2 6 7 )
        );
   }
Perhaps unsurprisingly, I'm running into problems with the line where I am attempting to calculate xn. Does anyone know the syntax how I can do this? Or if it's possible at all to do a simple calculation in the blockMeshDict?

Thanks in advance for any advice
arieljeds is offline   Reply With Quote
Sponsored Links

Old   December 23, 2015, 08:44
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,685
Rep Power: 27
alexeym will become famous soon enoughalexeym will become famous soon enough
Send a message via Skype™ to alexeym
Hi,

Code:
$ cd $FOAM_TUTORIALS
$ grep -r '#calc' *
incompressible/simpleFoam/pipeCyclic/system/blockMeshDict:radHalfAngle    #calc "degToRad($halfAngle)";
incompressible/simpleFoam/pipeCyclic/system/blockMeshDict:y               #calc "$radius*sin($radHalfAngle)";
incompressible/simpleFoam/pipeCyclic/system/blockMeshDict:minY            #calc "-1.0*$y";
incompressible/simpleFoam/pipeCyclic/system/blockMeshDict:z               #calc "$radius*cos($radHalfAngle)";
incompressible/simpleFoam/pipeCyclic/system/blockMeshDict:minZ            #calc "-1.0*$z";
multiphase/interDyMFoam/ras/floatingObject/constant/dynamicMeshDict:    mass            #calc "$rho*$Lx*$Ly*$Lz";
$ less incompressible/simpleFoam/pipeCyclic/system/blockMeshDict
...
//- Half angle of wedge in degrees
halfAngle 45.0;

//- Radius of pipe [m]
radius 0.5;


radHalfAngle    #calc "degToRad($halfAngle)";
y               #calc "$radius*sin($radHalfAngle)";
minY            #calc "-1.0*$y";
z               #calc "$radius*cos($radHalfAngle)";
minZ            #calc "-1.0*$z";
...
beatlejuice, havref and mbookin like this.
alexeym is offline   Reply With Quote

Old   December 23, 2015, 08:49
Default
  #3
Senior Member
 
ArielJ
Join Date: Aug 2015
Posts: 127
Rep Power: 4
arieljeds is on a distinguished road
@alexeym - Thanks a lot. That's what I was looking for
arieljeds is offline   Reply With Quote

Old   December 23, 2015, 08:58
Default
  #4
Senior Member
 
ArielJ
Join Date: Aug 2015
Posts: 127
Rep Power: 4
arieljeds is on a distinguished road
Ok one more question on this.. Because the calculation I am making is going to be for the number of cells, I need to convert it to an integer. I'm having trouble finding an example of how to do this.

Any ideas?

Thanks again!
arieljeds is offline   Reply With Quote

Old   December 23, 2015, 09:11
Default
  #5
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,685
Rep Power: 27
alexeym will become famous soon enoughalexeym will become famous soon enough
Send a message via Skype™ to alexeym
Well, if you take a look into src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.H, there is a note:

Code:
Note
    Internally this is just a wrapper around codeStream functionality - the
    #calc string gets used to construct a dictionary for codeStream.
So you can use usual C++ functions, for example, std::floor or std::ceil.
alexeym is offline   Reply With Quote

Old   December 23, 2015, 09:17
Default
  #6
Senior Member
 
ArielJ
Join Date: Aug 2015
Posts: 127
Rep Power: 4
arieljeds is on a distinguished road
Hi Alexey, thanks again for getting back to me so quickly. Ok so as I'm understanding it, the use of calc would be:

Code:
x     20.0; 
n = 5; 
L = 3.69;

xn  #calc "($x/$L)*n";
xn1 #calc "std::floor(float $xn)"; 

...

blocks 
{
    hex ( 0 1 2 3 4 5 6 7 ) (xn1 10 10) simpleGrading (1 1 1)
}

...
Is this correct?
arieljeds is offline   Reply With Quote

Old   December 23, 2015, 09:34
Default
  #7
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,685
Rep Power: 27
alexeym will become famous soon enoughalexeym will become famous soon enough
Send a message via Skype™ to alexeym
Just

Code:
std::floor($xn)
If we take an example from tutorials (incompressible/simpleFoam/pipeCyclic) and add the lines:

Code:
test            #calc "std::floor($halfAngle/4)";
#calc "Info<< $test << endl";
output of blockMesh would be

Code:
... codeStream object compilation output ...
11
Creating curved edges
Creating topology blocks
...
So in your expressions you forget $ before n and used unnecessary float in function call.
Mojtaba.a and Milica like this.
alexeym is offline   Reply With Quote

Old   December 23, 2015, 09:35
Default
  #8
Senior Member
 
ArielJ
Join Date: Aug 2015
Posts: 127
Rep Power: 4
arieljeds is on a distinguished road
Hi Alexey,

I should've written back quicker... I messed around with it a bit and found my way to that syntax and have it working now.

thanks a lot again for your help!

Ariel
arieljeds is offline   Reply With Quote

Old   December 14, 2016, 12:25
Default
  #9
New Member
 
Luca Franceschini
Join Date: Aug 2012
Posts: 29
Rep Power: 6
Luchini is on a distinguished road
Hello,

I was trying to implement something similar, but i have problems with negative variables.
It seems i can decleare them but as soon i use them in the calc expression the blockMesh gives me an error.

So in

Code:
x1 -30;
//x1 30;
x2 50;

dx #calc "$x1";
//dx 10;
If x1 is declared as positive, everything is ok.
If x1 is declared as negative and dx =10 , everything is ok.
if x1 is declared as negative and dx as #calc "$x1"; i get an error.

Does anybody knows the reason and a work around?

Note that the real operation that i would like to do is something like

Code:
nx #calc "std::floor( ($x2-$x1)*$n )";

Thank you in advance.
Luchini is offline   Reply With Quote

Old   December 14, 2016, 22:17
Default
  #10
Senior Member
 
Join Date: Aug 2013
Posts: 292
Rep Power: 6
Antimony is on a distinguished road
Hi,

You need to have a space between the variables and the operator for it to recognize it as subtraction.

Instead of: $x2-$x1

So it should be: $x2 - $x1

Not sure if this is documented, but this was what I found out when I was playing around with this feature.

Hope this helps.

Cheers,
Antimony
Luchini likes this.
Antimony is offline   Reply With Quote

Old   December 15, 2016, 06:47
Default
  #11
New Member
 
Luca Franceschini
Join Date: Aug 2012
Posts: 29
Rep Power: 6
Luchini is on a distinguished road
Correct,

This worked.

Thank you
Luchini is offline   Reply With Quote

Old   July 20, 2017, 19:21
Default Using Regular C++ syntax to write Blockmesh file
  #12
New Member
 
Join Date: Feb 2016
Posts: 9
Rep Power: 3
LeeRuns is on a distinguished road
hello everyone,
if i wanted to use regular C++ or objective C syntax to organize my code could I do that?
for example
Code:
class cPlane
{ // whatever you need
};

class cSphere
{
int MyVariable;
// whatever else you need
};

class cObject
{ cPlane MyPlane;
   cSphere MySphere;

//  whetever else you need
};

int main()
{
   cObject MyObjects[99];

// whatever  you need

}
i mostly write in python. So please don't fill me in on how there are better languages for writing text files than C++. I am WELL AWARE LOL! But i like learning languages by writing in them. So this is a good way for me to improve.

i want to get practice writing in C++11 so that I can more easily ready the source code.
I am working on a pretty complex blockmesh right now and would like to use oop in my code to try to help organize the shapes.

Has anyone done this? Would I use #codestream for this. I am working my way through the manual. But found the codestream section a bit confusing...
LeeRuns is offline   Reply With Quote

Reply

Tags
blockmeshdict, variable definition

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Patches to compile OpenFOAM 2.2 on Mac OS X gschaider OpenFOAM Installation on Windows, Mac and other Unsupported Platforms 134 December 5, 2015 04:30
How to use finite area method in official OpenFOAM 2.2.0? Detian Liu OpenFOAM Meshing & Mesh Conversion 4 November 3, 2015 04:04
Adding solvers from DensityBasedTurbo to foam-extend 3.0 Seroga OpenFOAM Installation 9 June 12, 2015 17:18
"parabolicVelocity" in OpenFoam 2.1.0 ? sawyer86 OpenFOAM Running, Solving & CFD 21 February 7, 2012 12:44
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 20:08

Sponsored Links


All times are GMT -4. The time now is 10:14.