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

Custom Boundary Conditions compile but won't show up.

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Novel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 8, 2017, 12:09
Default Custom Boundary Conditions compile but won't show up.
  #1
New Member
 
Roman G.
Join Date: Apr 2017
Posts: 16
Rep Power: 9
Novel is on a distinguished road
Hello there,
I tried to implement a no slip boundary condition as described in the book "The finite volume method in computational fluid dynamics" from M. Darwish, L. Mangani, F. Moukalled, page 753fff
I'm using OpenFoam 4.1 so I had to change the code a bit. The code compiles but won't show up in the list of available BCs when running one of my solvers. I included the library in the ControlDict file.

I attached the code bellow. It would be nice if someone could take a look at it.
https://www.dropbox.com/sh/hebpojxa2...ijITG1u4a?dl=0

Regards,
Roman

PS: Most of the code is similar to fixedValue.
Novel is offline   Reply With Quote

Old   May 8, 2017, 12:25
Default
  #2
Senior Member
 
Join Date: Sep 2013
Posts: 353
Rep Power: 20
Bloerb will become famous soon enough
How does the make folder and the controlDict look like?
You have a line like
Code:
libs ("libmyboundary.so");
in your controlDict?
Bloerb is offline   Reply With Quote

Old   May 8, 2017, 12:31
Default
  #3
New Member
 
Roman G.
Join Date: Apr 2017
Posts: 16
Rep Power: 9
Novel is on a distinguished road
Yes I included the .so file in ControlDict like:
libs ("noSlipWallFvPatchVectorField.so");

I added files & options to the dropbox folder.
Novel is offline   Reply With Quote

Old   May 9, 2017, 08:02
Default
  #4
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 20
floquation will become famous soon enough
The answer why it does not show up is that you did not implement the run-time selection mechanism [warning: link information out-of-date, so I'll explain below].

I'm not sure how exactly that happens for BCs (so for the time being I'll leave that for you to find out), but in general it would require something like:

Run-time selection (in general)

Child header file: (you already have this)
Code:
#include "parent.H"

(...) other stuff

    //- Runtime type information
        TypeName("child"); // name that you can select


Child source file:
<-- you are missing something like this
Code:
#include "child.H"
#include "addToRunTimeSelectionTable.H"


// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
  defineTypeNameAndDebug(child, 0); // not sure: either class name or typename (I always give them the same name anyway)... The error message will tell you soon enough!
  addToRunTimeSelectionTable
  (
      parent, // name of parent class
      child, // name of child class
      thisIsJustAName // see the parent class below
  );
}

(...) other stuff
Then, in the parent class there is some code to define the lookup table. You don't have to do this, as you are adding a child class to an existing table. However, I'll explain it anyway.

Parent header file:
Code:
#include "runTimeSelectionTables.H"

(...) other stuff


    //- Runtime type information

        TypeName("parent"); // typename for the parent class

    // Declare run-time constructor selection table

        declareRunTimeSelectionTable // defines the table that children will be added to
        (
            autoPtr,
            parent, // classname of the parent
            thisIsJustAName, // name you give to the table
            (
                const word& name,
                const foo& foo
            ), // List of arguments that the constructor requires (see constructor example below)
            (name, foo) // Repeat the same list, but only with the parameter names
        );

    // Constructors

        parent(
            const word& name,
            const foo& foo
        );

    // Selectors

        //- Select based on given type name
        static autoPtr<parent> New(const word& type, const foo& foo);
// This is a method you can call that initiates the appropriate child and returns the instance. Pretty much like the "new" keyword in Java.


    //- Destructor

        virtual ~parent(); // abstract parent class needs a virtual destructor
Parent source file:
Code:
#include "parent.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
    defineTypeNameAndDebug(parent, 0);
    defineRunTimeSelectionTable(parent, thisIsJustAName);
}


(...) other stuff
Run-time selection (fvPatchField)

For your case...
Code:
# First find out where the parent is
$of41
$src
$grep -rni "declareRunTimeSelectionTable" .
(...)
./finiteVolume/lnInclude/fvPatchField.H:124:        declareRunTimeSelectionTable                                                                                                                                                         
./finiteVolume/lnInclude/fvPatchField.H:136:        declareRunTimeSelectionTable                                                                                                                                                         
./finiteVolume/lnInclude/fvPatchField.H:150:        declareRunTimeSelectionTable 
(...)

