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

Inactive debug switches for fvOption SemiImplicitSource

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 27, 2014, 14:22
Default Inactive debug switches for fvOption SemiImplicitSource
  #1
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 342
Rep Power: 28
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
I seem to be unable to report an issue with the mantis system. However, I post the information here, and will report it later, unless someone has an alternative explanation.


When I run the injection tutorial case from the twoPhaseEulerFoam tutorials and I add the following lines to controlDict no debug information is printed:

Code:
DebugSwitches
{
    scalarSemiImplicitSource    1;
    vectorSemiImplicitSource    1;
}
In the injection case both options are active, thus, I expect some debug information.

The class SemiImplicitSource contains some debug output like this:

Code:
    if (debug)
    {
        Info<< "SemiImplicitSource<" << pTraits<Type>::typeName
            << ">::addSup for source " << name_ << endl;
    }
in the method void Foam::fv::SemiImplicitSource<Type>::addSup()




The file semiImplicitSource.C contains the following "macro call"

Code:
makeFvOption(SemiImplicitSource, scalar);
The file makeFvOptions.H defines the called macro:

Code:
#define makeFvOption(Option, Type)                                            \
                                                                              \
    defineTemplateTypeNameAndDebugWithName                                    \
    (                                                                         \
        Option<Type>,                                                         \
        #Type#Option,                                                         \
        0                                                                     \
    );                                                                        \
                                                                              \
    option::adddictionaryConstructorToTable<Option<Type> >                    \
        add##Option##Type##dictionary##ConstructorTooptionTable_
The part of the code I suspect is:

Code:
#Type#Option
which is the stringification of both Type and Option. When called (with Type=scalar, Option=SemiImpicitSource)
the macro argument is

Code:
"scalar""SemiImplicitSource"
Compiling the file semiImplicitSource.C with the g++ option -E we gain the output of the preprocessor.

The macro

Code:
makeFvOption(SemiImplicitSource, scalar);
expands to

Code:
template<> const ::Foam::word SemiImplicitSource<scalar>::typeName("scalar""SemiImplicitSource");
template<> int SemiImplicitSource<scalar>::debug(::Foam::debug::debugSwitch("scalar""SemiImplicitSource", 0));
option::adddictionaryConstructorToTable<SemiImplicitSource<scalar> > addSemiImplicitSourcescalardictionaryConstructorTooptionTable_;
Here we also see the argument "scalar""SemiImplicitSource"

I wonder why there is no compiler error message, however, the debug switch does not work.


I think

Code:
#Type#Option
needs to be replaced with

Code:
Type##Option
as ## concatenates arguments instead of stringifying them.
GerhardHolzinger is offline   Reply With Quote

Old   August 31, 2014, 19:21
Default
  #2
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings Gerhard,

Fortunately there is no bug, but in fact it's a missing feature.
The problem is that the flags defined in the case's "system/controlDict" only work in some situations. In this situation, you will need to define it at the level of the global "controlDict" or similar, such as:
Code:
$HOME/.OpenFOAM/2.3.x/controlDict
As for cases where it works or not, I found the following comment on this bug report: http://www.openfoam.org/mantisbt/view.php?id=640#c2737
Quote:
Originally Posted by mattijs
The DebugSwitches entry in the case controlDict is pretty good (for non-templated classes). See e.g.
http://www.openfoam.org/version2.2.0...me-control.php
Therefore, the problem is in fact that this will not work for templated classes, such as "SemiImplicitSource".


As for your suggestion of using "Type##Option" instead of "#Type#Option", that's incorrect. The interpretation of the two is as follows:
  • "Type##Option" means that the resulting macro generated code will be a concatenation of the names defined for each macro:
    Code:
    scalarSemiImplicitSource
    without any quotes. This would be interpreted as being code and not text.
  • "#Type#Option" means that the content of the two macro variables are to be converted to text:
    Code:
    "scalar""SemiImplicitSource"
    which the compiler will in turn automatically concatenate and convert to:
    Code:
    "scalarSemiImplicitSource"
Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   September 1, 2014, 03:59
Default
  #3
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 342
Rep Power: 28
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
Quote:
Originally Posted by wyldckat View Post
Greetings Gerhard,

