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

Calling a method from derived BC

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 6, 2012, 11:04
Default Calling a method from derived BC
  #1
Senior Member
 
Pawel Sosnowski
Join Date: Mar 2009
Location: Munich, Germany
Posts: 105
Rep Power: 18
psosnows is on a distinguished road
Dear Foamers,

I implemented a derived boundary condition, and added a new method. Now I am trying to use this new method "from the main code".

In general, the derived patch field is:
Code:
class myDerivedPatchField
:
    public fixedGradientFvPatchScalarField
{
   TypeName("myDerivedPatch");
//(...) some standard overloading of updateCoeffs(), constructors, etc
   public:
   bool myMethod() 
   {
      return true;
   }
}
Now supposing I created a volScalarField F, which has as one of its boundaries myDerivedPatchField, I want to call that method in the main code of the solver:
Code:
//(...)
int main(int argc, char *argv[])
{
   //(...) declarations, loading, creating volScalarField F
   forAll(F.boundaryField(),b)
   {
      if(isA<myDerivedPatchField>(F.boundaryField()[b]))
      {
         Info << refCast<myDerivedPatchField>(F.boundaryField()[b]).myMethod() <<endl;
      }
   }
}
Unfortunately isA<myDerivedPatchField>(F.boundaryField()[b]) returns always false. From what I get, F.boundaryField()[b] at this level of the code is a fvPatchField, and does not match myDerivedPatchField. At the same time, without the isA<>() check, refCast breaks as it encounters some other boundary type (like zeroGradient).

What should I do to cast an added method in the main code?

Thank you in advance!
Pawel
psosnows is offline   Reply With Quote

Old   December 4, 2013, 03:48
Default
  #2
Member
 
hua1015's Avatar
 
Hua
Join Date: May 2012
Posts: 31
Rep Power: 13
hua1015 is on a distinguished road
Dear Psosnows,
I also met this problem but failed to correct it. Have you got the right way?I will be thankful for your suggestions.
hua1015 is offline   Reply With Quote

Old   December 26, 2013, 14:38
Default
  #3
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
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 to all!

Can either one of you attach the 3 things necessary for replicating this issue? Namely:
  1. The derived boundary condition.
  2. The modified solver.
  3. A test case to use them.
Because I don't know the answer, but if I have access to the 3, I can easily solve your problem.


Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   December 26, 2013, 17:44
Default
  #4
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Good evening,

I do not have access to a prober computer, so I do not have the means of checking the hypothesis, but...:

You should carefully check the "isA<>()" command, because if it take a patchField and not a fvPatchField it makes all the difference. Your boundary condition is derived from a patchField deep down, so you might encounter this problem, because the many derived levels are merely ignored.

Good luck,

Niels
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj is offline   Reply With Quote

Old   December 26, 2013, 18:02
Default
  #5
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Also, it might be that isA asks for the physical type of the boundary condition, i.e. you might want to check on the typeName instead,. Something like this:

Code:
if (F.boundaryField()[p]::typeName == Foam::myDerivedFvPatchField::typeName)
Note that I have not tried to compile this, so it might fail. Especially, I am uncertain of the need of "()" after typeName.

Kind regards,

Niels
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj 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
[Gmsh] discretizer - gmshToFoam Andyjoe OpenFOAM Meshing & Mesh Conversion 13 March 14, 2012 04:35
Comparison: Finite Volume Method vs. Analytic Method m-fry Main CFD Forum 1 April 20, 2010 14:40
Code for most powerfull FDV Method D.S.Nasan Main CFD Forum 6 September 4, 2008 02:08
Help about the preconditioner in gmres method Dan Gao Main CFD Forum 3 July 5, 2008 01:18
hess-smith method and fvm method yangqing FLUENT 0 March 20, 2002 19:25


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