From fc2b60ba3ed181cb000b6eb5ca34f94aca84c2e8 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Fri, 3 Sep 2010 11:53:33 +0200 Subject: [PATCH] Operator Extension clone method: allows to create a copy/clone of an existing extension This will be necessary for the upcoming multi-grid approach... --- FDTD/operator_ext_mur_abc.cpp | 36 +++++++++++++++++++++++++++-------- FDTD/operator_ext_mur_abc.h | 5 +++++ FDTD/operator_extension.cpp | 13 +++++++++++++ FDTD/operator_extension.h | 9 +++++++++ 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/FDTD/operator_ext_mur_abc.cpp b/FDTD/operator_ext_mur_abc.cpp index d1f37f6..327c587 100644 --- a/FDTD/operator_ext_mur_abc.cpp +++ b/FDTD/operator_ext_mur_abc.cpp @@ -21,6 +21,33 @@ #include "tools/array_ops.h" Operator_Ext_Mur_ABC::Operator_Ext_Mur_ABC(Operator* op) : Operator_Extension(op) +{ + Initialize(); +} + +Operator_Ext_Mur_ABC::~Operator_Ext_Mur_ABC() +{ + Delete2DArray(m_Mur_Coeff_nyP,m_numLines); + m_Mur_Coeff_nyP = NULL; + Delete2DArray(m_Mur_Coeff_nyPP,m_numLines); + m_Mur_Coeff_nyPP = NULL; +} + +Operator_Ext_Mur_ABC::Operator_Ext_Mur_ABC(Operator* op, Operator_Ext_Mur_ABC* op_ext) : Operator_Extension(op, op_ext) +{ + Initialize(); + m_v_phase = op_ext->m_v_phase; + SetDirection(op_ext->m_ny,op_ext->m_top); +} + +Operator_Extension* Operator_Ext_Mur_ABC::Clone(Operator* op) +{ + if (dynamic_cast(this)==NULL) + return NULL; + return new Operator_Ext_Mur_ABC(op, this); +} + +void Operator_Ext_Mur_ABC::Initialize() { m_ny = -1; m_nyP = -1; @@ -37,14 +64,6 @@ Operator_Ext_Mur_ABC::Operator_Ext_Mur_ABC(Operator* op) : Operator_Extension(op m_numLines[1]=0; } -Operator_Ext_Mur_ABC::~Operator_Ext_Mur_ABC() -{ - Delete2DArray(m_Mur_Coeff_nyP,m_numLines); - m_Mur_Coeff_nyP = NULL; - Delete2DArray(m_Mur_Coeff_nyPP,m_numLines); - m_Mur_Coeff_nyPP = NULL; -} - void Operator_Ext_Mur_ABC::SetDirection(int ny, bool top_ny) { if ((ny<0) || (ny>2)) @@ -54,6 +73,7 @@ void Operator_Ext_Mur_ABC::SetDirection(int ny, bool top_ny) Delete2DArray(m_Mur_Coeff_nyPP,m_numLines); m_ny = ny; + m_top = top_ny; m_nyP = (ny+1)%3; m_nyPP = (ny+2)%3; if (!top_ny) diff --git a/FDTD/operator_ext_mur_abc.h b/FDTD/operator_ext_mur_abc.h index 0d6b340..798886c 100644 --- a/FDTD/operator_ext_mur_abc.h +++ b/FDTD/operator_ext_mur_abc.h @@ -28,6 +28,9 @@ public: Operator_Ext_Mur_ABC(Operator* op); ~Operator_Ext_Mur_ABC(); + Operator_Ext_Mur_ABC(Operator* op, Operator_Ext_Mur_ABC* op_ext); + virtual Operator_Extension* Clone(Operator* op); + //! Define the direction of this ABC: \a ny=0,1,2 -> x,y,z and if at bottom_ny -> e.g. x=0 or x=end void SetDirection(int ny, bool top_ny); @@ -45,8 +48,10 @@ public: virtual void ShowStat(ostream &ostr) const; protected: + void Initialize(); int m_ny; int m_nyP,m_nyPP; + bool m_top; unsigned int m_LineNr; int m_LineNr_Shift; diff --git a/FDTD/operator_extension.cpp b/FDTD/operator_extension.cpp index 69f0442..cc3b3bc 100644 --- a/FDTD/operator_extension.cpp +++ b/FDTD/operator_extension.cpp @@ -24,7 +24,20 @@ Operator_Extension::Operator_Extension(Operator* op) m_Op = op; } +Operator_Extension::Operator_Extension(Operator* op, Operator_Extension* op_ext) +{ + UNUSED(op_ext); + m_Op = op; +} + void Operator_Extension::ShowStat(ostream &ostr) const { ostr << "--- " << GetExtensionName() << " ---" << endl; } + +Operator_Extension* Operator_Extension::Clone(Operator* op) +{ + if (dynamic_cast(this)==NULL) + return NULL; + return new Operator_Extension(op, this); +} diff --git a/FDTD/operator_extension.h b/FDTD/operator_extension.h index fcc24cb..54d24d9 100644 --- a/FDTD/operator_extension.h +++ b/FDTD/operator_extension.h @@ -35,6 +35,13 @@ class Operator_Extension { friend class Engine_Extension; public: + //! Create a clone of this extension, will return NULL if this is impossible + /*! + Create a clone of this extension, will return NULL if this is impossible (e.g. derived extension has no clone method and copy-constructor)... + BuildExtension has to be called separatly! + */ + virtual Operator_Extension* Clone(Operator* op); + virtual bool BuildExtension() {return true;} virtual Engine_Extension* CreateEngineExtention() {return 0;} @@ -47,6 +54,8 @@ public: protected: Operator_Extension(Operator* op); + //! Copy constructor, returns NULL if extension cannot be copied... + Operator_Extension(Operator* op, Operator_Extension* op_ext); Operator* m_Op; };