00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _FINITE_DIFF3D_H_
00032 #define _FINITE_DIFF3D_H_
00033
00034 #include "ArbitraryCartesianGrid3D.h"
00035 #include "CartesianNode3D.h"
00036 #include "grid_enums.h"
00037 #include "SparseRowMatrix.h"
00038 #include "Source3D.h"
00039 #include "Detector3D.h"
00040 #include "ComplexVector.h"
00041 #include "Preconditioner.h"
00042 #include <string>
00043 #include <vector>
00044 #include <map>
00045 #include "solver.h"
00046 #include "BoundaryCondition3D.h"
00047
00048 namespace FDDlib {
00049
00053 class FiniteDifferences3D
00054 {
00055 protected:
00056
00058 struct s_neighbordata {
00060 CartesianNode3D* n_node;
00062 int n_linearIndex;
00063 };
00064
00066 ArbitraryCartesianGrid3D *grid;
00067
00069 static const int UNKNOWN_VALUE = -10;
00070
00072 static const int OMITVAL = -1;
00073
00075 SparseRowMatrix<double> Amat_;
00076
00078 ComplexVector<double> Phi_;
00079
00081 ComplexVector<double> AdjointPhi_;
00082
00084 int startTime;
00085
00087 int stopTime;
00088
00090 double achievedTol_;
00091
00093 int usedIterations_;
00094
00096 int currSrcNum_;
00097
00099 double currFreq_;
00100
00102 int numUnknowns;
00103
00105 std::map<int, Complex<double> > knowns;
00106
00108 std::vector<BoundaryCondition3D*> bconds_;
00109
00113 SparseRowMatrix<double> Adep;
00114
00119 std::vector<int> rowMap;
00120
00124 bool validAndActive(const s_neighbordata& ndata) const;
00125
00132 double getOffDiagVal(const CartesianNode3D& node,
00133 const CartesianNode3D& node_p,
00134 const CartesianNode3D& node_m,
00135 direction3D dir) const;
00136
00140 void resetDataVector(std::vector<s_neighbordata>& datavec) const;
00141
00145 void buildAMatrix(double omega) throw(std::string);
00146
00148 void postProcessAMatrix();
00149
00151 void updateRightHandSide(RealVector<double>& RHS);
00152
00158 void copySubMatrices();
00159
00160 public:
00161
00166 FiniteDifferences3D(ArbitraryCartesianGrid3D* acg3d,
00167 const std::vector<BoundaryCondition3D*>& bconds);
00168
00184 void SingleSrcSolve(int solveIterations, double residualTol,
00185 const Source3D &src,
00186 const std::vector<Detector3D*> &detarr,
00187 Preconditioner& Pre, enum_solver Solver,
00188 void (*callback)(const FiniteDifferences3D&, bool,
00189 const std::vector<Detector3D*>&)) throw(std::string);
00190
00208 void MultipleSrcSolve(int solveIterations, double residualTol,
00209 const std::vector<Source3D*> &srcarr,
00210 const std::vector<Detector3D*> &detarr,
00211 Preconditioner& Pre, enum_solver Solver,
00212 void (*callback)(const FiniteDifferences3D&, bool,
00213 const std::vector<Detector3D*>&)) throw(std::string);
00214
00226 bool AdjointSolve(int solveIterations, double residualTol,
00227 const Detector3D &adjDetector, double frequency,
00228 Preconditioner& Pre, enum_solver Solver) throw(std::string);
00229
00242 bool solve(int solveIterations, double residualTol,
00243 bool adjoint, Preconditioner& Pre,
00244 RealVector<double>& RHS, enum_solver Solver) throw(std::string);
00245
00249 ComplexVector<double> getPhi() const;
00250
00254 ComplexVector<double> getAdjointPhi() const;
00255
00261 void getPhi(RealVector<double>& realvec, RealVector<double>& imagvec) const;
00262
00267 void getAdjointPhi(RealVector<double>& realvec,
00268 RealVector<double>& imagvec) const;
00269
00276 void getStatistics(double& solveTime, double& achievedTol,
00277 int& usedIterations) const;
00278
00287 void getSourceInfo(int& srcNum, double& freq) const;
00288
00289 };
00290
00291 }
00292
00293 #endif