FEMTIC
ResistivityBlock.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_RESISTIVITY_BLOCK
25 #define DBLDEF_RESISTIVITY_BLOCK
26 
27 #include "AnalysisControl.h"
28 #include "RougheningSquareMatrix.h"
29 
30 #include <vector>
31 
32 // Class of resistivity blocks
34 
35 public:
36 
42  };
43 
47  };
48 
49  // Return the the instance of the class
50  static ResistivityBlock* getInstance();
51 
52  // Read data of resisitivity block model from input file
54 
55  // Get resisitivity block ID from element ID
56  inline int getBlockIDFromElemID( const int ielem ) const{
57  return m_elementID2blockID[ ielem ];
58  };
59 
60  // Get resistivity values from resisitivity block ID
61  double getResistivityValuesFromBlockID( const int iblk ) const;
62 
63  // Get previous resistivity values from resisitivity block ID
64  double getResistivityValuesPreFromBlockID( const int iblk ) const;
65 
66  // Get conductivity values from resisitivity block ID
67  double getConductivityValuesFromBlockID( const int iblk ) const;
68 
69  // Get resistivity values from element ID
70  double getResistivityValuesFromElemID( const int ielem ) const;
71 
72  // Get conductivity values from element ID
73  double getConductivityValuesFromElemID( const int ielem ) const;
74 
75  // Get model ID from block ID
76  int getModelIDFromBlockID( const int iblk ) const;
77 
78  // Get block ID from model ID
79  int getBlockIDFromModelID( const int imdl ) const;
80 
81  // Get total number of resistivity blocks
82  int getNumResistivityBlockTotal() const;
83 
84  // Get number of resistivity blocks whose resistivity values are not fixed
86 
87  // Get flag specifing whether bottom resistivity is included in roughning
88  bool includeBottomResistivity() const;
89 
90  // Get resistivity of the bottom of the model
91  double getBottomResistivity() const;
92 
93  // Get roughning factor at the bottom of the model
94  double getRoughningFactorAtBottom() const;
95 
96  // Get flag specifing whether small value is added to diagonals
98 
99  // Set small value added to diagonals
100  double getSmallValueAddedToDiagonals() const;
101 
102  // Get minimum distance between current resistivity and resistivity bounds in common logarithm scale
103  double getMinDistanceToBounds() const;
104 
105  // Get type of bound constraints
106  int getTypeBoundConstraints() const;
107 
108  // Get positive real factor of inverse distance weighting
109  double getInverseDistanceWeightingFactor() const;
110 
111  // Set flag specifing whether bottom resistivity is included in roughning
112  void setFlagIncludeBottomResistivity( bool include );
113 
114  // Set resistivity of the bottom of the model
115  void setBottomResistivity( const double resistivity );
116 
117  // Set roughning factor at the bottom of the model
118  void setRoughningFactorAtBottom( const double factor );
119 
120  // Set flag specifing whether small value is added to diagonals
121  void setFlagAddSmallValueToDiagonals( const bool flag );
122 
123  // Set small value added to bottom
124  void setSmallValueAddedToDiagonals( const double value );
125 
126  // Set minimum distance to resistivity bounds in common logarithm scale
127  void setMinDistanceToBounds( const double distance );
128 
129  // Set type of bound constraints
130  void setTypeBoundConstraints( const int type );
131 
132  // Set positive real factor of inverse distance weighting
133  void setInverseDistanceWeightingFactor( const double factor );
134 
135  // Get flag specifing whether resistivity value of each block is fixed or not
136  bool isFixedResistivityValue( const int iblk ) const;
137 
138  // Get flag specifing whether resistivity block is excluded from roughing matrix
139  bool isolated( const int iblk ) const;
140 
141  // Calculate volume of the specified resistivity block
142  double calcVolumeOfBlock( int iblk ) const;
143 
144  // Calculate pre-degenerated roughning matrix
145  void calcRougheningMatrix();
146 
147  // Calculate roughning matrix degenerated for laplacian filter
148  void calcRougheningMatrixDegeneratedForLaplacianFilter( DoubleSparseMatrix& rougheningMatrixDegenerated, const double factor ) const;
149 
150  // Calculate roughning matrix degenerated for difference filter
151  void calcRougheningMatrixDegeneratedForDifferenceFilter( const double factor,
152  std::vector< std::pair<int,int> >& nonZeroCols, std::vector<double>& matValues, std::vector<double>& rhsValues ) const;
153 
154  // Calculate array of resistivity values obtained by inversion which is the ones fully updated ( damping factor = 1 )
155  // from common logarithm
156  void calctResistivityUpdatedFullFromLog10ResistivityIncres( const double* const log10resistivity );
157 
158  // Copy derivatives of logarithm of resistivities with respect to transformed model parameter x
159  void copyDerivativeLog10ResistivityWithRespectToX( double* derivs ) const;
160 
161  // Change resistivity values
163 
164  // Output resistivity values to VTK file
165  void outputResistivityValuesToVTK() const;
166 
167  // Output resistivity values to binary file
168  void outputResistivityValuesToBinary( const int iterNum ) const;
169 
170  // Output data of resisitivity block model to file
171  void outputResisitivityBlock( const int iterNum ) const;
172 
173  // Copy common logarithm of free resistivity values to vector
174  void copyResistivityValuesNotFixedToVectorLog10( double* vector ) const;
175 
176  // Copy common logarithm of previous free resistivity values to vector
177  void copyResistivityValuesNotFixedPreToVectorLog10( double* vector ) const;
178 
179  // Copy common logarithm of current free resistivity values to previous ones
181 
182  // Calculate model roughness for laplacian filter
184 
185  // Calculate model roughness for difference filter
187 
188  // Calculate model roughness at the bottom
189  double calcModelRoughnessAtBottom() const;
190 
191  // Copy common logarithm of resistivity values
192  void copyResistivityValuesToVectorLog10( double* vector ) const;
193 
195  //void addProductOfSensitivityMatrixAndModelVector( const double senMat, const int numData, double* vecOut ) const;
196 
198  //const double* const getResistivityValues() const;
199 
200  // Output resistivity data to VTK file
201  void outputResistivityDataToVTK() const;
202 
203  // Output resistivity data to binary file
204  void outputResistivityDataToBinary() const;
205 
207  //const std::vector<int>& getBlockID2Elements( const int iBlk ) const;
208  // Get arrays of elements belonging to each resistivity model
209  //const std::vector<int>& getBlockID2Elements( const int iBlk ) const;
210  const std::vector< std::pair<int,double> >& getBlockID2Elements( const int iBlk ) const;
211 
212 #ifdef _ANISOTOROPY
214  //void calcAisotropyCoefficientRotated( const int iBlk, CommonParameters::Vector3D& coeffX, CommonParameters::Vector3D& coeffY, CommonParameters::Vector3D& coeffZ ) const;
215 
216  // Calculate anisotropic conductivity tensor
217  //void calcAisotropicConductivityTensor( const int blockID, CommonParameters::Vector3D& matX, CommonParameters::Vector3D& matY, CommonParameters::Vector3D& matZ ) const;
218  void calcAisotropicConductivityTensor( const int blockID, double conductivityTensor[3][3] ) const;
219 #endif
220 
221 private:
222 
223  // Constructer
225 
226  // Destructer
228 
229  // Copy constructer
231  std::cerr << "Error : Copy constructer of the class ResistivityBlock is not implemented." << std::endl;
232  exit(1);
233  };
234 
235  // Assignment operator
237  std::cerr << "Error : Assignment operator of the class ResistivityBlock is not implemented." << std::endl;
238  exit(1);
239  };
240 
241  // Array of the resistivity block IDs of each element
243 
244  // Array convert IDs of resistivity block to model IDs
246 
247  // Array convert model IDs to IDs of resistivity block
249 
250  // Total number of resistivity blocks
252 
253  // Number of resistivity blocks whose resistivity values are fixed
255 
256  // Array of resistivity values of each block
258 
259  // Array of previous resistivity values of each block
261 
262  // Array of resistivity values obtained by inversion which is the ones fully updated ( damping factor = 1 )
264 
265  // Array of minimum resistivity values of each block
267 
268  // Array of maximum resistivity values of each block
270 
271  // Positive constant parameter n
273 
274  // Flag specifing whether resistivity value of each block is fixed or not
276 
277  // Flag specifing whether resistivity block is excluded from roughing matrix
278  bool* m_isolated;
279 
280 #ifdef _ANISOTOROPY
281  // Anisotoropy coefficient
282  //CommonParameters::Vector3D* m_anisotoropyCoeff;
283 
284  // Array mapping block IDs to indexes of the blocks where anisotropic conductivity tensor components are specified
285  std::map<int, int> m_mapBlockIDWithAnisotropyToIndex;
286 
287  // Array of the current components of resistivity tensor of axial anisotropy
288  std::vector<CommonParameters::Vector3D> m_resistivityValuesAxialAnisotropy;
289 
290  // Array of the previous components of resistivity tensor of axial anisotropy
291  std::vector<CommonParameters::Vector3D> m_resistivityValuesAxialAnisotropyPre;
292 
293  // Array of the current XX components of resistivity tensor obtained by inversion which is the ones fully updated ( damping factor = 1 )
294  std::vector<CommonParameters::Vector3D> m_resistivityValuesAxialAnisotropyFull;
295 
296  // Axial anisotropy strike angles
297  std::vector<double> m_axialAnisotropyStrileAngle;
298 
299  // Axial anisotropy dip angles
300  std::vector<double> m_axialAnisotropyDipAngle;
301 
302  // Axial anisotropy slant angles
303  std::vector<double> m_axialAnisotropySlantAngle;
304 #endif
305 
306  // Roughening matrix
308 
309  // Arrays of elements belonging to each resistivity model
310  std::vector< std::pair<int,double> >* m_blockID2Elements;
311 
312  // Flag specifing whether bottom resistivity is included in roughning
314 
315  // Resistivity of the bottom of the model
317 
318  // Roughning factor at the bottom of the model
320 
321  // Flag specifing whether small value is added to diagonals
323 
324  // Small value added to bottom
326 
327  // Type of bound constraints
329 
330  // Minimum distance between current resistivity and resistivity bounds in common logarithm scale
332 
333  // Positive real factor of inverse distance weighting
335 
336  // Calculate weighting factor
337  double calWeightingFactor( const double alphaX, const double alphaY, const double alphaZ, const int iElem1, const int iElem2 ) const;
338 
339  // Get type of resistivity block
340  int getTypeOfResistivityBlock( const bool fixed, const bool isolated ) const;
341 
342  // Calculate roughening matrix with using elements share faces
343  void calcRougheningMatrixUsingElementsShareFaces( const double factor );
344 
345  // Calculate roughening matrix with using elements share faces using area-volume ratio as weights
347 
348  // Calculate roughening matrix with using resistivty blocks share faces
349  void calcRougheningMatrixUsingResistivityBlocksShareFaces( const double factor );
350 
351  // Calculate roughning matrix from user-defined roughning factor
352  void calcRougheningMatrixUserDefined( const double factor );
353 
354  // Add contribution of bottom resistivity to roughning matrix
356 
357  // Add small value to diagonals
359 
360  // Calculate transformed model parameter x from resistivity
361  double calcTransformedModelParameterFromResistivity( const int iBlk, const double resistivity ) const;
362 
363  // Calculate transformed model parameter x from common logarithm of resistivity
364  double calcTransformedModelParameterFromLog10Resistivity( const int iBlk, const double log10Resistivity ) const;
365 
366  // Calculate resistivity from transformed model parameter x
367  double calcResistivityFromTransformedModelParameter( const int iBlk, const double x ) const;
368 
369  // Calculate common logarithm of resistivity from transformed model parameter x
370  double calcLog10ResistivityFromTransformedModelParameter( const int iBlk, const double x ) const;
371 
372  // Calculate derivative of logarithm of resistivity with respect to transformed model parameter x
373  double calcDerivativeLog10ResistivityWithRespectToX( const int iBlk ) const;
374 
375  // Calculate derivative of transformed model parameter x with respect to logarithm of resistivity
376  double calcDerivativeXWithRespectToLog10Resistivity( const int iBlk ) const;
377 
378 };
379 
380 #endif
Definition: DoubleSparseMatrix.h:29
Definition: ResistivityBlock.h:33
void setBottomResistivity(const double resistivity)
Definition: ResistivityBlock.cpp:702
void inputResisitivityBlock()
Definition: ResistivityBlock.cpp:139
double getBottomResistivity() const
Definition: ResistivityBlock.cpp:670
void calcRougheningMatrixUserDefined(const double factor)
Definition: ResistivityBlock.cpp:1873
void copyResistivityValuesNotFixedCurToPre() const
Definition: ResistivityBlock.cpp:1410
int getNumResistivityBlockTotal() const
Definition: ResistivityBlock.cpp:659
~ResistivityBlock()
Definition: ResistivityBlock.cpp:74
void setMinDistanceToBounds(const double distance)
Definition: ResistivityBlock.cpp:722
void outputResistivityDataToBinary() const
Definition: ResistivityBlock.cpp:1048
double getRoughningFactorAtBottom() const
Definition: ResistivityBlock.cpp:673
bool includeBottomResistivity() const
Definition: ResistivityBlock.cpp:667
int m_numResistivityBlockTotal
Definition: ResistivityBlock.h:251
void outputResistivityValuesToBinary(const int iterNum) const
Definition: ResistivityBlock.cpp:1318
double m_smallValueAddedToDiagonals
Definition: ResistivityBlock.h:325
double getResistivityValuesPreFromBlockID(const int iblk) const
Definition: ResistivityBlock.cpp:588
const std::vector< std::pair< int, double > > & getBlockID2Elements(const int iBlk) const
Definition: ResistivityBlock.cpp:1090
void addSmallValueToDiagonals()
Definition: ResistivityBlock.cpp:2019
void copyDerivativeLog10ResistivityWithRespectToX(double *derivs) const
Definition: ResistivityBlock.cpp:969
int getModelIDFromBlockID(const int iblk) const
Definition: ResistivityBlock.cpp:635
double getSmallValueAddedToDiagonals() const
Definition: ResistivityBlock.cpp:681
double calcLog10ResistivityFromTransformedModelParameter(const int iBlk, const double x) const
Definition: ResistivityBlock.cpp:2056
double getMinDistanceToBounds() const
Definition: ResistivityBlock.cpp:686
double getConductivityValuesFromElemID(const int ielem) const
Definition: ResistivityBlock.cpp:628
void updateResistivityValues()
Definition: ResistivityBlock.cpp:977
void setTypeBoundConstraints(const int type)
Definition: ResistivityBlock.cpp:728
void calcRougheningMatrixDegeneratedForDifferenceFilter(const double factor, std::vector< std::pair< int, int > > &nonZeroCols, std::vector< double > &matValues, std::vector< double > &rhsValues) const
Definition: ResistivityBlock.cpp:867
double * m_resistivityValuesUpdatedFull
Definition: ResistivityBlock.h:263
double calcResistivityFromTransformedModelParameter(const int iBlk, const double x) const
Definition: ResistivityBlock.cpp:2049
double * m_weightingConstants
Definition: ResistivityBlock.h:272
ResistivityBlock()
Definition: ResistivityBlock.cpp:48
void setInverseDistanceWeightingFactor(const double factor)
Definition: ResistivityBlock.cpp:738
void addBottomResistivityContribution()
Definition: ResistivityBlock.cpp:1928
ResistivityBlock(const ResistivityBlock &rhs)
Definition: ResistivityBlock.h:230
double calcModelRoughnessForDifferenceFilter() const
Definition: ResistivityBlock.cpp:1430
void outputResistivityValuesToVTK() const
Definition: ResistivityBlock.cpp:1296
BoundconstrainingTypes
Definition: ResistivityBlock.h:44
@ TRANSFORMING_METHOD
Definition: ResistivityBlock.h:46
@ SIMPLE_BOUND_CONSTRAINING
Definition: ResistivityBlock.h:45
void setSmallValueAddedToDiagonals(const double value)
Definition: ResistivityBlock.cpp:717
double calcTransformedModelParameterFromResistivity(const int iBlk, const double resistivity) const
Definition: ResistivityBlock.cpp:2027
void outputResisitivityBlock(const int iterNum) const
Definition: ResistivityBlock.cpp:1361
int m_typeBoundConstraints
Definition: ResistivityBlock.h:328
void calcRougheningMatrixUsingElementsShareFaces(const double factor)
Definition: ResistivityBlock.cpp:1561
int * m_elementID2blockID
Definition: ResistivityBlock.h:239
double calcModelRoughnessForLaplacianFilter() const
Definition: ResistivityBlock.cpp:1417
void calctResistivityUpdatedFullFromLog10ResistivityIncres(const double *const log10resistivity)
Definition: ResistivityBlock.cpp:934
bool getFlagAddSmallValueToDiagonals() const
Definition: ResistivityBlock.cpp:676
double * m_resistivityValuesMax
Definition: ResistivityBlock.h:269
ResistivityBlock & operator=(const ResistivityBlock &rhs)
Definition: ResistivityBlock.h:236
bool isolated(const int iblk) const
Definition: ResistivityBlock.cpp:755
double calcTransformedModelParameterFromLog10Resistivity(const int iBlk, const double log10Resistivity) const
Definition: ResistivityBlock.cpp:2034
int * m_modelID2blockID
Definition: ResistivityBlock.h:248
double calcModelRoughnessAtBottom() const
Definition: ResistivityBlock.cpp:1481
void outputResistivityDataToVTK() const
Definition: ResistivityBlock.cpp:1028
void setFlagAddSmallValueToDiagonals(const bool flag)
Definition: ResistivityBlock.cpp:712
double m_bottomResistivity
Definition: ResistivityBlock.h:316
void calcRougheningMatrixUsingResistivityBlocksShareFaces(const double factor)
Definition: ResistivityBlock.cpp:1733
void calcRougheningMatrix()
Definition: ResistivityBlock.cpp:782
double * m_resistivityValuesMin
Definition: ResistivityBlock.h:266
int getBlockIDFromElemID(const int ielem) const
Definition: ResistivityBlock.h:56
int getNumResistivityBlockNotFixed() const
Definition: ResistivityBlock.cpp:662
bool isFixedResistivityValue(const int iblk) const
Definition: ResistivityBlock.cpp:743
void copyResistivityValuesNotFixedPreToVectorLog10(double *vector) const
Definition: ResistivityBlock.cpp:1403
int getTypeOfResistivityBlock(const bool fixed, const bool isolated) const
Definition: ResistivityBlock.cpp:1544
int getBlockIDFromModelID(const int imdl) const
Definition: ResistivityBlock.cpp:647
bool m_includeBottomResistivity
Definition: ResistivityBlock.h:313
std::vector< std::pair< int, double > > * m_blockID2Elements
Definition: ResistivityBlock.h:310
double getResistivityValuesFromElemID(const int ielem) const
Definition: ResistivityBlock.cpp:621
void calcRougheningMatrixDegeneratedForLaplacianFilter(DoubleSparseMatrix &rougheningMatrixDegenerated, const double factor) const
Definition: ResistivityBlock.cpp:839
double * m_resistivityValuesPre
Definition: ResistivityBlock.h:260
double m_inverseDistanceWeightingFactor
Definition: ResistivityBlock.h:334
double * m_resistivityValues
Definition: ResistivityBlock.h:257
void copyResistivityValuesToVectorLog10(double *vector) const
Definition: ResistivityBlock.cpp:1524
bool * m_isolated
Definition: ResistivityBlock.h:278
RougheningSquareMatrix m_rougheningMatrix
Definition: ResistivityBlock.h:307
double m_roughningFactorAtBottom
Definition: ResistivityBlock.h:319
double calWeightingFactor(const double alphaX, const double alphaY, const double alphaZ, const int iElem1, const int iElem2) const
Definition: ResistivityBlock.cpp:1531
double getResistivityValuesFromBlockID(const int iblk) const
Definition: ResistivityBlock.cpp:572
double calcVolumeOfBlock(int iblk) const
Definition: ResistivityBlock.cpp:763
void setRoughningFactorAtBottom(const double factor)
Definition: ResistivityBlock.cpp:707
ResistivityBlockTypes
Definition: ResistivityBlock.h:37
@ FREE_AND_CONSTRAINED
Definition: ResistivityBlock.h:38
@ FREE_AND_ISOLATED
Definition: ResistivityBlock.h:41
@ FIXED_AND_ISOLATED
Definition: ResistivityBlock.h:39
@ FIXED_AND_CONSTRAINED
Definition: ResistivityBlock.h:40
int getTypeBoundConstraints() const
Definition: ResistivityBlock.cpp:689
int * m_blockID2modelID
Definition: ResistivityBlock.h:245
double getConductivityValuesFromBlockID(const int iblk) const
Definition: ResistivityBlock.cpp:605
void copyResistivityValuesNotFixedToVectorLog10(double *vector) const
Definition: ResistivityBlock.cpp:1396
double getInverseDistanceWeightingFactor() const
Definition: ResistivityBlock.cpp:692
double calcDerivativeXWithRespectToLog10Resistivity(const int iBlk) const
Definition: ResistivityBlock.cpp:2082
bool m_addSmallValueToDiagonals
Definition: ResistivityBlock.h:322
bool * m_fixResistivityValues
Definition: ResistivityBlock.h:275
static ResistivityBlock * getInstance()
Definition: ResistivityBlock.cpp:42
int m_numResistivityBlockNotFixed
Definition: ResistivityBlock.h:254
double m_minDistanceToBounds
Definition: ResistivityBlock.h:331
void calcRougheningMatrixUsingElementsShareFacesWeightingByAreaVolumeRatio(const double factor)
Definition: ResistivityBlock.cpp:1637
double calcDerivativeLog10ResistivityWithRespectToX(const int iBlk) const
Definition: ResistivityBlock.cpp:2066
void setFlagIncludeBottomResistivity(bool include)
Definition: ResistivityBlock.cpp:697
Definition: RougheningSquareMatrix.h:30