summaryrefslogtreecommitdiff
path: root/src/simulation
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-04-18 19:44:01 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-04-18 19:44:01 (GMT)
commit10e3f176d234782ecd097ab62dc328c6dafc5758 (patch)
treef5625b4651411eb08612fd7048aa92dea315d510 /src/simulation
parentd9cca3ec1eb0cc6da94c991baaca5bff09997604 (diff)
downloadpowder-10e3f176d234782ecd097ab62dc328c6dafc5758.zip
powder-10e3f176d234782ecd097ab62dc328c6dafc5758.tar.gz
TPT: REALISTIC - Latent heat. It may be buggy, and enthalpy table isn't filled, but it works 4b4830b5a4
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/Simulation.cpp87
-rw-r--r--src/simulation/Simulation.h1
-rw-r--r--src/simulation/SimulationData.cpp172
-rw-r--r--src/simulation/SimulationData.h2
4 files changed, 258 insertions, 4 deletions
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index 1d24d2b..730e5f1 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -2662,14 +2662,17 @@ void Simulation::update_particles_i(int start, int inc)
else
pt = (c_heat+parts[i].temp*96.645/ptypes[t].hconduct*fabs(ptypes[t].weight))/(c_Cm+96.645/ptypes[t].hconduct*fabs(ptypes[t].weight));
+ c_heat += parts[i].temp*96.645/ptypes[t].hconduct*fabs(ptypes[t].weight);
+ c_Cm += 96.645/ptypes[t].hconduct*fabs(ptypes[t].weight);
+ parts[i].temp = restrict_flt(pt, MIN_TEMP, MAX_TEMP);
#else
pt = (c_heat+parts[i].temp)/(h_count+1);
-#endif
pt = parts[i].temp = restrict_flt(pt, MIN_TEMP, MAX_TEMP);
for (j=0; j<8; j++)
{
parts[surround_hconduct[j]].temp = pt;
}
+#endif
ctemph = ctempl = pt;
// change boiling point with pressure
@@ -2682,29 +2685,93 @@ void Simulation::update_particles_i(int start, int inc)
s = 1;
if (ctemph>ptransitions[t].thv&&ptransitions[t].tht>-1) {
// particle type change due to high temperature
+#ifdef REALISTIC
+ float dbt = ctempl - pt;
+ if (ptransitions[t].tht!=PT_NUM)
+ {
+ if (platent[t] <= (c_heat - (ptransitions[t].thv - dbt)*c_Cm))
+ {
+ pt = (c_heat - platent[t])/c_Cm;
+ t = ptransitions[t].tht;
+ }
+ else
+ {
+ parts[i].temp = restrict_flt(ptransitions[t].thv - dbt, MIN_TEMP, MAX_TEMP);
+ s = 0;
+ }
+ }
+ #else
if (ptransitions[t].tht!=PT_NUM)
t = ptransitions[t].tht;
+#endif
else if (t==PT_ICEI) {
- if (parts[i].ctype>0&&parts[i].ctype<PT_NUM&&parts[i].ctype!=PT_ICEI) {
+ if (parts[i].ctype<PT_NUM&&parts[i].ctype!=PT_ICEI) {
if (ptransitions[parts[i].ctype].tlt==PT_ICEI&&pt<=ptransitions[parts[i].ctype].tlv) s = 0;
else {
+#ifdef REALISTIC
+ //One ice table value for all it's kinds
+ if (platent[t] <= (c_heat - (ptransitions[parts[i].ctype].tlv - dbt)*c_Cm))
+ {
+ pt = (c_heat - platent[t])/c_Cm;
+ t = parts[i].ctype;
+ parts[i].ctype = PT_NONE;
+ parts[i].life = 0;
+ }
+ else
+ {
+ parts[i].temp = restrict_flt(ptransitions[parts[i].ctype].tlv - dbt, MIN_TEMP, MAX_TEMP);
+ s = 0;
+ }
+ #else
t = parts[i].ctype;
parts[i].ctype = PT_NONE;
parts[i].life = 0;
+#endif
}
}
- else if (pt>274.0f) t = PT_WATR;
else s = 0;
}
else if (t==PT_SLTW) {
+#ifdef REALISTIC
+ if (platent[t] <= (c_heat - (ptransitions[t].thv - dbt)*c_Cm))
+ {
+ pt = (c_heat - platent[t])/c_Cm;
+
+ if (1>rand()%6) t = PT_SALT;
+ else t = PT_WTRV;
+ }
+ else
+ {
+ parts[i].temp = restrict_flt(ptransitions[t].thv - dbt, MIN_TEMP, MAX_TEMP);
+ s = 0;
+ }
+#else
if (1>rand()%6) t = PT_SALT;
else t = PT_WTRV;
+#endif
}
else s = 0;
} else if (ctempl<ptransitions[t].tlv&&ptransitions[t].tlt>-1) {
// particle type change due to low temperature
+#ifdef REALISTIC
+ float dbt = ctempl - pt;
if (ptransitions[t].tlt!=PT_NUM)
- t = ptransitions[t].tlt;
+ {
+ if (platent[ptransitions[t].tlt] >= (c_heat - (ptransitions[t].tlv - dbt)*c_Cm))
+ {
+ pt = (c_heat + platent[ptransitions[t].tlt])/c_Cm;
+ t = ptransitions[t].tlt;
+ }
+ else
+ {
+ parts[i].temp = restrict_flt(ptransitions[t].tlv - dbt, MIN_TEMP, MAX_TEMP);
+ s = 0;
+ }
+ }
+#else
+ if (ptransitions[t].tlt!=PT_NUM)
+ t = ptransitions[t].tlt;
+#endif
else if (t==PT_WTRV) {
if (pt<273.0f) t = PT_RIME;
else t = PT_DSTW;
@@ -2736,6 +2803,13 @@ void Simulation::update_particles_i(int start, int inc)
else s = 0;
}
else s = 0;
+#ifdef REALISTIC
+ pt = restrict_flt(pt, MIN_TEMP, MAX_TEMP);
+ for (j=0; j<8; j++)
+ {
+ parts[surround_hconduct[j]].temp = pt;
+ }
+#endif
if (s) { // particle type change occurred
if (t==PT_ICEI||t==PT_LAVA)
parts[i].ctype = parts[i].type;
@@ -3502,6 +3576,11 @@ Simulation::Simulation():
memcpy(ptypes, ptypesT, elementCount * sizeof(part_type));
free(ptypesT);
+ int latentCount;
+ unsigned int * platentT = LoadLatent(latentCount);
+ memcpy(platent, platentT, latentCount * sizeof(unsigned int));
+ free(platentT);
+
int transitionCount;
part_transition * ptransitionsT = LoadTransitions(transitionCount);
memcpy(ptransitions, ptransitionsT, sizeof(part_transition) * transitionCount);
diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h
index 3139b77..1258373 100644
--- a/src/simulation/Simulation.h
+++ b/src/simulation/Simulation.h
@@ -140,6 +140,7 @@ public:
Air * air;
part_type ptypes[PT_NUM];
+ unsigned int platent[PT_NUM];
part_transition ptransitions[PT_NUM];
wall_type wtypes[UI_WALLCOUNT];
gol_menu gmenu[NGOL];
diff --git a/src/simulation/SimulationData.cpp b/src/simulation/SimulationData.cpp
index e533491..7022b93 100644
--- a/src/simulation/SimulationData.cpp
+++ b/src/simulation/SimulationData.cpp
@@ -358,6 +358,178 @@ part_type * LoadElements(int & elementCount)
return ptypesT;
}
+unsigned int * LoadLatent(int & elementCount)
+{
+ unsigned int platent[PT_NUM] =
+ {
+ /* NONE */ 0,
+ /* DUST */ 0,
+ /* WATR */ 7500,
+ /* OIL */ 0,
+ /* FIRE */ 0,
+ /* STNE */ 0,
+ /* LAVA */ 0,
+ /* GUN */ 0,
+ /* NITR */ 0,
+ /* CLNE */ 0,
+ /* GAS */ 0,
+ /* C-4 */ 0,
+ /* GOO */ 0,
+ /* ICE */ 1095,
+ /* METL */ 919,
+ /* SPRK */ 0,
+ /* SNOW */ 1095,
+ /* WOOD */ 0,
+ /* NEUT */ 0,
+ /* PLUT */ 0,
+ /* PLNT */ 0,
+ /* ACID */ 0,
+ /* VOID */ 0,
+ /* WTRV */ 0,
+ /* CNCT */ 0,
+ /* DSTW */ 7500,
+ /* SALT */ 0,
+ /* SLTW */ 7500,
+ /* DMND */ 0,
+ /* BMTL */ 0,
+ /* BRMT */ 0,
+ /* PHOT */ 0,
+ /* URAN */ 0,
+ /* WAX */ 0,
+ /* MWAX */ 0,
+ /* PSCN */ 0,
+ /* NSCN */ 0,
+ /* LN2 */ 0,
+ /* INSL */ 0,
+ /* VACU */ 0,
+ /* VENT */ 0,
+ /* RBDM */ 0,
+ /* LRBD */ 0,
+ /* NTCT */ 0,
+ /* SAND */ 0,
+ /* GLAS */ 0,
+ /* PTCT */ 0,
+ /* BGLA */ 0,
+ /* THDR */ 0,
+ /* PLSM */ 0,
+ /* ETRD */ 0,
+ /* NICE */ 0,
+ /* NBLE */ 0,
+ /* BTRY */ 0,
+ /* LCRY */ 0,
+ /* STKM */ 0,
+ /* SWCH */ 0,
+ /* SMKE */ 0,
+ /* DESL */ 0,
+ /* COAL */ 0,
+ /* LO2 */ 0,
+ /* O2 */ 0,
+ /* INWR */ 0,
+ /* YEST */ 0,
+ /* DYST */ 0,
+ /* THRM */ 0,
+ /* GLOW */ 0,
+ /* BRCK */ 0,
+ /* CFLM */ 0,
+ /* FIRW */ 0,
+ /* FUSE */ 0,
+ /* FSEP */ 0,
+ /* AMTR */ 0,
+ /* BCOL */ 0,
+ /* PCLN */ 0,
+ /* HSWC */ 0,
+ /* IRON */ 0,
+ /* MORT */ 0,
+ /* LIFE */ 0,
+ /* DLAY */ 0,
+ /* CO2 */ 0,
+ /* DRIC */ 0,
+ /* CBNW */ 7500,
+ /* STOR */ 0,
+ /* STOR */ 0,
+ /* FREE */ 0,
+ /* FREE */ 0,
+ /* FREE */ 0,
+ /* FREE */ 0,
+ /* FREE */ 0,
+ /* SPNG */ 0,
+ /* RIME */ 0,
+ /* FOG */ 0,
+ /* BCLN */ 0,
+ /* LOVE */ 0,
+ /* DEUT */ 0,
+ /* WARP */ 0,
+ /* PUMP */ 0,
+ /* FWRK */ 0,
+ /* PIPE */ 0,
+ /* FRZZ */ 0,
+ /* FRZW */ 0,
+ /* GRAV */ 0,
+ /* BIZR */ 0,
+ /* BIZRG*/ 0,
+ /* BIZRS*/ 0,
+ /* INST */ 0,
+ /* ISOZ */ 0,
+ /* ISZS */ 0,
+ /* PRTI */ 0,
+ /* PRTO */ 0,
+ /* PSTE */ 0,
+ /* PSTS */ 0,
+ /* ANAR */ 0,
+ /* VINE */ 0,
+ /* INVS */ 0,
+ /* EQVE */ 0,
+ /* SPWN2*/ 0,
+ /* SPAWN*/ 0,
+ /* SHLD1*/ 0,
+ /* SHLD2*/ 0,
+ /* SHLD3*/ 0,
+ /* SHLD4*/ 0,
+ /* LOlZ */ 0,
+ /* WIFI */ 0,
+ /* FILT */ 0,
+ /* ARAY */ 0,
+ /* BRAY */ 0,
+ /* STKM2*/ 0,
+ /* BOMB */ 0,
+ /* C-5 */ 0,
+ /* SING */ 0,
+ /* QRTZ */ 0,
+ /* PQRT */ 0,
+ /* EMP */ 0,
+ /* BREL */ 0,
+ /* ELEC */ 0,
+ /* ACEL */ 0,
+ /* DCEL */ 0,
+ /* TNT */ 0,
+ /* IGNP */ 0,
+ /* BOYL */ 0,
+ /* FREE */ 0,
+ /* FREE */ 0,
+ /* FREE */ 0,
+ /* FREE */ 0,
+ /* FREE */ 0,
+ /* WIND */ 0,
+ /* H2 */ 0,
+ /* SOAP */ 0,
+ /* NBHL */ 0,
+ /* NWHL */ 0,
+ /* MERC */ 0,
+ /* PBCN */ 0,
+ /* GPMP */ 0,
+ /* CLST */ 0,
+ /* WIRE */ 0,
+ /* GBMB */ 0,
+ /* FIGH */ 0,
+ /* FRAY */ 0,
+ /* REPL */ 0,
+ };
+ elementCount = PT_NUM;
+ unsigned int * platentT = (unsigned int*)malloc(PT_NUM*sizeof(unsigned int));
+ memcpy(platentT, platent, PT_NUM*sizeof(unsigned int));
+ return platentT;
+}
+
part_transition * LoadTransitions(int & transitionCount)
{
#define IPL -257.0f
diff --git a/src/simulation/SimulationData.h b/src/simulation/SimulationData.h
index 1e1c455..03c491a 100644
--- a/src/simulation/SimulationData.h
+++ b/src/simulation/SimulationData.h
@@ -148,6 +148,8 @@ menu_section * LoadMenus(int & menuCount);
part_type * LoadElements(int & elementCount);
+unsigned int * LoadLatent(int & elementCount);
+
part_transition * LoadTransitions(int & transitionCount);
#endif /* SIMULATIONDATA_H_ */