From 2e8e8caa4e5eb94356d2f6d608bac8696d72c1a5 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Fri, 22 Jul 2011 09:58:02 +0200 Subject: [PATCH] Operator: new SnapBox2Mesh + used by CalcLumpedElement --- Common/operator_base.h | 16 +++++++-- FDTD/operator.cpp | 78 +++++++++++++++++++++++++++++++++++------- FDTD/operator.h | 4 +++ 3 files changed, 84 insertions(+), 14 deletions(-) diff --git a/Common/operator_base.h b/Common/operator_base.h index cad69d8..e01b696 100644 --- a/Common/operator_base.h +++ b/Common/operator_base.h @@ -69,8 +69,20 @@ public: */ virtual double GetEdgeArea(int ny, const unsigned int pos[3], bool dualMesh = false) const =0; - //! Snap the given coodinates to mesh indices - virtual bool SnapToMesh(const double* coord, unsigned int* uicoord, bool lower=false, bool* inside=NULL) const =0; + //! Snap the given coodinates to mesh indices, return box dimension + virtual bool SnapToMesh(const double* coord, unsigned int* uicoord, bool dualMesh=false, bool* inside=NULL) const =0; + + //! Snap a given box to the operator mesh, uiStart will be always <= uiStop + /*! + \param[in] start the box-start coorindate + \param[in] stop the box-stopt coorindate + \param[out] uiStart the snapped box-start coorindate index + \param[out] uiStop the snapped box-stop coorindate index + \param[in] dualMesh snap to main or dual mesh (default is main mesh) + \param[in] SnapMethod Snapping method, 0=snap to closest line, 1/(2)=snap such that given box is inside (outside) the snapped lines + \return returns the box dimension or -1 if box is not inside the simulation domain + */ + virtual int SnapBox2Mesh(const double* start, const double* stop, unsigned int* uiStart, unsigned int* uiStop, bool dualMesh=false, int SnapMethod=0, bool* bStartIn=NULL, bool* bStopIn=NULL) const =0; //! Set the boundary conditions virtual void SetBoundaryCondition(int* BCs) {for (int n=0; n<6; ++n) m_BC[n]=BCs[n];} diff --git a/FDTD/operator.cpp b/FDTD/operator.cpp index 545cdeb..cf3a26d 100644 --- a/FDTD/operator.cpp +++ b/FDTD/operator.cpp @@ -16,6 +16,7 @@ */ #include +#include #include "operator.h" #include "engine.h" #include "extensions/operator_extension.h" @@ -253,6 +254,69 @@ bool Operator::SnapToMesh(const double* dcoord, unsigned int* uicoord, bool dual return ok; } +int Operator::SnapBox2Mesh(const double* start, const double* stop, unsigned int* uiStart, unsigned int* uiStop, bool dualMesh, int SnapMethod, bool* bStartIn, bool* bStopIn) const +{ + double l_start[3], l_stop[3]; + for (int n=0;n<3;++n) + { + l_start[n] = fmin(start[n],stop[n]); + l_stop[n] = fmax(start[n], stop[n]); + double min = GetDiscLine(n,0); + double max = GetDiscLine(n,GetNumberOfLines(n)-1); + if ( ((l_start[n]max) && (l_stop[n]>max)) ) + { + return -1; + } + } + + SnapToMesh(l_start, uiStart, dualMesh, bStartIn); + SnapToMesh(l_stop, uiStop, dualMesh, bStopIn); + int iDim = 0; + + if (SnapMethod==0) + { + for (int n=0;n<3;++n) + if (uiStop[n]>uiStart[n]) + ++iDim; + return iDim; + } + else if (SnapMethod==1) + { + for (int n=0;n<3;++n) + { + if (uiStop[n]>uiStart[n]) + { + if ((GetDiscLine( n, uiStart[n], dualMesh ) > l_start[n]) && (uiStart[n]>0)) + --uiStart[n]; + if ((GetDiscLine( n, uiStop[n], dualMesh ) < l_stop[n]) && (uiStop[n]uiStart[n]) + ++iDim; + } + return iDim; + } + else if (SnapMethod==2) + { + for (int n=0;n<3;++n) + { + if (uiStop[n]>uiStart[n]) + { + if ((GetDiscLine( n, uiStart[n], dualMesh ) < l_start[n]) && (uiStart[n] l_stop[n]) && (uiStop[n]>0)) + --uiStop[n]; + } + if (uiStop[n]>uiStart[n]) + ++iDim; + } + return iDim; + } + else + cerr << "Operator::SnapBox2Mesh: Unknown snapping method!" << endl; + return -1; +} + struct Operator::Grid_Path Operator::FindPath(double start[], double stop[]) { struct Grid_Path path; @@ -1205,18 +1269,8 @@ bool Operator::Calc_LumpedElements() unsigned int uiStart[3]; unsigned int uiStop[3]; // snap to the native coordinate system - SnapToMesh(box->GetStartCoord()->GetNativeCoords(),uiStart); - SnapToMesh(box->GetStopCoord()->GetNativeCoords(),uiStop); - - for (int n=0;n<3;++n) - { - if (uiStop[n]GetStartCoord()->GetNativeCoords(), box->GetStopCoord()->GetNativeCoords(), uiStart, uiStop)<=0) + return false; if (uiStart[ny]==uiStop[ny]) { diff --git a/FDTD/operator.h b/FDTD/operator.h index 676b6ef..8d83810 100644 --- a/FDTD/operator.h +++ b/FDTD/operator.h @@ -120,8 +120,12 @@ public: virtual unsigned int SnapToMeshLine(int ny, double coord, bool &inside, bool dualMesh=false) const; + //! Snap the given coodinates to mesh indices virtual bool SnapToMesh(const double* coord, unsigned int* uicoord, bool dualMesh=false, bool* inside=NULL) const; + //! Snap a given box to the FDTD mesh + virtual int SnapBox2Mesh(const double* start, const double* stop, unsigned int* uiStart, unsigned int* uiStop, bool dualMesh=false, int SnapMethod=0, bool* bStartIn=NULL, bool* bStopIn=NULL) const; + virtual void AddExtension(Operator_Extension* op_ext); virtual size_t GetNumberOfExtentions() const {return m_Op_exts.size();} virtual Operator_Extension* GetExtension(size_t index) const {return m_Op_exts.at(index);}