diff --git a/FDTD/operator_ext_pml_sf.cpp b/FDTD/operator_ext_pml_sf.cpp index f9a6004..b02d8b1 100644 --- a/FDTD/operator_ext_pml_sf.cpp +++ b/FDTD/operator_ext_pml_sf.cpp @@ -21,7 +21,7 @@ #include "tools/array_ops.h" -bool Build_Split_Field_PML(Operator* op, int BC[6]) +bool Build_Split_Field_PML(Operator* op, int BC[6], int size[6]) { for (int n=0;n<6;++n) { @@ -30,7 +30,7 @@ bool Build_Split_Field_PML(Operator* op, int BC[6]) 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); - op_pml_sf->SetPMLLength(8); + op_pml_sf->SetPMLLength(size[n]); op_pml_sf->SetBoundaryCondition(BC); op->AddExtension(op_pml_sf); } diff --git a/FDTD/operator_ext_pml_sf.h b/FDTD/operator_ext_pml_sf.h index 1e15d80..764e119 100644 --- a/FDTD/operator_ext_pml_sf.h +++ b/FDTD/operator_ext_pml_sf.h @@ -22,7 +22,7 @@ #include "operator_extension.h" //! 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]); +bool Build_Split_Field_PML(Operator* op, int BC[6], int size[6]); //! This is the abstract operator extension for truncating the FDTD domain with a split field pml class Operator_Ext_PML_SF : public Operator_Extension diff --git a/openems.cpp b/openems.cpp index a736e05..84f2c1c 100644 --- a/openems.cpp +++ b/openems.cpp @@ -153,11 +153,63 @@ bool openEMS::parseCommandLineArgument( const char *argv ) return false; } +bool openEMS::SetupBoundaryConditions(TiXmlElement* BC) +{ + int EC; //error code of tinyxml + 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; + + string bound_names[] = {"xmin","xmax","ymin","ymax","zmin","zmax"}; + + for (int n=0;n<6;++n) + { + EC = BC->QueryIntAttribute(bound_names[n].c_str(),&bounds[n]); + if (EC==TIXML_SUCCESS) + continue; + if (EC==TIXML_WRONG_TYPE) + { + s_bc = string(BC->Attribute(bound_names[n].c_str())); + if (s_bc=="PEC") + bounds[n] = 0; + else if (s_bc=="PMC") + bounds[n] = 1; + else if (s_bc=="MUR") + bounds[n] = 2; + else if(strncmp(s_bc.c_str(),"PML_=",4)==0) + { + bounds[n] = 3; + pml_size[n] = atoi(s_bc.c_str()+4); + } + else + cerr << "openEMS::SetupBoundaryConditions: Warning, boundary condition for \"" << bound_names[n] << "\" unknown... set to PEC " << endl; + } + else + cerr << "openEMS::SetupBoundaryConditions: Warning, boundary condition for \"" << bound_names[n] << "\" not found... set to PEC " << endl; + } + + FDTD_Op->SetBoundaryCondition(bounds); //operator only knows about PEC and PMC, everything else is defined by extensions (see below) + + /**************************** create all operator/engine extensions here !!!! **********************************/ + //Mur-ABC, defined as extension to the operator + for (int n=0;n<6;++n) + { + if (bounds[n]==2) //Mur-ABC + { + Operator_Ext_Mur_ABC* op_ext_mur = new Operator_Ext_Mur_ABC(FDTD_Op); + op_ext_mur->SetDirection(n/2,n%2); + FDTD_Op->AddExtension(op_ext_mur); + } + } + Build_Split_Field_PML(FDTD_Op,bounds,pml_size); + + return true; +} + int openEMS::SetupFDTD(const char* file) { if (file==NULL) return -1; Reset(); - int bounds[6]; timeval startTime; gettimeofday(&startTime,NULL); @@ -218,12 +270,6 @@ int openEMS::SetupFDTD(const char* file) cerr << "Can't read openEMS boundary cond Settings... " << endl; exit(-3); } - BC->QueryIntAttribute("xmin",&bounds[0]); - BC->QueryIntAttribute("xmax",&bounds[1]); - BC->QueryIntAttribute("ymin",&bounds[2]); - BC->QueryIntAttribute("ymax",&bounds[3]); - BC->QueryIntAttribute("zmin",&bounds[4]); - BC->QueryIntAttribute("zmax",&bounds[5]); cout << "Read Geometry..." << endl; ContinuousStructure CSX; @@ -262,20 +308,7 @@ int openEMS::SetupFDTD(const char* file) if (FDTD_Op->SetGeometryCSX(&CSX)==false) return(2); - FDTD_Op->SetBoundaryCondition(bounds); //operator only knows about PEC and PMC, everything else is defined by extensions (see below) - - /**************************** create all operator/engine extensions here !!!! **********************************/ - //Mur-ABC, defined as extension to the operator - for (int n=0;n<6;++n) - { - if (bounds[n]==2) //Mur-ABC - { - Operator_Ext_Mur_ABC* op_ext_mur = new Operator_Ext_Mur_ABC(FDTD_Op); - op_ext_mur->SetDirection(n/2,n%2); - FDTD_Op->AddExtension(op_ext_mur); - } - } - Build_Split_Field_PML(FDTD_Op,bounds); + SetupBoundaryConditions(BC); if (CSX.GetQtyPropertyType(CSProperties::LORENTZMATERIAL)>0) FDTD_Op->AddExtension(new Operator_Ext_LorentzMaterial(FDTD_Op)); diff --git a/openems.h b/openems.h index 73aa2cc..eae1bc7 100644 --- a/openems.h +++ b/openems.h @@ -63,6 +63,9 @@ protected: enum EngineType {EngineType_Standard, EngineType_SSE, EngineType_SSE_Compressed, EngineType_Multithreaded}; EngineType m_engine; unsigned int m_engine_numThreads; + + //! Read boundary conditions from xml element and apply to FDTD operator + bool SetupBoundaryConditions(TiXmlElement* BC); }; #endif // OPENEMS_H