FEMTIC
ObservedData.h
Go to the documentation of this file.
1 //-------------------------------------------------------------------------------------------------------
2 // The MIT License (MIT)
3 //
4 // Copyright (c) 2021 Yoshiya Usui
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //-------------------------------------------------------------------------------------------------------
24 #ifndef DBLDEF_OBSERVED_DATA
25 #define DBLDEF_OBSERVED_DATA
26 
27 #include <vector>
28 #include <complex>
29 
31 #include "ObservedDataStationMT.h"
33 #include "ObservedDataStationHTF.h"
34 #include "ObservedDataStationVTF.h"
35 #include "ObservedDataStationPT.h"
36 #include "ObservedDataStationNMT.h"
39 #include "AdditinalOutputPoint.h"
40 #include "Forward3D.h"
41 #include "CommonParameters.h"
42 #include "MeshDataTetraElement.h"
43 
44 // Class of observed data
46 
47 public:
48  // Return the the instance of the class
49  static ObservedData* getInstance();
50 
51  // Type IDs of observed data
52  enum typeID{
53  MT=0,
54  HTF,
55  VTF,
56  PT,
57  NMT,
61  };
62 
63  // Input mesh data from "observe.dat"
64  void inputObservedData();
65 
66  // Input data of distortion matrix from "distortion_iterX.dat"
68 
69  // Get total number of different frquencies
71 
72  // Get frequency value
73  double getFrequencyValue( const int num ) const;
74 
75  // Find element including each station
77 
78  // Calulate EM field of all stations
79  void calculateEMFieldOfAllStations( const Forward3D* const ptrForward3D, const double freq, const int iPol, const int ifreq );
80 
81  // Calulate response function of all stations
82  void calculateResponseFunctionOfAllStations( const int freqIDAmongThisPE );
83 
84  // Initialize response functions and errors of all stations
86 
87  // Allocate memory for the calculated values and errors of all stations after setting up frequencies calculated by this PE, at which observed value exists
89 
90  // Output calculated values of all stations
92 
93  // Calulate right-hand side vectors consisting of interpolator vectors
94  void calculateInterpolatorVectors( Forward3D* const ptrForward3D, const double freq );
95 
96  // Calulate sensitivity matrix
97  void calculateSensitivityMatrix( const std::complex<double>* const derivativesOfEMFieldExPol, const std::complex<double>* const derivativesOfEMFieldEyPol,
98  const double freq, const int nModel, double* const sensitivityMatrix ) const;
99 
100  // Calculate data vector of this PE
101  void calculateResidualVectorOfDataThisPE( double* const vector ) const;
102 
103  // Get number of interpolator vectors
104  int getNumInterpolatorVectors() const;
105 
106  // Get total number of observed data
107  int getNumObservedDataThisPETotal() const;
108 
109  // Get number of observed data
110  int getNumObservedDataThisPE( const int ifreq ) const;
111 
112  // Get number of observed data accumulated
113  int getNumObservedDataThisPEAccumulated( const int num ) const;
114 
115  // Increment number of interpolator vectors
117 
118  // Multiply inputed matrix by scaled data values and output new vector
119  void multiplyMatrixByScaledData( const int nRow, const double* const matIn, const double* const vecIn, double* vecOut ) const;
120 
121  // Calculate frequencies treated by thie PE
123 
124  // Get Total number of frequencies calculated by this PE
126 
127  // Get IDs of Frequencies calculated by this PE
128  int getIDsOfFrequenciesCalculatedByThisPE( const int num ) const;
129 
130  // Get values of Frequencies calculated by this PE
131  double getValuesOfFrequenciesCalculatedByThisPE( const int num ) const;
132 
133  // Calculate error sum of squares
134  double calculateErrorSumOfSquaresThisPE() const;
135 
136  // Calculate sum of squares of distortion matrix complexity
138 
139  // Calculate sum of squares of distortion matrix gains
141 
142  // Calculate sum of squares of distortion matrix rotations
144 
145  // Get total number of the distortion parameters whose value is not fixed
146  int getNumDistortionParamsNotFixed() const;
147 
148  // Get types of distortion parameters whose value is not fixed
149  int getTypesOfDistortionParamsNotFixed( const int iParamsNotFixed ) const;
150 
151  // Copy the distortion parameters not fixed to vector
152  void copyDistortionParamsNotFixedToVector( double* vector ) const;
153 
154  // Copy previous distortion parameters not fixed to vector
155  void copyDistortionParamsNotFixedPreToVector( double* vector ) const;
156 
157  // Copy current distortion parameters to previous values
158  void copyDistortionParamsCurToPre() const;
159 
160  // Calculate full updated values of distortion parameters
161  void calcDistortionParamsUpdatedFullFromIncrements( const double* const distortionParamIncre );
162 
163  // Update distortion parameters
164  void updateDistortionParams();
165 
166  // Output distortion parametersto file
167  void outputDistortionParams( const int iterNum ) const;
168 
169  // Output information of locations of observed stations to vtk file
171 
172  // Output induction arrow to vtk file
173  void outputInductionArrowToVtk( const int iterNum ) const;
174 
175  // Find and return frequency IDs from frequency value
176  int getFreqIDs( const double freq ) const;
177 
178 private:
179  // Constructer
180  ObservedData();
181 
182  // Destructer
183  ~ObservedData();
184 
185  // Copy constructer
187 
188  // Copy assignment operator
190 
191  // Number of all stations
193 
194  // Number of usual MT stations
196 
197  // Number of usual apparent resistivity and phase stations
199 
200  // Number of HTF stations
202 
203  // Number of VTF stations
205 
206  // Number of PT stations
208 
209  // Number of NMT (line) stations
211 
212  // Number of NMT (triangle area) stations
214 
215  // Number of NMT (triangle area) stations using apparent resistivity and phase stations
217 
218  // Number of additional output points
220 
221  // Number of interpolator vectors
223 
224  // Map : key = station ID, value = Types of stations
225  std::map<int,int> m_stationID2type;
226 
227  // Map : key = station ID, value = IDs among each station type of all stations
229 
230  // All frequencies for which observed data exists
231  std::vector<double> m_frequencyAll;
232 
233  // Total number of frequencies calculated by this PE
235 
236  // IDs of frequencies calculated by this PE
238 
239  // Values of Frequencies calculated by this PE
241 
242  // Observed data of MT station
244 
245  // Observed data of apparent resistivity and phase stations
247 
248  // Observed data of HTF station
250 
251  // Observed data of VTF station
253 
254  // Observed data of PT station
256 
257  // Observed data of NMT station ( line )
259 
260  // Observed data of NMT station ( triangle area )
262 
263  // Observed data of NMT station ( triangle area ) using apparent resistivity and phase
265 
266  // Additional output points
268 
269  // Number of data
271 
272  // Types of distortion parameters whose value is not fixed
274 
275  // Add new frequency to the array of all frequencies for which observed data exists after checking
276  // wheter inputed frequency have not been contained
277  void checkAndAddNewFrequency( const double freq );
278 
279  // Check whether magnetic field value of the specified station is used to calculate response functions of the specified frequency
280  bool isUseMagneticFieldOfTheStation( const double freq, const int staID );
281 
282  // Get instance of the station where magnetic field is observed
283  ObservedDataStationPoint* getInstanceOfMagneticStation( const int IDOfMagSta ) const;
284 
285  // Calculate total number of components of distortion parameters whose value is not fixed
287 
288 };
289 
290 #endif
Definition: AdditinalOutputPoint.h:34
Definition: Forward3D.h:37
Definition: ObservedDataStationApparentResistivityAndPhase.h:36
Definition: ObservedDataStationHTF.h:36
Definition: ObservedDataStationMT.h:36
Definition: ObservedDataStationNMT2ApparentResistivityAndPhase.h:36
Definition: ObservedDataStationNMT2.h:37
Definition: ObservedDataStationNMT.h:37
Definition: ObservedDataStationPT.h:36
Definition: ObservedDataStationPoint.h:33
Definition: ObservedDataStationVTF.h:36
Definition: ObservedData.h:45
void calculateEMFieldOfAllStations(const Forward3D *const ptrForward3D, const double freq, const int iPol, const int ifreq)
Definition: ObservedData.cpp:1029
ObservedData(const ObservedData &rhs)
int getNumInterpolatorVectors() const
Definition: ObservedData.cpp:1635
void calcDistortionParamsUpdatedFullFromIncrements(const double *const distortionParamIncre)
Definition: ObservedData.cpp:2037
ObservedDataStationNMT * m_observedStationNMT
Definition: ObservedData.h:258
int * m_numObservedDataThisPEAccumulated
Definition: ObservedData.h:270
double getFrequencyValue(const int num) const
Definition: ObservedData.cpp:681
void copyDistortionParamsNotFixedToVector(double *vector) const
Definition: ObservedData.cpp:1957
void copyDistortionParamsNotFixedPreToVector(double *vector) const
Definition: ObservedData.cpp:1985
void updateDistortionParams()
Definition: ObservedData.cpp:2094
void inputObservedData()
Definition: ObservedData.cpp:155
int m_numAllStations
Definition: ObservedData.h:192
void calcNumDistortionParamsNotFixed()
Definition: ObservedData.cpp:878
double calculateSumSquareOfDistortionMatrixRotations() const
Definition: ObservedData.cpp:1922
void outputInductionArrowToVtk(const int iterNum) const
Definition: ObservedData.cpp:2417
ObservedDataStationPoint * getInstanceOfMagneticStation(const int IDOfMagSta) const
Definition: ObservedData.cpp:829
int m_numStationsNMT2
Definition: ObservedData.h:213
int incrementNumInterpolatorVectors()
Definition: ObservedData.cpp:1674
void outputLocationsOfObservedStationsToVtk() const
Definition: ObservedData.cpp:2188
int getNumObservedDataThisPE(const int ifreq) const
Definition: ObservedData.cpp:1645
int getTotalNumberOfDifferenetFrequencies() const
Definition: ObservedData.cpp:674
int getNumObservedDataThisPEAccumulated(const int num) const
Definition: ObservedData.cpp:1660
int m_numStationsVTF
Definition: ObservedData.h:204
ObservedDataStationVTF * m_observedStationVTF
Definition: ObservedData.h:252
double * m_valuesOfFrequenciesCalculatedByThisPE
Definition: ObservedData.h:240
void calculateInterpolatorVectors(Forward3D *const ptrForward3D, const double freq)
Definition: ObservedData.cpp:1444
int m_numInterpolatorVectors
Definition: ObservedData.h:222
std::map< int, int > m_stationID2IDAmongEachStationType
Definition: ObservedData.h:228
void initializeResponseFunctionsAndErrorsOfAllStations()
Definition: ObservedData.cpp:1203
ObservedDataStationApparentResistivityAndPhase * m_observedStationApparentResistivityAndPhase
Definition: ObservedData.h:246
bool isUseMagneticFieldOfTheStation(const double freq, const int staID)
Definition: ObservedData.cpp:758
int m_numStationsNMT
Definition: ObservedData.h:210
void calculateResponseFunctionOfAllStations(const int freqIDAmongThisPE)
Definition: ObservedData.cpp:1144
void multiplyMatrixByScaledData(const int nRow, const double *const matIn, const double *const vecIn, double *vecOut) const
void outputCalculatedValuesOfAllStations() const
Definition: ObservedData.cpp:1302
int * m_IDsOfFrequenciesCalculatedByThisPE
Definition: ObservedData.h:237
void outputDistortionParams(const int iterNum) const
Definition: ObservedData.cpp:2109
int getIDsOfFrequenciesCalculatedByThisPE(const int num) const
Definition: ObservedData.cpp:1789
ObservedData & operator=(const ObservedData &rhs)
int getNumDistortionParamsNotFixed() const
Definition: ObservedData.cpp:1943
ObservedDataStationMT * m_observedStationMT
Definition: ObservedData.h:243
ObservedDataStationPT * m_observedStationPT
Definition: ObservedData.h:255
int m_numStationsApparentResistivityAndPhase
Definition: ObservedData.h:198
AdditinalOutputPoint * m_additinalOutputPoint
Definition: ObservedData.h:267
void calculateResidualVectorOfDataThisPE(double *const vector) const
Definition: ObservedData.cpp:1583
typeID
Definition: ObservedData.h:52
@ VTF
Definition: ObservedData.h:55
@ NMT2_APP_RES_AND_PHS
Definition: ObservedData.h:60
@ APP_RES_AND_PHS
Definition: ObservedData.h:59
@ PT
Definition: ObservedData.h:56
@ NMT
Definition: ObservedData.h:57
@ NMT2
Definition: ObservedData.h:58
@ HTF
Definition: ObservedData.h:54
@ MT
Definition: ObservedData.h:53
static ObservedData * getInstance()
Definition: ObservedData.cpp:44
double calculateErrorSumOfSquaresThisPE() const
Definition: ObservedData.cpp:1816
void calcFrequenciesCalculatedByThisPE()
Definition: ObservedData.cpp:1679
int getNumObservedDataThisPETotal() const
Definition: ObservedData.cpp:1640
int getNumOfFrequenciesCalculatedByThisPE() const
Definition: ObservedData.cpp:1784
std::vector< int > m_typesOfDistortionParamsNotFixed
Definition: ObservedData.h:273
std::map< int, int > m_stationID2type
Definition: ObservedData.h:225
int m_numAdditinalOutputPoint
Definition: ObservedData.h:219
ObservedDataStationHTF * m_observedStationHTF
Definition: ObservedData.h:249
void copyDistortionParamsCurToPre() const
Definition: ObservedData.cpp:2011
int m_numStationsNMT2ApparentResistivityAndPhase
Definition: ObservedData.h:216
std::vector< double > m_frequencyAll
Definition: ObservedData.h:231
double calculateSumSquareOfDistortionMatrixComplexity() const
Definition: ObservedData.cpp:1863
double calculateSumSquareOfDistortionMatrixGains() const
Definition: ObservedData.cpp:1892
ObservedDataStationNMT2ApparentResistivityAndPhase * m_observedStationNMT2ApparentResistivityAndPhase
Definition: ObservedData.h:264
void allocateMemoryForCalculatedValuesOfAllStations()
Definition: ObservedData.cpp:1244
ObservedData()
Definition: ObservedData.cpp:50
~ObservedData()
Definition: ObservedData.cpp:82
double getValuesOfFrequenciesCalculatedByThisPE(const int num) const
Definition: ObservedData.cpp:1803
int getTypesOfDistortionParamsNotFixed(const int iParamsNotFixed) const
Definition: ObservedData.cpp:1950
int m_numStationsHTF
Definition: ObservedData.h:201
void findElementIncludingEachStation()
Definition: ObservedData.cpp:695
int m_numStationsMT
Definition: ObservedData.h:195
void calculateSensitivityMatrix(const std::complex< double > *const derivativesOfEMFieldExPol, const std::complex< double > *const derivativesOfEMFieldEyPol, const double freq, const int nModel, double *const sensitivityMatrix) const
Definition: ObservedData.cpp:1513
void checkAndAddNewFrequency(const double freq)
Definition: ObservedData.cpp:737
ObservedDataStationNMT2 * m_observedStationNMT2
Definition: ObservedData.h:261
int getFreqIDs(const double freq) const
Definition: ObservedData.cpp:2526
void inputDistortionMatrixData()
Definition: ObservedData.cpp:494
int m_numOfFrequenciesCalculatedByThisPE
Definition: ObservedData.h:234
int m_numStationsPT
Definition: ObservedData.h:207