├── .github └── workflows │ └── ci.yml ├── CMakeLists.txt ├── COPYING ├── INSTALL ├── NEWS ├── README ├── cmake └── Modules │ └── FindTinyXML.cmake ├── doxydoc ├── linux ├── CSXCAD.dsc ├── CSXCAD.spec ├── CSXGeomPlot.m.patch ├── README.patch ├── debian.changelog ├── debian.control ├── debian.csxcad-dev.install ├── debian.csxcad.docs ├── debian.csxcad.install ├── debian.rules └── debian.series ├── matlab ├── AddBox.m ├── AddConductingSheet.m ├── AddCurve.m ├── AddCylinder.m ├── AddCylindricalShell.m ├── AddDebyeMaterial.m ├── AddDiscMaterial.m ├── AddDump.m ├── AddExcitation.m ├── AddLinPoly.m ├── AddLorentzMaterial.m ├── AddLumpedElement.m ├── AddMaterial.m ├── AddMetal.m ├── AddPlaneWaveExcite.m ├── AddPoint.m ├── AddPolygon.m ├── AddPolyhedron.m ├── AddProbe.m ├── AddPropAttribute.m ├── AddRotPoly.m ├── AddSphere.m ├── AddSphericalShell.m ├── AddWire.m ├── AnalyseMesh.m ├── AutoSmoothMeshLines.m ├── CSXGeomPlot.m ├── CalcDebyeMaterial.m ├── CalcDrudeMaterial.m ├── CalcLorentzMaterial.m ├── CheckMesh.m ├── Convert_VF_DiscMaterial.m ├── CreateDiscMaterial.m ├── DefineRectGrid.m ├── DetectEdges.m ├── DirChar2Int.m ├── ImportPLY.m ├── ImportSTL.m ├── InitCSX.m ├── RecursiveSmoothMesh.m ├── SetBackgroundMaterial.m ├── SetExcitationWeight.m ├── SetMaterialProperty.m ├── SetMaterialWeight.m ├── SmoothMesh.m ├── SmoothMeshLines.m ├── SmoothMeshLines2.m ├── export_empire.m ├── export_excellon.m ├── export_gerber.m ├── export_povray.m ├── isOctave.m ├── private │ ├── Add2Property.m │ ├── AddPrimitiveArgs.m │ ├── AddProperty.m │ ├── CheckSymmtricLines.m │ ├── FindProperty.m │ ├── GetPropertyPosition.m │ ├── GetPropertyType.m │ ├── SetPropertyArgs.m │ ├── SmoothRange.m │ ├── octave_struct2xml_2.m │ ├── struct_2_xmlNode.m │ └── vector2str.m ├── searchBinary.m └── struct_2_xml.m ├── python ├── CSXCAD │ ├── CSPrimitives.pxd │ ├── CSPrimitives.pyx │ ├── CSProperties.pxd │ ├── CSProperties.pyx │ ├── CSRectGrid.pxd │ ├── CSRectGrid.pyx │ ├── CSTransform.pxd │ ├── CSTransform.pyx │ ├── CSXCAD.pxd │ ├── CSXCAD.pyx │ ├── ParameterObjects.pxd │ ├── ParameterObjects.pyx │ ├── SmoothMeshLines.py │ ├── Utilities.pyx │ └── __init__.py ├── README.md ├── doc │ ├── CSPrimitives.rst │ ├── CSPrimitives │ │ ├── CSPrimBox.rst │ │ ├── CSPrimCurve.rst │ │ ├── CSPrimCylinder.rst │ │ ├── CSPrimCylindricalShell.rst │ │ ├── CSPrimLinPoly.rst │ │ ├── CSPrimPoint.rst │ │ ├── CSPrimPolygon.rst │ │ ├── CSPrimPolyhedron.rst │ │ ├── CSPrimPolyhedronReader.rst │ │ ├── CSPrimRotPoly.rst │ │ ├── CSPrimSphere.rst │ │ ├── CSPrimSphericalShell.rst │ │ ├── CSPrimWire.rst │ │ └── CSPrimitives.rst │ ├── CSProperties.rst │ ├── CSProperties │ │ ├── CSPropConductingSheet.rst │ │ ├── CSPropDumpBox.rst │ │ ├── CSPropExcitation.rst │ │ ├── CSPropLumpedElement.rst │ │ ├── CSPropMaterial.rst │ │ ├── CSPropMetal.rst │ │ ├── CSPropProbeBox.rst │ │ └── CSProperties.rst │ ├── CSRectGrid.rst │ ├── CSTransform.rst │ ├── CSXCAD.rst │ ├── CSXCAD_API.rst │ ├── Makefile │ ├── Mesh.rst │ ├── Utilities.rst │ ├── about.rst │ ├── conf.py │ ├── index.rst │ └── install.rst ├── setup.py └── tests │ ├── sphere.ply │ ├── sphere.stl │ ├── test_CSPrimitives.py │ ├── test_CSProperties.py │ ├── test_CSRectGrid.py │ ├── test_CSTransform.py │ └── test_CSXCAD.py └── src ├── CMakeLists.txt ├── CSBackgroundMaterial.cpp ├── CSBackgroundMaterial.h ├── CSFunctionParser.cpp ├── CSFunctionParser.h ├── CSPrimBox.cpp ├── CSPrimBox.h ├── CSPrimCurve.cpp ├── CSPrimCurve.h ├── CSPrimCylinder.cpp ├── CSPrimCylinder.h ├── CSPrimCylindricalShell.cpp ├── CSPrimCylindricalShell.h ├── CSPrimLinPoly.cpp ├── CSPrimLinPoly.h ├── CSPrimMultiBox.cpp ├── CSPrimMultiBox.h ├── CSPrimPoint.cpp ├── CSPrimPoint.h ├── CSPrimPolygon.cpp ├── CSPrimPolygon.h ├── CSPrimPolyhedron.cpp ├── CSPrimPolyhedron.h ├── CSPrimPolyhedronReader.cpp ├── CSPrimPolyhedronReader.h ├── CSPrimPolyhedron_p.h ├── CSPrimRotPoly.cpp ├── CSPrimRotPoly.h ├── CSPrimSphere.cpp ├── CSPrimSphere.h ├── CSPrimSphericalShell.cpp ├── CSPrimSphericalShell.h ├── CSPrimUserDefined.cpp ├── CSPrimUserDefined.h ├── CSPrimWire.cpp ├── CSPrimWire.h ├── CSPrimitives.cpp ├── CSPrimitives.h ├── CSPropConductingSheet.cpp ├── CSPropConductingSheet.h ├── CSPropDebyeMaterial.cpp ├── CSPropDebyeMaterial.h ├── CSPropDiscMaterial.cpp ├── CSPropDiscMaterial.h ├── CSPropDispersiveMaterial.cpp ├── CSPropDispersiveMaterial.h ├── CSPropDumpBox.cpp ├── CSPropDumpBox.h ├── CSPropExcitation.cpp ├── CSPropExcitation.h ├── CSPropLorentzMaterial.cpp ├── CSPropLorentzMaterial.h ├── CSPropLumpedElement.cpp ├── CSPropLumpedElement.h ├── CSPropMaterial.cpp ├── CSPropMaterial.h ├── CSPropMetal.cpp ├── CSPropMetal.h ├── CSPropProbeBox.cpp ├── CSPropProbeBox.h ├── CSPropResBox.cpp ├── CSPropResBox.h ├── CSPropUnknown.cpp ├── CSPropUnknown.h ├── CSProperties.cpp ├── CSProperties.h ├── CSRectGrid.cpp ├── CSRectGrid.h ├── CSTransform.cpp ├── CSTransform.h ├── CSUseful.cpp ├── CSUseful.h ├── CSXCAD_Global.h ├── ContinuousStructure.cpp ├── ContinuousStructure.h ├── ParameterCoord.cpp ├── ParameterCoord.h ├── ParameterObjects.cpp └── ParameterObjects.h /INSTALL: -------------------------------------------------------------------------------- 1 | Install instructions for the CSXCAD library: 2 | --------------------------------------------- 3 | 4 | 1) Prerequirements: 5 | CSXCAD relies on a number of third-party open-source libraries: 6 | - fparser (http://warp.povusers.org/FunctionParser/) 7 | - tinyxml (http://www.grinninglizard.com/tinyxml/) 8 | - hdf5 (http://www.hdfgroup.org/HDF5/) 9 | - vtk (http://www.vtk.org/) 10 | - boost (http://www.boost.org/) 11 | - cgal (http://www.cgal.org/) 12 | 13 | 2) Build: 14 | - change directory to CSXCAD 15 | - build: 16 | mkdir build 17 | cd build 18 | cmake .. -DCMAKE_INSTALL_PREFIX= -DFPARSER_ROOT_DIR= 19 | make 20 | make install (may require root) 21 | 22 | Note: 23 | - all path informations may be stored in a localConfig.cmake 24 | - the default "prefix" is /usr/local 25 | 26 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | Changes in v0.5.1 2 | ------------------------------- 3 | - matlab interface: throw an error when re-adding an already existing property (fix) 4 | 5 | Changes in v0.5.0 6 | ------------------------------- 7 | - new file-format for discrete materials 8 | - new create function for discrete materials 9 | - fix for curve primitive in cylindrical coordinates 10 | - full multi-pole Lorentz/Drude/Debye material models 11 | - extensive code-cleanup 12 | - bug fixes -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | * 2 | * CSXCAD - Continuous Structure XML 3 | * 4 | 5 | A C++ library to describe geometrical objects and their physical or non-physical properties. 6 | CSXCAD is licensed under the terms of the LGPLv3. 7 | 8 | -------------------------------------------------------------------------------- /cmake/Modules/FindTinyXML.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################################## 2 | # 3 | # CMake script for finding TinyXML. 4 | # 5 | # Input variables: 6 | # 7 | # - TinyXML_ROOT_DIR (optional): When specified, header files and libraries will be searched for in 8 | # ${TinyXML_ROOT_DIR}/include 9 | # ${TinyXML_ROOT_DIR}/libs 10 | # respectively, and the default CMake search order will be ignored. When unspecified, the default 11 | # CMake search order is used. 12 | # This variable can be specified either as a CMake or environment variable. If both are set, 13 | # preference is given to the CMake variable. 14 | # Use this variable for finding packages installed in a nonstandard location, or for enforcing 15 | # that one of multiple package installations is picked up. 16 | # 17 | # 18 | # Cache variables (not intended to be used in CMakeLists.txt files) 19 | # 20 | # - TinyXML_INCLUDE_DIR: Absolute path to package headers. 21 | # - TinyXML_LIBRARY: Absolute path to library. 22 | # 23 | # 24 | # Output variables: 25 | # 26 | # - TinyXML_FOUND: Boolean that indicates if the package was found 27 | # - TinyXML_INCLUDE_DIRS: Paths to the necessary header files 28 | # - TinyXML_LIBRARIES: Package libraries 29 | # 30 | # 31 | # Example usage: 32 | # 33 | # find_package(TinyXML) 34 | # if(NOT TinyXML_FOUND) 35 | # # Error handling 36 | # endif() 37 | # ... 38 | # include_directories(${TinyXML_INCLUDE_DIRS} ...) 39 | # ... 40 | # target_link_libraries(my_target ${TinyXML_LIBRARIES}) 41 | # 42 | ################################################################################################## 43 | 44 | # Get package location hint from environment variable (if any) 45 | if(NOT TinyXML_ROOT_DIR AND DEFINED ENV{TinyXML_ROOT_DIR}) 46 | set(TinyXML_ROOT_DIR "$ENV{TinyXML_ROOT_DIR}" CACHE PATH 47 | "TinyXML base directory location (optional, used for nonstandard installation paths)") 48 | endif() 49 | 50 | # Search path for nonstandard package locations 51 | if(TinyXML_ROOT_DIR) 52 | set(TinyXML_INCLUDE_PATH PATHS "${TinyXML_ROOT_DIR}/include" NO_DEFAULT_PATH) 53 | set(TinyXML_LIBRARY_PATH PATHS "${TinyXML_ROOT_DIR}/lib" NO_DEFAULT_PATH) 54 | endif() 55 | 56 | # Find headers and libraries 57 | find_path(TinyXML_INCLUDE_DIR NAMES tinyxml.h PATH_SUFFIXES "tinyxml" ${TinyXML_INCLUDE_PATH}) 58 | find_library(TinyXML_LIBRARY NAMES tinyxml PATH_SUFFIXES "tinyxml" ${TinyXML_LIBRARY_PATH}) 59 | 60 | mark_as_advanced(TinyXML_INCLUDE_DIR 61 | TinyXML_LIBRARY) 62 | 63 | # Output variables generation 64 | include(FindPackageHandleStandardArgs) 65 | find_package_handle_standard_args(TinyXML DEFAULT_MSG TinyXML_LIBRARY 66 | TinyXML_INCLUDE_DIR) 67 | 68 | set(TinyXML_FOUND ${TINYXML_FOUND}) # Enforce case-correctness: Set appropriately cased variable... 69 | unset(TINYXML_FOUND) # ...and unset uppercase variable generated by find_package_handle_standard_args 70 | 71 | if(TinyXML_FOUND) 72 | set(TinyXML_INCLUDE_DIRS ${TinyXML_INCLUDE_DIR}) 73 | set(TinyXML_LIBRARIES ${TinyXML_LIBRARY}) 74 | endif() 75 | -------------------------------------------------------------------------------- /linux/CSXCAD.dsc: -------------------------------------------------------------------------------- 1 | Format: 1.0 2 | Source: csxcad 3 | Version: 0.3.0-3 4 | Binary: csxcad, csxcad-dev 5 | Maintainer: Thorsten Liebig , Sebastian Held 6 | Homepage: http://www.openems.de 7 | Architecture: any 8 | Build-Depends: debhelper (>=7.0.50~), qt4-qmake, libfparser4, libhdf5-serial-dev, libtinyxml-dev, libvtk5-qt4-dev 9 | DEBTRANSFORM-TAR: CSXCAD-0.3.0.tar.bz2 10 | -------------------------------------------------------------------------------- /linux/CSXGeomPlot.m.patch: -------------------------------------------------------------------------------- 1 | diff --git a/matlab/CSXGeomPlot.m b/matlab/CSXGeomPlot.m 2 | index 21d3ef8..37427a1 100644 3 | --- a/matlab/CSXGeomPlot.m 4 | +++ b/matlab/CSXGeomPlot.m 5 | @@ -13,18 +13,10 @@ if nargin < 1 6 | error 'specify the xml file to open' 7 | end 8 | 9 | -filename = mfilename('fullpath'); 10 | -dir = fileparts( filename ); 11 | -AppCSXCAD_Path = [dir filesep '../../AppCSXCAD' filesep]; 12 | - 13 | -if (~exist(AppCSXCAD_Path,'dir')) 14 | - AppCSXCAD_Path = [dir filesep '..' filesep] 15 | -end 16 | - 17 | if isunix 18 | - AppCSXCAD_Path = [AppCSXCAD_Path 'AppCSXCAD.sh']; 19 | + AppCSXCAD_Path = 'AppCSXCAD.sh'; 20 | else 21 | - AppCSXCAD_Path = [AppCSXCAD_Path 'AppCSXCAD']; 22 | + AppCSXCAD_Path = 'AppCSXCAD'; 23 | end 24 | 25 | command = [AppCSXCAD_Path ' --disableEdit ' CSX_filename]; 26 | -------------------------------------------------------------------------------- /linux/README.patch: -------------------------------------------------------------------------------- 1 | diff --git a/README b/README 2 | index 9b5056e..fc3176c 100644 3 | --- a/README 4 | +++ b/README 5 | @@ -11,8 +11,8 @@ Forum: http://openems.de/forum/ 6 | Tutorials: http://openems.de/index.php/Tutorials 7 | 8 | 9 | -To use CSXCAD from Matlab or Octave, you need to include the /matlab folder in the respective environment: 10 | -> addpath( '/matlab' ); 11 | +To use CSXCAD from Matlab or Octave, you need to include the /usr/share/CSXCAD/matlab folder in the respective environment: 12 | +> addpath( '/usr/share/CSXCAD/matlab' ); 13 | 14 | To verify the correct installation follow the instructions at: 15 | http://openems.de/index.php/Tutorial:_First_Steps 16 | -------------------------------------------------------------------------------- /linux/debian.changelog: -------------------------------------------------------------------------------- 1 | csxcad (0.3.0-3) stable; urgency=low 2 | * replaced recommended deps by suggested deps 3 | -- Sebastian Held Sat, 30 Jun 2012 12:16:00 +0200 4 | csxcad (0.3.0-2) stable; urgency=low 5 | * fixed missing files and version information 6 | -- Sebastian Held Sat, 23 Jun 2012 11:58:00 +0200 7 | csxcad (0.3.0-1) stable; urgency=low 8 | * New upstream version 9 | -- Sebastian Held Sun, 17 Jun 2012 21:54:30 +0200 10 | csxcad (0.2.4-6) stable; urgency=low 11 | * New upstream fix 12 | -- Sebastian Held Wed, 29 Feb 2012 23:20:00 +0100 13 | csxcad (0.2.4-5) stable; urgency=low 14 | * New upstream fix 15 | -- Sebastian Held Sat, 21 Jan 2012 21:22:00 +0100 16 | csxcad (0.2.4-4) stable; urgency=low 17 | * Added README 18 | -- Sebastian Held Thu, 29 Dec 2011 21:06:00 +0100 19 | csxcad (0.2.4-3) stable; urgency=low 20 | * New upstream fix 21 | -- Sebastian Held Thu, 22 Dec 2011 22:45:00 +0100 22 | csxcad (0.2.4-2) stable; urgency=low 23 | * New upstream release 24 | -- Sebastian Held Sun, 4 Dec 2011 15:20:00 +0100 25 | csxcad (0.0.24-1) stable; urgency=low 26 | * Initial Release 27 | -- Sebastian Held Thu, 6 Oct 2011 17:58:38 +0200 28 | -------------------------------------------------------------------------------- /linux/debian.control: -------------------------------------------------------------------------------- 1 | Source: csxcad 2 | Section: contrib/libdevel 3 | Priority: optional 4 | Maintainer: Sebastian Held 5 | Build-Depends: debhelper (>=7.0.50~), qt4-qmake, libfparser4, libhdf5-serial-dev, libtinyxml-dev, libvtk5-qt4-dev 6 | 7 | Package: csxcad 8 | Architecture: any 9 | Depends: ${shlibs:Depends} 10 | Suggests: appcsxcad 11 | Description: Library for Geometric Primitives primarily used by openEMS 12 | Library for Geometric Primitives primarily used by openEMS. 13 | 14 | Package: csxcad-dev 15 | Architecture: any 16 | Depends: ${shlibs:Depends} csxcad (= ${binary:Version}) 17 | Description: Development files for csxcad 18 | The csxcad-dev package contains libraries and header files for developing applications that use csxcad. 19 | -------------------------------------------------------------------------------- /linux/debian.csxcad-dev.install: -------------------------------------------------------------------------------- 1 | usr/include/* 2 | usr/lib/*.so 3 | -------------------------------------------------------------------------------- /linux/debian.csxcad.docs: -------------------------------------------------------------------------------- 1 | COPYING 2 | README 3 | -------------------------------------------------------------------------------- /linux/debian.csxcad.install: -------------------------------------------------------------------------------- 1 | usr/lib/*.so.* 2 | usr/share/CSXCAD/* 3 | -------------------------------------------------------------------------------- /linux/debian.rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | export DH_VERBOSE=1 4 | export DH_OPTIONS=-v 5 | export DH_COMPAT=7 6 | 7 | %: 8 | dh $@ 9 | -------------------------------------------------------------------------------- /linux/debian.series: -------------------------------------------------------------------------------- 1 | CSXGeomPlot.m.patch -p1 2 | README.patch -p1 3 | -------------------------------------------------------------------------------- /matlab/AddBox.m: -------------------------------------------------------------------------------- 1 | function CSX = AddBox(CSX, propName, prio, start, stop, varargin) 2 | % function CSX = AddBox(CSX, propName, prio, start, stop, varargin) 3 | % 4 | % Add a box to CSX and assign to a property with name . 5 | % 6 | % - start: box start coordinates 7 | % - stop : box stop coordinates 8 | % - prio : primitive priority 9 | % 10 | % optional: 11 | % - Transformation: perform a transformation on a primitive by adding 12 | % e.g.: 'Transform', {'Scale','1,1,2','Rotate_X',pi/4,'Translate','0,0,100'} 13 | % Note: This will only affect the 3D material/metal discretisation 14 | % 15 | % example: 16 | % 17 | % CSX = AddMetal(CSX,'metal'); %create PEC with propName 'metal' 18 | % CSX = AddBox(CSX,'metal',10,[0 0 0],[100 100 200]); %assign box 19 | % 20 | % with transformation: 21 | % 22 | % CSX = AddBox(CSX,'metal',10,[0 0 0],[100 100 200], ... 23 | % 'Transform', {Rotate_Z, pi/4}); 24 | % 25 | % See also AddCylinder, AddCylindricalShell, AddSphere, AddSphericalShell, 26 | % AddCurve, AddWire, AddMetal 27 | % 28 | % CSXCAD matlab interface 29 | % ----------------------- 30 | % author: Thorsten Liebig 31 | 32 | box.ATTRIBUTE.Priority = prio; 33 | 34 | box.P1.ATTRIBUTE.X=start(1); 35 | box.P1.ATTRIBUTE.Y=start(2); 36 | box.P1.ATTRIBUTE.Z=start(3); 37 | 38 | box.P2.ATTRIBUTE.X=stop(1); 39 | box.P2.ATTRIBUTE.Y=stop(2); 40 | box.P2.ATTRIBUTE.Z=stop(3); 41 | 42 | box = AddPrimitiveArgs(box,varargin{:}); 43 | 44 | CSX = Add2Property(CSX,propName, box, 'Box'); 45 | -------------------------------------------------------------------------------- /matlab/AddConductingSheet.m: -------------------------------------------------------------------------------- 1 | function CSX = AddConductingSheet(CSX, name, conductivity, thickness) 2 | %function CSX = AddConductingSheet(CSX, name, conductivity, thickness) 3 | % 4 | % Add a conducting sheet property to CSX with the given name. 5 | % Remember to add at least one or more 2D!! geometrical primitives to this 6 | % property. 7 | % 8 | % Hint: 9 | % Set the thickness to 0 to fall back to a perfect metal (AddMetal) 10 | % 11 | % example: 12 | % 13 | % % create the conducting material peroperty, e.g. 40um thick copper 14 | % CSX = AddConductingSheet(CSX,'copper',56e6,40e-6); 15 | % % assign box the 2D box --> 40um thick sheet 16 | % CSX = AddBox(CSX,'copper',10,[0 -50 200],[1000 50 200]); 17 | % 18 | % See also AddMaterial, AddMetal, AddExcitation, AddBox 19 | % 20 | % CSXCAD matlab interface 21 | % ----------------------- 22 | % author: Thorsten Liebig 2012 23 | 24 | 25 | % fall back to ideal pec for t==0 or c==0 26 | if ((thickness==0) || (conductivity==0)) 27 | CSX = AddMetal(CSX,name); 28 | return; 29 | end 30 | 31 | if ((conductivity<0) || (thickness<0)) 32 | error('CSXCAD:AddConductingSheet','a negative conductivity or thickness is invalid'); 33 | end 34 | 35 | if (conductivity<1e6) 36 | warning('CSXCAD:AddConductingSheet','a conductivity below 1MA/Vm is not recommended'); 37 | end 38 | 39 | if (thickness>500e-6) 40 | warning('CSXCAD:AddConductingSheet','a thickness greater than 500um is not recommended'); 41 | end 42 | 43 | 44 | if (thickness<1e-6) 45 | warning('CSXCAD:AddConductingSheet','a thickness lower than 1um is not recommended'); 46 | end 47 | 48 | CSX = AddProperty(CSX, 'ConductingSheet', name,'Conductivity',conductivity,'Thickness',thickness); 49 | -------------------------------------------------------------------------------- /matlab/AddCurve.m: -------------------------------------------------------------------------------- 1 | function CSX = AddCurve(CSX, propName, prio, points, varargin) 2 | % function CSX = AddCurve(CSX, propName, prio, points, varargin) 3 | % 4 | % Add a curve to CSX and assign to a property with name . 5 | % 6 | % Warning: This is a 1D object, not all properties may be compatible with a 7 | % 1D object, e.g. a material property. 8 | % 9 | % - points: curve coordinates array 10 | % - prio : primitive priority 11 | % 12 | % example: 13 | % 14 | % %first point 15 | % points(1,1) = 0; 16 | % points(2,1) = 5; 17 | % points(3,1) = 10; 18 | % %second point 19 | % points(1,2) = 0; 20 | % points(2,2) = 10; 21 | % points(3,2) = 10; 22 | % %third point ... 23 | % % create a thin metal wire... 24 | % CSX = AddMetal(CSX,'metal'); %create PEC with propName 'metal' 25 | % CSX = AddCurve(CSX,'metal',10, points); 26 | % 27 | % See also AddBox, AddCylindricalShell, AddCylinder, AddSphere, 28 | % AddSphericalShell, AddWire, AddMetal 29 | % 30 | % CSXCAD matlab interface 31 | % ----------------------- 32 | % author: Thorsten Liebig 33 | 34 | curve.ATTRIBUTE.Priority = prio; 35 | 36 | curve.Vertex={}; 37 | for s=1:size(points,2) 38 | curve.Vertex{end+1}.ATTRIBUTE.X = points(1,s); 39 | curve.Vertex{end}.ATTRIBUTE.Y = points(2,s); 40 | curve.Vertex{end}.ATTRIBUTE.Z = points(3,s); 41 | end 42 | 43 | curve = AddPrimitiveArgs(curve,varargin{:}); 44 | 45 | CSX = Add2Property(CSX,propName, curve, 'Curve'); 46 | -------------------------------------------------------------------------------- /matlab/AddCylinder.m: -------------------------------------------------------------------------------- 1 | function CSX = AddCylinder(CSX, propName, prio, start, stop, rad, varargin) 2 | % function CSX = AddCylinder(CSX, propName, prio, start, stop, rad, varargin) 3 | % 4 | % Add a cylinder to CSX and assign to a property with name . 5 | % 6 | % - start: cylinder axis start coordinates 7 | % - stop : cylinder axis box stop coordinates 8 | % - rad : cylinder radius 9 | % - prio : primitive priority 10 | % 11 | % example: 12 | % 13 | % CSX = AddMetal(CSX,'metal'); %create PEC with propName 'metal' 14 | % CSX = AddCylinder(CSX,'metal',10,[0 0 0],[0 0 200],50); 15 | % 16 | % See also AddBox, AddCylindricalShell, AddSphere, AddSphericalShell, 17 | % AddCurve, AddWire, AddMetal 18 | % 19 | % CSXCAD matlab interface 20 | % ----------------------- 21 | % author: Thorsten Liebig 22 | 23 | cylinder.ATTRIBUTE.Priority = prio; 24 | cylinder.ATTRIBUTE.Radius = rad; 25 | 26 | cylinder.P1.ATTRIBUTE.X=start(1); 27 | cylinder.P1.ATTRIBUTE.Y=start(2); 28 | cylinder.P1.ATTRIBUTE.Z=start(3); 29 | 30 | cylinder.P2.ATTRIBUTE.X=stop(1); 31 | cylinder.P2.ATTRIBUTE.Y=stop(2); 32 | cylinder.P2.ATTRIBUTE.Z=stop(3); 33 | 34 | cylinder = AddPrimitiveArgs(cylinder,varargin{:}); 35 | 36 | CSX = Add2Property(CSX,propName, cylinder, 'Cylinder'); 37 | -------------------------------------------------------------------------------- /matlab/AddCylindricalShell.m: -------------------------------------------------------------------------------- 1 | function CSX = AddCylindricalShell(CSX, propName, prio, start, stop, rad, shell_width, varargin) 2 | %function CSX = AddCylindricalShell(CSX, propName, prio, start, stop, rad, shell_width, varargin) 3 | % 4 | % Add a cylinder shell to CSX and assign to a property with name . 5 | % 6 | % - start: cylinder axis start coordinates 7 | % - stop : cylinder axis box stop coordinates 8 | % - rad : cylinder radius 9 | % - shell_width: cylinder shell width 10 | % - prio : primitive priority 11 | % 12 | % Note: 13 | % - the inner radius of this shell is rad-shell_width/2 14 | % - the outer radius of this shell is rad+shell_width/2 15 | % 16 | % example: 17 | % 18 | % CSX = AddMetal(CSX,'metal'); %create PEC with propName 'metal' 19 | % CSX = AddCylindricalShell(CSX,'metal',10,[0 0 0],[0 0 200],50,10); 20 | % 21 | % See also AddBox, AddCylinder, AddSphere, AddSphericalShell, 22 | % AddCurve, AddWire, AddMetal 23 | % 24 | % CSXCAD matlab interface 25 | % ----------------------- 26 | % author: Thorsten Liebig 27 | 28 | cylinder.ATTRIBUTE.Priority = prio; 29 | cylinder.ATTRIBUTE.Radius = rad; 30 | cylinder.ATTRIBUTE.ShellWidth = shell_width; 31 | 32 | cylinder.P1.ATTRIBUTE.X=start(1); 33 | cylinder.P1.ATTRIBUTE.Y=start(2); 34 | cylinder.P1.ATTRIBUTE.Z=start(3); 35 | 36 | cylinder.P2.ATTRIBUTE.X=stop(1); 37 | cylinder.P2.ATTRIBUTE.Y=stop(2); 38 | cylinder.P2.ATTRIBUTE.Z=stop(3); 39 | 40 | cylinder = AddPrimitiveArgs(cylinder,varargin{:}); 41 | 42 | CSX = Add2Property(CSX,propName, cylinder, 'CylindricalShell'); 43 | -------------------------------------------------------------------------------- /matlab/AddDebyeMaterial.m: -------------------------------------------------------------------------------- 1 | function CSX = AddDebyeMaterial(CSX, name, varargin) 2 | % function CSX = AddDebyeMaterial(CSX, name, varargin) 3 | % 4 | % Add a Debye type dispersive material model. 5 | % 6 | % The Debye type frequency dependent material: 7 | % 8 | % eps_r(w) = eps_r + sum_p ( eps_r_delta,p / (1+jw*t_relex,p) ) - j*kappa/w 9 | % 10 | % with 11 | % - eps_r_delta,p: the delta electric relative permitivity 12 | % - t_relex,p: the electric relaxation time 13 | % 14 | % Use SetMaterialProperty to define the material constants: 15 | % - 'EpsilonDelta_p': p-th eps_r_delta,p 16 | % - 'EpsilonRelaxTime_p': p-th t_relex,p 17 | % 18 | % example: 19 | % 20 | % CSX = AddDebyeMaterial(CSX,'debye'); 21 | % CSX = SetMaterialProperty(CSX,'debye','Epsilon',5,'EpsilonDelta_1',0.1,'EpsilonRelaxTime_1',1e-9); 22 | % [..] 23 | % CSX = AddBox(CSX,'debye', 10 ,start,stop); 24 | % 25 | % See also AddBox, AddMaterial, SetMaterialProperty, AddLorentzMaterial 26 | % 27 | % CSXCAD matlab interface 28 | % ----------------------- 29 | % author: Thorsten Liebig (2013) 30 | 31 | CSX = AddProperty(CSX, 'DebyeMaterial', name, varargin{:}); 32 | -------------------------------------------------------------------------------- /matlab/AddDiscMaterial.m: -------------------------------------------------------------------------------- 1 | function CSX = AddDiscMaterial(CSX, name, varargin) 2 | % function CSX = AddDiscMaterial(CSX, name, varargin) 3 | % 4 | % Add a discretized material model property to CSX with the given name. 5 | % Discretized model has to be stored in an hdf5 file. 6 | % Use Transform option to perfom some transformation actions. 7 | % 8 | % variable arguments (key/value) 9 | % - 'File' (mandatory): define the filename of the discrete material 10 | % - 'Scale': scale the discrete material 11 | % e.g. to your drawing units: 'Scale', 1/unit 12 | % - 'Transform': Apply a transformation, see AddBox for more infos 13 | % - 'UseDBBackground': set to 0, to use the properties background material 14 | % instead of the database material with index 0 (default) 15 | % 16 | % examples: 17 | % 18 | % %add human body model 19 | % CSX = AddDiscMaterial(CSX, 'Ella', 'Scale', 1/unit, ... 20 | % 'Transform', {'Rotate_Z',pi/2,'Translate','300,300,500'}, ... 21 | % 'File', 'model_file_name.h5' ); 22 | % start = [mesh.x(1) mesh.y(1) mesh.z(1)]; 23 | % stop = [mesh.x(end) mesh.y(end) mesh.z(end)]; 24 | % CSX = AddBox(CSX,'Ella', 0 ,start,stop); 25 | % 26 | % See also AddBox, AddMetal, AddExcitation, AddProbe, AddDump 27 | % 28 | % CSXCAD matlab interface 29 | % ----------------------- 30 | % author: Thorsten Liebig 31 | 32 | transform = []; 33 | 34 | for n=1:2:(nargin-2) 35 | if (strcmp(varargin{n},'Transform')) 36 | transform = varargin([n:n+1]); 37 | varargin([n:n+1]) = []; 38 | break 39 | end 40 | end 41 | 42 | CSX = AddProperty(CSX, 'DiscMaterial', name, varargin{:}); 43 | 44 | if ~isempty(transform) 45 | for n=1:2:numel(transform{2}) 46 | CSX.Properties.DiscMaterial{end}.Transformation.(transform{2}{n}).ATTRIBUTE.Argument=transform{2}{n+1}; 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /matlab/AddExcitation.m: -------------------------------------------------------------------------------- 1 | function CSX = AddExcitation(CSX, name, type, excite, varargin) 2 | % function CSX = AddExcitation(CSX, name, type, excite, varargin) 3 | % 4 | % Creates an E-field or H-field excitation. 5 | % 6 | % - CSX: CSX-struct created by InitCSX 7 | % - name: property name for the excitation 8 | % - type: 0=E-field soft excitation 1=E-field hard excitation 9 | % 2=H-field soft excitation 3=H-field hard excitation 10 | % 10=plane wave excitation 11 | % 12 | % excite: e.g. [2 0 0] for excitation of 2 V/m in x-direction 13 | % 14 | % additional options for openEMS: 15 | % - 'Delay' : setup an excitation time delay in seconds 16 | % - 'PropDir': direction of plane wave propagation (plane wave excite only) 17 | % 18 | % example: 19 | % 20 | % CSX = AddExcitation( CSX, 'infDipole', 1, [1 0 0] ); 21 | % start = [-dipole_length/2, 0, 0]; 22 | % stop = [+dipole_length/2, 0, 0]; 23 | % CSX = AddBox( CSX, 'infDipole', 1, start, stop ); 24 | % 25 | % 26 | % CSXCAD matlab interface 27 | % ----------------------- 28 | % author: Thorsten Liebig 29 | % 30 | % See also SetExcitationWeight, AddMetal, AddExcitation, AddProbe, 31 | % AddDump, AddBox 32 | 33 | CSX = AddProperty(CSX, 'Excitation', name, 'Type', type, 'Excite', excite, varargin{:}); 34 | -------------------------------------------------------------------------------- /matlab/AddLinPoly.m: -------------------------------------------------------------------------------- 1 | function CSX = AddLinPoly( CSX, materialname, prio, normDir, elevation, points, Length, varargin) 2 | % CSX = AddLinPoly( CSX, materialname, prio, normDir, elevation, points, Length, varargin) 3 | % 4 | % - CSX: CSX-object created by InitCSX() 5 | % - materialname: created by AddMetal() or AddMaterial() 6 | % - prio: priority 7 | % - normDir: normal direction of the polygon, 8 | % e.g. 'x', 'y' or 'z', or numeric 0..2 9 | % - elevation: position of the polygon plane 10 | % - points: two-dimensional coordinates 11 | % - length: linear extrution in normal direction, starting at elevation 12 | % 13 | % Warning: Polygon has to be defined using Cartesian Coords 14 | % for use with cylindrical mesh, set 'CoordSystem',0 15 | % 16 | % example: 17 | % 18 | % p(1,1) = 0; % x-coord point 1 19 | % p(2,1) = 0; % y-coord point 1 20 | % p(1,2) = 10; % x-coord point 2 21 | % p(2,2) = 20; % y-coord point 2 22 | % % normal direction: z (2) 23 | % CSX = AddLinPoly( CSX, 'PEC', 1, 2, 254, p , 10, 'CoordSystem',0) 24 | % 25 | % 2011, Thorsten Liebig 26 | % 27 | % See also InitCSX AddMetal AddMaterial AddPolygon AddRotPoly 28 | 29 | polygon.ATTRIBUTE.Priority = prio; 30 | polygon.ATTRIBUTE.Elevation = elevation; 31 | polygon.ATTRIBUTE.Length = Length; 32 | polygon.ATTRIBUTE.NormDir = DirChar2Int(normDir); 33 | 34 | polygon.Vertex = {}; 35 | for s=1:size(points,2) 36 | polygon.Vertex{end+1}.ATTRIBUTE.X1 = points(1,s); 37 | polygon.Vertex{end}.ATTRIBUTE.X2 = points(2,s); 38 | end 39 | 40 | polygon = AddPrimitiveArgs(polygon,varargin{:}); 41 | 42 | CSX = Add2Property( CSX, materialname, polygon, 'LinPoly'); 43 | -------------------------------------------------------------------------------- /matlab/AddLorentzMaterial.m: -------------------------------------------------------------------------------- 1 | function CSX = AddLorentzMaterial(CSX, name, varargin) 2 | % function CSX = AddLorentzMaterial(CSX, name, varargin) 3 | % 4 | % Add a Drude/Lorentz type dispersive material model. 5 | % Note: openEMS currently only supports a drude material type. 6 | % 7 | % The drude type frequency dependent material: 8 | % 9 | % eps_r(f) = eps_r* ( 1 - f_eps_plasma^2/(f*(f-j/t_eps_r)) ) 10 | % mue_r(f) = mue_r* ( 1 - f_mue_plasma^2/(f*(f-j/t_mue_r)) ) 11 | % 12 | % with 13 | % 14 | % - f_eps_plasma: the respective electric angular plasma frequency 15 | % - f_mue_plasma: the respective magnetic angular plasma frequency 16 | % - t_eps_r: the respective electric relaxation time 17 | % - t_mue_r: the respective magnetic relaxation time 18 | % 19 | % Use SetMaterialProperty to define the material constants: 20 | % - 'EpsilonPlasmaFrequency': electric plasma frequency (f_eps_plasma) 21 | % - 'MuePlasmaFrequency': magnetic plasma frequency (f_mue_plasma) 22 | % - 'EpsilonRelaxTime': electric plasma relaxation time (losses) 23 | % - 'MueRelaxTime': magnetic plasma relaxation time (losses) 24 | % 25 | % Note: all properties must be positive values 26 | % 27 | % Higher order Drude type: 28 | % - 'EpsilonPlasmaFrequency_': n-th order electric plasma frequency (f_eps_plasma) 29 | % - 'MuePlasmaFrequency_': n-th order magnetic plasma frequency (f_mue_plasma) 30 | % - 'EpsilonRelaxTime_': n-th order electric plasma relaxation time (losses) 31 | % - 'MueRelaxTime_': n-th order magnetic plasma relaxation time (losses) 32 | % 33 | % The Lorentz type frequency dependent material: 34 | % 35 | % eps_r(f) = eps_r* ( 1 - f_eps_plasma^2/(f^2-f_eps_Lor_Pole^2-jf^2*/t_eps_r)) ) 36 | % mue_r(f) = mue_r* ( 1 - f_mue_plasma^2/(f^2-f_mue_Lor_Pole^2-jf^2*/t_mue_r)) ) 37 | % 38 | % with the additional parameter (see above) 39 | % 40 | % - f_eps_Lor_Pole: the respective electric angular lorentz pole frequency 41 | % - f_mue_Lor_Pole: the respective magnetic angular lorentz pole frequency 42 | % 43 | % Use SetMaterialProperty to define the material constants: 44 | % - 'EpsilonLorPoleFrequency': electric lorentz pole frequency (f_eps_Lor_Pole) 45 | % - 'MueLorPoleFrequency': magnetic lorentz pole frequency (f_mue_Lor_Pole) 46 | % 47 | % Note: all properties must be positive values 48 | % 49 | % Higher order Drude type: 50 | % - 'EpsilonLorPoleFrequency_': n-th order electric lorentz pole frequency (f_eps_plasma) 51 | % - 'MueLorPoleFrequency_': n-th order magnetic lorentz pole frequency (f_mue_plasma) 52 | % 53 | % example: 54 | % 55 | % CSX = AddLorentzMaterial(CSX,'drude'); 56 | % CSX = SetMaterialProperty(CSX,'drude','Epsilon',5,'EpsilonPlasmaFrequency',5e9,'EpsilonRelaxTime',1e-9); 57 | % CSX = SetMaterialProperty(CSX,'drude','Mue',5,'MuePlasmaFrequency',5e9,'MueRelaxTime',1e-9); 58 | % [..] 59 | % CSX = AddBox(CSX,'drude', 10 ,start,stop); 60 | % 61 | % See also AddBox, AddMaterial, SetMaterialProperty 62 | % 63 | % CSXCAD matlab interface 64 | % ----------------------- 65 | % author: Thorsten Liebig 66 | 67 | CSX = AddProperty(CSX, 'LorentzMaterial', name, varargin{:}); 68 | -------------------------------------------------------------------------------- /matlab/AddLumpedElement.m: -------------------------------------------------------------------------------- 1 | function CSX = AddLumpedElement(CSX, name, direction, varargin) 2 | % function CSX = AddLumpedElement(CSX, name, direction, varargin) 3 | % 4 | % Add a lumped element property to CSX with the given name. 5 | % Remember to add at least one or more box primitive to any 6 | % property. 7 | % 8 | % arguments: 9 | % - direction: 0,1,2 or 'x','y','z' for the orientation of the lumped element 10 | % 11 | % optional arguments: 12 | % - 'R', 'C', 'L': definition of the lumped element properties 13 | % - 'Caps': 0 or 1 to (de)activate lumped element caps (1=default) 14 | % If Caps are enable, a small PEC plate is added to each 15 | % end of the lumped element to ensure contact to e.g 16 | % a microstrip line 17 | % 18 | % examples: 19 | % 20 | % %lumped element capacitor in y-direction with 1pF 21 | % CSX = AddLumpedElement( CSX, 'Capacitor', 1, 'Caps', 1, 'C', 1e-12 ); 22 | % CSX = AddBox( CSX, 'Capacitor', 0, [0 0 0], [10 10 10] ); 23 | % 24 | % See also AddMaterial, AddMetal, AddExcitation, AddProbe, AddDump, AddBox 25 | % 26 | % CSXCAD matlab interface 27 | % ----------------------- 28 | % author: Thorsten Liebig 29 | 30 | CSX = AddProperty(CSX, 'LumpedElement', name, 'Direction', DirChar2Int(direction), varargin{:}); 31 | -------------------------------------------------------------------------------- /matlab/AddMaterial.m: -------------------------------------------------------------------------------- 1 | function CSX = AddMaterial(CSX, name, varargin) 2 | % function CSX = AddMaterial(CSX, name, varargin) 3 | % 4 | % Add a material property to CSX with the given name. 5 | % Remember to add at least one or more geometrical primitives to any 6 | % property. 7 | % 8 | % Use SetMaterialProperty to define the material constants: 9 | % - 'Epsilon': relative electric permitivity 10 | % - 'Mue': relative magnetic permeability 11 | % - 'Kappa': electric conductivity 12 | % - 'Sigma': magnetc conductivity (non-physical property) 13 | % 14 | % examples: 15 | % 16 | % CSX = AddMaterial( CSX, 'RO3010' ); 17 | % CSX = SetMaterialProperty( CSX, 'RO3010', 'Epsilon', 10.2, 'Mue', 1 ); 18 | % CSX = AddBox( CSX, 'RO3010', 0, [0 0 0], [100 1000 1000] ); 19 | % 20 | % See also SetMaterialProperty, SetMaterialWeight, AddMetal, AddExcitation, 21 | % AddProbe, AddDump, AddBox 22 | % 23 | % CSXCAD matlab interface 24 | % ----------------------- 25 | % author: Thorsten Liebig 26 | 27 | CSX = AddProperty(CSX, 'Material', name, varargin{:}); 28 | -------------------------------------------------------------------------------- /matlab/AddMetal.m: -------------------------------------------------------------------------------- 1 | function CSX = AddMetal(CSX, name) 2 | %function CSX = AddMetal(CSX, name) 3 | % 4 | % Add a metal property (PEC) to CSX with the given name. 5 | % Remember to add at least one or more geometrical primitives to any 6 | % property. 7 | % 8 | % example: 9 | % 10 | % CSX = AddMetal(CSX,'metal'); %create PEC with propName 'metal' 11 | % CSX = AddBox(CSX,'metal',10,[0 0 0],[100 100 200]); %assign box 12 | % 13 | % See also AddMaterial, AddExcitation, AddProbe, AddDump, AddBox 14 | % 15 | % CSXCAD matlab interface 16 | % ----------------------- 17 | % author: Thorsten Liebig 18 | 19 | % check if this property already exists 20 | [type_found pos] = FindProperty(CSX, name); 21 | 22 | % since it has no varargs, accept already existing metal with this name 23 | if ((pos>0) && strcmp(type_found,'Metal')) 24 | return 25 | end 26 | 27 | CSX = AddProperty(CSX, 'Metal', name); 28 | -------------------------------------------------------------------------------- /matlab/AddPlaneWaveExcite.m: -------------------------------------------------------------------------------- 1 | function CSX = AddPlaneWaveExcite(CSX, name, k_dir, E_dir, f0, varargin) 2 | % function CSX = AddPlaneWaveExcite(CSX, name, k_dir, E_dir, ) 3 | % 4 | % Creates a plane wave excitation in the sense of a total-field/scattered 5 | % field approach. 6 | % 7 | % Note: A plane wave excitation must not intersect with any kind of 8 | % material. This exctiation type can only be applies in air/vacuum and 9 | % completely surrounding a structure!!! 10 | % 11 | % Note: Only a single Box can be applied to this property!! 12 | % 13 | % Arguments 14 | % - CSX: CSX-struct created by InitCSX 15 | % - name: property name for the excitation 16 | % - k_dir: unit vector of wave progation direction 17 | % - E_dir: electric field polarisation vector (must be orthogonal to k_dir) 18 | % - f0: frequency for numerical phase velocity compensation (optional) 19 | % 20 | % example: 21 | % 22 | % inc_angle = 0 /180*pi; %incident angle on the x-axis 23 | % k_dir = [cos(inc_angle) sin(inc_angle) 0]; % plane wave direction 24 | % E_dir = [0 0 1]; % plane wave polarization --> E_z 25 | % f0 = 500e6; % frequency for numerical phase velocity compensation 26 | % 27 | % CSX = AddPlaneWaveExcite(CSX, 'plane_wave', k_dir, E_dir, f0); 28 | % 29 | % CSXCAD matlab interface 30 | % ----------------------- 31 | % author: Thorsten Liebig 32 | % 33 | % See also AddExcitation, AddBox 34 | 35 | if (nargin<5) 36 | f0 = 0; 37 | end 38 | 39 | CSX = AddExcitation(CSX, name, 10, E_dir, 'PropDir', k_dir, 'Frequency', f0, varargin{:}); 40 | -------------------------------------------------------------------------------- /matlab/AddPoint.m: -------------------------------------------------------------------------------- 1 | function CSX = AddPoint(CSX, propName, prio, pos, varargin) 2 | % CSX = AddPoint(CSX, propName, prio, pos, varargin) 3 | % 4 | % CSXCAD matlab interface 5 | 6 | point.ATTRIBUTE.Priority = prio; 7 | 8 | point.ATTRIBUTE.X=pos(1); 9 | point.ATTRIBUTE.Y=pos(2); 10 | point.ATTRIBUTE.Z=pos(3); 11 | 12 | point = AddPrimitiveArgs(point,varargin{:}); 13 | 14 | CSX = Add2Property(CSX,propName, point, 'Point'); 15 | -------------------------------------------------------------------------------- /matlab/AddPolygon.m: -------------------------------------------------------------------------------- 1 | function CSX = AddPolygon( CSX, materialname, prio, normDir, elevation, points, varargin) 2 | % CSX = AddPolygon( CSX, materialname, prio, normDir, elevation, points, varargin) 3 | % 4 | % - CSX: CSX-object created by InitCSX() 5 | % - materialname: created by AddMetal() or AddMaterial() 6 | % - prio: priority 7 | % - normDir: normal direction of the polygon, 8 | % e.g. 'x', 'y' or 'z', or numeric 0..2 9 | % - elevation: position of the polygon plane 10 | % - points: two-dimensional coordinates 11 | % 12 | % Warning: Polygon has to be defined using Cartesian Coords 13 | % for use with cylindrical mesh, set 'CoordSystem',0 14 | % 15 | % example: 16 | % 17 | % p(1,1) = 0; % x-coord point 1 18 | % p(2,1) = 0; % y-coord point 1 19 | % p(1,2) = 10; % x-coord point 2 20 | % p(2,2) = 20; % y-coord point 2 21 | % % normal direction: z (2) 22 | % CSX = AddPolygon( CSX, 'PEC', 1, 'z', 254, p, 'CoordSystem',0) 23 | % 24 | % 25 | % (c) 2011 Thorsten Liebig 26 | % (c) 2010 Sebastian Held 27 | % 28 | % See also InitCSX AddMetal AddMaterial AddLinPoly AddRotPoly 29 | 30 | polygon.ATTRIBUTE.Priority = prio; 31 | polygon.ATTRIBUTE.Elevation = elevation; 32 | polygon.ATTRIBUTE.NormDir = DirChar2Int(normDir); 33 | 34 | polygon.Vertex = {}; 35 | for s=1:size(points,2) 36 | polygon.Vertex{end+1}.ATTRIBUTE.X1 = points(1,s); 37 | polygon.Vertex{end}.ATTRIBUTE.X2 = points(2,s); 38 | end 39 | 40 | polygon = AddPrimitiveArgs(polygon,varargin{:}); 41 | 42 | CSX = Add2Property( CSX, materialname, polygon, 'Polygon'); 43 | -------------------------------------------------------------------------------- /matlab/AddPolyhedron.m: -------------------------------------------------------------------------------- 1 | function CSX = AddPolyhedron(CSX, propName, prio, vertices, faces, varargin) 2 | % CSX = AddPolyhedron(CSX, propName, prio, vertices, faces, varargin) 3 | % 4 | % Add a polyhedron to CSX and assign to a property with name . 5 | % 6 | % - prio: primitive priority 7 | % - vertices: cell array of all vertices 8 | % - faces: cell array of all faces 9 | % 10 | % Note: 11 | % - The polyhedron must be a closed surface for 3D discretisation 12 | % - All faces must contain the vertices in a right-handed order with 13 | % the normal direction for each face pointing out of the solid 14 | % 15 | % optional: 16 | % - Transformation: perform a transformation on a primitive by adding 17 | % e.g.: 'Transform', {'Scale','1,1,2','Rotate_X',pi/4,'Translate','0,0,100'} 18 | % Note: This will only affect the 3D material/metal discretisation 19 | % 20 | % example: 21 | % 22 | % % example tetrahedron 23 | % vertices{1}=[0 0 0]; 24 | % vertices{2}=[1 0 0]; 25 | % vertices{3}=[0 1 0]; 26 | % vertices{4}=[0 0 1]; 27 | % faces{1}=[0 2 1]; 28 | % faces{2}=[0 1 3]; 29 | % faces{3}=[0 3 2]; 30 | % faces{4}=[1 2 3]; 31 | % CSX = AddMetal( CSX, 'metal' ); 32 | % CSX = AddPolyhedron(CSX, 'metal', 0, vertices, faces); 33 | % 34 | % 35 | % See also AddBox, AddCylinder, AddCylindricalShell, AddSphere, AddSphericalShell, 36 | % AddCurve, AddWire, AddMetal 37 | % 38 | % CSXCAD matlab interface 39 | % ----------------------- 40 | % author: Thorsten Liebig 41 | 42 | polyhedron.ATTRIBUTE.Priority = prio; 43 | 44 | for n=1:numel(vertices) 45 | polyhedron.Vertex{n}=vector2str(vertices{n}); 46 | end 47 | for n=1:numel(faces) 48 | polyhedron.Face{n}=vector2str(faces{n}); 49 | end 50 | 51 | polyhedron = AddPrimitiveArgs(polyhedron,varargin{:}); 52 | 53 | CSX = Add2Property(CSX,propName, polyhedron, 'Polyhedron'); 54 | -------------------------------------------------------------------------------- /matlab/AddProbe.m: -------------------------------------------------------------------------------- 1 | function CSX = AddProbe(CSX, name, type, varargin) 2 | % function CSX = AddProbe(CSX, name, type, varargin) 3 | % 4 | % Add a probe property to CSX with the given name. 5 | % Remember to add a geometrical primitive to any property. 6 | % 7 | % name: name of the property and probe file 8 | % 9 | % type: 10 | % - 0 for voltage probing 11 | % - 1 for current probing 12 | % - 2 for E-field probing 13 | % - 3 for H-field probing 14 | % - 10 for waveguide voltage mode matching 15 | % - 11 for waveguide current mode matching 16 | % 17 | % all following parameter are optional key/value parameter: 18 | % 19 | % - weight: weighting factor (default is 1) 20 | % - frequency: dump in the frequency domain at the given samples (in Hz) 21 | % - ModeFunction: A mode function (used only with type 3/4) 22 | % - NormDir: necessary for current probing box with dimension~=2 23 | % - StartTime/StopTime: Define a start and/or stop time (in seconds) 24 | % for this probe to be active. 25 | % 26 | % examples: 27 | % 28 | % CSX = AddProbe(CSX,'ut1',0); %voltate probe 29 | % CSX = AddProbe(CSX,'it1',1); %current probe 30 | % 31 | % See also ReadUI in the openEMS matlab interface, AddDump, 32 | % AddExcitation, AddMaterial, AddExcitation, AddProbe, AddBox 33 | % 34 | % CSXCAD matlab interface 35 | % ----------------------- 36 | % author: Thorsten Liebig 37 | 38 | FD_samples = []; 39 | ModeFunction = {}; 40 | 41 | if ~ischar(name) 42 | error('CSXCAD::AddProbe: name must be a string'); 43 | end 44 | 45 | prop_args = {'Type', type}; 46 | 47 | for n=1:2:numel(varargin) 48 | if (strcmpi(varargin{n},'weight')==1); 49 | prop_args{end+1} = 'Weight'; 50 | prop_args{end+1} = varargin{n+1}; 51 | elseif (strcmpi(varargin{n},'Frequency')==1); 52 | FD_samples = varargin{n+1}; 53 | elseif (strcmpi(varargin{n},'ModeFunction')==1); 54 | ModeFunction = varargin{n+1}; 55 | elseif (strcmpi(varargin{n},'NormDir')==1); 56 | prop_args{end+1} = 'NormDir'; 57 | prop_args{end+1} = varargin{n+1}; 58 | elseif (strcmpi(varargin{n},'StartTime')==1); 59 | prop_args{end+1} = 'StartTime'; 60 | prop_args{end+1} = varargin{n+1}; 61 | elseif (strcmpi(varargin{n},'StopTime')==1); 62 | prop_args{end+1} = 'StopTime'; 63 | prop_args{end+1} = varargin{n+1}; 64 | else 65 | warning('CSXCAD:AddProbe',['variable argument key: "' varargin{n+1} '" unknown']); 66 | end 67 | end 68 | 69 | [CSX pos] = AddProperty(CSX, 'ProbeBox', name, prop_args{:}); 70 | 71 | if (numel(FD_samples)>0) 72 | CSX.Properties.ProbeBox{pos}.FD_Samples=FD_samples; 73 | end 74 | 75 | if (numel(ModeFunction)>0) 76 | CSX.Properties.ProbeBox{pos}.Attributes.ATTRIBUTE.ModeFunctionX = ModeFunction{1}; 77 | CSX.Properties.ProbeBox{pos}.Attributes.ATTRIBUTE.ModeFunctionY = ModeFunction{2}; 78 | CSX.Properties.ProbeBox{pos}.Attributes.ATTRIBUTE.ModeFunctionZ = ModeFunction{3}; 79 | end 80 | 81 | -------------------------------------------------------------------------------- /matlab/AddPropAttribute.m: -------------------------------------------------------------------------------- 1 | function CSX = AddPropAttribute(CSX, name, att_name, att_value) 2 | % CSX = AddPropAttribute(CSX, name, att_name, att_value) 3 | % 4 | % Add a given attribute (name and value) to the given property 5 | % 6 | % CSXCAD matlab interface 7 | % ----------------------- 8 | % author: Thorsten Liebig (c) 2013 9 | 10 | type = GetPropertyType(CSX, name); 11 | 12 | pos=0; 13 | for n=1:numel(CSX.Properties.(type)) 14 | if strcmp(CSX.Properties.(type){n}.ATTRIBUTE.Name, name) 15 | pos=n; 16 | end 17 | end 18 | 19 | if (pos==0) 20 | error('CSXCAD::AddPropAttribute: property not found'); 21 | return; 22 | end 23 | 24 | CSX.Properties.(type){pos}.Attributes.ATTRIBUTE.(att_name) = att_value; 25 | -------------------------------------------------------------------------------- /matlab/AddRotPoly.m: -------------------------------------------------------------------------------- 1 | function CSX = AddRotPoly( CSX, materialname, prio, normDir, points, RotAxisDir, angle, varargin) 2 | % function CSX = AddRotPoly( CSX, materialname, prio, normDir, points, RotAxisDir, angle, varargin) 3 | % 4 | % - CSX: CSX-object created by InitCSX() 5 | % - materialname: created by AddMetal() or AddMaterial() 6 | % - prio: priority 7 | % - normDir: normal direction of the polygon, 8 | % e.g. 'x', 'y' or 'z', or numeric 0..2 9 | % - points: two-dimensional coordinates 10 | % - RotAxisDir: direction of the rotational axis 11 | % e.g. 'x', 'y' or 'z', or numeric 0..2 12 | % - angle (optional): rotational start/stop angle, default is [0 2pi] 13 | % 14 | % Warning: Polygon has to be defined using Cartesian Coords 15 | % for use with cylindrical mesh, set 'CoordSystem',0 16 | % 17 | % example: 18 | % 19 | % p(1,1) = 0; % x-coord point 1 20 | % p(2,1) = 0; % y-coord point 1 21 | % p(1,2) = 10; % x-coord point 2 22 | % p(2,2) = 20; % y-coord point 2 23 | % % normal direction: z 24 | % CSX = AddRotPoly( CSX, 'PEC', 1, 'z', p , 'y'); 25 | % 26 | % 2011, Thorsten Liebig 27 | % 28 | % See also InitCSX AddMetal AddMaterial AddPolygon 29 | 30 | if (nargin<7) 31 | angle = [0 2*pi]; 32 | end 33 | 34 | polygon.ATTRIBUTE.Priority = prio; 35 | polygon.ATTRIBUTE.NormDir = DirChar2Int(normDir); 36 | polygon.ATTRIBUTE.RotAxisDir = DirChar2Int(RotAxisDir); 37 | 38 | polygon.Angles.ATTRIBUTE.Start = angle(1); 39 | polygon.Angles.ATTRIBUTE.Stop = angle(2); 40 | 41 | polygon.Vertex = {}; 42 | for s=1:size(points,2) 43 | polygon.Vertex{end+1}.ATTRIBUTE.X1 = points(1,s); 44 | polygon.Vertex{end}.ATTRIBUTE.X2 = points(2,s); 45 | end 46 | 47 | polygon = AddPrimitiveArgs(polygon,varargin{:}); 48 | 49 | CSX = Add2Property( CSX, materialname, polygon, 'RotPoly'); 50 | -------------------------------------------------------------------------------- /matlab/AddSphere.m: -------------------------------------------------------------------------------- 1 | function CSX = AddSphere(CSX, propName, prio, center, rad, varargin) 2 | % function CSX = AddSphere(CSX, propName, prio, center, rad, varargin) 3 | % 4 | % Add a sphere to CSX and assign to a property with name . 5 | % 6 | % - center: sphere center coordinates 7 | % - rad : sphere radius 8 | % - prio : primitive priority 9 | % 10 | % example: 11 | % 12 | % CSX = AddMetal(CSX,'metal'); %create PEC with propName 'metal' 13 | % CSX = AddSphere(CSX,'metal',10,[0 0 0],50); 14 | % 15 | % See also AddBox, AddCylindricalShell, AddCylinder, AddSphericalShell, 16 | % AddCurve, AddWire, AddMetal 17 | % 18 | % CSXCAD matlab interface 19 | % ----------------------- 20 | % author: Thorsten Liebig 21 | 22 | sphere.ATTRIBUTE.Priority = prio; 23 | sphere.ATTRIBUTE.Radius = rad; 24 | 25 | sphere.Center.ATTRIBUTE.X=center(1); 26 | sphere.Center.ATTRIBUTE.Y=center(2); 27 | sphere.Center.ATTRIBUTE.Z=center(3); 28 | 29 | sphere = AddPrimitiveArgs(sphere,varargin{:}); 30 | 31 | CSX = Add2Property(CSX,propName, sphere, 'Sphere'); 32 | -------------------------------------------------------------------------------- /matlab/AddSphericalShell.m: -------------------------------------------------------------------------------- 1 | function CSX = AddSphericalShell(CSX, propName, prio, center, rad, shell_width, varargin) 2 | % function CSX = AddSphericalShell(CSX, propName, prio, center, rad, shell_width, varargin) 3 | % 4 | % Add a sphere shell to CSX and assign to a property with name . 5 | % 6 | % - center: sphere center coordinates 7 | % - rad : sphere radius 8 | % - shell_width: sphere shell width 9 | % - prio : primitive priority 10 | % 11 | % Note: 12 | % - the inner radius of this shell is rad-shell_width/2 13 | % - the outer radius of this shell is rad+shell_width/2 14 | % 15 | % example: 16 | % 17 | % CSX = AddMetal(CSX,'metal'); %create PEC with propName 'metal' 18 | % CSX = AddSphericalShell(CSX,'metal',10,[0 0 0],50,10); 19 | % 20 | % See also AddBox, AddCylindricalShell, AddCylinder, AddSphere, 21 | % AddCurve, AddWire, AddMetal 22 | % 23 | % CSXCAD matlab interface 24 | % ----------------------- 25 | % author: Thorsten Liebig 26 | 27 | sphere.ATTRIBUTE.Priority = prio; 28 | sphere.ATTRIBUTE.Radius = rad; 29 | sphere.ATTRIBUTE.ShellWidth = shell_width; 30 | 31 | sphere.Center.ATTRIBUTE.X=center(1); 32 | sphere.Center.ATTRIBUTE.Y=center(2); 33 | sphere.Center.ATTRIBUTE.Z=center(3); 34 | 35 | sphere = AddPrimitiveArgs(sphere,varargin{:}); 36 | 37 | CSX = Add2Property(CSX,propName, sphere, 'SphericalShell'); 38 | -------------------------------------------------------------------------------- /matlab/AddWire.m: -------------------------------------------------------------------------------- 1 | function CSX = AddWire(CSX, propName, prio, points, wire_rad, varargin) 2 | % function CSX = AddWire(CSX, propName, prio, points, wire_rad, varargin) 3 | % 4 | % Add a wire to CSX and assign to a property with name . 5 | % 6 | % Warning: This is a 1D object, not all properties may be compatible with a 7 | % 1D object, e.g. a material property. 8 | % 9 | % - points: curve coordinates array 10 | % - prio : primitive priority 11 | % - wire_rad: wire radius 12 | % 13 | % example: 14 | % 15 | % %first point 16 | % points(1,1) = 0; 17 | % points(2,1) = 5; 18 | % points(3,1) = 10; 19 | % %second point 20 | % points(1,2) = 0; 21 | % points(2,2) = 10; 22 | % points(3,2) = 10; 23 | % %third point ... 24 | % % create a metal wire with finite radius... 25 | % CSX = AddMetal(CSX,'metal'); %create PEC with propName 'metal' 26 | % CSX = AddCurve(CSX,'metal',10, points, 2); 27 | % 28 | % See also AddBox, AddCylindricalShell, AddCylinder, AddSphere, 29 | % AddSphericalShell, AddCurve, AddMetal 30 | % 31 | % CSXCAD matlab interface 32 | % ----------------------- 33 | % author: Thorsten Liebig 34 | 35 | wire.ATTRIBUTE.Priority = prio; 36 | wire.ATTRIBUTE.WireRadius = wire_rad; 37 | 38 | wire.Vertex={}; 39 | for s=1:size(points,2) 40 | wire.Vertex{end+1}.ATTRIBUTE.X = points(1,s); 41 | wire.Vertex{end}.ATTRIBUTE.Y = points(2,s); 42 | wire.Vertex{end}.ATTRIBUTE.Z = points(3,s); 43 | end 44 | 45 | wire = AddPrimitiveArgs(wire,varargin{:}); 46 | 47 | CSX = Add2Property(CSX,propName, wire, 'Wire'); 48 | -------------------------------------------------------------------------------- /matlab/AnalyseMesh.m: -------------------------------------------------------------------------------- 1 | function results = AnalyseMesh(lines) 2 | % function results = AnalyseMesh(lines) 3 | % 4 | % Analyse a given mesh line vector 5 | % 6 | % output structure: 7 | % - results.numLines: number of lines 8 | % - results.max_res: max. resolution found 9 | % - results.min_res: min. resolution found 10 | % - results.max_ratio: max. grading ratio found 11 | % - results.homogeneous: true/false for homogeneous mesh 12 | % - results.symmetric: true/false for symmetric mesh 13 | % 14 | % CSXCAD matlab interface 15 | % ----------------------- 16 | % author: Thorsten Liebig (C) 2012 17 | 18 | results = []; 19 | 20 | lines = sort(unique(lines)); 21 | 22 | if (numel(lines)<=1) 23 | warning('CSXCAD:AnalyseMesh', 'more than one line needed to analyse mesh'); 24 | end 25 | 26 | diff_lines = diff(lines); 27 | 28 | results.numLines = numel(lines); 29 | 30 | results.max_res = max(diff_lines); 31 | results.min_res = min(diff_lines); 32 | if (results.max_res==results.min_res) 33 | results.homogeneous = 1; 34 | else 35 | results.homogeneous = 0; 36 | end 37 | 38 | results.symmetric = CheckSymmtricLines(lines); 39 | 40 | ratio_lines = diff_lines(1:end-1)./diff_lines(2:end); 41 | 42 | results.max_ratio = max([ratio_lines 1./ratio_lines]); 43 | -------------------------------------------------------------------------------- /matlab/CSXGeomPlot.m: -------------------------------------------------------------------------------- 1 | function CSXGeomPlot(CSX_filename, args_string) 2 | % function CSXGeomPlot(CSX_filename<, args_string>) 3 | % 4 | % Show the geometry stored in the CSX file using AppCSXCAD 5 | % 6 | % Optional AppCSXCAD arguments (args_string): 7 | % - '--RenderDiscMaterial', enable material rendering 8 | % 9 | % exports: 10 | % - '--export-polydata-vtk=' 11 | % - '--export-STL=' 12 | % 13 | % See also InitCSX, DefineRectGrid 14 | % 15 | % CSXCAD matlab interface 16 | % ----------------------- 17 | % author: Thorsten Liebig 18 | 19 | if nargin < 1 20 | error 'specify the xml file to open' 21 | end 22 | 23 | if nargin < 2 24 | args_string = ''; 25 | end 26 | 27 | filename = mfilename('fullpath'); 28 | pathname = fileparts( filename ); 29 | 30 | if isunix 31 | AppCSXCAD_bin = searchBinary('AppCSXCAD.sh', ... 32 | {[pathname filesep '..' filesep '..' filesep 'AppCSXCAD' filesep], ... 33 | [pathname filesep '..' filesep '..' filesep '..' filesep 'bin' filesep]}); 34 | else % assume windows 35 | AppCSXCAD_bin = searchBinary('AppCSXCAD.exe',[pathname filesep '..' filesep]); 36 | end 37 | 38 | command = [AppCSXCAD_bin ' --disableEdit ' args_string ' ' CSX_filename]; 39 | disp( ['invoking AppCSXCAD, exit to continue script...'] ); 40 | if isOctave() 41 | fflush(stdout); 42 | end 43 | 44 | if ~isunix && isOctave() % assume Octave on windows 45 | old_qt_plugin_path=getenv('QT_PLUGIN_PATH'); 46 | setenv('QT_PLUGIN_PATH',[pathname filesep '..' filesep 'qt5' filesep 'plugins']); 47 | system(command); 48 | setenv('QT_PLUGIN_PATH', old_qt_plugin_path); 49 | else 50 | system(command); 51 | end 52 | -------------------------------------------------------------------------------- /matlab/CalcDebyeMaterial.m: -------------------------------------------------------------------------------- 1 | function eps_debye = CalcDebyeMaterial(f, eps_r, kappa, eps_Delta, t_relax) 2 | % eps_debye = CalcDebyeMaterial(f, eps_r, kappa, eps_Delta, t_relax) 3 | % 4 | % Calculate the Debye type dispersive material constant 5 | % 6 | % arguments: 7 | % - f: frequeny range of interest 8 | % - eps_r: eps_r infinity 9 | % - kappa: conductivity (losses) 10 | % - eps_Delta: (vector) delta of relative permitivity 11 | % - t_relax: (vector) relaxation time (losses) 12 | % 13 | % return: 14 | % - eps_debye: the complex relative permitivity 15 | % 16 | % See also: CalcLorentzMaterial 17 | % 18 | % CSXCAD matlab interface 19 | % ----------------------- 20 | % author: Thorsten Liebig (2013) 21 | 22 | EPS0 = 8.85418781762e-12; 23 | eps_debye = ones(size(f))*eps_r - 1j*kappa./(2*pi*f)/EPS0; 24 | 25 | for n=1:numel(eps_Delta) 26 | eps_debye = eps_debye + eps_Delta(n)./(1+2j*pi*f*t_relax(n)); 27 | end 28 | 29 | end 30 | -------------------------------------------------------------------------------- /matlab/CalcDrudeMaterial.m: -------------------------------------------------------------------------------- 1 | function eps_drude = CalcDrudeMaterial(f, eps_r, kappa, plasmaFreq, t_relax) 2 | % eps_drude = CalcDrudeMaterial(f, eps_r, kappa, plasmaFreq, t_relax) 3 | % 4 | % Calculate the Drude type dispersive material constant 5 | % 6 | % arguments: 7 | % - f: frequeny range of interest 8 | % - eps_r: eps_r infinity 9 | % - kappa: conductivity (losses) 10 | % - plasmaFreq: (vector) plasma frequencies 11 | % - t_relax: (vector) relaxation time (losses) 12 | % 13 | % return: 14 | % - eps_drude: the complex relative permitivity 15 | % 16 | % Example: 17 | % 18 | % % silver (AG) at optical frequencies (Drude model) [1, p. 201] 19 | % f = linspace(300e12, 1100e12, 201); 20 | % eps_model = CalcDrudeMaterial(f, 3.942, 7.97e3, 7e15/2/pi, 0, 1/2.3e13); 21 | % 22 | % figure 23 | % plot(f,real(eps_model)) 24 | % hold on; 25 | % grid on; 26 | % plot(f,imag(eps_model),'r--') 27 | % 28 | % See also: CalcDebyeMaterial, CalcLorentzMaterial 29 | % 30 | % * [1] Rennings, Andre: "Elektromagnetische Zeitbereichssimulationen 31 | % innovativer Antennen auf Basis von Metamaterialien." 32 | % PhD Thesis, University of Duisburg-Essen, September 2008 33 | % 34 | % CSXCAD matlab interface 35 | % ----------------------- 36 | % author: Thorsten Liebig (2013) 37 | 38 | eps_drude = CalcLorentzMaterial(f, eps_r, kappa, plasmaFreq, plasmaFreq*0, t_relax); 39 | -------------------------------------------------------------------------------- /matlab/CalcLorentzMaterial.m: -------------------------------------------------------------------------------- 1 | function eps_lorentz = CalcLorentzMaterial(f, eps_r, kappa, plasmaFreq, LorPoleFreq, t_relax) 2 | % eps_lorentz = CalcLorentzMaterial(f, eps_r, kappa, plasmaFreq, LorPoleFreq, t_relax) 3 | % 4 | % Calculate the Lorentz type dispersive material constant 5 | % 6 | % arguments: 7 | % - f: frequeny range of interest 8 | % - eps_r: eps_r infinity 9 | % - kappa: conductivity (losses) 10 | % - plasmaFreq: (vector) plasma frequencies (Drude model) 11 | % - LorPoleFreq: (vector) Lorentz pole frequencies (zero for pure Drude model) 12 | % - t_relax: (vector) relaxation time (losses) 13 | % 14 | % return: 15 | % - eps_lorentz: the complex relative permitivity 16 | % 17 | % Example: 18 | % 19 | % % silver (AG) at optical frequencies (Drude model) [1, p. 201] 20 | % f = linspace(300e12, 1100e12, 201); 21 | % eps_model = CalcLorentzMaterial(f, 3.942, 7.97e3, 7e15/2/pi, 0, 1/2.3e13); 22 | % 23 | % figure 24 | % plot(f,real(eps_model)) 25 | % hold on; 26 | % grid on; 27 | % plot(f,imag(eps_model),'r--') 28 | % 29 | % % silver (AG) at optical frequencies (Drude+Lorentz model) [1, p. 201] 30 | % f = linspace(300e12, 1100e12, 201); 31 | % eps_model = CalcLorentzMaterial(f, 1.138, 4.04e3, [13e15 9.61e15]/2/pi, [0 7.5e15]/2/pi,[1/2.59e13 1/3e14]); 32 | % 33 | % figure 34 | % plot(f,real(eps_model)) 35 | % hold on; 36 | % grid on; 37 | % plot(f,imag(eps_model),'r--') 38 | % 39 | % See also: CalcDebyeMaterial 40 | % 41 | % * [1] Rennings, Andre: "Elektromagnetische Zeitbereichssimulationen 42 | % innovativer Antennen auf Basis von Metamaterialien." 43 | % PhD Thesis, University of Duisburg-Essen, September 2008 44 | % 45 | % CSXCAD matlab interface 46 | % ----------------------- 47 | % author: Thorsten Liebig (2013) 48 | 49 | EPS0 = 8.85418781762e-12; 50 | eps_lorentz = ones(size(f))*eps_r - 1j*kappa./(2*pi*f)/EPS0; 51 | 52 | w = 2*pi*f; 53 | for n=1:numel(plasmaFreq) 54 | if (t_relax(n)>0) 55 | w_r = 1/t_relax(n); 56 | else 57 | w_r = 0; 58 | end 59 | eps_lorentz = eps_lorentz - eps_r*(2*pi*plasmaFreq(n))^2./(w.^2 - (2*pi*LorPoleFreq(n))^2 - 2j*pi*f*w_r); 60 | end 61 | 62 | end 63 | -------------------------------------------------------------------------------- /matlab/CheckMesh.m: -------------------------------------------------------------------------------- 1 | function [EC pos E_type] = CheckMesh(lines, min_res, max_res, ratio, be_quiet) 2 | % function [EC pos E_type] = CheckMesh(lines, min_res, max_res, ratio, be_quiet) 3 | % 4 | % Check if mesh lines are valid 5 | % 6 | % parameter: 7 | % - min_res: minimal allowed mesh-diff 8 | % - max_res: maximal allowed mesh-diff 9 | % - ratio: maximal allowed mesh-diff ratio 10 | % - be_quiet: disable warnings 11 | % 12 | % return: 13 | % - EC: error code (number of found errors) 14 | % - pos: line positions with error 15 | % - E_type: error type 16 | % 17 | % CSXCAD matlab interface 18 | % ----------------------- 19 | % author: Thorsten Liebig 20 | 21 | if (nargin<5) 22 | be_quiet = 0; 23 | end 24 | 25 | diff_lines = diff(lines); 26 | EC = 0; 27 | E_type = []; 28 | 29 | pos = []; 30 | max_err = find(diff_lines>max_res); 31 | if (~isempty(max_err) && ~be_quiet) 32 | warning('CSXCAD:CheckMesh','found resolution larger than max_res'); 33 | pos = [pos max_err]; 34 | EC = EC + numel(max_err); 35 | E_type = [E_type 1]; 36 | end 37 | 38 | min_err = find(diff_lines ratio*1.01) 48 | str = ['lines: ' num2str(n) '@' num2str(lines(n)) ' ' num2str(n+1) '@' num2str(lines(n+1)) ' ' num2str(n+2) '@' num2str(lines(n+2))]; 49 | if (~be_quiet) 50 | warning('CSXCAD:CheckMesh', [str '\nfound resolution increase larger than ratio: ' num2str(diff_lines(n+1)/diff_lines(n)) ' > ' num2str(ratio) ]); 51 | end 52 | pos = [pos n+1]; 53 | EC = EC + 1; 54 | E_type = [E_type 3]; 55 | end 56 | if (diff_lines(n+1)/diff_lines(n) < 1/ratio/1.01) 57 | str = ['lines: ' num2str(n) '@' num2str(lines(n)) ' ' num2str(n+1) '@' num2str(lines(n+1)) ' ' num2str(n+2) '@' num2str(lines(n+2))]; 58 | if (~be_quiet) 59 | warning('CSXCAD:SmoothRange', [str '\nfound resolution decrease smaller than ratio: ' num2str(diff_lines(n+1)/diff_lines(n)) ' < 1/' num2str(ratio) '=' num2str(1/ratio) ]); 60 | end 61 | pos = [pos n]; 62 | EC = EC + 1; 63 | E_type = [E_type 4]; 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /matlab/CreateDiscMaterial.m: -------------------------------------------------------------------------------- 1 | function CreateDiscMaterial(filename, data, mat_db, mesh) 2 | % function CreateDiscMaterial(filename, data, mat_db, mesh) 3 | % 4 | % Create the discrete material hdf5 file (version 2) usable by AddDiscMaterial 5 | % 6 | % Note: This function currently requires Matlab. Octave is missing the 7 | % necessary hdf5 write functions. 8 | % 9 | % arguments: 10 | % - filename: hdf5 file to create (must not exist) 11 | % - data: voxel based index data, index as used in mat_db-1 12 | % - mat_db: material database 13 | % - mesh: used voxel mesh. Note size is size(data)+[1 1 1] 14 | % 15 | % example: 16 | % 17 | % mat_db.epsR = [1 3 4]; %relative permittivity 18 | % mat_db.kappa = [0 0.2 0.4]; %electric conductivity (S/m) 19 | % mat_db.density = [0 1000 1010]; %material density (kg/m³) 20 | % mat_db.Name = {'Background','mat2','mat3'}; 21 | % 22 | % data = [0 1 0; 2 1 2; 0 1 0]; % 3x3x3 data 23 | % mesh.x = [0 0.1 0.2 0.3]; % 4 mesh lines in x-dir (3 cells) 24 | % mesh.y = [-0.1 0 0.1 0.2]; % 4 mesh lines in y-dir (3 cells) 25 | % mesh.z = [0 0.4 0.8 1.2]; % 4 mesh lines in z-dir (3 cells) 26 | % 27 | % CreateDiscMaterial('test_mat.h5', data, mat_db, mesh); 28 | % 29 | % See also AddDiscMaterial 30 | % 31 | % CSXCAD matlab interface 32 | % ----------------------- 33 | % author: Thorsten Liebig (2013) 34 | 35 | if isOctave 36 | error('CreateDiscMaterial currently does not support Octave, due to missing hdf5 functions!'); 37 | end 38 | 39 | if (exist('h5create')==0) 40 | error('CSXCAD:CreateDiscMaterial','Your matlab seems to be too old, h5create cannot be found!'); 41 | end 42 | 43 | data_size = size(data); 44 | mesh_size = [numel(mesh.x) numel(mesh.y) numel(mesh.z)]; 45 | 46 | if ((mesh_size-1)~=data_size) 47 | error('data size and mesh size mismatch'); 48 | end 49 | 50 | if (exist(filename,'file')) 51 | error(['file "' filename '" already exist. Delete/rename first!']); 52 | end 53 | 54 | h5create(filename, '/DiscData',data_size, 'Datatype', 'uint8', 'ChunkSize',data_size, 'Deflate',9); 55 | h5write(filename, '/DiscData', data); 56 | 57 | clear data; 58 | 59 | h5writeatt(filename, '/DiscData', 'DB_Size', int32(numel(mat_db.epsR))); 60 | 61 | h5writeatt(filename, '/DiscData', 'epsR', mat_db.epsR); 62 | h5writeatt(filename, '/DiscData', 'kappa', mat_db.kappa); 63 | h5writeatt(filename, '/DiscData', 'density', mat_db.density); 64 | h5writeatt(filename, '/DiscData', 'Name', strjoin(mat_db.Name,',')); 65 | 66 | h5create(filename, '/mesh/x', mesh_size(1)); 67 | h5write(filename, '/mesh/x', mesh.x); 68 | 69 | h5create(filename, '/mesh/y', mesh_size(2)); 70 | h5write(filename, '/mesh/y', mesh.y); 71 | 72 | h5create(filename, '/mesh/z', mesh_size(3)); 73 | h5write(filename, '/mesh/z', mesh.z); 74 | 75 | h5writeatt(filename, '/', 'Version', 2); 76 | 77 | 78 | 79 | function out = strjoin(names, delimitier) 80 | 81 | out = names{1}; 82 | for n=2:numel(names) 83 | out = [out delimitier names{n}]; 84 | end 85 | -------------------------------------------------------------------------------- /matlab/DefineRectGrid.m: -------------------------------------------------------------------------------- 1 | function CSX = DefineRectGrid(CSX, deltaUnit, mesh) 2 | % function CSX = DefineRectGrid(CSX, deltaUnit, mesh); 3 | % 4 | % Create a rectiliniear grid. 5 | % 6 | % example Cartesian mesh: 7 | % 8 | % CSX = InitCSX(); 9 | % mesh.x = AutoSmoothMeshLines([0 a], 10); 10 | % mesh.y = AutoSmoothMeshLines([0 b], 10); 11 | % mesh.z = AutoSmoothMeshLines([0 length], 15); 12 | % CSX = DefineRectGrid(CSX, unit,mesh); 13 | % 14 | % example Cylindrical mesh: 15 | % 16 | % CSX = InitCSX('CoordSystem',1); 17 | % mesh.r = AutoSmoothMeshLines([0 a], 10); 18 | % mesh.a = AutoSmoothMeshLines([0 2*pi], pi/30); 19 | % mesh.z = AutoSmoothMeshLines([-length 0 length], 15); 20 | % CSX = DefineRectGrid(CSX, unit,mesh); 21 | % 22 | % See also InitCSX, SmoothMesh, AutoSmoothMeshLines, DetectEdges 23 | % 24 | % CSXCAD matlab interface 25 | % ----------------------- 26 | % author: Thorsten Liebig 27 | 28 | CSX.RectilinearGrid.ATTRIBUTE.DeltaUnit = deltaUnit; 29 | 30 | if (isfield(CSX,'ATTRIBUTE')) 31 | if (isfield(CSX.ATTRIBUTE,'CoordSystem')) 32 | CSX.RectilinearGrid.ATTRIBUTE.CoordSystem = CSX.ATTRIBUTE.CoordSystem; 33 | end 34 | end 35 | 36 | if (isfield(mesh,'x')) 37 | CSX.RectilinearGrid.XLines = mesh.x; 38 | elseif ( (isfield(mesh,'r')) && (CSX.ATTRIBUTE.CoordSystem==1)) 39 | CSX.RectilinearGrid.XLines = mesh.r; 40 | else 41 | error 'x/(r) direction not found' 42 | end 43 | 44 | if (isfield(mesh,'y')) 45 | CSX.RectilinearGrid.YLines = mesh.y; 46 | elseif ((isfield(mesh,'a')) && (CSX.ATTRIBUTE.CoordSystem==1)) 47 | CSX.RectilinearGrid.YLines = mesh.a; 48 | else 49 | error 'y/(a) direction not found' 50 | end 51 | 52 | CSX.RectilinearGrid.ZLines = mesh.z; 53 | -------------------------------------------------------------------------------- /matlab/DirChar2Int.m: -------------------------------------------------------------------------------- 1 | function n = DirChar2Int(dir_char) 2 | % function n = DirChar2Int(dir_char) 3 | % 4 | % internal function to convert a character like 'x','y','z' into a numeric 5 | % direction: 0..2! 6 | % If input already is a numeric value from 0..2, it will just be copied! 7 | % Everything else will raise an error! 8 | % 9 | % CSXCAD matlab interface 10 | % ----------------------- 11 | % author: Thorsten Liebig (c) 2013 12 | 13 | if (numel(dir_char)>1) 14 | error('CSXCAD:DirChar2Int','invalid normal direction') 15 | end 16 | 17 | if (ischar(dir_char)) 18 | if (strcmp(dir_char,'x') || strcmp(dir_char,'r')) 19 | n = 0; return; 20 | elseif (strcmp(dir_char,'y') || strcmp(dir_char,'a')) 21 | n = 1; return; 22 | elseif strcmp(dir_char,'z') 23 | n = 2; return; 24 | else 25 | error('CSXCAD:DirChar2Int','invalid normal direction') 26 | end 27 | elseif (isnumeric(dir_char) && ((dir_char==0) || (dir_char==1) || (dir_char==2))) 28 | n = dir_char; 29 | else 30 | error('CSXCAD:DirChar2Int','invalid normal direction') 31 | end 32 | -------------------------------------------------------------------------------- /matlab/ImportPLY.m: -------------------------------------------------------------------------------- 1 | function CSX = ImportPLY(CSX, propName, prio, filename, varargin) 2 | % function CSX = ImportPLY(CSX, propName, prio, filename, varargin) 3 | % 4 | % example: 5 | % 6 | % CSX = AddMetal( CSX, 'cad_model' ); % create a perfect electric conductor (PEC) 7 | % CSX = ImportPLY(CSX, 'cad_model',10, 'sphere.ply','Transform',{'Scale',1/unit}); 8 | % 9 | % % Note: make sure the file 'sphere.ply' is in the working directory 10 | % 11 | % See also AddBox, AddCylinder, AddCylindricalShell, AddSphere, AddSphericalShell, 12 | % AddCurve, AddWire, AddMetal, ImportSTL 13 | % 14 | % CSXCAD matlab interface 15 | % ----------------------- 16 | % author: Thorsten Liebig 17 | 18 | plyfile.ATTRIBUTE.Priority = prio; 19 | plyfile.ATTRIBUTE.FileName = filename; 20 | plyfile.ATTRIBUTE.FileType = 'PLY'; 21 | 22 | plyfile = AddPrimitiveArgs(plyfile,varargin{:}); 23 | 24 | CSX = Add2Property(CSX,propName, plyfile, 'PolyhedronReader'); 25 | -------------------------------------------------------------------------------- /matlab/ImportSTL.m: -------------------------------------------------------------------------------- 1 | function CSX = ImportSTL(CSX, propName, prio, filename, varargin) 2 | % function CSX = ImportSTL(CSX, propName, prio, filename, varargin) 3 | % 4 | % example: 5 | % 6 | % CSX = AddMetal( CSX, 'cad_model' ); % create a perfect electric conductor (PEC) 7 | % CSX = ImportSTL(CSX, 'cad_model',10, 'sphere.stl','Transform',{'Scale',1/unit}); 8 | % 9 | % % Note: make sure the file 'sphere.stl' is in the working directory 10 | % 11 | % See also AddBox, AddCylinder, AddCylindricalShell, AddSphere, AddSphericalShell, 12 | % AddCurve, AddWire, AddMetal, ImportPLY 13 | % 14 | % CSXCAD matlab interface 15 | % ----------------------- 16 | % author: Thorsten Liebig 17 | 18 | stlfile.ATTRIBUTE.Priority = prio; 19 | stlfile.ATTRIBUTE.FileName = filename; 20 | stlfile.ATTRIBUTE.FileType = 'STL'; 21 | 22 | stlfile = AddPrimitiveArgs(stlfile,varargin{:}); 23 | 24 | CSX = Add2Property(CSX,propName, stlfile, 'PolyhedronReader'); 25 | -------------------------------------------------------------------------------- /matlab/InitCSX.m: -------------------------------------------------------------------------------- 1 | function CSX = InitCSX(varargin) 2 | % function CSX = InitCSX() 3 | % 4 | % Inititalize the CSX data-structure. 5 | % 6 | % variable arguments: 7 | % - 'CoordSystem' : define the default coordinate system 8 | % - 0 -> Cartesian 9 | % - 1 -> Cylindircal 10 | % - 2 -> Sphercial (not yet implemented) 11 | % 12 | % example: 13 | % 14 | % CSX = InitCSX(); %for a default cartesian mesh 15 | % or 16 | % 17 | % CSX = InitCSX('CoordSystem','1'); % for a cylindrical mesh definition 18 | % 19 | % See also DefineRectGrid, SmoothMeshLines, SmoothMeshLines2, 20 | % SetBackgroundMaterial 21 | % 22 | % CSXCAD matlab interface 23 | % ----------------------- 24 | % author: Thorsten Liebig 25 | 26 | CSX.Properties = []; 27 | 28 | %Cartesian mesh as default coordinate system 29 | CSX.ATTRIBUTE.CoordSystem = 0; 30 | 31 | for n=1:2:numel(varargin) 32 | CSX.ATTRIBUTE.(varargin{n}) = (varargin{n+1}); 33 | end 34 | -------------------------------------------------------------------------------- /matlab/SetBackgroundMaterial.m: -------------------------------------------------------------------------------- 1 | function CSX = SetBackgroundMaterial(CSX, varargin) 2 | % function CSX = SetBackgroundMaterial(CSX, varargin)) 3 | % 4 | % Set the background material properties 5 | % 6 | % variable arguments: 7 | % - 'Epsilon' : background rel. electric permittivity (default 1) 8 | % - 'Kappa' : background electric conductivity (default 0) 9 | % - 'Mue' : background rel. magnetic permeability (default 1) 10 | % 11 | % example: 12 | % 13 | % CSX = InitCSX(); 14 | % CSX = SetBackgroundMaterial(CSX, 'Epsilon', 4) 15 | % 16 | % See also InitCSX 17 | % 18 | % CSXCAD matlab interface 19 | % ----------------------- 20 | % author: Thorsten Liebig (c) 2013 21 | 22 | for n=1:2:numel(varargin) 23 | CSX.BackgroundMaterial.ATTRIBUTE.(varargin{n}) = (varargin{n+1}); 24 | end 25 | -------------------------------------------------------------------------------- /matlab/SetExcitationWeight.m: -------------------------------------------------------------------------------- 1 | function CSX = SetExcitationWeight(CSX, name, weight) 2 | % function CSX = SetExcitationWeight(CSX, name, weight) 3 | % 4 | % Define weighting functions for x-, y- and z-direction of excitation 5 | % 6 | % The functions can use the variables: 7 | % - x,y,z 8 | % - rho for the distance to z-axis 9 | % - r for the distance to origin 10 | % - a for alpha (as in cylindircal and spherical coord systems) 11 | % - t for theta (as in the spherical coord system 12 | % 13 | % all these variables are not weighted with the drawing unit defined by 14 | % the grid 15 | % 16 | % example: 17 | % 18 | % start=[0 0 0]; 19 | % stop=[width height 0]; 20 | % CSX = AddExcitation(CSX,'excite',0,[1 1 0]); 21 | % weight{1} = '2*cos(0.0031416*x)*sin(0.0062832*y)'; 22 | % weight{2} = '1*sin(0.0031416*x)*cos(0.0062832*y)'; 23 | % weight{3} = 0; 24 | % CSX = SetExcitationWeight(CSX,'excite',weight); 25 | % CSX = AddBox(CSX,'excite',0 ,start,stop); 26 | % 27 | % See also AddExcitation, InitCSX, DefineRectGrid 28 | % 29 | % CSXCAD matlab interface 30 | % ----------------------- 31 | % author: Thorsten Liebig 32 | 33 | if ~isfield(CSX,'Properties') 34 | error('CSXCAD::SetExcitationWeight: no properties not found'); 35 | end 36 | if ~isfield(CSX.Properties,'Excitation') 37 | error('CSXCAD::SetExcitationWeight: no excitation properties found'); 38 | end 39 | 40 | pos=0; 41 | for n=1:numel(CSX.Properties.Excitation) 42 | if strcmp(CSX.Properties.Excitation{n}.ATTRIBUTE.Name, name) 43 | pos=n; 44 | end 45 | end 46 | 47 | if (pos==0) 48 | error('CSXCAD::SetExcitationWeight: property not found'); 49 | return; 50 | end 51 | 52 | CSX.Properties.Excitation{pos}.Weight.ATTRIBUTE.X = weight{1}; 53 | CSX.Properties.Excitation{pos}.Weight.ATTRIBUTE.Y = weight{2}; 54 | CSX.Properties.Excitation{pos}.Weight.ATTRIBUTE.Z = weight{3}; 55 | -------------------------------------------------------------------------------- /matlab/SetMaterialProperty.m: -------------------------------------------------------------------------------- 1 | function CSX = SetMaterialProperty(CSX, name, varargin) 2 | % function CSX = SetMaterialProperty(CSX, name, varargin) 3 | % 4 | % Use this function to define the material constants: 5 | % - 'Epsilon': relative electric permittivity: [Epsilon] = 1 6 | % - 'Mue': relative magnetic permeability: [Mue} = 1 7 | % - 'Kappa': electric conductivity: [Kappa] = S/m 8 | % - 'Sigma': magnetic conductivity (non-physical property): [Sigma] = Ohm/m 9 | % - 'Density': material mass density: [Density] = kg/m^3, e.g. water: 1000 10 | % necessary for SAR calculations 11 | % 12 | % examples: 13 | % 14 | % CSX = AddMaterial( CSX, 'RO3010' ); 15 | % CSX = SetMaterialProperty( CSX, 'RO3010', 'Epsilon', 10.2, 'Mue', 1 ); 16 | % CSX = AddBox( CSX, 'RO3010', 0, [0 0 0], [100 1000 1000] ); 17 | % 18 | % % anisotropic material 19 | % CSX = AddMaterial( CSX, 'sheet','Isotropy',0); 20 | % CSX = SetMaterialProperty(CSX, 'sheet', 'Kappa', [0 0 kappa]); 21 | % CSX = AddBox( CSX, 'sheet', 0, [0 0 0], [10 1000 1000] ); 22 | % 23 | % See also AddMaterial, SetMaterialWeight 24 | % 25 | % CSXCAD matlab interface 26 | % ----------------------- 27 | % author: Thorsten Liebig 28 | 29 | CSX = SetPropertyArgs(CSX, GetPropertyType(CSX,name), name, 'Property', varargin{:}); 30 | 31 | -------------------------------------------------------------------------------- /matlab/SetMaterialWeight.m: -------------------------------------------------------------------------------- 1 | function CSX = SetMaterialWeight(CSX, name, varargin) 2 | % function CSX = SetMaterialWeight(CSX, name, varargin) 3 | % 4 | % Define the material weighting function(s) 5 | % 6 | % The functions can use the variables: 7 | % - x,y,z 8 | % - rho for the distance to z-axis 9 | % - r for the distance to origin 10 | % - a for alpha (as in cylindircal and spherical coord systems) 11 | % - t for theta (as in the spherical coord system 12 | % 13 | % all these variables are not weighted with the drawing unit defined by 14 | % the grid 15 | % 16 | % example: 17 | % 18 | % %material distribution as a rect-function with 4 periods 19 | % start=[-500 -100 -500]; 20 | % stop =[ 500 100 500]; 21 | % CSX = AddMaterial(CSX, 'material'); 22 | % CSX = SetMaterialProperty(CSX, 'material', 'Epsilon', 1); 23 | % CSX = SetMaterialWeight(CSX, 'material', 'Epsilon', ['(sin(4*z / 1000 *2*pi)>0)+1']); 24 | % CSX = AddBox(CSX, 'material' ,10 , start, stop); 25 | % 26 | % See also AddMaterial, SetMaterialProperty, InitCSX, DefineRectGrid 27 | % 28 | % CSXCAD matlab interface 29 | % ----------------------- 30 | % author: Thorsten Liebig 31 | 32 | CSX = SetPropertyArgs(CSX, GetPropertyType(CSX,name), name, 'Weight', varargin{:}); 33 | -------------------------------------------------------------------------------- /matlab/SmoothMesh.m: -------------------------------------------------------------------------------- 1 | function [mesh] = SmoothMesh( mesh, max_res, ratio, varargin) 2 | % function [mesh] = SmoothMesh( mesh, max_res, ) 3 | % 4 | % Convienent function to create a smooth mesh in all directions. 5 | % Generate smooth mesh by choosing an appropriate algorithm in each direction. 6 | % 7 | % Currently supported smoothing algorithm: 8 | % SmoothMeshLines, SmoothMeshLines2 and RecursiveSmoothMesh 9 | % 10 | % arguments: 11 | % - lines: given fixed lines to create a smooth mesh in between 12 | % - max_res: scalar or vector of desired max. allowed resolution 13 | % - ratio: grading ratio: scalar or vector of desired neighboring 14 | % line-delta ratio (optional, default is 1.5) 15 | % - see also 'allowed_max_ratio' argument 16 | % 17 | % variable arguments ('keyword',value): 18 | % - algorithm: define subset of tried algorihm, e.g. [1 3] 19 | % - symmetric: 0/1 force symmetric mesh (default is input symmetry) 20 | % - homogeneous: 0/1 force homogeneous mesh 21 | % - allowed_min_res: allow a given min resolution only 22 | % - allowed_max_ratio: allow only a given max. grading ratio 23 | % (default --> ratio*1.25) 24 | % - debug: 0/1 off/on 25 | % 26 | % example: 27 | % 28 | % mesh.x = [-BoundBox 0 BoundBox]; 29 | % mesh.y = [-BoundBox 0 BoundBox]; 30 | % mesh.z = [0 BoundBox]; 31 | % mesh = SmoothMesh(mesh, lambda/20/unit); 32 | % CSX = DefineRectGrid(CSX, unit, mesh); 33 | % 34 | % See also AutoSmoothMeshLines, InitCSX, DefineRectGrid, DetectEdges 35 | % 36 | % CSXCAD matlab interface 37 | % ----------------------- 38 | % author: Thorsten Liebig (C) 2012 39 | 40 | if (nargin<3) 41 | ratio = 1.5; 42 | end 43 | 44 | if (numel(max_res)==1) 45 | max_res = [max_res max_res max_res]; 46 | end 47 | if (numel(ratio)==1) 48 | ratio = [ratio ratio ratio]; 49 | end 50 | if (numel(max_res)~=1) 51 | max_res = [max_res max_res max_res]; 52 | end 53 | 54 | if isfield(mesh,'x') 55 | mesh.x = AutoSmoothMeshLines(mesh.x, max_res(1), ratio(1), varargin{:}); 56 | elseif isfield(mesh,'r') 57 | mesh.r = AutoSmoothMeshLines(mesh.r, max_res(1), ratio(1), varargin{:}); 58 | else 59 | error 'x/(r) direction not found' 60 | end 61 | 62 | if isfield(mesh,'y') 63 | mesh.y = AutoSmoothMeshLines(mesh.y, max_res(2), ratio(2), varargin{:}); 64 | elseif isfield(mesh,'a') 65 | mesh.a = AutoSmoothMeshLines(mesh.a, max_res(2), ratio(2), varargin{:}); 66 | else 67 | error 'y/(a) direction not found' 68 | end 69 | 70 | if isfield(mesh,'z') 71 | mesh.z = AutoSmoothMeshLines(mesh.z, max_res(3), ratio(3), varargin{:}); 72 | else 73 | error 'z direction not found' 74 | end 75 | -------------------------------------------------------------------------------- /matlab/SmoothMeshLines.m: -------------------------------------------------------------------------------- 1 | function lines = SmoothMeshLines( lines, max_res, ratio, varargin) 2 | %function lines = SmoothMeshLines( lines, max_res, ratio, varargin) 3 | % 4 | % create smooth mesh lines 5 | % 6 | % Warning: This function may not always produce a desired output. 7 | % 8 | % - lines: given fixed lines to create a smooth mesh in between 9 | % - max_res: desired max. resolution 10 | % - ratio: max. neighboring line-delta ratio, (optional, default is 1.3) 11 | % 12 | % optional variable arguments ('key', value) 13 | % - recursive: SmoothMeshLines a couple of times recursivly (default is 0) 14 | % - CheckMesh: Do a final mesh check (default is true) 15 | % - allowed_max_ratio: allow only a given max. grading ratio 16 | % (default --> ratio*1.25) 17 | % 18 | % example: 19 | % 20 | % % create a x-mesh with lines at 0, 50 and 200 an a desired mesh 21 | % resolution of 5 22 | % mesh.x = SmoothMeshLines([0 50 200],5,1.3); 23 | % 24 | % See also InitCSX, DefineRectGrid 25 | % 26 | % CSXCAD matlab interface 27 | % ----------------------- 28 | % author: Thorsten Liebig 29 | 30 | if (numel(lines)<2) 31 | return 32 | end 33 | 34 | if (nargin<3) 35 | ratio = 1.3; 36 | end 37 | 38 | recursive = 0; 39 | check_mesh = true; 40 | max_ratio = ratio*1.25; 41 | 42 | for vn=1:2:numel(varargin) 43 | if (strcmpi(varargin{vn},'recursive')) 44 | recursive = varargin{vn+1}; 45 | end 46 | if (strcmpi(varargin{vn},'CheckMesh')) 47 | check_mesh = varargin{vn+1}; 48 | end 49 | if (strcmpi(varargin{vn},'allowed_max_ratio')) 50 | max_ratio = varargin{vn+1}; 51 | end 52 | end 53 | 54 | lines = unique(sort(lines)); 55 | 56 | diff_Lines = diff(lines); 57 | 58 | index = find(diff_Lines>(1.001*max_res)); 59 | 60 | % for n=1:numel(diff_Lines)-1 61 | % if ( (diff_Lines(n+1)/diff_Lines(n) > ratio) ) 62 | % index = [index n+1]; 63 | % end 64 | % end 65 | 66 | index = unique(index); 67 | 68 | addLines = []; 69 | 70 | for n=1:numel(index) 71 | if (index(n)==1) 72 | start_res = max_res; 73 | else 74 | start_res = lines(index(n)) - lines(index(n)-1); 75 | end 76 | 77 | if ((index(n)+1)==numel(lines)) 78 | stop_res = max_res; 79 | else 80 | stop_res = lines(index(n)+2) - lines(index(n)+1); 81 | end 82 | 83 | addLines = [addLines SmoothRange(lines(index(n)),lines(index(n)+1),start_res,stop_res,max_res,ratio)]; 84 | end 85 | 86 | 87 | lines = unique(sort([lines addLines])); 88 | 89 | addLines = []; 90 | % relax ratio for test 91 | ratio_relax = ratio + (ratio-1) * 1; 92 | 93 | [EC pos E_type] = CheckMesh(lines,0,max_res,ratio_relax,1); 94 | diff_Lines = diff(lines); 95 | 96 | for n=1:EC 97 | if pos(n)>1 98 | start_res = diff_Lines(pos(n)-1); 99 | else 100 | start_res = diff_Lines(pos(n)); 101 | end 102 | if pos(n) >= numel(diff_Lines) 103 | stop_res = diff_Lines(end); 104 | else 105 | stop_res = diff_Lines(pos(n)+1); 106 | end 107 | max_res_R = max([start_res stop_res])/2/ratio; 108 | addLines = [addLines SmoothRange(lines(pos(n)),lines(pos(n)+1),start_res,stop_res,max_res_R,ratio)]; 109 | end 110 | 111 | lines = unique(sort([lines addLines])); 112 | 113 | for n=1:recursive 114 | old_numL = numel(lines); 115 | lines = SmoothMeshLines( lines, max_res, ratio, 0); 116 | if numel(lines) == old_numL 117 | return 118 | end 119 | end 120 | 121 | if (check_mesh) 122 | CheckMesh(lines,0,max_res,max_ratio,0); 123 | end 124 | -------------------------------------------------------------------------------- /matlab/isOctave.m: -------------------------------------------------------------------------------- 1 | function [isOct,ver] = isOctave() 2 | % [isOct,version] = isOctave() 3 | % 4 | % Function to test if matlab or octave is used. 5 | % 6 | % Output: 7 | % - isOct: bool; true, if interpreter is Octave 8 | % - version: struct 9 | % - .major: number; major version 10 | % - .minor: number; minor version 11 | % - .release: number; release version 12 | % 13 | % example (Octave 3.6.1): 14 | % 15 | % isOct = true 16 | % version.major = 3 17 | % version.minor = 6 18 | % version.release = 1 19 | % 20 | % example (Matlab 7.8.0.347 (R2009a)): 21 | % 22 | % isOct = false 23 | % version.major = 7 24 | % version.minor = 8 25 | % version.release = 0 26 | % 27 | % openEMS matlab/octave interface 28 | % ----------------------- 29 | % (C) 2011 Thorsten Liebig 30 | % (C) 2012 Sebastian Held 31 | 32 | isOct = exist('OCTAVE_VERSION','builtin') ~= 0; 33 | 34 | if (isOct) 35 | ver_cell = strsplit( OCTAVE_VERSION, '.' ); 36 | else 37 | remain = version(); 38 | ver_cell = {}; 39 | while ~isempty(remain) 40 | [str, remain] = strtok(remain, '.'); 41 | ver_cell{end+1} = str; 42 | end 43 | end 44 | 45 | ver = []; 46 | ver.major = str2double(ver_cell{1}); 47 | ver.minor = str2double(ver_cell{2}); 48 | ver.release = str2double(ver_cell{3}); 49 | -------------------------------------------------------------------------------- /matlab/private/Add2Property.m: -------------------------------------------------------------------------------- 1 | function CSX = Add2Property(CSX, propName, newPrim, primName) 2 | % function CSX = Add2Property(CSX, propName, newPrim, primName) 3 | % 4 | % meant for internal use!! 5 | % 6 | % CSXCAD matlab interface 7 | % ----------------------- 8 | % author: Thorsten Liebig 9 | 10 | type = GetPropertyType(CSX, propName); 11 | if isempty(type) 12 | error('CSXCAD:Add2Property',['the type for the property "' propName '" cannot be found']); 13 | end 14 | 15 | pos = GetPropertyPosition(CSX, type, propName); 16 | if (pos==0) 17 | error('CSXCAD:Add2Property',['property "' propName '" of type "' type '" not found!']); 18 | end 19 | 20 | if ~isfield(CSX.Properties.(type){pos}, 'Primitives') 21 | CSX.Properties.(type){pos}.Primitives.(primName){1}=newPrim; 22 | elseif ~isfield(CSX.Properties.(type){pos}.Primitives, primName) 23 | CSX.Properties.(type){pos}.Primitives.(primName){1}=newPrim; 24 | else 25 | CSX.Properties.(type){pos}.Primitives.(primName){end+1}=newPrim; 26 | end 27 | -------------------------------------------------------------------------------- /matlab/private/AddPrimitiveArgs.m: -------------------------------------------------------------------------------- 1 | function primitive = AddPrimitiveArgs(primitive, varargin) 2 | % prim = AddPrimitiveArgs(primitive, varargin) 3 | % 4 | % meant for internal use only 5 | % 6 | % CSXCAD matlab interface 7 | % ----------------------- 8 | % author: Thorsten Liebig 9 | 10 | transform = []; 11 | 12 | for n=1:2:(nargin-2) 13 | if (strcmp(varargin{n},'Transform')) 14 | transform = varargin([n:n+1]); 15 | varargin([n:n+1]) = []; 16 | break 17 | end 18 | end 19 | 20 | for n=1:2:numel(varargin) 21 | primitive.ATTRIBUTE.(varargin{n}) = varargin{n+1}; 22 | end 23 | 24 | if ~isempty(transform) 25 | for n=1:2:numel(transform{2}) 26 | primitive.Transformation.(transform{2}{n}).ATTRIBUTE.Argument=transform{2}{n+1}; 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /matlab/private/AddProperty.m: -------------------------------------------------------------------------------- 1 | function [CSX pos] = AddProperty(CSX, type, name, varargin) 2 | % function [CSX pos] = AddProperty(CSX, type, name, varargin) 3 | % 4 | % internal function to add a property to CSX.Properties 5 | % 6 | % CSXCAD matlab interface 7 | % ----------------------- 8 | % author: Thorsten Liebig 9 | 10 | % check if this property already exists 11 | [type_found pos] = FindProperty(CSX, name); 12 | if (pos>0) 13 | error('CSXCAD:AddProperty',['property with name "' name '" with type "' type_found '" already exists! Choose a different name!']); 14 | end 15 | 16 | if isfield(CSX.Properties,type) 17 | pos = numel(CSX.Properties.(type))+1; 18 | else 19 | CSX.Properties.(type) = {}; % create cell array 20 | pos = 1; 21 | end 22 | 23 | CSX.Properties.(type){pos}.ATTRIBUTE.Name=name; 24 | for n=1:numel(varargin)/2 25 | if ~ischar(varargin{2*n-1}) 26 | error(['CSXCAD::AddProperty: not an attribute: ' varargin{2*n-1}]); 27 | end 28 | CSX.Properties.(type){pos}.ATTRIBUTE.(varargin{2*n-1})=varargin{2*n}; 29 | end 30 | -------------------------------------------------------------------------------- /matlab/private/CheckSymmtricLines.m: -------------------------------------------------------------------------------- 1 | function result = CheckSymmtricLines(lines) 2 | % function result = CheckSymmtricLines(lines) 3 | % 4 | % check mesh lines for symmetry 5 | % 6 | % Note: make sure lines are sorted and unique 7 | % 8 | % CSXCAD matlab interface 9 | % ----------------------- 10 | % author: Thorsten Liebig (C) 2012 11 | 12 | result = false; 13 | 14 | tolerance = 1e-10; 15 | NP = numel(lines); 16 | range = lines(end)-lines(1); 17 | center = 0.5*(lines(end)+lines(1)); 18 | 19 | % check all lines for symmetry 20 | for n=1:NP/2 21 | if (abs((center-lines(n))-(lines(end-n+1)-center)) > range*tolerance/NP) 22 | return; 23 | end 24 | end 25 | 26 | % check central point to be symmetry-center 27 | if (mod(NP,2)) 28 | if (abs(lines((NP+1)/2)-center) > range*tolerance/NP) 29 | return; 30 | end 31 | end 32 | 33 | % if all checks pass, return true 34 | result = true; 35 | -------------------------------------------------------------------------------- /matlab/private/FindProperty.m: -------------------------------------------------------------------------------- 1 | function [type pos] = FindProperty(CSX, name) 2 | % function [type pos] = FindProperty(CSX, name) 3 | % 4 | % internal function to find a given property 5 | % 6 | % CSXCAD matlab interface 7 | % ----------------------- 8 | % author: Thorsten Liebig (c) 2013 9 | 10 | pos = 0; 11 | type = GetPropertyType(CSX, name); 12 | 13 | if isempty(type) 14 | return; 15 | end 16 | 17 | pos = GetPropertyPosition(CSX, type, name); 18 | -------------------------------------------------------------------------------- /matlab/private/GetPropertyPosition.m: -------------------------------------------------------------------------------- 1 | function pos = GetPropertyPosition(CSX, type, name) 2 | % function pos = GetPropertyPosition(CSX, type, name) 3 | % 4 | % - internal function to get the position of property with name: 5 | % inside a given type 6 | % - function will perform a series of validitiy tests 7 | % - will return 0 if not found 8 | % 9 | % CSXCAD matlab interface 10 | % ----------------------- 11 | % author: Thorsten Liebig (c) 2013 12 | 13 | pos = 0; 14 | 15 | if ~ischar(name) 16 | error('CSXCAD::GetPropertyPosition: name must be a string'); 17 | end 18 | 19 | if ~ischar(type) 20 | error('CSXCAD::GetPropertyPosition: type name must be a string'); 21 | end 22 | 23 | if ~isfield(CSX,'Properties') 24 | error('CSXCAD:GetPropertyPosition','CSX.Properties is not defined'); 25 | end 26 | 27 | if isempty(type) 28 | error('CSXCAD:GetPropertyPosition','type is empty, maybe the property you requested is undefined'); 29 | end 30 | 31 | % type not (yet) defined, thus not found 32 | if ~isfield(CSX.Properties,type) 33 | return 34 | end 35 | 36 | for n=1:numel(CSX.Properties.(type)) 37 | if strcmp(CSX.Properties.(type){n}.ATTRIBUTE.Name, name) 38 | pos=n; 39 | return 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /matlab/private/GetPropertyType.m: -------------------------------------------------------------------------------- 1 | function type_name = GetPropertyType(CSX, name) 2 | % function type_name = GetPropertyType(CSX, name) 3 | % 4 | % internal function to get the type of a given property 5 | % 6 | % CSXCAD matlab interface 7 | % ----------------------- 8 | % author: Thorsten Liebig (c) 2010-2013 9 | 10 | if ~ischar(name) 11 | error('CSXCAD::GetPropertyType: name must be a string'); 12 | end 13 | if ~isfield(CSX,'Properties') 14 | error('CSXCAD:GetPropertyPosition','CSX.Properties is not defined'); 15 | end 16 | 17 | type_name = ''; 18 | if isempty(CSX.Properties) 19 | return 20 | end 21 | 22 | prop_types = fieldnames(CSX.Properties); 23 | for n=1:numel(prop_types) 24 | for p = 1:numel(CSX.Properties.(prop_types{n})) 25 | if (strcmp(CSX.Properties.(prop_types{n}){p}.ATTRIBUTE.Name,name)) 26 | type_name = prop_types{n}; 27 | return; 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /matlab/private/SetPropertyArgs.m: -------------------------------------------------------------------------------- 1 | function CSX = SetPropertyArgs(CSX, type, name, property, varargin) 2 | % CSX = SetPropertyArgs(CSX, type, name, property, varargin) 3 | % 4 | % CSXCAD matlab interface 5 | % ----------------------- 6 | % author: Thorsten Liebig 7 | 8 | pos = GetPropertyPosition(CSX, type, name); 9 | 10 | if (pos==0) 11 | error('CSXCAD:SetPropertyArgs',['property "' name '" of type "' type '" not found!']); 12 | end 13 | 14 | for n=1:numel(varargin)/2 15 | CSX.Properties.(type){pos}.(property).ATTRIBUTE.(varargin{2*n-1}) = varargin{2*n}; 16 | end 17 | -------------------------------------------------------------------------------- /matlab/private/SmoothRange.m: -------------------------------------------------------------------------------- 1 | function [ lines ] = SmoothRange(start, stop, start_res, stop_res, max_res, ratio) 2 | %function [ lines ] = SmoothRange(start, stop, start_res, stop_res, max_res, ratio) 3 | % 4 | % internal function only, use SmoothMeshLines instead 5 | % 6 | % See also SmoothMeshLines 7 | % 8 | % CSXCAD matlab interface 9 | % ----------------------- 10 | % author: Thorsten Liebig 11 | 12 | if (nargin<6) 13 | ratio = 1.3; 14 | end 15 | 16 | taper = start_res*ratio; 17 | start_taper = start; 18 | while (taperdiff_stop(1)) 43 | start_taper = start_taper(1:end-1); 44 | else 45 | stop_taper = stop_taper(2:end); 46 | end 47 | 48 | if (numel(stop_taper)==0) || (numel(start_taper)==0) 49 | break 50 | end 51 | end 52 | 53 | if (numel(stop_taper)==0) || (numel(start_taper)==0) 54 | lines = unique([start_taper stop_taper]); 55 | else 56 | numL = ceil((stop_taper(1) - start_taper(end))/max_res)+1; 57 | lines = unique([start_taper linspace(start_taper(end),stop_taper(1),numL) stop_taper]); 58 | end -------------------------------------------------------------------------------- /matlab/private/octave_struct2xml_2.m: -------------------------------------------------------------------------------- 1 | function out = octave_struct2xml_2( in, rootName, indent ) 2 | 3 | out = [indent '<' rootName]; 4 | 5 | float_accuracy = 15; 6 | 7 | % process attributes 8 | if isstruct( in ) 9 | fnames = fieldnames( in ); 10 | for n=1:numel(fnames) 11 | current_field = fnames{n}; 12 | if strcmp( current_field, 'ATTRIBUTE' ) 13 | attributes = fieldnames( in.ATTRIBUTE ); 14 | for m=1:numel( attributes ) 15 | temp = in.ATTRIBUTE.(attributes{m}); 16 | if ~ischar( temp ) 17 | temp = vector2str( temp, float_accuracy ); 18 | end 19 | out = [out ' ' attributes{m} '="' temp '"']; 20 | end 21 | break 22 | end 23 | end 24 | end 25 | 26 | out = [out '>']; 27 | 28 | 29 | % process content 30 | if ~isstruct( in ) 31 | if ~ischar( in ) 32 | temp = vector2str(in, float_accuracy); 33 | else 34 | temp = in; 35 | end 36 | out = [out temp '\n']; 37 | return 38 | end 39 | 40 | out = [out '\n']; 41 | 42 | fnames = fieldnames( in ); 43 | for n=1:numel(fnames) 44 | current_field = fnames{n}; 45 | if strcmp( current_field, 'ATTRIBUTE' ) 46 | continue 47 | end 48 | if iscell( in.(current_field) ) 49 | for m=1:numel( in.(current_field) ) 50 | out = [out octave_struct2xml_2( in.(current_field){m}, current_field, [indent ' '] )]; 51 | end 52 | else 53 | out = [out octave_struct2xml_2( in.(current_field), current_field, [indent ' '] )]; 54 | end 55 | end 56 | 57 | out = [out indent '\n']; 58 | -------------------------------------------------------------------------------- /matlab/private/struct_2_xmlNode.m: -------------------------------------------------------------------------------- 1 | function docElem = struct_2_xmlNode(docNode, docElem, mat_struct) 2 | 3 | if (isfield(mat_struct,'ATTRIBUTE')) 4 | names = fieldnames(mat_struct.ATTRIBUTE); 5 | for n=1:numel(names) 6 | if isnumeric(getfield(mat_struct.ATTRIBUTE,names{n})) || islogical(getfield(mat_struct.ATTRIBUTE,names{n})) 7 | docElem.setAttribute(names{n},vector2str(getfield(mat_struct.ATTRIBUTE,names{n}),15)); 8 | else 9 | docElem.setAttribute(names{n},getfield(mat_struct.ATTRIBUTE,names{n})); 10 | end 11 | end 12 | mat_struct = rmfield(mat_struct,'ATTRIBUTE'); 13 | end 14 | 15 | names = fieldnames(mat_struct); 16 | 17 | for n=1:numel(names) 18 | if isstruct(getfield(mat_struct,names{n})) 19 | docNewElem = docNode.createElement(names{n}); 20 | docNewElem = struct_2_xmlNode(docNode, docNewElem, getfield(mat_struct,names{n})); 21 | docElem.appendChild(docNewElem); 22 | elseif iscell(getfield(mat_struct,names{n})) 23 | cellfield = getfield(mat_struct,names{n}); 24 | for m=1:numel(cellfield) 25 | if ischar(cellfield{m}) 26 | docNewElem = docNode.createElement(names{n}); 27 | docNewElem.appendChild(docNode.createTextNode(cellfield{m})); 28 | docElem.appendChild(docNewElem); 29 | else 30 | docNewElem = docNode.createElement(names{n}); 31 | docNewElem = struct_2_xmlNode(docNode, docNewElem, cellfield{m}); 32 | docElem.appendChild(docNewElem); 33 | end 34 | end 35 | elseif isempty(getfield(mat_struct,names{n})) 36 | %do nothing... 37 | elseif isnumeric(getfield(mat_struct,names{n})) 38 | number = getfield(mat_struct,names{n}); 39 | str = vector2str(number,15); 40 | docNewElem = docNode.createElement(names{n}); 41 | docNewElem.appendChild(docNode.createTextNode(str)); 42 | docElem.appendChild(docNewElem); 43 | elseif ischar(getfield(mat_struct,names{n})) 44 | docNewElem = docNode.createElement(names{n}); 45 | docNewElem.appendChild(docNode.createTextNode(getfield(mat_struct,names{n}))); 46 | docElem.appendChild(docNewElem); 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /matlab/private/vector2str.m: -------------------------------------------------------------------------------- 1 | function str = vector2str(vec, acc) 2 | % str = vector2str( vec [, acc] ) 3 | % 4 | % internal function for CSXCAD 5 | % 6 | % (c) 2012-2015 Thorsten Liebig 7 | % (C) 2012 Sebastian Held 8 | 9 | str = ''; 10 | 11 | if (numel(vec)==0) 12 | return 13 | end 14 | 15 | if (nargin<2) 16 | acc = 9; 17 | end 18 | 19 | % Octave < 3.8.0 has a bug in num2str() (only 64bit versions) 20 | % see bug report https://savannah.gnu.org/bugs/index.php?36121 21 | [isOct,version] = isOctave(); 22 | if (isOct && version.major <= 3 && version.minor < 8) 23 | % affected Octave versions 24 | for n = 1:numel(vec) 25 | str = [str sprintf('%.*g', acc, vec(n)) ',']; 26 | end 27 | else 28 | % Matlab and non affected Octave 29 | for n = 1:numel(vec) 30 | str = [str num2str(vec(n),acc) ',']; 31 | end 32 | end 33 | 34 | % remove the last ',' 35 | str = str(1:end-1); 36 | -------------------------------------------------------------------------------- /matlab/searchBinary.m: -------------------------------------------------------------------------------- 1 | function [binary_location] = searchBinary(name, searchpath, err_fail) 2 | % [binary_location] = searchBinary(name, searchpath<, err_fail>) 3 | % 4 | % Function to search for executable. If the executable isn't found 5 | % in searchpath, look in environment search path. 6 | % 7 | % parameter: 8 | % 9 | % - name: name of the binary to search 10 | % - searchpath: (list of) search paths 11 | % - err_fail: 0/1, throw an error if binary is not found (default is 1) 12 | % 13 | % Output: 14 | % 15 | % - binary_location: 16 | % - if found in searchpath: full path of binary 17 | % - if found in environment search path: name of binary 18 | % - if not found: empty string 19 | % 20 | % 21 | % openEMS matlab/octave interface 22 | % ----------------------- 23 | % (C) 2013 Stefan Mahr 24 | 25 | if (nargin<3) 26 | err_fail = 1; 27 | end 28 | 29 | if ischar(searchpath) 30 | searchpath = {searchpath}; 31 | end 32 | 33 | % append PATH search paths 34 | searchpath = [searchpath regexp(getenv('PATH'), pathsep, 'split')]; 35 | 36 | % try all search paths 37 | for n=1:numel(searchpath) 38 | binary_location = [searchpath{n} name]; 39 | if exist(binary_location, 'file') 40 | return 41 | end 42 | end 43 | 44 | % binary not found 45 | binary_location = ''; 46 | 47 | if (err_fail) 48 | error('CSXCAD:binary_location', [name ' binary not found!']); 49 | end 50 | -------------------------------------------------------------------------------- /matlab/struct_2_xml.m: -------------------------------------------------------------------------------- 1 | function struct_2_xml(filename, xml_struct, rootName); 2 | 3 | if ~isOctave() 4 | docNode = com.mathworks.xml.XMLUtils.createDocument(rootName); 5 | docElem = docNode.getDocumentElement; 6 | 7 | docElem = struct_2_xmlNode(docNode, docElem, xml_struct); 8 | 9 | % Save the sample XML document. 10 | xmlFileName = [filename]; 11 | xmlwrite(xmlFileName,docNode); 12 | else 13 | % % for octave you need the octave_xmltoolbox (C) 2007 Thomas Geiger 14 | % % http://wiki.octave.org/wiki.pl?XMLToolboxPort 15 | % xml_struct = octave_struct2xml( xml_struct, rootName ); 16 | % xml_save( filename, xml_struct, 'any' ); 17 | 18 | % xml_toolbox is buggy (sequence of elements is not preserved) 19 | fid = fopen( filename, 'w' ); 20 | fprintf( fid, '\n' ); 21 | fprintf( fid, octave_struct2xml_2(xml_struct,rootName,'') ); 22 | fclose( fid ); 23 | end 24 | -------------------------------------------------------------------------------- /python/CSXCAD/CSRectGrid.pxd: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Copyright (C) 2015,20016 Thorsten Liebig (Thorsten.Liebig@gmx.de) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Lesser General Public License as published 7 | # by the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | from libcpp.string cimport string 20 | from libcpp cimport bool 21 | 22 | cdef extern from "CSXCAD/CSXCAD_Global.h": 23 | cpdef enum CoordinateSystem "CoordinateSystem": 24 | CARTESIAN "CARTESIAN" 25 | CYLINDRICAL "CYLINDRICAL" 26 | UNDEFINED_CS "UNDEFINED_CS" 27 | 28 | cdef extern from "CSXCAD/CSRectGrid.h": 29 | cdef cppclass _CSRectGrid "CSRectGrid": 30 | _CSRectGrid() except + 31 | void AddDiscLine(int direct, double val) 32 | 33 | void clear() 34 | void ClearLines(int direct) 35 | 36 | void SetDeltaUnit(double val) 37 | double GetDeltaUnit() 38 | 39 | void Sort(int direct) 40 | double* GetLines(int direct, double *array, unsigned int &qty, bool sorted) 41 | size_t GetQtyLines(int direct) 42 | double GetLine(int direct, size_t Index) 43 | 44 | unsigned int Snap2LineNumber(int ny, double value, bool &inside) 45 | 46 | int GetDimension() 47 | void SetMeshType(CoordinateSystem cs_type) 48 | CoordinateSystem GetMeshType() 49 | 50 | void IncreaseResolution(int nu, int factor) 51 | double* GetSimArea() 52 | bool isValid() 53 | 54 | cdef class CSRectGrid: 55 | cdef _CSRectGrid *thisptr 56 | @staticmethod 57 | cdef fromPtr(_CSRectGrid *ptr) 58 | cdef _SetPtr(self, _CSRectGrid *ptr) 59 | cdef bool no_init 60 | -------------------------------------------------------------------------------- /python/CSXCAD/CSTransform.pxd: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Copyright (C) 2015,20016 Thorsten Liebig (Thorsten.Liebig@gmx.de) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Lesser General Public License as published 7 | # by the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | from libcpp.string cimport string 20 | from libcpp cimport bool 21 | from CSXCAD.ParameterObjects cimport _ParameterSet 22 | 23 | cdef extern from "CSXCAD/CSTransform.h": 24 | cdef cppclass _CSTransform "CSTransform": 25 | _CSTransform() except + 26 | _CSTransform(_ParameterSet*) except + 27 | 28 | void Reset() 29 | 30 | double* Transform(double *inCoord, double *outCoord) 31 | double* InvertTransform(double *inCoord, double *outCoord) 32 | 33 | double* GetMatrix() 34 | 35 | bool HasTransform() 36 | 37 | void Translate(double *translate, bool concatenate) 38 | 39 | void SetMatrix(double *matrix, bool concatenate) 40 | 41 | void RotateOrigin(double *vector, double angle, bool concatenate) 42 | void RotateXYZ(int ny, double angle, bool concatenate) 43 | 44 | void Scale(double scale, bool concatenate) 45 | void Scale(double *scale, bool concatenate) 46 | 47 | void SetPreMultiply() 48 | void SetPostMultiply() 49 | 50 | void SetAngleRadian() 51 | 52 | cdef class CSTransform: 53 | cdef _CSTransform *thisptr 54 | @staticmethod 55 | cdef fromPtr(_CSTransform *ptr) 56 | cdef _SetPtr(self, _CSTransform *ptr) 57 | -------------------------------------------------------------------------------- /python/CSXCAD/CSXCAD.pxd: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Copyright (C) 2015,20016 Thorsten Liebig (Thorsten.Liebig@gmx.de) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Lesser General Public License as published 7 | # by the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | from libcpp.string cimport string 20 | from libcpp cimport bool 21 | from libcpp.vector cimport vector 22 | 23 | cimport CSXCAD.CSPrimitives 24 | cimport CSXCAD.CSProperties 25 | 26 | from CSXCAD.CSPrimitives cimport _CSPrimitives, CSPrimitives, PrimitiveType 27 | from CSXCAD.ParameterObjects cimport _ParameterSet, ParameterSet 28 | from CSXCAD.CSProperties cimport _CSProperties, CSProperties, PropertyType 29 | from CSXCAD.CSRectGrid cimport _CSRectGrid, CSRectGrid, CoordinateSystem 30 | 31 | cdef extern from "CSXCAD/ContinuousStructure.h": 32 | cdef cppclass _ContinuousStructure "ContinuousStructure": 33 | _ContinuousStructure() except + 34 | bool Write2XML(string) 35 | string ReadFromXML(string) 36 | _ParameterSet* GetParameterSet() 37 | 38 | _CSRectGrid* GetGrid() 39 | 40 | void SetCoordInputType(CoordinateSystem cs_type) 41 | CoordinateSystem GetCoordInputType() 42 | 43 | void AddProperty(_CSProperties* prop) 44 | void RemoveProperty(_CSProperties* prop) 45 | void DeleteProperty(_CSProperties* prop) 46 | _CSProperties* GetProperty(int index) 47 | int GetQtyPrimitives(PropertyType prop_type) 48 | int GetQtyProperties() 49 | 50 | _CSProperties* GetPropertyByCoordPriority(const double* coord, PropertyType prop_type, bool markFoundAsUsed, _CSPrimitives** foundPrimitive) 51 | 52 | vector[_CSPrimitives*] GetAllPrimitives(bool sort, PropertyType prop_type) 53 | 54 | vector[_CSProperties*] GetPropertiesByName(string name) 55 | vector[_CSProperties*] GetPropertyByType(PropertyType prop_type) 56 | 57 | void clear() 58 | string Update() 59 | 60 | cdef class ContinuousStructure: 61 | cdef _ContinuousStructure *thisptr # hold a C++ instance which we're wrapping 62 | cdef _GetProperty(self, int index) 63 | cdef __GetPropertyByCoordPriority(self, double* coord, PropertyType prop_type, bool markFoundAsUsed) 64 | cdef __GetAllPrimitives(self, bool sort, PropertyType prop_type) 65 | cdef __GetPropertiesByName(self, string name) 66 | cdef __GetPropertyByType(self, PropertyType prop_type) 67 | -------------------------------------------------------------------------------- /python/CSXCAD/ParameterObjects.pxd: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Copyright (C) 2015,20016 Thorsten Liebig (Thorsten.Liebig@gmx.de) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Lesser General Public License as published 7 | # by the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | from libcpp cimport bool 20 | 21 | cdef extern from "CSXCAD/ParameterObjects.h": 22 | cdef cppclass _ParameterSet "ParameterSet": 23 | _ParameterSet() except + 24 | void PrintSelf() 25 | bool GetModified() 26 | 27 | cdef class ParameterSet: 28 | cdef _ParameterSet *thisptr 29 | @staticmethod 30 | cdef fromPtr(_ParameterSet *ptr) 31 | cdef _SetPtr(self, _ParameterSet *ptr) 32 | cdef bool no_init 33 | -------------------------------------------------------------------------------- /python/CSXCAD/ParameterObjects.pyx: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Copyright (C) 2015,20016 Thorsten Liebig (Thorsten.Liebig@gmx.de) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Lesser General Public License as published 7 | # by the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | from libcpp.string cimport string 20 | from libcpp cimport bool 21 | from libc.stdint cimport uintptr_t 22 | 23 | cimport CSXCAD.ParameterObjects 24 | 25 | cdef class ParameterSet: 26 | _instances = {} 27 | 28 | @staticmethod 29 | cdef fromPtr(_ParameterSet *ptr): 30 | if ptr == NULL: 31 | return None 32 | cdef ParameterSet pset 33 | pset = ParameterSet._instances.get(ptr, None) 34 | if pset is not None: 35 | return pset 36 | pset = ParameterSet(no_init=True) 37 | pset._SetPtr(ptr) 38 | return pset 39 | 40 | def __cinit__(self, no_init=False): 41 | self.no_init = no_init 42 | if no_init==True: 43 | self.thisptr = NULL 44 | else: 45 | self._SetPtr(new _ParameterSet()) 46 | 47 | cdef _SetPtr(self, _ParameterSet *ptr): 48 | if self.thisptr != NULL and self.thisptr != ptr: 49 | raise Exception('Different C++ class pointer already assigned to python wrapper class!') 50 | self.thisptr = ptr 51 | ParameterSet._instances[self.thisptr] = self 52 | 53 | def __dealloc__(self): 54 | if not self.no_init: 55 | del ParameterSet._instances[self.thisptr] 56 | del self.thisptr 57 | -------------------------------------------------------------------------------- /python/CSXCAD/Utilities.pyx: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Copyright (C) 2015,20016 Thorsten Liebig (Thorsten.Liebig@gmx.de) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Lesser General Public License as published 7 | # by the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | def CheckNyDir(ny): 20 | """ CheckNyDir(ny) 21 | 22 | Translate directions like 'x'/'y' or 'z' into 0/1 or 2. 23 | Raise an assertion error otherwise. 24 | 25 | :param ny: int or str 26 | :returns: int -- direction as 0/1/2 27 | """ 28 | CARTESIAN_COORDINATES = ('x','y','z') 29 | CYLINDRICAL_COORDINATES = ('r','a','z') 30 | if ny in [0, 1, 2]: 31 | return ny 32 | elif ny in CARTESIAN_COORDINATES: 33 | return CARTESIAN_COORDINATES.index(ny) 34 | elif ny in CYLINDRICAL_COORDINATES: 35 | return CYLINDRICAL_COORDINATES.index(ny) 36 | else: 37 | raise ValueError(f'Invalid direction `{ny}`, valid directions are {(0,1,2)}, or {CARTESIAN_COORDINATES} in Cartesian coordinates or {CYLINDRICAL_COORDINATES} in cylindrical coordinates.') 38 | 39 | def GetMultiDirs(dirs): 40 | assert type(dirs)==str, 'GetMultiDirs: dirs must be of type str' 41 | dirs = ''.join(sorted(dirs)) 42 | if dirs == 'all' or dirs == 'xyz' or dirs == 'raz': 43 | return [0, 1, 2] 44 | elif dirs == 'x' or dirs == 'r': 45 | return [0,] 46 | elif dirs == 'y' or dirs == 'a': 47 | return [1,] 48 | elif dirs == 'z': 49 | return [2,] 50 | elif dirs == 'xy' or dirs == 'ra': 51 | return [0, 1] 52 | elif dirs == 'yz' or dirs == 'az': 53 | return [1, 2] 54 | elif dirs == 'xz' or dirs == 'rz': 55 | return [0, 2] 56 | -------------------------------------------------------------------------------- /python/CSXCAD/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Shortcut CSXCAD import 4 | 5 | from __future__ import absolute_import 6 | 7 | AppCSXCAD_BIN = 'AppCSXCAD' 8 | 9 | import os 10 | if os.name == 'nt' and 'OPENEMS_INSTALL_PATH' in os.environ and os.path.exists(os.environ['OPENEMS_INSTALL_PATH']): 11 | try: # to use Python 3.8's DLL handling 12 | os.add_dll_directory(os.environ['OPENEMS_INSTALL_PATH']) 13 | except AttributeError: # <3.8, use PATH 14 | if os.environ['OPENEMS_INSTALL_PATH'] not in os.environ['PATH']: 15 | os.environ['PATH'] += os.pathsep + os.environ['OPENEMS_INSTALL_PATH'] 16 | 17 | AppCSXCAD_BIN = os.path.join(os.environ['OPENEMS_INSTALL_PATH'], 'AppCSXCAD') 18 | 19 | from CSXCAD.CSXCAD import ContinuousStructure 20 | -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 | # CSXCAD python interface 2 | 3 | ## Install 4 | If openEMS was installed into `~/opt/openEMS`, then install this package with: 5 | 6 | ```bash 7 | python setup.py build_ext -I ~/opt/openEMS/include -L ~/opt/openEMS/lib -R ~/opt/openEMS/lib 8 | python setup.py install 9 | ``` 10 | 11 | Otherwise, replace `~/opt/openEMS` with the path to the place where it was installed. 12 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives.rst: -------------------------------------------------------------------------------- 1 | .. _csprimitives: 2 | 3 | CSPrimitives 4 | ============ 5 | 6 | .. automodule:: CSXCAD.CSPrimitives 7 | 8 | **List of Primitives:** 9 | 10 | .. toctree:: 11 | 12 | CSPrimitives/CSPrimitives 13 | CSPrimitives/CSPrimPoint 14 | CSPrimitives/CSPrimBox 15 | CSPrimitives/CSPrimCylinder 16 | CSPrimitives/CSPrimCylindricalShell 17 | CSPrimitives/CSPrimSphere 18 | CSPrimitives/CSPrimSphericalShell 19 | CSPrimitives/CSPrimPolygon 20 | CSPrimitives/CSPrimLinPoly 21 | CSPrimitives/CSPrimRotPoly 22 | CSPrimitives/CSPrimCurve 23 | CSPrimitives/CSPrimWire 24 | CSPrimitives/CSPrimPolyhedron 25 | CSPrimitives/CSPrimPolyhedronReader 26 | 27 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimBox.rst: -------------------------------------------------------------------------------- 1 | .. _csprimbox: 2 | 3 | CSPrimBox 4 | --------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimBox 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimCurve.rst: -------------------------------------------------------------------------------- 1 | .. _csprimcurve: 2 | 3 | CSPrimCurve 4 | ----------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimCurve 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimCylinder.rst: -------------------------------------------------------------------------------- 1 | .. _csprimcylinder: 2 | 3 | CSPrimCylinder 4 | -------------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimCylinder 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimCylindricalShell.rst: -------------------------------------------------------------------------------- 1 | .. _csprimcylindricalshell: 2 | 3 | CSPrimCylindricalShell 4 | ---------------------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimCylindricalShell 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimLinPoly.rst: -------------------------------------------------------------------------------- 1 | .. _csprimlinpoly: 2 | 3 | CSPrimLinPoly 4 | ------------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimLinPoly 6 | :members: 7 | :show-inheritance: 8 | 9 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimPoint.rst: -------------------------------------------------------------------------------- 1 | .. _csprimpoint: 2 | 3 | CSPrimPoint 4 | ----------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimPoint 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimPolygon.rst: -------------------------------------------------------------------------------- 1 | .. _csprimpolygon: 2 | 3 | CSPrimPolygon 4 | ------------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimPolygon 6 | :members: 7 | :show-inheritance: 8 | 9 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimPolyhedron.rst: -------------------------------------------------------------------------------- 1 | .. _csprimpolyhedron: 2 | 3 | CSPrimPolyhedron 4 | ---------------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimPolyhedron 6 | :members: 7 | :show-inheritance: 8 | 9 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimPolyhedronReader.rst: -------------------------------------------------------------------------------- 1 | .. _csprimpolyhedronreader: 2 | 3 | CSPrimPolyhedronReader 4 | ---------------------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimPolyhedronReader 6 | :members: 7 | :show-inheritance: 8 | 9 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimRotPoly.rst: -------------------------------------------------------------------------------- 1 | .. _csprimrotpoly: 2 | 3 | CSPrimRotPoly 4 | ------------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimRotPoly 6 | :members: 7 | :show-inheritance: 8 | 9 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimSphere.rst: -------------------------------------------------------------------------------- 1 | .. _csprimsphere: 2 | 3 | CSPrimSphere 4 | ------------ 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimSphere 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimSphericalShell.rst: -------------------------------------------------------------------------------- 1 | .. _csprimsphericalshell: 2 | 3 | CSPrimSphericalShell 4 | -------------------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimSphericalShell 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimWire.rst: -------------------------------------------------------------------------------- 1 | .. _csprimwire: 2 | 3 | CSPrimWire 4 | ---------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimWire 6 | :members: 7 | :show-inheritance: 8 | 9 | -------------------------------------------------------------------------------- /python/doc/CSPrimitives/CSPrimitives.rst: -------------------------------------------------------------------------------- 1 | .. _csprimitives_base: 2 | 3 | CSPrimitives (Base Class) 4 | ------------------------- 5 | .. autoclass:: CSXCAD.CSPrimitives.CSPrimitives 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSProperties.rst: -------------------------------------------------------------------------------- 1 | .. _csproperties: 2 | 3 | CSProperties 4 | ============ 5 | 6 | .. automodule:: CSXCAD.CSProperties 7 | 8 | **List of Properties:** 9 | 10 | .. toctree:: 11 | 12 | CSProperties/CSProperties 13 | CSProperties/CSPropMaterial 14 | CSProperties/CSPropLumpedElement 15 | CSProperties/CSPropMetal 16 | CSProperties/CSPropConductingSheet 17 | CSProperties/CSPropExcitation 18 | CSProperties/CSPropProbeBox 19 | CSProperties/CSPropDumpBox 20 | -------------------------------------------------------------------------------- /python/doc/CSProperties/CSPropConductingSheet.rst: -------------------------------------------------------------------------------- 1 | .. _cspropconductingsheet: 2 | 3 | CSPropConductingSheet 4 | --------------------- 5 | .. autoclass:: CSXCAD.CSProperties.CSPropConductingSheet 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSProperties/CSPropDumpBox.rst: -------------------------------------------------------------------------------- 1 | .. _cspropdumpbox: 2 | 3 | CSPropDumpBox 4 | ------------- 5 | .. autoclass:: CSXCAD.CSProperties.CSPropDumpBox 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSProperties/CSPropExcitation.rst: -------------------------------------------------------------------------------- 1 | .. _cspropexcitation: 2 | 3 | CSPropExcitation 4 | ---------------- 5 | .. autoclass:: CSXCAD.CSProperties.CSPropExcitation 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSProperties/CSPropLumpedElement.rst: -------------------------------------------------------------------------------- 1 | .. _csproplumpedelement: 2 | 3 | CSPropLumpedElement 4 | ------------------- 5 | .. autoclass:: CSXCAD.CSProperties.CSPropLumpedElement 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSProperties/CSPropMaterial.rst: -------------------------------------------------------------------------------- 1 | .. _cspropmaterial: 2 | 3 | CSPropMaterial 4 | -------------- 5 | .. autoclass:: CSXCAD.CSProperties.CSPropMaterial 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSProperties/CSPropMetal.rst: -------------------------------------------------------------------------------- 1 | .. _cspropmetal: 2 | 3 | CSPropMetal 4 | ----------- 5 | .. autoclass:: CSXCAD.CSProperties.CSPropMetal 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSProperties/CSPropProbeBox.rst: -------------------------------------------------------------------------------- 1 | .. _cspropprobebox: 2 | 3 | CSPropProbeBox 4 | -------------- 5 | .. autoclass:: CSXCAD.CSProperties.CSPropProbeBox 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSProperties/CSProperties.rst: -------------------------------------------------------------------------------- 1 | .. _cspropertiesbase: 2 | 3 | CSProperties (Base Class) 4 | ------------------------- 5 | .. autoclass:: CSXCAD.CSProperties.CSProperties 6 | :members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /python/doc/CSRectGrid.rst: -------------------------------------------------------------------------------- 1 | .. _csrectgrid: 2 | 3 | CSRectGrid 4 | ---------- 5 | 6 | .. automodule:: CSXCAD.CSRectGrid 7 | :members: 8 | :undoc-members: 9 | -------------------------------------------------------------------------------- /python/doc/CSTransform.rst: -------------------------------------------------------------------------------- 1 | .. _cstransform: 2 | 3 | CSTransform 4 | ------------ 5 | 6 | .. automodule:: CSXCAD.CSTransform 7 | :members: 8 | :undoc-members: 9 | 10 | -------------------------------------------------------------------------------- /python/doc/CSXCAD.rst: -------------------------------------------------------------------------------- 1 | .. _csxcad: 2 | 3 | CSXCAD 4 | ------ 5 | 6 | .. automodule:: CSXCAD 7 | :members: ContinuousStructure 8 | :undoc-members: 9 | -------------------------------------------------------------------------------- /python/doc/CSXCAD_API.rst: -------------------------------------------------------------------------------- 1 | CSXCAD Python Interface 2 | ======================= 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | CSXCAD 8 | CSProperties 9 | CSPrimitives 10 | CSTransform 11 | CSRectGrid 12 | Mesh 13 | Utilities 14 | -------------------------------------------------------------------------------- /python/doc/Mesh.rst: -------------------------------------------------------------------------------- 1 | .. _mesh: 2 | 3 | Mesh 4 | ==== 5 | 6 | SmoothMeshLines 7 | --------------- 8 | 9 | .. automodule:: CSXCAD.SmoothMeshLines 10 | :members: 11 | :undoc-members: 12 | 13 | -------------------------------------------------------------------------------- /python/doc/Utilities.rst: -------------------------------------------------------------------------------- 1 | .. _utilities: 2 | 3 | Utilities 4 | --------- 5 | 6 | .. automodule:: CSXCAD.Utilities 7 | :members: 8 | :undoc-members: 9 | -------------------------------------------------------------------------------- /python/doc/about.rst: -------------------------------------------------------------------------------- 1 | .. _about: 2 | 3 | About 4 | ===== 5 | 6 | CSXCAD (Continuous Structure XML) is a C++ library to describe geometrical objects and their physical or non-physical properties. 7 | 8 | It supports a Matlab/Octave and Python interface for high-level interaction. 9 | 10 | License 11 | ------- 12 | 13 | CSXCAD is licensed under the terms of the LGPLv3. 14 | 15 | Further information 16 | ------------------- 17 | 18 | :Website: http://openems.de/index.php/CSXCAD 19 | :Forum: http://openems.de/forum/ 20 | :Tutorials: http://openems.de/index.php/Tutorials 21 | 22 | -------------------------------------------------------------------------------- /python/doc/index.rst: -------------------------------------------------------------------------------- 1 | .. CSXCAD documentation master file, created by 2 | sphinx-quickstart on Sun Aug 28 22:27:13 2016. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to CSXCAD's documentation! 7 | ================================== 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | about 15 | install 16 | CSXCAD_API 17 | 18 | 19 | Indices and tables 20 | ================== 21 | 22 | * :ref:`genindex` 23 | * :ref:`modindex` 24 | * :ref:`search` 25 | 26 | -------------------------------------------------------------------------------- /python/doc/install.rst: -------------------------------------------------------------------------------- 1 | .. _install: 2 | 3 | Install 4 | ======= 5 | 6 | Instructions how to install the CSXCAD python interface. 7 | 8 | Linux 9 | ----- 10 | 11 | * Make sure CSXCAD was build and installed correctly 12 | 13 | * Simple version: 14 | 15 | .. code-block:: console 16 | 17 | python setup.py install 18 | 19 | * Extended options, e.g. for custom install path at */opt*: 20 | 21 | .. code-block:: console 22 | 23 | python setup.py build_ext -I/opt/include -L/opt/lib -R/opt/lib" 24 | pyhton setup.py install 25 | 26 | **Note:** The install command may require root on Linux, or add ``--user`` to install to *~/.local* 27 | 28 | Windows 29 | ------- 30 | 31 | The python interface for CSXCAD currently does not support MS Windows. 32 | -------------------------------------------------------------------------------- /python/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import Extension, setup 2 | from Cython.Build import cythonize 3 | 4 | import os 5 | 6 | extensions = [ 7 | Extension("*", [os.path.join(os.path.dirname(__file__), "CSXCAD","*.pyx")], 8 | language="c++", # generate C++ code 9 | libraries = ['CSXCAD',]), 10 | ] 11 | 12 | setup( 13 | name="CSXCAD", 14 | version = '0.6.2', 15 | description = "Python interface for the CSXCAD library", 16 | classifiers = [ 17 | 'Development Status :: 3 - Alpha', 18 | 'Intended Audience :: Developers', 19 | 'Intended Audience :: Information Technology', 20 | 'Intended Audience :: Science/Research', 21 | 'License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)', 22 | 'Programming Language :: Python', 23 | 'Topic :: Scientific/Engineering', 24 | 'Topic :: Software Development :: Libraries :: Python Modules', 25 | 'Operating System :: POSIX :: Linux', 26 | 'Operating System :: Microsoft :: Windows', 27 | ], 28 | author = 'Thorsten Liebig', 29 | author_email = 'Thorsten.Liebig@gmx.de', 30 | maintainer = 'Thorsten Liebig', 31 | maintainer_email = 'Thorsten.Liebig@gmx.de', 32 | url = 'https://openEMS.de', 33 | packages=["CSXCAD", ], 34 | package_data={'CSXCAD': ['*.pxd']}, 35 | ext_modules = cythonize(extensions, language_level=3) 36 | ) 37 | -------------------------------------------------------------------------------- /python/tests/sphere.ply: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thliebig/CSXCAD/3314deb163156bba60495c9a5a61ffb4eee96757/python/tests/sphere.ply -------------------------------------------------------------------------------- /python/tests/sphere.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thliebig/CSXCAD/3314deb163156bba60495c9a5a61ffb4eee96757/python/tests/sphere.stl -------------------------------------------------------------------------------- /python/tests/test_CSRectGrid.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sat Dec 12 22:04:58 2015 4 | 5 | @author: thorsten 6 | """ 7 | 8 | import numpy as np 9 | 10 | from CSXCAD import CSRectGrid 11 | 12 | import unittest 13 | 14 | class Test_CSRectGrid(unittest.TestCase): 15 | def test_rect_grid(self): 16 | 17 | grid = CSRectGrid.CSRectGrid(CoordSystem=0) 18 | 19 | self.assertEqual( grid.GetMeshType(), 0 ) 20 | 21 | grid.SetMeshType(1) 22 | self.assertEqual( grid.GetMeshType(), 1 ) 23 | 24 | grid.SetLines('x', [0, 1, 2]) 25 | grid.SetLines('y', [-2,0, 1]) 26 | self.assertEqual( grid.GetQtyLines('y'), 3 ) 27 | grid.AddLine('y',4) 28 | self.assertEqual( grid.GetQtyLines('y'), 4 ) 29 | grid.AddLine('y',[4, 2, 5]) 30 | self.assertEqual( grid.GetQtyLines('y'), 7 ) 31 | self.assertTrue( (grid.GetLines('y')==np.array([-2., 0., 1., 4., 4., 2., 5.])).all() ) # check unsorted lines 32 | grid.Sort('y') 33 | self.assertTrue( (grid.GetLines('y')==np.array([-2., 0., 1., 2., 4., 5.])).all() ) 34 | self.assertEqual( grid.GetQtyLines('y'), 6 ) 35 | 36 | grid.SetLines('z', [10, 11, 12]) 37 | 38 | self.assertEqual( grid.GetLine('y', 1), 0.0 ) 39 | 40 | self.assertEqual( grid.GetQtyLines('x'), 3 ) 41 | 42 | grid.SetDeltaUnit(1e-3) 43 | self.assertEqual( grid.GetDeltaUnit(), 1e-3 ) 44 | 45 | self.assertTrue( grid.IsValid() ) 46 | 47 | # check grid snapping 48 | self.assertEqual( grid.Snap2LineNumber('y', 1), (2,True) ) 49 | self.assertEqual( grid.Snap2LineNumber('y', 1.1), (2,True) ) 50 | self.assertEqual( grid.Snap2LineNumber('y', 1.5), (3,True) ) 51 | self.assertEqual( grid.Snap2LineNumber('y', 1.6), (3,True) ) 52 | self.assertEqual( grid.Snap2LineNumber('y', 5.0), (5,True) ) 53 | self.assertEqual( grid.Snap2LineNumber('y', 5.01), (5,False) ) 54 | 55 | self.assertEqual( grid.Snap2LineNumber('y', -2.0), (0,True) ) 56 | self.assertEqual( grid.Snap2LineNumber('y', -2.01), (0,False) ) 57 | 58 | self.assertTrue( (grid.GetSimArea() == np.array([[0, -2, 10],[2, 5, 12]])).all() ) 59 | 60 | grid.ClearLines('x') 61 | self.assertEqual( grid.GetQtyLines('x'), 0 ) 62 | self.assertEqual( grid.GetQtyLines('y'), 6 ) 63 | self.assertEqual( grid.GetQtyLines('z'), 3 ) 64 | 65 | self.assertFalse( grid.IsValid() ) 66 | 67 | grid.Clear() 68 | self.assertEqual( grid.GetQtyLines('y'), 0 ) 69 | 70 | self.assertFalse( grid.IsValid() ) 71 | 72 | if __name__ == '__main__': 73 | unittest.main() -------------------------------------------------------------------------------- /python/tests/test_CSTransform.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Sep 2 21:42:50 2016 4 | 5 | @author: thorsten 6 | """ 7 | 8 | from CSXCAD import CSTransform 9 | import numpy as np 10 | 11 | import unittest 12 | 13 | def compare_coords(c1, c2): 14 | c1 = np.array(c1) 15 | c2 = np.array(c2) 16 | return np.sum(np.abs(c1-c2))<1e-6 17 | 18 | 19 | class Test_CSTransform(unittest.TestCase): 20 | def setUp(self): 21 | self.tr = CSTransform.CSTransform() 22 | 23 | def test_basics(self): 24 | identity = np.identity(4) 25 | 26 | self.assertFalse( self.tr.HasTransform() ) 27 | self.assertTrue( (self.tr.GetMatrix()==identity).all() ) 28 | 29 | self.tr.Translate([1,2,1]) 30 | self.assertTrue( self.tr.HasTransform() ) 31 | self.assertFalse((self.tr.GetMatrix()==identity).all() ) 32 | 33 | self.tr.Reset() 34 | self.assertFalse( self.tr.HasTransform() ) 35 | self.assertTrue( (self.tr.GetMatrix()==identity).all() ) 36 | 37 | def test_translate(self): 38 | test_pnt = np.array([1,1,1])/np.sqrt(3) 39 | 40 | self.tr.Translate([1,2,1]) 41 | translate = np.identity(4) 42 | translate[:3,3] = [1,2,1] 43 | self.assertTrue( (self.tr.GetMatrix()==translate).all() ) 44 | 45 | self.assertTrue( compare_coords(self.tr.Transform(test_pnt), [ 1.57735027, 2.57735027, 1.57735027]) ) 46 | 47 | def test_rotate(self): 48 | self.tr.RotateAxis('x', 45) 49 | self.assertTrue( compare_coords(self.tr.Transform([0,np.sqrt(2),0]), [0, 1, 1]) ) 50 | 51 | self.tr.Reset() 52 | self.tr.RotateAxis('x', -45) 53 | self.assertTrue( compare_coords(self.tr.Transform([0,np.sqrt(2),0]), [0, 1, -1]) ) 54 | 55 | self.tr.Reset() 56 | self.tr.RotateAxis('z', -90) 57 | self.assertTrue( compare_coords(self.tr.Transform([1,0,0]), [0, -1, 0]) ) 58 | self.tr.RotateOrigin([0,0,1], 90) 59 | self.assertTrue( compare_coords(self.tr.Transform([1,0,0]), [1, 0, 0]) ) 60 | 61 | self.tr.Reset() 62 | self.tr.RotateOrigin([0,1,1], 90) 63 | self.assertTrue( compare_coords(self.tr.Transform([1,0,0]), [0, 1/np.sqrt(2), -1/np.sqrt(2)]) ) 64 | 65 | def test_scale(self): 66 | self.tr.Scale(3) 67 | self.assertTrue( compare_coords(self.tr.Transform([1,0,0]), [3, 0, 0]) ) 68 | 69 | self.tr.Reset() 70 | self.tr.Scale([1,2,3]) 71 | self.assertTrue( compare_coords(self.tr.Transform([1,1,1]), [1, 2, 3]) ) 72 | 73 | def test_matrix(self): 74 | self.tr.RotateOrigin([1,1,1], 90) 75 | mat = self.tr.GetMatrix() 76 | self.tr.Reset() 77 | self.tr.SetMatrix(mat) 78 | self.assertTrue( (self.tr.GetMatrix()==mat).all() ) 79 | 80 | if __name__ == '__main__': 81 | unittest.main() 82 | -------------------------------------------------------------------------------- /python/tests/test_CSXCAD.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Dec 4 16:24:49 2015 4 | 5 | @author: thorsten 6 | """ 7 | 8 | import numpy as np 9 | 10 | from CSXCAD.CSXCAD import ContinuousStructure 11 | from CSXCAD import CSProperties 12 | 13 | from CSXCAD.CSProperties import CSPropMetal 14 | from CSXCAD import CSPrimitives 15 | csx = ContinuousStructure() 16 | pset = csx.GetParameterSet() 17 | grid = csx.GetGrid() 18 | 19 | ##### Test Metal Prop 20 | metal = CSPropMetal(pset) 21 | assert metal.GetQtyPrimitives() == 0 22 | assert metal.GetTypeString()=='Metal' 23 | 24 | metal.SetName('metal') 25 | assert metal.GetName()=='metal' 26 | 27 | 28 | print(csx.GetQtyPrimitives(0)) 29 | metal.AddBox([0,0,0], [1,1,1]) 30 | 31 | ans = csx.AddProperty(metal) 32 | 33 | print(csx.GetQtyPrimitives(CSProperties.ANY)) 34 | print(csx.GetQtyPrimitives(CSProperties.METAL)) 35 | metal2 = csx.AddMetal('test') 36 | assert metal2.GetName()=='test' 37 | 38 | ##### Test Excitation Prop 39 | exc_val = np.array([0,1,0]) 40 | exc = csx.AddExcitation('excite', 0, exc_val) 41 | assert exc.GetName()=='excite' 42 | assert exc.GetExcitType() == 0 43 | assert (exc.GetExcitation()==exc_val).all() 44 | 45 | csx.Write2XML('test_CSXCAD.xml') 46 | 47 | del metal 48 | 49 | print("all ok") -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set( PUB_HEADERS 3 | ContinuousStructure.h 4 | CSPrimitives.h 5 | CSProperties.h 6 | CSRectGrid.h 7 | CSXCAD_Global.h 8 | ParameterObjects.h 9 | CSFunctionParser.h 10 | CSUseful.h 11 | ParameterCoord.h 12 | CSTransform.h 13 | CSBackgroundMaterial.h 14 | CSPrimPoint.h 15 | CSPrimBox.h 16 | CSPrimMultiBox.h 17 | CSPrimSphere.h 18 | CSPrimSphericalShell.h 19 | CSPrimCylinder.h 20 | CSPrimCylindricalShell.h 21 | CSPrimPolygon.h 22 | CSPrimLinPoly.h 23 | CSPrimRotPoly.h 24 | CSPrimPolyhedron.h 25 | CSPrimPolyhedronReader.h 26 | CSPrimCurve.h 27 | CSPrimWire.h 28 | CSPrimUserDefined.h 29 | CSPropUnknown.h 30 | CSPropMaterial.h 31 | CSPropDispersiveMaterial.h 32 | CSPropLorentzMaterial.h 33 | CSPropDebyeMaterial.h 34 | CSPropDiscMaterial.h 35 | CSPropLumpedElement.h 36 | CSPropMetal.h 37 | CSPropConductingSheet.h 38 | CSPropExcitation.h 39 | CSPropProbeBox.h 40 | CSPropDumpBox.h 41 | CSPropResBox.h 42 | ) 43 | 44 | set(SOURCES 45 | ContinuousStructure.cpp 46 | CSPrimitives.cpp 47 | CSProperties.cpp 48 | CSRectGrid.cpp 49 | ParameterObjects.cpp 50 | CSFunctionParser.cpp 51 | CSUseful.cpp 52 | ParameterCoord.cpp 53 | CSTransform.cpp 54 | CSPrimPoint.cpp 55 | CSPrimBox.cpp 56 | CSPrimMultiBox.cpp 57 | CSPrimSphere.cpp 58 | CSPrimSphericalShell.cpp 59 | CSPrimCylinder.cpp 60 | CSPrimCylindricalShell.cpp 61 | CSPrimPolygon.cpp 62 | CSPrimLinPoly.cpp 63 | CSPrimRotPoly.cpp 64 | CSPrimPolyhedron.cpp 65 | CSPrimPolyhedronReader.cpp 66 | CSPrimCurve.cpp 67 | CSPrimWire.cpp 68 | CSPrimUserDefined.cpp 69 | CSPropUnknown.cpp 70 | CSPropMaterial.cpp 71 | CSPropDispersiveMaterial.cpp 72 | CSPropLorentzMaterial.cpp 73 | CSPropDebyeMaterial.cpp 74 | CSPropDiscMaterial.cpp 75 | CSPropLumpedElement.cpp 76 | CSPropMetal.cpp 77 | CSPropConductingSheet.cpp 78 | CSPropExcitation.cpp 79 | CSPropProbeBox.cpp 80 | CSPropDumpBox.cpp 81 | CSPropResBox.cpp 82 | CSBackgroundMaterial.cpp 83 | ) 84 | 85 | # CSXCAD library 86 | add_library( CSXCAD SHARED ${SOURCES} ) 87 | 88 | TARGET_LINK_LIBRARIES( CSXCAD 89 | ${fparser_LIBRARIES} 90 | ${TinyXML_LIBRARIES} 91 | ${HDF5_LIBRARIES} 92 | ${HDF5_HL_LIBRARIES} 93 | CGAL 94 | ${Boost_LIBRARIES} 95 | ${vtk_LIBS} 96 | ) 97 | 98 | set_target_properties(CSXCAD PROPERTIES VERSION ${LIB_VERSION_STRING} 99 | SOVERSION ${LIB_VERSION_MAJOR}) 100 | 101 | INSTALL(TARGETS CSXCAD DESTINATION lib${LIB_SUFFIX}) 102 | 103 | INSTALL(FILES ${PUB_HEADERS} DESTINATION include/CSXCAD) 104 | 105 | 106 | -------------------------------------------------------------------------------- /src/CSBackgroundMaterial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "CSBackgroundMaterial.h" 19 | 20 | #include "tinyxml.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | CSBackgroundMaterial::CSBackgroundMaterial() 27 | { 28 | // init material 29 | Reset(); 30 | } 31 | 32 | void CSBackgroundMaterial::Reset() 33 | { 34 | SetEpsilon(1); 35 | SetMue(1); 36 | SetKappa(0); 37 | SetSigma(0); 38 | } 39 | 40 | void CSBackgroundMaterial::SetEpsilon(double val) 41 | { 42 | if (val<1) 43 | { 44 | std::cerr << __func__ << ": Error, a relative electric permittivity smaller 1 is not allowed! Skipping. " << std::endl; 45 | return; 46 | } 47 | m_epsR=val; 48 | } 49 | 50 | void CSBackgroundMaterial::SetMue(double val) 51 | { 52 | if (val<1) 53 | { 54 | std::cerr << __func__ << ": Error, a relative magnetic permeability smaller 1 is not allowed! Skipping. " << std::endl; 55 | return; 56 | } 57 | m_mueR=val; 58 | } 59 | 60 | void CSBackgroundMaterial::SetKappa(double val) 61 | { 62 | if (val<0) 63 | { 64 | std::cerr << __func__ << ": Error, a negative electric conductivity is not allowed! Skipping. " << std::endl; 65 | return; 66 | } 67 | m_kappa=val; 68 | } 69 | 70 | void CSBackgroundMaterial::SetSigma(double val) 71 | { 72 | if (val<0) 73 | { 74 | std::cerr << __func__ << ": Error, a negative (artificial) magnetic conductivity is not allowed! Skipping. " << std::endl; 75 | return; 76 | } 77 | m_sigma=val; 78 | } 79 | 80 | bool CSBackgroundMaterial::Write2XML(TiXmlNode& root, bool parameterised, bool sparse) 81 | { 82 | UNUSED(parameterised); 83 | UNUSED(sparse); 84 | TiXmlElement bg_elem("BackgroundMaterial"); 85 | 86 | bg_elem.SetDoubleAttribute("Epsilon", GetEpsilon()); 87 | bg_elem.SetDoubleAttribute("Mue", GetMue()); 88 | bg_elem.SetDoubleAttribute("Kappa", GetKappa()); 89 | bg_elem.SetDoubleAttribute("Sigma", GetSigma()); 90 | 91 | root.InsertEndChild(bg_elem); 92 | 93 | return true; 94 | } 95 | 96 | bool CSBackgroundMaterial::ReadFromXML(TiXmlNode &root) 97 | { 98 | Reset(); 99 | TiXmlElement* rootElem=root.ToElement(); 100 | 101 | if (rootElem==NULL) 102 | return false; 103 | 104 | double val; 105 | if (rootElem->QueryDoubleAttribute("Epsilon",&val) == TIXML_SUCCESS) 106 | SetEpsilon(val); 107 | if (rootElem->QueryDoubleAttribute("Mue",&val) == TIXML_SUCCESS) 108 | SetMue(val); 109 | if (rootElem->QueryDoubleAttribute("Kappa",&val) == TIXML_SUCCESS) 110 | SetKappa(val); 111 | if (rootElem->QueryDoubleAttribute("Sigma",&val) == TIXML_SUCCESS) 112 | SetSigma(val); 113 | 114 | return true; 115 | } 116 | -------------------------------------------------------------------------------- /src/CSBackgroundMaterial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef CSBACKGROUNDMATERIAL_H 19 | #define CSBACKGROUNDMATERIAL_H 20 | 21 | #include "CSXCAD_Global.h" 22 | 23 | class TiXmlNode; 24 | 25 | class CSBackgroundMaterial 26 | { 27 | public: 28 | CSBackgroundMaterial(); 29 | 30 | //! Get the rel. electric permittivity 31 | double GetEpsilon() const {return m_epsR;} 32 | //! Set the rel. electric permittivity 33 | void SetEpsilon(double val); 34 | 35 | //! Get the rel. magnetic permeability 36 | double GetMue() const {return m_mueR;} 37 | //! Set the rel. magnetic permeability 38 | void SetMue(double val); 39 | 40 | //! Get the electric conductivity 41 | double GetKappa() const {return m_kappa;} 42 | //! Set the electric conductivity 43 | void SetKappa(double val); 44 | 45 | //! Get the (artificial) magnetic conductivity 46 | double GetSigma() const {return m_sigma;} 47 | //! Set the (artificial) magnetic conductivity 48 | void SetSigma(double val); 49 | 50 | //! Reset all values to default 51 | void Reset(); 52 | 53 | virtual bool Write2XML(TiXmlNode& root, bool parameterised=true, bool sparse=false); 54 | virtual bool ReadFromXML(TiXmlNode &root); 55 | 56 | protected: 57 | double m_epsR; 58 | double m_mueR; 59 | double m_kappa; 60 | double m_sigma; 61 | }; 62 | 63 | #endif // CSBACKGROUNDMATERIAL_H 64 | -------------------------------------------------------------------------------- /src/CSFunctionParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010,2011 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "CSFunctionParser.h" 19 | #include 20 | #include 21 | 22 | double bessel_first_kind_0(const double* p) 23 | { 24 | return j0(p[0]); 25 | } 26 | double bessel_first_kind_1(const double* p) 27 | { 28 | return j1(p[0]); 29 | } 30 | double bessel_first_kind_n(const double* p) 31 | { 32 | int n=p[0]; 33 | if (n<0) 34 | { 35 | std::cerr << "CSFunctionParser::bessel_first_kind_n (jn): first argument must be integer larger than zero! found: " << p[0] << std::endl; 36 | return 0; 37 | } 38 | return jn(n,p[1]); 39 | } 40 | 41 | double bessel_second_kind_0(const double* p) 42 | { 43 | return y0(p[0]); 44 | } 45 | double bessel_second_kind_1(const double* p) 46 | { 47 | return y1(p[0]); 48 | } 49 | double bessel_second_kind_n(const double* p) 50 | { 51 | int n=p[0]; 52 | if (n<0) 53 | { 54 | std::cerr << "CSFunctionParser::bessel_second_kind_n (yn): first argument must be integer larger than zero! found: " << p[0] << std::endl; 55 | return 0; 56 | } 57 | return yn(n,p[1]); 58 | } 59 | 60 | 61 | CSFunctionParser::CSFunctionParser() 62 | { 63 | setlocale(LC_NUMERIC, "en_US.UTF-8"); 64 | 65 | //some usefull constants 66 | AddConstant("pi", 3.14159265358979323846); 67 | AddConstant("e", 2.71828182845904523536); 68 | 69 | //some bessel functions of first kind 70 | AddFunction("j0",bessel_first_kind_0,1); 71 | AddFunction("j1",bessel_first_kind_1,1); 72 | AddFunction("jn",bessel_first_kind_n,2); 73 | 74 | //some bessel functions of second kind 75 | AddFunction("y0",bessel_second_kind_0,1); 76 | AddFunction("y1",bessel_second_kind_1,1); 77 | AddFunction("yn",bessel_second_kind_n,2); 78 | } 79 | -------------------------------------------------------------------------------- /src/CSFunctionParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010,2011 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef CSFUNCTIONPARSER_H 19 | #define CSFUNCTIONPARSER_H 20 | 21 | #include "CSXCAD_Global.h" 22 | #include "fparser.hh" 23 | 24 | //! Extended FunctionParser using some additional constants (pi,e) and functions 25 | /*! 26 | This is an extended FunctionParser with the additional constants, "pi" and "e", as well as severel bessel functions of first (j0, j1, jn) and second kind (y0, y1, yn). 27 | */ 28 | class CSXCAD_EXPORT CSFunctionParser : public FunctionParser 29 | { 30 | public: 31 | CSFunctionParser(); 32 | }; 33 | 34 | #endif // CSFUNCTIONPARSER_H 35 | -------------------------------------------------------------------------------- /src/CSPrimBox.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | 22 | //! Box Primitive (Cube) 23 | /*! 24 | This is a cube primitive defined by its start-, end-coordinates. 25 | */ 26 | class CSXCAD_EXPORT CSPrimBox : public CSPrimitives 27 | { 28 | public: 29 | CSPrimBox(ParameterSet* paraSet, CSProperties* prop); 30 | CSPrimBox(CSPrimBox* primBox, CSProperties *prop=NULL); 31 | CSPrimBox(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 32 | virtual ~CSPrimBox(); 33 | 34 | virtual CSPrimitives* GetCopy(CSProperties *prop=NULL) {return new CSPrimBox(this,prop);} 35 | 36 | void SetCoord(int index, double val); 37 | void SetCoord(int index, const char* val); 38 | void SetCoord(int index, std::string val); 39 | 40 | double GetCoord(int index) {if ((index>=0) && (index<6)) return m_Coords[index%2].GetValue(index/2); else return 0;} 41 | ParameterScalar* GetCoordPS(int index) {if ((index>=0) && (index<6)) return m_Coords[index%2].GetCoordPS(index/2); else return NULL;} 42 | 43 | ParameterCoord* GetStartCoord() {return &m_Coords[0];} 44 | ParameterCoord* GetStopCoord() {return &m_Coords[1];} 45 | 46 | virtual bool GetBoundBox(double dBoundBox[6], bool PreserveOrientation=false); 47 | virtual bool IsInside(const double* Coord, double tol=0); 48 | 49 | virtual bool Update(std::string *ErrStr=NULL); 50 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 51 | virtual bool ReadFromXML(TiXmlNode &root); 52 | 53 | virtual void ShowPrimitiveStatus(std::ostream& stream); 54 | 55 | protected: 56 | //start and stop coords defining the box 57 | ParameterCoord m_Coords[2]; 58 | }; 59 | 60 | -------------------------------------------------------------------------------- /src/CSPrimCurve.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | 22 | //! Curve Primitive (Polygonal chain) 23 | /*! 24 | This is a curve primitive defined by a number of 3D points 25 | */ 26 | class CSXCAD_EXPORT CSPrimCurve : public CSPrimitives 27 | { 28 | public: 29 | CSPrimCurve(ParameterSet* paraSet, CSProperties* prop); 30 | CSPrimCurve(CSPrimCurve* primCurve, CSProperties *prop=NULL); 31 | CSPrimCurve(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 32 | virtual ~CSPrimCurve(); 33 | 34 | virtual CSPrimitives* GetCopy(CSProperties *prop=NULL) {return new CSPrimCurve(this,prop);} 35 | 36 | virtual size_t AddPoint(double coords[]); 37 | virtual void SetCoord(size_t point_index, int nu, double val); 38 | virtual void SetCoord(size_t point_index, int nu, std::string val); 39 | 40 | virtual size_t GetNumberOfPoints() {return points.size();} 41 | virtual bool GetPoint(size_t point_index, double point[3]); 42 | //! Get the point coordinates for the given index in the specified coordinate system 43 | virtual bool GetPoint(size_t point_index, double* point, CoordinateSystem c_system, bool transform=true); 44 | 45 | virtual void ClearPoints(); 46 | 47 | virtual bool GetBoundBox(double dBoundBox[6], bool PreserveOrientation=false); 48 | virtual bool IsInside(const double* Coord, double tol=0); 49 | 50 | virtual bool Update(std::string *ErrStr=NULL); 51 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 52 | virtual bool ReadFromXML(TiXmlNode &root); 53 | 54 | protected: 55 | std::vector points; 56 | }; 57 | -------------------------------------------------------------------------------- /src/CSPrimCylinder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | 22 | #define PI 3.141592653589793238462643383279 23 | 24 | void NormalizeVector(double *vec); 25 | 26 | //! Cylinder Primitive 27 | /*! 28 | This is a cylindrical primitive defined by its axis start-, end-coordinates and a radius. 29 | */ 30 | class CSXCAD_EXPORT CSPrimCylinder : public CSPrimitives 31 | { 32 | public: 33 | CSPrimCylinder(ParameterSet* paraSet, CSProperties* prop); 34 | CSPrimCylinder(CSPrimCylinder* cylinder, CSProperties *prop=NULL); 35 | CSPrimCylinder(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 36 | virtual ~CSPrimCylinder(); 37 | 38 | virtual CSPrimitives* GetCopy(CSProperties *prop=NULL) {return new CSPrimCylinder(this,prop);} 39 | 40 | void SetCoord(int index, double val); 41 | void SetCoord(int index, const char* val); 42 | void SetCoord(int index, std::string val); 43 | 44 | double GetCoord(int index) {if ((index>=0) && (index<6)) return m_AxisCoords[index%2].GetValue(index/2); else return 0;} 45 | ParameterScalar* GetCoordPS(int index) {if ((index>=0) && (index<6)) return m_AxisCoords[index%2].GetCoordPS(index/2); else return NULL;} 46 | 47 | ParameterCoord* GetAxisStartCoord() {return &m_AxisCoords[0];} 48 | ParameterCoord* GetAxisStopCoord() {return &m_AxisCoords[1];} 49 | 50 | void SetRadius(double val); 51 | void SetRadius(const char* val); 52 | 53 | double GetRadius() {return psRadius.GetValue();} 54 | ParameterScalar* GetRadiusPS() {return &psRadius;} 55 | 56 | virtual bool GetBoundBox(double dBoundBox[6], bool PreserveOrientation=false); 57 | virtual bool IsInside(const double* Coord, double tol=0); 58 | 59 | virtual bool Update(std::string *ErrStr=NULL); 60 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 61 | virtual bool ReadFromXML(TiXmlNode &root); 62 | 63 | virtual void ShowPrimitiveStatus(std::ostream& stream); 64 | 65 | protected: 66 | ParameterCoord m_AxisCoords[2]; 67 | ParameterScalar psRadius; 68 | virtual double GetBBRadius() {return psRadius.GetValue();} // Get the radius for the bounding box calculation 69 | }; 70 | -------------------------------------------------------------------------------- /src/CSPrimCylindricalShell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | #include "CSPrimCylinder.h" 22 | 23 | //! CylindicalShell Primitive 24 | /*! 25 | This is a cylindrical shell primitive derived from the cylinder primitive, adding a shell width which is centered around the cylinder radius. 26 | \sa CSPrimCylinder 27 | */ 28 | class CSXCAD_EXPORT CSPrimCylindricalShell : public CSPrimCylinder 29 | { 30 | public: 31 | CSPrimCylindricalShell(ParameterSet* paraSet, CSProperties* prop); 32 | CSPrimCylindricalShell(CSPrimCylindricalShell* cylinder, CSProperties *prop=NULL); 33 | CSPrimCylindricalShell(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 34 | virtual ~CSPrimCylindricalShell(); 35 | 36 | virtual CSPrimitives* GetCopy(CSProperties *prop=NULL) {return new CSPrimCylindricalShell(this,prop);} 37 | 38 | void SetShellWidth(double val) {psShellWidth.SetValue(val);} 39 | void SetShellWidth(const char* val) {psShellWidth.SetValue(val);} 40 | 41 | double GetShellWidth() {return psShellWidth.GetValue();} 42 | ParameterScalar* GetShellWidthPS() {return &psShellWidth;} 43 | 44 | virtual bool IsInside(const double* Coord, double tol=0); 45 | 46 | virtual bool Update(std::string *ErrStr=NULL); 47 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 48 | virtual bool ReadFromXML(TiXmlNode &root); 49 | 50 | virtual void ShowPrimitiveStatus(std::ostream& stream); 51 | 52 | protected: 53 | ParameterScalar psShellWidth; 54 | virtual double GetBBRadius() {return psRadius.GetValue()+psShellWidth.GetValue()/2.0;} // Get the radius for the bounding box calculation 55 | }; 56 | 57 | -------------------------------------------------------------------------------- /src/CSPrimLinPoly.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | #include "CSPrimPolygon.h" 22 | 23 | //! Linear extruded polygon Primitive 24 | /*! 25 | This is a linear extruded area polygon primitive defined by a number of points in space and an extrude vector. 26 | Warning: This primitive currently can only be defined in Cartesian coordinates. 27 | */ 28 | class CSXCAD_EXPORT CSPrimLinPoly : public CSPrimPolygon 29 | { 30 | public: 31 | CSPrimLinPoly(ParameterSet* paraSet, CSProperties* prop); 32 | CSPrimLinPoly(CSPrimLinPoly* primPolygon, CSProperties *prop=NULL); 33 | CSPrimLinPoly(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 34 | virtual ~CSPrimLinPoly(); 35 | 36 | virtual CSPrimLinPoly* GetCopy(CSProperties *prop=NULL) {return new CSPrimLinPoly(this,prop);} 37 | 38 | void SetLength(double val); 39 | void SetLength(const std::string val); 40 | 41 | double GetLength() {return extrudeLength.GetValue();} 42 | ParameterScalar* GetLengthPS() {return &extrudeLength;} 43 | 44 | virtual bool GetBoundBox(double dBoundBox[6], bool PreserveOrientation=false); 45 | virtual bool IsInside(const double* Coord, double tol=0); 46 | 47 | virtual bool Update(std::string *ErrStr=NULL); 48 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 49 | virtual bool ReadFromXML(TiXmlNode &root); 50 | 51 | protected: 52 | ParameterScalar extrudeLength; 53 | }; 54 | -------------------------------------------------------------------------------- /src/CSPrimMultiBox.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | 22 | //! Multi-Box Primitive (Multi-Cube) 23 | /*! 24 | This is a primitive defined by multiple cubes. Mostly used for already discretized objects. 25 | */ 26 | class CSXCAD_EXPORT CSPrimMultiBox : public CSPrimitives 27 | { 28 | public: 29 | CSPrimMultiBox(ParameterSet* paraSet, CSProperties* prop); 30 | CSPrimMultiBox(CSPrimMultiBox* multiBox,CSProperties *prop=NULL); 31 | CSPrimMultiBox(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 32 | virtual ~CSPrimMultiBox(); 33 | 34 | virtual CSPrimitives* GetCopy(CSProperties *prop=NULL); 35 | 36 | void SetCoord(int index, double val); 37 | void SetCoord(int index, const char* val); 38 | 39 | void AddCoord(double val); 40 | void AddCoord(const char* val); 41 | 42 | void AddBox(int initBox=-1); 43 | void DeleteBox(size_t box); 44 | 45 | double GetCoord(int index); 46 | ParameterScalar* GetCoordPS(int index); 47 | 48 | double* GetAllCoords(size_t &Qty, double* array); 49 | 50 | void ClearOverlap(); 51 | 52 | virtual bool GetBoundBox(double dBoundBox[6], bool PreserveOrientation=false); 53 | virtual bool IsInside(const double* Coord, double tol=0); 54 | 55 | unsigned int GetQtyBoxes(); 56 | 57 | virtual bool Update(std::string *ErrStr=NULL); 58 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 59 | virtual bool ReadFromXML(TiXmlNode &root); 60 | 61 | protected: 62 | std::vector vCoords; 63 | }; 64 | 65 | -------------------------------------------------------------------------------- /src/CSPrimPoint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | 22 | //! Point Primitive 23 | /*! 24 | This is a point primitive (useful for field probes). 25 | */ 26 | class CSXCAD_EXPORT CSPrimPoint : public CSPrimitives 27 | { 28 | public: 29 | CSPrimPoint(ParameterSet* paraSet, CSProperties* prop); 30 | CSPrimPoint(CSPrimPoint* primPoint, CSProperties *prop=NULL); 31 | CSPrimPoint(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 32 | virtual ~CSPrimPoint(); 33 | 34 | virtual CSPrimPoint* GetCopy(CSProperties *prop=NULL) {return new CSPrimPoint(this,prop);} 35 | 36 | void SetCoord(int index, double val); 37 | void SetCoord(int index, const std::string val); 38 | void SetCoords( double c1, double c2, double c3 ); 39 | 40 | //! Get the point coordinates according to the input mesh type 41 | double GetCoord(int index); 42 | ParameterScalar* GetCoordPS(int index); 43 | 44 | const ParameterCoord* GetCoords() const {return &m_Coords;} 45 | 46 | virtual bool GetBoundBox(double dBoundBox[6], bool PreserveOrientation=false); 47 | virtual bool IsInside(const double* Coord, double tol=0); 48 | 49 | virtual bool Update(std::string *ErrStr=NULL); 50 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 51 | virtual bool ReadFromXML(TiXmlNode &root); 52 | 53 | virtual void ShowPrimitiveStatus(std::ostream& stream); 54 | 55 | protected: 56 | //! Vector describing the point: x,y,z 57 | ParameterCoord m_Coords; 58 | }; 59 | 60 | -------------------------------------------------------------------------------- /src/CSPrimPolygon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | 22 | //! 2D Polygon Primitive 23 | /*! 24 | This is an area polygon primitive defined by a number of points in space. 25 | Warning: This primitive currently can only be defined in Cartesian coordinates. 26 | */ 27 | class CSXCAD_EXPORT CSPrimPolygon : public CSPrimitives 28 | { 29 | public: 30 | CSPrimPolygon(ParameterSet* paraSet, CSProperties* prop); 31 | CSPrimPolygon(CSPrimPolygon* primPolygon, CSProperties *prop=NULL); 32 | CSPrimPolygon(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 33 | virtual ~CSPrimPolygon(); 34 | 35 | virtual CSPrimPolygon* GetCopy(CSProperties *prop=NULL); 36 | 37 | void SetCoord(int index, double val); 38 | void SetCoord(int index, const std::string val); 39 | 40 | void AddCoord(double val); 41 | void AddCoord(const std::string val); 42 | 43 | void RemoveCoords(int index); 44 | void ClearCoords() {vCoords.clear();} 45 | 46 | double GetCoord(int index); 47 | ParameterScalar* GetCoordPS(int index); 48 | 49 | size_t GetQtyCoords(); 50 | double* GetAllCoords(size_t &Qty, double* array); 51 | 52 | void SetNormDir(int dir); 53 | 54 | int GetNormDir() {return m_NormDir;} 55 | 56 | void SetElevation(double val) {Elevation.SetValue(val);} 57 | void SetElevation(const char* val) {Elevation.SetValue(val);} 58 | 59 | double GetElevation() {return Elevation.GetValue();} 60 | ParameterScalar* GetElevationPS() {return &Elevation;} 61 | 62 | virtual bool GetBoundBox(double dBoundBox[6], bool PreserveOrientation=false); 63 | virtual bool IsInside(const double* Coord, double tol=0); 64 | 65 | virtual bool Update(std::string *ErrStr=NULL); 66 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 67 | virtual bool ReadFromXML(TiXmlNode &root); 68 | 69 | protected: 70 | ///Vector describing the polygon, x1,y1,x2,y2 ... xn,yn 71 | std::vector vCoords; 72 | ///The polygon plane normal direction 73 | int m_NormDir; 74 | ///The polygon plane elevation in direction of the normal vector 75 | ParameterScalar Elevation; 76 | }; 77 | 78 | -------------------------------------------------------------------------------- /src/CSPrimPolyhedron.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | 22 | struct CSPrimPolyhedronPrivate; 23 | 24 | //! Polyhedron Primitive 25 | /*! 26 | This is a polyhedron primitive. A 3D solid object, defined by vertices and faces 27 | */ 28 | class CSXCAD_EXPORT CSPrimPolyhedron : public CSPrimitives 29 | { 30 | friend class Polyhedron_Builder; 31 | public: 32 | struct face 33 | { 34 | unsigned int numVertex; 35 | int* vertices; 36 | bool valid; 37 | }; 38 | struct vertex 39 | { 40 | float coord[3]; 41 | }; 42 | 43 | CSPrimPolyhedron(ParameterSet* paraSet, CSProperties* prop); 44 | CSPrimPolyhedron(CSPrimPolyhedron* primPolyhedron, CSProperties *prop=NULL); 45 | CSPrimPolyhedron(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 46 | virtual ~CSPrimPolyhedron(); 47 | 48 | virtual void Reset(); 49 | 50 | virtual void AddVertex(float p[3]) {AddVertex(p[0],p[1],p[2]);} 51 | virtual void AddVertex(double p[3]) {AddVertex(p[0],p[1],p[2]);} 52 | virtual void AddVertex(float px, float py, float pz); 53 | 54 | virtual unsigned int GetNumVertices() const {return m_Vertices.size();} 55 | virtual float* GetVertex(unsigned int n); 56 | 57 | virtual void AddFace(face f); 58 | virtual void AddFace(int numVertex, int* vertices); 59 | virtual void AddFace(std::vector vertices); 60 | 61 | virtual bool BuildTree(); 62 | 63 | virtual unsigned int GetNumFaces() const {return m_Faces.size();} 64 | virtual int* GetFace(unsigned int n, unsigned int &numVertices); 65 | virtual bool GetFaceValid(unsigned int n) const {return m_Faces.at(n).valid;} 66 | 67 | virtual CSPrimPolyhedron* GetCopy(CSProperties *prop=NULL) {return new CSPrimPolyhedron(this,prop);} 68 | 69 | virtual bool GetBoundBox(double dBoundBox[6], bool PreserveOrientation=false); 70 | virtual bool IsInside(const double* Coord, double tol=0); 71 | 72 | virtual bool Update(std::string *ErrStr=NULL); 73 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 74 | virtual bool ReadFromXML(TiXmlNode &root); 75 | 76 | virtual void ShowPrimitiveStatus(std::ostream& stream); 77 | 78 | protected: 79 | unsigned int m_InvalidFaces; 80 | virtual void Invalidate(); 81 | std::vector m_Vertices; 82 | std::vector m_Faces; 83 | CSPrimPolyhedronPrivate *d_ptr; //!< pointer to private data structure, to hide the CGAL dependency from applications 84 | }; 85 | -------------------------------------------------------------------------------- /src/CSPrimPolyhedronReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | #include "CSPrimPolyhedron.h" 22 | 23 | //! STL/PLY import primitive 24 | class CSXCAD_EXPORT CSPrimPolyhedronReader : public CSPrimPolyhedron 25 | { 26 | public: 27 | //! Import file type 28 | enum FileType 29 | { 30 | UNKNOWN, STL_FILE, PLY_FILE 31 | }; 32 | 33 | CSPrimPolyhedronReader(ParameterSet* paraSet, CSProperties* prop); 34 | CSPrimPolyhedronReader(CSPrimPolyhedronReader* primPHReader, CSProperties *prop=NULL); 35 | CSPrimPolyhedronReader(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 36 | virtual ~CSPrimPolyhedronReader(); 37 | 38 | virtual CSPrimPolyhedronReader* GetCopy(CSProperties *prop=NULL) {return new CSPrimPolyhedronReader(this,prop);} 39 | 40 | virtual void SetFilename(std::string name) {m_filename=name;} 41 | virtual std::string GetFilename() const {return m_filename;} 42 | 43 | virtual void SetFileType(FileType ft) {m_filetype=ft;} 44 | virtual FileType GetFileType() const {return m_filetype;} 45 | 46 | virtual bool Update(std::string *ErrStr=NULL); 47 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 48 | virtual bool ReadFromXML(TiXmlNode &root); 49 | 50 | virtual bool ReadFile(); 51 | 52 | protected: 53 | std::string m_filename; 54 | FileType m_filetype; 55 | }; 56 | -------------------------------------------------------------------------------- /src/CSPrimPolyhedron_p.h: -------------------------------------------------------------------------------- 1 | #ifndef CSPRIMPOLYHEDRON_P_H 2 | #define CSPRIMPOLYHEDRON_P_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #if CGAL_VERSION_NR >= CGAL_VERSION_NUMBER(4,6,0) 10 | #include 11 | #else 12 | #include 13 | #include 14 | #endif 15 | 16 | typedef CGAL::Simple_cartesian Kernel; 17 | typedef CGAL::Polyhedron_3 Polyhedron; 18 | typedef Polyhedron::HalfedgeDS HalfedgeDS; 19 | 20 | class Polyhedron_Builder : public CGAL::Modifier_base 21 | { 22 | public: 23 | Polyhedron_Builder(CSPrimPolyhedron* polyhedron) {m_polyhedron=polyhedron;} 24 | void operator()(HalfedgeDS &hds); 25 | 26 | protected: 27 | CSPrimPolyhedron* m_polyhedron; 28 | }; 29 | 30 | typedef Kernel::Point_3 Point; 31 | #if CGAL_VERSION_NR >= CGAL_VERSION_NUMBER(4,6,0) 32 | typedef CGAL::AABB_face_graph_triangle_primitive Primitive; 33 | #else 34 | typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; 35 | #endif 36 | typedef CGAL::AABB_traits Traits; 37 | typedef CGAL::Simple_cartesian::Ray_3 Ray; 38 | typedef Kernel::Segment_3 Segment; 39 | 40 | struct CSPrimPolyhedronPrivate 41 | { 42 | Polyhedron m_Polyhedron; 43 | Point m_RandPt; 44 | CGAL::AABB_tree *m_PolyhedronTree; 45 | }; 46 | 47 | 48 | #endif // CSPRIMPOLYHEDRON_P_H 49 | -------------------------------------------------------------------------------- /src/CSPrimRotPoly.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | #include "CSPrimPolygon.h" 22 | 23 | //! Rotational extruded polygon Primitive 24 | /*! 25 | This is a rotation extruded area polygon primitive defined by a number of points in space, an extrude axis and start-, stop-angle. 26 | Warning: This primitive currently can only be defined in Cartesian coordinates. 27 | */ 28 | class CSXCAD_EXPORT CSPrimRotPoly : public CSPrimPolygon 29 | { 30 | public: 31 | CSPrimRotPoly(ParameterSet* paraSet, CSProperties* prop); 32 | CSPrimRotPoly(CSPrimRotPoly* primPolygon, CSProperties *prop=NULL); 33 | CSPrimRotPoly(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 34 | virtual ~CSPrimRotPoly(); 35 | 36 | virtual CSPrimRotPoly* GetCopy(CSProperties *prop=NULL) {return new CSPrimRotPoly(this,prop);} 37 | 38 | void SetRotAxisDir(int dir) {if ((dir>=0) && (dir<3)) m_RotAxisDir=dir;} 39 | 40 | int GetRotAxisDir() const {return m_RotAxisDir;} 41 | 42 | void SetAngle(int index, double val) {if ((index>=0) && (index<2)) StartStopAngle[index].SetValue(val);} 43 | void SetAngle(int index, const std::string val) {if ((index>=0) && (index<2)) StartStopAngle[index].SetValue(val);} 44 | 45 | double GetAngle(int index) const {if ((index>=0) && (index<2)) return StartStopAngle[index].GetValue(); else return 0;} 46 | ParameterScalar* GetAnglePS(int index) {if ((index>=0) && (index<2)) return &StartStopAngle[index]; else return NULL;} 47 | 48 | virtual bool IsInside(const double* Coord, double tol=0); 49 | 50 | virtual bool Update(std::string *ErrStr=NULL); 51 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 52 | virtual bool ReadFromXML(TiXmlNode &root); 53 | 54 | protected: 55 | //start-stop angle 56 | ParameterScalar StartStopAngle[2]; 57 | //sorted and pre evaluated angles 58 | double m_StartStopAng[2]; 59 | //rot axis direction 60 | int m_RotAxisDir; 61 | }; 62 | -------------------------------------------------------------------------------- /src/CSPrimSphere.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | 22 | //! Sphere Primitive 23 | /*! 24 | This is a spherical primitive defined by its center coordinates and a radius. 25 | */ 26 | class CSXCAD_EXPORT CSPrimSphere : public CSPrimitives 27 | { 28 | public: 29 | CSPrimSphere(ParameterSet* paraSet, CSProperties* prop); 30 | CSPrimSphere(CSPrimSphere* sphere, CSProperties *prop=NULL); 31 | CSPrimSphere(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 32 | virtual ~CSPrimSphere(); 33 | 34 | virtual CSPrimitives* GetCopy(CSProperties *prop=NULL) {return new CSPrimSphere(this,prop);} 35 | 36 | //! Set the center point coordinate 37 | void SetCoord(int index, double val) {m_Center.SetValue(index,val);} 38 | //! Set the center point coordinate as paramater string 39 | void SetCoord(int index, const char* val) {m_Center.SetValue(index,val);} 40 | //! Set the center point coordinate as paramater string 41 | void SetCoord(int index, std::string val) {m_Center.SetValue(index,val);} 42 | 43 | void SetCenter(double x1, double x2, double x3); 44 | void SetCenter(double x[3]); 45 | 46 | void SetCenter(std::string x1, std::string x2, std::string x3); 47 | void SetCenter(std::string x[3]); 48 | 49 | double GetCoord(int index) {return m_Center.GetValue(index);} 50 | ParameterScalar* GetCoordPS(int index) {return m_Center.GetCoordPS(index);} 51 | ParameterCoord* GetCenter() {return &m_Center;} 52 | 53 | void SetRadius(double val) {psRadius.SetValue(val);} 54 | void SetRadius(const char* val) {psRadius.SetValue(val);} 55 | 56 | double GetRadius() {return psRadius.GetValue();} 57 | ParameterScalar* GetRadiusPS() {return &psRadius;} 58 | 59 | virtual bool GetBoundBox(double dBoundBox[6], bool PreserveOrientation=false); 60 | virtual bool IsInside(const double* Coord, double tol=0); 61 | 62 | virtual bool Update(std::string *ErrStr=NULL); 63 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 64 | virtual bool ReadFromXML(TiXmlNode &root); 65 | 66 | virtual void ShowPrimitiveStatus(std::ostream& stream); 67 | 68 | protected: 69 | ParameterCoord m_Center; 70 | ParameterScalar psRadius; 71 | }; 72 | 73 | -------------------------------------------------------------------------------- /src/CSPrimSphericalShell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | #include "CSPrimSphere.h" 22 | 23 | //! SphericalShell Primitive 24 | /*! 25 | This is a spherical shell primitive derived from the sphere primitive, adding a shell width which is centered around the sphere radius. 26 | \sa CSPrimSphere 27 | */ 28 | class CSXCAD_EXPORT CSPrimSphericalShell : public CSPrimSphere 29 | { 30 | public: 31 | CSPrimSphericalShell(ParameterSet* paraSet, CSProperties* prop); 32 | CSPrimSphericalShell(CSPrimSphericalShell* sphereshell, CSProperties *prop=NULL); 33 | CSPrimSphericalShell(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 34 | virtual ~CSPrimSphericalShell(); 35 | 36 | virtual CSPrimitives* GetCopy(CSProperties *prop=NULL) {return new CSPrimSphericalShell(this,prop);} 37 | 38 | void SetShellWidth(double val) {psShellWidth.SetValue(val);} 39 | void SetShellWidth(const char* val) {psShellWidth.SetValue(val);} 40 | 41 | double GetShellWidth() {return psShellWidth.GetValue();} 42 | ParameterScalar* GetShellWidthPS() {return &psShellWidth;} 43 | 44 | virtual bool GetBoundBox(double dBoundBox[6], bool PreserveOrientation=false); 45 | virtual bool IsInside(const double* Coord, double tol=0); 46 | 47 | virtual bool Update(std::string *ErrStr=NULL); 48 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 49 | virtual bool ReadFromXML(TiXmlNode &root); 50 | 51 | virtual void ShowPrimitiveStatus(std::ostream& stream); 52 | 53 | protected: 54 | ParameterScalar psShellWidth; 55 | }; 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/CSPrimUserDefined.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | 22 | //! User defined Primitive given by an analytic formula 23 | /*! 24 | This primitive is defined by a boolean result analytic formula. If a given coordinate results in a true result the primitive is assumed existing at these coordinate. 25 | */ 26 | class CSXCAD_EXPORT CSPrimUserDefined: public CSPrimitives 27 | { 28 | public: 29 | enum UserDefinedCoordSystem 30 | { 31 | CARESIAN_SYSTEM,CYLINDER_SYSTEM,SPHERE_SYSTEM 32 | }; 33 | CSPrimUserDefined(ParameterSet* paraSet, CSProperties* prop); 34 | CSPrimUserDefined(CSPrimUserDefined* primUDef, CSProperties *prop=NULL); 35 | CSPrimUserDefined(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 36 | virtual ~CSPrimUserDefined(); 37 | 38 | virtual CSPrimUserDefined* GetCopy(CSProperties *prop=NULL) {return new CSPrimUserDefined(this,prop);} 39 | 40 | void SetCoordSystem(UserDefinedCoordSystem newSystem); 41 | UserDefinedCoordSystem GetCoordSystem() {return CoordSystem;} 42 | 43 | void SetCoordShift(int index, double val) {if ((index>=0) && (index<3)) dPosShift[index].SetValue(val);} 44 | void SetCoordShift(int index, const char* val) {if ((index>=0) && (index<3)) dPosShift[index].SetValue(val);} 45 | 46 | double GetCoordShift(int index) {if ((index>=0) && (index<3)) return dPosShift[index].GetValue(); else return 0;} 47 | ParameterScalar* GetCoordShiftPS(int index) {if ((index>=0) && (index<3)) return &dPosShift[index]; else return NULL;} 48 | 49 | void SetFunction(const char* func); 50 | const char* GetFunction() {return stFunction.c_str();} 51 | 52 | virtual bool GetBoundBox(double dBoundBox[6], bool PreserveOrientation=false); 53 | virtual bool IsInside(const double* Coord, double tol=0); 54 | 55 | virtual bool Update(std::string *ErrStr=NULL); 56 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 57 | virtual bool ReadFromXML(TiXmlNode &root); 58 | 59 | protected: 60 | std::string stFunction; 61 | UserDefinedCoordSystem CoordSystem; 62 | CSFunctionParser* fParse; 63 | std::string fParameter; 64 | int iQtyParameter; 65 | ParameterScalar dPosShift[3]; 66 | }; 67 | -------------------------------------------------------------------------------- /src/CSPrimWire.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPrimitives.h" 21 | #include "CSPrimCurve.h" 22 | 23 | //! Wire Primitive (Polygonal chain with finite radius) 24 | /*! 25 | This is a wire primitive derived from a curve with an additional wire radius 26 | \sa CSPrimCurve 27 | */ 28 | class CSXCAD_EXPORT CSPrimWire : public CSPrimCurve 29 | { 30 | public: 31 | CSPrimWire(ParameterSet* paraSet, CSProperties* prop); 32 | CSPrimWire(CSPrimWire* primCurve, CSProperties *prop=NULL); 33 | CSPrimWire(unsigned int ID, ParameterSet* paraSet, CSProperties* prop); 34 | virtual ~CSPrimWire(); 35 | 36 | virtual CSPrimitives* GetCopy(CSProperties *prop=NULL) {return new CSPrimWire(this,prop);} 37 | 38 | void SetWireRadius(double val); 39 | void SetWireRadius(const char* val); 40 | 41 | double GetWireRadius() {return wireRadius.GetValue();} 42 | ParameterScalar* GetWireRadiusPS() {return &wireRadius;} 43 | 44 | virtual bool GetBoundBox(double dBoundBox[6], bool PreserveOrientation=false); 45 | virtual bool IsInside(const double* Coord, double tol=0); 46 | 47 | virtual bool Update(std::string *ErrStr=NULL); 48 | virtual bool Write2XML(TiXmlElement &elem, bool parameterised=true); 49 | virtual bool ReadFromXML(TiXmlNode &root); 50 | 51 | protected: 52 | ParameterScalar wireRadius; 53 | }; 54 | -------------------------------------------------------------------------------- /src/CSPropConductingSheet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2025 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSPropMetal.h" 21 | 22 | //! Continuous Structure Conductive Sheet Material Property 23 | /*! 24 | This is a condiction sheet dispersive model for an efficient wide band Analysis of planar waveguides and circuits. 25 | */ 26 | class CSXCAD_EXPORT CSPropConductingSheet : public CSPropMetal 27 | { 28 | public: 29 | CSPropConductingSheet(ParameterSet* paraSet); 30 | CSPropConductingSheet(CSPropConductingSheet* prop, bool copyPrim=false); 31 | CSPropConductingSheet(unsigned int ID, ParameterSet* paraSet); 32 | virtual ~CSPropConductingSheet(); 33 | 34 | //! Create a copy of this property. Optional: Copy all primitives assigned to this property too. 35 | virtual CSProperties* GetCopy(bool incl_prim=false) {return new CSPropConductingSheet(this, incl_prim);} 36 | 37 | virtual void Init(); 38 | 39 | //! Get PropertyType as a xml element name \sa PropertyType and GetType 40 | virtual const std::string GetTypeXMLString() const {return std::string("ConductingSheet");} 41 | 42 | //! Set the Conductivity 43 | void SetConductivity(double val) {Conductivity.SetValue(val);} 44 | //! Set the Conductivity 45 | int SetConductivity(const std::string val) {return Conductivity.SetValue(val);} 46 | //! Get the Conductivity 47 | double GetConductivity() {return Conductivity.GetValue();} 48 | //! Get the Conductivity as a string 49 | const std::string GetConductivityTerm() {return Conductivity.GetString();} 50 | 51 | //! Set the Thickness 52 | void SetThickness(double val) {Thickness.SetValue(val);} 53 | //! Set the Thickness 54 | int SetThickness(const std::string val) {return Thickness.SetValue(val);} 55 | //! Get the Thickness 56 | double GetThickness() {return Thickness.GetValue();} 57 | //! Get the Thickness as a string 58 | const std::string GetThicknessTerm() {return Thickness.GetString();} 59 | 60 | virtual bool Update(std::string *ErrStr=NULL); 61 | 62 | virtual bool Write2XML(TiXmlNode& root, bool parameterised=true, bool sparse=false); 63 | virtual bool ReadFromXML(TiXmlNode &root); 64 | 65 | virtual void ShowPropertyStatus(std::ostream& stream); 66 | 67 | protected: 68 | ParameterScalar Conductivity; 69 | ParameterScalar Thickness; 70 | }; 71 | -------------------------------------------------------------------------------- /src/CSPropDiscMaterial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSProperties.h" 21 | #include "CSPropMaterial.h" 22 | 23 | typedef unsigned char uint8; 24 | 25 | class vtkPolyData; 26 | 27 | //! Continuous Structure Discrete Material Property 28 | /*! 29 | This Property reads a discrete material distribution from a file. (currently only HDF5) 30 | */ 31 | class CSXCAD_EXPORT CSPropDiscMaterial : public CSPropMaterial 32 | { 33 | public: 34 | CSPropDiscMaterial(ParameterSet* paraSet); 35 | CSPropDiscMaterial(CSPropDiscMaterial* prop, bool copyPrim=false); 36 | CSPropDiscMaterial(unsigned int ID, ParameterSet* paraSet); 37 | virtual ~CSPropDiscMaterial(); 38 | 39 | //! Create a copy of this property. Optional: Copy all primitives assigned to this property too. 40 | virtual CSProperties* GetCopy(bool incl_prim=false) {return new CSPropDiscMaterial(this, incl_prim);} 41 | 42 | virtual const std::string GetTypeXMLString() const {return std::string("Discrete-Material");} 43 | 44 | virtual double GetEpsilonWeighted(int ny, const double* coords); 45 | virtual double GetMueWeighted(int ny, const double* coords); 46 | virtual double GetKappaWeighted(int ny, const double* coords); 47 | virtual double GetSigmaWeighted(int ny, const double* coords); 48 | 49 | virtual double GetDensityWeighted(const double* coords); 50 | 51 | //! Set true if database index 0 is used as background material (default), or false if CSPropMaterial should be used as index 0 52 | virtual void SetUseDataBaseForBackground(bool val) {m_DB_Background=val;} 53 | 54 | CSTransform* GetTransform() {return m_Transform;} 55 | 56 | double GetScale() {return m_Scale;} 57 | 58 | virtual bool Write2XML(TiXmlNode& root, bool parameterised=true, bool sparse=false); 59 | virtual bool ReadFromXML(TiXmlNode &root); 60 | 61 | bool ReadFile(); 62 | 63 | virtual void ShowPropertyStatus(std::ostream& stream); 64 | 65 | //! Create a vtkPolyData surface that separates the discrete material from background material 66 | virtual vtkPolyData* CreatePolyDataModel() const; 67 | 68 | protected: 69 | unsigned int GetWeightingPos(const double* coords); 70 | int GetDBPos(const double* coords); 71 | virtual void Init(); 72 | 73 | int m_FileType; 74 | std::string m_Filename; 75 | unsigned int m_Size[3]; 76 | unsigned int m_DB_size; 77 | uint8* m_Disc_Ind; 78 | float *m_mesh[3]; 79 | float *m_Disc_epsR; 80 | float *m_Disc_kappa; 81 | float *m_Disc_mueR; 82 | float *m_Disc_sigma; 83 | float *m_Disc_Density; 84 | double m_Scale; 85 | bool m_DB_Background; 86 | CSTransform* m_Transform; 87 | 88 | bool ReadHDF5(std::string filename); 89 | void* ReadDataSet(std::string filename, std::string d_name, int type_id, int &rank, unsigned int &size, bool debug=false); 90 | }; 91 | 92 | -------------------------------------------------------------------------------- /src/CSPropDispersiveMaterial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2025 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "tinyxml.h" 19 | 20 | #include "CSPropDispersiveMaterial.h" 21 | 22 | CSPropDispersiveMaterial::CSPropDispersiveMaterial(ParameterSet* paraSet) : CSPropMaterial(paraSet) {Type=(CSProperties::PropertyType)(DISPERSIVEMATERIAL | MATERIAL);Init();} 23 | CSPropDispersiveMaterial::CSPropDispersiveMaterial(CSPropDispersiveMaterial* prop, bool copyPrim) : CSPropMaterial(prop, copyPrim) 24 | { 25 | Init(); 26 | SetDispersionOrder(prop->m_Order); 27 | Type=(CSProperties::PropertyType)(DISPERSIVEMATERIAL | MATERIAL); 28 | } 29 | CSPropDispersiveMaterial::CSPropDispersiveMaterial(unsigned int ID, ParameterSet* paraSet) : CSPropMaterial(ID,paraSet) {Type=(CSProperties::PropertyType)(DISPERSIVEMATERIAL | MATERIAL);Init();} 30 | CSPropDispersiveMaterial::~CSPropDispersiveMaterial() {m_Order = 0;} 31 | 32 | bool CSPropDispersiveMaterial::Update(std::string *ErrStr) 33 | { 34 | return CSPropMaterial::Update(ErrStr); 35 | } 36 | 37 | void CSPropDispersiveMaterial::Init() 38 | { 39 | m_Order = 0; 40 | } 41 | 42 | void CSPropDispersiveMaterial::SetDispersionOrder(int val) 43 | { 44 | if (m_Order>0) 45 | DeleteValues(); 46 | m_Order=val; 47 | this->InitValues(); 48 | } 49 | 50 | double CSPropDispersiveMaterial::GetValue3(ParameterScalar **ps, int order, int ny) 51 | { 52 | if ((ny>2) || (ny<0)) return 0; 53 | if ((order>=m_Order) || (order<0)) return 0; 54 | return this->GetValue(ps[order], ny); 55 | } 56 | 57 | std::string CSPropDispersiveMaterial::GetTerm3(ParameterScalar **ps, int order, int ny) 58 | { 59 | if ((ny>2) || (ny<0)) return 0; 60 | if ((order>=m_Order) || (order<0)) return 0; 61 | return this->GetTerm(ps[order], ny); 62 | } 63 | 64 | void CSPropDispersiveMaterial::SetValue3(double val, ParameterScalar **ps, int order, int ny) 65 | { 66 | if ((ny>2) || (ny<0)) return; 67 | if ((order>=m_Order) || (order<0)) return; 68 | this->SetValue(val, ps[order], ny); 69 | } 70 | 71 | int CSPropDispersiveMaterial::SetValue3(std::string val, ParameterScalar **ps, int order, int ny) 72 | { 73 | if ((ny>2) || (ny<0)) return 0; 74 | if ((order>=m_Order) || (order<0)) return 0; 75 | return this->SetValue(val, ps[order], ny); 76 | } 77 | 78 | double CSPropDispersiveMaterial::GetWeight3(ParameterScalar **ps, int order, int ny, const double* coords) 79 | { 80 | if ((ny>2) || (ny<0)) return 0; 81 | if ((order>=m_Order) || (order<0)) return 0; 82 | return this->GetWeight(ps[order], ny, coords); 83 | } 84 | 85 | bool CSPropDispersiveMaterial::Write2XML(TiXmlNode& root, bool parameterised, bool sparse) 86 | { 87 | return CSPropMaterial::Write2XML(root,parameterised,sparse); 88 | } 89 | 90 | bool CSPropDispersiveMaterial::ReadFromXML(TiXmlNode &root) 91 | { 92 | return CSPropMaterial::ReadFromXML(root); 93 | } 94 | -------------------------------------------------------------------------------- /src/CSPropDispersiveMaterial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2025 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSProperties.h" 21 | #include "CSPropMaterial.h" 22 | 23 | //! Continuous Structure Dispersive Material Property 24 | /*! 25 | This abstarct Property can hold information about the special properties of dispersive materials. 26 | */ 27 | class CSXCAD_EXPORT CSPropDispersiveMaterial : public CSPropMaterial 28 | { 29 | public: 30 | virtual ~CSPropDispersiveMaterial(); 31 | 32 | //! Get the dispersion order 33 | virtual int GetDispersionOrder() {return m_Order;} 34 | 35 | //! Set the dispersion order. This will reset all values! 36 | virtual void SetDispersionOrder(int); 37 | 38 | //! Get PropertyType as a xml element name \sa PropertyType and GetType 39 | virtual const std::string GetTypeXMLString() const {return std::string("DispersiveMaterial");} 40 | 41 | protected: 42 | int m_Order; 43 | virtual void Init(); 44 | virtual void InitValues() {}; 45 | virtual void DeleteValues() {}; 46 | 47 | virtual bool Update(std::string *ErrStr=NULL); 48 | double GetValue3(ParameterScalar **ps, int order, int ny); 49 | std::string GetTerm3(ParameterScalar **ps, int order, int ny); 50 | void SetValue3(double val, ParameterScalar **ps, int order, int ny); 51 | int SetValue3(std::string val, ParameterScalar **ps, int order, int ny); 52 | double GetWeight3(ParameterScalar **ps, int order, int ny, const double* coords); 53 | 54 | virtual bool Write2XML(TiXmlNode& root, bool parameterised=true, bool sparse=false); 55 | virtual bool ReadFromXML(TiXmlNode &root); 56 | 57 | CSPropDispersiveMaterial(ParameterSet* paraSet); 58 | CSPropDispersiveMaterial(CSPropDispersiveMaterial* prop, bool copyPrim=false); 59 | CSPropDispersiveMaterial(unsigned int ID, ParameterSet* paraSet); 60 | 61 | //! Create a copy of this property. Optional: Copy all primitives assigned to this property too. 62 | virtual CSProperties* GetCopy(bool incl_prim=false) {return new CSPropDispersiveMaterial(this, incl_prim);} 63 | }; 64 | -------------------------------------------------------------------------------- /src/CSPropLumpedElement.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2025 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSProperties.h" 21 | 22 | //! Continuous Structure Lumped Element Property 23 | /*! 24 | This property represents lumped elements, e.g. smd capacitors etc. 25 | */ 26 | class CSXCAD_EXPORT CSPropLumpedElement : public CSProperties 27 | { 28 | public: 29 | enum LEtype 30 | { 31 | PARALLEL = 0, 32 | SERIES = 1, 33 | INVALID = -1 34 | }; 35 | 36 | CSPropLumpedElement(ParameterSet* paraSet); 37 | CSPropLumpedElement(CSPropLumpedElement* prop, bool copyPrim=false); 38 | CSPropLumpedElement(unsigned int ID, ParameterSet* paraSet); 39 | virtual ~CSPropLumpedElement(); 40 | 41 | //! Create a copy of this property. Optional: Copy all primitives assigned to this property too. 42 | virtual CSProperties* GetCopy(bool incl_prim=false) {return new CSPropLumpedElement(this, incl_prim);} 43 | 44 | virtual void Init(); 45 | 46 | void SetResistance(double val) {m_R.SetValue(val);} 47 | int SetResistance(const std::string val) {return m_R.SetValue(val);} 48 | double GetResistance() const {return m_R.GetValue();} 49 | const std::string GetResistanceTerm() const {return m_R.GetString();} 50 | 51 | void SetCapacity(double val) {m_C.SetValue(val);} 52 | int SetCapacity(const std::string val) {return m_C.SetValue(val);} 53 | double GetCapacity() const {return m_C.GetValue();} 54 | const std::string GetCapacityTerm() const {return m_C.GetString();} 55 | 56 | void SetInductance(double val) {m_L.SetValue(val);} 57 | int SetInductance(const std::string val) {return m_L.SetValue(val);} 58 | double GetInductance() const {return m_L.GetValue();} 59 | const std::string GetInductanceTerm() const {return m_L.GetString();} 60 | 61 | void SetDirection(int ny); 62 | int GetDirection() const {return m_ny;} 63 | 64 | void SetCaps(bool val) {m_Caps=val;} 65 | int GetCaps() const {return m_Caps;} 66 | 67 | void SetLEtype(LEtype c_LEtype) {m_LEtype = c_LEtype;}; 68 | LEtype GetLEtype() const {return m_LEtype; }; 69 | 70 | virtual void ShowPropertyStatus(std::ostream& stream); 71 | 72 | //! Get PropertyType as a xml element name \sa PropertyType and GetType 73 | virtual const std::string GetTypeXMLString() const {return std::string("LumpedElement");} 74 | 75 | protected: 76 | int m_ny; 77 | bool m_Caps; 78 | ParameterScalar m_R,m_C,m_L; 79 | 80 | LEtype m_LEtype; 81 | 82 | virtual bool Update(std::string *ErrStr=NULL); 83 | 84 | virtual bool Write2XML(TiXmlNode& root, bool parameterised=true, bool sparse=false); 85 | virtual bool ReadFromXML(TiXmlNode &root); 86 | }; 87 | 88 | -------------------------------------------------------------------------------- /src/CSPropMetal.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2025 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "tinyxml.h" 19 | 20 | #include "CSPropMetal.h" 21 | 22 | CSPropMetal::CSPropMetal(ParameterSet* paraSet) : CSProperties(paraSet) {Type=METAL;} 23 | CSPropMetal::CSPropMetal(CSPropMetal* prop, bool copyPrim) : CSProperties(prop, copyPrim) 24 | { 25 | Type=METAL; 26 | } 27 | CSPropMetal::CSPropMetal(unsigned int ID, ParameterSet* paraSet) : CSProperties(ID,paraSet) {Type=METAL;} 28 | CSPropMetal::~CSPropMetal() {} 29 | 30 | bool CSPropMetal::Write2XML(TiXmlNode& root, bool parameterised, bool sparse) 31 | { 32 | if (CSProperties::Write2XML(root,parameterised,sparse) == false) return false; 33 | TiXmlElement* prop=root.ToElement(); 34 | if (prop==NULL) return false; 35 | 36 | return true; 37 | } 38 | 39 | bool CSPropMetal::ReadFromXML(TiXmlNode &root) 40 | { 41 | return CSProperties::ReadFromXML(root); 42 | } 43 | -------------------------------------------------------------------------------- /src/CSPropMetal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2025 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSProperties.h" 21 | 22 | //! Continuous Structure Metal Property 23 | /*! 24 | This Property defines a metal property (aka. PEC). 25 | */ 26 | class CSXCAD_EXPORT CSPropMetal : public CSProperties 27 | { 28 | public: 29 | CSPropMetal(ParameterSet* paraSet); 30 | CSPropMetal(CSPropMetal* prop, bool copyPrim=false); 31 | CSPropMetal(unsigned int ID, ParameterSet* paraSet); 32 | virtual ~CSPropMetal(); 33 | 34 | virtual bool GetMaterial() const {return true;} 35 | 36 | //! Create a copy of this property. Optional: Copy all primitives assigned to this property too. 37 | virtual CSProperties* GetCopy(bool incl_prim=false) {return new CSPropMetal(this, incl_prim);} 38 | 39 | //! Get PropertyType as a xml element name \sa PropertyType and GetType 40 | virtual const std::string GetTypeXMLString() const {return std::string("Metal");} 41 | 42 | virtual bool Write2XML(TiXmlNode& root, bool parameterised=true, bool sparse=false); 43 | virtual bool ReadFromXML(TiXmlNode &root); 44 | }; 45 | -------------------------------------------------------------------------------- /src/CSPropProbeBox.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2025 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSProperties.h" 21 | 22 | 23 | //! Continuous Structure Probe Property for calculating integral properties 24 | /*! 25 | CSProbProbeBox is a class for calculating integral properties such as (static) charges, voltages or currents. 26 | */ 27 | class CSXCAD_EXPORT CSPropProbeBox : public CSProperties 28 | { 29 | public: 30 | CSPropProbeBox(ParameterSet* paraSet); 31 | CSPropProbeBox(CSPropProbeBox* prop, bool copyPrim=false); 32 | CSPropProbeBox(unsigned int ID, ParameterSet* paraSet); 33 | virtual ~CSPropProbeBox(); 34 | 35 | //! Create a copy of this property. Optional: Copy all primitives assigned to this property too. 36 | virtual CSProperties* GetCopy(bool incl_prim=false) {return new CSPropProbeBox(this, incl_prim);} 37 | 38 | //! Get PropertyType as a xml element name \sa PropertyType and GetType 39 | virtual const std::string GetTypeXMLString() const {return std::string("ProbeBox");} 40 | 41 | //! Define a number for this probe property \sa GetNumber 42 | void SetNumber(unsigned int val); 43 | //! Get the number designated to this probe property \sa SetNumber 44 | unsigned int GetNumber(); 45 | 46 | //! Get the normal direction of this probe box (required by some types of probes) 47 | int GetNormalDir() const {return m_NormDir;} 48 | //! Set the normal direction of this probe box (required by some types of probes) 49 | void SetNormalDir(unsigned int ndir) {m_NormDir=ndir;} 50 | 51 | //! Define/Set the probe weighting \sa GetWeighting 52 | void SetWeighting(double weight) {m_weight=weight;} 53 | //! Get the probe weighting \sa GetWeighting 54 | double GetWeighting() {return m_weight;} 55 | 56 | //! Define the probe type (e.g. type=0 for a charge integration, can/must be defined by the user interface) \sa GetProbeType 57 | void SetProbeType(int type) {ProbeType=type;} 58 | //! Get the probe type \sa SetProbeType 59 | int GetProbeType() {return ProbeType;} 60 | 61 | //! Set the probe start time 62 | void SetStartTime(float value) {startTime=value;} 63 | //! Get the probe start time 64 | double GetStartTime() {return startTime;} 65 | 66 | //! Set the probe stop time 67 | void SetStopTime(float value) {stopTime=value;} 68 | //! Get the probe stop time 69 | double GetStopTime() {return stopTime;} 70 | 71 | size_t CountFDSamples() {return m_FD_Samples.size();} 72 | std::vector *GetFDSamples() {return &m_FD_Samples;} 73 | void ClearFDSamples() {m_FD_Samples.clear();} 74 | void AddFDSample(double freq) {m_FD_Samples.push_back(freq);} 75 | void AddFDSample(std::vector *freqs); 76 | void AddFDSample(std::string freqs); 77 | 78 | virtual bool Write2XML(TiXmlNode& root, bool parameterised=true, bool sparse=false); 79 | virtual bool ReadFromXML(TiXmlNode &root); 80 | 81 | protected: 82 | unsigned int uiNumber; 83 | int m_NormDir; 84 | double m_weight; 85 | int ProbeType; 86 | std::vector m_FD_Samples; 87 | double startTime, stopTime; 88 | }; 89 | 90 | -------------------------------------------------------------------------------- /src/CSPropResBox.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2025 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "tinyxml.h" 19 | 20 | #include "CSPropResBox.h" 21 | 22 | CSPropResBox::CSPropResBox(ParameterSet* paraSet) : CSProperties(paraSet) {Type=RESBOX;uiFactor=1;bVisisble=false;} 23 | CSPropResBox::CSPropResBox(CSPropResBox* prop, bool copyPrim) : CSProperties(prop, copyPrim) 24 | { 25 | Type=RESBOX; 26 | uiFactor=prop->uiFactor; 27 | } 28 | CSPropResBox::CSPropResBox(unsigned int ID, ParameterSet* paraSet) : CSProperties(ID,paraSet) {Type=RESBOX;uiFactor=1;bVisisble=false;} 29 | CSPropResBox::~CSPropResBox() {}; 30 | 31 | void CSPropResBox::SetResFactor(unsigned int val) {uiFactor=val;} 32 | unsigned int CSPropResBox::GetResFactor() {return uiFactor;} 33 | 34 | bool CSPropResBox::Write2XML(TiXmlNode& root, bool parameterised, bool sparse) 35 | { 36 | if (CSProperties::Write2XML(root,parameterised,sparse) == false) return false; 37 | TiXmlElement* prop=root.ToElement(); 38 | if (prop==NULL) return false; 39 | 40 | prop->SetAttribute("Factor",(int)uiFactor); 41 | 42 | return true; 43 | } 44 | 45 | bool CSPropResBox::ReadFromXML(TiXmlNode &root) 46 | { 47 | if (CSProperties::ReadFromXML(root)==false) return false; 48 | 49 | TiXmlElement *prop = root.ToElement(); 50 | if (prop==NULL) return false; 51 | 52 | int iHelp; 53 | if (prop->QueryIntAttribute("Factor",&iHelp)!=TIXML_SUCCESS) uiFactor=1; 54 | else uiFactor=(unsigned int)iHelp; 55 | 56 | return true; 57 | } 58 | -------------------------------------------------------------------------------- /src/CSPropResBox.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2025 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSProperties.h" 21 | 22 | //! Continuous Structure Resolution Property 23 | /*! 24 | This Property defines a refined mesh area. 25 | */ 26 | class CSXCAD_EXPORT CSPropResBox : public CSProperties 27 | { 28 | public: 29 | CSPropResBox(ParameterSet* paraSet); 30 | CSPropResBox(CSPropResBox* prop, bool copyPrim=false); 31 | CSPropResBox(unsigned int ID, ParameterSet* paraSet); 32 | virtual ~CSPropResBox(); 33 | 34 | //! Create a copy of this property. Optional: Copy all primitives assigned to this property too. 35 | virtual CSProperties* GetCopy(bool incl_prim=false) {return new CSPropResBox(this, incl_prim);} 36 | 37 | //! Get PropertyType as a xml element name \sa PropertyType and GetType 38 | virtual const std::string GetTypeXMLString() const {return std::string("ResBox");} 39 | 40 | void SetResFactor(unsigned int val); 41 | unsigned int GetResFactor(); 42 | 43 | virtual bool Write2XML(TiXmlNode& root, bool parameterised=true, bool sparse=false); 44 | virtual bool ReadFromXML(TiXmlNode &root); 45 | 46 | protected: 47 | unsigned int uiFactor; 48 | }; 49 | -------------------------------------------------------------------------------- /src/CSPropUnknown.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2025 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "tinyxml.h" 19 | 20 | #include "CSPropUnknown.h" 21 | 22 | CSPropUnknown::CSPropUnknown(ParameterSet* paraSet) : CSProperties(paraSet) {Type=UNKNOWN;bVisisble=false;} 23 | CSPropUnknown::CSPropUnknown(unsigned int ID, ParameterSet* paraSet) : CSProperties(ID,paraSet) {Type=UNKNOWN;bVisisble=false;} 24 | CSPropUnknown::CSPropUnknown(CSPropUnknown* prop, bool copyPrim) : CSProperties(prop, copyPrim) 25 | { 26 | Type=UNKNOWN; 27 | } 28 | CSPropUnknown::~CSPropUnknown() {} 29 | 30 | void CSPropUnknown::SetProperty(const std::string val) {sUnknownProperty=std::string(val);} 31 | const std::string CSPropUnknown::GetProperty() {return sUnknownProperty;} 32 | 33 | 34 | bool CSPropUnknown::Write2XML(TiXmlNode& root, bool parameterised, bool sparse) 35 | { 36 | if (CSProperties::Write2XML(root,parameterised,sparse) == false) return false; 37 | TiXmlElement* prop=root.ToElement(); 38 | if (prop==NULL) return false; 39 | 40 | prop->SetAttribute("Property",sUnknownProperty.c_str()); 41 | 42 | return true; 43 | } 44 | 45 | bool CSPropUnknown::ReadFromXML(TiXmlNode &root) 46 | { 47 | if (CSProperties::ReadFromXML(root)==false) return false; 48 | TiXmlElement* prob=root.ToElement(); 49 | 50 | const char* chProp=prob->Attribute("Property"); 51 | if (chProp==NULL) 52 | sUnknownProperty=std::string("unknown"); 53 | else sUnknownProperty=std::string(chProp); 54 | return true; 55 | } 56 | -------------------------------------------------------------------------------- /src/CSPropUnknown.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2025 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "CSProperties.h" 21 | 22 | //! Continuous Structure Unknown Property 23 | /*! 24 | This is a property that is getting designated for new properties which are unknown so far (e.g. written by a newer version of CSXCAD) 25 | */ 26 | class CSXCAD_EXPORT CSPropUnknown : public CSProperties 27 | { 28 | public: 29 | CSPropUnknown(ParameterSet* paraSet); 30 | CSPropUnknown(unsigned int ID, ParameterSet* paraSet); 31 | CSPropUnknown(CSPropUnknown* prop, bool copyPrim=false); 32 | virtual ~CSPropUnknown(); 33 | 34 | //! Create a copy of this property. Optional: Copy all primitives assigned to this property too. 35 | virtual CSProperties* GetCopy(bool incl_prim=false) {return new CSPropUnknown(this, incl_prim);} 36 | 37 | //! Get PropertyType as a xml element name \sa PropertyType and GetType 38 | virtual const std::string GetTypeXMLString() const {return std::string("Unknown");} 39 | 40 | void SetProperty(const std::string val); 41 | const std::string GetProperty(); 42 | 43 | virtual bool Write2XML(TiXmlNode& root, bool parameterised=true, bool sparse=false); 44 | virtual bool ReadFromXML(TiXmlNode &root); 45 | 46 | protected: 47 | std::string sUnknownProperty; 48 | }; 49 | -------------------------------------------------------------------------------- /src/CSUseful.h: -------------------------------------------------------------------------------- 1 | #ifndef CSUSEFUL_H 2 | #define CSUSEFUL_H 3 | 4 | class CSDebug; 5 | 6 | #include "CSXCAD_Global.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | std::string CSXCAD_EXPORT ConvertInt(int number); 14 | int CSXCAD_EXPORT String2Int(std::string number); 15 | double CSXCAD_EXPORT String2Double(std::string number, bool &ok, int accurarcy=15); 16 | std::vector CSXCAD_EXPORT SplitString2Double(std::string str, const char delimiter); 17 | std::vector CSXCAD_EXPORT SplitString2Vector(std::string str, const char delimiter); 18 | std::string CSXCAD_EXPORT CombineVector2String(std::vector values, const char delimiter, int accurarcy=15); 19 | std::string CSXCAD_EXPORT CombineArray2String(double* values, unsigned int numVal, const char delimiter, int accurarcy=15); 20 | std::string CSXCAD_EXPORT CombineArray2String(float* values, unsigned int numVal, const char delimiter, int accurarcy=15); 21 | std::string CSXCAD_EXPORT CombineArray2String(int* values, unsigned int numVal, const char delimiter, int accurarcy=15); 22 | 23 | std::vector CSXCAD_EXPORT SplitString2Int(std::string str, const char delimiter); 24 | 25 | class CSXCAD_EXPORT CSDebug 26 | { 27 | public: 28 | CSDebug(); 29 | 30 | void SetLevel(int level) {m_level=level;} 31 | 32 | void Debug(int on_level, const char* message); 33 | void Debug(int on_level, std::string message); 34 | 35 | protected: 36 | int m_level; 37 | }; 38 | 39 | static CSDebug g_CSDebug; 40 | 41 | #endif // CSUSEFUL_H 42 | -------------------------------------------------------------------------------- /src/CSXCAD_Global.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef CSXCAD_GLOBAL_H_ 19 | #define CSXCAD_GLOBAL_H_ 20 | 21 | #define _CSXCAD_LIB_NAME_ "CSXCAD-Lib: Continuous Structure XML - CAD" 22 | #define _CSXCAD_LIB_NAME_SHORT_ "CSXCAD" 23 | #define _CSXCAD_AUTHOR_ "Thorsten Liebig (2008-2023)" 24 | #define _CSXCAD_AUTHOR_MAIL_ "Thorsten.Liebig@gmx.de" 25 | #define _CSXCAD_VERSION_ GIT_VERSION 26 | #define _CSXCAD_LICENSE_ "LGPL v3" 27 | 28 | #if defined(WIN32) 29 | #ifdef BUILD_CSXCAD_LIB 30 | #pragma warning(disable:4251) 31 | #define CSXCAD_EXPORT __declspec(dllexport) 32 | #else 33 | #define CSXCAD_EXPORT __declspec(dllimport) 34 | #endif 35 | #else 36 | #define CSXCAD_EXPORT 37 | #endif 38 | 39 | // declare a parameter as unused 40 | #define UNUSED(x) (void)(x); 41 | 42 | enum CoordinateSystem 43 | { 44 | CARTESIAN, CYLINDRICAL, UNDEFINED_CS 45 | }; 46 | 47 | #endif /*CSXCAD_GLOBAL_H_*/ 48 | -------------------------------------------------------------------------------- /src/ParameterCoord.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef PARAMETERCOORD_H 19 | #define PARAMETERCOORD_H 20 | 21 | #include "ParameterObjects.h" 22 | 23 | //! This class can hold a parameterized coordinate, defined in different coordinate systems. 24 | class CSXCAD_EXPORT ParameterCoord 25 | { 26 | public: 27 | ParameterCoord(); 28 | ParameterCoord(ParameterSet* ParaSet); 29 | ParameterCoord(CoordinateSystem cs); 30 | ParameterCoord(ParameterSet* ParaSet, const double value[3]); 31 | ParameterCoord(ParameterSet* ParaSet, const std::string value[3]); 32 | ParameterCoord(ParameterCoord* pc); 33 | ~ParameterCoord(); 34 | 35 | void SetParameterSet(ParameterSet *paraSet); 36 | 37 | //! Set the coordinate system used for this coordinates 38 | void SetCoordinateSystem(CoordinateSystem cs) {m_CoordSystem=cs; Update();} 39 | //! Convienient method to set the coordinate system, including a fall back if primary coordinate system is undefined. 40 | void SetCoordinateSystem(CoordinateSystem cs, CoordinateSystem fallBack_cs); 41 | //! Get the coordinate system that has been set for this coordinate 42 | CoordinateSystem GetCoordinateSystem() const {return m_CoordSystem;} 43 | 44 | int SetValue(int ny, std::string value); 45 | void SetValue(int ny, double value); 46 | 47 | //! Get the native coordinate values 48 | double GetValue(int ny); 49 | //! Get the native coordinate values as string 50 | const std::string GetValueString(int ny) const; 51 | //! Get the internal scalar parameter, use carefully... 52 | ParameterScalar* GetCoordPS(int ny); 53 | 54 | //! Get the coordinate in the given coordinate system 55 | double GetCoordValue(int ny, CoordinateSystem cs); 56 | 57 | const double* GetNativeCoords() const; 58 | const double* GetCartesianCoords() const {return m_CartesianCoords;} 59 | const double* GetCylindricalCoords() const {return m_CylindricalCoords;} 60 | const double* GetCoords(CoordinateSystem cs) const; 61 | 62 | //! Evaluate the parametric coordinates and return an error message. This methode should be called before requesting coordinate values to check for valid parametric coordinates. 63 | bool Evaluate(std::string *ErrStr); 64 | 65 | // Copy all values and parameter from pc to this. 66 | void Copy(ParameterCoord* pc); 67 | 68 | //! Write this coords to a XML-node. 69 | bool Write2XML(TiXmlElement *elem, bool parameterised=true); 70 | //! Read coords from a XML-node. 71 | bool ReadFromXML(TiXmlElement *elem); 72 | 73 | protected: 74 | //! Update/evaluate the internal data structure 75 | void Update(); 76 | ParameterScalar* m_Coords[3]; 77 | 78 | //! Coordinate system used for this coordinate 79 | CoordinateSystem m_CoordSystem; 80 | 81 | //! evaluated cartesian coords 82 | double m_CartesianCoords[3]; 83 | //! evaluated cylindrical coords 84 | double m_CylindricalCoords[3]; 85 | }; 86 | 87 | //! Convert a given coordinate into another coordinate system 88 | CSXCAD_EXPORT double* TransformCoordSystem(const double* in, double* out, CoordinateSystem CS_In, CoordinateSystem CS_out); 89 | 90 | #endif // PARAMETERCOORD_H 91 | --------------------------------------------------------------------------------