CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   C question (http://www.cfd-online.com/Forums/openfoam-solving/58877-c-question.html)

kar February 19, 2008 12:43

Hello, I'm not sure what's
 
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.

deepsterblue February 19, 2008 18:06

This has been answered before:
 
This has been answered before:

http://www.cfd-online.com/OpenFOAM_D...tml?1202118865

gschaider February 19, 2008 18:21

The super-classes and member-v
 
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

marziolettich February 20, 2008 04:31

I had the same problem in unde
 
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).

jaswi February 20, 2008 05:15

Hi Karlis Please just read
 
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

tspon February 20, 2008 05:33

Hi guys, sorry for disturbi
 
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

jaswi February 20, 2008 05:49

Hi Thomas Try const lab
 
Hi Thomas

Try

const label patchID = mesh.boundaryMesh().findPatchID("outlet")
volVectorField = U.boundaryField()[patchID]

Hope that helps

Regards
Jaswi

tspon February 20, 2008 06:16

Hi Jaswi, thanks for your q
 
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.

jaswi February 20, 2008 06:33

Hi Thomas As per my underst
 
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

tspon February 20, 2008 07:34

Hi Jaswi, Thanks for your h
 
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

kar February 28, 2008 16:39

Hi, this is me again http://w
 
Hi,
this is me again http://www.cfd-online.com/OpenFOAM_D...part/happy.gif

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

deepsterblue February 28, 2008 17:10

Simple. vectorField::opera
 
Simple.

vectorField::operator= calls the base-class implementation of the '=' operator (from which FvPatchVectorField is derived).

deepsterblue February 29, 2008 11:38

I'm not sure if I've understoo
 
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.

kar February 29, 2008 13:19

Thanks for trying Sandeep! Yo
 
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???

deepsterblue February 29, 2008 13:30

Not just that. The derived cla
 
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.

kar February 29, 2008 13:45

Yeeeeeeesss, I got 60! Thanks
 
Yeeeeeeesss, I got 60!
Thanks for prompt response! I had to be very careful or write your code in new file to diff...

kar March 3, 2008 13:00

Hi, one more thing: in code
 
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

deepsterblue March 3, 2008 18:42

Yes, PtrList gives a Field, wh
 
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.

kar March 4, 2008 04:46

Sandeep, follows, that it's
 
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

dmoroian March 4, 2008 04:57

Hi Kārlis, If you look at th
 
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


All times are GMT -4. The time now is 12:29.