GOAT (Geometrical optics application tool) 0.1
Loading...
Searching...
No Matches
superarray.h
Go to the documentation of this file.
1#pragma once
2#include <stdlib.h>
3#include <fstream>
4#include "vector.h"
5#include "resutil.h"
6#include "objectshape.h"
7#include "error.h"
8#include <vector>
9#include "gridentry.h"
10
11// #define INDEX_TYPE long long int
12namespace GOAT
13{
14 namespace raytracing
15 {
16 typedef long long int INDEX_TYPE;
25 template <class T> class SuperArray
26 {
27 public :
35 SuperArray(double r0, INDEX_TYPE nx, INDEX_TYPE ny, INDEX_TYPE nz, const int typ=IN_OBJECT);
36 SuperArray(double r0, INDEX_TYPE nx, INDEX_TYPE ny, INDEX_TYPE nz, std::vector<ObjectShape*>Obj, int numObjs, const bool isAbsolute=false, const int typ=IN_OBJECT);
38 {
40
41 type = S.type;
42 ywerte = S.ywerte;
43 zwerte = S.zwerte;
44 numObjs = S.numObjs;
45 Obj = S.Obj;
46 G = S.G;
47 K = S.K;
48 Pul = S.Pul;
49 n = S.n;
50 nges = S.nges;
51 d = S.d;
52 r0 = S.r0;
53 isequal = S.isequal;
55 pc = S.pc;
56 H = S.H;
57 R = S.R;
58 }
60
65 void copy (const SuperArray &S);
72 void add (const SuperArray& S);
79 void sub (const SuperArray& S);
80 // friend double sumabs (const SuperArray &S); ///< The absolute values of the cell contents are summed up
81 // friend double sumabs2 (const SuperArray &S); ///< The squared absolute values of the cell contents are summed up
86 // friend double abs2sum (const SuperArray &S);
96 bool addInc(std::vector<ObjectShape*>Obj,int numObj, const bool isAbsolute=false); // numObjs Einschluesse hinzufuegen
97 // isAbsolute=true => Orts-/Groessenangaben in absoluten Koordinaten
106 bool addInc (ObjectShape *E,const bool isAbsolute=false); // Einschluss hinzufuegen (isAbsolute s.o.)
107 void removeObject(int i);
109 void setActive(int i);
110 void setInactive(int i);
113 bool inObject (maths::Vector<INDEX_TYPE> Pi, int i);
114 bool inObject (INDEX_TYPE ix, INDEX_TYPE iy, INDEX_TYPE iz, int i);
121 T& operator () (int i, INDEX_TYPE ix, INDEX_TYPE iy, INDEX_TYPE iz, bool isObjectCoordinate=true);
126
127 void makeReal ();
128 void fill(const T &x);
130 void clear();
131 void reinit(double r0, INDEX_TYPE n);
132 void reinit(double r0, INDEX_TYPE nx, INDEX_TYPE ny, INDEX_TYPE nz);
133
134 void allockugel();
135
143 T kugelwert(int ix, int iy, int iz);
144
145 int Error;
146 std::vector<ObjectShape*> Obj;
148 int type;
149 std::vector<int> ywerte;
150 std::vector<std::vector<int> > zwerte;
151 std::vector <std::vector <std::vector <std::vector <T> > > > G;
152 std::vector < std::vector < std::vector <T> > > K;
154 std::vector<maths::Vector<INDEX_TYPE>> Pul;
155 std::vector<maths::Vector<INDEX_TYPE>> n;
157
159 double r0;
161 bool iscleared = true;
162 T pc;
164 bool write(std::string fname);
165 bool read(std::string fname);
166
169 // Ensure the parameter is valid and reinitialize the grid with the given number of cells per direction
170 if (no > 0) {
171 reinit(r0, no, no, no);
172 }
173 else {
174 Error = INVALID_PARAMETER; // Set an error code for invalid input
175 }
176 }
177
178
180 };
181
182 /* Specialization of Superarray for use together with std::vector<gridEntry> */
184 template <class T> T dummy;
185
186
187 /*------------------------- IMPLEMENTATION --------------------------------------*/
188
190
191 template <class T> SuperArray<T>::SuperArray()
192 {
193 H = maths::unity();
194 R = maths::unity();
196 numObjs = 0;
197 isequal = false;
198
199 type = IN_HOST;
200 }
201
202 template <class T> SuperArray<T>::SuperArray(double r0, INDEX_TYPE nx, INDEX_TYPE ny, INDEX_TYPE nz, const int typ)
203 {
205 double b = 2.0 * r0;
206 isequal = false;
207 numObjs = 0;
208 this->r0 = r0;
209
210
211
212 nges = maths::Vector<INDEX_TYPE>(nx, ny, nz);
213 d = maths::Vector<double>(b / (double)nx, b / (double)ny, b / (double)nz);
214 iscleared = true;
215 type = typ;
216 if (type & IN_HOST)
217 allockugel();
218 }
219
220 template <class T> SuperArray<T>::SuperArray(double r0, INDEX_TYPE nx, INDEX_TYPE ny, INDEX_TYPE nz, std::vector<ObjectShape*> Obj, int numObjs, const bool isAbsolute, const int typ)
221 {
223 double b = 2.0 * r0;
224 isequal = isAbsolute;
225 this->numObjs = 0;
226 this->r0 = r0;
227 nges = maths::Vector<INDEX_TYPE>(nx, ny, nz);
228 type = typ;
229 d = maths::Vector<double>(b / nx, b / ny, b / nz);
230 iscleared = true;
231 if (type & IN_HOST)
232 {
233 allockugel();
234 }
235 addInc(Obj, numObjs, isAbsolute);
236 }
237
238
239 template <class T> bool SuperArray<T>::addInc(std::vector<ObjectShape*> Obj, int numObjs, const bool isAbsolute)
240 {
241 bool ok = true;
242 for (int i = 0; (i < numObjs)/* && (canCalc)*/ && (ok); i++) ok = addInc(Obj[i], isAbsolute);
243 return ok;
244 }
245
246 template<class T>
247 inline void SuperArray<T>::setInactive(int i)
248 {
249 removeObject(i);
250 }
251
252 template<class T>
254 {
255 if (G[i].size() == 0) G[i].resize(n[i][0] + 1);
256 for (INDEX_TYPE ix = 0; ix < n[i][0] + 1; ix++)
257 {
258 G[i][ix].resize(n[i][1] + 1);
259
260 for (INDEX_TYPE iy = 0; iy < n[i][1] + 1; iy++)
261 {
262 G[i][ix][iy].resize(n[i][2] + 1);
263 }
264 }
265 }
266
268 {
271 h = H * P + maths::Vector<double>(r0, r0, r0);
272 pi = maths::Vector<INDEX_TYPE>((INDEX_TYPE)floor(h[0] / d[0]), (INDEX_TYPE)floor(h[1] / d[1]), (INDEX_TYPE)floor(h[2] / d[2]));
273 /*
274 if (type & IN_HOST) //????????
275 {
276 pi = ph;
277 }
278 else
279 {
280 pi = ph;
281 }*/
282 return pi;
283 }
284
288 template <class T> void SuperArray<T>::arrangeGrids()
289 {
290 clear();
291 maths::Vector<INDEX_TYPE> pul, por, N, hn;
293 O = maths::Vector<double>(-r0, -r0, -r0);
294 d = 2.0 * r0 * maths::Vector<double>(1.0 / (double)nges[0], 1.0 / (double)nges[1], 1.0 / (double)nges[2]);
295 std::cerr << "[arrangeGrids] d=" << d << "\tr0=" << r0 << "\tnges=(" << nges[0] << "," << nges[1] << "," << nges[2] << ")" << std::endl;
296
297 for (int i = 0; i < numObjs; i++)
298 {
299 Obj[i]->initQuad();
300; h = ceil(ediv(Obj[i]->por, d)) - floor(ediv(Obj[i]->pul, d));
301 hn = maths::Vector<INDEX_TYPE>((INDEX_TYPE)h[0] + 1, (INDEX_TYPE)h[1] + 1, (INDEX_TYPE)h[2] + 1); // Gr��e des 3D-Gitters in die drei Koordinatenrichtungen
302 n.push_back(hn);
303
304 h = floor(ediv(Obj[i]->pul + maths::Vector<double>(r0, r0, r0), d));
305 Pul.push_back(maths::Vector<INDEX_TYPE>((INDEX_TYPE)h[0], (INDEX_TYPE)h[1], (INDEX_TYPE)h[2]));
306
307 if (Obj[i]->isActive()) // Ist der Einschluss �berhaupt inelastisch aktiv ?
308 {
309 G[i].resize(n[i][0] + 1);
310 for (INDEX_TYPE ix = 0; ix < n[i][0] + 1; ix++)
311 {
312 G[i][ix].resize(n[i][1] + 1);
313
314 for (INDEX_TYPE iy = 0; iy < n[i][1] + 1; iy++)
315 {
316 G[i][ix][iy].resize(n[i][2] + 1);
317 }
318 }
319 }
320 }
321 }
322
323 template <class T> bool SuperArray<T>::addInc(ObjectShape* E, const bool isAbsolute)
324 {
325
326 //SysMemInfo smi;
327 //MemInfo mi;
328 long int allocMem;
329 maths::Vector<INDEX_TYPE> pul, por, N, hn;
331 O = maths::Vector<double>(-r0, -r0, -r0);
332 double b = 2.0 * r0;
333 d = maths::Vector<double>(b / (double)(nges[0] - 1), b / (double)(nges[1] - 1), b / (double)(nges[2] - 1));
334 // h = ceil(ediv(E->por, d)) - floor(ediv(E->pul, d));
335 h = ceil(ediv(E->por-E->pul, d)) ;
336
337 hn = maths::Vector<INDEX_TYPE>((INDEX_TYPE)h[0]+1, (INDEX_TYPE)h[1]+1, (INDEX_TYPE)h[2]+1); // Gr��e des 3D-Gitters in die drei Koordinatenrichtungen
338
339 /* Berechne den tats�chlichen Bedarf */
340 allocMem = sizeof(T***) + 2 * sizeof(maths::Vector<int>) + sizeof(ObjectShape*)
341 + hn[0] * sizeof(T**)
342 + hn[0] * hn[1] * sizeof(T*)
343 + hn[0] * hn[1] * hn[2] * sizeof(T);
344
345 {
346 if (numObjs < 1) // Es ist der erste Einschluss der hinzugef�gt wird
347 {
348 G.resize(1);
349 G.shrink_to_fit();
350 }
351 else
352 {
353 G.resize(numObjs + 1);
354 G.shrink_to_fit();
355 }
356 }
357
358 n.push_back(hn);
359 Obj.push_back(E);
360 h = floor(ediv(Obj[numObjs]->pul + maths::Vector<double>(r0, r0, r0), d));
361 Pul.push_back(maths::Vector<INDEX_TYPE>((INDEX_TYPE)h[0], (INDEX_TYPE)h[1], (INDEX_TYPE)h[2]));
362
363 if (E->isActive()) // Ist der Einschluss �berhaupt inelastisch aktiv ?
364 {
365// std::cout << "n[" << numObjs << "]=" << n[numObjs] << std::endl;
366 G[numObjs].resize(n[numObjs][0] + 1);
367
368 for (INDEX_TYPE ix = 0; ix < n[numObjs][0] + 1; ix++)
369 {
370 G[numObjs][ix].resize(n[numObjs][1] + 1);
371
372 for (INDEX_TYPE iy = 0; iy < n[numObjs][1] + 1; iy++)
373 {
374 G[numObjs][ix][iy].resize(n[numObjs][2] + 1) ;
375 }
376 }
377 }
378
379
380 int i = 0;
381 numObjs++;
382 iscleared = false;
383 return true;
384 }
385
386 template<class T>
388 {
389
390 if (G[i].size() > 0)
391 {
392 for (int ix = n[i][0]; ix >= 0; ix--)
393 {
394 for (int iy = n[i][1]; iy >= 0; iy--)
395 G[i][ix][iy].clear();
396 G[i][ix].clear();
397 } // for ix
398 G[i].clear();
399 } // if (G[i]!=NULL)
400 }
401 template<class T>
403 {
404 for (int i = 0; i < Obj.size(); i++)
405 {
406 removeObject(i);
407 }
408
409 Obj.clear();
410 Obj.shrink_to_fit();
411 numObjs = 0;
412
413
414 }
415
416
417 template <class T> bool SuperArray<T>::inObject(maths::Vector<double> P, int i) // da muss noch was gemacht werden
418 {
419 return Obj[i]->isInside(P);
420 }
421
422 template <class T> bool SuperArray<T>::inObject(maths::Vector<INDEX_TYPE> Pi, int i)
423 {
424 return (Obj[i]->isInside(emult(Pi, d)));
425 }
426
427 template <class T> bool SuperArray<T>::inObject(INDEX_TYPE ix, INDEX_TYPE iy, INDEX_TYPE iz, int i)
428 {
429 return (Obj[i]->isInside(emult(maths::Vector<double>(ix, iy, iz), d)));
430 }
431
433 {
435 INDEX_TYPE i = 0;
436 bool found = false;
437 if (type == IN_OBJECT)
438 {
439 do
440 {
441 found = inObject(ix, iy, iz, i);
442 i++;
443 } while ((i < numObjs) && (!found));
444 i--;
445 if (!found)
446 {
448 return dummy;
449 }
450 else
451 {
452 Pi = Pi - Pul[i];
453 Pi = kugelindex(Pi);
454 if (Error == NO_ERRORS)
455 return G[i][Pi[0]][Pi[1]][Pi[2]];
456 else
457 {
459 return dummy;
460 }
461 }
462 }
463 else
464 {
465 Pi = kugelindex(Pi);
466 if (Error == NO_ERRORS)
467 return K[Pi[0]][Pi[1]][Pi[2]];
468 else
469 {
471 return dummy;
472 }
473 }
474 }
475
477 {
478 // dummy = maths::Vector<std::complex<double> >(0.0, 0.0, 0.0);
479
480 if (type == IN_OBJECT)
481 {
482 int i = 0;
483 bool found = false;
484 do
485 {
486 found = inObject(Pi, i);
487 i++;
488 } while ((i < numObjs) && (!found));
489 i--;
490
491 if (!found)
492 {
494 return dummy;
495 }
496 else
497 {
498 Pi = Pi - Pul[i];
499 Pi = kugelindex(Pi);
500 if (Error == NO_ERRORS)
501 return G[i][Pi[0]][Pi[1]][Pi[2]];
502 else
503 {
505 return dummy;
506 }
507 }
508 }
509 else
510 {
511 Pi = kugelindex(Pi);
512 if (Error == NO_ERRORS)
513 return K[Pi[0]][Pi[1]][Pi[2]];
514 else
515 {
517 return dummy;
518 }
519 }
520 }
521
522
523 template <class T> T& SuperArray<T>::operator () (int i, INDEX_TYPE ix, INDEX_TYPE iy, INDEX_TYPE iz, bool isEinKoord)
524 {
526 if (type == IN_OBJECT)
527 {
528 if (G[i].size() == 0)
529 {
531 return dummy;
532 }
533 if (!isEinKoord) Pi = Pi - Pul[i];
534 return G[i][Pi[0]][Pi[1]][Pi[2]];
535 }
536 else
537 {
538 Pi = kugelindex(Pi);
539 if (Error == NO_ERRORS)
540 return K[Pi[0]][Pi[1]][Pi[2]];
541 else
542 {
544 return dummy;
545 }
546 }
547 }
548
549
551 {
552 // T dummy;
553 if (type == IN_OBJECT)
554 {
555 Pi = Pi - Pul[i];
556 if (G[i].size() == 0) { Error = NOT_FOUND; return dummy; }
557 if (Pi[0] < 0) { Error = NOT_FOUND; return dummy; }//maths::Vector<std::complex<double> > (0,0,0);
558 if (Pi[1] < 0) { Error = NOT_FOUND; return dummy; } //maths::Vector<std::complex<double> > (0,0,0);
559 if (Pi[2] < 0) {
560 // std::cout << "Pi[2]=" << Pi[2] << std::endl;
561 Error = NOT_FOUND; return dummy; } // maths::Vector<std::complex<double> > (0,0,0);
562 if (Pi[0] >= n[i][0])
563 {
564 // std::cout << "PROBLEM: Pi[0]=" << Pi[0] << "\tn[i][0]=" << n[i][0] << std::endl;
566 return dummy; //maths::Vector<std::complex<double> > (0,0,0);
567 }
568
569 if (Pi[1] >= n[i][1])
570 {
571 // std::cout << "PROBLEM: Pi[1]=" << Pi[1] << "\tn[i][1]=" << n[i][1] << std::endl;
573 return dummy; //maths::Vector<std::complex<double> > (0,0,0);
574 }
575
576 if (Pi[2] >= n[i][2])
577 {
578 // std::cout << "PROBLEM: Pi[1]=" << Pi[2] << "\tn[i][2]=" << n[i][2] << std::endl;
580 return dummy;
581 }
582
584 return G[i][Pi[0]][Pi[1]][Pi[2]];
585 }
586 else
587 {
588 Pi = kugelindex(Pi);
589 if (Error == NO_ERRORS)
590 return K[Pi[0]][Pi[1]][Pi[2]];
591 else
592 {
593 Error = NOT_FOUND; return dummy;
594 }
595 }
596 }
597
599 {
600 int i;
603 h = H * P - maths::Vector<double>(-r0, -r0, -r0);
604 dummy = maths::Vector<std::complex<double> >(0.0, 0.0, 0.0);
605 for (i = 0; i < 3; i++)
606 Pi[i] = h[i] / d[i];
607
608 if (type == IN_OBJECT)
609 {
610 bool found = false;
611 i = 0;
612 do
613 {
614 found = inObject(Pi, i);
615 i++;
616 } while ((i < numObjs) && (!found));
617 i--;
618 // if (!found) return maths::Vector<std::complex<double> > (INF,INF,INF);
619 if (!found)
620 {
622 return dummy;
623 }
624 else
625 {
626 if (G[i] == NULL)
627 {
629 return dummy;
630 }
631 Pi = Pi - Pul[i];
632 std::cout << "PI:" << Pi << std::endl;
633 return G[i][Pi[0]][Pi[1]][Pi[2]];
634 }
635 }
636 else
637 {
638 Pi = kugelindex(Pi);
639 if (Error == NO_ERRORS)
640 return K[Pi[0]][Pi[1]][Pi[2]];
641 else
642 {
644 return dummy;
645 }
646 }
647 }
648
650 {
653 h = H * P - maths::Vector<double>(-r0, -r0, -r0);
654 T dummy;
655 // dummy = maths::Vector<std::complex<double> >(0.0, 0.0, 0.0);
657 for (int j = 0; j < 3; j++)
658 Pi[j] = h[j] / d[j];
659
660 if (type == IN_OBJECT)
661 {
662 if (G[i] == NULL)
663 {
665 return dummy;
666 }
667 Pi = Pi - Pul[i];
668 return G[i][Pi[0]][Pi[1]][Pi[2]];
669 }
670 else
671 {
672 Pi = kugelindex(Pi);
673 if (Error == NO_ERRORS)
674 return K[Pi[0]][Pi[1]][Pi[2]];
675 else
676 {
678 return dummy;
679 }
680 }
681 }
682
683
684 template <class T> void SuperArray<T>::clear()
685 {
686 int anzx, anzx2;
687 anzx = nges[0];
688 anzx2 = nges[0] / 2;
689 // if (!iscleared)
690 if (type == IN_OBJECT)
691 {
692 if (numObjs > 0)
693 {
694 for (int i = numObjs - 1; i >= 0; i--)
695 {
696 if (G[i].size()>0)
697 {
698 for (int ix = n[i][0]; ix >= 0; ix--)
699 {
700 for (int iy = n[i][1]; iy >= 0; iy--)
701 G[i][ix][iy].clear();
702 G[i][ix].clear();
703 } // for ix
704 G[i].clear();
705 } // if (G[i]!=NULL)
706 } // for i
707 n.clear();
708 Pul.clear();
709 /* if (Obj != NULL)
710 free(Obj);
711 numObjs = 0;
712 Obj = NULL;*/
713 iscleared = true;
714
715 }
716 }
717 else
718 {
719 if (K.size()>0)
720 {
721 for (int k = 0; k < anzx2; k++)
722 {
723 /*for (int l = 0; l < ywerte[k]; l++)
724 {
725 delete[] K[anzx2 - 1 - k][ywerte[k] + l];
726 delete[] K[anzx2 + k][ywerte[k] + l];
727 delete[] K[anzx2 - 1 - k][ywerte[k] - 1 - l];
728 delete[] K[anzx2 + k][ywerte[k] - 1 - l];
729 }
730 */
731 //delete[] K[anzx2 - 1 - k];
732 //delete[] K[anzx2 + k];
733 zwerte[k].clear();
734 }
735
736 ywerte.clear();
737 zwerte.clear();
738
739 /* if (numObjs > 0)
740 free(Obj);*/
741 }
742
743 // numObjs = 0;
744 iscleared = true;
745 }
746 }
747
748 template<class T>
750 {
751 reinit(r0, n, n, n);
752 }
753
754 template <class T>
755 void SuperArray<T>::reinit(double new_r0,
756 INDEX_TYPE nx,
757 INDEX_TYPE ny,
758 INDEX_TYPE nz
759 )
760 {
761 this->nges = maths::Vector<INDEX_TYPE>(nx, ny, nz);
762 // 2. Parameter übernehmen
763 this->r0 = new_r0;
764 // 1. Alte Daten freigeben
765 this->arrangeGrids();
766
767
768
769 // 4. Falls IN_HOST, das Kugel-Gitter (Host-Grid) neu allokieren
770 if (this->type & IN_HOST)
771 {
772 this->allockugel();
773 }
774 }
775
776
777 template <class T> void SuperArray<T>::copy(const SuperArray<T>& S) // MUSS DRINGEND GE�NDERT WERDEN !
778 {
779 clear();
780 addInc(S.Obj, S.numObjs);
781 for (int i = 0; i < numObjs; i++)
782 if (Obj[i]->isActive())
783 for (INDEX_TYPE ix = 0; ix < n[i][0]; ix++)
784 for (INDEX_TYPE iy = 0; iy < n[i][1]; iy++)
785 for (INDEX_TYPE iz = 0; iz < n[i][2]; iz++)
786 G[i][ix][iy][iz] = S.G[i][ix][iy][iz];
787 K = S.K;
788 Pul = S.Pul;
789 n = S.n;
790 nges = S.nges;
791 d = S.d;
792 r0 = S.r0;
793 isequal = S.isequal;
795 pc = S.pc;
796 H = S.H;
797 R = S.R;
798
799 }
800
802 {
803 int i = 0;
804 int anzx, anzx2;
805
806
807 if (this == &S) return *this;
808 clear();
809 if (this->numObjs > 0)
810 {
811 /* for (int i = 0; i < this->numObjs; i++)
812 delete this->Obj[i];*/
813 this->Obj.clear();
814 this->Obj.shrink_to_fit();
815 this->numObjs = 0;
816 }
817 r0 = S.r0;
818 d = S.d;
819 nges = S.nges;
820 type = S.type;
821
822 anzx = nges[0]; anzx2 = nges[0] / 2;
823
824 if (type == IN_OBJECT)
825 {
826 isequal = true; addInc(S.Obj, S.numObjs, true);
827 isequal = true;
828 G = S.G;
829 /* if (S.numObjs != 0)
830 do
831 {
832 for (int ix = 0; ix < n[i][0]; ix++)
833 for (int iy = 0; iy < n[i][1]; iy++)
834 for (int iz = 0; iz < n[i][2]; iz++)
835 G[i][ix][iy][iz] = S.G[i][ix][iy][iz];
836 i++;
837 } while (i < S.numObjs);*/
838 isequal = false;
839 }
840 else
841 {
842 allockugel();
843 isequal = true; addInc(S.Obj, S.numObjs, true);
844 isequal = true;
845
846 for (int k = 0; k < anzx2; k++)
847 {
848 ywerte[k] = S.ywerte[k];
849 for (int l = 0; l < S.ywerte[k]; l++)
850 {
851 zwerte[k][l] = S.zwerte[k][l];
852 for (int m = 0; m < S.zwerte[k][l]; m++)
853 {
854 K[anzx2 - 1 - k][ywerte[k] - 1 - l][m] = S.K[anzx2 - 1 - k][ywerte[k] - 1 - l][m];
855 K[anzx2 + k][ywerte[k] - 1 - l][m] = S.K[anzx2 + k][ywerte[k] - 1 - l][m];
856 K[anzx2 - 1 - k][ywerte[k] + l][m] = S.K[anzx2 - 1 - k][ywerte[k] + l][m];
857 K[anzx2 + k][ywerte[k] + l][m] = S.K[anzx2 + k][ywerte[k] + l][m];
858 K[anzx2 - 1 - k][ywerte[k] - 1 - l][2 * zwerte[k][l] - 1 - m] = S.K[anzx2 - 1 - k][ywerte[k] - 1 - l][2 * zwerte[k][l] - 1 - m];
859 K[anzx2 + k][ywerte[k] - 1 - l][2 * zwerte[k][l] - 1 - m] = S.K[anzx2 + k][ywerte[k] - 1 - l][2 * zwerte[k][l] - 1 - m];
860 K[anzx2 - 1 - k][ywerte[k] + l][2 * zwerte[k][l] - 1 - m] = S.K[anzx2 - 1 - k][ywerte[k] + l][2 * zwerte[k][l] - 1 - m];
861 K[anzx2 + k][ywerte[k] + l][2 * zwerte[k][l] - 1 - m] = S.K[anzx2 + k][ywerte[k] + l][2 * zwerte[k][l] - 1 - m];
862 }
863 }
864 }
865 }
866 return *this;
867 }
868
869
870
871 template <class T> void SuperArray<T>::add(const SuperArray<T>& S)
872 {
873 int anzx2 = nges[0] / 2;
874 isequal = false;
875 H = S.H;
876 R = S.R;
877 if (type == IN_OBJECT)
878 {
879 for (int i = 0; i < S.numObjs; i++)
880 for (int ix = 0; ix < S.n[i][0]; ix++)
881 for (int iy = 0; iy < S.n[i][1]; iy++)
882 for (int iz = 0; iz < S.n[i][2]; iz++)
883 G[i][ix][iy][iz] += S.G[i][ix][iy][iz];
884 }
885 else
886 {
887 for (int k = 0; k < anzx2; k++)
888 {
889 for (int l = 0; l < ywerte[k]; l++)
890 {
891
892 for (int m = 0; m < zwerte[k][l]; m++)
893 {
894 K[anzx2 - 1 - k][ywerte[k] - 1 - l][m] += S.K[anzx2 - 1 - k][ywerte[k] - 1 - l][m];
895 K[anzx2 + k][ywerte[k] - 1 - l][m] += S.K[anzx2 + k][ywerte[k] - 1 - l][m];
896 K[anzx2 - 1 - k][ywerte[k] + l][m] += S.K[anzx2 - 1 - k][ywerte[k] + l][m];
897 K[anzx2 + k][ywerte[k] + l][m] += S.K[anzx2 + k][ywerte[k] + l][m];
898 K[anzx2 - 1 - k][ywerte[k] - 1 - l][2 * zwerte[k][l] - 1 - m] += S.K[anzx2 - 1 - k][ywerte[k] - 1 - l][2 * zwerte[k][l] - 1 - m];
899 K[anzx2 + k][ywerte[k] - 1 - l][2 * zwerte[k][l] - 1 - m] += S.K[anzx2 + k][ywerte[k] - 1 - l][2 * zwerte[k][l] - 1 - m];
900 K[anzx2 - 1 - k][ywerte[k] + l][2 * zwerte[k][l] - 1 - m] += S.K[anzx2 - 1 - k][ywerte[k] + l][2 * zwerte[k][l] - 1 - m];
901 K[anzx2 + k][ywerte[k] + l][2 * zwerte[k][l] - 1 - m] += S.K[anzx2 + k][ywerte[k] + l][2 * zwerte[k][l] - 1 - m];
902 }
903 }
904 }
905 }
906 }
907
908 template <class T> void SuperArray<T>::sub(const SuperArray<T>& S)
909 {
910 int anzx2 = nges[0] / 2;
911
912 isequal = false;
913 if (type == IN_OBJECT)
914 {
915 for (int i = 0; i < S.numObjs; i++)
916 for (int ix = 0; ix < S.n[i][0]; ix++)
917 for (int iy = 0; iy < S.n[i][1]; iy++)
918 for (int iz = 0; iz < S.n[i][2]; iz++)
919 G[i][ix][iy][iz] -= S.G[i][ix][iy][iz];
920 }
921 else
922 {
923 for (int k = 0; k < anzx2; k++)
924 {
925 for (int l = 0; l < ywerte[k]; l++)
926 {
927
928 for (int m = 0; m < zwerte[k][l]; m++)
929 {
930 K[anzx2 - 1 - k][ywerte[k] - 1 - l][m] -= S.K[anzx2 - 1 - k][ywerte[k] - 1 - l][m];
931 K[anzx2 + k][ywerte[k] - 1 - l][m] -= S.K[anzx2 + k][ywerte[k] - 1 - l][m];
932 K[anzx2 - 1 - k][ywerte[k] + l][m] -= S.K[anzx2 - 1 - k][ywerte[k] + l][m];
933 K[anzx2 + k][ywerte[k] + l][m] -= S.K[anzx2 + k][ywerte[k] + l][m];
934 K[anzx2 - 1 - k][ywerte[k] - 1 - l][2 * zwerte[k][l] - 1 - m] -= S.K[anzx2 - 1 - k][ywerte[k] - 1 - l][2 * zwerte[k][l] - 1 - m];
935 K[anzx2 + k][ywerte[k] - 1 - l][2 * zwerte[k][l] - 1 - m] -= S.K[anzx2 + k][ywerte[k] - 1 - l][2 * zwerte[k][l] - 1 - m];
936 K[anzx2 - 1 - k][ywerte[k] + l][2 * zwerte[k][l] - 1 - m] -= S.K[anzx2 - 1 - k][ywerte[k] + l][2 * zwerte[k][l] - 1 - m];
937 K[anzx2 + k][ywerte[k] + l][2 * zwerte[k][l] - 1 - m] -= S.K[anzx2 + k][ywerte[k] + l][2 * zwerte[k][l] - 1 - m];
938 }
939 }
940 }
941 }
942 }
943
944 template <class T> std::ostream& operator << (std::ostream& os, const SuperArray<T>& S)
945 {
946 os << "r0=" << S.r0 << std::endl;
947 os << "Ausdehnung: nx=" << S.nges[0] << " ny=" << S.nges[1] << " nz=" << S.nges[2] << std::endl;
948 os << S.numObjs << " Einschluesse" << std::endl;
949 if (S.numObjs > 0)
950 for (int i = 0; i < S.numObjs; i++)
951 {
952 os << "====================== Einschluss Nr. " << i << " ======================" << std::endl;
953 for (int ix = 0; ix < S.n[i][0]; ix++)
954 for (int iy = 0; iy < S.n[i][1]; iy++)
955 for (int iz = 0; iz < S.n[i][2]; iz++)
956 os << abs(S.G[i][ix][iy][iz]) << std::endl;
957 }
958 return os;
959 }
960
961 std::ostream& operator << (std::ostream& os, const SuperArray<std::vector<gridEntry> >& S);
962
963
964 template <class T> void SuperArray<T>::fill(const T& x)
965 {
966 int anzx, anzx2;
967 anzx = nges[0]; anzx2 = nges[0] / 2;
968
969 if (type == IN_OBJECT)
970 {
971 for (int i = 0; i < numObjs; i++)
972 if (Obj[i]->isActive())
973 for (int ix = 0; ix < n[i][0]; ix++)
974 for (int iy = 0; iy < n[i][1]; iy++)
975 for (int iz = 0; iz < n[i][2]; iz++)
976 G[i][ix][iy][iz] = x;
977 }
978 else
979 {
980 for (int k = 0; k < anzx2; k++)
981 {
982 for (int l = 0; l < ywerte[k]; l++)
983 {
984 for (int m = 0; m < zwerte[k][l]; m++)
985 {
986 K[anzx2 - 1 - k][ywerte[k] - 1 - l][zwerte[k][l] - 1 - m] = x;
987 K[anzx2 + k][ywerte[k] - 1 - l][zwerte[k][l] - 1 - m] = x;
988 K[anzx2 - 1 - k][ywerte[k] + l][zwerte[k][l] - 1 - m] = x;
989 K[anzx2 + k][ywerte[k] + l][zwerte[k][l] - 1 - m] = x;
990 K[anzx2 - 1 - k][ywerte[k] - 1 - l][zwerte[k][l] + m] = x;
991 K[anzx2 + k][ywerte[k] - 1 - l][zwerte[k][l] + m] = x;
992 K[anzx2 - 1 - k][ywerte[k] + l][zwerte[k][l] + m] = x;
993 K[anzx2 + k][ywerte[k] + l][zwerte[k][l] + m] = x;
994 }
995 }
996 }
997 }
998 }
999
1000
1001 template <class T> void SuperArray<T>::makeReal()
1002 {
1003 for (int i = 0; i < numObjs; i++)
1004 for (int ix = 0; ix < n[i][0]; ix++)
1005 for (int iy = 0; iy < n[i][1]; iy++)
1006 for (int iz = 0; iz < n[i][2]; iz++)
1007 for (int j = 0; j < 3; j++)
1008 G[i][ix][iy][iz][j] = abs(G[i][ix][iy][iz][j]);
1009 }
1010
1011
1012
1013
1014 template <class T> void SuperArray<T>::allockugel()
1015 {
1016 int anzx, anzx2;
1017 double dx, dy, dz, hilf;
1018 anzx = nges[0];
1019 anzx2 = nges[0] / 2;
1020 // cout << "allockugel" << std::endl;
1021
1022 /*dx=d[0];
1023 dy=d[1];
1024 dz=d[2];*/
1025 dx = 2.0 / nges[0];
1026 dy = 2.0 / nges[1];
1027 dz = 2.0 / nges[2];
1028
1029 zwerte.resize(anzx2);
1030 for (int i = 0; i < anzx2; i++)
1031 {
1032 ywerte.push_back(ceil(sqrt(1.0 - (i * dx) * (i * dx)) / dy));
1033 for (int j = 0; j < anzx2; j++)
1034 {
1035 hilf = 1.0 - (i * dx) * (i * dx) - (j * dy) * (j * dy);
1036 // cout << "hilf:" << hilf << std::endl;
1037 if (hilf >= 0)
1038 // zwerte[i][j]=int(ceil(sqrt(1.0-(i*dx)*(i*dx)-(j*dy)*(j*dy))*nges[2]/2.0));
1039 zwerte[i].push_back(ceil(sqrt(hilf) / dz));
1040 else
1041 zwerte[i].push_back(1);
1042
1043 // cout << "zwerte[" << i << "][" << j << "]:" << zwerte[i][j] << std::endl;
1044 }
1045 }
1046
1047 K.resize(anzx);
1048 for (int k = 0; k < anzx2; k++)
1049 {
1050 K[anzx2 - 1 - k].resize(2 * ywerte[k]);
1051 K[anzx2 + k].resize(2 * ywerte[k]);
1052 for (int l = 0; l < ywerte[k]; l++)
1053 {
1054 K[anzx2 - 1 - k][ywerte[k] + l].resize(2 * zwerte[k][l]);
1055 K[anzx2 + k][ywerte[k] + l].resize(2 * zwerte[k][l]);
1056 K[anzx2 - 1 - k][ywerte[k] - 1 - l].resize(2 * zwerte[k][l]);
1057 K[anzx2 + k][ywerte[k] - 1 - l].resize(2 * zwerte[k][l]);
1058 }
1059 }
1060 }
1061
1063 {
1064 int anzx, jx, jy, jz, ix, iy, iz, jxh, jyh;
1066 anzx = nges[0];
1067 ix = Pi[0]; iy = Pi[1]; iz = Pi[2];
1068 Error = NO_ERRORS;
1069 jx = ix;
1070 jxh = abs(int(jx - (anzx - 1) / 2.0));
1071 jy = iy - (anzx / 2 - ywerte[jxh]);
1072 if ((jy < 0) || (jy > (2 * ywerte[jxh] - 1))) // Punkt ausserhalb
1073 {
1075 // cout << "ix:" << ix << ", iy:" << iy << ", iz:" << iz << ", jx:" << jx <<
1076 // ", jxh:" << jxh << ", jy:" << jy << std::endl;
1077 // cout << "ywerte[" << jxh << "]:" << ywerte[jxh] << std::endl;
1078 return maths::Vector<INDEX_TYPE>(-1, -1, -1);
1079 }
1080 else
1081 {
1082 jyh = abs(INDEX_TYPE(jy - (2 * ywerte[jxh] - 1) / 2.0));
1083 jz = iz - (anzx / 2 - zwerte[jxh][jyh]);
1084
1085 if ((jz < 0) || (jz > (2 * zwerte[jxh][jyh]) - 1)) // Punkt ausserhalb
1086 {
1088 // cout << "ix:" << ix << ", iy:" << iy << ", iz:" << iz << ", jx:" << jx << ", jy:" << jy <<
1089 // ", jxh:" << jxh << ", jyh:" << jyh << ", jz:" << jz << std::endl;
1090 // cout << "ywerte[" << jxh << "]:" << ywerte[jxh] << ", zwerte[" << jxh << "][" << jyh << "]:" <<
1091 // zwerte[jxh][jyh] << std::endl;
1092 return maths::Vector<INDEX_TYPE>(-1, -1, -1);
1093 return maths::Vector<INDEX_TYPE>(-1, -1, -1);
1094 }
1095 else
1096 {
1097 return maths::Vector<INDEX_TYPE>(jx, jy, jz);
1098 }
1099 }
1100 return pk;
1101 }
1102
1104 {
1105 int anzx, jx, jy, jz, ix, iy, iz, jxh, jyh;
1106 // maths::Vector<std::complex<double> > pc;
1107 anzx = nges[0];
1108 ix = Pi[0]; iy = Pi[1]; iz = Pi[2];
1109 jx = ix;
1110 jxh = abs(int(jx - (anzx - 1) / 2.0));
1111 jy = iy - (anzx / 2 - ywerte[jxh]);
1112 pc = maths::Vector<std::complex<double> >(0.0, 0.0, 0.0);
1113 if ((jy < 0) || (jy > (2 * ywerte[jxh] - 1)))
1114 {
1115 std::cout << "Fehler!! Index iy falsch" << std::endl;
1116 return pc;
1117 }
1118 else
1119 {
1120 jyh = abs(int(jy - (2 * ywerte[jxh] - 1) / 2.0));
1121 jz = iz - (anzx / 2 - zwerte[jxh][jyh]);
1122
1123 if ((jz < 0) || (jz > (2 * zwerte[jxh][jyh]) - 1))
1124 {
1125 return pc;
1126 }
1127 return K[jx][jy][jz];
1128 }
1129 return pc;
1130 }
1131
1132 template<class T> T SuperArray<T>::kugelwert(int ix, int iy, int iz)
1133 {
1134 int anzx, jx, jy, jz, jxh, jyh;
1135 T pc;
1136 anzx = nges[0];
1137
1138
1139 jx = ix;
1140 jxh = abs(int(jx - (anzx - 1) / 2.0));
1141 jy = iy - (anzx / 2 - ywerte[jxh]);
1142 if ((jy < 0) || (jy > (2 * ywerte[jxh] - 1)))
1143 {
1144 std::cout << "Fehler!! Index iy falsch" << std::endl;
1145 // pc = maths::Vector<std::complex<double> >(0.0, 0.0, 0.0);
1146 return pc;
1147 }
1148 else
1149 {
1150 jyh = abs(int(jy - (2 * ywerte[jxh] - 1) / 2.0));
1151 jz = iz - (anzx / 2 - zwerte[jxh][jyh]);
1152 if ((jz < 0) || (jz > (2 * zwerte[jxh][jyh]) - 1))
1153 {
1154 std::cout << "Fehler!! Index iz falsch" << std::endl;
1155 // pc = maths::Vector<std::complex<double> >(0.0, 0.0, 0.0);
1156 return pc;
1157 }
1158 pc = K[jx][jy][jz];
1159 }
1160 return pc;
1161 }
1162
1163
1173 bool saveExPhase(SuperArray<maths::Vector<std::complex<double> > > &S, char* FName, int i = 0);
1174
1184 bool saveEyPhase(SuperArray<maths::Vector<std::complex<double> > > &S, char* FName, int i = 0);
1185
1195 bool saveEzPhase(SuperArray<maths::Vector<std::complex<double> > > &S, char* FName, int i = 0);
1196 bool saveExPol(SuperArray < maths::Vector < std::complex<double> > > &S, char* FName, int i = 0);
1197 bool saveEyPol(SuperArray < maths::Vector < std::complex<double> > > &S, char* FName, int i = 0);
1198 bool saveEzPol(SuperArray < maths::Vector < std::complex<double> > > &S, char* FName, int i = 0);
1208 bool saveabsE(SuperArray < maths::Vector < std::complex<double> > > &S, std::string FName, int i = 0);
1209 bool saveabsEbin(SuperArray < maths::Vector < std::complex<double> > >& S, std::string FName, int i = 0);
1220 bool saveFullE(SuperArray < maths::Vector < std::complex<double> > > &S, std::string FName, int i = 0);
1221 double sumabs(const SuperArray<maths::Vector<std::complex<double> > >& S);
1222 double sumabs2(const SuperArray<maths::Vector<std::complex<double> > >& S);
1223 double sumabs2(const SuperArray<maths::Vector<std::complex<double> > >& S);
1224 double sumabs2(const SuperArray<maths::Vector<std::complex<double> > >& S, int i);
1225 bool save(SuperArray<GOAT::raytracing::gridEntry > S, std::string FName);
1226 double abs2sum(const SuperArray<maths::Vector<std::complex<double> > >& S);
1227bool save(SuperArray<std::vector<GOAT::raytracing::gridEntry > > S, std::string FName);
1228 }
1229}
This class represents a threedimensional (numeric) Matrix as a template.
Definition matrix.h:23
Template class for threedimensional vectors.
Definition vector.h:57
Abstract base class for all volume objects This abstract class provides a template for all volume obj...
Definition objectshape.h:60
maths::Vector< double > por
corners of the circumferent cuboid (lower left corner and upper right corner)
maths::Vector< double > pul
bool isActive()
returns true if the object should be considered for inelastic calculation
Template class to store arbitrary information in a 3D-grid This template class provides a virtual 3D-...
Definition superarray.h:26
SuperArray(const SuperArray &S)
Definition superarray.h:37
bool inObject(maths::Vector< double > P, int i)
checks if P is inside the i-th object (p in real coordinates)
Definition superarray.h:417
int type
Mainly used for inelastic scattering. type=IN_HOST means the grid is stored in the whole volume,...
Definition superarray.h:148
void reinit(double r0, INDEX_TYPE n)
Definition superarray.h:749
T kugelwert(maths::Vector< int > Pi)
for internal use only
maths::Vector< INDEX_TYPE > gitterpunkt(maths::Vector< double > P)
Definition superarray.h:267
maths::Vector< INDEX_TYPE > kugelindex(maths::Vector< INDEX_TYPE > Pi)
Checks if the point Pi (indicated by the indices) is inside the calculation sphere The function retur...
std::vector< std::vector< std::vector< std::vector< T > > > > G
Here, the data is stored. G[i][ix][iy][iz], whereas i: index of the object, ix,iy,...
Definition superarray.h:151
void sub(const SuperArray &S)
Subtract another SuperArray object. In this function, all array elements from S are subtracted from t...
Definition superarray.h:908
void add(const SuperArray &S)
Adds another SuperArray object. In this function, all array elements from S are added to the existing...
Definition superarray.h:871
bool addInc(std::vector< ObjectShape * >Obj, int numObj, const bool isAbsolute=false)
Summing up SuperArray Here, all cell contents are first added up. The absolute value is taken from th...
Definition superarray.h:239
std::vector< std::vector< int > > zwerte
Definition superarray.h:150
bool read(std::string fname)
std::vector< maths::Vector< INDEX_TYPE > > Pul
Definition superarray.h:154
bool write(std::string fname)
maths::Matrix< double > H
Definition superarray.h:163
maths::Vector< double > d
Edge length of one cell in x-, y- and z-direction.
Definition superarray.h:158
std::vector< int > ywerte
Definition superarray.h:149
void setNumberOfCellsPerDirection(INDEX_TYPE no)
Definition superarray.h:168
void clear()
Clear the SuperArray and release the allocated memory.
Definition superarray.h:684
maths::Matrix< double > R
Transformation matrices in the local array coordinate system and backwards.
Definition superarray.h:163
int Error
Holds an error number.
Definition superarray.h:145
SuperArray & operator=(const SuperArray &S)
Assignment operator.
Definition superarray.h:801
void fill(const T &x)
Fill the whole SuperArray with value x.
Definition superarray.h:964
void copy(const SuperArray &S)
Copies SuperArray object Here, S will be copied into the existing SuperArray and all elements will be...
Definition superarray.h:777
std::vector< maths::Vector< INDEX_TYPE > > n
n[i]: Dimensions, i.e. number of subdivision in x-, y- and z-direction
Definition superarray.h:155
std::vector< std::vector< std::vector< T > > > K
Definition superarray.h:152
maths::Vector< INDEX_TYPE > nges
Vector which contains the number of subdivisions in x-, y- and z-direction for the whole (virtual) ar...
Definition superarray.h:156
bool iscleared
Array is cleared (needed by the clear() function)
Definition superarray.h:161
T & operator()(INDEX_TYPE ix, INDEX_TYPE iy, INDEX_TYPE iz)
gives the content of the cell[ix][iy][iz]
Definition superarray.h:432
#define SUPERGITTER
Definition error.h:27
#define NO_ERRORS
Definition error.h:23
#define NOT_FOUND
Definition error.h:30
#define INVALID_PARAMETER
Definition error.h:31
Matrix< double > unity()
unity matrix (double precision)
Raytracer used for ultrashort pulse calculation with raytracing only.
Definition asphericLens.h:6
bool saveExPhase(SuperArray< maths::Vector< std::complex< double > > > &S, char *FName, int i=0)
save the phase of the x-component of the electric field Save the phase of the x-component of the elec...
bool saveExPol(SuperArray< maths::Vector< std::complex< double > > > &S, char *FName, int i=0)
bool saveEzPhase(SuperArray< maths::Vector< std::complex< double > > > &S, char *FName, int i=0)
save the phase of the z-component of the electric field Save the phase of the z-component of the elec...
bool saveEyPol(SuperArray< maths::Vector< std::complex< double > > > &S, char *FName, int i=0)
bool saveabsEbin(SuperArray< maths::Vector< std::complex< double > > > &S, std::string FName, int i=0)
long long int INDEX_TYPE
Definition superarray.h:16
bool saveabsE(SuperArray< maths::Vector< std::complex< double > > > &S, std::string FName, int i=0)
save the square of the absolute value of the z-component of the electric field Save the square of the...
bool saveEyPhase(SuperArray< maths::Vector< std::complex< double > > > &S, char *FName, int i=0)
save the phase of the y-component of the electric field Save the phase of the y-component of the elec...
std::ostream & operator<<(std::ostream &os, Box B)
output operator for the Box class
void clear(GlobalParms parms, maths::Vector< std::complex< double > > **Gitter)
bool saveEzPol(SuperArray< maths::Vector< std::complex< double > > > &S, char *FName, int i=0)
This class is used for the iray class. This class is intended for internal use only....
Definition fresnel.h:7
#define IN_OBJECT
Definition resutil.h:39
#define IN_HOST
Definition resutil.h:40
This file contains the Vector template class and some useful functions around this class.