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

#include <MonteCarloJob.h>

Inheritance diagram for eonc::MonteCarloJob:

Public Member Functions

 MonteCarloJob (std::unique_ptr< Parameters > parameters)
 ~MonteCarloJob (void)=default
std::vector< std::string > run (void)
 Virtual run; used solely for dynamic dispatch.
Public Member Functions inherited from eonc::Job
 Job (std::unique_ptr< Parameters > parameters)
 Job (std::shared_ptr< Potential > potPassed, const Parameters &parameters)
virtual ~Job ()=default
JobType getType ()

Private Attributes

eonc::log::Scoped log

Additional Inherited Members

Protected Attributes inherited from eonc::Job
JobType jtype
Parameters params
std::shared_ptr< Potentialpot

Detailed Description

Definition at line 20 of file MonteCarloJob.h.

Constructor & Destructor Documentation

◆ MonteCarloJob()

eonc::MonteCarloJob::MonteCarloJob ( std::unique_ptr< Parameters > parameters)
inline

Definition at line 22 of file MonteCarloJob.h.

23 : Job(std::move(parameters)) {}
Job(std::unique_ptr< Parameters > parameters)
Definition Job.h:58

◆ ~MonteCarloJob()

eonc::MonteCarloJob::~MonteCarloJob ( void )
default

Member Function Documentation

◆ run()

std::vector< std::string > MonteCarloJob::run ( void )
virtual

Virtual run; used solely for dynamic dispatch.

Implements eonc::Job.

Definition at line 23 of file MonteCarloJob.cpp.

23 {
24 std::string posInFilename("pos.con");
25 std::string posOutFilename("out.con");
26
27 if (params.main_options.checkpoint) {
28 if (std::filesystem::exists("pos_cp.con")) {
29 posInFilename = "pos_cp.con";
30 QUILL_LOG_DEBUG(log, "Resuming from checkpoint\n");
31 } else {
32 QUILL_LOG_DEBUG(log, "No checkpoint files found\n");
33 }
34 }
35
36 std::vector<std::string> returnFiles;
37
38 auto matter = std::make_shared<Matter>(pot, params);
39 if (!eonc::io::io_ok(matter->con2matter(posInFilename))) {
40 QUILL_LOG_CRITICAL(log, "Failed to load {}", posInFilename);
41 throw std::runtime_error("failed to load " + posInFilename);
42 }
43
44 MonteCarlo mc = MonteCarlo(matter, params);
45 mc.run(params.monte_carlo_options.steps, params.main_options.temperature,
46 params.monte_carlo_options.step_size);
47
48 QUILL_LOG_DEBUG(log, "Saving result to {}", posOutFilename);
49 if (eonc::io::io_ok(matter->matter2con(posOutFilename))) {
50 returnFiles.push_back(posOutFilename);
51 } else {
52 QUILL_LOG_ERROR(log, "Failed to write {}", posOutFilename);
53 }
54
55 std::string resultsFilename("results.dat");
56
57 std::ofstream out(resultsFilename, std::ios::binary);
58 if (!out) {
59 QUILL_LOG_CRITICAL(log, "Failed to open {}", resultsFilename);
60 throw std::runtime_error("failed to open " + resultsFilename);
61 }
62 out << std::format(
63 "{} potential_type\n",
64 magic_enum::enum_name<PotType>(params.potential_options.potential));
65 out << std::format("{} total_force_calls\n",
66 PotRegistry::get().total_force_calls());
67 out << std::format("{:f} potential_energy\n", matter->getPotentialEnergy());
68 out.close();
69 if (!out) {
70 QUILL_LOG_CRITICAL(log, "Failed to write {}", resultsFilename);
71 throw std::runtime_error("failed to write " + resultsFilename);
72 }
73 returnFiles.push_back(resultsFilename);
74
75 return returnFiles;
76}
std::shared_ptr< Potential > pot
Definition Job.h:55
Parameters params
Definition Job.h:54
eonc::log::Scoped log
void run(int numSteps, double temperature, double stepSize)
static PotRegistry & get() noexcept
Process-lifetime singleton.
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38

Member Data Documentation

◆ log

eonc::log::Scoped eonc::MonteCarloJob::log
private

Definition at line 28 of file MonteCarloJob.h.


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