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 General Public License as published by
6 *	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 General Public License for more details.
13 *
14 *	You should have received a copy of the GNU General Public License
15 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef PROCESSFIELDS_H
19 #define PROCESSFIELDS_H
20 
21 #include "processing.h"
22 #include "tools/array_ops.h"
23 
24 #define __VTK_DATA_TYPE__ "double"
25 
26 class VTK_File_Writer;
27 class HDF5_File_Writer;
28 
29 class ProcessFields : public Processing
30 {
31 public:
32 	ProcessFields(Engine_Interface_Base* eng_if);
33 	virtual ~ProcessFields();
34 
35 	//! File type definition.
36 	enum FileType { VTK_FILETYPE, HDF5_FILETYPE};
37 
38 	//! Dump type definitions.
39 	/*!
40 	  Current dump types are electric field (E_FIELD_DUMP), magnetic field (H_FIELD_DUMP),
41 	  (conduction) electric current density (kappa*E) (J_FIELD_DUMP) and total current density (rotH)
42 	  */
43 	enum DumpType { E_FIELD_DUMP=0, H_FIELD_DUMP=1, J_FIELD_DUMP=2, ROTH_FIELD_DUMP=3, D_FIELD_DUMP=4, B_FIELD_DUMP=5, SAR_LOCAL_DUMP=20, SAR_1G_DUMP=21, SAR_10G_DUMP=22, SAR_RAW_DATA=29};
44 
GetProcessingName()45 	virtual std::string GetProcessingName() const {return "common field processing";}
46 
47 	virtual void InitProcess();
48 
49 	virtual void DefineStartStopCoord(double* dstart, double* dstop);
50 
51 	//! Define a field dump sub sampling rate for a given direction (default: \a dir = -1 means all directions)
52 	virtual void SetSubSampling(unsigned int subSampleRate, int dir=-1);
53 
54 	//! Define a field dump optimal resolution for a given direction (default: \a dir = -1 means all directions)
55 	virtual void SetOptResolution(double optRes, int dir=-1);
56 
57 	//! Set the filename for a hdf5 data group file (HDF5 FileType only) \sa SetFileType()
SetFileName(std::string fn)58 	void SetFileName(std::string fn) {m_filename=fn;}
SetFileName()59 	std::string SetFileName() const {return m_filename;}
60 
61 	//! Define the Dump-Mode
62 	void SetDumpMode(Engine_Interface_Base::InterpolationType mode);
63 	//! This methode will dump all fields on a main cell node using 2 E-field and 4 H-fields per direction.
SetDumpMode2Node()64 	void SetDumpMode2Node() {SetDumpMode(Engine_Interface_Base::NODE_INTERPOLATE);}
65 	//! This methode will dump all fields in the center of a main cell (dual-node) using 4 E-field and 2 H-fields per direction.
SetDumpMode2Cell()66 	void SetDumpMode2Cell() {SetDumpMode(Engine_Interface_Base::CELL_INTERPOLATE);}
67 
68 	//! Set dump type: 0 for E-fields, 1 for H-fields, 2 for D-fields, 3 for B-fields, 4 for J-fields, etc...
SetDumpType(DumpType type)69 	virtual void SetDumpType(DumpType type) {m_DumpType=type;}
70 
71 	double CalcTotalEnergyEstimate() const;
72 
SetFileType(FileType fileType)73 	void SetFileType(FileType fileType) {m_fileType=fileType;}
74 
75 	static std::string GetFieldNameByType(DumpType type);
76 
77 	virtual bool NeedConductivity() const;
78 	virtual bool NeedPermittivity() const;
79 	virtual bool NeedPermeability() const;
80 
81 protected:
82 	DumpType m_DumpType;
83 	FileType m_fileType;
84 
85 	VTK_File_Writer* m_Vtk_Dump_File;
86 	HDF5_File_Writer* m_HDF5_Dump_File;
87 
88 	enum SampleType {NONE, SUBSAMPLE, OPT_RESOLUTION} m_SampleType;
89 	virtual void CalcMeshPos();
90 
91 	//! field dump sub-sampling (if enabled)
92 	unsigned int subSample[3];
93 
94 	//! field dump optimal resolution (if enabled)
95 	double optResolution[3];
96 
97 	//! dump mesh information
98 	unsigned int numLines[3];	//number of lines to dump
99 	unsigned int* posLines[3];	//grid positions to dump
100 	double* discLines[3];		//mesh disc lines to dump
101 
102 	//! Calculate and return the defined field. Caller has to cleanup the array.
103 	FDTD_FLOAT**** CalcField();
104 };
105 
106 #endif // PROCESSFIELDS_H
107