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

How to add a new class locally

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

Reply
 
LinkBack Thread Tools Display Modes
Old   December 8, 2006, 06:20
Default Hi, This question has not bee
  #1
Member
 
ville vuorinen
Join Date: Mar 2009
Posts: 63
Rep Power: 8
ville is on a distinguished road
Hi,
This question has not been asked and I thought this
could be usefull for many beginners like me: how to add a new class locally? Without any functionality I tried to add to the same folder where my solver is located just the frames for a new class. First, I included in the Make/files the new .C file. Then, naming the class sV the files
are:

my sV.C file:
**************
#include "sV.H"

namespace Foam {
sV::sV(){} // constructor
}

my sV.H file:
**************
#ifndef sampleLinesV_H
#define sampleLinesV_H
namespace Foam {
class sampleLinesV
{
public:
sampleLinesV();
};
}
#endif

******************
And in the main solver .C-file
I include the sV.H before main
and try to create an object inside
the main by stating

sV sob();

I tried also Foam::sV sob();
I also removed the namespaces from .C and .H
and tried all kinds of combinations but these did not work (to mention: removing the namespaces
produced a compiled version but no functionality
could be added to the class..). I think I should add some header
files (such as standard libraries in c) to my new class but which headers are those?

What about the namespace: why is practically everything (?) declared inside a namespace Foam
and what consequences does this have?
If someone could clarify and I can summarize
my experiences thereafter!

Thank you!
-Ville
ville is offline   Reply With Quote

Old   December 8, 2006, 09:56
Default Sorry for confusion, of course
  #2
Member
 
ville vuorinen
Join Date: Mar 2009
Posts: 63
Rep Power: 8
ville is on a distinguished road
Sorry for confusion, of course I meant sV instead of sampleLinesV. This 'sV' was just an abbreviation
I mailed here. So the class name I want to declare is sV.
-Ville
ville is offline   Reply With Quote

Old   December 8, 2006, 11:38
Default Hi Ville, your example look
  #3
Senior Member
 
Markus Hartinger
Join Date: Mar 2009
Posts: 102
Rep Power: 8
hartinger is on a distinguished road
Hi Ville,

your example looks alright, post the code and error message next time, otherwise its hard to say anything.

Namespace:
Namespaces are used to get some order in big projects and to avoid name conflicts. A class name like "vector" is relatively likely to used by many programmers. So to make sure to get the Foam "vector" you write "Foam::vector". Inside Namespaces you can have more Namespaces. A Foam example would be "Foam::fvc::div" and "Foam::fvm::div", which are explicit and implicit implementations of the divergence of a field.

markus
hartinger is offline   Reply With Quote

Old   December 11, 2006, 10:10
Default Thank you for the answer! To
  #4
Member
 
ville vuorinen
Join Date: Mar 2009
Posts: 63
Rep Power: 8
ville is on a distinguished road
Thank you for the answer!
To repeat, in the folder /mysolver/ I wanted
to add a new class sV. Thus I add here the
files sV.C and sV.H and add the sV.C in the
/Make/files. The #include "sV.H" is added before
main in the mysolver.C. I would just like to
first make a function returning an integer.
Here are the files:

.C
*******************
#include "sV.H"

namespace Foam {
sV::sV(const int tolerance):tole_(tolerance){}
int fV() { int integ; return(10);}
}


.H
********************
#ifndef sV_H
#define sV_H

namespace Foam {
class sV
{
const int tole_;
public:
sV(const int tolerance);
int fV();
};
}
#endif

and in mysolver.C
**********************
int number;

sV sobj(3);
number=sobj().fV();


1) I could not define any OF types such as scalars in my own files. int as a type was accepted. This made me to suspect I should add some headers.

2) Does working inside a namespace already include
some standard libraries?


Here is the compilation error with this configuration:

DroptrackV.C: In function 'int main(int, char**)':
DroptrackV.C:90: error: no match for call to '(Foam::sV) ()'
make: *** [Make/linuxGcc4DPOpt/DroptrackV.o] Error 1

What is the mistake I'm making?
Thank you for the help!
-Ville
ville is offline   Reply With Quote

Old   December 11, 2006, 14:20
Default Hi Ville, 1) you're right.
  #5
Senior Member
 
Markus Hartinger
Join Date: Mar 2009
Posts: 102
Rep Power: 8
hartinger is on a distinguished road
Hi Ville,

1) you're right. Add "fvCFD.H" at the top of your .H file. If you the compiler doesn't know a certain Foam thing, you have to include the appropriate Header file. Look at the example codes

2) No, it's just saving typing. Instead of "Foam::scalar" or "Foam::vector" you write "scalar" and "vector" if you're working inside a namspace. Namespaces are only for book-keeping.

regards
Markus
hartinger 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
Tmp class maka OpenFOAM Bugs 2 August 20, 2008 14:53
UDF_Define Turbulent_Viscosity locally efisio Solazzo FLUENT 0 March 29, 2007 11:37
Class Project Tiger Main CFD Forum 5 March 13, 2006 16:58
CFD class notes Lee Main CFD Forum 0 January 30, 2004 13:39
Export locally refine meshes to Tecplot Jens CD-adapco 3 June 18, 2003 18:02


All times are GMT -4. The time now is 18:36.