Loading...
Searching...
No Matches
EffectiveMediumTheory.cpp
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** SPDX-License-Identifier: BSD-3-Clause
5**
6** Copyright (c) 2010--present, eOn Development Team
7** All rights reserved.
8**
9** Repo:
10** https://github.com/TheochemUI/eOn
11*/
12
14
15#include <cstring>
16#include <vector>
17
19 delete EMTObj;
20 EMTObj = nullptr;
21 delete SuperCellObj;
22 SuperCellObj = nullptr;
23 delete AtomsObj;
24 AtomsObj = nullptr;
25 delete EMTParameterObj;
26 EMTParameterObj = nullptr;
27}
28
29// pointer to number of atoms, pointer to array of positions
30// pointer to array of forces, pointer to internal energy
31// adress to supercell size
32void EffectiveMediumTheory::force(long N, const double *R, const int *atomicNrs,
33 double *F, double *U, double *variance,
34 const double *box) {
35 variance = nullptr;
36
37 // Copy positions (Asap may modify them internally)
38 std::vector<double> pos(R, R + 3 * N);
39
40 // Reinitialize if atom count changed
41 if (numberOfAtoms != N) {
42 numberOfAtoms = N;
44
45 Vec tempBasis[3] = {
46 Vec(box[0], box[1], box[2]),
47 Vec(box[3], box[4], box[5]),
48 Vec(box[6], box[7], box[8]),
49 };
50
51 SuperCellObj = new SuperCell(tempBasis, periodicity);
52 AtomsObj = new Atoms(reinterpret_cast<Vec *>(pos.data()), N, SuperCellObj);
53
54 std::vector<int> atomicNrsTemp(atomicNrs, atomicNrs + N);
55 AtomsObj->SetAtomicNumbers(atomicNrsTemp.data());
56
57 if (emtRasmussen) {
60 } else {
61 EMTObj = new EMT(nullptr);
62 }
63 AtomsObj->SetCalculator(EMTObj);
64 }
65
66 AtomsObj->SetCartesianPositions(reinterpret_cast<Vec *>(pos.data()));
67
68 // Update the box
69 Vec tempBasis[3] = {
70 Vec(box[0], box[1], box[2]),
71 Vec(box[3], box[4], box[5]),
72 Vec(box[6], box[7], box[8]),
73 };
74 AtomsObj->SetUnitCell(tempBasis, true);
75
76 *U = EMTObj->GetPotentialEnergy();
77
78 const Vec *tempF = EMTObj->GetCartesianForces();
79 std::memcpy(F, tempF, N * sizeof(Vec));
80}
The main list of atoms class.
Definition Atoms.h:36
The Effective Medium Theory (EMT) potential.
Definition EMT.h:24
void force(long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box)
EMTDefaultParameterProvider * EMTParameterObj
The SuperCell defines the size, shape and boundary condx of a simulation.
Definition SuperCell.h:20
A 3-vector useful for postions etc.
Definition Vec.h:18