more work on read_data and write_data

This commit is contained in:
Steve Plimpton
2023-09-13 13:29:37 -06:00
parent c7e794146f
commit e5f3fcbbf4
18 changed files with 488 additions and 14 deletions

View File

@ -16,8 +16,10 @@
#include "atom.h"
#include "body.h"
#include "domain.h"
#include "error.h"
#include "fix.h"
#include "math_extra.h"
#include "memory.h"
#include "modify.h"
#include "my_pool_chunk.h"
@ -51,6 +53,8 @@ AtomVecBody::AtomVecBody(LAMMPS *lmp) : AtomVec(lmp)
nlocal_bonus = nghost_bonus = nmax_bonus = 0;
bonus = nullptr;
quat_hold = nullptr;
bptr = nullptr;
if (sizeof(double) == sizeof(int))
@ -547,6 +551,90 @@ void AtomVecBody::data_atom_post(int ilocal)
angmom[ilocal][2] = 0.0;
}
/* ----------------------------------------------------------------------
convert read_data file info from general to restricted triclinic
parent class operates on data from Velocities section of data file
child class operates on bonus quat
------------------------------------------------------------------------- */
void AtomVecBody::read_data_general_to_restricted(int nlocal_previous, int nlocal)
{
AtomVec::read_data_general_to_restricted(nlocal_previous, nlocal);
double quat[4];
double *bquat;
for (int i = nlocal_previous; i < nlocal; i++) {
if (body[i] < 0) continue;
bquat = bonus[body[i]].quat;
MathExtra::quatquat(domain->quat_g2r,bquat,quat);
bquat[0] = quat[0];
bquat[1] = quat[1];
bquat[2] = quat[2];
bquat[3] = quat[3];
MathExtra::qnormalize(bquat);
}
}
/* ----------------------------------------------------------------------
convert info output by write_data from restricted to general triclinic
parent class operates on x and data from Velocities section of data file
child class operates on bonus quat
------------------------------------------------------------------------- */
void AtomVecBody::write_data_restricted_to_general()
{
AtomVec::write_data_restricted_to_general();
double quat[4],quat_r2g[4];
double *bquat;
memory->create(quat_hold,nlocal_bonus,4,"atomvec:quat_hold");
MathExtra::qconjugate(domain->quat_g2r,quat_r2g);
for (int i = 0; i < nlocal_bonus; i++) {
bquat = bonus[i].quat;
quat_hold[i][0] = bquat[0];
quat_hold[i][1] = bquat[1];
quat_hold[i][2] = bquat[2];
quat_hold[i][3] = bquat[3];
MathExtra::quatquat(quat_r2g,bquat,quat);
bquat[0] = quat[0];
bquat[1] = quat[1];
bquat[2] = quat[2];
bquat[3] = quat[3];
MathExtra::qnormalize(bquat);
}
}
/* ----------------------------------------------------------------------
restore info output by write_data to restricted triclinic
original data is in "hold" arrays
parent class operates on x and data from Velocities section of data file
child class operates on bonus quat
------------------------------------------------------------------------- */
void AtomVecBody::write_data_restore_restricted()
{
AtomVec::write_data_restore_restricted();
if (!quat_hold) return;
double *bquat;
for (int i = 0; i < nlocal_bonus; i++) {
bquat = bonus[i].quat;
bquat[0] = quat_hold[i][0];
bquat[1] = quat_hold[i][1];
bquat[2] = quat_hold[i][2];
bquat[3] = quat_hold[i][3];
}
memory->destroy(quat_hold);
quat_hold = nullptr;
}
/* ----------------------------------------------------------------------
unpack one body from Bodies section of data file
------------------------------------------------------------------------- */