Class - functions

I have a code which says (in some part of the main):
1
2
3
    /*define mesh*/
    mesh electrodeMesh(10e-9,4,10);
    mesh electrolyteMesh(10e-9,4,10);

and mesh is a class defined like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
class mesh
{
public:
        //! Constructor
        /*!
        * Default constructor for mesh.
        * @param nNodes[] is a vector with the number of nodes in the x, y, or z direction.
        */
	mesh();
	mesh(vector<unsigned int>& nNodes, unsigned int nNeighbours, const vector<double> &dimensions);
	mesh(unsigned int nx);
    mesh(double length, unsigned int nDecades, unsigned int pointsPerDecade);
	mesh(double length, unsigned int nx);
    mesh(double lenght, vector<double> xpos);

        //!Destructor
	~mesh();
        //!Copy constructor
	mesh(const mesh & _mesh);
        
    /*!Return a vector<double> with the dimensions of the mesh*/
    vector<double> getDimensions();
    /*!Return the corresponding dimension in direction d*/
    double getDimensions(unsigned int d);
    /*!Return a vector<node> object*/
    vector<node> getNodes();
    /*!Return a node object*/
    node getNode(const unsigned int i);
    /*!Return a vector<face> object*/
    vector<face> getFaces();
    /*!Return a face object*/
    face getFace(const unsigned int i);
    /*!Return the number of neighbors in the mesh*/
    unsigned int nNeighbors();
    /*!Return the total number of node*/
    unsigned int nNodes();
    /*!Return the number of nodes in dimension d*/
    unsigned int nNodes(unsigned int d); 
    /*!Print node position and volume*/
    void printNodes();
    /*!Print face position and surface*/
    void printFaces();
        
        /*! Assign geometric values to the mesh*/
        /*! Discretizes the position of the nodes and the volume of them
         * according to an even distribution of the nodes at the center of
         * the faces.
         * Only implemented in 1D.
         */
	void discretizeFaceCentered();
        /*! Assign geometric values to the mesh*/
        /*! Discretizes the position of the nodes and the volume of them
         * according to an even distribution of the nodes at the center of
         * the volume.
         * Only implemented in 1D.
         */
	void discretizeEven();
        /*! Assign geometric values to the mesh*/
        /*! Discretizes the position of the nodes and the volume of them
         * according to a logarithmic distribution of the nodes.
         * Only implemented in 1D.
         */
	void discretizeLog(unsigned int nDecades, unsigned int pointsPerDecade);
        /*! Assign geometric values to the mesh*/
        /*! Discretizes the position of the nodes according to a finite
         *  difference scheme, without setting either the values of the faces or
         *  the volumes of them*/
        void discretizeFiniteDifferences();
        
        /*Auxiliary distance functions*/
        
        /*! Calculates the distance between 2 node centers*/
        /*! @param n1 origin node
         *  @param n2 final node
         */
	double distanceNodeNode(unsigned int n1, unsigned int n2);
        /*! Calculates the distance from a node to a face*/
        /*! @param n origin node
         *  @param f final face
         */
	double distanceNodeFace(unsigned int n, unsigned int f);
        /*! Calculates the distance from a face to a node*/
        /*! @param f origin face
         *  @param n final node
         */
	double distanceFaceNode(unsigned int f, unsigned int n);
    
    void setSfx(double (*S)(double x));

	friend class FVM;
    friend class FDM;

	friend void setD(FVM& , unsigned int);
	friend void setCoefficients(FVM& , unsigned int);
	friend void setSources(FVM& , unsigned int);
    /*! Initialization function to implement constructors*/
    void initialize(vector<unsigned int>& _nNodes, unsigned int _nNeighbours, const vector<double> &dimensions);

        
private:
	vector<node> m_nodes;
	vector<face> m_faces;
	unsigned int m_nNeighbors;
	unsigned int m_nDimensions;
	unsigned int m_nNodesTotal;
	unsigned int m_nFacesTotal;
	vector<unsigned int> m_nNodesDimension;
	vector<double> m_dimensions;
};


As I understand, the main creates an object of the class mesh and calls the 4th constructor of the class (mesh(double length, unsigned int nDecades, unsigned int pointsPerDecade);).

Then, I have to suppose that all the functions that appear in the class will "be done"?

ryllprous wrote:
Then, I have to suppose that all the functions that appear in the class will "be done"?
I don't know what you mean by this. Functions exist globally, they're part of the code that the OS loads into memory to execute your program. They are not invoked or called unless you do that in your code.
Although my question was not clear enough, you have answered what I asked. Thanks

So, in conclusion: what I'm doing here:

1
2
3
4
5
    mesh electrodeMesh(10e-9,4,10);
    mesh electrolyteMesh(10e-9,4,10);
  
    ElectrodeAssembly anode(electrodeMesh, electrolyteMesh,
                    ReactionMechanism, "Anode");


is just create two objects of the class mesh,, right? I'm not invoking or calling the functions of the class mesh. In order to call them I would have to invoke them somewhere in the main.cpp file (or in the funtions included in the main.cpp file)
And then (in line 4) I create an object of the class ElectrodeAssembly, but I don't invoke the functions of this class neither.


Thank you again for your help..!


Ramon


1
2
3
4
5
6
7
8
9
class ElectrodeAssembly:FuncEval
{
public:
    string name;
    double TPBLengthPerArea;
    /* Bulk phases*/
    IdealGasMix Gas;
  [......]
Last edited on
Topic archived. No new replies allowed.