KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
Kernel_Recorder.cpp
Go to the documentation of this file.
2
3#include "kids/Einsum.h"
5#include "kids/RuleSet.h"
6#include "kids/hash_fnv1a.h"
7#include "kids/linalg.h"
8#include "kids/macro_utils.h"
9#include "kids/vars_list.h"
10
11namespace PROJECT_NS {
12
13const std::string Kernel_Recorder::getName() { return "Kernel_Recorder"; }
14
16
18 _ruleset = std::shared_ptr<RuleSet>(new RuleSet()); //
19}
20
22
23void Kernel_Recorder::setInputParam_impl(std::shared_ptr<Param>& PM) {
24 dt = PM->get_double("dt", LOC(), phys::time_d);
25 t0 = PM->get_double("t0", LOC(), phys::time_d, 0.0f);
26 time_unit = PM->get_double("time_unit", LOC(), phys::time_d, 1.0f);
27 directory = PM->get_string("directory", LOC(), "default");
28}
29
37
39 std::string rule, mode, save;
40 if (j.is_string()) {
41 rule = j.get<std::string>();
42 mode = "average";
43 save = "res.dat";
44 // mode = "every";
45 // save = "traj_{TRAJID}.dat";
46 } else if (j.is_object()) {
47 if (j.count("rule") == 1) {
48 rule = j["rule"].get<std::string>();
49 } else {
50 throw kids_error("parser rule error");
51 }
52 if (j.count("mode") == 1) mode = j["mode"].get<std::string>();
53 if (j.count("save") == 1) save = j["save"].get<std::string>();
54 } else if (j.is_array()) { // compile with old format @deprecated!
55 std::string v0 = j[0].get<std::string>();
56 auto ipos = v0.find_first_of("#");
57 if (ipos != std::string::npos) rule = v0.substr(ipos + 1, v0.size());
58 if (ipos != std::string::npos) v0 = v0.substr(0, ipos);
59 std::string v1 = j[1].get<std::string>();
60 ipos = v1.find_first_of("#");
61 if (ipos != std::string::npos) rule += v1.substr(ipos + 1, v1.size());
62 if (ipos != std::string::npos) v1 = v1.substr(0, ipos);
63 rule += utils::concat("A(", v0, ",", v1, ")");
64 mode = "average";
65 save = "res.dat";
66 } else {
67 throw std::runtime_error("recorder parse error");
68 }
69
70 if (std::find(opened_files.begin(), opened_files.end(), save) == opened_files.end()) {
71 std::shared_ptr<RuleEvaluator> record_time_rule( //
72 new RuleEvaluator("t{iter}:R", _dataset, "copy", save, nsamp_ptr[0]));
73 _ruleset->registerRules(record_time_rule);
74 opened_files.push_back(save);
75 }
76
77 std::shared_ptr<RuleEvaluator> record_rule( //
78 new RuleEvaluator(rule, _dataset, mode, save, nsamp_ptr[0]));
79 _ruleset->registerRules(record_rule);
80}
81
83 bool not_parsed = _ruleset->getRules().size() == 0;
84 auto& json = *(_param->pjson());
85 if (not_parsed && json.count("result") == 1 && json["result"].is_array()) {
86 for (auto& j : (json["result"])) token(j);
87 }
88 return stat;
89}
90
93 for (auto& irule : _ruleset->getRules()) { irule->calculateResult(isamp_ptr[0]); }
94 }
95 return stat;
96}
97
99 for (auto& irule : _ruleset->getRules()) irule->collectResult();
100 return stat;
101}
102
103}; // namespace PROJECT_NS
this file provides einsum operation
this file provides Kernel_Recorder class for trace data in dataset during the dynamics.
provide RuleEvaluator class
provide RuleSet class
virtual void token(Param::JSON &j)
virtual const std::string getName()
Get the name of the kernel.
virtual Status & finalizeKernel_impl(Status &stat)
Virtual function to finalize the kernel implementation.
virtual Status & initializeKernel_impl(Status &stat)
Virtual function to initialize the kernel implementation.
std::vector< std::string > opened_files
virtual void setInputParam_impl(std::shared_ptr< Param > &PM)
Virtual function to set input parameters for the kernel implementation.
virtual void setInputDataSet_impl(std::shared_ptr< DataSet > &DS)
Virtual function to set input data set for the kernel implementation.
virtual Status & executeKernel_impl(Status &stat)
Virtual function to execute the kernel implementation.
kids_bint * at_samplingstep_initially_ptr
virtual int getType() const
Get the type of the kernel.
std::shared_ptr< Param > _param
Shared pointer to the Param object associated with this kernel.
Definition Kernel.h:273
std::shared_ptr< DataSet > _dataset
Shared pointer to the DataSet object associated with this kernel.
Definition Kernel.h:278
std::shared_ptr< RuleSet > _ruleset
Recorded Rules associated with the Kernel.
Definition Kernel.h:283
configor::json JSON
Definition Param.h:84
Represents a handler for input/output operations related to expressions.
Definition RuleSet.h:48
#define LOC()
show the location information for debug
Definition fmt.h:49
Provide linalg APIs.
#define FUNCTION_NAME
Definition macro_utils.h:9
VARIABLE< kids_int > sstep
VARIABLE< kids_bint > at_samplingstep_initially
VARIABLE< kids_int > istep
VARIABLE< kids_int > isamp
VARIABLE< kids_int > nsamp
< http://warp.povusers.org/FunctionParser/fparser.html
Definition Context.h:39
constexpr dimension7 time_d
[T]
Definition phys.h:187
std::basic_string< CharT > concat(const separator_t< CharT > &sep, Args &&... seq)
Definition concat.h:242
constexpr uint32_t hash(const char *str)
Definition hash_fnv1a.h:12
Represents a rule for evaluating an expression.
declaration of variables used in the program.