00001 /*************************************************************************** 00002 * * 00003 * LBflow - an extensible lattice Boltzmann simulation framework * 00004 * * 00005 * Copyright (C) 2007 by Ed Llewellin * 00006 * * 00007 * This file may not be copied or shared without permission * 00008 * Contact ed@lbflow.co.uk or visit www.lbflow.co.uk * 00009 * * 00010 ***************************************************************************/ 00011 00012 #ifndef SIMULATION_H 00013 #define SIMULATION_H 00014 00015 #include <vector> 00016 #include <list> 00017 #include <set> 00018 #include <map> 00019 00020 #ifdef HAVE_CONFIG_H 00021 #include <config.h> 00022 #endif 00023 00024 #include "variableuser.h" 00025 00026 //forward declarations 00027 class Parser; 00028 class Lattice; 00029 class Output; 00030 class Event; 00031 class Variable; 00032 class TimeController; 00033 class Nodegroup; 00034 class Module; 00035 class Mapping; 00036 class Steered; 00037 #ifdef ENABLE_MPI 00038 class MPIShuttle; 00039 #endif /*ENABLE_MPI*/ 00040 00048 class Simulation : public VariableUser { 00049 00050 private: 00051 //private data members 00052 Lattice* lattice; 00053 00054 TimeController* tc; 00055 00056 vector<Module*> modules; 00057 00058 vector<VariableUser*> variable_users; 00059 00060 map<string, Variable*> variables; 00061 00062 vector<Steered*> steered_parameters; 00063 00064 vector<Nodegroup*> nodegroups; 00065 00066 list<Event*> events; 00067 00068 vector<map<Module*, void(*)(void*)>*> actions; 00069 00070 string halt; 00071 00072 static Mapping* mapping; 00073 00074 public: 00075 //constructor 00076 Simulation(); 00077 //destructor 00078 ~Simulation(); 00079 00080 //overload methods in VariableUser 00081 virtual string updateValueInVariable(Variable*); 00082 virtual string getVariableValue(Variable*) ; 00083 00084 //read and write methods 00085 void read(Parser*); 00086 void writeToSim(ostream&); 00087 00088 //setters 00089 void addVariableUser(VariableUser*); 00090 void addVariable(Variable*); 00091 void addSteeredParameter(Steered*); 00092 void addNodegroup(Nodegroup*); 00093 void addModuleAction(Module*, void (*)(void*)); 00094 00095 //getters 00096 Lattice* getLattice(); 00097 TimeController* getTimeController(); 00098 vector<VariableUser*>* getVariableUsers(); 00099 Variable* getVariable(string); 00100 Nodegroup* getNodegroup(string); 00101 vector<Nodegroup*>* getNodegroups(); 00102 list<Event*>* getEvents(); 00103 static Mapping* getMapping(); 00104 00105 //other public methods 00106 void removeModule(Module*); 00107 void removeNodegroup(Nodegroup*); 00108 bool hasVariable(string); 00109 void haltSimulation(string); 00110 bool isHalted(); 00111 string whyStopped(); 00112 void outputModInfo(string); 00113 void run(); 00114 00115 private: 00116 //private methods 00117 void createLattice(Parser*); 00118 void readModule(Parser*); 00119 Module* loadModule(string); 00120 void readEvent(Parser*); 00121 void initialize(); 00122 00123 #ifdef ENABLE_MPI 00124 private: 00125 int mpi_myrank; 00126 int mpi_size; 00127 map<int, int>* mpi_proc_map; 00128 map<int, MPIShuttle*> shuttles; 00129 public: 00130 enum PartitionType {trivial, metis}; 00131 int mpiGetSize(); 00132 int mpiGetRank(); 00133 void mpiInit(int); 00134 void mpiPartitionDomain(int, Parser*, PartitionType, string); 00135 void mpiAddShuttle(MPIShuttle*); 00136 MPIShuttle* mpiGetShuttle(int); 00137 private: 00138 void mpiReadModulesAndWeights(Parser*); 00139 void mpiWriteProcMap(string); 00140 #endif /*ENABLE_MPI*/ 00141 00142 }; 00143 00144 #endif