/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2013, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
*
* GROMACS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_selection
*/
-#include <string.h>
+#include "gmxpre.h"
+
+#include "position.h"
-#include "gromacs/legacyheaders/smalloc.h"
-#include "gromacs/legacyheaders/typedefs.h"
-#include "gromacs/legacyheaders/vec.h"
+#include <string.h>
+#include "gromacs/math/vec.h"
#include "gromacs/selection/indexutil.h"
-#include "gromacs/selection/position.h"
#include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/smalloc.h"
-/*!
- * \param[out] pos Output structure.
- *
- * Any contents of \p pos are discarded without freeing.
- */
-void
-gmx_ana_pos_clear(gmx_ana_pos_t *pos)
+gmx_ana_pos_t::gmx_ana_pos_t()
{
- pos->nr = 0;
- pos->x = NULL;
- pos->v = NULL;
- pos->f = NULL;
- gmx_ana_indexmap_clear(&pos->m);
- pos->nalloc_x = 0;
+ x = NULL;
+ v = NULL;
+ f = NULL;
+ gmx_ana_indexmap_clear(&m);
+ nalloc_x = 0;
+}
+
+gmx_ana_pos_t::~gmx_ana_pos_t()
+{
+ sfree(x);
+ sfree(v);
+ sfree(f);
+ gmx_ana_indexmap_deinit(&m);
}
/*!
void
gmx_ana_pos_init_const(gmx_ana_pos_t *pos, const rvec x)
{
- gmx_ana_pos_clear(pos);
- pos->nr = 1;
snew(pos->x, 1);
snew(pos->v, 1);
snew(pos->f, 1);
gmx_ana_indexmap_init(&pos->m, NULL, NULL, INDEX_UNKNOWN);
}
-/*!
- * \param[in,out] pos Position data structure.
- *
- * Frees any memory allocated within \p pos.
- * The pointer \p pos itself is not freed.
- *
- * \see gmx_ana_pos_free()
- */
-void
-gmx_ana_pos_deinit(gmx_ana_pos_t *pos)
-{
- pos->nr = 0;
- sfree(pos->x); pos->x = NULL;
- sfree(pos->v); pos->v = NULL;
- sfree(pos->f); pos->f = NULL;
- pos->nalloc_x = 0;
- gmx_ana_indexmap_deinit(&pos->m);
-}
-
-/*!
- * \param[in,out] pos Position data structure.
- *
- * Frees any memory allocated for \p pos.
- * The pointer \p pos is also freed, and is invalid after the call.
- *
- * \see gmx_ana_pos_deinit()
- */
-void
-gmx_ana_pos_free(gmx_ana_pos_t *pos)
-{
- gmx_ana_pos_deinit(pos);
- sfree(pos);
-}
-
/*!
* \param[in,out] dest Destination positions.
* \param[in] src Source positions.
{
if (bFirst)
{
- gmx_ana_pos_reserve(dest, src->nr, 0);
+ gmx_ana_pos_reserve(dest, src->count(), 0);
if (src->v)
{
gmx_ana_pos_reserve_velocities(dest);
gmx_ana_pos_reserve_forces(dest);
}
}
- dest->nr = src->nr;
- memcpy(dest->x, src->x, dest->nr*sizeof(*dest->x));
+ memcpy(dest->x, src->x, src->count()*sizeof(*dest->x));
if (dest->v)
{
GMX_ASSERT(src->v, "src velocities should be non-null if dest velocities are allocated");
- memcpy(dest->v, src->v, dest->nr*sizeof(*dest->v));
+ memcpy(dest->v, src->v, src->count()*sizeof(*dest->v));
}
if (dest->f)
{
GMX_ASSERT(src->f, "src forces should be non-null if dest forces are allocated");
- memcpy(dest->f, src->f, dest->nr*sizeof(*dest->f));
+ memcpy(dest->f, src->f, src->count()*sizeof(*dest->f));
}
gmx_ana_indexmap_copy(&dest->m, &src->m, bFirst);
}
void
gmx_ana_pos_set_nr(gmx_ana_pos_t *pos, int nr)
{
- pos->nr = nr;
+ // TODO: This puts the mapping in a somewhat inconsistent state.
+ pos->m.mapb.nr = nr;
}
/*!
void
gmx_ana_pos_empty_init(gmx_ana_pos_t *pos)
{
- pos->nr = 0;
- pos->m.nr = 0;
pos->m.mapb.nr = 0;
pos->m.mapb.nra = 0;
pos->m.b.nr = 0;
void
gmx_ana_pos_empty(gmx_ana_pos_t *pos)
{
- pos->nr = 0;
- pos->m.nr = 0;
pos->m.mapb.nr = 0;
pos->m.mapb.nra = 0;
/* This should not really be necessary, but do it for safety... */
{
int j, k;
- j = dest->nr;
+ j = dest->count();
copy_rvec(src->x[i], dest->x[j]);
if (dest->v)
{
}
dest->m.mapb.index[j+1] = dest->m.mapb.nra;
dest->m.b.index[j+1] = dest->m.mapb.nra;
- dest->nr++;
- dest->m.nr = dest->nr;
- dest->m.mapb.nr = dest->nr;
- dest->m.b.nr = dest->nr;
+ dest->m.mapb.nr++;
+ dest->m.b.nr++;
}
/*!
{
dest->m.mapb.a[dest->m.mapb.nra++] = src->m.mapb.a[k];
}
- const int j = dest->nr;
+ const int j = dest->count();
if (dest->v)
{
if (src->v)
dest->m.mapid[j] = dest->m.orgid[refid];
}
dest->m.mapb.index[j+1] = dest->m.mapb.nra;
- dest->nr++;
- dest->m.nr = dest->nr;
- dest->m.mapb.nr = dest->nr;
+ dest->m.mapb.nr++;
}
/*!
void
gmx_ana_pos_append_finish(gmx_ana_pos_t *pos)
{
- if (pos->m.nr != pos->m.b.nr)
+ if (pos->m.mapb.nr != pos->m.b.nr)
{
pos->m.bStatic = false;
}