As for your suggestion of using "Type##Option" instead of "#Type#Option", that's incorrect. The interpretation of the two is as follows:
  • "Type##Option" means that the resulting macro generated code will be a concatenation of the names defined for each macro:
    Code:
    scalarSemiImplicitSource
    without any quotes. This would be interpreted as being code and not text.
  • "#Type#Option" means that the content of the two macro variables are to be converted to text:
    Code:
    "scalar""SemiImplicitSource"
    which the compiler will in turn automatically concatenate and convert to:
    Code:
    "scalarSemiImplicitSource"
Best regards,
Bruno

My guess was that the macros that create all this debug run-time magic need to get the data type passed instead of a string.

I will take another close look and compare the workings of the pre-processor magic with non-templated and templated classes.

Anyway, I will post my findings when I had a look.
GerhardHolzinger is offline   Reply With Quote

Old   September 1, 2014, 04:55
Default
  #4
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 342
Rep Power: 28
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
Some time ago I took a look at the non-templated macro magic of the SchillerNaumann drag model class, see the attached pdf.

There the macro
Code:
        /* Layout-provided Styles */ div.standard { margin-bottom: 2ex; }defineTypeNameAndDebug(SchillerNaumann, 0);
is with the type name un-stringyfied, this leads me to the assumption, that in the templated case, the macro should also be provided with the unstringyfied type name.

The macro above is defined as
Code:
        /* Layout-provided Styles */ div.standard { margin-bottom: 2ex; }      //- Define the typeName and debug information 
  #define defineTypeNameAndDebug(Type, DebugSwitch)                             \
      defineTypeName(Type);                                                     \
      defineDebugSwitch(Type, DebugSwitch)
after some further macro expansion we end up with

Code:
       /* Layout-provided Styles */ div.standard { margin-bottom: 2ex; }      defineTypeNameWithName(Type, Type::typeName_()) 
       /* Layout-provided Styles */ div.standard { margin-bottom: 2ex; }      int Type::debug(::Foam::debug::debugSwitch(Name, DebugSwitch))
       /* Layout-provided Styles */ div.standard { margin-bottom: 2ex; }      registerDebugSwitchWithName(Type, Type, Type::typeName_())


The argument Type is needed to correctly address namespaces and datatypes.

However, I still have to look more closely into the templated stuff.
Attached Files
File Type: gz runTimeSelectionAndDebug.pdf.tar.gz (82.5 KB, 6 views)
GerhardHolzinger is offline   Reply With Quote

Old   March 22, 2015, 08:06
Default
  #5
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Gerhard,

The ability to also control the debug flags for template classes has been implemented in the OpenFOAM-dev repository: https://github.com/OpenFOAM/OpenFOAM-dev/

It was implemented in this commit: https://github.com/OpenFOAM/OpenFOAM...09b8cb4b967baa

Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   March 23, 2015, 04:07
Default
  #6
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 342
Rep Power: 28
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
Hi Bruno,

thanks for the hint.

Allow me a related off-topic question.

Is the OpenFOAM-dev repo something new or newly made public? I started noticing links and references to this repo a few month ago.

Cheers Gerhard
GerhardHolzinger is offline   Reply With Quote

Old   March 28, 2015, 17:06
Default
  #7
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quote:
Originally Posted by GerhardHolzinger View Post
Is the OpenFOAM-dev repo something new or newly made public? I started noticing links and references to this repo a few month ago.
Quick answer: OpenFOAM-dev repo was started soon after OpenFOAM's 10th year anniversary:
wyldckat is offline   Reply With Quote

Reply

Tags
debugswitch, fvoptions, semi-implicit-source


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
create the file *.foam phongstar OpenFOAM 12 October 14, 2018 19:06
[OpenFOAM] could not open file .vtk in paraview ali_atrian ParaView 8 August 27, 2014 11:31
Debug Switches Peter Müller OpenFOAM Programming & Development 2 September 30, 2013 03:23
Eclipse - case debug error Bufacchi OpenFOAM 1 February 7, 2012 16:15


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