|
[Sponsors] |
February 19, 2008, 12:43 |
Hello,
I'm not sure what's
|
#1 |
Senior Member
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17 |
Hello,
I'm not sure what's the meaning of that part after ":": template<class> fvMatrix<type>::fvMatrix(const fvMatrix<type>& fvm) : refCount(), lduMatrix(fvm), psi_(fvm.psi_), dimensions_(fvm.dimensions_), source_(fvm.source_), internalCoeffs_(fvm.internalCoeffs_), boundaryCoeffs_(fvm.boundaryCoeffs_), faceFluxCorrectionPtr_(NULL) { ... } Could you explain or give some example? K. |
|
February 19, 2008, 18:06 |
This has been answered before:
|
#2 |
Senior Member
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25 |
||
February 19, 2008, 18:21 |
The super-classes and member-v
|
#3 |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
The super-classes and member-variables get initialized
That is the short explanation. Books have been written with longer explanations (on the basics of C++) and I would recommend rereading one of these before even looking at the fvMatrix-class Sorry. But these are the two best explanations I can think of that take less than one page
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
|
February 20, 2008, 04:31 |
I had the same problem in unde
|
#4 |
New Member
Marzio Lettich
Join Date: Mar 2009
Posts: 14
Rep Power: 17 |
I had the same problem in understanding this "initializer list": it's a way to initialize the private member of a class (at least, that's what I understood!). I found an exhaustive answer on a C++ Ubuntu forum: http://ubuntuforums.org/archive/index.php/t-645008.html
Anyway, in some books this "initializer list" is not even mentioned (Schildt's for instance is quite a popular book on C++, but I wasn't able to find it). |
|
February 20, 2008, 05:15 |
Hi Karlis
Please just read
|
#5 |
Senior Member
Join Date: Mar 2009
Posts: 248
Rep Power: 18 |
Hi Karlis
Please just read through a nice book on C++ and you will have no problem with OpenFOAM. I would recommend you the following books: 1) C++ How to Program Harvey M. Deitel and Paul J. Deitel 2) Object-Oriented Programming in C++ by Josuttis. 3) Professional C++ by Kleper, Wrox professional series. Start with the first one and then move on to the next two books. 1st and 3rd are available as compiled HTML books all over the web. Just Google them. OpenFOAM is worth the time you will invest in understanding C++. These books will teach you how to read the code and OpenFOAM will teach you how one can put to real use, all you have read in these books. Wish you a successful FOAMing ahead. Jaswi |
|
February 20, 2008, 05:33 |
Hi guys,
sorry for disturbi
|
#6 |
New Member
Thomas Sponfeldner
Join Date: Mar 2009
Posts: 9
Rep Power: 17 |
Hi guys,
sorry for disturbing you, but I'm looking for some C++ experts who could help me with this little problem, nothing complicated really. I only want to extract the U field values at the outlet of my pipe in order to initialize my U_boundary inlet with the appropriate velocity values from the outlet (kind of manual cyclic). Even after an extensiv search in the documentation as well as in this forum I do not know which command to use. Something like field[outlet] does not help. @ Bernhard: I successfully tried your setParabolicInlet.C but that does not help with turbulent flows or not fully developed flows, I guess. Thanks for your reply in advance. Think its not too difficult for you guys. thomas |
|
February 20, 2008, 05:49 |
Hi Thomas
Try
const lab
|
#7 |
Senior Member
Join Date: Mar 2009
Posts: 248
Rep Power: 18 |
Hi Thomas
Try const label patchID = mesh.boundaryMesh().findPatchID("outlet") volVectorField = U.boundaryField()[patchID] Hope that helps Regards Jaswi |
|
February 20, 2008, 06:16 |
Hi Jaswi,
thanks for your q
|
#8 |
New Member
Thomas Sponfeldner
Join Date: Mar 2009
Posts: 9
Rep Power: 17 |
Hi Jaswi,
thanks for your quick response. I tried a similar one vectorField& outlet = U.boundaryField()[patchID] but the problem is that I only get the entries of the outlet_boundary. What I want is extracting from the U_field of lets say 1000 time steps (simple foam) the entries of the cells forming the outlet of my pipe. That is take for example 50 cells out of 2000. Take these entries and put them in the /0/U boundary_inlet for the next run. So my problem is, how do I tell OpenFoam to take only the ones of the outlet. BTW I could manually do that with the help of paraview but I'll be a mess with more than 50 cells. |
|
February 20, 2008, 06:33 |
Hi Thomas
As per my underst
|
#9 |
Senior Member
Join Date: Mar 2009
Posts: 248
Rep Power: 18 |
Hi Thomas
As per my understanding level, in that case you need to use sets. Define a cellSet comprising of the desired cells and then you can access all the data fields associated to this set. Look into /applications/utilities/mesh/manipulation/ There are examples of faceSetDict, cellSetDict, faceSetDict. Anybody please correct me if I am wrong. Also please checkout a recent post by Dragos. Search the forum for his posts and there you will find a recent post where he has shown how to extract cell sets and the fields related to them. Hope that helps Regards Jaswi |
|
February 20, 2008, 07:34 |
Hi Jaswi,
Thanks for your h
|
#10 |
New Member
Thomas Sponfeldner
Join Date: Mar 2009
Posts: 9
Rep Power: 17 |
Hi Jaswi,
Thanks for your help once again. It works now. I could manage your first hint. It was my fault. I forgot to put in the time steps and only tried for the /U/0. Therefore the outlet had no entries. Sorry for that. BTW the faceSet hint could be of great importance for me. I'll have a look. Regards Thomas |
|
February 28, 2008, 16:39 |
Hi,
this is me again http://w
|
#11 |
Senior Member
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17 |
Hi,
this is me again One more C++ question - I try to make my own boundary condition that involves gradient, but don't understand what is done when something like this: "vectorField::operator=(n_*maxValue_*(1.0 - sqr(coord)));" is called in parabolic U BC by Harvoje: void parabolicVelocityFvPatchVectorField::updateCoeffs( ) { // Get range and orientation boundBox bb(patch().patch().localPoints(), false); vector ctr = 0.5*(bb.max() + bb.min()); const vectorField& c = patch().Cf(); // Calculate local 1-D coordinate for the parabolic profile scalarField coord = ((c - ctr) & y_)/((bb.max() - bb.min()) & y_); vectorField::operator=(n_*maxValue_*(1.0 - sqr(coord))); } I managed to make similar BC based on fixedValue, but not yet on fixedGradient, which is necessary indeed. That requires better understanding of code. Please explain about "vectorField::operator=(n_*maxValue_*(1.0 - sqr(coord)));"! Kārlis |
|
February 28, 2008, 17:10 |
Simple.
vectorField::opera
|
#12 |
Senior Member
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25 |
Simple.
vectorField::operator= calls the base-class implementation of the '=' operator (from which FvPatchVectorField is derived). |
|
February 29, 2008, 11:38 |
I'm not sure if I've understoo
|
#13 |
Senior Member
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25 |
I'm not sure if I've understood this right, but here goes - Do you want to access the '=' operator of the base class using the derived class? If that's the case, here's the modified code:
#include <iostream> using namespace std; class base { private: int x; public: base(const int& a = 2) : x(a) {} const int gx() {return x;} void se(int& i) {x=i;} void operator=(int k); }; class deriv : public base { private: int z; public: deriv(const int &tz, const int & x): z(tz), base(x) { } const int & mul(){ int rez = z*base::gx(); int & p = rez; return p; } //void operator=(int k) {z = k;} }; void base::operator=(int k) { x = k; } int main(int argc, char ** args) { deriv d(6, 7); d.base::operator=(10); cout << d.mul() << "\n"; return 0; } It gives me the answer you want. Hope this helps. |
|
February 29, 2008, 13:19 |
Thanks for trying Sandeep!
Yo
|
#14 |
Senior Member
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17 |
Thanks for trying Sandeep!
You just added ".base::operator=(10)", right? Somehow my compiler says: operators2.cpp: In function 'int main(int, char**)': operators2.cpp:5: error: 'class base' is inaccessible operators2.cpp:35: error: within this context operators2.cpp:35: error: 'base' is an inaccessible base of 'deriv' GNU C++ version 4.2.1 (i686-pc-linux-gnu) compiled by GNU C version 4.2.1. Comments??? |
|
February 29, 2008, 13:30 |
Not just that. The derived cla
|
#15 |
Senior Member
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25 |
Not just that. The derived class is defined as:
class deriv : public base This allows deriv to access the public members of its base class. |
|
February 29, 2008, 13:45 |
Yeeeeeeesss, I got 60!
Thanks
|
#16 |
Senior Member
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17 |
Yeeeeeeesss, I got 60!
Thanks for prompt response! I had to be very careful or write your code in new file to diff... |
|
March 3, 2008, 13:00 |
Hi,
one more thing: in code
|
#17 |
Senior Member
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17 |
Hi,
one more thing: in code above one has to call d.base::operator=(10); to access operator in base class. Let T be volScalarField. T.boundaryField()[patchID][faceID]; works, despite there is no operator[] in GeometricBoundaryField, nor FieldField, just in class PtrList (to access [patchID]! There are numerous other similar examples, so my question now is: when members of base or base-base-..-base class can be accessible directly? Kārlis |
|
March 3, 2008, 18:42 |
Yes, PtrList gives a Field, wh
|
#18 |
Senior Member
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25 |
Yes, PtrList[patchID] gives a Field, which is in turn derived from List, and so on. The base has an operator[] implementation, which is used.
Without looking at the details, I'm guessing that something like this is being done: #include <iostream> using namespace std; class base { private: int x; public: base(const int& a = 2) : x(a) {} const int gx() {return x;} void se(int& i) {x=i;} void operator=(int k); }; void base::operator=(int k) { x = k; } class deriv : public base { private: int z; public: deriv(const int &tz, const int & x): z(tz), base(x) { } const int & mul(){ int rez = z*base::gx(); int & p = rez; return p; } void operator=(int k) { this->base::operator=(k);} }; int main(int argc, char ** args) { deriv d(6, 7); d=10; cout << d.mul() << "\n"; return 0; } As you can see, I've just used 'd=10', which gives me the same answer you want. |
|
March 4, 2008, 04:46 |
Sandeep,
follows, that it's
|
#19 |
Senior Member
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17 |
Sandeep,
follows, that it's sufficient to prove there is no direct member function operator[] for GeometricBoundaryField,to show something other is done in OpenFOAM code. I'm quite sure there is no operator[] in GeometricBoundaryField class. (reviewed class declaration + searched through ALL OF code for " GeometricBoundaryField" and "::operator\[\]" in one line. No results!) So, my question remains - why T.boundaryField()[patchID] returns element of PtrList? Kārlis |
|
March 4, 2008, 04:57 |
Hi Kārlis,
If you look at th
|
#20 |
Senior Member
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20 |
Hi Kārlis,
If you look at the inheritance diagram GeometricBoundaryField, you'll see that it inherits the PtrList (among other classes). Consequently (see List of all members), one of the inherited operators is operator[](const label); and guess what it returns...? Dragos |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Question concerning VOF | Flora | FLUENT | 2 | July 9, 2007 10:50 |
question about LES | gino briganti | FLUENT | 3 | June 27, 2005 07:05 |
A question | zhhuang | Siemens | 0 | April 29, 2003 02:44 |
The question about Y+ | rambol | CFX | 2 | November 7, 2002 10:40 |
Another UDF question | Christian | FLUENT | 7 | July 23, 2002 05:19 |