eOn 3.2.0
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
TestJob.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
#include "
eon/TestJob.h
"
13
#include "
eon/HelperFunctions.h
"
14
#include "
eon/Matter.h
"
15
#include "
eon/Potential.h
"
16
17
#include "magic_enum/magic_enum.hpp"
18
#include <array>
19
#include <cmath>
20
#include <fstream>
21
#include <stdexcept>
22
#include <string>
23
24
namespace
eonc
{
25
26
namespace
{
27
struct
PotRef {
28
const
char
*tag;
29
eonc::PotType
type;
30
double
energy;
31
double
max_force;
32
};
33
}
// namespace
34
35
std::vector<std::string>
TestJob::run
() {
36
checkPotentials
();
37
checkFullSearch
();
38
return
{
"results.dat"
};
39
}
40
41
void
TestJob::checkFullSearch
() {
42
// Historical saddle self-test needs reactant_test.con / displacement_test.con
43
// which the tree does not ship. Keep the hook.
44
}
45
46
void
TestJob::checkPotentials
() {
47
const
std::array<PotRef, 8> cases{{
48
{
"lj"
,
eonc::PotType::LJ
, -1475.984331, 2.007213},
49
{
"emt"
,
eonc::PotType::EMT
, 46.086312, 0.357493},
50
{
"edip"
,
eonc::PotType::EDIP
, -1033.250950, 7.080115},
51
{
"tersoff_si"
,
eonc::PotType::TERSOFF_SI
, -1035.809985, 11.145002},
52
{
"sw_si"
,
eonc::PotType::SW_SI
, -1449.795645, 2.530904},
53
{
"lenosky_si"
,
eonc::PotType::LENOSKY_SI
, -1410.679106, 2.320168},
54
{
"eam_al"
,
eonc::PotType::EAM_AL
, -1206.825825, 0.000246},
55
{
"tip4p"
,
eonc::PotType::TIP4P
, 4063.865115, 73.655248},
56
}};
57
58
std::ofstream out(
"results.dat"
);
59
for
(
const
auto
&c : cases) {
60
try
{
61
const
double
de =
getEnergyDiff
(c.tag, c.energy);
62
if
(std::abs(de) >
tolerance
) {
63
out <<
"FAIL "
<< c.tag <<
" energy_diff "
<< de <<
"\n"
;
64
continue
;
65
}
66
const
double
df =
getForceDiff
(c.tag, c.max_force);
67
if
(std::abs(df) >
tolerance
) {
68
out <<
"FAIL "
<< c.tag <<
" force_diff "
<< df <<
"\n"
;
69
continue
;
70
}
71
out <<
"OK "
<< c.tag <<
"\n"
;
72
}
catch
(
const
std::exception &e) {
73
out <<
"SKIP "
<< c.tag <<
" "
<< e.what() <<
"\n"
;
74
}
75
}
76
}
77
78
double
TestJob::getEnergyDiff
(
const
std::string &potTag,
double
refEnergy) {
79
auto
type = magic_enum::enum_cast<eonc::PotType>(
80
potTag, magic_enum::case_insensitive);
81
if
(!type) {
82
throw
std::invalid_argument(
"unknown pot "
+ potTag);
83
}
84
Parameters
p =
params
;
85
ParametersLoadAccess::potential_options
(p).
potential
= *type;
86
auto
potHandle =
eonc::helpers::makePotential
(*type, p);
87
Matter
pos(potHandle, p);
88
if
(!
eonc::io::io_ok
(pos.
con2matter
(std::string(
"pos_test.con"
)))) {
89
throw
std::runtime_error(
"no pos_test.con"
);
90
}
91
return
pos.
getPotentialEnergy
() - refEnergy;
92
}
93
94
double
TestJob::getForceDiff
(
const
std::string &potTag,
double
refForce) {
95
auto
type = magic_enum::enum_cast<eonc::PotType>(
96
potTag, magic_enum::case_insensitive);
97
if
(!type) {
98
throw
std::invalid_argument(
"unknown pot "
+ potTag);
99
}
100
Parameters
p =
params
;
101
ParametersLoadAccess::potential_options
(p).
potential
= *type;
102
auto
potHandle =
eonc::helpers::makePotential
(*type, p);
103
Matter
pos(potHandle, p);
104
if
(!
eonc::io::io_ok
(pos.
con2matter
(std::string(
"pos_test.con"
)))) {
105
throw
std::runtime_error(
"no pos_test.con"
);
106
}
107
return
pos.
maxForce
() - refForce;
108
}
109
110
}
// namespace eonc
HelperFunctions.h
Matter.h
Potential.h
TestJob.h
eonc::Job::params
Parameters params
Definition
Job.h:58
eonc::Matter
Definition
Matter.h:90
eonc::Matter::getPotentialEnergy
double getPotentialEnergy() const
Definition
Matter.cpp:554
eonc::Matter::con2matter
io::IoStatus con2matter(std::string filename)
Definition
Matter.h:256
eonc::Matter::maxForce
double maxForce(void) const
Definition
Matter.cpp:685
eonc::Parameters
Definition
Parameters.h:35
eonc::TestJob::tolerance
double tolerance
Definition
TestJob.h:31
eonc::TestJob::checkPotentials
void checkPotentials()
Definition
TestJob.cpp:46
eonc::TestJob::checkFullSearch
void checkFullSearch()
Definition
TestJob.cpp:41
eonc::TestJob::getEnergyDiff
double getEnergyDiff(const std::string &potTag, double refEnergy)
Definition
TestJob.cpp:78
eonc::TestJob::run
std::vector< std::string > run()
Virtual run; used solely for dynamic dispatch.
Definition
TestJob.cpp:35
eonc::TestJob::getForceDiff
double getForceDiff(const std::string &potTag, double refForce)
Definition
TestJob.cpp:94
eonc::helpers::makePotential
std::shared_ptr< Potential > makePotential(const Parameters ¶ms)
Definition
Potential.cpp:246
eonc::io::io_ok
constexpr bool io_ok(IoStatus s) noexcept
Definition
ConFileIO.h:38
eonc
RAII resource manager for the ARTn C library with global synchronization.
Definition
ARTnSaddleSearch.cpp:23
eonc::PotType
PotType
Definition
BaseStructures.h:36
eonc::PotType::EMT
@ EMT
Definition
BaseStructures.h:39
eonc::PotType::TERSOFF_SI
@ TERSOFF_SI
Definition
BaseStructures.h:54
eonc::PotType::EDIP
@ EDIP
Definition
BaseStructures.h:50
eonc::PotType::LJ
@ LJ
Definition
BaseStructures.h:41
eonc::PotType::TIP4P
@ TIP4P
Definition
BaseStructures.h:45
eonc::PotType::LENOSKY_SI
@ LENOSKY_SI
Definition
BaseStructures.h:52
eonc::PotType::SW_SI
@ SW_SI
Definition
BaseStructures.h:53
eonc::PotType::EAM_AL
@ EAM_AL
Definition
BaseStructures.h:49
eonc::ParametersLoadAccess::potential_options
static potential_options_t & potential_options(Parameters &p)
Definition
ParametersAccess.cpp:282
eonc::potential_options_t::potential
PotType potential
Definition
ParametersOptions.h:51
client
TestJob.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf