diff --git a/FDTD/operator_ext_pml_sf.cpp b/FDTD/operator_ext_pml_sf.cpp index a3e760d..4205b92 100644 --- a/FDTD/operator_ext_pml_sf.cpp +++ b/FDTD/operator_ext_pml_sf.cpp @@ -21,17 +21,31 @@ #include "tools/array_ops.h" #include "fparser.hh" -bool Build_Split_Field_PML(Operator* op, int BC[6], int size[6]) +bool Build_Split_Field_PML(Operator* op, int BC[6], int size[6], string gradFunc) { for (int n=0;n<6;++n) { if (BC[n]==3) //split field PML { - cerr << "Build_Split_Field_PML:: Warning, currently only pml planes are implemented... edges and corner coming soon..." << endl; Operator_Ext_PML_SF_Plane* op_pml_sf = new Operator_Ext_PML_SF_Plane(op); op_pml_sf->SetDirection(n/2,n%2); + if ((size[n]<4) || (size[n]>50)) + { + cerr << "Build_Split_Field_PML: Warning, pml size invalid, skipping pml..." << endl; + delete op_pml_sf; + continue; + } op_pml_sf->SetPMLLength(size[n]); op_pml_sf->SetBoundaryCondition(BC); + + if (!op_pml_sf->SetGradingFunction(gradFunc)) + { + cerr << "Build_Split_Field_PML: Warning, pml grading function invalid, skipping pml..." << endl; + delete op_pml_sf; + continue; + } + + cerr << "Build_Split_Field_PML:: Warning, currently only pml planes are implemented... edges and corner coming soon..." << endl; op->AddExtension(op_pml_sf); } } @@ -112,7 +126,11 @@ void Operator_Ext_PML_SF::DeleteOP() bool Operator_Ext_PML_SF::SetGradingFunction(string func) { - int res = m_GradingFunction->Parse(func.c_str(), "D,dl,W,Z,N"); + if (func.empty()) + return true; + + m_GradFunc = func; + int res = m_GradingFunction->Parse(m_GradFunc.c_str(), "D,dl,W,Z,N"); if(res < 0) return true; cerr << "Operator_Ext_PML_SF::SetGradingFunction: Warning, an error occured parsing the pml grading function (see below) ..." << endl; @@ -401,4 +419,5 @@ void Operator_Ext_PML_SF_Plane::ShowStat(ostream &ostr) const string top_bot[2] = {"bottom", "top"}; ostr << " Active direction\t: " << XYZ[m_ny] << " (" << top_bot[m_top] << ")" << endl; ostr << " PML width (cells)\t: " << m_numLines[m_ny] << endl; + ostr << " Grading function\t: \"" << m_GradFunc << "\"" << endl; } diff --git a/FDTD/operator_ext_pml_sf.h b/FDTD/operator_ext_pml_sf.h index a079cb6..28f6077 100644 --- a/FDTD/operator_ext_pml_sf.h +++ b/FDTD/operator_ext_pml_sf.h @@ -24,7 +24,7 @@ class FunctionParser; //! Insert split field pml planes, edges and corner as necessary by the given boundary conditions -bool Build_Split_Field_PML(Operator* op, int BC[6], int size[6]); +bool Build_Split_Field_PML(Operator* op, int BC[6], int size[6], string gradFunc); //! This is the abstract operator extension for truncating the FDTD domain with a split field pml class Operator_Ext_PML_SF : public Operator_Extension @@ -57,6 +57,8 @@ public: N = number of cells for the pml Z = wave impedance at the current depth and position example: SetGradingFunction("-log(1e-6)*log(2.5)/(2*dl*pow(2.5,W/dl)-1) * pow(2.5, D/dl) / Z"); + + An empty function string will be ignored. */ virtual bool SetGradingFunction(string func); @@ -78,6 +80,7 @@ protected: int m_BC[6]; + string m_GradFunc; FunctionParser* m_GradingFunction; void InitOP(); diff --git a/openems.cpp b/openems.cpp index 84f2c1c..bdfb118 100644 --- a/openems.cpp +++ b/openems.cpp @@ -159,6 +159,10 @@ bool openEMS::SetupBoundaryConditions(TiXmlElement* BC) int bounds[6] = {0,0,0,0,0,0}; //default boundary cond. (PEC) int pml_size[6] = {8,8,8,8,8,8}; //default pml size string s_bc; + const char* tmp = BC->Attribute("PML_Grading"); + string pml_gradFunc; + if (tmp) + pml_gradFunc = string(tmp); string bound_names[] = {"xmin","xmax","ymin","ymax","zmin","zmax"}; @@ -169,7 +173,9 @@ bool openEMS::SetupBoundaryConditions(TiXmlElement* BC) continue; if (EC==TIXML_WRONG_TYPE) { - s_bc = string(BC->Attribute(bound_names[n].c_str())); + tmp = BC->Attribute(bound_names[n].c_str()); + if (tmp) + s_bc = string(tmp); if (s_bc=="PEC") bounds[n] = 0; else if (s_bc=="PMC") @@ -201,7 +207,7 @@ bool openEMS::SetupBoundaryConditions(TiXmlElement* BC) FDTD_Op->AddExtension(op_ext_mur); } } - Build_Split_Field_PML(FDTD_Op,bounds,pml_size); + Build_Split_Field_PML(FDTD_Op,bounds,pml_size,pml_gradFunc); return true; }