Geophysical Inversion and Modelling Library v1.5.4
Loading...
Searching...
No Matches
modellingbase.h
1/******************************************************************************
2 * Copyright (C) 2005-2024 by the GIMLi 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 _GIMLI_MODELLINGBASE__H
20#define _GIMLI_MODELLINGBASE__H
21
22#include "gimli.h"
23#include "matrix.h"
24//#include "blockmatrix.h"
25
26namespace GIMLI{
27
28//class H2SparseMapMatrix;
29
31class DLLEXPORT ModellingBase{
32public:
33
34 ModellingBase(bool verbose=false) ;
35
36 ModellingBase(DataContainer & dataContainer, bool verbose=false);
37
38 ModellingBase(const Mesh & mesh, bool verbose=false);
39
40 ModellingBase(const Mesh & mesh, DataContainer & dataContainer, bool verbose=false);
41
42 virtual ~ModellingBase();
43
45 void setVerbose(bool verbose);
46
48 inline bool verbose() const {return verbose_;}
49
50 virtual RVector response(const RVector & model) {
51 throwError(WHERE_AM_I + " you need to implement a response "
52 "function.");
53 return RVector(0);
54 }
55
58 virtual RVector response_mt(const RVector & model, Index i=0) const {
59 throwError(WHERE_AM_I + " if you want to use read only response "
60 "function to use in multi threading environment .. you need to "
61 " implement me");
62 return RVector(0);
63 }
64
65 inline RVector operator() (const RVector & model){ return response(model); }
66
68 void setData(DataContainer & data);
69
71 DataContainer & data() const;
72
74 virtual RVector createDefaultStartModel() { return RVector(0); }
75
80 virtual RVector startModel();
81
82 virtual void setStartModel(const RVector & startModel);
83
86 void setMesh(const Mesh & mesh, bool ignoreRegionManager=false);
87
88 inline Mesh * mesh() { return mesh_; }
89
90 void createRefinedForwardMesh(bool refine=true, bool pRefine=false);
91
93 void deleteMesh();
94
96 virtual void setJacobian(MatrixBase * J);
97
99 virtual void createJacobian(const RVector & model);
100
105 virtual void createJacobian(const RVector & model, const RVector & resp);
106
112 virtual void createJacobian_mt(const RVector & model, const RVector & resp);
113
115 virtual void initJacobian();
116
118 MatrixBase * jacobian() { return jacobian_; }
119
121 MatrixBase * jacobian() const { return jacobian_; }
122
126 virtual RMatrix & jacobianRef() const {
127 if (! jacobian_) {
128 throwError(WHERE_AM_I + " Jacobian matrix is not initialized.");
129 }
130 return *dynamic_cast< RMatrix * >(jacobian_);
131 }
132
133 virtual RMatrix & jacobianRef() {
134 if (! jacobian_) {
135 throwError(WHERE_AM_I + " Jacobian matrix is not initialized.");
136 }
137 return *dynamic_cast< RMatrix * >(jacobian_);
138 }
139
141 virtual void clearJacobian(){ jacobian_->clear(); }
142
144// inline void setConstraintMatrix(const RSparseMapMatrix & C){ C_ = C; }
145// inline const RSparseMapMatrix & constraintMatrix() const { return C_; }
146// /*! Clear Constraints matrix */
147 virtual void setConstraints(MatrixBase * C);
148
149 virtual void clearConstraints();
150
151 virtual void initConstraints();
152
153 virtual void createConstraints();
154
155 virtual MatrixBase * constraints();
156
157 virtual MatrixBase * constraints() const;
158
159 virtual RSparseMapMatrix & constraintsRef() const;
160
161 virtual RSparseMapMatrix & constraintsRef();
162
163 const RMatrix & solution() const { return solutions_; }
164
165 void mapModel(const RVector & model, double background=0);
166
171 RVector createMappedModel(const RVector & model, double background=-9e99) const;
172
173 void setRegionManager(RegionManager * reg);
174
175 const RegionManager & regionManager() const;
176
177 RegionManager & regionManager();
178
179 RegionManager & regionManagerRef(){ return regionManager(); }
180
181 bool verbose() { return verbose_; }
182
184 Region * region(int marker);
185
186
187 RVector createStartModel();
188
190 RVector createStartVector();
191
192 void initRegionManager();
193
197 void setThreadCount(Index nThreads);
198
200 Index threadCount();
201
207 void setMultiThreadJacobian(Index nThreads);
208
210 inline Index multiThreadJacobian() const { return nThreadsJacobian_; }
211
212
213protected:
214
215 virtual void init_();
216
217 virtual void deleteMeshDependency_(){}
218
219 virtual void updateMeshDependency_(){}
220
221 virtual void updateDataDependency_(){}
222
223 void setMesh_(const Mesh & mesh, bool update=true);
224
225 Mesh * mesh_;
226
227 DataContainer * dataContainer_;
228
229 MatrixBase * jacobian_;
230 bool ownJacobian_;
231
232 MatrixBase * constraints_;
233 bool ownConstraints_;
234
235 RMatrix solutions_;
236
237 RVector startModel_;
238
239 bool verbose_;
240
241 bool regionManagerInUse_;
242 bool ownRegionManager_;
243
244 Index nThreads_;
245 Index nThreadsJacobian_;
246
247private:
248 RegionManager * regionManager_;
249
250};
251
255class DLLEXPORT LinearModelling : public ModellingBase {
256public:
257 LinearModelling(Mesh & mesh, MatrixBase & A, bool verbose=false)
258 : ModellingBase(mesh, verbose){
259 setJacobian(&A);
260 }
261
262 LinearModelling(Mesh & mesh, MatrixBase * A, bool verbose=false)
263 : ModellingBase(mesh, verbose){
264 setJacobian(A);
265 }
266
267 LinearModelling(MatrixBase & A, bool verbose=false);
268
269 virtual ~LinearModelling() { }
270
272 RVector response(const RVector & model);
273
274 virtual void createJacobian(const RVector & model);
275
276 RVector createDefaultStartModel();
277
278protected:
279
280};
281
282
283
284} // namespace GIMLI
285
286#endif // MODELLINGBASE__H
DataContainer to store, load and save data in the GIMLi unified data format.
Definition datacontainer.h:48
RVector response(const RVector &model)
Definition modellingbase.cpp:565
virtual void createJacobian(const RVector &model)
Definition modellingbase.cpp:574
RVector createDefaultStartModel()
Definition modellingbase.cpp:576
Interface class for matrices.
Definition matrix.h:137
Definition mesh.h:128
bool verbose() const
Definition modellingbase.h:48
MatrixBase * jacobian() const
Definition modellingbase.h:121
virtual void clearJacobian()
Definition modellingbase.h:141
void setVerbose(bool verbose)
Definition modellingbase.cpp:88
virtual void setJacobian(MatrixBase *J)
Definition modellingbase.cpp:225
virtual RVector createDefaultStartModel()
Definition modellingbase.h:74
virtual RMatrix & jacobianRef() const
Definition modellingbase.h:126
MatrixBase * jacobian()
Definition modellingbase.h:118
virtual RVector response_mt(const RVector &model, Index i=0) const
Definition modellingbase.h:58
Index multiThreadJacobian() const
Definition modellingbase.h:210
GIMLi main namespace for the Geophyiscal Inversion and Modelling Library.
Definition baseentity.h:24
void setThreadCount(Index nThreads)
Definition gimli.cpp:73