# Now open the parent to see how the tables are defined
$ vi ./finiteVolume/lnInclude/fvPatchField.H +124

    // Declare run-time constructor selection tables

        declareRunTimeSelectionTable
        (
            tmp,
            fvPatchField,
            patch,
            (
                const fvPatch& p,
                const DimensionedField<Type, volMesh>& iF
            ),
            (p, iF)
        );

        declareRunTimeSelectionTable
        (
            tmp,
            fvPatchField,
            patchMapper,
            (
                const fvPatchField<Type>& ptf,
                const fvPatch& p,
                const DimensionedField<Type, volMesh>& iF,
                const fvPatchFieldMapper& m
            ),
            (dynamic_cast<const fvPatchFieldType&>(ptf), p, iF, m)
        );

        declareRunTimeSelectionTable
        (
            tmp,
            fvPatchField,
            dictionary,
            (
                const fvPatch& p,
                const DimensionedField<Type, volMesh>& iF,
                const dictionary& dict
            ),
            (p, iF, dict)
        );


# Good to know, but it is much smarter to check out a child to see how that is done...
$ cd finiteVolume
$ grep -rni "addToRunTimeSelectionTable" .
(...)
./fields/fvPatchFields/derived/slip/slipFvPatchFields.C:27:#include "addToRunTimeSelectionTable.H"
(...)
$ vi ./fields/fvPatchFields/derived/slip/slipFvPatchFields.C +27
#include "slipFvPatchFields.H"
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

makePatchFields(slip);

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam
Apparently they defined a macro specially for defining boundary conditions! This is a shortcut for the run-time selection mechanism. You might as well use it!
The reason they added such a macro, is that run-time selection would be much more elaborate to implement than the two lines you saw in my child.C above, because patchFields are templated classes.
For each template possibility you have to separately add the class to the table... The macro takes care of that for you!
(I used an IDE to find out that it is defined in fvPatchField.H, in case you are interested).
So, just apply what was done for "slip" for your case... and it should automagically work.
floquation is offline   Reply With Quote

Old   May 9, 2017, 11:10
Default
  #5
New Member
 
Roman G.
Join Date: Apr 2017
Posts: 16
Rep Power: 9
Novel is on a distinguished road
Thank you! I added the child source file (The files are now inlcluded in dropbox).
I changed in files "noSlipWallFvPatchVectorField.C" by "noSlipWallFvPatchVectorFields.C" . When I now try to compile the error:

/opt/openfoam4/src/finiteVolume/lnInclude/fvPatchField.H:693:5: note: in expansion of macro ‘makeTemplatePatchTypeField’
makeTemplatePatchTypeField \
^
noSlipWallFvPatchVectorFields.C:37:1: note: in expansion of macro ‘makePatchFields’
makePatchFields(noSlipWall);
^
make: *** [Make/linux64GccDPInt32Opt/noSlipWallFvPatchVectorFields.o] Error 1


shows up.
Novel is offline   Reply With Quote

Old   May 10, 2017, 03:06
Default
  #6
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 20
floquation will become famous soon enough
That's not the error; that's merely the location of the error.
Please post the entire compilation error between [code]-tags if you wish for someone to diagnose it.
floquation is offline   Reply With Quote

Old   May 10, 2017, 03:16
Default
  #7
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 20
floquation will become famous soon enough
When I quickly look at your code anyway, I do notice one thing:
Your child source file is nowhere included in the compilation!

childs.C is in Make/files
it includes childs.H
which includes child.H
which does not include child.C, because you commented it in lines 227-230.
Why did you do that?
floquation is offline   Reply With Quote

Old   May 10, 2017, 05:09
Default
  #8
New Member
 
Roman G.
Join Date: Apr 2017
Posts: 16
Rep Power: 9
Novel is on a distinguished road
Thanks for the reply. I command it out to test something, it's now back in. I added the complete error message in the dropbox folder.

It's starting with :

