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

Calling a method from derived BC

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

Reply
 
LinkBack Thread Tools 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: Trieste, Italy
Posts: 105
Rep Power: 9
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, 04:48
Default
  #2
New Member
 
hua1015's Avatar
 
Hua
Join Date: May 2012
Posts: 25
Rep Power: 5
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, 15:38
Default
  #3
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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, 18:44
Default
  #4
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Rotterdam, The Netherlands
Posts: 1,595
Rep Power: 24
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, 19:02
Default
  #5
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Rotterdam, The Netherlands
Posts: 1,595
Rep Power: 24
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

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
discretizer - gmshToFoam Andyjoe Open Source Meshers: Gmsh, Netgen, CGNS, ... 13 March 14, 2012 05: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 20:25


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