diff --git a/FDTD/engine_multithread.cpp b/FDTD/engine_multithread.cpp
new file mode 100644
index 0000000..ee5e167
--- /dev/null
+++ b/FDTD/engine_multithread.cpp
@@ -0,0 +1,109 @@
+/*
+* Copyright (C) 2010 Sebastian Held (sebastian.held@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 .
+*/
+
+#include "engine_multithread.h"
+#include "tools/array_ops.h"
+
+Engine_Multithread::Engine_Multithread(Operator* op) : Engine(op)
+{
+}
+
+Engine_Multithread::~Engine_Multithread()
+{
+}
+
+void Engine_Multithread::Init()
+{
+ Engine::Init();
+}
+
+void Engine_Multithread::Reset()
+{
+ Engine::Reset();
+}
+
+bool Engine_Multithread::IterateTS(unsigned int iterTS)
+{
+ unsigned int pos[3];
+ int exc_pos;
+ bool shift[3];
+
+ for (unsigned int iter=0;iternumLines[0];++pos[0])
+ {
+ shift[0]=pos[0];
+ for (pos[1]=0;pos[1]numLines[1];++pos[1])
+ {
+ shift[1]=pos[1];
+ for (pos[2]=0;pos[2]numLines[2];++pos[2])
+ {
+ shift[2]=pos[2];
+ //do the updates here
+ //for x
+ volt[0][pos[0]][pos[1]][pos[2]] *= Op->vv[0][pos[0]][pos[1]][pos[2]];
+ volt[0][pos[0]][pos[1]][pos[2]] += Op->vi[0][pos[0]][pos[1]][pos[2]] * ( curr[2][pos[0]][pos[1]][pos[2]] - curr[2][pos[0]][pos[1]-shift[1]][pos[2]] - curr[1][pos[0]][pos[1]][pos[2]] + curr[1][pos[0]][pos[1]][pos[2]-shift[2]]);
+
+ //for y
+ volt[1][pos[0]][pos[1]][pos[2]] *= Op->vv[1][pos[0]][pos[1]][pos[2]];
+ volt[1][pos[0]][pos[1]][pos[2]] += Op->vi[1][pos[0]][pos[1]][pos[2]] * ( curr[0][pos[0]][pos[1]][pos[2]] - curr[0][pos[0]][pos[1]][pos[2]-shift[2]] - curr[2][pos[0]][pos[1]][pos[2]] + curr[2][pos[0]-shift[0]][pos[1]][pos[2]]);
+
+ //for x
+ volt[2][pos[0]][pos[1]][pos[2]] *= Op->vv[2][pos[0]][pos[1]][pos[2]];
+ volt[2][pos[0]][pos[1]][pos[2]] += Op->vi[2][pos[0]][pos[1]][pos[2]] * ( curr[1][pos[0]][pos[1]][pos[2]] - curr[1][pos[0]-shift[0]][pos[1]][pos[2]] - curr[0][pos[0]][pos[1]][pos[2]] + curr[0][pos[0]][pos[1]-shift[1]][pos[2]]);
+ }
+ }
+ }
+
+ //soft voltage excitation here (E-field excite)
+ for (unsigned int n=0;nE_Exc_Count;++n)
+ {
+ exc_pos = (int)numTS - (int)Op->E_Exc_delay[n];
+ exc_pos*= (exc_pos>0 && exc_pos<(int)Op->ExciteLength);
+// if (n==0) cerr << numTS << " => " << Op->ExciteSignal[exc_pos] << endl;
+ volt[Op->E_Exc_dir[n]][Op->E_Exc_index[0][n]][Op->E_Exc_index[1][n]][Op->E_Exc_index[2][n]] += Op->E_Exc_amp[n]*Op->ExciteSignal[exc_pos];
+ }
+
+ //current updates
+ for (pos[0]=0;pos[0]numLines[0]-1;++pos[0])
+ {
+ for (pos[1]=0;pos[1]numLines[1]-1;++pos[1])
+ {
+ for (pos[2]=0;pos[2]numLines[2]-1;++pos[2])
+ {
+ //do the updates here
+ //for x
+ curr[0][pos[0]][pos[1]][pos[2]] *= Op->ii[0][pos[0]][pos[1]][pos[2]];
+ curr[0][pos[0]][pos[1]][pos[2]] += Op->iv[0][pos[0]][pos[1]][pos[2]] * ( volt[2][pos[0]][pos[1]][pos[2]] - volt[2][pos[0]][pos[1]+1][pos[2]] - volt[1][pos[0]][pos[1]][pos[2]] + volt[1][pos[0]][pos[1]][pos[2]+1]);
+
+ //for y
+ curr[1][pos[0]][pos[1]][pos[2]] *= Op->ii[1][pos[0]][pos[1]][pos[2]];
+ curr[1][pos[0]][pos[1]][pos[2]] += Op->iv[1][pos[0]][pos[1]][pos[2]] * ( volt[0][pos[0]][pos[1]][pos[2]] - volt[0][pos[0]][pos[1]][pos[2]+1] - volt[2][pos[0]][pos[1]][pos[2]] + volt[2][pos[0]+1][pos[1]][pos[2]]);
+
+ //for x
+ curr[2][pos[0]][pos[1]][pos[2]] *= Op->ii[2][pos[0]][pos[1]][pos[2]];
+ curr[2][pos[0]][pos[1]][pos[2]] += Op->iv[2][pos[0]][pos[1]][pos[2]] * ( volt[1][pos[0]][pos[1]][pos[2]] - volt[1][pos[0]+1][pos[1]][pos[2]] - volt[0][pos[0]][pos[1]][pos[2]] + volt[0][pos[0]][pos[1]+1][pos[2]]);
+ }
+ }
+ }
+
+ //soft current excitation here (H-field excite)
+ ++numTS;
+ }
+ return true;
+}
diff --git a/FDTD/engine_multithread.h b/FDTD/engine_multithread.h
new file mode 100644
index 0000000..3d45b6c
--- /dev/null
+++ b/FDTD/engine_multithread.h
@@ -0,0 +1,45 @@
+/*
+* Copyright (C) 2010 Sebastian Held (sebastian.held@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 .
+*/
+
+#ifndef ENGINE_MULTITHREAD_H
+#define ENGINE_MULTITHREAD_H
+
+#include "operator.h"
+#include "engine.h"
+
+class Engine_Multithread : public Engine
+{
+ friend class Processing;
+ friend class ProcessVoltage;
+ friend class ProcessCurrent;
+ friend class ProcessFields;
+ friend class ProcessFieldsTD;
+public:
+ Engine_Multithread(Operator* op);
+ virtual ~Engine_Multithread();
+
+ virtual void Init();
+ virtual void Reset();
+
+ //!Iterate a number of timesteps
+ virtual bool IterateTS(unsigned int iterTS);
+
+
+protected:
+};
+
+#endif // ENGINE_MULTITHREAD_H
diff --git a/openEMS.pro b/openEMS.pro
index 43c0d75..0098bf2 100644
--- a/openEMS.pro
+++ b/openEMS.pro
@@ -31,7 +31,8 @@ SOURCES += main.cpp \
FDTD/processfields_td.cpp \
FDTD/processcurrent.cpp \
examples/FDTD_examples.cpp \
- openems.cpp
+ openems.cpp \
+ FDTD/engine_multithread.cpp
HEADERS += tools/ErrorMsg.h \
tools/AdrOp.h \
tools/constants.h \
@@ -44,4 +45,5 @@ HEADERS += tools/ErrorMsg.h \
FDTD/processfields_td.h \
FDTD/processcurrent.h \
examples/FDTD_examples.h \
- openems.h
+ openems.h \
+ FDTD/engine_multithread.h
diff --git a/openems.cpp b/openems.cpp
index fe9790e..e2ffc2f 100644
--- a/openems.cpp
+++ b/openems.cpp
@@ -20,6 +20,7 @@
#include "tools/array_ops.h"
#include "FDTD/operator.h"
#include "FDTD/engine.h"
+#include "FDTD/engine_multithread.h"
#include "FDTD/processvoltage.h"
#include "FDTD/processcurrent.h"
#include "FDTD/processfields_td.h"
@@ -95,6 +96,12 @@ bool openEMS::parseCommandLineArgument( const char *argv )
DebugOperator();
return true;
}
+ else if (strcmp(argv,"--engine=multithreaded")==0)
+ {
+ cout << "openEMS - enabled multithreading" << endl;
+ m_engine = EngineType_Multithreaded;
+ return true;
+ }
return false;
}
@@ -217,7 +224,15 @@ int openEMS::SetupFDTD(const char* file)
cout << "Creation time for operator: " << difftime(OpDoneTime,startTime) << " s" << endl;
//create FDTD engine
- FDTD_Eng = new Engine(FDTD_Op);
+ switch (m_engine) {
+ case EngineType_Multithreaded:
+ FDTD_Eng = new Engine_Multithread(FDTD_Op);
+ break;
+ default:
+ FDTD_Eng = new Engine(FDTD_Op);
+ break;
+ }
+
time_t currTime = time(NULL);
diff --git a/openems.h b/openems.h
index 73bc943..ae2885d 100644
--- a/openems.h
+++ b/openems.h
@@ -52,6 +52,9 @@ protected:
Operator* FDTD_Op;
Engine* FDTD_Eng;
ProcessingArray* PA;
+
+ enum EngineType {EngineType_Standard,EngineType_Multithreaded};
+ EngineType m_engine;
};
#endif // OPENEMS_H