|
[Sponsors] |
[OpenFOAM 1.7.1] runTimeSelection two levels deep? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 29, 2012, 09:37 |
[OpenFOAM 1.7.1] runTimeSelection two levels deep?
|
#1 |
Senior Member
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 16 |
Hi all,
I am trying to implement some models in OpenFOAM and need some advice on the strategy. Basically the structure is this: Let's say the base is A, and when the user chooses to activate the feature A, he/she has the choice of two models B and C. This part is easy to implement using runTime selection. Now I want to add a new model to the mix, so that the user can choose feature A, and then the models B,C or D. The new thing about D is that D can have submodels, say D0 and D1. If I am not wrong in this case I would need runTimeSelection that is two levels deep. Is it at all possible in the current framework? And if you can point me to a place where something similar has been done it'll be great. |
|
January 29, 2012, 15:07 |
|
#2 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,901
Rep Power: 37 |
Good evening Adhiraj
What you are asking about is definitely possible, however, what you are after is still a bit unclear to me. So the interface, which both B, C, and D obeys to is identical. Nevertheless, D has some special properties which differs, namely D0 and D1, so the question is: Why are you not simply making two runTime selectable object E and F, where E=D+D0 and F=D+D1? To make it into a practical discussion, then D0 and D1 describes the behaviour of one particular parameter, so if you want your original design, then you can make a runTime selection of say myDFunctionalityParameter and in D you get a pointer to this object in the standard runTime way, namely Code:
autoPtr<myDFunctionalityParameter> Dparameter = DN::New(argList); scalar returnMyParameter = Dparameter->param(); I hope this helps. Kind regards, Niels |
|
January 29, 2012, 21:41 |
|
#3 |
Senior Member
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 16 |
Thanks for replying.
I am not fully sure what you meant, but possibly something like this: Implement A, B, C, D as usual. Put the functionalities D0 and D1 in a different class, which runs with P as base, and E and F derived from it. So now D has as a member a pointer to P, and using runtime selection that pointer gives D access to the appropriate model E or F. |
|
January 30, 2012, 03:28 |
|
#4 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,901
Rep Power: 37 |
Hi
No, you have mixed my suggestions together. I suggest the following possibilities: 1. Make the derived classes from A, which are called B, C, DD0, DD1, where DD0 is the derived class D from A, which explicitly contains the methods held in D0, and similar for DD1. DD0 and DD1 are those I called E and F. 2. The second option is to make the derived classes B, C, D, from the (abstract) base class A. Then, as you state, D holds a pointer to an abstract base class P, from which you derive D0 and D1, which are then chosen using runTime selection. If D0 and D1 is simple and you are not going to extend it, then at least as a start I would go for "1", whereas, if the complexity is large, and D0 and D1 contains many methods, then go straight for "2". Kind regards, Niels |
|
|
|