00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00039
00040 #ifndef simulationCore_h
00041 #define simulationCore_h
00042
00043
00044 #include <iostream>
00045 #include <map>
00046 #include <vector>
00047 #include <list>
00048 #include <cassert>
00049 #include <string>
00050 #include "constants.h"
00051 #include "config.h"
00052 #include "crusde_api.h"
00053 #include "exceptions.h"
00054
00055 using namespace std;
00056
00057 class LoadHistoryPlugin;
00058 class InputHandler;
00059 class Plugin;
00060 class DataOutPlugin;
00061 class LoadPlugin;
00062 class GreensFunction;
00063 class ExperimentManager;
00064 class PluginManager;
00065 class LoadFunction;
00066 class ParamWrapper;
00067
00069
00074 struct s_parameters {
00075 map< unsigned int, multimap< string, ParamWrapper* > > load;
00076 map< unsigned int, multimap< string, ParamWrapper* > > loadhistory;
00077 map< unsigned int, multimap< string, ParamWrapper* > > crustaldecay;
00078 multimap<string, ParamWrapper* > green;
00079 multimap<string, ParamWrapper* > kernel;
00080 multimap<string, ParamWrapper* > datahandler;
00081 multimap<string, ParamWrapper* > postprocessor;
00082 };
00083
00084 extern void Debug( char* format, ... );
00085
00087
00098 class SimulationCore
00099 {
00100
00101 InputHandler *com_port;
00102 ExperimentManager *exp_man;
00103 PluginManager *plugin_man;
00105 Plugin *pl_kernel;
00106 DataOutPlugin *pl_out;
00107 GreensFunction *greens_function;
00108 LoadFunction *load_function;
00110 unsigned int load_function_component;
00111
00112
00113 int x_west;
00114 int x_east;
00115 int y_south;
00116 int y_north;
00117 int gridsize;
00118
00119 unsigned long int modelstep;
00120 unsigned long int modeltime;
00121 unsigned long int num_timesteps;
00122 unsigned long int num_timeincrement;
00123 int stepsize;
00124 int quadrant;
00125 int dimensions;
00126
00127 int x_index;
00128 int y_index;
00129 int z_index;
00130
00131 map<int*, int> add_field_map;
00132
00133 double **model_data;
00134
00135 list<Plugin*>::iterator pl_iter;
00136
00137 list<Plugin*> requested_plugin_list;
00142 list<Plugin*> pl_list_postprocess;
00144 string root_dir;
00145
00146 int operator_space_x;
00147 int operator_space_y;
00148 bool operator_space_set;
00149
00150 unsigned int num_load_components;
00151
00152 static SimulationCore *pSimulationCore;
00154
00155 SimulationCore(int argc, char** argv) throw(SeriousException);
00157 SimulationCore(const SimulationCore& x);
00159 SimulationCore const &operator=(SimulationCore const &rvalue);
00160
00161
00162
00163
00164 public:
00165 static s_parameters s_params;
00166
00168 ~SimulationCore();
00169
00170 void exec();
00171 void init();
00172 void terminate();
00173
00174 void abort(string msg);
00175
00181 static SimulationCore* instance(int argc, char** argv) throw(){
00182 if(!pSimulationCore){
00183 try{
00184 pSimulationCore = new SimulationCore(argc, argv);
00185 }
00186 catch(SeriousException e)
00187 {
00188 cerr<<e.what()<<"\nAborting..."<<endl;
00189 delete pSimulationCore;
00190 exit(2);
00191 }
00192 catch(...)
00193 {
00194 cerr<<"An unrecognized error occured while trying to build the SimulationCore.\nAborting..."<<endl;
00195 delete pSimulationCore;
00196 exit(2);
00197 }
00198 }
00199
00200 return pSimulationCore;
00201 }
00202
00207 static SimulationCore* instance() throw() {
00208 if(pSimulationCore)
00209 return pSimulationCore;
00210 else{
00211 cerr << "call instance(argc, argv) first! "<< endl;
00212 exit(1);
00213 }
00214 }
00215
00216 GreensFunction* greensFunction(){ return greens_function;}
00217 LoadFunction* loadFunction(){ return load_function;}
00218 DataOutPlugin* dataOutPlugin(){ return pl_out;}
00219
00220
00221 unsigned int getLoadFunctionComponent();
00222 void setLoadFunctionComponent(unsigned int i);
00223
00224 unsigned int getNumberOfLoadComponents();
00225
00226 void registerParam(ParamWrapper *param, const char* name, PluginCategory category);
00227
00228 const char* outFile();
00229
00230 int sizeX();
00231 int sizeY();
00232 int sizeT();
00233 int gridSize();
00234 int minX();
00235 int minY();
00236 unsigned long int modelTime();
00237 int modelStep();
00238 int stepSize();
00239 int xIndex();
00240 int yIndex();
00241 int zIndex();
00242
00243 int getDimensions();
00244 unsigned long int getTimesteps();
00245 int displacementDimensions();
00246
00247
00248 int getQuadrant();
00249 void setQuadrant(int);
00250 void setModelData(double**);
00251 double** getModelData();
00252 void runExperimentManager();
00253 void runPluginManager();
00254 PluginManager* pluginManager();
00255 list<string> getRegisteredParameters(PluginCategory cat);
00256 void deleteRegistrees();
00257 list<string> getRequestedNames();
00258 void deleteRequests();
00259
00260 int getOperatorSpaceX();
00261 int getOperatorSpaceY();
00262 void setOperatorSpace(int, int);
00263 bool operatorSpaceIsSet();
00264
00265 string getPluginFilename(string, string);
00266 void registerOutputField(int *output_index, FieldName field);
00267
00268 string currentJob();
00269
00270
00271 green_exec_function addGreenPlugin(string plugin) throw (FileNotFound, runtime_error);
00272 load_exec_function addLoadPlugin(string plugin) throw (FileNotFound, runtime_error);
00273 run_function addKernelPlugin(string plugin) throw (FileNotFound, runtime_error);
00274 run_function addPostprocessorPlugin(string plugin) throw (FileNotFound, runtime_error);
00275 loadhistory_exec_function addLoadHistoryPlugin(string plugin) throw (FileNotFound, runtime_error);
00276 crustaldecay_exec_function addCrustalDecayPlugin(string plugin) throw (FileNotFound, runtime_error);
00277
00278 };
00279
00280 #endif // simulationCore_h