We already copy the data once from the OPM state into the ERT-managed
memory, so we may as well fudge a conversion routine in there (at the
expense of having to do this everywhere).
The writeTimeStep method is called *after* each timestep and does
not include the initial state of the reservoir. If the writer wants
to dump the initial state of the reservoir, this must be done in
writeInit, which is called before the simulator is run, but after
the initial state has been set up.
The Eclipse timestep index can not always be retrieved from the
SimulatorTimer object; the initial state is 0 in Eclipse (and does not
have an index in OPM), and the timestep in OPM is not increased until
*after* the timestep is completed (i.e. it is not initialized to -1).
We would like to build up and write the header only once (with
ecl_sum_fwrite_smspec) and then the data for each timestep (with
ecl_sum_fwrite_step), but since the data attach to the summary
object and so does the header, how do we keep the header in memory
without also accumulating all the data?
Instead of calling the destroy functions for the timestep and well
report objects, the ERT memory allocated for these are contained in
the summary handle and freed together with that.
The timestep and well report objects thus becomes only views into this
memory; it is no longer allowed for these to outlive the summary section
(not that this was ever sensible in the first place).
Although this will lead to parsing the same input data over and over
again (setting up the smspecs for the wells), the summary files contain
this redundant information because in Eclipse, wells can appear and
disappear during the run.
Although GCC 4.6.3 implements div by including stdlib.h (where
everything is put in the global namespace), and then importing these
into std, not every compiler does this (one could for instance think
that in #include <stdlib.h> inside the namespace).
The original rationale for commit c39d367 was to pass a pointer since
this was all we got from one of the APIs. However, just after the code
was changed to copy the data anyway since it would have to be converted
from double to float.
Reverting actually serves a purpose; as @bska pointed out, taking
&data[0] of an empty vector is undefined, whereas it now checks the
size and assert here (and not in the standard library) on that condition.
The EclipseSummary field is just forward declared in the header, and
the compiler cannot create a proper destructor based on just that. If
we define it in the compilation unit, it will get instantiated there
once and for all and the compiler won't try to create it (and leave it
to the linker to sort out duplicates) everywhere the header is used
(which may be in another module, even).
This is similar to commit 18b9f2b for SimulatorOutput.
Since all construction should go through the wrapper method, and the
class otherwise just handed everything down to the base class, we might
as well inline everything in there to avoid someone starting to make
their own objects of this type.
Instead of having each timestep available just locally in the
writeTimeStep method, which will free the memory and create a
corruption error, keep all timesteps on a free list in the summary,
and do all the writing in the destructor there (the memory of the
individual timesteps will have to linger on anyway).
ERT requires the type of the keywords that are passed to the grid
allocation routine to be float (and it is checked - causes abort if
there is a mismatch!)
Clients written to the C++03 standard (most of opm-core, really) do
obviously not use shared_ptr, and most likely takes references with
an implicit lifetime guarantee instead. Converting everything to
shared_ptr is a task for the long run.
This constructor provides the conversion routine that is most likely
to be used: To rely on the lifetime through convention, and then
wrapping everything with share_obj.
It should be considered deprecated out of the box; as soon as you
have the chance to use shared_ptr instead, you should do so.
The Event type must be known because we call it from the inline template
method. The alternative is worse, we'd have to instantiate the template
for every possible simulator type in the .cpp!
If the compiler is to create the default destructor for us, it will
need the size of the OutputWriter type to be defined at the time of
inclusion in the header. By explicitly defining it in a compilation
unit, we can avoid that.
When the sim parameter is a pointer to a simulator, we must of course
use indirect access to its field; the shared_ptr template class does not
have this method!
The writer will need to know which cells are the active cells after
post-processing (because these are the cells there is stored results
for in the pressure and saturation arrays), and thus not only the
raw input grid (to get the COORD and ZCORN arrays which is not easily
detainable from the UnstructuredGrid), *and* the UnstructuredGrid
needs to be available.
I originally wanted to make share_obj a class so that I could hide the
helper function, but it turned out that I needed a function after all
since a function template can be inferred from the parameters but the
type cannot from the constructor.
By returning a shared_ptr directly, the compiler can do return object
optimization.
The template function share_obj let you pass regular references
as shared pointers, which makes it easy (perhaps too easy) to quick-
fix old code which pass references and have stern warnings about the
lifetime rules of the objects in the documentation section instead.
This wrapper class aggregate all the result objects (state, timer
etc.) and register itself for notification with the simulator. At
every timestep the simulator should provide a notification. The
wrapper will receive this and pass all the state objects to the
writer(s) which creates a new timestep.
Currently this doesn't work out-of-the-box because only the
two-phase simulator sends notifications and the writer only
understand the state of blackoil simulators, but these two concepts
should be unified.
If an interface requires a shared_ptr, but we have an object that is
known to outlive the client anyway, we can use a custom deleter to
suppress the delete part and pass this object around anyway.
The code is now allowed to use C++11, where shared_ptr is available
in the standard. To specify that the parser object must be present
for the output writer in its entire lifetime, we require to be passed
a shared_ptr. (This can be faked for local storage anyway).