From 9c5c5e9057dd7598db4df66e39cd0c661ef42df1 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Sun, 25 Apr 2010 21:59:05 +0200 Subject: [PATCH] new: operator & engine extensions --- FDTD/engine.cpp | 28 +++++++++++++++++++++ FDTD/engine.h | 6 +++++ FDTD/engine_extension.cpp | 9 +++++++ FDTD/engine_extension.h | 49 +++++++++++++++++++++++++++++++++++++ FDTD/operator.cpp | 9 +++++++ FDTD/operator.h | 6 +++++ FDTD/operator_extension.cpp | 8 ++++++ FDTD/operator_extension.h | 34 +++++++++++++++++++++++++ openEMS.pro | 8 ++++-- 9 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 FDTD/engine_extension.cpp create mode 100644 FDTD/engine_extension.h create mode 100644 FDTD/operator_extension.cpp create mode 100644 FDTD/operator_extension.h diff --git a/FDTD/engine.cpp b/FDTD/engine.cpp index 6f92093..9a29692 100644 --- a/FDTD/engine.cpp +++ b/FDTD/engine.cpp @@ -16,6 +16,7 @@ */ #include "engine.h" +#include "engine_extension.h" #include "tools/array_ops.h" //! \brief construct an Engine instance @@ -142,14 +143,41 @@ void Engine::ApplyCurrentExcite() { } +void Engine::AddExtension(Engine_Extension* eng_ext) +{ + m_Eng_exts.push_back(eng_ext); +} + bool Engine::IterateTS(unsigned int iterTS) { for (unsigned int iter=0;iterDoPreVoltageUpdates(); + UpdateVoltages(); + + for (size_t n=0;nDoPostVoltageUpdates(); + for (size_t n=0;nApply2Voltages(); + ApplyVoltageExcite(); + + //current updates with extensions + for (size_t n=0;nDoPreCurrentUpdates(); + UpdateCurrents(); + + for (size_t n=0;nDoPostCurrentUpdates(); + for (size_t n=0;nApply2Current(); + ApplyCurrentExcite(); + ++numTS; } return true; diff --git a/FDTD/engine.h b/FDTD/engine.h index 0e83249..9b37e93 100644 --- a/FDTD/engine.h +++ b/FDTD/engine.h @@ -21,6 +21,8 @@ #include #include "operator.h" +class Engine_Extension; + class Engine { public: @@ -38,6 +40,8 @@ public: inline virtual FDTD_FLOAT GetVolt( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return volt[n][x][y][z]; } inline virtual FDTD_FLOAT GetCurr( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return curr[n][x][y][z]; } + virtual void AddExtension(Engine_Extension* eng_ext); + protected: Engine(const Operator* op); const Operator* Op; @@ -53,6 +57,8 @@ protected: FDTD_FLOAT**** curr; unsigned int numTS; + vector m_Eng_exts; + ofstream file_et1; }; diff --git a/FDTD/engine_extension.cpp b/FDTD/engine_extension.cpp new file mode 100644 index 0000000..653d99b --- /dev/null +++ b/FDTD/engine_extension.cpp @@ -0,0 +1,9 @@ +#include "engine_extension.h" + +#include "engine.h" + +Engine_Extension::Engine_Extension(Operator_Extension* op_ext, Engine* eng) +{ + m_Op_ext = op_ext; + m_Eng = eng; +} diff --git a/FDTD/engine_extension.h b/FDTD/engine_extension.h new file mode 100644 index 0000000..756157a --- /dev/null +++ b/FDTD/engine_extension.h @@ -0,0 +1,49 @@ +/* +* 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 . +*/ + +#ifndef ENGINE_EXTENSION_H +#define ENGINE_EXTENSION_H + +class Operator_Extension; +class Engine; + +//! Abstract base-class for all engine extensions +class Engine_Extension +{ +public: + //! This methode will be called __before__ the main engine does the usual voltage updates. This methode may __not__ change the engine voltages!!! + virtual void DoPreVoltageUpdates() {} + //! This methode will be called __after__ the main engine does the usual voltage updates. This methode may __not__ change the engine voltages!!! + virtual void DoPostVoltageUpdates() {} + //! This methode will be called __after__ all updates to the voltages and extensions and may add its results to the engine voltages, but may __not__ rely on the current value of the engine voltages!!! + virtual void Apply2Voltages() {} + + //! This methode will be called __before__ the main engine does the usual current updates. This methode may __not__ change the engine current!!! + virtual void DoPreCurrentUpdates() {} + //! This methode will be called __after__ the main engine does the usual current updates. This methode may __not__ change the engine current!!! + virtual void DoPostCurrentUpdates() {} + //! This methode will be called __after__ all updates to the current and extensions and may add its results to the engine current, but may __not__ rely on the current value of the engine current!!! + virtual void Apply2Current() {} + +protected: + Engine_Extension(Operator_Extension* op_ext, Engine* eng); + + Operator_Extension* m_Op_ext; + Engine* m_Eng; +}; + +#endif // ENGINE_EXTENSION_H diff --git a/FDTD/operator.cpp b/FDTD/operator.cpp index 544514d..c4caa47 100644 --- a/FDTD/operator.cpp +++ b/FDTD/operator.cpp @@ -17,6 +17,7 @@ #include #include "operator.h" +#include "operator_extension.h" #include "processfields.h" #include "tools/array_ops.h" #include "fparser.hh" @@ -553,6 +554,10 @@ int Operator::CalcECOperator() } } + //all information available for extension... create now... + for (size_t n=0;nBuildExtension(); + //cleanup for (int n=0;n<3;++n) { @@ -1091,3 +1096,7 @@ bool Operator::CalcPEC() return true; } +void Operator::AddExtension(Operator_Extension* op_ext) +{ + m_Op_exts.push_back(op_ext); +} diff --git a/FDTD/operator.h b/FDTD/operator.h index d5504b7..a81a95d 100644 --- a/FDTD/operator.h +++ b/FDTD/operator.h @@ -24,6 +24,8 @@ #define FDTD_FLOAT float +class Operator_Extension; + //! Abstract base-class for the FDTD-operator class Operator { @@ -80,6 +82,8 @@ public: virtual double GetDiscLine(int n, unsigned int pos, bool dualMesh=false) const; virtual bool SnapToMesh(double* coord, unsigned int* uicoord, bool lower=false, bool* inside=NULL); + virtual void AddExtension(Operator_Extension* op_ext); + protected: //! use New() for creating a new Operator Operator(); @@ -126,6 +130,8 @@ protected: AdrOp* MainOp; AdrOp* DualOp; + vector m_Op_exts; + // engine/post-proc needs access public: //EC operator diff --git a/FDTD/operator_extension.cpp b/FDTD/operator_extension.cpp new file mode 100644 index 0000000..113890a --- /dev/null +++ b/FDTD/operator_extension.cpp @@ -0,0 +1,8 @@ +#include "operator_extension.h" + +#include "operator.h" + +Operator_Extension::Operator_Extension(Operator* op) +{ + m_Op = op; +} diff --git a/FDTD/operator_extension.h b/FDTD/operator_extension.h new file mode 100644 index 0000000..68f0a5e --- /dev/null +++ b/FDTD/operator_extension.h @@ -0,0 +1,34 @@ +/* +* 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 . +*/ + +#ifndef OPERATOR_EXTENSION_H +#define OPERATOR_EXTENSION_H + +class Operator; + +//! Abstract base-class for all operator extensions +class Operator_Extension +{ +public: + virtual bool BuildExtension() {return true;} + +protected: + Operator_Extension(Operator* op); + Operator* m_Op; +}; + +#endif // OPERATOR_EXTENSION_H diff --git a/openEMS.pro b/openEMS.pro index 6ab1fba..156d065 100644 --- a/openEMS.pro +++ b/openEMS.pro @@ -38,7 +38,9 @@ SOURCES += main.cpp \ openems.cpp \ FDTD/engine_multithread.cpp \ FDTD/operator_cylinder.cpp \ - FDTD/engine_cylinder.cpp + FDTD/engine_cylinder.cpp \ + FDTD/operator_extension.cpp \ + FDTD/engine_extension.cpp HEADERS += tools/ErrorMsg.h \ tools/AdrOp.h \ tools/constants.h \ @@ -54,7 +56,9 @@ HEADERS += tools/ErrorMsg.h \ openems.h \ FDTD/engine_multithread.h \ FDTD/operator_cylinder.h \ - FDTD/engine_cylinder.h + FDTD/engine_cylinder.h \ + FDTD/operator_extension.h \ + FDTD/engine_extension.h QMAKE_CXXFLAGS_RELEASE = -O2 \ -g \ -march=native