Geophysical Inversion and Modelling Library v1.5.4
Loading...
Searching...
No Matches
ttdijkstramodelling.h
1/******************************************************************************
2 * Copyright (C) 2006-2024 by the GIMLi development team *
3 * Carsten Rücker carsten@resistivity.net *
4 * Thomas Günther thomas@resistivity.net *
5 * *
6 * Licensed under the Apache License, Version 2.0 (the "License"); *
7 * you may not use this file except in compliance with the License. *
8 * You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, software *
13 * distributed under the License is distributed on an "AS IS" BASIS, *
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15 * See the License for the specific language governing permissions and *
16 * limitations under the License. *
17 * *
18 ******************************************************************************/
19
20#ifndef _GIMLI_TTDIJKSTRAMODDELING__H
21#define _GIMLI_TTDIJKSTRAMODDELING__H
22
23#include "gimli.h"
24#include "modellingbase.h"
25#include "mesh.h"
26
27namespace GIMLI {
28
29class GraphDistInfo{
30public:
31 GraphDistInfo()
32 : time_(0.0), dist_(0.0){
33 }
34 GraphDistInfo(double t, double d)
35 : time_(t), dist_(d){
36 }
37 GraphDistInfo(double t, double d, Index cellID)
38 : time_(t), dist_(d){
39 cells_.insert(cellID);
40 }
41
43 void setTime(double t) { time_ = t; }
44
46 double time() const { return time_; }
47
49 double dist() const { return dist_; }
50
52 std::set < Index > & cellIDs() { return cells_; }
53
55 const std::set < Index > & cellIDs() const { return cells_; }
56
57protected:
58
59 double time_;
60 double dist_;
61 std::set < Index > cells_;
62};
63
64//** sorted vector
65typedef std::map< Index, GraphDistInfo > NodeDistMap;
66//** sorted matrix
67typedef std::map< Index, NodeDistMap > Graph;
68
69
71class DLLEXPORT Dijkstra {
72public:
73 Dijkstra();
74
75 Dijkstra(const Graph & graph);
76
77 ~Dijkstra(){}
78
79 void setGraph(const Graph & graph);
80
81 void setStartNode(Index startNode);
82
84 void shortestPathTo(Index node, IndexArray & way) const;
85
87 IndexArray shortestPathTo(Index node) const;
88
90 IndexArray shortestPath(Index start, Index end);
91
93 double distance(Index root, Index node);
94
96 double distance(Index node);
97
99 RVector distances(Index root);
100
102 RVector distances() const;
103
104 Graph & graph() {
105 return graph_;
106 }
107
108 const Graph & graph() const {
109 return graph_;
110 }
111
112 GraphDistInfo graphInfo(Index na, Index nb) {
113 return graph_[na][nb];
114 }
115
116 class Edge_ : std::pair< Index, Index > {
117 public:
118 Edge_() : start(0), end(0) {}
119 Edge_(Index a, Index b) : start(a), end(b) {}
120 Index start;
121 Index end;
122 };
123
125 class DistancePair_ : std::pair< double, Edge_ > {
126 public:
127 DistancePair_() : first(0.0) {}
128 DistancePair_(double f, Edge_ & s) : first(f), second(s) {}
129
130 double first;
131 Edge_ second;
132 };
133
134 template < class T > class ComparePairsClass_ {
135 public:
136 bool operator() (const T & lhs, const T & rhs) {
137 return lhs.first > rhs.first;
138 }
139 };
140
141protected:
142 std::vector < Edge_ > pathMatrix_;
143
144 NodeDistMap distances_;
145
146 Graph graph_;
147 Index _root;
148};
149
151
152class DLLEXPORT TravelTimeDijkstraModelling : public ModellingBase {
153public:
154 TravelTimeDijkstraModelling(bool verbose=false);
155
156 TravelTimeDijkstraModelling(Mesh & mesh,
157 DataContainer & dataContainer,
158 bool verbose=false);
159
160 virtual ~TravelTimeDijkstraModelling() { }
161
162 virtual RVector createDefaultStartModel();
163
164 RVector createGradientModel(double lBound, double uBound);
165
167 virtual RVector response(const RVector & slowness);
168
170 virtual void createJacobian(const RVector & slowness);
171
173 virtual void initJacobian();
174
175 Graph createGraph(const RVector & slownessPerCell) const;
176
177// RVector calculate();
178
179 double findMedianSlowness() const;
180
181 RVector getApparentSlowness() const;
182
183 void createJacobian(RSparseMapMatrix & jacobian, const RVector & slowness);
184
189 const IndexArray & way(Index sht, Index rec) const;
190
192 const Dijkstra & dijkstra() const { return dijkstra_; };
193
194protected:
195
197 virtual void updateMeshDependency_();
198
199 Dijkstra dijkstra_;
200 double background_;
201
203 IndexArray shotNodeId_;
204
206 std::map< Index, Index > shotsInv_;
207
209 IndexArray receNodeId_;
210
212 std::map< Index, Index > receiInv_;
213
215 std::vector < std::vector < IndexArray > > wayMatrix_;
216
217};
218
220class DLLEXPORT TTModellingWithOffset: public TravelTimeDijkstraModelling{
221public:
222 TTModellingWithOffset(Mesh & mesh, DataContainer & dataContainer, bool verbose);
223
224 virtual ~TTModellingWithOffset();
225
226 virtual RVector createDefaultStartModel();
227
228 virtual RVector response(const RVector & model);
229
230 void initJacobian();
231
232 virtual void createJacobian(const RVector & slowness);
233
234 size_t nShots(){ return shots_.size(); }
235
236protected:
237 RVector shots_;
238 std::map< Index, Index > shotMap_;
239 Mesh offsetMesh_;
240};
241
242
243} //namespace GIMLI
244
245#endif
DataContainer to store, load and save data in the GIMLi unified data format.
Definition datacontainer.h:48
Definition ttdijkstramodelling.h:134
Definition ttdijkstramodelling.h:116
Definition ttdijkstramodelling.h:71
void shortestPathTo(Index node, IndexArray &way) const
Definition ttdijkstramodelling.cpp:125
RVector distances(Index root)
Definition ttdijkstramodelling.cpp:65
double distance(Index root, Index node)
Definition ttdijkstramodelling.cpp:54
IndexArray shortestPath(Index start, Index end)
Definition ttdijkstramodelling.cpp:148
Definition ttdijkstramodelling.h:29
std::set< Index > & cellIDs()
Definition ttdijkstramodelling.h:52
double time() const
Definition ttdijkstramodelling.h:46
const std::set< Index > & cellIDs() const
Definition ttdijkstramodelling.h:55
void setTime(double t)
Definition ttdijkstramodelling.h:43
double dist() const
Definition ttdijkstramodelling.h:49
Definition mesh.h:128
bool verbose() const
Definition modellingbase.h:48
MatrixBase * jacobian()
Definition modellingbase.h:118
virtual void createJacobian(const RVector &slowness)
Definition ttdijkstramodelling.cpp:666
void initJacobian()
Definition ttdijkstramodelling.cpp:658
virtual RVector response(const RVector &model)
Definition ttdijkstramodelling.cpp:643
virtual RVector createDefaultStartModel()
Definition ttdijkstramodelling.cpp:639
TTModellingWithOffset(Mesh &mesh, DataContainer &dataContainer, bool verbose)
Definition ttdijkstramodelling.cpp:615
std::map< Index, Index > shotsInv_
Definition ttdijkstramodelling.h:206
virtual RVector response(const RVector &slowness)
Definition ttdijkstramodelling.cpp:387
IndexArray shotNodeId_
Definition ttdijkstramodelling.h:203
std::vector< std::vector< IndexArray > > wayMatrix_
Definition ttdijkstramodelling.h:215
std::map< Index, Index > receiInv_
Definition ttdijkstramodelling.h:212
const IndexArray & way(Index sht, Index rec) const
Definition ttdijkstramodelling.cpp:444
virtual void createJacobian(const RVector &slowness)
Definition ttdijkstramodelling.cpp:494
const Dijkstra & dijkstra() const
Definition ttdijkstramodelling.h:192
virtual void initJacobian()
Definition ttdijkstramodelling.cpp:436
IndexArray receNodeId_
Definition ttdijkstramodelling.h:209
virtual RVector createDefaultStartModel()
Definition ttdijkstramodelling.cpp:173
GIMLi main namespace for the Geophyiscal Inversion and Modelling Library.
Definition baseentity.h:24