1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
#include "FundamentalAtomicQuantity.h"
using std::string;
namespace ATC {
//--------------------------------------------------------
//--------------------------------------------------------
// Class FundamentalAtomQuantity
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
//--------------------------------------------------------
FundamentalAtomQuantity::FundamentalAtomQuantity(ATC_Method * atc,
LammpsInterface::FundamentalAtomQuantity atomQuantity,
AtomType atomType) :
ShallowAtomQuantity<double>(atc,0,atomType),
atomQuantity_(atomQuantity),
unitsConversion_(lammpsInterface_->atom_quantity_conversion(atomQuantity_))
{
nCols_ = lammpsInterface_->atom_quantity_ndof(atomQuantity_);
}
//--------------------------------------------------------
// set_lammps_to_quantity
//--------------------------------------------------------
void FundamentalAtomQuantity::set_lammps_to_quantity() const
{
if (unitsConversion_==1.) { // is there a way to avoid equal testing a double?
PerAtomQuantity<double>::set_lammps_to_quantity();
}
else { // perform unit conversion
if (quantity_.nRows()>0) {
// full matrix copy
if (atomType_ == ALL || atomType_ == PROC_GHOST) {
if (nCols_==1) { // scalar
double * lammpsQuantity = lammps_scalar();
for (int i = 0; i < atc_.nlocal_total(); i++)
lammpsQuantity[i] = quantity_(i,0)/unitsConversion_;
}
else{ // vector
double ** lammpsQuantity = lammps_vector();
for (int i = 0; i < atc_.nlocal_total(); i++)
for (int j = 0; j < nCols_; j++)
lammpsQuantity[i][j] = quantity_(i,j)/unitsConversion_;
}
}
// mapped copy
else {
int atomIndex;
if (nCols_==1) { // scalar
double * lammpsQuantity = lammps_scalar();
for (int i = 0; i < quantity_.nRows(); i++) {
atomIndex = quantityToLammps_(i);
lammpsQuantity[atomIndex] = quantity_(i,0)/unitsConversion_;
}
}
else{ // vector
double ** lammpsQuantity = lammps_vector();
for (int i = 0; i < quantity_.nRows(); i++) {
atomIndex = quantityToLammps_(i);
for (int j = 0; j < nCols_; j++) {
lammpsQuantity[atomIndex][j] = quantity_(i,j)/unitsConversion_;
}
}
}
}
}
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class AtomMass
// Access-only operations when mass is
// defined per type.
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
//--------------------------------------------------------
AtomMass::AtomMass(ATC_Method * atc,AtomType atomType) :
FundamentalAtomQuantity(atc,LammpsInterface::ATOM_MASS,atomType)
{
// do nothing
}
//--------------------------------------------------------
// set_quantity_to_lammps
//--------------------------------------------------------
void AtomMass::set_quantity_to_lammps() const
{
const int * type = lammpsInterface_->atom_type();
const double * mass = lammpsInterface_->atom_mass();
if (atomType_ == ALL || atomType_ == PROC_GHOST) {
for (int i = 0; i < quantity_.nRows(); i++)
quantity_(i,0) = mass[type[i]];
}
else {
int atomIndex;
for (int i = 0; i < quantity_.nRows(); i++) {
atomIndex = quantityToLammps_(i);
quantity_(i,0) = mass[type[atomIndex]];
}
}
}
//--------------------------------------------------------
//--------------------------------------------------------
// Class ComputedAtomQuantity
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
// Constructor
//--------------------------------------------------------
ComputedAtomQuantity::ComputedAtomQuantity(ATC_Method * atc,
const string & tag,
double unitsConversion,
AtomType atomType) :
ShallowAtomQuantity<double>(atc,0,atomType),
computePointer_(nullptr),
computeTag_(tag),
unitsConversion_(unitsConversion)
{
// register compute with lammps interface and provide pointer for syncing
computePointer_ = lammpsInterface_->compute_pointer(computeTag_.c_str());
nCols_ = lammpsInterface_->compute_ncols_peratom(computePointer_);
}
//--------------------------------------------------------
// force_reset
//--------------------------------------------------------
void ComputedAtomQuantity::force_reset()
{
// only reset if the compute needs it this timestep
if (lammpsInterface_->compute_matchstep(computePointer_,lammpsInterface_->ntimestep())) {
if (!isFixed_) {
lammpsInterface_->reset_invoked_flag(computePointer_);
}
ShallowAtomQuantity<double>::force_reset();
}
}
}
|