Add atoms generation methods
This commit is contained in:
46
src/md/AtomsGenerator.cpp
Normal file
46
src/md/AtomsGenerator.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @file AtomsGenerator.cpp
|
||||
* @author jun <jun@firmwarejun.net>
|
||||
* @brief AtomsGenerator definitions
|
||||
* @version 0.1
|
||||
* @date 2023-08-05
|
||||
*
|
||||
* Copyright (c) 2023 jun <https://git.firmwarejun.net/jun/MolecularDynamics2>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "AtomsGenerator.hpp"
|
||||
|
||||
std::vector<Atom> generateFCCAtoms(double latticeConstant, std::size_t numberOfCells) {
|
||||
// Check for invalid lattice constants
|
||||
if (latticeConstant <= 0)
|
||||
throw std::invalid_argument("Lattice constant must be positive");
|
||||
|
||||
std::vector<Atom> atoms;
|
||||
|
||||
// Generate atoms in FCC lattice
|
||||
for (std::size_t i = 0; i < numberOfCells; i++)
|
||||
for (std::size_t j = 0; j < numberOfCells; j++)
|
||||
for (std::size_t k = 0; k < numberOfCells; k++) {
|
||||
atoms.push_back(Atom(i * latticeConstant, j * latticeConstant, k * latticeConstant));
|
||||
atoms.push_back(
|
||||
Atom((i + 0.5) * latticeConstant, (j + 0.5) * latticeConstant, k * latticeConstant));
|
||||
atoms.push_back(
|
||||
Atom((i + 0.5) * latticeConstant, j * latticeConstant, (k + 0.5) * latticeConstant));
|
||||
atoms.push_back(
|
||||
Atom(i * latticeConstant, (j + 0.5) * latticeConstant, (k + 0.5) * latticeConstant));
|
||||
}
|
||||
|
||||
// Use std::move to move the vector to the caller
|
||||
return std::move(atoms);
|
||||
}
|
||||
|
||||
void offsetAtoms(std::vector<Atom> &atoms, double x, double y, double z) {
|
||||
for (auto &atom : atoms) {
|
||||
atom.x += x;
|
||||
atom.y += y;
|
||||
atom.z += z;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user