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"
|
2011-11-08 10:49:14 +00:00
|
|
|
#include "tools/useful.h"
|
2010-05-06 20:55:59 +00:00
|
|
|
#include "FDTD/operator_cylinder.h"
|
2010-09-08 05:36:32 +00:00
|
|
|
#include "FDTD/operator_cylindermultigrid.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-12-06 14:30:47 +00:00
|
|
|
#include "FDTD/extensions/operator_ext_mur_abc.h"
|
|
|
|
#include "FDTD/extensions/operator_ext_pml_sf.h"
|
|
|
|
#include "FDTD/extensions/operator_ext_upml.h"
|
|
|
|
#include "FDTD/extensions/operator_ext_lorentzmaterial.h"
|
2010-12-02 12:51:34 +00:00
|
|
|
#include "FDTD/engine_interface_fdtd.h"
|
2011-04-13 10:16:54 +00:00
|
|
|
#include "FDTD/engine_interface_cylindrical_fdtd.h"
|
2010-12-06 09:44:25 +00:00
|
|
|
#include "Common/processvoltage.h"
|
|
|
|
#include "Common/processcurrent.h"
|
2011-01-18 09:45:03 +00:00
|
|
|
#include "Common/processfieldprobe.h"
|
2010-12-06 09:44:25 +00:00
|
|
|
#include "Common/processmodematch.h"
|
|
|
|
#include "Common/processfields_td.h"
|
2010-12-19 19:41:08 +00:00
|
|
|
#include "Common/processfields_fd.h"
|
2011-01-31 11:25:55 +00:00
|
|
|
#include "Common/processfields_sar.h"
|
2010-09-17 13:32:11 +00:00
|
|
|
#include <H5Cpp.h> // only for H5get_libversion()
|
2010-10-04 09:35:20 +00:00
|
|
|
#include <boost/version.hpp> // only for BOOST_LIB_VERSION
|
2011-04-08 10:27:42 +00:00
|
|
|
#include <vtkVersion.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;
|
2011-01-31 11:00:00 +00:00
|
|
|
m_CSX=NULL;
|
2010-03-11 09:56:19 +00:00
|
|
|
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-08-16 21:17:19 +00:00
|
|
|
m_debugBox = m_debugPEC = m_no_simulation = 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
|
|
|
|
2010-12-06 14:27:48 +00:00
|
|
|
m_engine = EngineType_Multithreaded; //default engine type
|
2010-03-30 11:13:00 +00:00
|
|
|
m_engine_numThreads = 0;
|
2010-10-18 11:26:25 +00:00
|
|
|
|
|
|
|
m_Abort = false;
|
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-12-06 12:04:37 +00:00
|
|
|
delete PA;
|
|
|
|
PA=0;
|
|
|
|
delete FDTD_Eng;
|
|
|
|
FDTD_Eng=0;
|
|
|
|
delete FDTD_Op;
|
|
|
|
FDTD_Op=0;
|
2011-01-31 11:00:00 +00:00
|
|
|
delete m_CSX;
|
|
|
|
m_CSX=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-12-06 14:27:48 +00:00
|
|
|
else if (strcmp(argv,"--engine=basic")==0)
|
2010-03-26 11:57:52 +00:00
|
|
|
{
|
2010-12-06 14:27:48 +00:00
|
|
|
cout << "openEMS - enabled basic engine" << endl;
|
|
|
|
m_engine = EngineType_Basic;
|
2010-03-30 11:13:00 +00:00
|
|
|
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-12-06 14:27:48 +00:00
|
|
|
else if (strcmp(argv,"--engine=multithreaded")==0)
|
|
|
|
{
|
|
|
|
cout << "openEMS - enabled multithreading" << endl;
|
|
|
|
m_engine = EngineType_Multithreaded;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
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-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-08-16 21:17:19 +00:00
|
|
|
else if (strcmp(argv,"--no-simulation")==0)
|
|
|
|
{
|
|
|
|
cout << "openEMS - disabling simulation => preprocessing only" << endl;
|
|
|
|
m_no_simulation = true;
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-26 10:57:53 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-25 06:17:45 +00:00
|
|
|
string openEMS::GetExtLibsInfo()
|
|
|
|
{
|
|
|
|
stringstream str;
|
|
|
|
|
|
|
|
str << "\tUsed external libraries:" << endl;
|
|
|
|
str << "\t\t" << ContinuousStructure::GetInfoLine(true) << endl;
|
|
|
|
|
2010-09-17 13:32:11 +00:00
|
|
|
// libhdf5
|
|
|
|
unsigned int major, minor, release;
|
|
|
|
if (H5get_libversion( &major, &minor, &release ) >= 0)
|
|
|
|
{
|
|
|
|
str << "\t\t" << "hdf5 -- Version: " << major << '.' << minor << '.' << release << endl;
|
|
|
|
str << "\t\t" << " compiled against: " H5_VERS_INFO << endl;
|
|
|
|
}
|
|
|
|
|
2010-10-04 09:35:20 +00:00
|
|
|
// tinyxml
|
|
|
|
str << "\t\t" << "tinyxml -- compiled against: " << TIXML_MAJOR_VERSION << '.' << TIXML_MINOR_VERSION << '.' << TIXML_PATCH_VERSION << endl;
|
|
|
|
|
2011-11-28 10:58:41 +00:00
|
|
|
// fparser
|
|
|
|
str << "\t\t" << "fparser" << endl;
|
|
|
|
|
2010-10-04 09:35:20 +00:00
|
|
|
// boost
|
2011-04-08 10:27:42 +00:00
|
|
|
str << "\t\t" << "boost -- compiled against: " << BOOST_LIB_VERSION << endl;
|
|
|
|
|
|
|
|
//vtk
|
|
|
|
str << "\t\t" << "vtk -- Version: " << vtkVersion::GetVTKMajorVersion() << "." << vtkVersion::GetVTKMinorVersion() << "." << vtkVersion::GetVTKBuildVersion() << endl;
|
|
|
|
str << "\t\t" << " compiled against: " << VTK_VERSION << endl;
|
2010-10-04 09:35:20 +00:00
|
|
|
|
2010-08-25 06:17:45 +00:00
|
|
|
return str.str();
|
|
|
|
}
|
|
|
|
|
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)
|
2010-10-04 09:52:39 +00:00
|
|
|
unsigned int pml_size[6] = {8,8,8,8,8,8}; //default pml size
|
2010-07-30 13:28:15 +00:00
|
|
|
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"};
|
|
|
|
|
2010-12-06 12:04:37 +00:00
|
|
|
for (int n=0; n<6; ++n)
|
2010-07-30 13:28:15 +00:00
|
|
|
{
|
|
|
|
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;
|
2010-12-06 12:04:37 +00:00
|
|
|
else if (strncmp(s_bc.c_str(),"PML_=",4)==0)
|
2010-07-30 13:28:15 +00:00
|
|
|
{
|
|
|
|
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
|
2010-10-14 10:19:31 +00:00
|
|
|
double mur_v_ph = 0;
|
|
|
|
//read general mur phase velocity
|
|
|
|
if (BC->QueryDoubleAttribute("MUR_PhaseVelocity",&mur_v_ph) != TIXML_SUCCESS)
|
|
|
|
mur_v_ph = -1;
|
|
|
|
string mur_v_ph_names[6] = {"MUR_PhaseVelocity_xmin", "MUR_PhaseVelocity_xmax", "MUR_PhaseVelocity_ymin", "MUR_PhaseVelocity_ymax", "MUR_PhaseVelocity_zmin", "MUR_PhaseVelocity_zmax"};
|
2010-12-06 12:04:37 +00:00
|
|
|
for (int n=0; n<6; ++n)
|
2010-07-30 13:28:15 +00:00
|
|
|
{
|
|
|
|
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;
|
2010-10-14 10:19:31 +00:00
|
|
|
//read special mur phase velocity or assign general phase velocity
|
|
|
|
if (BC->QueryDoubleAttribute(mur_v_ph_names[n].c_str(),&v_ph) == TIXML_SUCCESS)
|
2010-08-10 05:50:53 +00:00
|
|
|
op_ext_mur->SetPhaseVelocity(v_ph);
|
2010-10-14 10:19:31 +00:00
|
|
|
else if (mur_v_ph>0)
|
|
|
|
op_ext_mur->SetPhaseVelocity(mur_v_ph);
|
2010-07-30 13:28:15 +00:00
|
|
|
FDTD_Op->AddExtension(op_ext_mur);
|
|
|
|
}
|
|
|
|
}
|
2010-10-04 09:52:39 +00:00
|
|
|
|
|
|
|
//create the upml
|
|
|
|
Operator_Ext_UPML::Create_UPML(FDTD_Op,bounds,pml_size,pml_gradFunc);
|
2010-07-30 13:28:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-04-13 10:16:54 +00:00
|
|
|
Engine_Interface_FDTD* openEMS::NewEngineInterface()
|
|
|
|
{
|
|
|
|
Operator_Cylinder* op_cyl = dynamic_cast<Operator_Cylinder*>(FDTD_Op);
|
2011-11-07 11:07:55 +00:00
|
|
|
Engine_sse* eng_sse = dynamic_cast<Engine_sse*>(FDTD_Eng);
|
|
|
|
if (op_cyl && eng_sse)
|
|
|
|
return new Engine_Interface_Cylindrical_FDTD(op_cyl,eng_sse);
|
|
|
|
Operator_sse* op_sse = dynamic_cast<Operator_sse*>(FDTD_Op);
|
|
|
|
if (op_sse && eng_sse)
|
|
|
|
return new Engine_Interface_SSE_FDTD(op_sse,eng_sse);
|
2011-04-13 10:16:54 +00:00
|
|
|
return new Engine_Interface_FDTD(FDTD_Op,FDTD_Eng);
|
|
|
|
}
|
|
|
|
|
2011-01-31 11:00:00 +00:00
|
|
|
bool openEMS::SetupProcessing()
|
2011-01-10 07:27:50 +00:00
|
|
|
{
|
|
|
|
//*************** setup processing ************//
|
2011-11-08 10:49:14 +00:00
|
|
|
if (g_settings.GetVerboseLevel()>0)
|
|
|
|
cout << "Setting up processing..." << endl;
|
2011-01-10 07:27:50 +00:00
|
|
|
|
|
|
|
unsigned int Nyquist = FDTD_Op->Exc->GetNyquistNum();
|
|
|
|
PA = new ProcessingArray(Nyquist);
|
|
|
|
|
|
|
|
double start[3];
|
|
|
|
double stop[3];
|
2011-08-31 09:05:04 +00:00
|
|
|
bool l_MultiBox = false;
|
2011-01-31 11:00:00 +00:00
|
|
|
vector<CSProperties*> Probes = m_CSX->GetPropertyByType(CSProperties::PROBEBOX);
|
2011-01-10 07:27:50 +00:00
|
|
|
for (size_t i=0; i<Probes.size(); ++i)
|
|
|
|
{
|
2011-08-31 09:05:04 +00:00
|
|
|
//check whether one or more probe boxes are defined
|
|
|
|
l_MultiBox = (Probes.at(i)->GetQtyPrimitives()>1);
|
|
|
|
|
|
|
|
for (size_t nb=0; nb<Probes.at(i)->GetQtyPrimitives(); ++nb)
|
2011-01-10 07:27:50 +00:00
|
|
|
{
|
2011-08-31 09:05:04 +00:00
|
|
|
CSPrimitives* prim = Probes.at(i)->GetPrimitive(nb);
|
|
|
|
if (prim!=NULL)
|
2011-01-10 07:27:50 +00:00
|
|
|
{
|
2011-08-31 09:05:04 +00:00
|
|
|
double bnd[6] = {0,0,0,0,0,0};
|
2011-11-07 11:04:34 +00:00
|
|
|
prim->GetBoundBox(bnd,true);
|
2011-08-31 09:05:04 +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)
|
2011-01-10 07:27:50 +00:00
|
|
|
{
|
2011-08-31 09:05:04 +00:00
|
|
|
if (pb->GetProbeType()==0)
|
|
|
|
{
|
|
|
|
ProcessVoltage* procVolt = new ProcessVoltage(NewEngineInterface());
|
|
|
|
proc=procVolt;
|
|
|
|
}
|
|
|
|
else if (pb->GetProbeType()==1)
|
|
|
|
{
|
|
|
|
ProcessCurrent* procCurr = new ProcessCurrent(NewEngineInterface());
|
|
|
|
proc=procCurr;
|
|
|
|
}
|
|
|
|
else if (pb->GetProbeType()==2)
|
|
|
|
proc = new ProcessFieldProbe(NewEngineInterface(),0);
|
|
|
|
else if (pb->GetProbeType()==3)
|
|
|
|
proc = new ProcessFieldProbe(NewEngineInterface(),1);
|
|
|
|
else if ((pb->GetProbeType()==10) || (pb->GetProbeType()==11))
|
|
|
|
{
|
|
|
|
ProcessModeMatch* pmm = new ProcessModeMatch(NewEngineInterface());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cerr << "openEMS::SetupFDTD: Warning: Probe type " << pb->GetProbeType() << " of property '" << pb->GetName() << "' is unknown..." << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (CylinderCoords)
|
|
|
|
proc->SetMeshType(Processing::CYLINDRICAL_MESH);
|
|
|
|
if ((pb->GetProbeType()==1) || (pb->GetProbeType()==3) || (pb->GetProbeType()==11))
|
|
|
|
{
|
|
|
|
proc->SetDualTime(true);
|
|
|
|
proc->SetDualMesh(true);
|
|
|
|
}
|
|
|
|
proc->SetProcessInterval(Nyquist/m_OverSampling);
|
|
|
|
proc->AddFrequency(pb->GetFDSamples());
|
|
|
|
if (l_MultiBox==false)
|
|
|
|
proc->SetName(pb->GetName());
|
|
|
|
else
|
|
|
|
proc->SetName(pb->GetName(),nb);
|
|
|
|
proc->DefineStartStopCoord(start,stop);
|
|
|
|
if (g_settings.showProbeDiscretization())
|
|
|
|
proc->ShowSnappedCoords();
|
|
|
|
proc->SetWeight(pb->GetWeighting());
|
|
|
|
PA->AddProcessing(proc);
|
|
|
|
prim->SetPrimitiveUsed(true);
|
2011-01-10 07:27:50 +00:00
|
|
|
}
|
|
|
|
else
|
2011-08-31 09:05:04 +00:00
|
|
|
delete proc;
|
2011-01-10 07:27:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-31 11:00:00 +00:00
|
|
|
vector<CSProperties*> DumpProps = m_CSX->GetPropertyByType(CSProperties::DUMPBOX);
|
2011-01-10 07:27:50 +00:00
|
|
|
for (size_t i=0; i<DumpProps.size(); ++i)
|
|
|
|
{
|
|
|
|
ProcessFields* ProcField=NULL;
|
|
|
|
|
2011-08-31 09:05:04 +00:00
|
|
|
//check whether one or more probe boxes are defined
|
|
|
|
l_MultiBox = (DumpProps.at(i)->GetQtyPrimitives()>1);
|
|
|
|
|
|
|
|
for (size_t nb=0; nb<DumpProps.at(i)->GetQtyPrimitives(); ++nb)
|
2011-01-10 07:27:50 +00:00
|
|
|
{
|
2011-08-31 09:05:04 +00:00
|
|
|
|
|
|
|
CSPrimitives* prim = DumpProps.at(i)->GetPrimitive(nb);
|
|
|
|
if (prim!=NULL)
|
2011-01-10 07:27:50 +00:00
|
|
|
{
|
2011-08-31 09:05:04 +00:00
|
|
|
double bnd[6] = {0,0,0,0,0,0};
|
2011-11-07 11:04:34 +00:00
|
|
|
prim->GetBoundBox(bnd,true);
|
2011-08-31 09:05:04 +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)
|
2011-01-10 07:27:50 +00:00
|
|
|
{
|
2011-08-31 09:05:04 +00:00
|
|
|
if ((db->GetDumpType()>=0) && (db->GetDumpType()<=3))
|
|
|
|
ProcField = new ProcessFieldsTD(NewEngineInterface());
|
|
|
|
else if ((db->GetDumpType()>=10) && (db->GetDumpType()<=13))
|
|
|
|
ProcField = new ProcessFieldsFD(NewEngineInterface());
|
|
|
|
else if (db->GetDumpType()==20)
|
|
|
|
ProcField = new ProcessFieldsSAR(NewEngineInterface());
|
2011-01-10 07:27:50 +00:00
|
|
|
else
|
2011-08-31 09:05:04 +00:00
|
|
|
cerr << "openEMS::SetupFDTD: unknown dump box type... skipping!" << endl;
|
|
|
|
if (ProcField)
|
2011-01-31 11:25:55 +00:00
|
|
|
{
|
2011-08-31 09:05:04 +00:00
|
|
|
ProcField->SetEnable(Enable_Dumps);
|
|
|
|
ProcField->SetProcessInterval(Nyquist/m_OverSampling);
|
|
|
|
if ((db->GetDumpType()==1) || (db->GetDumpType()==11))
|
|
|
|
{
|
|
|
|
ProcField->SetDualTime(true);
|
|
|
|
//make dualMesh the default mesh for h-field dumps, maybe overwritten by interpolation type (node-interpolation)
|
|
|
|
ProcField->SetDualMesh(true);
|
|
|
|
}
|
|
|
|
if (db->GetDumpType()>=10)
|
|
|
|
{
|
|
|
|
ProcField->AddFrequency(db->GetFDSamples());
|
|
|
|
ProcField->SetDumpType((ProcessFields::DumpType)(db->GetDumpType()-10));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ProcField->SetDumpType((ProcessFields::DumpType)db->GetDumpType());
|
|
|
|
|
|
|
|
if (db->GetDumpType()==20)
|
|
|
|
{
|
|
|
|
ProcField->SetDumpType(ProcessFields::SAR_LOCAL_DUMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
//SetupMaterialStorages() has previewed storage needs... refresh here to prevent cleanup!!!
|
|
|
|
if ( ((db->GetDumpType()==2) || (db->GetDumpType()==12) || (db->GetDumpType()==20)) && Enable_Dumps )
|
|
|
|
FDTD_Op->SetMaterialStoreFlags(1,true);
|
|
|
|
|
|
|
|
ProcField->SetDumpMode((Engine_Interface_Base::InterpolationType)db->GetDumpMode());
|
|
|
|
ProcField->SetFileType((ProcessFields::FileType)db->GetFileType());
|
|
|
|
if (CylinderCoords)
|
|
|
|
ProcField->SetMeshType(Processing::CYLINDRICAL_MESH);
|
|
|
|
if (db->GetSubSampling())
|
|
|
|
for (int n=0; n<3; ++n)
|
|
|
|
ProcField->SetSubSampling(db->GetSubSampling(n),n);
|
|
|
|
if (db->GetOptResolution())
|
|
|
|
for (int n=0; n<3; ++n)
|
|
|
|
ProcField->SetOptResolution(db->GetOptResolution(n),n);
|
|
|
|
|
|
|
|
if (l_MultiBox==false)
|
|
|
|
ProcField->SetName(db->GetName());
|
|
|
|
else
|
|
|
|
ProcField->SetName(db->GetName(),nb);
|
|
|
|
|
|
|
|
ProcField->SetFileName(ProcField->GetName());
|
|
|
|
ProcField->DefineStartStopCoord(start,stop);
|
|
|
|
if (g_settings.showProbeDiscretization())
|
|
|
|
ProcField->ShowSnappedCoords();
|
|
|
|
PA->AddProcessing(ProcField);
|
|
|
|
prim->SetPrimitiveUsed(true);
|
2011-01-31 11:25:55 +00:00
|
|
|
}
|
2011-01-10 07:27:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-31 11:00:00 +00:00
|
|
|
bool openEMS::SetupMaterialStorages()
|
2011-01-10 07:27:50 +00:00
|
|
|
{
|
2011-01-31 11:00:00 +00:00
|
|
|
vector<CSProperties*> DumpProps = m_CSX->GetPropertyByType(CSProperties::DUMPBOX);
|
2011-01-10 07:27:50 +00:00
|
|
|
for (size_t i=0; i<DumpProps.size(); ++i)
|
|
|
|
{
|
|
|
|
CSPropDumpBox* db = DumpProps.at(i)->ToDumpBox();
|
|
|
|
if (!db)
|
|
|
|
continue;
|
|
|
|
if (db->GetQtyPrimitives()==0)
|
|
|
|
continue;
|
|
|
|
//check for current density dump types
|
2011-01-31 11:25:55 +00:00
|
|
|
if ( ((db->GetDumpType()==2) || (db->GetDumpType()==12) || (db->GetDumpType()==20)) && Enable_Dumps )
|
2011-01-10 07:27:50 +00:00
|
|
|
FDTD_Op->SetMaterialStoreFlags(1,true); //tell operator to store kappa material data
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-11 12:52:48 +00:00
|
|
|
bool openEMS::SetupOperator(TiXmlElement* FDTD_Opts)
|
|
|
|
{
|
|
|
|
if (CylinderCoords)
|
|
|
|
{
|
|
|
|
const char* radii = FDTD_Opts->Attribute("MultiGrid");
|
|
|
|
if (radii)
|
|
|
|
{
|
|
|
|
string rad(radii);
|
|
|
|
FDTD_Op = Operator_CylinderMultiGrid::New(SplitString2Double(rad,','),m_engine_numThreads);
|
2011-03-14 09:37:12 +00:00
|
|
|
if (FDTD_Op==NULL)
|
|
|
|
FDTD_Op = Operator_Cylinder::New(m_engine_numThreads);
|
2011-02-11 12:52:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
FDTD_Op = Operator_Cylinder::New(m_engine_numThreads);
|
|
|
|
}
|
|
|
|
else if (m_engine == EngineType_SSE)
|
|
|
|
{
|
|
|
|
FDTD_Op = Operator_sse::New();
|
|
|
|
}
|
|
|
|
else if (m_engine == EngineType_SSE_Compressed)
|
|
|
|
{
|
|
|
|
FDTD_Op = Operator_SSE_Compressed::New();
|
|
|
|
}
|
|
|
|
else if (m_engine == EngineType_Multithreaded)
|
|
|
|
{
|
|
|
|
FDTD_Op = Operator_Multithread::New(m_engine_numThreads);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FDTD_Op = Operator::New();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-10 07:27:50 +00:00
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
int openEMS::SetupFDTD(const char* file)
|
|
|
|
{
|
|
|
|
if (file==NULL) return -1;
|
|
|
|
Reset();
|
|
|
|
|
2011-11-08 10:49:14 +00:00
|
|
|
if (g_settings.GetVerboseLevel()>0)
|
|
|
|
cout << "Read openEMS xml file: " << file << " ..." << endl;
|
2010-10-06 14:27:31 +00:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-11-08 10:49:14 +00:00
|
|
|
if (g_settings.GetVerboseLevel()>0)
|
|
|
|
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);
|
|
|
|
}
|
2012-01-17 10:35:00 +00:00
|
|
|
double dhelp=0;
|
|
|
|
FDTD_Opts->QueryDoubleAttribute("NumberOfTimesteps",&dhelp);
|
|
|
|
if (dhelp<0)
|
2010-03-29 08:12:38 +00:00
|
|
|
NrTS=0;
|
|
|
|
else
|
2012-01-17 10:35:00 +00:00
|
|
|
NrTS = (unsigned int)dhelp;
|
2010-04-07 14:31:23 +00:00
|
|
|
|
2012-01-17 10:35:00 +00:00
|
|
|
int ihelp = 0;
|
|
|
|
FDTD_Opts->QueryIntAttribute("CylinderCoords",&ihelp);
|
|
|
|
if (ihelp==1)
|
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);
|
|
|
|
}
|
|
|
|
|
2011-11-08 10:49:14 +00:00
|
|
|
if (g_settings.GetVerboseLevel()>0)
|
|
|
|
cout << "Read Geometry..." << endl;
|
2011-01-31 11:00:00 +00:00
|
|
|
m_CSX = new ContinuousStructure();
|
|
|
|
string EC(m_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
|
|
|
}
|
|
|
|
|
2011-11-16 10:24:25 +00:00
|
|
|
if (g_settings.GetVerboseLevel()>2)
|
2011-03-14 07:50:28 +00:00
|
|
|
m_CSX->ShowPropertyStatus(cerr);
|
|
|
|
|
2010-11-02 15:32:00 +00:00
|
|
|
if (CylinderCoords)
|
2011-01-31 11:00:00 +00:00
|
|
|
if (m_CSX->GetCoordInputType()!=CYLINDRICAL)
|
2010-11-02 15:32:00 +00:00
|
|
|
{
|
2010-12-06 12:04:37 +00:00
|
|
|
cerr << "openEMS::SetupFDTD: Warning: Coordinate system found in the CSX file is not a cylindrical. Forcing to cylindrical coordinate system!" << endl;
|
2011-01-31 11:00:00 +00:00
|
|
|
m_CSX->SetCoordInputType(CYLINDRICAL); //tell CSX to use cylinder-coords
|
2010-11-02 15:32:00 +00:00
|
|
|
}
|
|
|
|
|
2010-07-08 09:28:11 +00:00
|
|
|
if (m_debugCSX)
|
2011-03-28 12:27:28 +00:00
|
|
|
m_CSX->Write2XML("debugCSX.xml");
|
2010-07-08 09:28:11 +00:00
|
|
|
|
2010-03-11 09:56:19 +00:00
|
|
|
//*************** setup operator ************//
|
2011-03-21 14:10:09 +00:00
|
|
|
if (SetupOperator(FDTD_Opts)==false)
|
|
|
|
return 2;
|
2010-04-09 13:51:37 +00:00
|
|
|
|
2011-01-31 11:00:00 +00:00
|
|
|
if (FDTD_Op->SetGeometryCSX(m_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-09-03 09:36:59 +00:00
|
|
|
double timestep=0;
|
|
|
|
FDTD_Opts->QueryDoubleAttribute("TimeStep",×tep);
|
|
|
|
if (timestep)
|
|
|
|
FDTD_Op->SetTimestep(timestep);
|
|
|
|
|
2012-04-27 14:47:27 +00:00
|
|
|
if (m_CSX->GetQtyPropertyType(CSProperties::LORENTZMATERIAL)>0)
|
|
|
|
FDTD_Op->AddExtension(new Operator_Ext_LorentzMaterial(FDTD_Op));
|
|
|
|
|
2011-01-10 07:27:50 +00:00
|
|
|
//check all properties to request material storage during operator creation...
|
2011-01-31 11:00:00 +00:00
|
|
|
SetupMaterialStorages();
|
2011-01-07 15:12:07 +00:00
|
|
|
|
2011-01-10 07:27:50 +00:00
|
|
|
/******************* create the EC-FDTD operator *****************************/
|
2010-10-27 09:17:58 +00:00
|
|
|
Operator::DebugFlags debugFlags = Operator::None;
|
|
|
|
if (DebugMat)
|
|
|
|
debugFlags |= Operator::debugMaterial;
|
|
|
|
if (DebugOp)
|
|
|
|
debugFlags |= Operator::debugOperator;
|
|
|
|
if (m_debugPEC)
|
|
|
|
debugFlags |= Operator::debugPEC;
|
2011-01-10 07:27:50 +00:00
|
|
|
|
2010-10-27 09:17:58 +00:00
|
|
|
FDTD_Op->CalcECOperator( debugFlags );
|
2011-01-10 07:27:50 +00:00
|
|
|
/*******************************************************************************/
|
2010-12-06 12:04:37 +00:00
|
|
|
|
2011-01-10 07:27:50 +00:00
|
|
|
//reset flags for material storage, if no dump-box resets it to true, it will be cleaned up...
|
|
|
|
FDTD_Op->SetMaterialStoreFlags(0,false);
|
2011-01-07 15:12:07 +00:00
|
|
|
FDTD_Op->SetMaterialStoreFlags(1,false);
|
2011-01-10 07:27:50 +00:00
|
|
|
FDTD_Op->SetMaterialStoreFlags(2,false);
|
|
|
|
FDTD_Op->SetMaterialStoreFlags(3,false);
|
2011-01-07 15:12:07 +00:00
|
|
|
|
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-08-19 08:13:03 +00:00
|
|
|
if (!FDTD_Op->SetupExcitation( FDTD_Opts->FirstChildElement("Excitation"), NrTS ))
|
2010-05-03 16:33:14 +00:00
|
|
|
exit(2);
|
2010-04-02 15:20:18 +00:00
|
|
|
|
2011-03-08 12:35:38 +00:00
|
|
|
FDTD_Op->DumpExciationSignals();
|
|
|
|
|
2010-06-05 22:47:56 +00:00
|
|
|
timeval OpDoneTime;
|
|
|
|
gettimeofday(&OpDoneTime,NULL);
|
2010-03-11 09:56:19 +00:00
|
|
|
|
2011-11-08 10:49:14 +00:00
|
|
|
if (g_settings.GetVerboseLevel()>0)
|
|
|
|
{
|
|
|
|
FDTD_Op->ShowStat();
|
|
|
|
FDTD_Op->ShowExtStat();
|
|
|
|
cout << "Creation time for operator: " << CalcDiffTime(OpDoneTime,startTime) << " s" << endl;
|
|
|
|
}
|
2011-11-14 13:12:36 +00:00
|
|
|
cout << "FDTD simulation size: " << FDTD_Op->GetNumberOfLines(0) << "x" << FDTD_Op->GetNumberOfLines(1) << "x" << FDTD_Op->GetNumberOfLines(2) << " --> " << FDTD_Op->GetNumberCells() << " FDTD cells " << endl;
|
2011-11-08 10:49:14 +00:00
|
|
|
cout << "FDTD timestep is: " <<FDTD_Op->GetTimestep() << " s; Nyquist rate: " << FDTD_Op->Exc->GetNyquistNum() << " timesteps @" << CalcNyquistFrequency(FDTD_Op->Exc->GetNyquistNum(),FDTD_Op->GetTimestep()) << " Hz" << endl;
|
|
|
|
if (FDTD_Op->Exc->GetNyquistNum()>1000)
|
|
|
|
cerr << "openEMS::SetupFDTD: Warning, the timestep seems to be very small --> long simulation. Check your mesh!?" << endl;
|
2010-03-11 09:56:19 +00:00
|
|
|
|
2012-01-17 09:22:16 +00:00
|
|
|
cout << "Excitation signal length is: " << FDTD_Op->Exc->Length << " timesteps (" << FDTD_Op->Exc->Length*FDTD_Op->GetTimestep() << "s)" << endl;
|
|
|
|
cout << "Max. number of timesteps: " << NrTS << " ( --> " << (double)NrTS/(double)(FDTD_Op->Exc->Length) << " * Excitation signal length)" << endl;
|
2012-01-17 10:31:53 +00:00
|
|
|
if ( ((double)NrTS/(double)FDTD_Op->Exc->Length < 3) && (FDTD_Op->Exc->GetExciteType()==0))
|
2012-01-17 09:22:16 +00:00
|
|
|
cerr << "openEMS::SetupFDTD: Warning, max. number of timesteps is smaller than three times the excitation. " << endl << \
|
|
|
|
"\tYou may want to choose a higher number of max. timesteps... " << endl;
|
|
|
|
|
2010-12-06 12:04:37 +00:00
|
|
|
if (m_no_simulation)
|
|
|
|
{
|
2010-10-19 07:05:51 +00:00
|
|
|
// simulation was disabled (to generate debug output only)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-01-10 07:27:50 +00:00
|
|
|
//setup all processing classes
|
2011-01-31 11:00:00 +00:00
|
|
|
if (SetupProcessing()==false)
|
2011-01-10 07:27:50 +00:00
|
|
|
return 2;
|
2010-04-19 14:09:41 +00:00
|
|
|
|
2011-01-10 07:27:50 +00:00
|
|
|
// Cleanup all unused material storages...
|
2011-01-07 15:12:07 +00:00
|
|
|
FDTD_Op->CleanupMaterialStorage();
|
|
|
|
|
2011-01-10 07:27:50 +00:00
|
|
|
//check and warn for unused properties and primitives
|
2011-01-31 11:00:00 +00:00
|
|
|
m_CSX->WarnUnusedPrimitves(cerr);
|
2010-05-29 15:40:18 +00:00
|
|
|
|
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-10-18 11:26:25 +00:00
|
|
|
bool openEMS::CheckAbortCond()
|
|
|
|
{
|
|
|
|
if (m_Abort) //abort was set externally
|
|
|
|
return true;
|
|
|
|
|
|
|
|
//check whether the file "ABORT" exist in current working directory
|
|
|
|
ifstream ifile("ABORT");
|
|
|
|
if (ifile)
|
|
|
|
{
|
|
|
|
ifile.close();
|
|
|
|
cerr << "openEMS::CheckAbortCond(): Found file \"ABORT\", aborting simulation..." << endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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...
|
2011-04-13 10:16:54 +00:00
|
|
|
ProcessFields* ProcField = new ProcessFields(NewEngineInterface());
|
2010-04-03 15:36:50 +00:00
|
|
|
PA->AddProcessing(ProcField);
|
2010-03-15 15:59:37 +00:00
|
|
|
double maxE=0,currE=0;
|
2010-04-03 15:36:50 +00:00
|
|
|
|
2011-02-16 09:11:39 +00:00
|
|
|
//init processings
|
|
|
|
PA->InitAll();
|
|
|
|
|
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();
|
2010-12-06 12:04:37 +00:00
|
|
|
for (unsigned int n=0; n<FDTD_Op->Exc->Volt_Count; ++n)
|
2010-08-16 11:28:19 +00:00
|
|
|
ProcField->AddStep(FDTD_Op->Exc->Volt_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-12-17 14:13:43 +00:00
|
|
|
PA->PreProcess();
|
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-10-18 11:26:25 +00:00
|
|
|
while ((FDTD_Eng->GetNumberOfTimesteps()<NrTS) && (change>endCrit) && !CheckAbortCond())
|
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())
|
|
|
|
{
|
2011-11-07 11:07:55 +00:00
|
|
|
currE = ProcField->CalcTotalEnergyEstimate();
|
2010-04-03 15:36:50 +00:00
|
|
|
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)
|
|
|
|
{
|
2011-11-07 11:07:55 +00:00
|
|
|
currE = ProcField->CalcTotalEnergyEstimate();
|
2010-03-15 21:19:51 +00:00
|
|
|
if (currE>maxE)
|
2010-03-15 15:59:37 +00:00
|
|
|
maxE=currE;
|
2012-01-17 09:22:16 +00:00
|
|
|
cout << "[@" << FormatTime(CalcDiffTime(currTime,startTime)) << "] Timestep: " << setw(12) << currTS ;
|
2010-09-09 06:15:26 +00:00
|
|
|
cout << " || Speed: " << setw(6) << setprecision(1) << std::fixed << speed*(currTS-prevTS)/t_diff << " MC/s (" << setw(4) << setprecision(3) << std::scientific << t_diff/(currTS-prevTS) << " s/TS)" ;
|
2010-03-15 21:19:51 +00:00
|
|
|
if (maxE)
|
|
|
|
change = currE/maxE;
|
2010-09-09 06:15:26 +00:00
|
|
|
cout << " || Energy: ~" << setw(6) << setprecision(2) << std::scientific << currE << " (-" << setw(5) << 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
|
|
|
}
|
2012-01-17 10:31:53 +00:00
|
|
|
if ((change>endCrit) && (FDTD_Op->Exc->GetExciteType()==0))
|
2012-01-17 09:22:16 +00:00
|
|
|
cerr << "RunFDTD: Warning: Max. number of timesteps was reached before the end-criteria of -" << fabs(10.0*log10(endCrit)) << "dB was reached... " << endl << \
|
|
|
|
"\tYou may want to choose a higher number of max. timesteps... " << endl;
|
|
|
|
|
2010-12-17 14:13:43 +00:00
|
|
|
PA->PostProcess();
|
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
|
|
|
}
|