I am a C++ beginner. I have questions regarding vectors of vectors. I have read the available threads on this topic and would very much appreciate it if someone could help with further questions. I apologize in advance for my ignorance!
Here is what I need to do: set up a finite element problem. Specifically, I need to (1) construct a 2-D grid (x and y points/nodes). Plus, (2) each node/point needs to have a vector associated with it (of physical properties like density, viscosity, etc).
Here is how I am thinking of doing it: use a 3-D vector. Two of the vectors would deal with the mesh/grid for the finite difference calculation and the third vector would contain the physical properties (density, etc). So question 1 is, does this sound like a good approach? If so, does anyone have a simple example of this?
Question 2: I would like to have a class called "Mesh" that will contain the data members x and y (for the nodes that make up the mesh). it will also contain physical properties. The thing is, as I continue with this project, I expect things to get complicated. So I would like to have 3 files: a header file where the Mesh class and its data members and member functions are declared, a .cpp file where the data members and member functions are defined, and a main file. The problem is, I cannot figure out 1) how to declare a 3-D vector in the header file and 2) I cannot figure out exactly how to define it in the .cpp definition file. I am fine with declaring and defining variables, but the 3D vector syntax is confusing me...
Specifically, in the header, would/could I have this:
I have the same stance on multi-D vectors as I do multi-D arrays: I hate them. (Well it's not that they're bad, they're just overused / misused)
A grid does not call for a 2D vector. It calls for a 1D array/vector. Layering vectors upon vectors upon vectors impedes performance and is unnecessary.
However... putting a vector in the node makes sense IF each node is going to have a different amount of properties. Since I find this a little puzzling... I'm not sure this is really what you need.
My approach would be to make a 'Properties' struct/class and have a 1D vector to it. Or if you don't like using 1D vectors for 2D lookup, you can wrap the vector in a class to access it 2D style.
Thanks a lot for your example and for your advice about using vectors of vectors!
It is going to take me a while to work through your example (not yet familiar with templates and operator keyword--good opportunity to learn!), but at first glance it looks like exactly what I need to get started. I hope you won't mind if I maybe post a few questions down the line... I'd like to develop good habits and I might want to ask you more about your comments on putting vectors on the nodes and using vectors of vectors in general.
Thanks again; really appreciate all the time you put in here.