forked from WarwickDumas/FocusFusion2D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FFxtubes.cpp
2666 lines (2214 loc) · 83.8 KB
/
FFxtubes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Version 0.75
// Here we attempted to tile the mesh by using expanding tiles that aimed basically for
// the vertices with the lowest link distance to the base.
// The result is that it ends up only at the back row finding that some tiles have become too narrow
// and cannot reach enough vertices.
// Version 0.76
// Next thing is to try an azimuthal sweep to create the back row.
// Project needs to include
// newkernel2.obj
// newkernel2.cu.obj
// DropJxy.cpp, qd cpp files, avi_utils.cpp
// meshutil.cpp, mesh.cpp, basics.cpp, surfacegraph_tri.cpp, vector_tensor.cpp
// simulation.cpp, solver.cpp, vetted.cpp, accelerate.cpp, advance.cpp
#include "headers.h"
// #include some cpp files, which should appear here only :
#include "qd/src/fpu.cpp"
#include "qd/src/dd_const.cpp"
#include "qd/src/dd_real.cpp"
#include "qd/src/bits.cpp"
#include "qd/src/c_dd.cpp"
#include "qd/src/util.cpp"
#include "avi_utils.cpp" // for making .avi
#include "cppconst.h"
// Global variables:
// =================
float xzscale;
bool bCullNone = false;
bool bGlobalsave = false;
int GlobalSwitchBox = 0;
int iGlobalScratch;
real GlobalHeightScale;
int GlobalSpeciesToGraph = 1;
int GlobalWhichLabels = 0;
bool GlobalRenderLabels = false;
int GlobalColoursPlanView = 0;
bool GlobalBothSystemsInUse;
bool GlobalCutaway = true;
unsigned int cw; // control word for floating point hardware exception hiding
// Simulation globals :
TriMesh * pX, * pXnew;
TriMesh X1, X2;
long steps_remaining, GlobalStepsCounter;
real evaltime, h;
extern real GlobalIzElasticity;
FILE * massfile,* maxfile;
// Global Variables:
HINSTANCE hInst; // current instance
// window vars:
HWND hWnd;
WNDCLASSEX wcex;
TCHAR szTitle[1024]; // The title bar text
TCHAR szWindowClass[1024]; // the main window class name
char Functionalfilename[1024];
int GlobalGraphSetting[5];
surfacegraph Graph[5]; // why was it 5? // 5th one can be whole thing.
float Historic_max[100][HISTORY]; // if max is falling, use historic maximum for graph.
float Historic_min[100][HISTORY];
int Historic_powermax[200];
int Historic_powermin[200]; // just store previous value only.
bool boolGlobalHistory, GlobalboolDisplayMeshWireframe;
D3DXVECTOR3 GlobalEye,GlobalLookat,GlobalPlanEye,GlobalPlanEye2,GlobalPlanLookat,
GlobalPlanLookat2, GlobalEye2,GlobalLookat2;
// avi file -oriented variables
int const NUMAVI = 1;
HAVI hAvi[NUMAVI];
int const GraphFlags[8] = {SPECIES_NEUTRAL,SPECIES_ION,SPECIES_ELEC,TOTAL,
JZAZBXYEZ, JXYAXYBZEXY, EXY_RHO_PHI_JXY, SIGMA_E_J};
char szAvi[9][128] = {"Plan","Neut","Ion","Elec","Total",
"JzAzBxyEz","JxyAxyBzExy","ExyRhoPhiJxy","SigmaEJ"};
AVICOMPRESSOPTIONS opts;
int counter;
HBITMAP surfbit, dib;
HDC surfdc, dibdc;
LPVOID lpvBits;
BITMAPINFO bitmapinfo;
IDirect3DSurface9* p_backbuffer_surface;
Systdata Systdata_host;
//=======================================================
// Declarations of functions included in this source file
void RefreshGraphs(const TriMesh & X, const int iGraphsFlag);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK SetupBox(HWND, UINT, WPARAM, LPARAM);
void TriMesh::CalculateTotalGraphingData()
{
long iVertex;
Vertex * pVertex = X;
for (iVertex = 0; iVertex < numVertices; iVertex++)
{
if ((pVertex->flags == DOMAIN_VERTEX) || (pVertex->flags == OUTERMOST))
{
pVertex->n = (pVertex->Neut.mass + pVertex->Ion.mass)/pVertex->AreaCell;
pVertex->v = (m_n*pVertex->Neut.mom + m_ion*pVertex->Ion.mom + m_e*pVertex->Elec.mom)/
(m_n*pVertex->Neut.mass+m_ion*pVertex->Ion.mass+m_e*pVertex->Elec.mass);
pVertex->T = (pVertex->Neut.heat + pVertex->Ion.heat + pVertex->Elec.heat)/
(pVertex->Neut.mass + pVertex->Ion.mass + pVertex->Elec.mass);
pVertex->Temp.x = pVertex->Ion.mass/(pVertex->Neut.mass + pVertex->Ion.mass);
};
++pVertex;
}
}
void TriMesh::Setup_J()
{
long iVertex;
Vertex * pVertex = X;
for (iVertex = 0; iVertex < numVertices; iVertex++)
{
if ((pVertex->flags == DOMAIN_VERTEX) || (pVertex->flags == OUTERMOST))
{
pVertex->Temp = q*(pVertex->Ion.mom-pVertex->Elec.mom)/pVertex->AreaCell;
} else {
memset(&(pVertex->Temp),0,sizeof(Vector3));
}
++pVertex;
}
}
void TriMesh::Reset_vertex_nvT(int species)
{
long iVertex;
Vertex * pVertex = X;
switch (species)
{
case SPECIES_NEUT:
for (iVertex = 0; iVertex < numVertices; iVertex++)
{
if ((pVertex->flags == DOMAIN_VERTEX) || (pVertex->flags == OUTERMOST))
{
pVertex->n = pVertex->Neut.mass/pVertex->AreaCell;
pVertex->v = pVertex->Neut.mom/pVertex->Neut.mass;
pVertex->T = pVertex->Neut.heat/pVertex->Neut.mass;
} else {
pVertex->n = 0.0;
memset(&(pVertex->v),0,sizeof(Vector3));
pVertex->T = 0.0;
};
++pVertex;
}
break;
case SPECIES_ION:
for (iVertex = 0; iVertex < numVertices; iVertex++)
{
if ((pVertex->flags == DOMAIN_VERTEX) || (pVertex->flags == OUTERMOST))
{
pVertex->n = pVertex->Ion.mass/pVertex->AreaCell;
pVertex->v = pVertex->Ion.mom/pVertex->Ion.mass;
pVertex->T = pVertex->Ion.heat/pVertex->Ion.mass;
} else {
pVertex->n = 0.0;
memset(&(pVertex->v),0,sizeof(Vector3));
pVertex->T= 0.0;
};
++pVertex;
}
break;
case SPECIES_ELEC:
for (iVertex = 0; iVertex < numVertices; iVertex++)
{
if ((pVertex->flags == DOMAIN_VERTEX) || (pVertex->flags == OUTERMOST))
{
pVertex->n = pVertex->Elec.mass/pVertex->AreaCell;
pVertex->v = pVertex->Elec.mom/pVertex->Elec.mass;
pVertex->T = pVertex->Elec.heat/pVertex->Elec.mass;
} else {
pVertex->n = 0.0;
memset(&(pVertex->v),0,sizeof(Vector3));
pVertex->T= 0.0;
};
++pVertex;
}
break;
}
}
char * report_time(int action)
{
/* action = 0: reset ; action = 1: report */
/* requires timebuffy to be defined as char[255] globally */
static char timebuffer[255];
static clock_t start;
double timenow;
long ops;
if (action == 0)
{
start = clock();
}
else
{
timenow = ((double)(clock()-start)/(double)CLOCKS_PER_SEC);
ops = (long)(clock()-start);
/* create a null-terminated string */
sprintf (timebuffer, "%6.4f sec.",timenow);
};
return &(timebuffer[0]);
};
void surfacegraph::DrawSurface(char szname[],
const int heightflag,
const real * var_ptr_0,
const int colourflag,
const real * var_ptr_c,
const bool bDisplayInner,
const int code, // graph code, to pass to called routines - sometimes useful
const TriMesh * pX // for passing to SetDataWithColour and Render
// and for working out offsets
)
{
// replaced CreateSurfaceGraphs.
// I think this is about the right balance.
char buff[256];
real * temprealptr = (real *)(pX->X);
long offset = var_ptr_0 - temprealptr;
long offset_c = var_ptr_c - temprealptr;
// Does shader always go with colour type?? yes I think.
switch(colourflag) {
case VELOCITY_COLOUR:
this->mhTech = mFX->GetTechniqueByName("VelociTech");
break;
case SEGUE_COLOUR:
this->mhTech = mFX->GetTechniqueByName("SegueTech");
break;
case CURRENT_COLOUR:
this->mhTech = mFX->GetTechniqueByName("XYZTech");
break;
case AZSEGUE_COLOUR:
mhTech = mFX->GetTechniqueByName("AzSegueTech");
break;
case IONISE_COLOUR:
mhTech = mFX->GetTechniqueByName("IoniseTech");
break;
};
// Usual settings:
//if (GlobalGraphSetting[i] != GRAPH_NONE) {
this->boolDisplayMainMesh = true;
this->boolDisplayMeshWireframe = GlobalboolDisplayMeshWireframe;
this->boolClearZBufferBeforeWireframe = false;
// Or try setting true and CULL_CCW to see if this stops it showing "the back of the wireframe"
this->SetEyeAndLookat(GlobalEye, GlobalLookat);
this->boolDisplayScales = true;
this->boolDisplayInnerMesh = bDisplayInner;
// work out whether to display key button:
if (((colourflag == FLAG_VELOCITY_COLOUR) || (colourflag == FLAG_CURRENT_COLOUR))
&& (bDisplayInner == 0))
{
this->boolDisplayKeyButton = true;
} else {
this->boolDisplayKeyButton = false;
};
//int const FLAG_COLOUR_MESH = 0;
//int const FLAG_SEGUE_COLOUR = 1;
//int const FLAG_VELOCITY_COLOUR = 2;
//int const FLAG_CURRENT_COLOUR = 3;
//int const FLAG_AZSEGUE_COLOUR = 4;
//int const FLAG_IONISE_COLOUR = 5;
this->SetDataWithColour(*pX,
colourflag, heightflag, // apparently it's that way round
offset,offset_c,
code);
if (this->bDisplayTimestamp) {
sprintf(buff, "%4.3f ns", evaltime*1.0e9);
this->Render(szname,false,pX,buff);
} else {
this->Render(szname,false,pX);
};
}
// Here we make a function that we can call to tidy up graph calling code:
void PlanViewGraphs1(TriMesh & X)// only not const because of such as Reset_vertex_nvT
{
Vertex * pVertex;
long iVertex;
X.Reset_vertex_nvT(SPECIES_ELECTRON);
D3DXVECTOR3 PlanEye(5.4f,3.2f,70.3f);
for (int i = 0; i < 4; i++)
{
Graph[i].SetEyePlan(PlanEye);
Graph[i].boolDisplayMeshWireframe = false;
Graph[i].boolClearZBufferBeforeWireframe = true;
Graph[i].boolDisplayMainMesh = true;
Graph[i].boolDisplayInnerMesh = false;
Graph[i].boolDisplayScales = false;
};
int offset_v_e = (real *)(&(X.X[0].v)) -(real *)(&(X.X[0]));
int offset_T_e = (real *)(&(X.X[0].T)) -(real *)(&(X.X[0]));
int offset_phi = (real *)(&(X.X[0].phi)) -(real *)(&(X.X[0]));
int offset_ndiff = (real *)(&(X.X[0].Temp.x)) -(real *)(&(X.X[0]));
pVertex = X.X;
for (iVertex = 0; iVertex < X.numVertices; iVertex++)
{
pVertex->Temp.x = (pVertex->Ion.mass-pVertex->Elec.mass)/pVertex->AreaCell;
++pVertex;
}
// phi:
Graph[0].mhTech = Graph[0].mFX->GetTechniqueByName("AzSegueTech");
// n_e-n_i:
Graph[2].mhTech = Graph[2].mFX->GetTechniqueByName("AzSegueTech");
// v_e:
Graph[1].mhTech = Graph[1].mFX->GetTechniqueByName("VelociTech");
// Te:
Graph[3].mhTech = Graph[3].mFX->GetTechniqueByName("SegueTech");
GlobalWhichLabels = 4; // numbers
Graph[0].SetDataWithColour(X,
FLAG_AZSEGUE_COLOUR,FLAG_FLAT_MESH,
offset_phi, offset_phi,
GRAPH_FLAT_WIRE_MESH);// colourmax is being set.
Graph[0].colourmax = 2.5;
Graph[0].Render("phi", true, &X);
GlobalWhichLabels = 5; // numbers
Graph[2].SetDataWithColour(X,
FLAG_AZSEGUE_COLOUR,FLAG_FLAT_MESH,
offset_ndiff, offset_ndiff,
GRAPH_FLAT_WIRE_MESH);
// Where to set colour scale params??
Graph[2].colourmax = 1.0e14;
Graph[2].Render("ni-ne", true, &X);
GlobalWhichLabels = 3;
Graph[1].SetDataWithColour(X,
FLAG_VELOCITY_COLOUR,FLAG_FLAT_MESH,
offset_v_e,offset_v_e,
GRAPH_FLAT_WIRE_MESH); // ?
Graph[1].colourmax = 2.5e8;
Graph[1].Render("ve",true,&X);
GlobalWhichLabels = 2;
// Labels will very shortly be upgraded.
Graph[3].SetDataWithColour(X,
FLAG_SEGUE_COLOUR,FLAG_FLAT_MESH,
offset_T_e, offset_T_e,
GRAPH_FLAT_WIRE_MESH);
//Graph[3].colourmax = 4.0e-11; // colourmax should be left == 1 for T, for whatever reason.
Graph[3].Render("Te",true,&X);
// For now use "Render" -- but create an adjunct routine for adding the
// polygon edges and other details such as velocity arrows..
// Let's see if we can get this to work before continuing.
//Graph[3].DrawSurface("[n_s T_s]/[n_s]",
// DATA_HEIGHT,(real *)(&(X.X[0].T)),
// SEGUE_COLOUR,(real *)(&(X.X[0].T)),
// false,
// GRAPH_TOTAL_T, &X);
//
// Graph 2, in case of species graphs:
//if (GlobalColoursPlanView == 0)
// nothing
//Graph[2].mhTech = Graph[2].mFX->GetTechniqueByName("MeshTech");
//Graph[2].SetDataWithColour(X,FLAG_COLOUR_MESH,FLAG_FLAT_MESH,0,0,
// GRAPH_FLAT_WIRE_MESH);
//Graph[2].Render(buff, GlobalRenderLabels, &X);
// Tell SDWC not to mess with colourmax if it's a flat mesh.
}
void RefreshGraphs(TriMesh & X, // only not const because of such as Reset_vertex_nvT
const int iGraphsFlag)
{
Vertex * pVertex;
long iVertex;
switch(iGraphsFlag) {
case SPECIES_NEUTRAL:
X.Reset_vertex_nvT(SPECIES_NEUTRAL);
Graph[0].DrawSurface("Neutral n",
DATA_HEIGHT,(real *)(&(X.X[0].n)),
VELOCITY_COLOUR,(real *)(&(X.X[0].v)),
false, // no inner mesh display
GRAPH_NEUT_N, &X);
Graph[1].DrawSurface("Neutral v",
VELOCITY_HEIGHT,(real *)(&(X.X[0].v)),
VELOCITY_COLOUR,(real *)(&(X.X[0].v)),
false, // no inner mesh display
GRAPH_NEUT_V, &X);
Graph[3].TickRescaling = 1.0/kB;
Graph[3].DrawSurface("Neutral T",
DATA_HEIGHT,(real *)(&(X.X[0].T)),
SEGUE_COLOUR,(real *)(&(X.X[0].T)),
false, // no inner mesh display
GRAPH_NEUT_T, &X);
Graph[3].TickRescaling = 1.0;
// How to handle Graph[2] ?
break;
case SPECIES_ION:
X.Reset_vertex_nvT(SPECIES_ION);
Graph[3].TickRescaling = 1.0/kB;
Graph[3].DrawSurface("Ion T",
DATA_HEIGHT,(real *)(&(X.X[0].T)),
SEGUE_COLOUR,(real *)(&(X.X[0].T)),
false, // no inner mesh display
GRAPH_ION_T, &X);
Graph[3].TickRescaling = 1.0;
// labels only appear on first 1 called.
Graph[0].DrawSurface("Ion n",
DATA_HEIGHT,(real *)(&(X.X[0].n)),
VELOCITY_COLOUR,(real *)(&(X.X[0].v)),
false, // no inner mesh display
GRAPH_ION_T, &X);
Graph[1].DrawSurface("Ion v",
VELOCITY_HEIGHT,(real *)(&(X.X[0].v)),
VELOCITY_COLOUR,(real *)(&(X.X[0].v)),
false, // no inner mesh display
GRAPH_ION_V, &X);
break;
case SPECIES_ELEC:
X.Reset_vertex_nvT(SPECIES_ELEC);
Graph[0].DrawSurface("Elec n",
DATA_HEIGHT,(real *)(&(X.X[0].n)),
VELOCITY_COLOUR,(real *)(&(X.X[0].v)),
false, // no inner mesh display
GRAPH_ELEC_T, &X);
Graph[1].DrawSurface("Elec v",
VELOCITY_HEIGHT,(real *)(&(X.X[0].v)),
VELOCITY_COLOUR,(real *)(&(X.X[0].v)),
false, // no inner mesh display
GRAPH_ELEC_V, &X);
Graph[3].TickRescaling = 1.0/kB;
Graph[3].DrawSurface("Neutral T",
DATA_HEIGHT,(real *)(&(X.X[0].T)),
SEGUE_COLOUR,(real *)(&(X.X[0].T)),
false, // no inner mesh display
GRAPH_ELEC_T, &X);
Graph[3].TickRescaling = 1.0;
break;
// In other cases, (and even for the above),
// here is a good place to call the
// setup routines for temp variables.
case JZAZBXYEZ:
X.Setup_J(); // the others can already exist.
Graph[0].DrawSurface("Az",
DATA_HEIGHT,(real *)(&(X.X[0].A.z)),
AZSEGUE_COLOUR,(real *)(&(X.X[0].A.z)),
true,
GRAPH_AZ, &X);
Graph[1].DrawSurface("Bxy",
VELOCITY_HEIGHT,(real *)(&(X.X[0].B)),
VELOCITY_COLOUR,(real *)(&(X.X[0].B)),
false, // no inner mesh display: ??
GRAPH_BXY, &X);
Graph[2].DrawSurface("Ez",
DATA_HEIGHT,(real *)(&(X.X[0].E.z)),
FLAG_SEGUE_COLOUR,(real *)(&(X.X[0].E.z)),
false, // ??
GRAPH_EZ, &X);
Graph[3].DrawSurface("Jz",
DATA_HEIGHT,(real *)(&(X.X[0].Temp.z)),
AZSEGUE_COLOUR,(real *)(&(X.X[0].Temp.z)),
false, // no inner mesh display.
GRAPH_JZ, &X);
break;
case JXYAXYBZEXY:
X.Setup_J(); // the others can already exist.
Graph[0].DrawSurface("Axy",
VELOCITY_HEIGHT,(real *)(&(X.X[0].A.x)),
VELOCITY_COLOUR,(real *)(&(X.X[0].A.x)),
true,
GRAPH_AXY, &X);
Graph[1].DrawSurface("Bz",
DATA_HEIGHT,(real *)(&(X.X[0].B.z)),
AZSEGUE_COLOUR,(real *)(&(X.X[0].B.z)),
false, // no inner mesh display: ??
GRAPH_BZ, &X);
Graph[2].DrawSurface("Exy",
VELOCITY_HEIGHT,(real *)(&(X.X[0].E)),
VELOCITY_COLOUR,(real *)(&(X.X[0].E)),
false,
GRAPH_EXY, &X);
Graph[3].DrawSurface("Jxy",
VELOCITY_HEIGHT,(real *)(&(X.X[0].Temp.x)),
VELOCITY_COLOUR,(real *)(&(X.X[0].Temp.x)),
false, // no inner mesh display.
GRAPH_JXY, &X);
break;
case EXY_RHO_PHI_JXY:
// create rho on pVertex->temp2.x ...
pVertex= pX->X;
for (iVertex = 0; iVertex < pX->numVertices; iVertex++)
{
if (pVertex->flags == DOMAIN_VERTEX) {
pVertex->temp2.x = q*(pVertex->Ion.mass-pVertex->Elec.mass)/pVertex->AreaCell;
} else {
pVertex->temp2.x = 0.0;
};
++pVertex;
}
Graph[0].DrawSurface("phi",
DATA_HEIGHT,(real *)(&(X.X[0].phi)),
AZSEGUE_COLOUR,(real *)(&(X.X[0].phi)),
false,
GRAPH_PHI, &X);
Graph[1].DrawSurface("Jxy",
VELOCITY_HEIGHT,(real *)(&(X.X[0].Temp)),
VELOCITY_COLOUR,(real *)(&(X.X[0].Temp)),
false, // no inner mesh display: ??
GRAPH_JXY, &X);
Graph[2].DrawSurface("Exy",
VELOCITY_HEIGHT,(real *)(&(X.X[0].E)),
VELOCITY_COLOUR,(real *)(&(X.X[0].E)),
false,
GRAPH_EXY, &X);
Graph[3].DrawSurface("rho",
DATA_HEIGHT,(real *)(&(X.X[0].temp2.x)),
AZSEGUE_COLOUR,(real *)(&(X.X[0].temp2.x)),
false, // no inner mesh display.
GRAPH_RHO, &X);
break;
case SIGMA_E_J:
X.Setup_J(); // the others can already exist.
Graph[0].DrawSurface("sigma_e_zz",
DATA_HEIGHT,(real *)(&(X.X[0].sigma_e.zz)),
AZSEGUE_COLOUR,(real *)(&(X.X[0].sigma_e.zz)),
true,
GRAPH_SIGMA_E, &X);
//Graph[1].DrawSurface("v_e_0.z",
// DATA_HEIGHT,(real *)(&(X.X[0].v_e_0.z)),
// AZSEGUE_COLOUR,(real *)(&(X.X[0].v_e_0.z)),
//false, // no inner mesh display: ??
// GRAPH_VE0Z, &X);
Graph[1].DrawSurface("nsigma",
DATA_HEIGHT,(real *)(&(X.X[0].xdotdot.x)),
AZSEGUE_COLOUR,(real *)(&(X.X[0].xdotdot.x)),
true, GRAPH_SIGMATEMP, &X);
Graph[2].DrawSurface("Ez",
DATA_HEIGHT,(real *)(&(X.X[0].E.z)),
FLAG_AZSEGUE_COLOUR,(real *)(&(X.X[0].E.z)), // how to make SEGUE_COLOUR work?
false, // ??
GRAPH_EZ, &X);
Graph[3].DrawSurface("Jz",
DATA_HEIGHT,(real *)(&(X.X[0].Temp.z)),
AZSEGUE_COLOUR,(real *)(&(X.X[0].Temp.z)),
false, // no inner mesh display.
GRAPH_JZ, &X);
break;
case TOTAL:
// In this case we have to create data,
// as we go.
// Best put it here so we can see where
// data is being populated.
X.CalculateTotalGraphingData();
// ought to change this to use variables n,v,T !
Graph[0].DrawSurface("n_n+n_ion",
DATA_HEIGHT,(real *)(&(X.X[0].n)),
IONISE_COLOUR,(real *)(&(X.X[0].Temp.y)),
false,
GRAPH_TOTAL_N, &X);
Graph[1].DrawSurface("[n_s v_s m_s]/[n_s m_s]",
VELOCITY_HEIGHT,(real *)(&(X.X[0].v)),
VELOCITY_COLOUR,(real *)(&(X.X[0].v)),
false, // no inner mesh display
GRAPH_TOTAL_V, &X);
Graph[2].DrawSurface("n_n+n_ion",
DATA_HEIGHT,(real *)(&(X.X[0].n)),
VELOCITY_COLOUR,(real *)(&(X.X[0].v)),
false,
GRAPH_TOTAL_N_II, &X);
Graph[3].TickRescaling = 1.0/kB;
Graph[3].DrawSurface("[n_s T_s]/[n_s]",
DATA_HEIGHT,(real *)(&(X.X[0].T)),
SEGUE_COLOUR,(real *)(&(X.X[0].T)),
false,
GRAPH_TOTAL_T, &X);
Graph[3].TickRescaling = 1.0;
break;
};
// Graph 2, in case of species graphs:
char buff[256];
sprintf(buff, "%4.3f ns", evaltime*1.0e9);
switch(iGraphsFlag) {
case SPECIES_NEUTRAL:
case SPECIES_ION:
case SPECIES_ELEC:
Graph[2].SetEyePlan(GlobalPlanEye);
Graph[2].boolDisplayMeshWireframe = true;
Graph[2].boolClearZBufferBeforeWireframe = true;
Graph[2].boolDisplayMainMesh = true;
Graph[2].boolDisplayInnerMesh = false;
Graph[2].boolDisplayScales = false;
if (GlobalColoursPlanView == 0)
{
// nothing
Graph[2].mhTech = Graph[2].mFX->GetTechniqueByName("MeshTech");
Graph[2].SetDataWithColour(X,FLAG_COLOUR_MESH,FLAG_FLAT_MESH,0,0,
GRAPH_FLAT_WIRE_MESH);
Graph[2].Render(buff, GlobalRenderLabels, &X);
} else {
// Tell SDWC not to mess with colourmax if it's a flat mesh.
X.Reset_vertex_nvT(SPECIES_ION);
int offset_v_ion = (real *)(&(X.X[0].v)) -(real *)(&(X.X[0]));
int offset_T_ion = (real *)(&(X.X[0].T)) -(real *)(&(X.X[0]));
if (GlobalColoursPlanView == 1)
{
// velocity
Graph[2].mhTech = Graph[2].mFX->GetTechniqueByName("VelociTech");
Graph[2].colourmax = Graph[0].colourmax; // match colours
Graph[2].SetDataWithColour(X,FLAG_VELOCITY_COLOUR,FLAG_FLAT_MESH,offset_v_ion,offset_v_ion,
GRAPH_FLAT_WIRE_MESH);
Graph[2].Render(buff, GlobalRenderLabels, &X);
} else {
// temperature
Graph[2].mhTech = Graph[2].mFX->GetTechniqueByName("SegueTech");
// SegueVS should take maximum as a parameter;
// at least for colours we should prefer an absolute scale for T
// Is it ever used for anything else? Not so far? eps?
Graph[2].SetDataWithColour(X,FLAG_SEGUE_COLOUR,FLAG_FLAT_MESH,offset_T_ion, offset_T_ion,
GRAPH_FLAT_WIRE_MESH);
Graph[2].Render(buff, GlobalRenderLabels, &X);
};
};
break;
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
unsigned int old_cw;
// with X86 defined 0 in config.h, this will do nothing:
// fpu_fix_start(&old_cw);
char szInitialFilenameAvi[512];
MSG msg;
HDC hdc;
// HACCEL hAccelTable;
real x,y,temp;
int i,j;
float a1,a2,a3,a4;
HWND hwndConsole;
FILE * fp;
extern char Functionalfilename[1024];
hInst = hInstance;
cw = 0;
_controlfp_s(&cw, 0, 0); // zeroes out control word.
_controlfp_s(0, _EM_INEXACT | _EM_UNDERFLOW, _MCW_EM);
// hide only "inexact" and underflow FP exception
// Why underflow?
AllocConsole(); // for development purposes
freopen( "CONOUT$", "wb", stdout );
SetConsoleTitle("2D 1/16 annulus DPF simulation");
Sleep(40);
hwndConsole = FindWindow(NULL,"2D 1/16 annulus DPF simulation");
MoveWindow(hwndConsole,0,0,SCREEN_WIDTH-VIDEO_WIDTH-10,SCREEN_HEIGHT-30,TRUE);
h = TIMESTEP;
evaltime = 0.0; // gets updated before advance
memset(Historic_powermax, 0,200*sizeof(int));
memset(Historic_powermin, 0,200*sizeof(int));
ZeroMemory(Historic_max,100*HISTORY*sizeof(float));
ZeroMemory(Historic_min,100*HISTORY*sizeof(float));
Vector2 x1,x2,x3,r1,r2,r3;
x1.x = 0.0; x1.y = 0.0;
x2.x = 1.0; x2.y = 1.0;
x3.x = 2.0; x3.y = 0.0;
r1.x = 0.0; r1.y = 0.0;
r2.x = 0.0; r2.y = 1.0;
r3.x = 1.0; r3.y = 0.0;
// so far, appears to work
real area = CalculateTriangleIntersectionArea(x1, x2, x3, r1, r2, r3);
area = CalculateTriangleIntersectionArea(r1, r2, r3,x1, x2, x3);
// what would really give confidence would be if we finish our columns method
// and verify that they give the same answers.
GlobalStepsCounter = 0; steps_remaining = 0;
// Note : atanf gives values in 1st and 4th quadrant - but remember atan2
// Find next available filename for functional output:
int filetag = 0;
do {
filetag++;
sprintf(Functionalfilename,FUNCTIONALFILE_START "%03d.txt",filetag);
} while ((_access( Functionalfilename, 0 )) != -1 );
//if( (_access( "ACCESS.C", 0 )) != -1 )
//{
// printf( "File ACCESS.C exists\n" );
// /* Check for write permission */
// if( (_access( "ACCESS.C", 2 )) != -1 )
// printf( "File ACCESS.C has write permission\n" );
//}
printf("\n\nopening %s \n",Functionalfilename);
fp = fopen(Functionalfilename,"w");
if (fp == 0) {
printf("error with %s \n",Functionalfilename);
getch();
} else {
printf("opened %s \n",Functionalfilename);
};
fprintf(fp,"GSC evaltime Area neut.N ion.N elec.N neut.r ion.r elec.r SDneut.r SDion.r SDelec.r "
" neut.vr neut.vth neut.vz ion.vr ion.vth ion.vz elec.vr elec.vth elec.vz neut.heat ion.heat elec.heat neut.T ion.T elec.T "
" neut.mnvv/3 ion.mnvv/3 elec.mnvv/3 elec.force(vxB)r within3.6 elec.Bth EE BB Heatings and dT changes - see code \n");
fclose(fp);
report_time(0);
printf("Initialising meshes...\n");
if (bScrewPinch) {
//X1.InitialiseScrewPinch();
//X2.InitialiseScrewPinch();
} else {
X1.Initialise(1); // Set evaltime first
X2.Initialise(2);
}
pX = &X1;
pXnew = &X2;
// A,phi seeding relies on both system values
GlobalBothSystemsInUse = 0;
//if (SYSTEM_INITIALISE_VS_LOAD == LOAD)
//{
// if (pX->Load(AUTO_DATA_LOAD_FILENAME))
// {
// printf("File error auto-loading %s",AUTO_DATA_LOAD_FILENAME);
// getch();
// PostQuitMessage(2000);
// } else {
// pXnew->Load(AUTO_DATA_LOAD_FILENAME);
// // lazy way! Do differently.
// };
//};
printf(report_time(1));
printf("\n");
report_time(0);
// Window setup
LoadString(hInstance, IDS_APP_TITLE, szTitle, 1024);
LoadString(hInstance, IDC_F2DVALS, szWindowClass, 1024);
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_F2DVALS));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
RegisterClassEx(&wcex);
printf("SCREEN_WIDTH %d VIDEO_WIDTH %d VIDEO_HEIGHT %d \n",
SCREEN_WIDTH,VIDEO_WIDTH,VIDEO_HEIGHT);
hWnd = CreateWindowEx(NULL,szWindowClass, szTitle, WS_BORDER | WS_POPUP,
SCREEN_WIDTH-VIDEO_WIDTH-5, 0, VIDEO_WIDTH+5, VIDEO_HEIGHT+20, NULL, NULL, hInstance, NULL);
if (!hWnd) return 3000;
// This fails, although dimensions are sensible.
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
xzscale = 2.0/0.1; // very zoomed in. Now what?
DXChk(Direct3D.Initialise(hWnd,hInstance,VIDEO_WIDTH,VIDEO_HEIGHT));
// With Field Of View = PI/4 used this:
GlobalEye.x = 0.0f;
GlobalEye.y = 12.4f; //7.2f;
GlobalEye.z = -18.0f+2.5*xzscale;//DEVICE_RADIUS_INSULATOR_OUTER*xzscale;//-17.8f+
GlobalLookat.x = 0.4f;
GlobalLookat.y = 3.0f;
GlobalLookat.z = DEVICE_RADIUS_INITIAL_FILAMENT_CENTRE*xzscale;
GlobalPlanEye.x = 0.0f;
GlobalPlanEye.y = 35.0f;
GlobalPlanEye.z = (3.44+4.1)*0.5*xzscale;
GlobalPlanEye2.x = -0.1f;
GlobalPlanEye2.y = 19.5f;
GlobalPlanEye2.z = 2.8*xzscale;
GlobalPlanLookat.x = GlobalPlanEye.x;
GlobalPlanLookat.y = 0.0f;
GlobalPlanLookat.z = GlobalPlanEye.z+0.0001;
GlobalPlanLookat2.x = GlobalPlanEye2.x;
GlobalPlanLookat2.y = 0.0f;
GlobalPlanLookat2.z = GlobalPlanEye2.z+0.0001;
if (DXChk( Graph[3].InitialiseWithoutBuffers(GRAPH_WIDTH,GRAPH_HEIGHT,GRAPH_WIDTH,GRAPH_HEIGHT,GlobalEye,GlobalLookat) ) +
DXChk( Graph[3].InitialiseBuffers(X1) )
)
{ PostQuitMessage(203); };
if (DXChk( Graph[2].InitialiseWithoutBuffers(GRAPH_WIDTH,0,GRAPH_WIDTH,GRAPH_HEIGHT,GlobalPlanEye,GlobalPlanLookat) ) +
DXChk( Graph[2].InitialiseBuffers(X1) )
)
{ PostQuitMessage(202); };
if (DXChk( Graph[1].InitialiseWithoutBuffers(0,GRAPH_HEIGHT,GRAPH_WIDTH,GRAPH_HEIGHT,GlobalEye,GlobalLookat) ) +
DXChk( Graph[1].InitialiseBuffers(X1) )
)
{ PostQuitMessage(201); };
if (DXChk( Graph[0].InitialiseWithoutBuffers(0,0,GRAPH_WIDTH,GRAPH_HEIGHT,GlobalEye, GlobalLookat) ) +
DXChk( Graph[0].InitialiseBuffers(X1) )
)
{ PostQuitMessage(200); };
if (DXChk( Graph[4].InitialiseWithoutBuffers(0,0,GRAPH_WIDTH*2,GRAPH_HEIGHT*2,GlobalPlanEye,GlobalPlanLookat) ) +
DXChk( Graph[4].InitialiseBuffers(X1) )
)
{ PostQuitMessage(204); };
Graph[4].SetEyePlan(GlobalPlanEye);
Graph[4].boolDisplayMeshWireframe = true;
Graph[4].boolClearZBufferBeforeWireframe = true;
Graph[4].boolDisplayMainMesh = true;
Graph[4].boolDisplayInnerMesh = false;
Graph[4].boolDisplayScales = false;
// if (DXChk( Graph[4].InitialiseWithoutBuffers(0,0,2*GRAPH_WIDTH,
// 2*GRAPH_HEIGHT,GlobalPlanEye2,GlobalPlanLookat2) ) +
// DXChk( Graph[4].InitialiseBuffers(X1) )
// )
// { PostQuitMessage(208); };
// ?? -- for doing 1 graph in whole space. ?!
Graph[0].bDisplayTimestamp = false;
Graph[1].bDisplayTimestamp = false;
Graph[2].bDisplayTimestamp = true;
Graph[3].bDisplayTimestamp = false;
Direct3D.pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &p_backbuffer_surface);
if(DXChk(p_backbuffer_surface->GetDC(&surfdc),1000))
MessageBox(NULL,"GetDC failed","oh dear",MB_OK);
surfbit = CreateCompatibleBitmap(surfdc,VIDEO_WIDTH,VIDEO_HEIGHT); // EXTRAHEIGHT = 90
SelectObject(surfdc,surfbit);
dibdc = CreateCompatibleDC(surfdc);
long VideoWidth = VIDEO_WIDTH;
long VideoHeight = VIDEO_HEIGHT;
// pasted here just to set up format:
bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFO);
bitmapinfo.bmiHeader.biWidth = VideoWidth;
bitmapinfo.bmiHeader.biHeight = VideoHeight;
bitmapinfo.bmiHeader.biPlanes = 1;
bitmapinfo.bmiHeader.biBitCount = 24;
bitmapinfo.bmiHeader.biCompression = BI_RGB; // uncompressed
bitmapinfo.bmiHeader.biSizeImage = bitmapinfo.bmiHeader.biHeight;
bitmapinfo.bmiHeader.biXPelsPerMeter = 3000;
bitmapinfo.bmiHeader.biYPelsPerMeter = 3000;
bitmapinfo.bmiHeader.biClrUsed = 0;
bitmapinfo.bmiHeader.biClrImportant = 0;
bitmapinfo.bmiColors->rgbBlue = 0;
bitmapinfo.bmiColors->rgbRed = 0;
bitmapinfo.bmiColors->rgbGreen = 0;
bitmapinfo.bmiColors->rgbReserved = 0;
// dimension DIB and set up pointer to bits
dib = CreateDIBSection(dibdc, &bitmapinfo, DIB_RGB_COLORS, &lpvBits, NULL, 0);
SelectObject(dibdc, dib);
BitBlt(dibdc,0,0,VIDEO_WIDTH,VIDEO_HEIGHT,surfdc,0,0,SRCCOPY);
for (i = 0 ; i < NUMAVI; i++)
{
sprintf(szInitialFilenameAvi,"%s%s_%s",FOLDER,szAvi[i],INITIALAVI);
hAvi[i] = CreateAvi(szInitialFilenameAvi, AVIFRAMEPERIOD, NULL);
};
// 1000/25 = 40
ZeroMemory(&opts,sizeof(opts));
opts.fccHandler=mmioFOURCC('D','I','B',' ');//('d','i','v','x');
opts.dwFlags = 8;
for (i = 0 ; i < NUMAVI; i++)