|
[Sponsors] |
December 8, 2006, 06:20 |
Hi,
This question has not bee
|
#1 |
Member
ville vuorinen
Join Date: Mar 2009
Posts: 67
Rep Power: 17 |
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 |
|
December 8, 2006, 09:56 |
Sorry for confusion, of course
|
#2 |
Member
ville vuorinen
Join Date: Mar 2009
Posts: 67
Rep Power: 17 |
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 |
|
December 8, 2006, 11:38 |
Hi Ville,
your example look
|
#3 |
Senior Member
Markus Hartinger
Join Date: Mar 2009
Posts: 102
Rep Power: 17 |
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 |
|
December 11, 2006, 10:10 |
Thank you for the answer!
To
|
#4 |
Member
ville vuorinen
Join Date: Mar 2009
Posts: 67
Rep Power: 17 |
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 |
|
December 11, 2006, 14:20 |
Hi Ville,
1) you're right.
|
#5 |
Senior Member
Markus Hartinger
Join Date: Mar 2009
Posts: 102
Rep Power: 17 |
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 |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Tmp class | maka | OpenFOAM Bugs | 2 | August 20, 2008 15:53 |
UDF_Define Turbulent_Viscosity locally | efisio Solazzo | FLUENT | 0 | March 29, 2007 12: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 | Siemens | 3 | June 18, 2003 19:02 |