openEMS/main.cpp

121 lines
2.9 KiB
C++
Raw Normal View History

2010-02-28 21:48:03 +00:00
#include <iostream>
#include <fstream>
#include <sstream>
2010-02-28 21:48:03 +00:00
#include <time.h>
#include "tools/array_ops.h"
#include "FDTD/operator.h"
#include "FDTD/engine.h"
#include "FDTD/processvoltage.h"
#include "FDTD/processcurrent.h"
#include "FDTD/processfields_td.h"
2010-02-28 21:48:03 +00:00
#include "ContinuousStructure.h"
2010-03-07 11:49:38 +00:00
#include "examples/FDTD_examples.h"
2010-02-28 21:48:03 +00:00
2010-03-07 11:49:38 +00:00
using namespace std;
2010-02-28 22:42:10 +00:00
2010-02-28 21:48:03 +00:00
int main(int argc, char *argv[])
{
time_t startTime=time(NULL);
//*************** setup/read geometry ************//
cerr << "Create Geometry..." << endl;
ContinuousStructure CSX;
2010-03-02 21:55:50 +00:00
//BuildPlaneWave(CSX);
BuildMSL(CSX);
2010-02-28 21:48:03 +00:00
//*************** setup operator ************//
cerr << "Create Operator..." << endl;
Operator cop;
2010-02-28 21:48:03 +00:00
cop.SetGeometryCSX(&CSX);
cop.CalcECOperator();
double fmax=1e9;
cop.CalcGaussianPulsExcitation(fmax/2,fmax/2);
2010-02-28 21:48:03 +00:00
time_t OpDoneTime=time(NULL);
cop.ShowSize();
bool bnd[] = {1,1,0,1,0,1};
2010-03-02 18:01:03 +00:00
cop.ApplyMagneticBC(bnd);
cerr << "Nyquist number of timesteps: " << cop.GetNyquistNum(fmax) << endl;
2010-03-01 19:50:42 +00:00
unsigned int NrIter = cop.GetNyquistNum(fmax)/3;
2010-02-28 21:48:03 +00:00
cerr << "Time for operator: " << difftime(OpDoneTime,startTime) << endl;
//create FDTD engine
Engine eng(&cop);
time_t currTime = time(NULL);
//*************** setup processing ************//
ProcessVoltage PV(&cop,&eng);
PV.OpenFile("tmp/u1");
double start[]={0,50,0};
double stop[]={0,0,0};
PV.DefineStartStopCoord(start,stop);
ProcessCurrent PCurr(&cop,&eng);
PCurr.OpenFile("tmp/i1");
start[0]=-50;start[1]=40;start[2]=-0;
stop[0]=50;stop[1]=60;stop[2]=-0;
PCurr.DefineStartStopCoord(start,stop);
unsigned int maxIter = 1800;
2010-03-07 11:49:38 +00:00
vector<CSProperties*> DumpProps = CSX.GetPropertyByType(CSProperties::DUMPBOX);
vector<ProcessFieldsTD*> TD_Dump;
ProcessFieldsTD PETD(&cop,&eng);
2010-03-07 11:49:38 +00:00
if (DumpProps.size()>0)
{
CSPrimitives* prim = DumpProps.at(0)->GetPrimitive(0);
bool acc;
double* bnd = prim->GetBoundBox(acc);
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(0)->ToDumpBox();
if (db)
{
if (db->GetEFieldDump())
{
PETD.SetDumpType(0);
PETD.SetFilePattern("tmp/Et_");
}
else
PETD.SetEnable(false);
}
else
PETD.SetEnable(false);
PETD.DefineStartStopCoord(start,stop);
}
2010-03-02 14:37:00 +00:00
2010-03-02 21:55:50 +00:00
PETD.SetEnable(true);
2010-03-02 18:01:03 +00:00
2010-03-01 19:50:42 +00:00
PV.Process();
PCurr.Process();
PETD.Process();
//*************** simulate ************//
for (unsigned int i=0;i<maxIter;i+=NrIter)
{
eng.IterateTS(NrIter);
PV.Process();
PCurr.Process();
PETD.Process();
}
//*************** postproc ************//
time_t prevTime = currTime;
currTime = time(NULL);
double t_diff = difftime(currTime,prevTime);
cerr << "Time for " << eng.GetNumberOfTimesteps() << " iterations with " << cop.GetNumberCells() << " cells : " << t_diff << " sec" << endl;
cerr << "Speed: " << (double)cop.GetNumberCells()*(double)eng.GetNumberOfTimesteps()/t_diff/1e6 << " MCells/s " << endl;
2010-02-28 21:48:03 +00:00
return 0;
}