make the Body struct standalone so we can use a forward declaration

This commit is contained in:
Axel Kohlmeyer
2023-12-15 18:14:28 -05:00
parent 06a445fd4c
commit 51b38c5b24
7 changed files with 65 additions and 61 deletions

View File

@ -30,7 +30,7 @@
#include "domain.h"
#include "error.h"
#include "fix.h"
#include "fix_rigid_nve_small.h"
#include "fix_rigid_small.h"
#include "force.h"
#include "group.h"
#include "improper.h"
@ -771,7 +771,7 @@ void FixHMC::save_current_state()
stored_nghost_body = fix_rigid->nghost_body;
stored_ntotal_body = stored_nlocal_body + stored_nghost_body;
delete stored_body;
stored_body = new FixRigidSmall::Body[stored_ntotal_body];
stored_body = new RigidSmallBody[stored_ntotal_body];
for (int i = 0; i < stored_ntotal_body; i++) stored_body[i] = fix_rigid->body[i];
}
@ -919,14 +919,14 @@ void FixHMC::random_velocities()
void FixHMC::rigid_body_random_velocities()
{
FixRigidSmall::Body *body = fix_rigid->body;
RigidSmallBody *body = fix_rigid->body;
int nlocal = fix_rigid->nlocal_body;
int ntotal = nlocal + fix_rigid->nghost_body;
int *mask = atom->mask;
double stdev, bmass, wbody[3], mbody[3];
double total_mass = 0;
FixRigidSmall::Body *b;
RigidSmallBody *b;
double vcm[] = {0.0, 0.0, 0.0};
for (int ibody = 0; ibody < nlocal; ibody++) {
@ -985,10 +985,10 @@ void FixHMC::rigid_body_random_velocities()
int FixHMC::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, int * /*pbc*/)
{
int *bodyown = fix_rigid->bodyown;
FixRigidSmall::Body *body = fix_rigid->body;
RigidSmallBody *body = fix_rigid->body;
int i, m, ibody;
FixRigidSmall::Body *b;
RigidSmallBody *b;
m = 0;
for (i = 0; i < n; i++) {
@ -1021,10 +1021,10 @@ int FixHMC::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, i
void FixHMC::unpack_forward_comm(int n, int first, double *buf)
{
int *bodyown = fix_rigid->bodyown;
FixRigidSmall::Body *body = fix_rigid->body;
RigidSmallBody *body = fix_rigid->body;
int i, m, last;
FixRigidSmall::Body *b;
RigidSmallBody *b;
m = 0;
last = first + n;
@ -1210,7 +1210,7 @@ double FixHMC::memory_usage()
}
}
bytes += stored_ntotal_body * sizeof(FixRigidSmall::Body);
bytes += stored_ntotal_body * sizeof(RigidSmallBody);
bytes += nvalues * atom->nmax * sizeof(double);
return bytes;

View File

@ -12,9 +12,9 @@
------------------------------------------------------------------------- */
#ifdef FIX_CLASS
FixStyle(hmc, FixHMC)
// clang-format off
FixStyle(hmc,FixHMC)
// clang-format on
#else
#ifndef LMP_FIX_HMC_H
@ -22,31 +22,30 @@ FixStyle(hmc, FixHMC)
#include "atom.h"
#include "fix.h"
#include "fix_rigid_small.h"
namespace LAMMPS_NS {
class FixHMC : public Fix {
public:
FixHMC(class LAMMPS *, int, char **);
~FixHMC();
void post_constructor();
int setmask();
void init();
void setup(int);
void end_of_step();
double compute_scalar();
double compute_vector(int);
~FixHMC() override;
void post_constructor() override;
int setmask() override;
void init() override;
void setup(int) override;
void end_of_step() override;
double compute_scalar() override;
double compute_vector(int) override;
int pack_forward_comm(int, int *, double *, int, int *);
void unpack_forward_comm(int, int, double *);
int pack_reverse_comm(int, int, double *);
void unpack_reverse_comm(int, int *, double *);
void grow_arrays(int);
void copy_arrays(int, int, int);
int pack_exchange(int, double *);
int unpack_exchange(int, double *);
double memory_usage();
int pack_forward_comm(int, int *, double *, int, int *) override;
void unpack_forward_comm(int, int, double *) override;
int pack_reverse_comm(int, int, double *) override;
void unpack_reverse_comm(int, int *, double *) override;
void grow_arrays(int) override;
void copy_arrays(int, int, int) override;
int pack_exchange(int, double *) override;
int unpack_exchange(int, double *) override;
double memory_usage() override;
private:
void setup_arrays_and_pointers();
@ -64,7 +63,7 @@ class FixHMC : public Fix {
tagint *stored_tag;
int stored_nlocal, stored_nghost, stored_ntotal, stored_nmax;
int stored_nbonds, stored_nangles, stored_ndihedrals, stored_nimpropers;
FixRigidSmall::Body *stored_body;
class RigidSmallBody *stored_body;
int stored_nlocal_body, stored_nghost_body, stored_ntotal_body;
int *stored_bodyown;
tagint *stored_bodytag;

View File

@ -39,6 +39,7 @@ using namespace LAMMPS_NS;
using namespace FixConst;
using namespace MathConst;
using namespace RigidConst;
typedef RigidSmallBody Body;
typedef struct {
double x, y, z;

View File

@ -13,7 +13,7 @@
------------------------------------------------------------------------- */
#include "compute_rigid_local.h"
#include <cstring>
#include "atom.h"
#include "update.h"
#include "domain.h"
@ -22,6 +22,8 @@
#include "memory.h"
#include "error.h"
#include <cstring>
using namespace LAMMPS_NS;
#define DELTA 10000
@ -150,7 +152,7 @@ int ComputeRigidLocal::compute_rigid(int flag)
{
int i,m,n,ibody;
double *ptr;
FixRigidSmall::Body *body;
RigidSmallBody *body;
double xprd = domain->xprd;
double yprd = domain->yprd;

View File

@ -42,6 +42,7 @@ using namespace LAMMPS_NS;
using namespace FixConst;
using namespace MathExtra;
using namespace RigidConst;
typedef RigidSmallBody Body;
/* ---------------------------------------------------------------------- */

View File

@ -48,6 +48,7 @@ using namespace LAMMPS_NS;
using namespace FixConst;
using namespace MathConst;
using namespace RigidConst;
typedef RigidSmallBody Body;
#define RVOUS 1 // 0 for irregular, 1 for all2all

View File

@ -24,6 +24,29 @@ FixStyle(rigid/small,FixRigidSmall);
namespace LAMMPS_NS {
struct RigidSmallBody {
int natoms; // total number of atoms in body
int ilocal; // index of owning atom
double mass; // total mass of body
double xcm[3]; // COM position
double xgc[3]; // geometric center position
double vcm[3]; // COM velocity
double fcm[3]; // force on COM
double torque[3]; // torque around COM
double quat[4]; // quaternion for orientation of body
double inertia[3]; // 3 principal components of inertia
double ex_space[3]; // principal axes in space coords
double ey_space[3];
double ez_space[3];
double xgc_body[3]; // geometric center relative to xcm in body coords
double angmom[3]; // space-frame angular momentum of body
double omega[3]; // space-frame omega of body
double conjqm[4]; // conjugate quaternion momentum
int remapflag[4]; // PBC remap flags
imageint image; // image flags of xcm
imageint dummy; // dummy entry for better alignment
};
class FixRigidSmall : public Fix {
friend class ComputeRigidLocal;
friend class FixHMC;
@ -82,34 +105,11 @@ class FixRigidSmall : public Fix {
tagint maxmol; // max mol-ID
double maxextent; // furthest distance from body owner to body atom
struct Body {
int natoms; // total number of atoms in body
int ilocal; // index of owning atom
double mass; // total mass of body
double xcm[3]; // COM position
double xgc[3]; // geometric center position
double vcm[3]; // COM velocity
double fcm[3]; // force on COM
double torque[3]; // torque around COM
double quat[4]; // quaternion for orientation of body
double inertia[3]; // 3 principal components of inertia
double ex_space[3]; // principal axes in space coords
double ey_space[3];
double ez_space[3];
double xgc_body[3]; // geometric center relative to xcm in body coords
double angmom[3]; // space-frame angular momentum of body
double omega[3]; // space-frame omega of body
double conjqm[4]; // conjugate quaternion momentum
int remapflag[4]; // PBC remap flags
imageint image; // image flags of xcm
imageint dummy; // dummy entry for better alignment
};
Body *body; // list of rigid bodies, owned and ghost
int nlocal_body; // # of owned rigid bodies
int nghost_body; // # of ghost rigid bodies
int nmax_body; // max # of bodies that body can hold
int bodysize; // sizeof(Body) in doubles
RigidSmallBody *body; // list of rigid bodies, owned and ghost
int nlocal_body; // # of owned rigid bodies
int nghost_body; // # of ghost rigid bodies
int nmax_body; // max # of bodies that body can hold
int bodysize; // sizeof(Body) in doubles
// per-atom quantities
// only defined for owned atoms, except bodyown for own+ghost