Geophysical Inversion and Modelling Library v1.5.4
Loading...
Searching...
No Matches
dcfemmodelling.h
1/******************************************************************************
2 * Copyright (C) 2006-2024 by the resistivity.net development team *
3 * Carsten Rücker carsten@resistivity.net *
4 * *
5 * Licensed under the Apache License, Version 2.0 (the "License"); *
6 * you may not use this file except in compliance with the License. *
7 * You may obtain a copy of the License at *
8 * *
9 * http://www.apache.org/licenses/LICENSE-2.0 *
10 * *
11 * Unless required by applicable law or agreed to in writing, software *
12 * distributed under the License is distributed on an "AS IS" BASIS, *
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14 * See the License for the specific language governing permissions and *
15 * limitations under the License. *
16 * *
17 ******************************************************************************/
18
19#ifndef _BERT_DCFEMMODDELING__H
20#define _BERT_DCFEMMODDELING__H
21
22#include "bert.h"
23#include "datamap.h"
24
25#include <modellingbase.h>
26#include <sparsematrix.h>
27#include <pos.h>
28#include <matrix.h>
29
30#include <vector>
31
32namespace GIMLI{
33
35DLLEXPORT void dcfemDomainAssembleStiffnessMatrix(RSparseMatrix & S, const Mesh & mesh,
36 double k=0.0, bool fix=true);
37
38DLLEXPORT void dcfemDomainAssembleStiffnessMatrix(CSparseMatrix & S, const Mesh & mesh,
39 double k=0.0, bool fix=true);
40
41// DLLEXPORT void assembleStiffnessMatrixHomogenDirichletBC(RSparseMatrix & S,
42// const IndexArray & nodeID);
43
44DLLEXPORT double mixedBoundaryCondition(const Boundary & boundary,
45 const RVector3 & sourcePos,
46 double k=0.0);
47
48DLLEXPORT void assembleCompleteElectrodeModel(RSparseMatrix & S,
49 const std::vector < ElectrodeShape * > & elecs,
50 uint oldMatSize, bool lastIsReferenz,
51 const RVector & contactImpedances);
52
62DLLEXPORT void setComplexResistivities(Mesh & mesh, const CVector & res);
63
69DLLEXPORT void setComplexResistivities(Mesh & mesh,
70 const std::map < float, Complex > & aMap);
71
77DLLEXPORT void setComplexResistivities(Mesh & mesh,
78 const RVector & amp,
79 const RVector & phase);
80
83DLLEXPORT CVector getComplexResistivities(const Mesh & mesh);
84
88DLLEXPORT void setComplexData(DataContainer & data, const CVector & u);
89
94DLLEXPORT void setComplexData(DataContainer & data,
95 const RVector & re, const RVector & im);
96
102DLLEXPORT CVector getComplexData(const DataContainer & data);
103
104
105class DLLEXPORT DCMultiElectrodeModelling : public GIMLI::ModellingBase {
106public:
107 DCMultiElectrodeModelling(bool verbose=false);
108
109 DCMultiElectrodeModelling(Mesh & mesh,
110 bool verbose=false);
111
112 DCMultiElectrodeModelling(DataContainerERT & dataContainer,
113 bool verbose=false);
114
115 DCMultiElectrodeModelling(Mesh & mesh, DataContainerERT & dataContainer,
116 bool verbose=false);
117
118 virtual ~DCMultiElectrodeModelling();
119
129
130 void assembleStiffnessMatrixDCFEMByPass(RSparseMatrix & S);
131
132 void assembleStiffnessMatrixDCFEMByPass(CSparseMatrix & S);
133
134 virtual void createJacobian(const RVector & model);
135
136 virtual void createConstraints();
137
138 DataContainerERT & dataContainer() const ;
139
143 virtual RVector createDefaultStartModel();
144
145// RVector operator () (const RVector & model, double background=0) {
146// return response(model, background); }
147
153 void mapERTModel(const CVector & model, Complex background);
154
160 void mapERTModel(const RVector & model, double background);
161
164 virtual RVector response(const RVector & model){return response(model, -9e99);}
165
168 RVector response(const RVector & model, double background);
169
170 void createCurrentPattern(std::vector < ElectrodeShape * > & eA,
171 std::vector < ElectrodeShape * > & eB,
172 bool reciprocity);
173
174 virtual void calculate(DataMap & dMap);
175
176 virtual void calculate(DataContainerERT & data, bool reciprocity=false);
177
178 virtual void calculate(const std::vector < ElectrodeShape * > & eA,
179 const std::vector < ElectrodeShape * > & eB);
180
181 virtual void calculateK(const std::vector < ElectrodeShape * > & eA,
182 const std::vector < ElectrodeShape * > & eB,
183 RMatrix & solutionK, int kIdx);
184
185 virtual void calculateK(const std::vector < ElectrodeShape * > & eA,
186 const std::vector < ElectrodeShape * > & eB,
187 CMatrix & solutionK, int kIdx);
188
189 template < class ValueType >
190 void calculateKAnalyt(const std::vector < ElectrodeShape * > & eA,
191 const std::vector < ElectrodeShape * > & eB,
192 Matrix < ValueType > & solutionK,
193 double k, int kIdx) const;
194
195 void setTopography(bool topography) { topography_=topography; }
196 bool topography() const { return topography_; }
197
198 bool neumann() const { return neumannDomain_; }
199
201 void setComplex(bool c);
202
204 bool complex() const { return complex_; }
205
211 void setDipoleCurrentPattern(bool dipole) {dipoleCurrentPattern_=dipole;}
212
214 bool dipoleCurrentPattern() const { return dipoleCurrentPattern_; }
215
217 inline void setAnalytical(bool ana){ analytical_=ana; }
218 inline bool analytical() const { return analytical_; }
219
220 void collectSubPotentials(RMatrix & subSolutions){
221 subSolutions_=& subSolutions;
222 }
223
226 inline const std::map < Index, Index > & currentPatternIdxMap() const {
227 return currentPatternIdxMap_;
228 }
229
235 inline void setBypassMapFile(const std::string & fileName){
236 byPassFile_=fileName;
237 }
238
239 inline void setkValues(const RVector & v) { kValues_=v; }
240 inline const RVector & kValues() const { return kValues_; }
241
242 inline void setWeights(const RVector & v) { weights_=v; }
243 inline const RVector & weights() const { return weights_; }
244
245 inline const std::vector< ElectrodeShape * > & electrodes() const {
246 return electrodes_;
247 }
248
249 void setContactImpedances(const RVector & zi);
250
251 virtual RVector calcGeometricFactor(const DataContainerERT & data,
252 Index nModel=0);
253
254 virtual void preCalculate(const std::vector < ElectrodeShape * > & eA,
255 const std::vector < ElectrodeShape * > & eB){
256 }
257
260 void setSingValue(bool s=true) { setSingValue_=s;}
261
263 bool isSetSingValue() const { return setSingValue_;}
264
266 void setSolver(SolverWrapper *solver){ solver_ = solver; }
267
268private:
269 void init_();
270
271protected:
272
273 template < class ValueType >
274 void calculateK_(const std::vector < ElectrodeShape * > & eA,
275 const std::vector < ElectrodeShape * > & eB,
276 Matrix < ValueType > & solutionK, int kIdx);
277
278 template < class ValueType >
279 void assembleStiffnessMatrixDCFEMByPass_(SparseMatrix < ValueType > & S);
280
281 template < class ValueType >
282 DataMap response_(const Vector < ValueType > & model,
283 ValueType background);
284
285 template < class ValueType >
286 Matrix < ValueType > * prepareJacobianT_(const Vector< ValueType > & model);
287
288 RMatrix * prepareJacobian_(const RVector & model);
289 CMatrix * prepareJacobian_(const CVector & model);
290
291 void createJacobian_(const RVector & model, const RMatrix & u, RMatrix * J);
292 void createJacobian_(const CVector & model, const CMatrix & u, CMatrix * J);
293
294 virtual void deleteMeshDependency_();
295 virtual void updateMeshDependency_();
296 virtual void updateDataDependency_();
297
298 virtual void searchElectrodes_();
299
300 MatrixBase * subSolutions_;
301
302 bool complex_;
303
304 bool JIsRMatrix_;
305 bool JIsCMatrix_;
306
307 bool analytical_;
308 bool topography_;
309 bool neumannDomain_;
310 bool subpotOwner_;
311 bool lastIsReferenz_;
312 bool setSingValue_;
313
314 std::string byPassFile_;
315
316 RVector kValues_;
317 RVector weights_;
318
319 double surfaceZ_;
320
321 IndexArray calibrationSourceIdx_;
322 IndexArray bypassNodeIdx_;
323
324 std::vector< ElectrodeShape * > electrodes_;
325 ElectrodeShape * electrodeRef_;
326
327 std::vector< ElectrodeShape * > passiveCEM_;
328
329 RVector3 sourceCenterPos_;
330
331 bool buildCompleteElectrodeModel_;
332
333 bool dipoleCurrentPattern_;
334 std::map < Index, Index > currentPatternIdxMap_;
335
336 RMatrix potentialsCEM_;
337 RVector vContactImpedance_;
338
339 DataMap * primDataMap_;
340
341 SolverWrapper *solver_;
342};
343
344class DLLEXPORT DCSRMultiElectrodeModelling : public DCMultiElectrodeModelling {
345public:
346 DCSRMultiElectrodeModelling(bool verbose=false)
347 : DCMultiElectrodeModelling(verbose) {
348 init_();
349 }
350
351 DCSRMultiElectrodeModelling(Mesh & mesh, bool verbose=false)
352 : DCMultiElectrodeModelling(mesh, verbose) {
353 init_();
354 }
355
356 DCSRMultiElectrodeModelling(Mesh & mesh, DataContainerERT & dataContainer, bool verbose=false)
357 : DCMultiElectrodeModelling(mesh, dataContainer, verbose){
358 init_();
359 }
360
361 virtual ~DCSRMultiElectrodeModelling(){
362 if (primPot_ && primPotOwner_) delete primPot_;
363 if (primMesh_ && primMeshOwner_) delete primMesh_;
364 };
365
366 virtual void calculateK(const std::vector < ElectrodeShape * > & eA,
367 const std::vector < ElectrodeShape * > & eB,
368 RMatrix & solutionK, int kIdx);
369
370 inline void setPrimaryPotFileBody(const std::string & primPotFileBody){
371 primPotFileBody_=primPotFileBody;
372 }
373
374 inline void setPrimaryPotential(RMatrix & primPot) { primPot_=& primPot; }
375
376 inline RMatrix & primaryPotential() { return *primPot_; }
377
378 inline void setPrimaryMesh(Mesh & mesh){ primMesh_=&mesh; }
379
380 void setPrimaryMesh(const std::string & meshname);
381
382 inline Mesh & primaryMesh() {return *primMesh_; }
383
384 //const DataMap & primDataMap() const { return ; }
385
386 virtual void preCalculate(const std::vector < ElectrodeShape * > & eA,
387 const std::vector < ElectrodeShape * > & eB);
388
389private:
390 void init_(){
391 primPotFileBody_= NOT_DEFINED;
392
393 primPotOwner_ =false;
394 primPot_ =NULL;
395
396 primMeshOwner_ =false;
397 primMesh_ =NULL;
398 }
399
400protected:
401 virtual void updateMeshDependency_();
402 virtual void updateDataDependency_();
403
404 void checkPrimpotentials_(const std::vector < ElectrodeShape * > & eA,
405 const std::vector < ElectrodeShape * > & eB);
406
407 std::string primPotFileBody_;
408
409 bool primPotOwner_;
410 RMatrix * primPot_;
411
412 bool primMeshOwner_;
413 Mesh * primMesh_;
414 Mesh mesh1_;
415};
416
417} //namespace BERT
418
419#endif // _BERT_DCFEMMODDELING__H
Definition meshentities.h:350
void setSingValue(bool s=true)
Definition dcfemmodelling.h:260
virtual void createJacobian(const RVector &model)
Definition dcfemmodelling.cpp:1446
void setDipoleCurrentPattern(bool dipole)
Definition dcfemmodelling.h:211
bool dipoleCurrentPattern() const
Definition dcfemmodelling.h:214
void assembleStiffnessMatrixDCFEMByPass(RSparseMatrix &S)
Definition dcfemmodelling.cpp:593
void setAnalytical(bool ana)
Definition dcfemmodelling.h:217
bool isSetSingValue() const
Definition dcfemmodelling.h:263
bool complex() const
Definition dcfemmodelling.h:204
const std::map< Index, Index > & currentPatternIdxMap() const
Definition dcfemmodelling.h:226
void setBypassMapFile(const std::string &fileName)
Definition dcfemmodelling.h:235
virtual RVector createDefaultStartModel()
Definition dcfemmodelling.cpp:1075
void mapERTModel(const CVector &model, Complex background)
Definition dcfemmodelling.cpp:1199
virtual RVector response(const RVector &model)
Definition dcfemmodelling.h:164
void setSolver(SolverWrapper *solver)
Definition dcfemmodelling.h:266
void checkPrimpotentials_(const std::vector< ElectrodeShape * > &eA, const std::vector< ElectrodeShape * > &eB)
Definition dcfemmodelling.cpp:1986
virtual void preCalculate(const std::vector< ElectrodeShape * > &eA, const std::vector< ElectrodeShape * > &eB)
Definition dcfemmodelling.cpp:2143
Definition bertDataContainer.h:32
DataContainer to store, load and save data in the GIMLi unified data format.
Definition datacontainer.h:48
Definition datamap.h:31
Abstract class for an electrode with a shape, which is required for modelling.
Definition electrode.h:58
Interface class for matrices.
Definition matrix.h:137
Definition mesh.h:128
Definition modellingbase.h:31
bool verbose() const
Definition modellingbase.h:48
Definition solverWrapper.h:26
One dimensional array aka Vector of limited size.
Definition vector.h:186
GIMLi main namespace for the Geophyiscal Inversion and Modelling Library.
Definition baseentity.h:24
void setComplexResistivities(Mesh &mesh, const std::map< float, Complex > &aMap)
Definition dcfemmodelling.cpp:51
CVector getComplexData(const DataContainer &data)
Definition dcfemmodelling.cpp:105
CVector getComplexResistivities(const Mesh &mesh)
Definition dcfemmodelling.cpp:82
void setComplexData(DataContainer &data, const RVector &re, const RVector &im)
Definition dcfemmodelling.cpp:92