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 addATMParametersToSite(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 _computedATMMixingData[i * _numRegisteredSiteTypes * _numRegisteredSiteTypes + j * _numRegisteredSiteTypes +
285 k]
286 .nu;
287 }
288
296 auto getATMMixingData(intType i, intType j, intType k) const {
297 return _computedATMMixingData[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 AxilrodTellerMuto 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>> _computedATMMixingData;
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::addATMParametersToSite(): Trying to set the axilrod-teller-muto parameter for a "
384 "site "
385 "type with id {},"
386 " which has not been registered yet. Currently there are {} registered types.",
387 siteID, _numRegisteredSiteTypes);
388 }
389 _storeATData = true;
390 if (_nus.size() != _numRegisteredSiteTypes) {
391 _nus.resize(_numRegisteredSiteTypes);
392 }
393 _nus[siteID] = nu;
394}
395
396template <typename floatType, typename intType>
397void ParticlePropertiesLibrary<floatType, intType>::addMolType(const intType molId, const std::vector<intType> siteIds,
398 const std::vector<std::array<floatType, 3>> relPos,
399 const std::array<floatType, 3> momentOfInertia) {
400 // Error handling
401#if MD_FLEXIBLE_MODE == SINGLESITE
402 AutoPasLog(WARN,
403 "ParticlePropertiesLibrary::addMolType(): trying to register a multi-site molecule type when md-flexible "
404 "has been compiled without support for multi-site molecules. Please compile with the CMake argument "
405 "'-DMD_FLEXIBLE_MODE=MULTISITE'.");
406#endif
407 if (_numRegisteredMolTypes != molId) {
409 "ParticlePropertiesLibrary::addMolType(): trying to register a molecule type with id {}. Please register types "
410 "consecutively, starting at id 0. Currently there are {} registered types.",
411 molId, _numRegisteredSiteTypes);
412 }
413 if (std::any_of(siteIds.cbegin(), siteIds.cend(), [this](intType i) { return i >= this->_numRegisteredSiteTypes; })) {
415 "ParticlePropertiesLibrary::addMolType(): trying to register a molecule type with an unregistered site type "
416 "Id.");
417 }
418 if (siteIds.size() != relPos.size()) {
420 "ParticlePropertiesLibrary::addMolType(): trying to register a molecule type with vectors of site IDs and site"
421 "positions that do not match in size.");
422 }
423
424 // Add molecule type if there are no errors.
425 ++_numRegisteredMolTypes;
426 _siteIds.emplace_back(siteIds);
427 _relativeSitePositions.emplace_back(relPos);
428 _numSites.emplace_back(siteIds.size());
429 floatType molMass{0.};
430 for (intType site = 0; site < siteIds.size(); ++site) {
431 molMass += _siteMasses[siteIds[site]];
432 }
433 _molMasses.emplace_back(molMass);
434 _momentOfInertias.emplace_back(momentOfInertia);
435
436 floatType molLargestSigma{0.};
437 for (size_t site = 0; site < siteIds.size(); site++) {
438 molLargestSigma = std::max(molLargestSigma, _sigmas[siteIds[site]]);
439 }
440 _moleculesLargestSigma.emplace_back(molLargestSigma);
441}
442
443template <typename floatType, typename intType>
445 if (_numRegisteredSiteTypes == 0) {
447 "ParticlePropertiesLibrary::calculateMixingCoefficients was called without any site types being registered!");
448 }
449
450 // There are Lennard-Jones Sites
451 if (_storeLJData) {
452 const auto cutoffSquared = _cutoff * _cutoff;
453 _computedLJMixingData.resize(_numRegisteredSiteTypes * _numRegisteredSiteTypes);
454
455 for (size_t firstIndex = 0ul; firstIndex < _numRegisteredSiteTypes; ++firstIndex) {
456 for (size_t secondIndex = 0ul; secondIndex < _numRegisteredSiteTypes; ++secondIndex) {
457 auto globalIndex = _numRegisteredSiteTypes * firstIndex + secondIndex;
458
459 // epsilon
460 const floatType epsilon24 = 24 * sqrt(_epsilons[firstIndex] * _epsilons[secondIndex]);
461 _computedLJMixingData[globalIndex].epsilon24 = epsilon24;
462
463 // sigma
464 const floatType sigma = (_sigmas[firstIndex] + _sigmas[secondIndex]) / 2.0;
465 const floatType sigmaSquared = sigma * sigma;
466 _computedLJMixingData[globalIndex].sigmaSquared = sigmaSquared;
467
468 // shift6
469 const floatType shift6 = calcShift6(epsilon24, sigmaSquared, cutoffSquared);
470 _computedLJMixingData[globalIndex].shift6 = shift6;
471 }
472 }
473 }
474
475 if (_storeATData) {
476 _computedATMMixingData.resize(_numRegisteredSiteTypes * _numRegisteredSiteTypes * _numRegisteredSiteTypes);
477 for (size_t firstIndex = 0ul; firstIndex < _numRegisteredSiteTypes; ++firstIndex) {
478 for (size_t secondIndex = 0ul; secondIndex < _numRegisteredSiteTypes; ++secondIndex) {
479 for (size_t thirdIndex = 0ul; thirdIndex < _numRegisteredSiteTypes; ++thirdIndex) {
480 const auto globalIndex3B = _numRegisteredSiteTypes * _numRegisteredSiteTypes * firstIndex +
481 _numRegisteredSiteTypes * secondIndex + thirdIndex;
482 // geometric mixing as used in e.g. https://doi.org/10.1063/1.3567308
483 const floatType mixedNu = cbrt(_nus[firstIndex] * _nus[secondIndex] * _nus[thirdIndex]);
484 _computedATMMixingData[globalIndex3B].nu = mixedNu;
485 }
486 }
487 }
488 }
489}
490
491template <typename floatType, typename intType>
493 return _siteMasses[i];
494}
495
496template <typename floatType, typename intType>
498#if MD_FLEXIBLE_MODE == MULTISITE
499 return _molMasses[i];
500#else
501 return _siteMasses[i];
502#endif
503}
504
505template <typename floatType, typename intType>
507#if MD_FLEXIBLE_MODE == SINGLESITE
508 AutoPasLog(WARN,
509 "ParticlePropertiesLibrary::getMomentOfInertia(): trying to get the Moment of Inertia of a multi-site "
510 "molecule type when md-flexible has been compiled without support for multi-site molecules. Please "
511 "compile with the CMake argument '-DMD_FLEXIBLE_MODE=MULTISITE'.");
512#endif
513 return _momentOfInertias[i];
514}
515
516template <typename floatType, typename intType>
517std::vector<std::array<floatType, 3>> ParticlePropertiesLibrary<floatType, intType>::getSitePositions(intType i) const {
518#if MD_FLEXIBLE_MODE == SINGLESITE
519 AutoPasLog(WARN,
520 "ParticlePropertiesLibrary::getSitePositions(): trying to get the site positions of a multi-site molecule "
521 "type when md-flexible has been compiled without support for multi-site molecules. Please compile with "
522 "the CMake argument '-DMD_FLEXIBLE_MODE=MULTISITE'.");
523#endif
524 return _relativeSitePositions[i];
525}
526
527template <typename floatType, typename intType>
529#if MD_FLEXIBLE_MODE == SINGLESITE
530 AutoPasLog(WARN,
531 "ParticlePropertiesLibrary::getSiteTypes(): trying to get the site types of a multi-site molecule type "
532 "when md-flexible has been compiled without support for multi-site molecules. Please compile with the "
533 "CMake argument '-DMD_FLEXIBLE_MODE=MULTISITE'.");
534#endif
535 return _siteIds[i];
536}
537
538template <typename floatType, typename intType>
540 return _epsilons[i];
541}
542
543template <typename floatType, typename intType>
545 return _sigmas[i];
546}
547
548template <typename floatType, typename intType>
550 return _nus[i];
551}
552
553template <typename floatType, typename intType>
555#if MD_FLEXIBLE_MODE == SINGLESITE
556 AutoPasLog(WARN,
557 "ParticlePropertiesLibrary::getNumSites(): trying to get the number of sites of a multi-site molecule "
558 "type when md-flexible has been compiled without support for multi-site molecules. Please compile with "
559 "the CMake argument '-DMD_FLEXIBLE_MODE=MULTISITE'.");
560#endif
561 return _numSites[i];
562}
563
564template <typename floatType, typename intType>
566#if MD_FLEXIBLE_MODE == SINGLESITE
567 AutoPasLog(WARN,
568 "ParticlePropertiesLibrary::getNumSites(): trying to get the number of sites of a multi-site molecule "
569 "type when md-flexible has been compiled without support for multi-site molecules. Please compile with "
570 "the CMake argument '-DMD_FLEXIBLE_MODE=MULTISITE'.");
571#endif
572 return _moleculesLargestSigma[i];
573}
574
575template <typename floatType, typename intType>
576double ParticlePropertiesLibrary<floatType, intType>::calcShift6(double epsilon24, double sigmaSquared,
577 double cutoffSquared) {
578 const auto sigmaDivCutoffPow2 = sigmaSquared / cutoffSquared;
579 const auto sigmaDivCutoffPow6 = sigmaDivCutoffPow2 * sigmaDivCutoffPow2 * sigmaDivCutoffPow2;
580 const auto shift6 = epsilon24 * (sigmaDivCutoffPow6 - sigmaDivCutoffPow6 * sigmaDivCutoffPow6);
581 return shift6;
582}
#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:497
floatType getMoleculesLargestSigma(intType i) const
Get the largest sigma of any site of a multi-site molecule.
Definition: ParticlePropertiesLibrary.h:565
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:444
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
auto getATMMixingData(intType i, intType j, intType k) const
Get complete mixing data for one triplet of ATM site types.
Definition: ParticlePropertiesLibrary.h:296
void addATMParametersToSite(const intType siteId, const floatType nu)
Adds the ATM properties of a single site type to the library.
Definition: ParticlePropertiesLibrary.h:380
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:554
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:517
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:397
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:539
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:506
ParticlePropertiesLibrary(const ParticlePropertiesLibrary &particlePropertiesLibrary)=default
Copy Constructor.
floatType getSiteMass(intType i) const
Getter for the site's mass.
Definition: ParticlePropertiesLibrary.h:492
floatType getNu(intType i) const
Getter for the site's nu.
Definition: ParticlePropertiesLibrary.h:549
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:576
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:544
std::vector< intType > getSiteTypes(intType i) const
Get site types of a multi-site molecule.
Definition: ParticlePropertiesLibrary.h:528
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