LatticeYangMills
jsonaction.cpp
1 #include "InputOutput/JsonInput/json.hpp"
2 #include "InputOutput/JsonInput/jsoninput.h"
3 #include "InputOutput/JsonInput/JsonAction/jsonaction.h"
4 //#include "Actions/JsonInput/jsonuseractions.h"
5 #include "Apps/app.h"
6 #include "Actions/actionlist.h"
7 #include <iostream>
8 
9 namespace LatticeIO {
10  namespace JsonInput {
11  void validateAction(){
12  // check action
13  if(jsonFile["App"]["type"] == "PGFG" || jsonFile["App"]["type"] == "FLOW"){
14  if(jsonFile.count("Action") == 0){
15  std::cerr << "LatticeQCD Error: no Action specified\n";
16  exit(1);
17  }
18  if(jsonFile.count("Action") != 1){
19  std::cerr << "LatticeQCD Error: too many Action specified\n";
20  exit(1);
21  }
22 
23  // check for action specification
24  if( jsonFile["Action"]["type"].size() != 1
25  || jsonFile["Action"]["params"].size() == 0){
26  std::cerr << "LatticeQCD Error: wrong Action specification\n"
27  "Correct format is:\n"
28  "\"Action\" : {\n"
29  " \"type\" : actionType, \n"
30  " \"params\" : { \n"
31  " \"param1\" : param1, \n"
32  " \"param2\" : param2, \n"
33  " ... \n"
34  " }\n"
35  "}\n";
36  exit(1);
37  }
38 
39  // check core actions
40  if( !validateCoreActions()
41  //&& !validateUserActions()
42  ) {
43  std::cerr << "LatticeQCD Error: unknown Action "
44  << jsonFile["Action"]["type"] << "\n";
45  exit(1);
46  }
47 
48  }
49  }
50 
51  bool validateCoreActions(){
52  // check puregauge
53  if(jsonFile["Action"]["type"] == "puregauge"){
54  validatePureGauge();
55  return true;
56  }
57  return false;
58  }
59 
60  void validatePureGauge(){
61  // check puregauge
62  if( jsonFile["Action"]["params"].size() != 1
63  || jsonFile["Action"]["params"]["beta"].size() != 1){
64  std::cerr << "LatticeQCD Error: wrong \"puregauge\" action specification\n"
65  "Correct format:"
66  "\"Action\" : {\n"
67  " \"type\" : \"puregauge\", \n"
68  " \"params\" : { \n"
69  " \"beta\" : beta \n"
70  " }\n"
71  "}\n";
72  exit(1);
73  }
74  }
75 
76  void registerAction(class App*& app){
77  registerCoreActions(app);
78  //registerUserActions(app);
79  }
80 
81  void registerCoreActions(class App*& app){
82  if(jsonFile["Action"]["type"] == "puregauge")
83  registerPureGauge(app);
84  }
85  // Core implemented actions
86  void registerPureGauge(class App*& app){
87  double beta = jsonFile["Action"]["params"]["beta"];
88  app->setAction(new PureGauge(beta));
89  }
90 
91  } // end JsonInput
92 } // end LatticeIO
Main include file for Action derived classes.
Implementation of the PureGauge derived Action class.
Definition: puregauge.h:50
void setAction(Action *action)
Initializes the Action object pointer given an instance of it.
Definition: app.cpp:50
Contains the definition of the App prototype.
Prototype for the App class group.
Definition: app.h:59