2010-03-11 15:47:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
#include "openems.h"
|
2010-03-15 19:50:49 +00:00
|
|
|
#include <iomanip>
|
2010-03-11 09:56:19 +00:00
|
|
|
#include "tools/array_ops.h"
|
2010-05-06 20:55:59 +00:00
|
|
|
#include "FDTD/operator_cylinder.h"
|
2010-03-26 11:57:52 +00:00
|
|
|
#include "FDTD/engine_multithread.h"
|
2010-05-20 20:02:06 +00:00
|
|
|
#include "FDTD/operator_multithread.h"
|
2010-04-27 21:06:42 +00:00
|
|
|
#include "FDTD/operator_ext_mur_abc.h"
|
2010-07-16 15:25:32 +00:00
|
|
|
#include "FDTD/operator_ext_pml_sf.h"
|
2010-03-11 09:56:19 +00:00
|
|
|
#include "FDTD/processvoltage.h"
|
|
|
|
#include "FDTD/processcurrent.h"
|
2010-07-16 13:55:35 +00:00
|
|
|
#include "FDTD/process_efield.h"
|
2010-07-19 06:41:53 +00:00
|
|
|
#include "FDTD/process_hfield.h"
|
2010-08-16 09:53:43 +00:00
|
|
|
#include "FDTD/processmodematch.h"
|
2010-03-11 09:56:19 +00:00
|
|
|
#include "FDTD/processfields_td.h"
|
2010-03-25 14:08:54 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
2010-03-11 09:56:19 +00:00
|
|
|
|
2010-07-06 08:01:26 +00:00
|
|
|
#include "FDTD/operator_ext_lorentzmaterial.h"
|
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
//external libs
|
|
|
|
#include "tinyxml.h"
|
|
|
|
#include "ContinuousStructure.h"
|
|
|
|
|
2010-03-25 14:08:54 +00:00
|
|
|
double CalcDiffTime(timeval t1, timeval t2)
|
|
|
|
{
|
2010-03-27 14:54:44 +00:00
|
|
|
double s_diff = t1.tv_sec - t2.tv_sec;
|
|
|
|
s_diff += (t1.tv_usec-t2.tv_usec)*1e-6;
|
2010-03-25 14:08:54 +00:00
|
|
|
return s_diff;
|
|
|
|
}
|
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
openEMS::openEMS()
|
|
|
|
{
|
|
|
|
FDTD_Op=NULL;
|
|
|
|
FDTD_Eng=NULL;
|
|
|
|
PA=NULL;
|
2010-04-09 13:51:37 +00:00
|
|
|
CylinderCoords = false;
|
2010-03-11 14:48:55 +00:00
|
|
|
Enable_Dumps = true;
|
2010-03-12 19:39:04 +00:00
|
|
|
DebugMat = false;
|
2010-03-17 22:16:41 +00:00
|
|
|
DebugOp = false;
|
2010-07-08 09:28:11 +00:00
|
|
|
m_debugCSX = false;
|
2010-06-02 14:37:21 +00:00
|
|
|
m_debugBox = m_debugPEC = false;
|
2010-03-15 15:59:37 +00:00
|
|
|
endCrit = 1e-6;
|
2010-04-04 17:48:36 +00:00
|
|
|
m_OverSampling = 4;
|
2010-03-30 11:13:00 +00:00
|
|
|
|
|
|
|
m_engine = EngineType_Standard;
|
|
|
|
m_engine_numThreads = 0;
|
2010-03-11 09:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
openEMS::~openEMS()
|
|
|
|
{
|
2010-04-01 14:11:25 +00:00
|
|
|
Reset();
|
2010-03-11 09:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void openEMS::Reset()
|
|
|
|
{
|
|
|
|
if (PA) PA->DeleteAll();
|
2010-04-01 14:11:25 +00:00
|
|
|
delete PA; PA=0;
|
|
|
|
delete FDTD_Eng; FDTD_Eng=0;
|
|
|
|
delete FDTD_Op; FDTD_Op=0;
|
2010-03-11 09:56:19 +00:00
|
|
|
}
|
|
|
|
|
2010-03-26 10:57:53 +00:00
|
|
|
//! \brief processes a command line argument
|
2010-07-16 08:41:12 +00:00
|
|
|
//! \return true if argument is known
|
|
|
|
//! \return false if argument is unknown
|
2010-03-26 10:57:53 +00:00
|
|
|
bool openEMS::parseCommandLineArgument( const char *argv )
|
|
|
|
{
|
|
|
|
if (!argv)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (strcmp(argv,"--disable-dumps")==0)
|
|
|
|
{
|
|
|
|
cout << "openEMS - disabling all field dumps" << endl;
|
|
|
|
SetEnableDumps(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv,"--debug-material")==0)
|
|
|
|
{
|
|
|
|
cout << "openEMS - dumping material to 'material_dump.vtk'" << endl;
|
|
|
|
DebugMaterial();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv,"--debug-operator")==0)
|
|
|
|
{
|
|
|
|
cout << "openEMS - dumping operator to 'operator_dump.vtk'" << endl;
|
|
|
|
DebugOperator();
|
|
|
|
return true;
|
|
|
|
}
|
2010-04-19 14:09:41 +00:00
|
|
|
else if (strcmp(argv,"--debug-boxes")==0)
|
|
|
|
{
|
|
|
|
cout << "openEMS - dumping boxes to 'box_dump*.vtk'" << endl;
|
|
|
|
DebugBox();
|
|
|
|
return true;
|
|
|
|
}
|
2010-06-02 14:37:21 +00:00
|
|
|
else if (strcmp(argv,"--debug-PEC")==0)
|
|
|
|
{
|
|
|
|
cout << "openEMS - dumping PEC info to 'PEC_dump.vtk'" << endl;
|
|
|
|
m_debugPEC = true;
|
|
|
|
return true;
|
|
|
|
}
|
2010-07-08 09:28:11 +00:00
|
|
|
else if (strcmp(argv,"--debug-CSX")==0)
|
|
|
|
{
|
|
|
|
cout << "openEMS - dumping CSX geometry to 'debugCSX.xml'" << endl;
|
|
|
|
m_debugCSX = true;
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-26 11:57:52 +00:00
|
|
|
else if (strcmp(argv,"--engine=multithreaded")==0)
|
|
|
|
{
|
|
|
|
cout << "openEMS - enabled multithreading" << endl;
|
2010-05-20 20:02:06 +00:00
|
|
|
m_engine = EngineType_Multithreaded;
|
2010-03-26 11:57:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-03-30 11:13:00 +00:00
|
|
|
else if (strncmp(argv,"--numThreads=",13)==0)
|
|
|
|
{
|
|
|
|
m_engine_numThreads = atoi(argv+13);
|
|
|
|
cout << "openEMS - fixed number of threads: " << m_engine_numThreads << endl;
|
|
|
|
return true;
|
|
|
|
}
|
2010-04-21 09:18:22 +00:00
|
|
|
else if (strcmp(argv,"--engine=sse")==0)
|
|
|
|
{
|
|
|
|
cout << "openEMS - enabled sse engine" << endl;
|
|
|
|
m_engine = EngineType_SSE;
|
|
|
|
return true;
|
|
|
|
}
|
2010-05-19 09:41:35 +00:00
|
|
|
else if (strcmp(argv,"--engine=sse-compressed")==0)
|
|
|
|
{
|
|
|
|
cout << "openEMS - enabled compressed sse engine" << endl;
|
|
|
|
m_engine = EngineType_SSE_Compressed;
|
|
|
|
return true;
|
|
|
|
}
|
2010-05-21 06:16:24 +00:00
|
|
|
else if (strcmp(argv,"--engine=fastest")==0)
|
|
|
|
{
|
|
|
|
cout << "openEMS - enabled multithreading engine" << endl;
|
|
|
|
m_engine = EngineType_Multithreaded;
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-26 10:57:53 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-30 13:28:15 +00:00
|
|
|
bool openEMS::SetupBoundaryConditions(TiXmlElement* BC)
|
|
|
|
{
|
|
|
|
int EC; //error code of tinyxml
|
|
|
|
int bounds[6] = {0,0,0,0,0,0}; //default boundary cond. (PEC)
|
|
|
|
int pml_size[6] = {8,8,8,8,8,8}; //default pml size
|
|
|
|
string s_bc;
|
2010-07-30 15:51:39 +00:00
|
|
|
const char* tmp = BC->Attribute("PML_Grading");
|
|
|
|
string pml_gradFunc;
|
|
|
|
if (tmp)
|
|
|
|
pml_gradFunc = string(tmp);
|
2010-07-30 13:28:15 +00:00
|
|
|
|
|
|
|
string bound_names[] = {"xmin","xmax","ymin","ymax","zmin","zmax"};
|
|
|
|
|
|
|
|
for (int n=0;n<6;++n)
|
|
|
|
{
|
|
|
|
EC = BC->QueryIntAttribute(bound_names[n].c_str(),&bounds[n]);
|
|
|
|
if (EC==TIXML_SUCCESS)
|
|
|
|
continue;
|
|
|
|
if (EC==TIXML_WRONG_TYPE)
|
|
|
|
{
|
2010-07-30 15:51:39 +00:00
|
|
|
tmp = BC->Attribute(bound_names[n].c_str());
|
|
|
|
if (tmp)
|
|
|
|
s_bc = string(tmp);
|
2010-07-30 13:28:15 +00:00
|
|
|
if (s_bc=="PEC")
|
|
|
|
bounds[n] = 0;
|
|
|
|
else if (s_bc=="PMC")
|
|
|
|
bounds[n] = 1;
|
|
|
|
else if (s_bc=="MUR")
|
|
|
|
bounds[n] = 2;
|
|
|
|
else if(strncmp(s_bc.c_str(),"PML_=",4)==0)
|
|
|
|
{
|
|
|
|
bounds[n] = 3;
|
|
|
|
pml_size[n] = atoi(s_bc.c_str()+4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cerr << "openEMS::SetupBoundaryConditions: Warning, boundary condition for \"" << bound_names[n] << "\" unknown... set to PEC " << endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cerr << "openEMS::SetupBoundaryConditions: Warning, boundary condition for \"" << bound_names[n] << "\" not found... set to PEC " << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
FDTD_Op->SetBoundaryCondition(bounds); //operator only knows about PEC and PMC, everything else is defined by extensions (see below)
|
|
|
|
|
|
|
|
/**************************** create all operator/engine extensions here !!!! **********************************/
|
|
|
|
//Mur-ABC, defined as extension to the operator
|
|
|
|
for (int n=0;n<6;++n)
|
|
|
|
{
|
|
|
|
if (bounds[n]==2) //Mur-ABC
|
|
|
|
{
|
|
|
|
Operator_Ext_Mur_ABC* op_ext_mur = new Operator_Ext_Mur_ABC(FDTD_Op);
|
|
|
|
op_ext_mur->SetDirection(n/2,n%2);
|
2010-08-10 05:50:53 +00:00
|
|
|
double v_ph = 0;
|
|
|
|
if (BC->QueryDoubleAttribute("MUR_PhaseVelocity",&v_ph) == TIXML_SUCCESS)
|
|
|
|
op_ext_mur->SetPhaseVelocity(v_ph);
|
2010-07-30 13:28:15 +00:00
|
|
|
FDTD_Op->AddExtension(op_ext_mur);
|
|
|
|
}
|
|
|
|
}
|
2010-07-30 15:51:39 +00:00
|
|
|
Build_Split_Field_PML(FDTD_Op,bounds,pml_size,pml_gradFunc);
|
2010-07-30 13:28:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
int openEMS::SetupFDTD(const char* file)
|
|
|
|
{
|
|
|
|
if (file==NULL) return -1;
|
|
|
|
Reset();
|
|
|
|
|
2010-06-05 22:47:56 +00:00
|
|
|
timeval startTime;
|
|
|
|
gettimeofday(&startTime,NULL);
|
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
|
|
|
|
TiXmlDocument doc(file);
|
|
|
|
if (!doc.LoadFile())
|
|
|
|
{
|
|
|
|
cerr << "openEMS: Error File-Loading failed!!! File: " << file << endl;
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2010-03-12 19:39:04 +00:00
|
|
|
cout << "Read openEMS Settings..." << endl;
|
2010-03-12 20:14:17 +00:00
|
|
|
TiXmlElement* openEMSxml = doc.FirstChildElement("openEMS");
|
|
|
|
if (openEMSxml==NULL)
|
|
|
|
{
|
|
|
|
cerr << "Can't read openEMS ... " << endl;
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
TiXmlElement* FDTD_Opts = openEMSxml->FirstChildElement("FDTD");
|
2010-04-07 14:31:23 +00:00
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
if (FDTD_Opts==NULL)
|
|
|
|
{
|
2010-03-12 20:14:17 +00:00
|
|
|
cerr << "Can't read openEMS FDTD Settings... " << endl;
|
2010-03-11 09:56:19 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
2010-03-29 08:12:38 +00:00
|
|
|
int help=0;
|
|
|
|
FDTD_Opts->QueryIntAttribute("NumberOfTimesteps",&help);
|
|
|
|
if (help<0)
|
|
|
|
NrTS=0;
|
|
|
|
else
|
|
|
|
NrTS = help;
|
2010-04-07 14:31:23 +00:00
|
|
|
|
2010-04-16 11:13:01 +00:00
|
|
|
help = 0;
|
2010-04-09 13:51:37 +00:00
|
|
|
FDTD_Opts->QueryIntAttribute("CylinderCoords",&help);
|
|
|
|
if (help==1)
|
|
|
|
{
|
2010-05-19 19:25:15 +00:00
|
|
|
// cout << "Using a cylinder coordinate FDTD..." << endl;
|
2010-04-09 13:51:37 +00:00
|
|
|
CylinderCoords = true;
|
|
|
|
}
|
|
|
|
|
2010-03-15 19:50:49 +00:00
|
|
|
FDTD_Opts->QueryDoubleAttribute("endCriteria",&endCrit);
|
|
|
|
if (endCrit==0)
|
|
|
|
endCrit=1e-6;
|
2010-03-11 09:56:19 +00:00
|
|
|
|
2010-04-04 17:48:36 +00:00
|
|
|
FDTD_Opts->QueryIntAttribute("OverSampling",&m_OverSampling);
|
|
|
|
if (m_OverSampling<2)
|
|
|
|
m_OverSampling=2;
|
|
|
|
|
2010-05-21 14:55:04 +00:00
|
|
|
double maxTime=0;
|
|
|
|
FDTD_Opts->QueryDoubleAttribute("MaxTime",&maxTime);
|
|
|
|
|
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
TiXmlElement* BC = FDTD_Opts->FirstChildElement("BoundaryCond");
|
|
|
|
if (BC==NULL)
|
|
|
|
{
|
|
|
|
cerr << "Can't read openEMS boundary cond Settings... " << endl;
|
|
|
|
exit(-3);
|
|
|
|
}
|
|
|
|
|
2010-03-12 19:39:04 +00:00
|
|
|
cout << "Read Geometry..." << endl;
|
2010-03-11 09:56:19 +00:00
|
|
|
ContinuousStructure CSX;
|
2010-03-12 20:14:17 +00:00
|
|
|
string EC(CSX.ReadFromXML(openEMSxml));
|
2010-03-11 09:56:19 +00:00
|
|
|
if (EC.empty()==false)
|
|
|
|
{
|
|
|
|
cerr << EC << endl;
|
2010-05-29 15:16:25 +00:00
|
|
|
// return(-2);
|
2010-03-11 09:56:19 +00:00
|
|
|
}
|
|
|
|
|
2010-07-08 09:28:11 +00:00
|
|
|
if (m_debugCSX)
|
|
|
|
CSX.Write2XML("debugCSX.xml");
|
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
//*************** setup operator ************//
|
2010-04-09 13:51:37 +00:00
|
|
|
if (CylinderCoords)
|
|
|
|
{
|
2010-06-05 23:50:58 +00:00
|
|
|
FDTD_Op = Operator_Cylinder::New(m_engine_numThreads);
|
2010-04-13 16:40:43 +00:00
|
|
|
CSX.SetCoordInputType(1); //tell CSX to use cylinder-coords
|
2010-04-09 13:51:37 +00:00
|
|
|
}
|
2010-04-21 13:38:15 +00:00
|
|
|
else if (m_engine == EngineType_SSE)
|
|
|
|
{
|
|
|
|
FDTD_Op = Operator_sse::New();
|
|
|
|
}
|
2010-05-19 09:41:35 +00:00
|
|
|
else if (m_engine == EngineType_SSE_Compressed)
|
|
|
|
{
|
|
|
|
FDTD_Op = Operator_SSE_Compressed::New();
|
|
|
|
}
|
2010-05-20 20:02:06 +00:00
|
|
|
else if (m_engine == EngineType_Multithreaded)
|
|
|
|
{
|
2010-06-05 09:50:13 +00:00
|
|
|
FDTD_Op = Operator_Multithread::New(m_engine_numThreads);
|
2010-05-20 20:02:06 +00:00
|
|
|
}
|
2010-04-09 13:51:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FDTD_Op = Operator::New();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FDTD_Op->SetGeometryCSX(&CSX)==false) return(2);
|
2010-03-11 09:56:19 +00:00
|
|
|
|
2010-07-30 13:28:15 +00:00
|
|
|
SetupBoundaryConditions(BC);
|
2010-04-27 21:06:42 +00:00
|
|
|
|
2010-07-06 08:01:26 +00:00
|
|
|
if (CSX.GetQtyPropertyType(CSProperties::LORENTZMATERIAL)>0)
|
|
|
|
FDTD_Op->AddExtension(new Operator_Ext_LorentzMaterial(FDTD_Op));
|
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
FDTD_Op->CalcECOperator();
|
2010-05-21 14:55:04 +00:00
|
|
|
|
|
|
|
unsigned int maxTime_TS = (unsigned int)(maxTime/FDTD_Op->GetTimestep());
|
|
|
|
if ((maxTime_TS>0) && (maxTime_TS<NrTS))
|
|
|
|
NrTS = maxTime_TS;
|
2010-03-11 09:56:19 +00:00
|
|
|
|
2010-05-03 16:33:14 +00:00
|
|
|
if (!FDTD_Op->Exc->setupExcitation( FDTD_Opts->FirstChildElement("Excitation"), NrTS ))
|
|
|
|
exit(2);
|
2010-04-02 15:20:18 +00:00
|
|
|
|
2010-03-27 22:05:45 +00:00
|
|
|
if (DebugMat)
|
|
|
|
{
|
|
|
|
FDTD_Op->DumpMaterial2File("material_dump.vtk");
|
|
|
|
}
|
2010-05-29 10:47:07 +00:00
|
|
|
if (DebugOp)
|
2010-03-27 22:05:45 +00:00
|
|
|
FDTD_Op->DumpOperator2File("operator_dump.vtk");
|
2010-06-02 14:37:21 +00:00
|
|
|
if (m_debugPEC)
|
|
|
|
FDTD_Op->DumpPEC2File("PEC_dump.vtk");
|
2010-03-27 22:05:45 +00:00
|
|
|
|
2010-06-05 22:47:56 +00:00
|
|
|
timeval OpDoneTime;
|
|
|
|
gettimeofday(&OpDoneTime,NULL);
|
2010-03-11 09:56:19 +00:00
|
|
|
|
2010-03-29 20:11:24 +00:00
|
|
|
FDTD_Op->ShowStat();
|
2010-07-11 21:45:41 +00:00
|
|
|
FDTD_Op->ShowExtStat();
|
2010-03-11 09:56:19 +00:00
|
|
|
|
2010-06-05 22:47:56 +00:00
|
|
|
cout << "Creation time for operator: " << CalcDiffTime(OpDoneTime,startTime) << " s" << endl;
|
2010-03-11 09:56:19 +00:00
|
|
|
|
|
|
|
//create FDTD engine
|
2010-05-20 20:02:06 +00:00
|
|
|
FDTD_Eng = FDTD_Op->CreateEngine();
|
2010-03-26 11:57:52 +00:00
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
//*************** setup processing ************//
|
2010-03-12 19:39:04 +00:00
|
|
|
cout << "Setting up processing..." << endl;
|
2010-05-03 16:33:14 +00:00
|
|
|
unsigned int Nyquist = FDTD_Op->Exc->GetNyquistNum();
|
2010-03-15 21:19:51 +00:00
|
|
|
PA = new ProcessingArray(Nyquist);
|
2010-03-11 09:56:19 +00:00
|
|
|
|
|
|
|
double start[3];
|
|
|
|
double stop[3];
|
|
|
|
vector<CSProperties*> Probes = CSX.GetPropertyByType(CSProperties::PROBEBOX);
|
|
|
|
for (size_t i=0;i<Probes.size();++i)
|
|
|
|
{
|
|
|
|
//only looking for one prim atm
|
|
|
|
CSPrimitives* prim = Probes.at(i)->GetPrimitive(0);
|
|
|
|
if (prim!=NULL)
|
|
|
|
{
|
|
|
|
bool acc;
|
2010-06-05 16:00:53 +00:00
|
|
|
double bnd[6] = {0,0,0,0,0,0};
|
|
|
|
acc = prim->GetBoundBox(bnd,true);
|
2010-03-11 09:56:19 +00:00
|
|
|
start[0]= bnd[0];start[1]=bnd[2];start[2]=bnd[4];
|
|
|
|
stop[0] = bnd[1];stop[1] =bnd[3];stop[2] =bnd[5];
|
|
|
|
CSPropProbeBox* pb = Probes.at(i)->ToProbeBox();
|
|
|
|
Processing* proc = NULL;
|
|
|
|
if (pb)
|
|
|
|
{
|
|
|
|
if (pb->GetProbeType()==0)
|
|
|
|
{
|
|
|
|
ProcessVoltage* procVolt = new ProcessVoltage(FDTD_Op,FDTD_Eng);
|
|
|
|
proc=procVolt;
|
|
|
|
}
|
2010-06-25 13:22:01 +00:00
|
|
|
else if (pb->GetProbeType()==1)
|
2010-03-11 09:56:19 +00:00
|
|
|
{
|
|
|
|
ProcessCurrent* procCurr = new ProcessCurrent(FDTD_Op,FDTD_Eng);
|
|
|
|
proc=procCurr;
|
|
|
|
}
|
2010-07-16 13:55:35 +00:00
|
|
|
else if (pb->GetProbeType()==2)
|
|
|
|
proc = new ProcessEField(FDTD_Op,FDTD_Eng);
|
2010-07-19 06:41:53 +00:00
|
|
|
else if (pb->GetProbeType()==3)
|
|
|
|
proc = new ProcessHField(FDTD_Op,FDTD_Eng);
|
2010-08-16 09:53:43 +00:00
|
|
|
else if ((pb->GetProbeType()==10) || (pb->GetProbeType()==11))
|
|
|
|
{
|
|
|
|
ProcessModeMatch* pmm = new ProcessModeMatch(FDTD_Op,FDTD_Eng);
|
|
|
|
pmm->SetFieldType(pb->GetProbeType()-10);
|
|
|
|
pmm->SetModeFunction(0,pb->GetAttributeValue("ModeFunctionX"));
|
|
|
|
pmm->SetModeFunction(1,pb->GetAttributeValue("ModeFunctionY"));
|
|
|
|
pmm->SetModeFunction(2,pb->GetAttributeValue("ModeFunctionZ"));
|
|
|
|
proc = pmm;
|
|
|
|
}
|
2010-06-25 13:22:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
cerr << "openEMS::SetupFDTD: Warning: Probe type " << pb->GetProbeType() << " of property '" << pb->GetName() << "' is unknown..." << endl;
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-11 16:46:47 +00:00
|
|
|
if (CylinderCoords)
|
|
|
|
proc->SetMeshType(Processing::CYLINDRICAL_MESH);
|
2010-04-04 17:48:36 +00:00
|
|
|
proc->SetProcessInterval(Nyquist/m_OverSampling);
|
2010-06-28 16:05:03 +00:00
|
|
|
proc->AddFrequency(pb->GetFDSamples());
|
2010-07-16 13:55:35 +00:00
|
|
|
proc->SetName(pb->GetName());
|
2010-03-11 09:56:19 +00:00
|
|
|
proc->DefineStartStopCoord(start,stop);
|
2010-06-16 10:50:19 +00:00
|
|
|
proc->SetWeight(pb->GetWeighting());
|
2010-06-28 16:27:41 +00:00
|
|
|
proc->InitProcess();
|
2010-03-11 09:56:19 +00:00
|
|
|
PA->AddProcessing(proc);
|
2010-05-29 15:40:18 +00:00
|
|
|
prim->SetPrimitiveUsed(true);
|
2010-03-11 09:56:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
delete proc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<CSProperties*> DumpProps = CSX.GetPropertyByType(CSProperties::DUMPBOX);
|
|
|
|
for (size_t i=0;i<DumpProps.size();++i)
|
|
|
|
{
|
|
|
|
ProcessFieldsTD* ProcTD = new ProcessFieldsTD(FDTD_Op,FDTD_Eng);
|
2010-03-11 14:48:55 +00:00
|
|
|
ProcTD->SetEnable(Enable_Dumps);
|
2010-04-04 17:48:36 +00:00
|
|
|
ProcTD->SetProcessInterval(Nyquist/m_OverSampling);
|
2010-03-11 09:56:19 +00:00
|
|
|
|
|
|
|
//only looking for one prim atm
|
|
|
|
CSPrimitives* prim = DumpProps.at(i)->GetPrimitive(0);
|
|
|
|
if (prim==NULL)
|
|
|
|
delete ProcTD;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool acc;
|
2010-06-05 16:00:53 +00:00
|
|
|
double bnd[6] = {0,0,0,0,0,0};
|
|
|
|
acc = prim->GetBoundBox(bnd,true);
|
2010-03-11 09:56:19 +00:00
|
|
|
start[0]= bnd[0];start[1]=bnd[2];start[2]=bnd[4];
|
|
|
|
stop[0] = bnd[1];stop[1] =bnd[3];stop[2] =bnd[5];
|
|
|
|
CSPropDumpBox* db = DumpProps.at(i)->ToDumpBox();
|
|
|
|
if (db)
|
|
|
|
{
|
2010-04-05 18:22:03 +00:00
|
|
|
ProcTD->SetDumpType((ProcessFields::DumpType)db->GetDumpType());
|
|
|
|
ProcTD->SetDumpMode((ProcessFields::DumpMode)db->GetDumpMode());
|
|
|
|
ProcTD->SetFileType((ProcessFields::FileType)db->GetFileType());
|
2010-06-02 12:18:25 +00:00
|
|
|
if (CylinderCoords)
|
2010-08-11 16:46:47 +00:00
|
|
|
ProcTD->SetMeshType(Processing::CYLINDRICAL_MESH);
|
2010-04-07 10:57:45 +00:00
|
|
|
for (int n=0;n<3;++n)
|
|
|
|
ProcTD->SetSubSampling(db->GetSubSampling(n),n);
|
2010-03-11 09:56:19 +00:00
|
|
|
ProcTD->SetFilePattern(db->GetName());
|
2010-04-05 18:22:03 +00:00
|
|
|
ProcTD->SetFileName(db->GetName());
|
2010-03-11 09:56:19 +00:00
|
|
|
ProcTD->DefineStartStopCoord(start,stop);
|
2010-04-05 18:22:03 +00:00
|
|
|
ProcTD->InitProcess();
|
2010-03-11 09:56:19 +00:00
|
|
|
PA->AddProcessing(ProcTD);
|
2010-05-29 15:40:18 +00:00
|
|
|
prim->SetPrimitiveUsed(true);
|
2010-03-11 09:56:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
delete ProcTD;
|
|
|
|
}
|
|
|
|
}
|
2010-04-19 14:09:41 +00:00
|
|
|
|
2010-05-29 15:40:18 +00:00
|
|
|
CSX.WarnUnusedPrimitves(cerr);
|
|
|
|
|
2010-04-19 14:09:41 +00:00
|
|
|
// dump all boxes (voltage, current, fields, ...)
|
|
|
|
if (m_debugBox)
|
|
|
|
{
|
|
|
|
PA->DumpBoxes2File("box_dump_");
|
|
|
|
}
|
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-21 14:14:41 +00:00
|
|
|
string FormatTime(int sec)
|
|
|
|
{
|
|
|
|
stringstream ss;
|
|
|
|
if (sec<60)
|
|
|
|
{
|
2010-06-25 13:22:01 +00:00
|
|
|
ss << setw(9) << sec << "s";
|
2010-06-21 14:14:41 +00:00
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
if (sec<3600)
|
|
|
|
{
|
2010-06-25 13:22:01 +00:00
|
|
|
ss << setw(6) << sec/60 << "m" << setw(2) << setfill('0') << sec%60 << "s";
|
2010-06-21 14:14:41 +00:00
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
ss << setw(3) << sec/3600 << "h" << setw(2) << setfill('0') << (sec%3600)/60 << "m" << setw(2) << setfill('0') << sec%60 << "s";
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
void openEMS::RunFDTD()
|
|
|
|
{
|
2010-03-29 20:11:24 +00:00
|
|
|
cout << "Running FDTD engine... this may take a while... grab a cup of coffee?!?" << endl;
|
2010-03-25 14:08:54 +00:00
|
|
|
|
2010-04-03 15:36:50 +00:00
|
|
|
//special handling of a field processing, needed to realize the end criteria...
|
|
|
|
ProcessFields* ProcField = new ProcessFields(FDTD_Op,FDTD_Eng);
|
|
|
|
PA->AddProcessing(ProcField);
|
2010-03-15 15:59:37 +00:00
|
|
|
double maxE=0,currE=0;
|
2010-04-03 15:36:50 +00:00
|
|
|
|
|
|
|
//add all timesteps to end-crit field processing with max excite amplitude
|
2010-05-03 16:33:14 +00:00
|
|
|
unsigned int maxExcite = FDTD_Op->Exc->GetMaxExcitationTimestep();
|
|
|
|
for (unsigned int n=0;n<FDTD_Op->Exc->E_Count;++n)
|
|
|
|
ProcField->AddStep(FDTD_Op->Exc->E_delay[n]+maxExcite);
|
2010-04-03 15:36:50 +00:00
|
|
|
|
2010-03-15 15:59:37 +00:00
|
|
|
double change=1;
|
|
|
|
int prevTS=0,currTS=0;
|
2010-03-27 14:54:44 +00:00
|
|
|
double speed = FDTD_Op->GetNumberCells()/1e6;
|
2010-03-15 15:59:37 +00:00
|
|
|
double t_diff;
|
2010-03-27 14:54:44 +00:00
|
|
|
|
|
|
|
timeval currTime;
|
|
|
|
gettimeofday(&currTime,NULL);
|
|
|
|
timeval startTime = currTime;
|
|
|
|
timeval prevTime= currTime;
|
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
//*************** simulate ************//
|
2010-03-27 14:54:44 +00:00
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
int step=PA->Process();
|
2010-03-29 08:12:38 +00:00
|
|
|
if ((step<0) || (step>(int)NrTS)) step=NrTS;
|
2010-03-15 15:59:37 +00:00
|
|
|
while ((FDTD_Eng->GetNumberOfTimesteps()<NrTS) && (change>endCrit))
|
2010-03-11 09:56:19 +00:00
|
|
|
{
|
|
|
|
FDTD_Eng->IterateTS(step);
|
|
|
|
step=PA->Process();
|
2010-04-03 15:36:50 +00:00
|
|
|
|
|
|
|
if (ProcField->CheckTimestep())
|
|
|
|
{
|
|
|
|
currE = ProcField->CalcTotalEnergy();
|
|
|
|
if (currE>maxE)
|
|
|
|
maxE=currE;
|
|
|
|
}
|
|
|
|
|
2010-03-12 19:39:04 +00:00
|
|
|
// cout << " do " << step << " steps; current: " << eng.GetNumberOfTimesteps() << endl;
|
2010-03-15 15:59:37 +00:00
|
|
|
currTS = FDTD_Eng->GetNumberOfTimesteps();
|
2010-03-29 08:12:38 +00:00
|
|
|
if ((step<0) || (step>(int)(NrTS - currTS))) step=NrTS - currTS;
|
2010-03-15 15:59:37 +00:00
|
|
|
|
2010-03-25 14:08:54 +00:00
|
|
|
gettimeofday(&currTime,NULL);
|
|
|
|
|
|
|
|
t_diff = CalcDiffTime(currTime,prevTime);
|
2010-03-15 15:59:37 +00:00
|
|
|
if (t_diff>4)
|
|
|
|
{
|
2010-04-03 15:36:50 +00:00
|
|
|
currE = ProcField->CalcTotalEnergy();
|
2010-03-15 21:19:51 +00:00
|
|
|
if (currE>maxE)
|
2010-03-15 15:59:37 +00:00
|
|
|
maxE=currE;
|
2010-06-21 14:14:41 +00:00
|
|
|
cout << "[@" << FormatTime(CalcDiffTime(currTime,startTime)) << "] Timestep: " << setw(12) << currTS << " (" << setw(6) << setprecision(2) << std::fixed << (double)currTS/(double)NrTS*100.0 << "%)" ;
|
2010-03-27 14:54:44 +00:00
|
|
|
cout << " with currently " << setw(6) << setprecision(1) << std::fixed << speed*(currTS-prevTS)/t_diff << " MCells/s" ;
|
2010-03-15 21:19:51 +00:00
|
|
|
if (maxE)
|
|
|
|
change = currE/maxE;
|
|
|
|
cout << " --- Energy: ~" << setw(6) << setprecision(2) << std::scientific << currE << " (decrement: " << setw(6) << setprecision(2) << std::fixed << fabs(10.0*log10(change)) << "dB)" << endl;
|
2010-03-15 15:59:37 +00:00
|
|
|
prevTime=currTime;
|
|
|
|
prevTS=currTS;
|
2010-06-28 16:05:03 +00:00
|
|
|
|
|
|
|
PA->FlushNext();
|
2010-03-15 15:59:37 +00:00
|
|
|
}
|
2010-03-11 09:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//*************** postproc ************//
|
2010-03-15 15:59:37 +00:00
|
|
|
prevTime = currTime;
|
2010-03-25 14:08:54 +00:00
|
|
|
gettimeofday(&currTime,NULL);
|
2010-03-11 09:56:19 +00:00
|
|
|
|
2010-03-25 14:08:54 +00:00
|
|
|
t_diff = CalcDiffTime(currTime,startTime);
|
2010-03-11 09:56:19 +00:00
|
|
|
|
2010-03-12 19:39:04 +00:00
|
|
|
cout << "Time for " << FDTD_Eng->GetNumberOfTimesteps() << " iterations with " << FDTD_Op->GetNumberCells() << " cells : " << t_diff << " sec" << endl;
|
2010-03-15 15:59:37 +00:00
|
|
|
cout << "Speed: " << speed*(double)FDTD_Eng->GetNumberOfTimesteps()/t_diff << " MCells/s " << endl;
|
2010-03-11 09:56:19 +00:00
|
|
|
}
|