AutoPas  3.0.0
Loading...
Searching...
No Matches
ParticlePropertiesLibrary.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <algorithm>
10#include <cmath>
11#include <map>
12#include <set>
13#include <vector>
14
17
27template <typename floatType = double, typename intType = unsigned long>
29 public:
34 explicit ParticlePropertiesLibrary(const double cutoff) : _cutoff(cutoff) {}
35
40 ParticlePropertiesLibrary(const ParticlePropertiesLibrary &particlePropertiesLibrary) = default;
41
47 ParticlePropertiesLibrary &operator=(const ParticlePropertiesLibrary &particlePropertiesLibrary) = default;
48
58 void addSiteType(const intType siteId, const floatType mass);
59
69 void addLJParametersToSite(const intType siteId, const floatType epsilon, const floatType sigma);
70
79 void addATParametersToSite(const intType siteId, const floatType nu);
80
93 void addMolType(const intType molId, const std::vector<intType> siteIds,
94 const std::vector<std::array<floatType, 3>> relPos, const std::array<floatType, 3> momentOfInertia);
95
100
101 ~ParticlePropertiesLibrary() = default;
102
107 [[nodiscard]] int getNumberRegisteredSiteTypes() const { return _numRegisteredSiteTypes; }
108
116 [[nodiscard]] int getNumberRegisteredMolTypes() const {
117#if MD_FLEXIBLE_MODE == SINGLESITE
119 WARN,
120 "ParticlePropertiesLibrary::getNumberRegisteredMolTypes(): trying to get the number of registered multi-site"
121 "molecule types when md-flexible has been compiled without support for multi-site molecules. Please compile "
122 "with the CMake argument '-DMD_FLEXIBLE_MODE=MULTISITE'.");
123#endif
124 return _numRegisteredMolTypes;
125 }
126
132 floatType getEpsilon(intType i) const;
133
139 floatType getSigma(intType i) const;
140
146 floatType getNu(intType i) const;
147
153 floatType getSiteMass(intType i) const;
154
164 floatType getMolMass(intType i) const;
165
175 std::array<floatType, 3> getMomentOfInertia(intType i) const;
176
186 std::vector<std::array<floatType, 3>> getSitePositions(intType i) const;
187
196 std::vector<intType> getSiteTypes(intType i) const;
197
206 intType getNumSites(intType i) const;
207
216 floatType getMoleculesLargestSigma(intType i) const;
217
224 floatType getMixing24Epsilon(intType i, intType j) const {
225 return _computedLJMixingData[i * _numRegisteredSiteTypes + j].epsilon24;
226 }
227
234 auto getLJMixingData(intType i, intType j) const { return _computedLJMixingData[i * _numRegisteredSiteTypes + j]; }
235
242 const double *getLJMixingDataPtr(intType i, intType j) {
243 return reinterpret_cast<const double *>(&_computedLJMixingData[i * _numRegisteredSiteTypes + j]);
244 }
245
252 floatType getMixingSigmaSquared(intType i, intType j) const {
253 return _computedLJMixingData[i * _numRegisteredSiteTypes + j].sigmaSquared;
254 }
255
262 floatType getMixingShift6(intType i, intType j) const {
263 return _computedLJMixingData[i * _numRegisteredSiteTypes + j].shift6;
264 }
265
274 static double calcShift6(double epsilon24, double sigmaSquared, double cutoffSquared);
275
283 floatType getMixingNu(intType i, intType j, intType k) const {
284 return _computedATMixingData[i * _numRegisteredSiteTypes * _numRegisteredSiteTypes + j * _numRegisteredSiteTypes +
285 k]
286 .nu;
287 }
288
296 auto getATMixingData(intType i, intType j, intType k) const {
297 return _computedATMixingData[i * _numRegisteredSiteTypes * _numRegisteredSiteTypes + j * _numRegisteredSiteTypes +
298 k];
299 }
300
301 private:
302 intType _numRegisteredSiteTypes{0};
303 intType _numRegisteredMolTypes{0};
304 const double _cutoff;
305
306 std::vector<floatType> _epsilons;
307 std::vector<floatType> _sigmas;
308 std::vector<floatType> _siteMasses;
309 std::vector<floatType> _nus; // Factor for AxilrodTeller potential
310
311 // Note: this is a vector of site type Ids for the sites of a certain molecular Id
312 std::vector<std::vector<intType>> _siteIds;
313 // This is a vector (indexed by mol ID) of vectors of site positions (which are 3D arrays)
314 std::vector<std::vector<std::array<floatType, 3>>> _relativeSitePositions;
315 std::vector<floatType> _molMasses;
316 std::vector<std::array<floatType, 3>> _momentOfInertias;
317 std::vector<size_t> _numSites;
318 std::vector<floatType> _moleculesLargestSigma;
319
320 // Allocate memory for the respective parameters
321 bool _storeLJData{false};
322 bool _storeATData{false};
323
324 struct PackedLJMixingData {
325 floatType epsilon24;
326 floatType sigmaSquared;
327 floatType shift6;
328 };
329
330 struct PackedATMixingData {
331 floatType nu;
332 };
333
334 std::vector<PackedLJMixingData, autopas::AlignedAllocator<PackedLJMixingData>> _computedLJMixingData;
335 std::vector<PackedATMixingData, autopas::AlignedAllocator<PackedATMixingData>> _computedATMixingData;
336};
337
338template <typename floatType, typename intType>
340 if (_numRegisteredSiteTypes != siteID) {
342 "ParticlePropertiesLibrary::addSiteType(): trying to register a site type with id {}. Please "
343 "register types "
344 "consecutively, starting at id 0. Currently there are {} registered types.",
345 siteID, _numRegisteredSiteTypes);
346 }
347 ++_numRegisteredSiteTypes;
348 _siteMasses.emplace_back(mass);
349
350 // Allocate memory for all parameters of used models
351 if (_storeLJData) {
352 _sigmas.emplace_back(0.0);
353 _epsilons.emplace_back(0.0);
354 }
355 if (_storeATData) {
356 _nus.emplace_back(0.0);
357 }
358}
359
360template <typename floatType, typename intType>
362 floatType sigma) {
363 if (siteID >= _numRegisteredSiteTypes) {
365 "ParticlePropertiesLibrary::addLJParametersToSite(): Trying to set lennard-jones parameters for a site type "
366 "with id {},"
367 " which has not been registered yet. Currently there are {} registered types.",
368 siteID, _numRegisteredSiteTypes);
369 }
370 _storeLJData = true;
371 if (_epsilons.size() != _numRegisteredSiteTypes) {
372 _epsilons.resize(_numRegisteredSiteTypes);
373 _sigmas.resize(_numRegisteredSiteTypes);
374 }
375 _epsilons[siteID] = epsilon;
376 _sigmas[siteID] = sigma;
377}
378
379template <typename floatType, typename intType>
381 if (siteID >= _numRegisteredSiteTypes) {
383 "ParticlePropertiesLibrary::addATParametersToSite(): Trying to set the axilrod-teller parameter for a site "
384 "type with id {},"
385 " which has not been registered yet. Currently there are {} registered types.",
386 siteID, _numRegisteredSiteTypes);
387 }
388 _storeATData = true;
389 if (_nus.size() != _numRegisteredSiteTypes) {
390 _nus.resize(_numRegisteredSiteTypes);
391 }
392 _nus[siteID] = nu;
393}
394
395template <typename floatType, typename intType>
396void ParticlePropertiesLibrary<floatType, intType>::addMolType(const intType molId, const std::vector<intType> siteIds,
397 const std::vector<std::array<floatType, 3>> relPos,
398 const std::array<floatType, 3> momentOfInertia) {
399 // Error handling
400#if MD_FLEXIBLE_MODE == SINGLESITE
401 AutoPasLog(WARN,
402 "ParticlePropertiesLibrary::addMolType(): trying to register a multi-site molecule type when md-flexible "
403 "has been compiled without support for multi-site molecules. Please compile with the CMake argument "
404 "'-DMD_FLEXIBLE_MODE=MULTISITE'.");
405#endif
406 if (_numRegisteredMolTypes != molId) {
408 "ParticlePropertiesLibrary::addMolType(): trying to register a molecule type with id {}. Please register types "
409 "consecutively, starting at id 0. Currently there are {} registered types.",
410 molId, _numRegisteredSiteTypes);
411 }
412 if (std::any_of(siteIds.cbegin(), siteIds.cend(), [this](intType i) { return i >= this->_numRegisteredSiteTypes; })) {
414 "ParticlePropertiesLibrary::addMolType(): trying to register a molecule type with an unregistered site type "
415 "Id.");
416 }
417 if (siteIds.size() != relPos.size()) {
419 "ParticlePropertiesLibrary::addMolType(): trying to register a molecule type with vectors of site IDs and site"
420 "positions that do not match in size.");
421 }
422
423 // Add molecule type if there are no errors.
424 ++_numRegisteredMolTypes;
425 _siteIds.emplace_back(siteIds);
426 _relativeSitePositions.emplace_back(relPos);
427 _numSites.emplace_back(siteIds.size());
428 floatType molMass{0.};
429 for (intType site = 0; site < siteIds.size(); ++site) {
430 molMass += _siteMasses[siteIds[site]];
431 }
432 _molMasses.emplace_back(molMass);
433 _momentOfInertias.emplace_back(momentOfInertia);
434
435 floatType molLargestSigma{0.};
436 for (size_t site = 0; site < siteIds.size(); site++) {
437 molLargestSigma = std::max(molLargestSigma, _sigmas[siteIds[site]]);
438 }
439 _moleculesLargestSigma.emplace_back(molLargestSigma);
440}
441
442template <typename floatType, typename intType>
444 if (_numRegisteredSiteTypes == 0) {
446 "ParticlePropertiesLibrary::calculateMixingCoefficients was called without any site types being registered!");
447 }
448
449 // There are Lennard-Jones Sites
450 if (_storeLJData) {
451 const auto cutoffSquared = _cutoff * _cutoff;
452 _computedLJMixingData.resize(_numRegisteredSiteTypes * _numRegisteredSiteTypes);
453
454 for (size_t firstIndex = 0ul; firstIndex < _numRegisteredSiteTypes; ++firstIndex) {
455 for (size_t secondIndex = 0ul; secondIndex < _numRegisteredSiteTypes; ++secondIndex) {
456 auto globalIndex = _numRegisteredSiteTypes * firstIndex + secondIndex;
457
458 // epsilon
459 const floatType epsilon24 = 24 * sqrt(_epsilons[firstIndex] * _epsilons[secondIndex]);
460 _computedLJMixingData[globalIndex].epsilon24 = epsilon24;
461
462 // sigma
463 const floatType sigma = (_sigmas[firstIndex] + _sigmas[secondIndex]) / 2.0;
464 const floatType sigmaSquared = sigma * sigma;
465 _computedLJMixingData[globalIndex].sigmaSquared = sigmaSquared;
466
467 // shift6
468 const floatType shift6 = calcShift6(epsilon24, sigmaSquared, cutoffSquared);
469 _computedLJMixingData[globalIndex].shift6 = shift6;
470 }
471 }
472 }
473
474 if (_storeATData) {
475 _computedATMixingData.resize(_numRegisteredSiteTypes * _numRegisteredSiteTypes * _numRegisteredSiteTypes);
476 for (size_t firstIndex = 0ul; firstIndex < _numRegisteredSiteTypes; ++firstIndex) {
477 for (size_t secondIndex = 0ul; secondIndex < _numRegisteredSiteTypes; ++secondIndex) {
478 for (size_t thirdIndex = 0ul; thirdIndex < _numRegisteredSiteTypes; ++thirdIndex) {
479 const auto globalIndex3B = _numRegisteredSiteTypes * _numRegisteredSiteTypes * firstIndex +
480 _numRegisteredSiteTypes * secondIndex + thirdIndex;
481 // geometric mixing as used in e.g. https://doi.org/10.1063/1.3567308
482 const floatType mixedNu = cbrt(_nus[firstIndex] * _nus[secondIndex] * _nus[thirdIndex]);
483 _computedATMixingData[globalIndex3B].nu = mixedNu;
484 }
485 }
486 }
487 }
488}
489
490template <typename floatType, typename intType>
492 return _siteMasses[i];
493}
494
495template <typename floatType, typename intType>
497#if MD_FLEXIBLE_MODE == MULTISITE
498 return _molMasses[i];
499#else
500 return _siteMasses[i];
501#endif
502}
503
504template <typename floatType, typename intType>
506#if MD_FLEXIBLE_MODE == SINGLESITE
507 AutoPasLog(WARN,
508 "ParticlePropertiesLibrary::getMomentOfInertia(): trying to get the Moment of Inertia of a multi-site "
509 "molecule type when md-flexible has been compiled without support for multi-site molecules. Please "
510 "compile with the CMake argument '-DMD_FLEXIBLE_MODE=MULTISITE'.");
511#endif
512 return _momentOfInertias[i];
513}
514
515template <typename floatType, typename intType>
516std::vector<std::array<floatType, 3>> ParticlePropertiesLibrary<floatType, intType>::getSitePositions(intType i) const {
517#if MD_FLEXIBLE_MODE == SINGLESITE
518 AutoPasLog(WARN,
519 "ParticlePropertiesLibrary::getSitePositions(): trying to get the site positions of a multi-site molecule "
520 "type when md-flexible has been compiled without support for multi-site molecules. Please compile with "
521 "the CMake argument '-DMD_FLEXIBLE_MODE=MULTISITE'.");
522#endif
523 return _relativeSitePositions[i];
524}
525
526template <typename floatType, typename intType>
528#if MD_FLEXIBLE_MODE == SINGLESITE
529 AutoPasLog(WARN,
530 "ParticlePropertiesLibrary::getSiteTypes(): trying to get the site types of a multi-site molecule type "
531 "when md-flexible has been compiled without support for multi-site molecules. Please compile with the "
532 "CMake argument '-DMD_FLEXIBLE_MODE=MULTISITE'.");
533#endif
534 return _siteIds[i];
535}
536
537template <typename floatType, typename intType>
539 return _epsilons[i];
540}
541
542template <typename floatType, typename intType>
544 return _sigmas[i];
545}
546
547template <typename floatType, typename intType>
549 return _nus[i];
550}
551
552template <typename floatType, typename intType>
554#if MD_FLEXIBLE_MODE == SINGLESITE
555 AutoPasLog(WARN,
556 "ParticlePropertiesLibrary::getNumSites(): trying to get the number of sites of a multi-site molecule "
557 "type when md-flexible has been compiled without support for multi-site molecules. Please compile with "
558 "the CMake argument '-DMD_FLEXIBLE_MODE=MULTISITE'.");
559#endif
560 return _numSites[i];
561}
562
563template <typename floatType, typename intType>
565#if MD_FLEXIBLE_MODE == SINGLESITE
566 AutoPasLog(WARN,
567 "ParticlePropertiesLibrary::getNumSites(): trying to get the number of sites of a multi-site molecule "
568 "type when md-flexible has been compiled without support for multi-site molecules. Please compile with "
569 "the CMake argument '-DMD_FLEXIBLE_MODE=MULTISITE'.");
570#endif
571 return _moleculesLargestSigma[i];
572}
573
574template <typename floatType, typename intType>
575double ParticlePropertiesLibrary<floatType, intType>::calcShift6(double epsilon24, double sigmaSquared,
576 double cutoffSquared) {
577 const auto sigmaDivCutoffPow2 = sigmaSquared / cutoffSquared;
578 const auto sigmaDivCutoffPow6 = sigmaDivCutoffPow2 * sigmaDivCutoffPow2 * sigmaDivCutoffPow2;
579 const auto shift6 = epsilon24 * (sigmaDivCutoffPow6 - sigmaDivCutoffPow6 * sigmaDivCutoffPow6);
580 return shift6;
581}
#define AutoPasLog(lvl, fmt,...)
Macro for logging providing common meta information without filename.
Definition: Logger.h:24
This class stores the (physical) properties of molecule types, and, in the case of multi-site molecul...
Definition: ParticlePropertiesLibrary.h:28
floatType getMolMass(intType i) const
Getter for a molecules' mass.
Definition: ParticlePropertiesLibrary.h:496
floatType getMoleculesLargestSigma(intType i) const
Get the largest sigma of any site of a multi-site molecule.
Definition: ParticlePropertiesLibrary.h:564
floatType getMixingShift6(intType i, intType j) const
Returns precomputed mixed shift * 6 for one pair of site types.
Definition: ParticlePropertiesLibrary.h:262
void calculateMixingCoefficients()
Calculates the actual mixing coefficients.
Definition: ParticlePropertiesLibrary.h:443
ParticlePropertiesLibrary & operator=(const ParticlePropertiesLibrary &particlePropertiesLibrary)=default
Copy assignment operator.
int getNumberRegisteredMolTypes() const
Returns the number of registered multi-site molecule types.
Definition: ParticlePropertiesLibrary.h:116
void addLJParametersToSite(const intType siteId, const floatType epsilon, const floatType sigma)
Adds the LJ properties of a single site type to the library.
Definition: ParticlePropertiesLibrary.h:361
intType getNumSites(intType i) const
Get number of sites of a multi-site molecule.
Definition: ParticlePropertiesLibrary.h:553
std::vector< std::array< floatType, 3 > > getSitePositions(intType i) const
Get relative site positions to a multi-site molecule's center-of-mass.
Definition: ParticlePropertiesLibrary.h:516
auto getATMixingData(intType i, intType j, intType k) const
Get complete mixing data for one triplet of AT site types.
Definition: ParticlePropertiesLibrary.h:296
void addATParametersToSite(const intType siteId, const floatType nu)
Adds the AT properties of a single site type to the library.
Definition: ParticlePropertiesLibrary.h:380
void addMolType(const intType molId, const std::vector< intType > siteIds, const std::vector< std::array< floatType, 3 > > relPos, const std::array< floatType, 3 > momentOfInertia)
Adds the properties of a molecule type to the library including: position and type of all sites,...
Definition: ParticlePropertiesLibrary.h:396
floatType getMixingSigmaSquared(intType i, intType j) const
Returns precomputed mixed squared sigma for one pair of site types.
Definition: ParticlePropertiesLibrary.h:252
floatType getEpsilon(intType i) const
Getter for the site's epsilon.
Definition: ParticlePropertiesLibrary.h:538
void addSiteType(const intType siteId, const floatType mass)
Registers a new single site type to the library with a given mass.
Definition: ParticlePropertiesLibrary.h:339
ParticlePropertiesLibrary(const double cutoff)
Constructor.
Definition: ParticlePropertiesLibrary.h:34
std::array< floatType, 3 > getMomentOfInertia(intType i) const
Getter for the multi-site molecule's diagonalized Moment of Inertia.
Definition: ParticlePropertiesLibrary.h:505
ParticlePropertiesLibrary(const ParticlePropertiesLibrary &particlePropertiesLibrary)=default
Copy Constructor.
floatType getSiteMass(intType i) const
Getter for the site's mass.
Definition: ParticlePropertiesLibrary.h:491
floatType getNu(intType i) const
Getter for the site's nu.
Definition: ParticlePropertiesLibrary.h:548
const double * getLJMixingDataPtr(intType i, intType j)
Get a pointer to Mixing Data for one pair of LJ site types.
Definition: ParticlePropertiesLibrary.h:242
floatType getMixing24Epsilon(intType i, intType j) const
Returns the precomputed mixed epsilon * 24.
Definition: ParticlePropertiesLibrary.h:224
static double calcShift6(double epsilon24, double sigmaSquared, double cutoffSquared)
Calculate the shift multiplied 6 of the lennard jones potential from given cutoff,...
Definition: ParticlePropertiesLibrary.h:575
auto getLJMixingData(intType i, intType j) const
Get complete mixing data for one pair of LJ site types.
Definition: ParticlePropertiesLibrary.h:234
floatType getSigma(intType i) const
Getter for the site's sigma.
Definition: ParticlePropertiesLibrary.h:543
std::vector< intType > getSiteTypes(intType i) const
Get site types of a multi-site molecule.
Definition: ParticlePropertiesLibrary.h:527
int getNumberRegisteredSiteTypes() const
Returns the number of registered site / single-site molecule types.
Definition: ParticlePropertiesLibrary.h:107
floatType getMixingNu(intType i, intType j, intType k) const
Returns the precomputed mixed epsilon * 24.
Definition: ParticlePropertiesLibrary.h:283
Default exception class for autopas exceptions.
Definition: ExceptionHandler.h:115
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63