In file included from noSlipWallFvPatchVectorField.H:57:0,
from noSlipWallFvPatchVectorFields.H:29,
from noSlipWallFvPatchVectorFields.C:26:
noSlipWallFvPatchVectorFields.H:39:28: error: ‘noSlipWallFvPatchField’ does not name a type
makePatchTypeFieldTypedefs(noSlipWall);
^
/opt/openfoam4/src/finiteVolume/lnInclude/fvPatchField.H:709:13: note: in definition of macro ‘makePatchTypeFieldTypedefs’
typedef type##FvPatchField<scalar> type##FvPatchScalarField; \
^
noSlipWallFvPatchVectorFields.H:39:28: error: ‘noSlipWallFvPatchField’ does not name a type
makePatchTypeFieldTypedefs(noSlipWall);
....
...
...
Novel is offline   Reply With Quote

Old   May 10, 2017, 06:05
Default
  #9
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 20
floquation will become famous soon enough
Quote:
Originally Posted by Novel View Post
In file included from noSlipWallFvPatchVectorField.H:57:0,
from noSlipWallFvPatchVectorFields.H:29,
from noSlipWallFvPatchVectorFields.C:26:
noSlipWallFvPatchVectorFields.H:39:28: error: ‘noSlipWallFvPatchField’ does not name a type
makePatchTypeFieldTypedefs(noSlipWall);
^
/opt/openfoam4/src/finiteVolume/lnInclude/fvPatchField.H:709:13: note: in definition of macro ‘makePatchTypeFieldTypedefs’
typedef type##FvPatchField<scalar> type##FvPatchScalarField; \
^
noSlipWallFvPatchVectorFields.H:39:28: error: ‘noSlipWallFvPatchField’ does not name a type
makePatchTypeFieldTypedefs(noSlipWall);
....
...
...
For your future reference, what I put in bold is the error, which tells you what you do incorrectly. It says that your 'noSlipWallFvPatchField' does not have a type...

I'm inclined to conclude that there is something wrong with your "TypeName" then, but it looks fine.

Another "Type" that appears is in the templating... But I don't think this refers to that. Besides, I see nothing weird there when compared with the "slip" BC.


With that being said, I do not know what goes wrong... But I do notice that you have a rather weird name for your file.
Why is it called noSlipWallFvPatchVectorField? Not a single file in OpenFoam is called like that, because they are templated. A (...)VectorField is a typedef from (...)Field<vector>.
Now, if we look at the macro that is complaining:
Code:
#define makePatchTypeFieldTypedefs(type)                                       \
    typedef type##FvPatchField<scalar> type##FvPatchScalarField;               \
    typedef type##FvPatchField<vector> type##FvPatchVectorField;               \
    typedef type##FvPatchField<sphericalTensor>                                \
        type##FvPatchSphericalTensorField;                                     \
    typedef type##FvPatchField<symmTensor> type##FvPatchSymmTensorField;       \
    typedef type##FvPatchField<tensor> type##FvPatchTensorField;
I have no experience reading macros, but to me this looks like it concatenates the word you specified when calling this macro (i.e. "noSlipWall") together with "FvPatchField". This should be a valid name: noSlipWallFvPatchField. However, this does not exist, because you called your file "noSlipWallFvPatchVectorField".
Therefore, an error shall result: it cannot typedef noSlipWallFvPatchField<vector> to noSlipWallFvPatchVectorField, because noSlipWallFvPatchField<vector> "does not name a type".

Conclusion:
Please use the OpenFOAM naming convention, otherwise the macros will not work.
floquation is offline   Reply With Quote

Old   May 10, 2017, 09:12
Default
  #10
New Member
 
Roman G.
Join Date: Apr 2017
Posts: 16
Rep Power: 9
Novel is on a distinguished road
Thanks allot!! I changed the file and class names to noSlipWallFvPatchField... and It's running now.
Still a lot of errors came up but I managed to track them down. No I can start playing around with the boundary conditions. I added the working files if someone has same issues as I.
Attached Files
File Type: gz noSlipWall.tar.gz (141.9 KB, 61 views)
floquation likes this.
Novel 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
sliding mesh problem in CFX Saima CFX 46 September 11, 2021 07:38
Centrifugal fan j0hnny CFX 13 October 1, 2019 13:55
Domain Imbalance HMR CFX 5 October 10, 2016 05:57
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 06:28
Low Mixing time Problem Mavier CFX 5 April 29, 2013 00:00


All times are GMT -4. The time now is 15:44.