Merge branch release-2016
[alexxy/gromacs.git] / src / gromacs / mdlib / trajectory_writing.cpp
index 206bb1f83b05d4c539f571b7aeabb37b003eff4d..af0bc7785de4bd5acc973bec604e5da04ed14497 100644 (file)
 #include "gromacs/mdlib/sim_util.h"
 #include "gromacs/mdlib/update.h"
 #include "gromacs/mdtypes/commrec.h"
-#include "gromacs/mdtypes/energyhistory.h"
 #include "gromacs/mdtypes/inputrec.h"
+#include "gromacs/mdtypes/observableshistory.h"
+#include "gromacs/mdtypes/state.h"
 #include "gromacs/timing/wallcycle.h"
 #include "gromacs/topology/topology.h"
 #include "gromacs/utility/smalloc.h"
 
 void
-do_md_trajectory_writing(FILE           *fplog,
-                         t_commrec      *cr,
-                         int             nfile,
-                         const t_filenm  fnm[],
-                         gmx_int64_t     step,
-                         gmx_int64_t     step_rel,
-                         double          t,
-                         t_inputrec     *ir,
-                         t_state        *state,
-                         t_state        *state_global,
-                         gmx_mtop_t     *top_global,
-                         t_forcerec     *fr,
-                         gmx_mdoutf_t    outf,
-                         t_mdebin       *mdebin,
-                         gmx_ekindata_t *ekind,
-                         rvec           *f,
-                         int            *nchkpt,
-                         gmx_bool        bCPT,
-                         gmx_bool        bRerunMD,
-                         gmx_bool        bLastStep,
-                         gmx_bool        bDoConfOut,
-                         gmx_bool        bSumEkinhOld
+do_md_trajectory_writing(FILE               *fplog,
+                         t_commrec          *cr,
+                         int                 nfile,
+                         const t_filenm      fnm[],
+                         gmx_int64_t         step,
+                         gmx_int64_t         step_rel,
+                         double              t,
+                         t_inputrec         *ir,
+                         t_state            *state,
+                         t_state            *state_global,
+                         ObservablesHistory *observablesHistory,
+                         gmx_mtop_t         *top_global,
+                         t_forcerec         *fr,
+                         gmx_mdoutf_t        outf,
+                         t_mdebin           *mdebin,
+                         gmx_ekindata_t     *ekind,
+                         PaddedRVecVector   *f,
+                         int                *nchkpt,
+                         gmx_bool            bCPT,
+                         gmx_bool            bRerunMD,
+                         gmx_bool            bLastStep,
+                         gmx_bool            bDoConfOut,
+                         gmx_bool            bSumEkinhOld
                          )
 {
     int   mdof_flags;
-    rvec *x_for_confout = NULL;
+    rvec *x_for_confout = nullptr;
 
     mdof_flags = 0;
     if (do_per_step(step, ir->nstxout))
@@ -139,11 +141,12 @@ do_md_trajectory_writing(FILE           *fplog,
                     update_ekinstate(&state_global->ekinstate, ekind);
                     state_global->ekinstate.bUpToDate = TRUE;
                 }
-                update_energyhistory(state_global->enerhist, mdebin);
+
+                update_energyhistory(observablesHistory->energyHistory.get(), mdebin);
             }
         }
         mdoutf_write_to_trajectory_files(fplog, cr, outf, mdof_flags, top_global,
-                                         step, t, state, state_global, f);
+                                         step, t, state, state_global, observablesHistory, f);
         if (bCPT)
         {
             (*nchkpt)++;
@@ -152,7 +155,7 @@ do_md_trajectory_writing(FILE           *fplog,
             bDoConfOut && MASTER(cr) &&
             !bRerunMD)
         {
-            if (fr->bMolPBC && state->x == state_global->x)
+            if (fr->bMolPBC && state == state_global)
             {
                 /* This (single-rank) run needs to allocate a
                    temporary array of size natoms so that any
@@ -162,13 +165,13 @@ do_md_trajectory_writing(FILE           *fplog,
                    identical, and makes .edr restarts binary
                    identical. */
                 snew(x_for_confout, state_global->natoms);
-                copy_rvecn(state_global->x, x_for_confout, 0, state_global->natoms);
+                copy_rvecn(as_rvec_array(state_global->x.data()), x_for_confout, 0, state_global->natoms);
             }
             else
             {
                 /* With DD, or no bMolPBC, it doesn't matter if
-                   we change state_global->x */
-                x_for_confout = state_global->x;
+                   we change as_rvec_array(state_global->x.data()) */
+                x_for_confout = as_rvec_array(state_global->x.data());
             }
 
             /* x and v have been collected in mdoutf_write_to_trajectory_files,
@@ -183,9 +186,9 @@ do_md_trajectory_writing(FILE           *fplog,
             }
             write_sto_conf_mtop(ftp2fn(efSTO, nfile, fnm),
                                 *top_global->name, top_global,
-                                x_for_confout, state_global->v,
+                                x_for_confout, as_rvec_array(state_global->v.data()),
                                 ir->ePBC, state->box);
-            if (fr->bMolPBC && state->x == state_global->x)
+            if (fr->bMolPBC && state == state_global)
             {
                 sfree(x_for_confout);
             }