CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

Mathematical expressions in a FoamFile

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

Reply
 
LinkBack Thread Tools Display Modes
Old   January 20, 2016, 19:21
Default Mathematical expressions in a FoamFile
  #1
New Member
 
Brad Perfect
Join Date: Jan 2014
Posts: 6
Rep Power: 4
bhperfect is on a distinguished road
This one's a two-parter:

First, the implementation. In the definitions section in blockMeshDict, I want to define and discretize the domain. So I define

>back -600;
>front 250;

Cool. Now, I'd like to define the number of grid cells along this dimension. Previously I had been doing

>nx 40;

But now I'm playing around with changing the domain size. I would like to be able to say something like,

>nx floor((front-back)/8);

How can I accomplish this? OpenFOAM gets angry at me whenever I try to insert a math expression.

Now, for the second part:

I can't find any information about how these FoamFile definitions are stored. Do they stay local to whatever application calls the file that it's in, or could I, for example, define all of my parameters that might change in my executable file? Going with the same example as above, is there a way to define 'front' and 'back' in my executable so that I only have to edit one file every time I do a run?
bhperfect is offline   Reply With Quote

Old   January 21, 2016, 09:21
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,370
Rep Power: 23
alexeym will become famous soon enoughalexeym will become famous soon enough
Hi,

You know, you can search forums:

How to use mathematical constants?

Writing a blockMeshDict file with variables

#codeStream loop inside a blockMeshDict

Also you can use grep:

Code:
$ cd $FOAM_TUTORIALS
$ grep -r '#calc' *
incompressible/simpleFoam/pipeCyclic/constant/polyMesh/blockMeshDict:radHalfAngle    #calc "degToRad($halfAngle)";
incompressible/simpleFoam/pipeCyclic/constant/polyMesh/blockMeshDict:y               #calc "$radius*sin($radHalfAngle)";
incompressible/simpleFoam/pipeCyclic/constant/polyMesh/blockMeshDict:minY            #calc "-1.0*$y";
incompressible/simpleFoam/pipeCyclic/constant/polyMesh/blockMeshDict:z               #calc "$radius*cos($radHalfAngle)";
incompressible/simpleFoam/pipeCyclic/constant/polyMesh/blockMeshDict:minZ            #calc "-1.0*$z";
multiphase/interDyMFoam/ras/floatingObject/constant/dynamicMeshDict:    mass            #calc "$rho*$Lx*$Ly*$Lz";
And finally, you can generate blockMeshDict using whatever language you know. Since #calc is just convenience wrapper around C++.
alexeym is offline   Reply With Quote

Old   January 21, 2016, 18:37
Default
  #3
New Member
 
Brad Perfect
Join Date: Jan 2014
Posts: 6
Rep Power: 4
bhperfect is on a distinguished road
Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 1;
back -600;
front 250;
side -215;
z1 -40;
//40m depth permits waves up to 80m long to propagate as deep water waves
z2 3.87;
z3 5.87;
z4 50;
hsize 8;
vsize 6;

nx #calc "std::ceil(($front-$back)/$hsize)";
#calc "Info<< $nx << endl"
ny #calc "std::ceil(-$side/$hsize)";
when run, this yields
Code:
/*---------------------------------------------------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
Build  : 2.3.0-f5222ca19ce6
Exec   : blockMesh
Date   : Jan 21 2016
Time   : 14:30:39
Host   : "fourier"
PID    : 17214
Case   : /home/bperfect/OpenFOAM/bperfect-2.3.0/run/small
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Creating block mesh from
    "/home/bperfect/OpenFOAM/bperfect-2.3.0/run/small/constant/polyMesh/blockMeshDict"
Using #calcEntry at line 29 in file "/home/bperfect/OpenFOAM/bperfect-2.3.0/run/small/constant/polyMesh/blockMeshDict"
Using #codeStream with "/home/bperfect/OpenFOAM/bperfect-2.3.0/run/small/dynamicCode/platforms/linux64GccDPOpt/lib/libcodeStream_d8e5566d16e6b658bc2352d18ed09d52db601d72.so"
Invoking "wmake -s libso /home/bperfect/OpenFOAM/bperfect-2.3.0/run/small/dynamicCode/_d8e5566d16e6b658bc2352d18ed09d52db601d72"
: In function ‘void Foam::codeStream_d8e5566d16e6b658bc2352d18ed09d52db601d72(Foam::Ostream&, const Foam::dictionary&)’:
:1:22: error: lvalue required as decrement operand
:1:24: error: expected ‘)’ before numeric constant
:1:32: error: expected ‘)’ before ‘;’ token
make: *** [Make/linux64GccDPOpt/codeStreamTemplate.o] Error 1


--> FOAM FATAL IO ERROR: 
Failed wmake "dynamicCode/_d8e5566d16e6b658bc2352d18ed09d52db601d72/platforms/linux64GccDPOpt/lib/libcodeStream_d8e5566d16e6b658bc2352d18ed09d52db601d72.so"


file: /home/bperfect/OpenFOAM/bperfect-2.3.0/run/small/constant/polyMesh/blockMeshDict from line 17 to line 26.

    From function functionEntries::codeStream::execute(..)
    in file db/dictionary/functionEntries/codeStream/codeStream.C at line 177.

FOAM exiting
So, it looks like I was able to make it understand my #calc calls, but now everything else defined in the dictionary is failing. Do you know how I might fix this?
bhperfect is offline   Reply With Quote

Old   January 21, 2016, 19:06
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,370
Rep Power: 23
alexeym will become famous soon enoughalexeym will become famous soon enough
Hi,

Though strictly speaking it is just shitty Gcc diagnostics, but try to control your expansions. Here is clang output:

Code:
  [CC] codeStreamTemplate.C
:1:22: error: expression is not assignable
os << (std::ceil((250--600)/8));
                  ~~~^
1 error generated.
make: *** [Make/darwin64ClangDPInt64Opt/codeStreamTemplate.o] Error 1
As you can see, your $front-$back was expanded into 250--600, which is not quite valid C++ expression. Use brackets. Or spaces ($front - $back). -$side is also expanded into --215.
alexeym is offline   Reply With Quote

Reply

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
Regular expressions in cfMesh rama13 OpenFOAM Meshing & Mesh Conversion 6 June 7, 2015 17:01
Mathematical Expressions at Boundaries AeroJay CFX 5 May 26, 2013 20:19
Average of Expressions in Transient Run for Parameter Study BigPapi34 CFX 1 August 7, 2012 05:34
Grouping expressions in CEL foo7 CFX 4 September 21, 2011 09:15
Cel expressions for trasient problem Jervds CFX 0 March 4, 2008 11:03


All times are GMT -4. The time now is 13:03.