00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "ParticleState.h"
00015 #include "papi.h"
00016
00017 #include <iostream>
00018 #include <typeinfo>
00019
00020
00021 float PActionBase::dt;
00022
00023 std::vector<ParticleGroup> ParticleState::PGroups;
00024 std::vector<ActionList> ParticleState::ALists;
00025
00026
00027
00028 ParticleState __ps;
00029
00030 const pVec P010(0.0f, 1.0f, 0.0f);
00031 const pVec P000(0.0f, 0.0f, 0.0f);
00032 const pVec P111(1.0f, 1.0f, 1.0f);
00033
00034 ParticleState::ParticleState() : Up(new PDPoint(P010)), Vel(new PDPoint(P000)), RotVel(new PDPoint(P000)),
00035 VertexB(new PDPoint(P000)), Size(new PDPoint(P111)), Color(new PDPoint(P111)), Alpha(new PDPoint(P111))
00036 {
00037 in_call_list = false;
00038 in_new_list = false;
00039 vertexB_tracks = true;
00040
00041 dt = 1.0f;
00042
00043 pgroup_id = -1;
00044 alist_id = -1;
00045 tid = 0;
00046 ErrorCode = PERR_NO_ERROR;
00047
00048 Age = 0.0f;
00049 AgeSigma = 0.0f;
00050 Mass = 1.0f;
00051 }
00052
00053 ParticleState::~ParticleState()
00054 {
00055 delete Up;
00056 delete Vel;
00057 delete RotVel;
00058 delete VertexB;
00059 delete Size;
00060 delete Color;
00061 delete Alpha;
00062 }
00063
00064 void ParticleState::SetError(const int err, const std::string &Str)
00065 {
00066 std::cerr << Str << std::endl;
00067
00068 if(ErrorCode == PERR_NO_ERROR)
00069 ErrorCode = err;
00070
00071 abort();
00072 }
00073
00074 ParticleGroup &ParticleState::GetPGroup(int p_group_num)
00075 {
00076 if(p_group_num < 0) {
00077 std::cerr << "ERROR: Negative particle group number\n";
00078 abort();
00079 }
00080
00081 if(p_group_num >= (int)PGroups.size()) {
00082 std::cerr << "ERROR: Bad particle group number\n";
00083 abort();
00084 }
00085
00086 return PGroups[p_group_num];
00087 }
00088
00089 ActionList &ParticleState::GetAList(int a_list_num)
00090 {
00091 if(a_list_num < 0) {
00092 std::cerr << "ERROR: Negative action list number\n";
00093 abort();
00094 }
00095
00096 if(a_list_num >= (int)ALists.size()) {
00097 std::cerr << "ERROR: Bad action list number\n";
00098 abort();
00099 }
00100
00101 return ALists[a_list_num];
00102 }
00103
00104
00105
00106 int ParticleState::GeneratePGroups(int pgroups_requested)
00107 {
00108 int old_size = (int)PGroups.size();
00109 PGroups.resize(old_size + pgroups_requested);
00110
00111 return old_size;
00112 }
00113
00114
00115
00116 int ParticleState::GenerateALists(int alists_requested)
00117 {
00118 int old_size = (int)ALists.size();
00119 ALists.resize(old_size + alists_requested);
00120
00121 return old_size;
00122 }
00123
00124
00125 void ParticleState::SendAction(PActionBase *S)
00126 {
00127 if(in_new_list) {
00128
00129 ActionList &AList = GetAList(alist_id);
00130 AList.push_back(S);
00131 } else {
00132
00133 S->dt = dt;
00134 ParticleGroup &pg = GetPGroup(pgroup_id);
00135 S->Execute(pg, pg.begin(), pg.end());
00136 delete S;
00137 }
00138 }
00139
00140
00141 void ParticleState::ExecuteActionList(ActionList &AList)
00142 {
00143 ParticleGroup &pg = GetPGroup(pgroup_id);
00144 in_call_list = true;
00145
00146 ActionList::iterator it = AList.begin();
00147 while(it != AList.end()) {
00148
00149 ActionList::iterator abeg = it;
00150 ActionList::iterator aend = it+1;
00151
00152
00153 if(!(*abeg)->GetKillsParticles() && !(*abeg)->GetDoNotSegment())
00154 while(aend != AList.end() && !(*aend)->GetKillsParticles() && !(*aend)->GetDoNotSegment())
00155 aend++;
00156
00157
00158 ParticleList::iterator pbeg = pg.begin();
00159 ParticleList::iterator pend = min(pbeg + PWorkingSetSize, pg.end());
00160 bool one_pass = false;
00161 if(aend - abeg == 1) {
00162 pend = pg.end();
00163 one_pass = true;
00164 }
00165
00166 ActionList::iterator ait = abeg;
00167 do {
00168
00169 ait = abeg;
00170 while(ait < aend) {
00171 (*ait)->dt = dt;
00172 (*ait)->Execute(pg, pbeg, pend);
00173
00174
00175 if(typeid(ait) == typeid(PAFountain))
00176 ait += 6;
00177 else
00178 ait++;
00179 }
00180 pbeg = pend;
00181 pend = min(pend + PWorkingSetSize, pg.end());
00182 } while (!one_pass && pbeg != pg.end());
00183 it = ait;
00184 }
00185 in_call_list = false;
00186 }