diff --git a/matlab/CalcNF2FF.m b/matlab/CalcNF2FF.m index 4d9f2c1..72778a9 100644 --- a/matlab/CalcNF2FF.m +++ b/matlab/CalcNF2FF.m @@ -4,6 +4,10 @@ function nf2ff = CalcNF2FF(nf2ff, Sim_Path, freq, theta, phi, varargin) % Calculate the near-field to far-field transformation created by % CreateNF2FFBox % +% IMPORTANT: +% Make sure to define the correct nf2ff phase center, aka. central antenna +% position! See optional parameter below!! Default is [0 0 0] +% % parameter: % nf2ff: data structure created by CreateNF2FFBox % Sim_Path: path to simulation data @@ -11,6 +15,10 @@ function nf2ff = CalcNF2FF(nf2ff, Sim_Path, freq, theta, phi, varargin) % theta,phi: spherical coordinates to evaluate the far-field on % % optional paramater: +% 'Center': nf2ff phase center, default is [0 0 0] +% !! Make sure the center is never outside of your nf2ff box!! +% Definition is the correct coordinate system necessary +% --> either Cartesian or cylindrical coordinates % 'Mode': 'Mode', 0 -> read only, if data already exist (default) % 'Mode', 1 -> calculate anyway, overwrite existing % 'Mode', 2 -> read only, fail if not existing diff --git a/matlab/CreateNF2FFBox.m b/matlab/CreateNF2FFBox.m index 2107662..c32c62f 100644 --- a/matlab/CreateNF2FFBox.m +++ b/matlab/CreateNF2FFBox.m @@ -27,6 +27,7 @@ end directions = ones(6,1); add_args = {}; dump_type = 0; +dump_mode = 1; for n=1:numel(varargin)/2 if strcmp(varargin{2*n-1},'Frequency') @@ -43,14 +44,20 @@ nf2ff.filenames_E = {[name '_E_xn'],[name '_E_xp'],[name '_E_yn'],[name '_E_yp'] nf2ff.filenames_H = {[name '_H_xn'],[name '_H_xp'],[name '_H_yn'],[name '_H_yp'],[name '_H_zn'],[name '_H_zp']}; nf2ff.directions = directions; +if (isfield(CSX,'ATTRIBUTE')) + if (isfield(CSX.ATTRIBUTE,'CoordSystem')) + nf2ff.CoordSystem = CSX.ATTRIBUTE.CoordSystem; + end +end + for nd = 1:3 pos = 2*nd-1; if (directions(pos)) l_start = start; l_stop = stop; l_stop(nd) = start(nd); - CSX = AddBox( AddDump(CSX,nf2ff.filenames_E{pos},'DumpType',dump_type,'DumpMode',2,'FileType',1,add_args{:}), nf2ff.filenames_E{pos}, 0, l_start, l_stop ); - CSX = AddBox( AddDump(CSX,nf2ff.filenames_H{pos},'DumpType',dump_type+1,'DumpMode',2,'FileType',1,add_args{:}), nf2ff.filenames_H{pos}, 0, l_start, l_stop ); + CSX = AddBox( AddDump(CSX,nf2ff.filenames_E{pos},'DumpType',dump_type,'DumpMode',dump_mode,'FileType',1,add_args{:}), nf2ff.filenames_E{pos}, 0, l_start, l_stop ); + CSX = AddBox( AddDump(CSX,nf2ff.filenames_H{pos},'DumpType',dump_type+1,'DumpMode',dump_mode,'FileType',1,add_args{:}), nf2ff.filenames_H{pos}, 0, l_start, l_stop ); else nf2ff.filenames_E{pos}=''; nf2ff.filenames_H{pos}=''; @@ -60,8 +67,8 @@ for nd = 1:3 l_start = start; l_stop = stop; l_start(nd) = stop(nd); - CSX = AddBox( AddDump(CSX,nf2ff.filenames_E{pos},'DumpType',dump_type,'DumpMode',2,'FileType',1,add_args{:}), nf2ff.filenames_E{pos}, 0, l_start, l_stop ); - CSX = AddBox( AddDump(CSX,nf2ff.filenames_H{pos},'DumpType',dump_type+1,'DumpMode',2,'FileType',1,add_args{:}), nf2ff.filenames_H{pos}, 0, l_start, l_stop ); + CSX = AddBox( AddDump(CSX,nf2ff.filenames_E{pos},'DumpType',dump_type,'DumpMode',dump_mode,'FileType',1,add_args{:}), nf2ff.filenames_E{pos}, 0, l_start, l_stop ); + CSX = AddBox( AddDump(CSX,nf2ff.filenames_H{pos},'DumpType',dump_type+1,'DumpMode',dump_mode,'FileType',1,add_args{:}), nf2ff.filenames_H{pos}, 0, l_start, l_stop ); else nf2ff.filenames_E{pos}=''; nf2ff.filenames_H{pos}=''; diff --git a/nf2ff/nf2ff.cpp b/nf2ff/nf2ff.cpp index 17b2f7c..695b8f0 100644 --- a/nf2ff/nf2ff.cpp +++ b/nf2ff/nf2ff.cpp @@ -34,7 +34,7 @@ //external libs #include "tinyxml.h" -nf2ff::nf2ff(vector freq, vector theta, vector phi, unsigned int numThreads) +nf2ff::nf2ff(vector freq, vector theta, vector phi, vector center, unsigned int numThreads) { m_freq = freq; @@ -51,11 +51,10 @@ nf2ff::nf2ff(vector freq, vector theta, vector phi, unsigne m_nf2ff.resize(freq.size(),NULL); for (size_t fn=0;fnSetNumThreads(numThreads); } - m_radius = 1; m_Verbose = 0; } @@ -99,6 +98,12 @@ bool nf2ff::AnalyseXMLNode(TiXmlElement* ti_nf2ff) return false; } vector freq = SplitString2Float(attr); + + vector center; + attr = ti_nf2ff->Attribute("Center"); + if (attr!=NULL) + center = SplitString2Float(attr); + attr = ti_nf2ff->Attribute("Outfile"); if (attr==NULL) { @@ -152,7 +157,7 @@ bool nf2ff::AnalyseXMLNode(TiXmlElement* ti_nf2ff) } vector phi = SplitString2Float(ti_phi_text->Value()); - nf2ff* l_nf2ff = new nf2ff(freq,theta,phi,numThreads); + nf2ff* l_nf2ff = new nf2ff(freq,theta,phi,center,numThreads); l_nf2ff->SetVerboseLevel(Verbose); TiXmlElement* ti_Planes = ti_nf2ff->FirstChildElement(); @@ -266,7 +271,7 @@ bool nf2ff::AnalyseFile(string E_Field_file, string H_Field_file) { if (m_Verbose>1) cerr << "nf2ff: f = " << m_freq.at(fn) << "Hz (" << fn+1 << "/" << m_nf2ff.size() << ") ..."; - m_nf2ff.at(fn)->AddPlane(E_lines, E_numLines, E_fd_data.at(fn), H_fd_data.at(fn)); + m_nf2ff.at(fn)->AddPlane(E_lines, E_numLines, E_fd_data.at(fn), H_fd_data.at(fn),E_meshType); if (m_Verbose>1) cerr << " done." << endl; } diff --git a/nf2ff/nf2ff.h b/nf2ff/nf2ff.h index 60b10de..e59b8ed 100644 --- a/nf2ff/nf2ff.h +++ b/nf2ff/nf2ff.h @@ -32,7 +32,7 @@ class TiXmlElement; class nf2ff { public: - nf2ff(vector freq, vector theta, vector phi, unsigned int numThreads=0); + nf2ff(vector freq, vector theta, vector phi, vector center, unsigned int numThreads=0); ~nf2ff(); bool AnalyseFile(string E_Field_file, string H_Field_file); diff --git a/nf2ff/nf2ff_calc.cpp b/nf2ff/nf2ff_calc.cpp index 3f04f11..1ec6b1f 100644 --- a/nf2ff/nf2ff_calc.cpp +++ b/nf2ff/nf2ff_calc.cpp @@ -60,23 +60,39 @@ void nf2ff_calc_thread::operator()() complex**** E_field=m_data.E_field; complex**** H_field=m_data.H_field; + int mesh_type = m_data.mesh_type; + // calc Js and Ms (eq. 8.15a/b) pos[ny]=0; for (pos_t=0; pos_t** m_Nt=m_data.m_Nt; @@ -84,6 +100,12 @@ void nf2ff_calc_thread::operator()() complex** m_Lt=m_data.m_Lt; complex** m_Lp=m_data.m_Lp; + float center[3] = {m_nf_calc->m_centerCoord[0],m_nf_calc->m_centerCoord[1],m_nf_calc->m_centerCoord[2]}; + if (mesh_type==1) + { + center[0] = m_nf_calc->m_centerCoord[0]*cos(m_nf_calc->m_centerCoord[1]); + center[1] = m_nf_calc->m_centerCoord[0]*sin(m_nf_calc->m_centerCoord[1]); + } // calc local Nt,Np,Lt and Lp float area; float cosT_cosP,cosP_sinT; @@ -110,19 +132,21 @@ void nf2ff_calc_thread::operator()() { pos[nP] = m_start+pos_t; for (pos[nPP]=0; pos[nPP] theta, vector phi) +nf2ff_calc::nf2ff_calc(float freq, vector theta, vector phi, vector center) { m_freq = freq; m_numTheta = theta.size(); m_theta = new float[m_numTheta]; for (size_t n=0;n >(numLines); @@ -156,7 +180,19 @@ nf2ff_calc::nf2ff_calc(float freq, vector theta, vector phi) m_H_phi = Create2DArray >(numLines); m_P_rad = Create2DArray(numLines); - m_centerCoord[0]=m_centerCoord[1]=m_centerCoord[2]=0; + if (center.size()==3) + { + m_centerCoord[0]=center.at(0); + m_centerCoord[1]=center.at(1); + m_centerCoord[2]=center.at(2); + } + else if (center.size()>0) + { + cerr << "nf2ff_calc::nf2ff_calc: Warning: Center coordinates error, ignoring!" << endl; + m_centerCoord[0]=m_centerCoord[1]=m_centerCoord[2]=0.0; + } + else + m_centerCoord[0]=m_centerCoord[1]=m_centerCoord[2]=0.0; m_radPower = 0; m_maxDir = 0; @@ -189,7 +225,7 @@ nf2ff_calc::~nf2ff_calc() m_Barrier = NULL; } -bool nf2ff_calc::AddPlane(float **lines, unsigned int* numLines, complex**** E_field, complex**** H_field) +bool nf2ff_calc::AddPlane(float **lines, unsigned int* numLines, complex**** E_field, complex**** H_field, int MeshType) { //find normal direction int ny = -1; @@ -231,6 +267,24 @@ bool nf2ff_calc::AddPlane(float **lines, unsigned int* numLines, complex* edge_length_PP[0]=0.5*(lines[nPP][1]-lines[nPP][0]); edge_length_PP[numLines[nPP]-1]=0.5*(lines[nPP][numLines[nPP]-1]-lines[nPP][numLines[nPP]-2]); + //check for cylindrical mesh + if (MeshType==1) + { + if (ny==0) //surface a-z + { + for (unsigned int n=0;n power = 0; float area; for (pos[0]=0; pos[0]* { area = edge_length_P[pos[nP]]*edge_length_PP[pos[nPP]]; power = (E_field[nP][pos[0]][pos[1]][pos[2]]*conj(H_field[nPP][pos[0]][pos[1]][pos[2]]) \ - - E_field[nPP][pos[0]][pos[1]][pos[2]]*conj(H_field[nP][pos[0]][pos[1]][pos[2]])); + - E_field[nPP][pos[0]][pos[1]][pos[2]]*conj(H_field[nP][pos[0]][pos[1]][pos[2]])); m_radPower += 0.5*area*real(power)*normDir[ny]; } - unsigned int numAngles[2] = {m_numTheta, m_numPhi}; // setup multi-threading jobs @@ -255,6 +308,7 @@ bool nf2ff_calc::AddPlane(float **lines, unsigned int* numLines, complex* for (unsigned int n=0; n theta, vector phi); + nf2ff_calc(float freq, vector theta, vector phi, vector center); ~nf2ff_calc(); float GetRadPower() const {return m_radPower;} @@ -83,7 +84,7 @@ public: unsigned int GetNumThreads() const {return m_numThreads;} void SetNumThreads(unsigned int n) {m_numThreads=n;} - bool AddPlane(float **lines, unsigned int* numLines, complex**** E_field, complex**** H_field); + bool AddPlane(float **lines, unsigned int* numLines, complex**** E_field, complex**** H_field, int MeshType=0); protected: float m_freq;