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

C question

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 19, 2008, 12:43
Default Hello, I'm not sure what's
  #1
kar
Senior Member
 
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17
kar is on a distinguished road
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.
kar is offline   Reply With Quote

Old   February 19, 2008, 18:06
Default This has been answered before:
  #2
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25
deepsterblue will become famous soon enough
This has been answered before:

http://www.cfd-online.com/OpenFOAM_D...tml?1202118865
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   February 19, 2008, 18:21
Default The super-classes and member-v
  #3
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
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
gschaider is offline   Reply With Quote

Old   February 20, 2008, 04:31
Default I had the same problem in unde
  #4
New Member
 
Marzio Lettich
Join Date: Mar 2009
Posts: 14
Rep Power: 17
marziolettich is on a distinguished road
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).
marziolettich is offline   Reply With Quote

Old   February 20, 2008, 05:15
Default Hi Karlis Please just read
  #5
Senior Member
 
Join Date: Mar 2009
Posts: 248
Rep Power: 18
jaswi is on a distinguished road
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
jaswi is offline   Reply With Quote

Old   February 20, 2008, 05:33
Default Hi guys, sorry for disturbi
  #6
New Member
 
Thomas Sponfeldner
Join Date: Mar 2009
Posts: 9
Rep Power: 17
tspon is on a distinguished road
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
tspon is offline   Reply With Quote

Old   February 20, 2008, 05:49
Default Hi Thomas Try const lab
  #7
Senior Member
 
Join Date: Mar 2009
Posts: 248
Rep Power: 18
jaswi is on a distinguished road
Hi Thomas

Try

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

Hope that helps

Regards
Jaswi
jaswi is offline   Reply With Quote

Old   February 20, 2008, 06:16
Default Hi Jaswi, thanks for your q
  #8
New Member
 
Thomas Sponfeldner
Join Date: Mar 2009
Posts: 9
Rep Power: 17
tspon is on a distinguished road
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.
tspon is offline   Reply With Quote

Old   February 20, 2008, 06:33
Default Hi Thomas As per my underst
  #9
Senior Member
 
Join Date: Mar 2009
Posts: 248
Rep Power: 18
jaswi is on a distinguished road
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
jaswi is offline   Reply With Quote

Old   February 20, 2008, 07:34
Default Hi Jaswi, Thanks for your h
  #10
New Member
 
Thomas Sponfeldner
Join Date: Mar 2009
Posts: 9
Rep Power: 17
tspon is on a distinguished road
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
tspon is offline   Reply With Quote

Old   February 28, 2008, 16:39
Default Hi, this is me again http://w
  #11
kar
Senior Member
 
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17
kar is on a distinguished road
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
kar is offline   Reply With Quote

Old   February 28, 2008, 17:10
Default Simple. vectorField::opera
  #12
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25
deepsterblue will become famous soon enough
Simple.

vectorField::operator= calls the base-class implementation of the '=' operator (from which FvPatchVectorField is derived).
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   February 29, 2008, 11:38
Default 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
deepsterblue will become famous soon enough
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.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   February 29, 2008, 13:19
Default Thanks for trying Sandeep! Yo
  #14
kar
Senior Member
 
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17
kar is on a distinguished road
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???
kar is offline   Reply With Quote

Old   February 29, 2008, 13:30
Default Not just that. The derived cla
  #15
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25
deepsterblue will become famous soon enough
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.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   February 29, 2008, 13:45
Default Yeeeeeeesss, I got 60! Thanks
  #16
kar
Senior Member
 
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17
kar is on a distinguished road
Yeeeeeeesss, I got 60!
Thanks for prompt response! I had to be very careful or write your code in new file to diff...
kar is offline   Reply With Quote

Old   March 3, 2008, 13:00
Default Hi, one more thing: in code
  #17
kar
Senior Member
 
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17
kar is on a distinguished road
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
kar is offline   Reply With Quote

Old   March 3, 2008, 18:42
Default Yes, PtrList gives a Field, wh
  #18
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25
deepsterblue will become famous soon enough
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.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   March 4, 2008, 04:46
Default Sandeep, follows, that it's
  #19
kar
Senior Member
 
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17
kar is on a distinguished road
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
kar is offline   Reply With Quote

Old   March 4, 2008, 04:57
Default Hi Kārlis, If you look at th
  #20
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
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
dmoroian 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
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


All times are GMT -4. The time now is 14:28.