Hi,
I have currently writing a program to calculate a temperature profile of a building construction. For these calculations I am using an iterative approach. In the final version of the program one data set for each time step of the simulations should be saved (that is one per hour). While testing the program (and also later on as an option) I would also like to store the calculated sub-steps (up to 3600 per hour) and that is where I run into a wall just now.
To store the data I have build a few struct in which I intend to store the data. These are as follows (shortened)
struct Temperature{
Temperature(): pipeInlet(-FLT_MAX),
pipeInletSetpoint(-FLT_MAX){};
float pipeInlet;
float pipeInletSetpoint;
vector<float> node; // the number of nodes depends on the building to be simulated
};
struct HeatFlow{
HeatFlow(): circuit(-FLT_MAX),
floorSurface(-FLT_MAX){};
float circuit;
float floorSurface;
};
struct Results{
Temperature temp;
vector<Temperature> subTemp; // temperatures calculated in sub-timesteps
HeatFlow heat;
vector<HeatFlow> subHeat; // HeatFlows calculated in sub-timesteps
};
In the program I am then using vector<Results> results_ to create one container to store all the simulation results in one place. I would prefer to do this in order not to (for what ever reason) get confused as to which sub time-steps belong to which time-step.
My problem is now: How do I write to this last vector (results_)?
Since I don't know what the size is going to be in the end it would not make sense for me to define the vector with a fixed amount of elements. The only solution I can think of (and also believe that I could pull of) is to always append a single element to the vector when I need it (and I have done this elsewhere with success). The problem here is however that I don't relay know what to do with the vectors included in results_ (e.g. subTemp and subHeat). At this point of the simulation I know very little about them (at best I know the first element, which could just be a copy of the data at the current time-step).
Not quite sure on how good a handle I have on your project, but here goes nothing. I'll just post an example of how I'd push data to each vector. Not sure if it'll be what you're looking for, but it may help a little.
Let's assume that the only struct you're really interested in at the end result is the Results struct. The others are temporary, and used only for storing data into results.
So, somewhere in our code, we'll have:
1 2
vector<Results> results;
Results local_result;
To add something to the vector in Temperature
1 2 3 4
local_result.temp.pipeInlet = 0.5; // Excuse the made up values, example only
local_result.temp.pipeInletSetPoint = 1.5;
local_result.temp.node.push_back(0.4);
local_result.temp.node.push_back(0.5);
Yes, that seams to be exactly what I have been trying to do. I guess my problem was that I wanted to start at the end (sort of). Ordering it as you did seam much more logic (and doable) now.