1 /*
2 *	Copyright (C) 2012-2014 Thorsten Liebig (Thorsten.Liebig@gmx.de)
3 *
4 *	This program is free software: you can redistribute it and/or modify
5 *	it under the terms of the GNU General Public License as published by
6 *	the Free Software Foundation, either version 3 of the License, or
7 *	(at your option) any later version.
8 *
9 *	This program is distributed in the hope that it will be useful,
10 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *	GNU General Public License for more details.
13 *
14 *	You should have received a copy of the GNU General Public License
15 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef NF2FF_CALC_H
19 #define NF2FF_CALC_H
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <vector>
24 #include <cmath>
25 #include <complex>
26 #include <boost/thread.hpp>
27 #define _USE_MATH_DEFINES
28 
29 class nf2ff_calc;
30 
31 #define MIRROR_OFF 0
32 #define MIRROR_PEC 1
33 #define MIRROR_PMC 2
34 
35 // data structure to exchange data between thread-controller and worker-threads
36 typedef struct
37 {
38 	//local working data IN
39 	int ny;
40 	int mesh_type;
41 	float* normDir;
42 	unsigned int* numLines;
43 	float **lines;
44 	float* edge_length_P;
45 	float* edge_length_PP;
46 
47 	std::complex<float>**** E_field;
48 	std::complex<float>**** H_field;
49 	std::complex<float>**** Js;
50 	std::complex<float>**** Ms;
51 
52 	//local working data OUT
53 	std::complex<double>** m_Nt;
54 	std::complex<double>** m_Np;
55 	std::complex<double>** m_Lt;
56 	std::complex<double>** m_Lp;
57 
58 } nf2ff_data;
59 
60 class nf2ff_calc_thread
61 {
62 public:
63 	nf2ff_calc_thread(nf2ff_calc* nfc, unsigned int start, unsigned int stop, unsigned int threadID, nf2ff_data &data);
64 	void operator()();
65 
66 protected:
67 	unsigned int m_start, m_stop, m_threadID;
68 	nf2ff_calc *m_nf_calc;
69 
70 	nf2ff_data m_data;
71 };
72 
73 class nf2ff_calc
74 {
75 	// allow full data access to nf2ff_calc_thread class
76 	friend class nf2ff_calc_thread;
77 public:
78 	nf2ff_calc(float freq, std::vector<float> theta, std::vector<float> phi, std::vector<float> center);
79 	~nf2ff_calc();
80 
SetRadius(float radius)81 	void SetRadius(float radius) {m_radius=radius;}
SetPermittivity(float permittivity)82 	void SetPermittivity(float permittivity) {m_permittivity=permittivity;}
SetPermeability(float permeability)83 	void SetPermeability(float permeability) {m_permeability=permeability;}
84 
GetTotalRadPower()85 	double GetTotalRadPower() const {return m_radPower;}
GetMaxDirectivity()86 	double GetMaxDirectivity() const {return m_maxDir;}
87 
GetETheta()88 	std::complex<double>** GetETheta() const {return m_E_theta;}
GetEPhi()89 	std::complex<double>** GetEPhi() const {return m_E_phi;}
GetRadPower()90 	double** GetRadPower() const {return m_P_rad;}
91 
GetNumThreads()92 	unsigned int GetNumThreads() const {return m_numThreads;}
SetNumThreads(unsigned int n)93 	void SetNumThreads(unsigned int n) {m_numThreads=n;}
94 
95 	void SetMirror(int type, int dir, float pos);
96 
97 	bool AddPlane(float **lines, unsigned int* numLines, std::complex<float>**** E_field, std::complex<float>**** H_field, int MeshType=0);
98 
99 protected:
100 	float m_freq;
101 	float m_radius;
102 
103 	float m_permittivity; //relative electric permittivity
104 	float m_permeability; //relative magnetic permeability
105 
106 	double m_radPower;
107 	double m_maxDir;
108 
109 	std::complex<double>** m_E_theta;
110 	std::complex<double>** m_E_phi;
111 	std::complex<double>** m_H_theta;
112 	std::complex<double>** m_H_phi;
113 	double** m_P_rad;
114 
115 	float m_centerCoord[3];
116 	unsigned int m_numTheta;
117 	unsigned int m_numPhi;
118 	float* m_theta;
119 	float* m_phi;
120 
121 	//mirror settings
122 	bool m_EnableMirror;
123 	int m_MirrorType[3];
124 	float m_MirrorPos[3];
125 
126 	int GetNormalDir(unsigned int* numLines);
127 	bool AddSinglePlane(float **lines, unsigned int* numLines, std::complex<float>**** E_field, std::complex<float>**** H_field, int MeshType=0);
128 	bool AddMirrorPlane(int n, float **lines, unsigned int* numLines, std::complex<float>**** E_field, std::complex<float>**** H_field, int MeshType=0);
129 
130 	//boost multi-threading
131 	unsigned int m_numThreads;
132 	boost::thread_group m_thread_group;
133 	boost::barrier *m_Barrier;
134 };
135 
136 
137 #endif // NF2FF_CALC_H
138