Loading...
Searching...
No Matches
eonc::TestJob Class Reference

#include <TestJob.h>

Inheritance diagram for eonc::TestJob:

Public Member Functions

 TestJob (std::unique_ptr< Parameters > params, Runtime &rt)
 ~TestJob ()=default
std::vector< std::string > run ()
 Virtual run; used solely for dynamic dispatch.
Public Member Functions inherited from eonc::Job
void adoptRuntime (std::unique_ptr< Runtime > rt)
 Take ownership of a Runtime previously passed as Runtime&.
 Job (std::unique_ptr< Parameters > parameters, Runtime &rt)
 Borrow: caller keeps Runtime alive (CLI stack / Python Session).
 Job (std::unique_ptr< Parameters > parameters, std::unique_ptr< Runtime > rt)
 Own a Runtime (one-shot makeJob / rvalue).
 Job (std::unique_ptr< Parameters > parameters)
 Own a default-constructed Runtime.
 Job (std::shared_ptr< Potential > potPassed, const Parameters &parameters)
virtual ~Job ()=default
JobType getType ()
PotRegistry & pots () noexcept
void releasePotential ()
 Drop the Potential so on_destroyed is recorded before Runtime dies.

Private Member Functions

void checkFullSearch ()
void checkPotentials ()
double getEnergyDiff (const std::string &potTag, double refEnergy)
double getForceDiff (const std::string &potTag, double refForce)

Private Attributes

double tolerance {0.01}

Additional Inherited Members

Protected Attributes inherited from eonc::Job
JobType jtype
Parameters params
std::unique_ptr< Runtime > owned_runtime_
 Non-null when this Job owns the composition root (one-shot makeJob).
Runtime * runtime_
 Always valid: either owned_runtime_.get() or a caller-owned Runtime.
std::shared_ptr< Potential > pot

Detailed Description

Definition at line 22 of file TestJob.h.

Constructor & Destructor Documentation

◆ TestJob()

eonc::TestJob::TestJob ( std::unique_ptr< Parameters > params,
Runtime & rt )
inline

Definition at line 24 of file TestJob.h.

25 : Job(std::move(params), rt),
26 tolerance{0.01} {}
Job(std::unique_ptr< Parameters > parameters, Runtime &rt)
Borrow: caller keeps Runtime alive (CLI stack / Python Session).
Definition Job.h:76
Parameters params
Definition Job.h:58
double tolerance
Definition TestJob.h:31

◆ ~TestJob()

eonc::TestJob::~TestJob ( )
default

Member Function Documentation

◆ checkFullSearch()

void eonc::TestJob::checkFullSearch ( )
private

Definition at line 41 of file TestJob.cpp.

41 {
42 // Historical saddle self-test needs reactant_test.con / displacement_test.con
43 // which the tree does not ship. Keep the hook.
44}

◆ checkPotentials()

void eonc::TestJob::checkPotentials ( )
private

Definition at line 46 of file TestJob.cpp.

46 {
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}
double getEnergyDiff(const std::string &potTag, double refEnergy)
Definition TestJob.cpp:78
double getForceDiff(const std::string &potTag, double refForce)
Definition TestJob.cpp:94

◆ getEnergyDiff()

double eonc::TestJob::getEnergyDiff ( const std::string & potTag,
double refEnergy )
private

Definition at line 78 of file TestJob.cpp.

78 {
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;
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}
std::shared_ptr< Potential > makePotential(const Parameters &params)
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38
static potential_options_t & potential_options(Parameters &p)

◆ getForceDiff()

double eonc::TestJob::getForceDiff ( const std::string & potTag,
double refForce )
private

Definition at line 94 of file TestJob.cpp.

94 {
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;
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}

◆ run()

std::vector< std::string > eonc::TestJob::run ( )
virtual

Virtual run; used solely for dynamic dispatch.

Implements eonc::Job.

Definition at line 35 of file TestJob.cpp.

35 {
38 return {"results.dat"};
39}
void checkPotentials()
Definition TestJob.cpp:46
void checkFullSearch()
Definition TestJob.cpp:41

Member Data Documentation

◆ tolerance

double eonc::TestJob::tolerance {0.01}
private

Definition at line 31 of file TestJob.h.

31{0.01};

The documentation for this class was generated from the following files: