25 #include "CVs/CVManager.h"
26 #include "Validator/ObjectRequirement.h"
27 #include "Drivers/DriverException.h"
36 if(IsMasterRank(comm_))
39 log_.open(filename_.c_str(), std::ofstream::out | std::ofstream::app);
43 log_.open(filename_.c_str(), std::ofstream::out);
47 auto cvs = cvmanager.
GetCVs(cvmask_);
48 for(
size_t i = 0; i < cvs.size() - 1; ++i)
49 log_ <<
"cv_" + std::to_string(i) <<
" ";
50 log_ <<
"cv_" + std::to_string(cvs.size() - 1) << std::endl;
58 auto cvs = cvmanager.
GetCVs(cvmask_);
59 if(IsMasterRank(comm_))
65 for(
size_t i = 0; i < cvs.size() - 1; ++i)
66 log_ << cvs[i]->GetValue() <<
" ";
67 log_ << cvs.back()->GetValue() << std::endl;
75 Logger* Logger::Build(
const Value& json,
76 const MPI_Comm& world,
78 const std::string& path)
82 CharReaderBuilder rbuilder;
83 CharReader* reader = rbuilder.newCharReader();
85 reader->parse(JsonSchema::Logger.c_str(),
86 JsonSchema::Logger.c_str() + JsonSchema::Logger.size(),
88 validator.
Parse(schema, path);
95 auto freq = json.get(
"frequency", 1).asInt();
96 std::string name =
"cvlog.dat";
98 bool ismulti = GetNumWalkers(world, comm) > 1;
99 unsigned int wid = GetWalkerID(world, comm);
101 if(json[
"output_file"].isArray())
103 if(json[
"output_file"].size() != GetNumWalkers(world, comm))
105 throw BuildException({path +
": Multi-walker simulations require a separate output file for each walker."});
107 name = json[
"output_file"][wid].asString();
110 throw std::invalid_argument(path +
": Multi-walker simulations require a separate output file for each.");
112 name = json[
"output_file"].asString();
114 auto* l =
new Logger(freq, name, world, comm);
115 l->SetAppend(json.get(
"append",
false).asBool());
118 std::vector<unsigned int> cvmask;
119 for(
auto& cv : json[
"cvs"])
121 cvmask.push_back(CVManager::LookupCV(cv, path));
123 l->SetCVMask(cvmask);
Requirements on an object.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement(s).
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.
std::vector< std::string > GetErrors()
Get list of error messages.
bool HasErrors()
Check if errors have occured.
Exception to be thrown when building the Driver fails.
Collective variable manager.
CVList GetCVs(const std::vector< unsigned int > &mask=std::vector< unsigned int >()) const
Get CV iterator.
Base class for logging SSAGES data.
Class containing a snapshot of the current simulation in time.
size_t GetIteration() const
Get the current iteration.