├── LICENSE
├── README.md
├── data
├── inv_aniso_model_aniso.mat
├── inv_aniso_model_iso.mat
├── inv_iso_model_iso.mat
├── inversion_data.mat
├── protocol.mat
└── synt_data_for_inversion.mat
├── figures
├── forward_validation_model1.fig
├── forward_validation_model1.png
├── forward_validation_model2.fig
├── forward_validation_model2.png
├── inv_aniso_model_aniso.fig
├── inv_aniso_model_aniso.png
├── inv_aniso_model_iso.fig
├── inv_aniso_model_iso.png
├── inv_iso_model_iso.fig
└── inv_iso_model_iso.png
├── functions
├── Calc_data_weight.m
├── CtC_anis.m
├── calcul_alpha_anis.m
├── calcul_u_S_anis.m
├── cglscd.m
├── deriv2D.m
├── distance_weighting.m
├── find_k.m
├── gauss_newton_inversion_anis.m
├── geometric_factor.m
├── getAperture.m
├── gradient_product_anis.m
├── grille2d_elect.m
├── integration_U.m
├── matrix_coeff_anis.m
├── tri_electr_pos.m
└── vec2model.m
└── scripts
├── drawing
├── script_drawing_aniso.m
└── script_drawing_iso.m
├── forward
├── script_analytical_anis_2layers.m
└── script_analytical_anis_semiInfiniteSpace.m
├── inversion
└── script_preparation_inversion.m
├── script_drawing.m
├── script_forward_validation.m
└── script_inversion.m
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AIM4RES user guide
2 |
3 | AIM4RES is a finite-differences forward and inverse anisotropic modeling open source MATLAB library. By considering the resistivity as a tensor, allowing for the anisotropy estimation, AIM4RES provides three model sections from Electrical Resistivity Tomography data: highest resistivity ρ1, lowest resistivity ρ3 and the angle of anisotropy θ. Details about the theory will be found in the article _AIM4RES, an open-source 2.5D finite differences MATLAB library for anisotropic electrical resistivity modeling_ currently in review.
4 |
5 | ## Library description
6 |
7 | The library is open source and freely available for any purpose. It contains 4 folders:
8 | * _functions_: this folder contains all the needed functions for AIM4RES proper functioning. Each function contains a header describing its purpose, the needed input and its outputs. A description of the 3 major structures __param__, __XYZ__ and __Inv__ are thoroughly explained below.
9 |
10 | * _scripts_: this folder contains the executable example scripts.
11 |
12 |
13 | * _data_: this folder contains the data used the scripts previously described, and the output data resulting from the scripts. These latter allow for direct parameters exploration or drawing without previous calculation (for the inversion).
14 |
15 | * _figures_: this folder contains the .fig files obtain from the previous scripts, and correspond to the figures presented in the article.
16 |
17 | All scripts are executable form the folder __./aim4res__
18 |
19 | ### Prerequisites
20 |
21 | Having a working MATLAB distribution, installed on any operating system. No installation is needed for this library and it is directly usable in a MATLAB environment.
22 |
23 | ## What AIM4RES has inside
24 |
25 | ### Key functions
26 |
27 | AIM4RES is based on some key functions, which functioning is described in the accompanying article:
28 |
29 | * *calcul_u_S_anis* drives forward modeling as well as sensitivity calculation,
30 |
31 | * *matrix_coeff_anis* is the function building the capacitance matrix thoroughly described in the article and is called by *calcul_u_S_anis*,
32 |
33 | * *gauss_newton_inversion_anis* drives the inverse modeling. This function needs the two structures __param__ and __XYZ__ and return the __Inv__ structure.
34 |
35 | ### Key parameters
36 |
37 | Three structures are needed in the modeling process:
38 |
39 | * __param__: parameters structure. Some of its items are computed by the different functions. The others are user filled out:
40 | * **flag.geo_factor**: geometric factor associated to each measurements. Needed for the apparent resistivity calculation used in the inverse modeling,
41 | * **cell_size**: determine the block size. Assuming a raw block is 1 m2, **cell_size** slices it dividing its horizontal dimension by **cell_size(1)** and its vertical dimension by **cell_size(2)**,
42 | * **nb_pad_bloc**, **nb_raff**, **nb_surr** and **fact** are described in *grille2d_elect.m* header,
43 | * **rho.xx**, **rho.zz**, **rho.xz** and **rho.yy**: synthetic model resistivity components (ρxx, ρzz, ρxz and ρyy),
44 | * **flag.inv.p**: determines wether inverse modeling computes only the two ρxx and ρzz components (**flag.inv.p** = 2) ; or the three ρxx, ρzz and ρxz components (**flag.inv.p** = 3),
45 | * **data_nb**: ρxx, ρzz or ρxz components size,
46 | * **K**: geometric factor,
47 | * **MEAS.Res**: resistance data (U/I), synthetically computed or measured on the field,
48 | * **anis_init**: homogeneous initial anisotropy considered in the inversion,
49 | * **const_ind**, **const_vect** and **const_TrueFalse**: respectively constrained model cells indices, constrained model cells resistivity value and application (or not) of the constraints,
50 | * **const.***: other constraints parameters (see *script_preparation_inversion.m*),
51 | * **inv.***: inverse modeling features
52 | * **invparam** = 'log resistivity', 'resistivity' or 'resistance' according to the desired inversion. 'log resistivity' is highly recommended,
53 | * **fct_reg** = 'flatness' or 'smoothness', depending on wether first derivative or second derivative is prefered as regularization, respectively,
54 | * **appl_fct_reg** = 'model' or 'model perturbation'
55 | * **dataweight**: see *Calc_data_weight.m* header,
56 | * **alx**, **alz**, **als**: see *CtC_anis.m* header
57 | * **BETA**: regularization coefficient. Usually higher for the anisotropic problem than for the isotropic one,
58 | * **rms_model**
59 | * **tol**: tolerance threshold iteration criterion,
60 | * **maxit**: maximum amount of iterations,
61 | * **weight**: weights applied on the regularization matrix (true of false),
62 | * **weightMinit** and **weightMaxit**: respectively first and last iteration for the weigthing application,
63 | * **weightFun**: 'Distance weighting' or 'Sensitivity weighting' (see Li and Oldenburg, 1996)
64 | * **alp**: Armijo coefficient.
65 |
66 |
67 | * __XYZ__: geometric structures
68 | * **surface_electrode**, **borehole1_electrode** and **borehole2_electrode**: respectively surface, first borehole and second borehole admissible coordinates. Can contain unused coordinates but __*MUST*__ contain all the used coordinates (x: first column, z: second column),
69 | * **MEAS.***: quadrupoles coordinates
70 | * **C1**: current electrode 1 coordinates. nth row = nth measure (x: first column, z: second column)
71 | * **C2**:current electrode 2 coordinates,
72 | * **P1**:potential electrode 1 coordinates,
73 | * **P2**:potential electrode 2 coordinates,
74 | * **areas**: area formed b the quadrupoles. nth row = nth measure.
75 |
76 |
77 | * __Inv__: inverse modeling products
78 | * **rho.***: ρ1, ρ2, ρxx, ρzz, ρxz and θ inverted sections at each iteration,
79 | * **D**: data weighting matrix (see *Calc_data_weight.m* header),
80 | * **d_cal**: apparent resistivity computed on the inverted model at each iteration
81 | * **rho_app_pos_index**: indices of the considered measures at each iteration. Inverse modeling considers logarithmic values of apparent resistivity, **rho_app_pos_index** only keep positive apparent resistivities,
82 | * **rms**: root mean square value at each iteration,
83 | * **beta_weighting**: weighting coefficient stored at each iteration,
84 | * **sens_weighting**: weighting sections stored at each iteration,
85 | * **Ki2**: χ2 value stored at each iteration,
86 | * **CTC**: regularization matrix stored at each iteration
87 |
88 | ## Running the tests
89 |
90 | Ready for use scripts have been added to AIM4RES library. They reproduce the figures presented in the article. These scripts can be edited for any use to adapt any ERT data.
91 |
92 | Scripts are to be executed from AIM4RES root folder:
93 |
94 | * *script_forward_validation.m*: forward modeling considering the two synthetic models described in the article. The script waits for user input to compute the two different forward modeling proposed.
95 |
96 | * *script_inversion.m*: inverse modeling considering the synthetic model described in the article. The script waits for user input to determine if synthetic data have to be computed beforehand from *script_preparation_inversion.m*, or if already existing MATLAB file is to be considered ('synt_data_for_inversion.mat').
97 |
98 | * *script_drawing.m*: script producing the figures presented in the article.
99 |
100 |
101 | ## Authors
102 |
103 | * **Simon GERNEZ**
104 |
105 | * **Abderrezak BOUCHEDDA**
106 |
107 | Members of the [Laboratoire d'Interprétation et Acquisition des Mesures en Géosciences](https://github.com/groupeLIAMG) of INRS-ETE University, Quebec, Canada.
108 |
109 | ## License
110 |
111 | This project is licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE.txt for details.
112 |
--------------------------------------------------------------------------------
/data/inv_aniso_model_aniso.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/data/inv_aniso_model_aniso.mat
--------------------------------------------------------------------------------
/data/inv_aniso_model_iso.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/data/inv_aniso_model_iso.mat
--------------------------------------------------------------------------------
/data/inv_iso_model_iso.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/data/inv_iso_model_iso.mat
--------------------------------------------------------------------------------
/data/inversion_data.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/data/inversion_data.mat
--------------------------------------------------------------------------------
/data/protocol.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/data/protocol.mat
--------------------------------------------------------------------------------
/data/synt_data_for_inversion.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/data/synt_data_for_inversion.mat
--------------------------------------------------------------------------------
/figures/forward_validation_model1.fig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/figures/forward_validation_model1.fig
--------------------------------------------------------------------------------
/figures/forward_validation_model1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/figures/forward_validation_model1.png
--------------------------------------------------------------------------------
/figures/forward_validation_model2.fig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/figures/forward_validation_model2.fig
--------------------------------------------------------------------------------
/figures/forward_validation_model2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/figures/forward_validation_model2.png
--------------------------------------------------------------------------------
/figures/inv_aniso_model_aniso.fig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/figures/inv_aniso_model_aniso.fig
--------------------------------------------------------------------------------
/figures/inv_aniso_model_aniso.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/figures/inv_aniso_model_aniso.png
--------------------------------------------------------------------------------
/figures/inv_aniso_model_iso.fig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/figures/inv_aniso_model_iso.fig
--------------------------------------------------------------------------------
/figures/inv_aniso_model_iso.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/figures/inv_aniso_model_iso.png
--------------------------------------------------------------------------------
/figures/inv_iso_model_iso.fig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/figures/inv_iso_model_iso.fig
--------------------------------------------------------------------------------
/figures/inv_iso_model_iso.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/figures/inv_iso_model_iso.png
--------------------------------------------------------------------------------
/functions/Calc_data_weight.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/functions/Calc_data_weight.m
--------------------------------------------------------------------------------
/functions/CtC_anis.m:
--------------------------------------------------------------------------------
1 | function[CTC,Cx,Cz] = CtC_anis(wt,param,nb_composantes)
2 |
3 | %%========================================================================%
4 | % %
5 | % CtC calculation - the model regularization matrix %
6 | % %
7 | %%========================================================================%
8 | % %
9 | % In: %
10 | % ----------- %
11 | % wt: weigths applied on the regularization matrix %
12 | % param.param.inv.alx: smoothing parameter in x direction %
13 | % param.param.inv.alz: smoothing parameter in z direction %
14 | % param.h_x: x step %
15 | % param.h_z: z step %
16 | % %
17 | % Out: %
18 | % ----------- %
19 | % CTC: model weighting matrix %
20 | % Cx: model weighting matrix in x direction %
21 | % Cx: model weighting matrix in z direction %
22 | % %
23 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 | %%========================================================================%
25 | % Copyright (C) 2019 Simon GERNEZ and Abderrezak BOUCHEDDA %
26 | %%========================================================================%
27 | % %
28 | % Contacts: %
29 | % %
30 | % Simon GERNEZ %
31 | % simon.gernez@ete.inrs.ca %
32 | % Institut National de la Recherche Scientifique %
33 | % Centre Eau-Terre-Environnement %
34 | % http://www.ete.inrs.ca/ %
35 | % %
36 | % Abderrezak BOUCHEDDA %
37 | % Abderrezak.Bouchedda@ete.inrs.ca %
38 | % Institut National de la Recherche Scientifique %
39 | % Centre Eau-Terre-Environnement %
40 | % http://www.ete.inrs.ca/ %
41 | % %
42 | % This program is free software; you can redistribute it and/or modify %
43 | % it under the terms of the GNU General Public License as published by %
44 | % the Free Software Foundation; either version 2 of the License, or %
45 | % (at your option) any later version. %
46 | % %
47 | % This program is distributed in the hope that it will be useful, %
48 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
49 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
50 | % GNU General Public License for more details. %
51 | % %
52 | % You should have received a copy of the GNU General Public License %
53 | % along with this program; if not, write to the Free Software %
54 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
55 |
56 | %%========================================================================%
57 |
58 | %% Calculation
59 |
60 | param.h_x = [param.h_x ; param.h_x(end)];
61 | param.h_z = [param.h_z ; param.h_z(end)];
62 |
63 | %smoothing parammeters
64 | alx = param.inv.alx;
65 | alz = param.inv.alz;
66 |
67 | nx = param.nb_col;
68 | nz = param.nb_ligne;
69 |
70 | %Smallness parameter
71 | als = param.inv.als;
72 | wts = wt(:);
73 |
74 | % derivative matrix
75 | [Cx,Cz] = deriv2D(param.h_x,param.h_z,param.flag.reg_fct);
76 |
77 | if ~isempty(param.const.WGx)
78 | Cx = spdiags(param.const.WGx,0,nx*nz,nx*nz)*Cx;
79 | end
80 |
81 | if ~isempty(param.const.WGz)
82 | Cz = spdiags(param.const.WGz,0,nx*nz,nx*nz)*Cz;
83 | end
84 |
85 | if isfield(param.const,'Wti')
86 | Ci = spdiags(param.const.Wti,0,nx*nz,nx*nz);
87 | else
88 | Ci = speye(nx*nz,nx*nz);
89 | end
90 |
91 | %% Create a weighted smallness term
92 |
93 | % Weights certain points more than others
94 |
95 | Wts_1 = spdiags(wts(1:nx*nz), 0, nx*nz, nx*nz);
96 | Wts_2 = spdiags(wts(nx*nz+1:2*nx*nz), 0, nx*nz, nx*nz);
97 |
98 | if nb_composantes == 3
99 | Wts_3 = spdiags(wts(2*nx*nz+1:end), 0, nx*nz, nx*nz);
100 | end
101 |
102 | % Assemble the Anisotropic derivative operator
103 | Gs = [alx*Cx ; alz*Cz];
104 |
105 | % Assemble the 2d weighting matrix
106 | CTC = (Gs'*Gs + als * Ci);
107 | % if flag == 0
108 | % CTC = (Gs'*Gs + als * Ci);
109 | % else
110 | % CTC = (Gs'*Gs + als * speye(nx*nz,nx*nz));
111 | % end
112 |
113 | if nb_composantes == 2
114 | CTC = sparse( blkdiag(Wts_1',Wts_2') * blkdiag(CTC,CTC) * blkdiag(Wts_1,Wts_2) );
115 | elseif nb_composantes == 3
116 | CTC = sparse( blkdiag(Wts_1',Wts_2',Wts_3') * blkdiag(CTC,CTC,CTC) * blkdiag(Wts_1,Wts_2,Wts_3) );
117 | end
118 | end
--------------------------------------------------------------------------------
/functions/calcul_alpha_anis.m:
--------------------------------------------------------------------------------
1 | function alpha = calcul_alpha_anis(a,k,rho,sigma,pos,normale)
2 |
3 | %%========================================================================%
4 | % %
5 | % calculation of nu for mixed boundary condition %
6 | % %
7 | %%========================================================================%
8 | % %
9 | % In: %
10 | % ------- %
11 | % r: distance between current source frontiers points %
12 | % k: wave number vector %
13 | % rho: resistivity values %
14 | % sigma: conductivity values %
15 | % pos: positions vector %
16 | % normale: normale direction vector %
17 | % %
18 | % Out: %
19 | % ----------- %
20 | % nu: mixed boundary condition coefficient %
21 | % %
22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23 | %%========================================================================%
24 | % Copyright (C) 2019 Simon GERNEZ and Abderrezak BOUCHEDDA %
25 | %%========================================================================%
26 | % %
27 | % Contacts: %
28 | % %
29 | % Simon GERNEZ %
30 | % simon.gernez@ete.inrs.ca %
31 | % Institut National de la Recherche Scientifique %
32 | % Centre Eau-Terre-Environnement %
33 | % http://www.ete.inrs.ca/ %
34 | % %
35 | % Abderrezak BOUCHEDDA %
36 | % Abderrezak.Bouchedda@ete.inrs.ca %
37 | % Institut National de la Recherche Scientifique %
38 | % Centre Eau-Terre-Environnement %
39 | % http://www.ete.inrs.ca/ %
40 | % %
41 | % This program is free software; you can redistribute it and/or modify %
42 | % it under the terms of the GNU General Public License as published by %
43 | % the Free Software Foundation; either version 2 of the License, or %
44 | % (at your option) any later version. %
45 | % %
46 | % This program is distributed in the hope that it will be useful, %
47 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
48 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
49 | % GNU General Public License for more details. %
50 | % %
51 | % You should have received a copy of the GNU General Public License %
52 | % along with this program; if not, write to the Free Software %
53 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
54 |
55 | %%========================================================================%
56 |
57 | %% Calculation
58 |
59 | eps = 10^-10;
60 | nk = length(k);
61 | nr = length(a);
62 | alpha = zeros(nr,nk);
63 | normale = normale(:);
64 |
65 | x = pos(:,1);
66 | z = pos(:,2);
67 |
68 |
69 | % scal = 2*[x z]; % [sigma . grad(a)] dot product
70 | scal = [sigma.xx.*(2.*x.*rho.xx + 2.*z.*rho.xz) + sigma.xz.*(2.*x.*rho.xz + 2.*z.*rho.zz), ...
71 | sigma.xz.*(2.*x.*rho.xx + 2.*z.*rho.xz) + sigma.zz.*(2.*x.*rho.xz + 2.*z.*rho.zz)];
72 | scal_norm = scal*normale;
73 | scal_norm = (1./rho.yy).*scal_norm;
74 |
75 | for j=1:nk
76 | % K0 = besselk(0,(k(j)*sqrt(a)),0);
77 | % K1 = besselk(1,(k(j)*sqrt(a)),0);
78 | K0 = besselk(0,(k(j)*sqrt(a)));
79 | K1 = besselk(1,(k(j)*sqrt(a)));
80 | alpha(:,j) = k(j)./(2*sqrt(a)).*(K1./(K0+eps)).*scal_norm;
81 | end
82 |
83 | end
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/functions/calcul_u_S_anis.m:
--------------------------------------------------------------------------------
1 | function [u,S] = calcul_u_S_anis(param,XYZ,rho,sens_calc)
2 |
3 | %%========================================================================%
4 | % %
5 | % Calculation of potential u and sensitivity S in anisotropic media %
6 | % %
7 | %%========================================================================%
8 | % %
9 | % In: %
10 | % ----------- %
11 | % sens_calc: sensitivity calculation %
12 | % sens_calc == 0: don't calculate sensitivity matrix %
13 | % sens_calc == 1: calculate sensistivity matrix %
14 | % param: parameters structure %
15 | % XYZ: electrodes position structure %
16 | % %
17 | % Out: %
18 | % ----------- %
19 | % u: calculated potential %
20 | % I = 1 == > u = resistance (= u/I = u/1) %
21 | % S: sensitivity matrix (if sens_calc == 1) %
22 | % %
23 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 | %%========================================================================%
25 | % Copyright (C) 2019 Simon GERNEZ and Abderrezak BOUCHEDDA %
26 | %%========================================================================%
27 | % %
28 | % Contacts: %
29 | % %
30 | % Simon GERNEZ %
31 | % simon.gernez@ete.inrs.ca %
32 | % Institut National de la Recherche Scientifique %
33 | % Centre Eau-Terre-Environnement %
34 | % http://www.ete.inrs.ca/ %
35 | % %
36 | % Abderrezak BOUCHEDDA %
37 | % Abderrezak.Bouchedda@ete.inrs.ca %
38 | % Institut National de la Recherche Scientifique %
39 | % Centre Eau-Terre-Environnement %
40 | % http://www.ete.inrs.ca/ %
41 | % %
42 | % This program is free software; you can redistribute it and/or modify %
43 | % it under the terms of the GNU General Public License as published by %
44 | % the Free Software Foundation; either version 2 of the License, or %
45 | % (at your option) any later version. %
46 | % %
47 | % This program is distributed in the hope that it will be useful, %
48 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
49 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
50 | % GNU General Public License for more details. %
51 | % %
52 | % You should have received a copy of the GNU General Public License %
53 | % along with this program; if not, write to the Free Software %
54 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
55 |
56 | %%========================================================================%
57 |
58 | %% Initialisation
59 |
60 | S = [];
61 | eps = 1e-5;
62 | position = param.pos;
63 | ind = param.ind;
64 | I = 1; % current intensity
65 | nb_ligne = max(size(param.h_z))+1;
66 | nb_col = max(size(param.h_x))+1;
67 | nb_t = nb_ligne*nb_col;
68 | nb_electrode1 = size(position.C,1);
69 | nb_electrode2 = size(position.P);
70 | nb_electrode2 = nb_electrode2(1,1);
71 | nb_electrode = nb_electrode1+nb_electrode2; % number of electrodes
72 | nb_k = length(param.k); % wave number
73 | nb_meas = param.data_nb; % measures number
74 | position1 = [position.C ; position.P];
75 | u_P1 = zeros(2*nb_meas,1);
76 | u_P2 = zeros(2*nb_meas,1);
77 |
78 | if sens_calc == 0 % no sensitivity
79 | param.flag.sen = 0; % force to no sensitivity
80 | end
81 |
82 | if param.flag.sen == 1
83 | u1 = zeros(nb_col*nb_ligne,nb_electrode*nb_k);
84 | end
85 |
86 | qq = sparse(nb_col*nb_ligne,nb_electrode);
87 | ind_source = [];
88 | u = zeros(nb_meas,nb_k);
89 |
90 | %% Matrix coeff calculation
91 |
92 | [A1,Ak] = matrix_coeff_anis(param.h_x,param.h_z,param.grille,rho,param.k);
93 |
94 | % Ak shouldn't be complex
95 | try
96 | isreal(Ak) == false;
97 | catch
98 | error('complex Ak: Ak should be real')
99 | end
100 |
101 | for ii = 1:nb_electrode
102 | iind = find(abs(position1(ii,1)-param.grille(:,1)) < eps & abs(position1(ii,2)-param.grille(:,2)) < eps);
103 | qq(iind,ii) = I/2;
104 | ind_source = [ind_source;iind];
105 | end
106 |
107 | %% Forward problem resolution
108 |
109 | if nb_t > 10^6 % if huge parameters number to estimate
110 |
111 | for j = 1:nb_k % loop for k
112 |
113 | A = A1 + sparse(1:nb_t,1:nb_t,Ak(:,j));
114 |
115 | % Symmetric reverse Cuthill-McKee permutation
116 | p = symrcm(A);
117 | A = A(p,p);
118 | [~,up] = sort(p);
119 | %--------
120 | setup.droptol = 10^-5;
121 | % LU precondit.
122 | [L1,U1] = ilu(A,setup);
123 | %--------
124 | l1 = 0;
125 | l2 = 0;
126 |
127 | for i = 1:nb_electrode1 % loop for current electrode position
128 |
129 | q = qq(:,i);
130 | q = q(p);
131 |
132 | % resoudre Au = q
133 | [uu,~] = bicgstab(A,q,10^-9,20,L1,U1);
134 |
135 | uu = uu(up); % rearrangement after Cuthill-McKee permutation
136 |
137 | l2 = l2+param.L(i);
138 |
139 | u1(:,i+(j-1)*nb_electrode) = uu;
140 |
141 | u_P1((1+l1:l2)) = uu(ind.P1(1+l1:l2));
142 | u_P2((1+l1:l2)) = uu(ind.P2(1+l1:l2));
143 |
144 | l1 = l2;
145 |
146 | end
147 |
148 | u_P1C1(ind.C1C2(param.sign == 1)) = u_P1(param.sign == 1);
149 | u_P1C2(ind.C1C2(param.sign == -1)) = u_P1(param.sign == -1);
150 | u_P2C1(ind.C1C2(param.sign == 1)) = u_P2(param.sign == 1);
151 | u_P2C2(ind.C1C2(param.sign == -1)) = u_P2(param.sign == -1);
152 |
153 | u(:,j) = (u_P1C1-u_P1C2)-(u_P2C1-u_P2C2);
154 |
155 | end
156 |
157 | % integration into the spatial domain
158 | u = integration_U(u,param.wk,param.k,param.nbk1);
159 |
160 | else
161 |
162 | for j = 1:nb_k % loop for k
163 |
164 | A = A1 + sparse(1:nb_t,1:nb_t,Ak(:,j));
165 |
166 | if param.flag.inv.p == 3
167 | [L,U] = lu(A);
168 | elseif param.flag.inv.p == 2
169 | % symmetric coefficient matrix if only 2 components, chol
170 | % more efficient than lu in that case
171 | R = chol(A);
172 | RT = R';
173 | end
174 |
175 | l1 = 0;
176 | l2 = 0;
177 |
178 | q = qq;
179 |
180 | for i = 1:nb_electrode1 % loop for current electrode position
181 | if param.flag.inv.p == 3
182 | uu = (U\(L\(q(:,i))));
183 | elseif param.flag.inv.p == 2
184 | uu = (R\(RT\(q(:,i))));
185 | end
186 |
187 | l2 = l2+param.L(i);
188 |
189 | if param.flag.sen == 1
190 | u1(:,i+(j-1)*nb_electrode) = uu;
191 | end
192 |
193 | u_P1((1+l1:l2)) = uu(ind.P1(1+l1:l2));
194 | u_P2((1+l1:l2)) = uu(ind.P2(1+l1:l2));
195 |
196 | l1 = l2;
197 | end
198 |
199 | u_P1C1(ind.C1C2(param.sign == 1)) = u_P1(param.sign == 1);
200 | u_P1C2(ind.C1C2(param.sign == -1)) = u_P1(param.sign == -1);
201 | u_P2C1(ind.C1C2(param.sign == 1)) = u_P2(param.sign == 1);
202 | u_P2C2(ind.C1C2(param.sign == -1)) = u_P2(param.sign == -1);
203 |
204 | if isnan(XYZ.MEAS.C2(1,1)) && isnan(XYZ.MEAS.P2(1,1)) % pole-pole
205 | u_P2C1 = 0;
206 | u_P2C2 = 0;
207 | u_P1C2 = 0;
208 | elseif isnan(XYZ.MEAS.C2(1,1)) && ~isnan(XYZ.MEAS.P2(1,1)) % pole-dipole
209 | u_P2C2 = 0;
210 | u_P1C2 = 0;
211 | end
212 |
213 | u_k = (u_P1C1-u_P1C2) - (u_P2C1-u_P2C2);
214 | u(:,j) = u_k(:);
215 |
216 | end
217 |
218 | % integration into the spatial domain
219 | u = integration_U(u,param.wk,param.k,param.nbk1);
220 |
221 | end
222 |
223 | %% Sensitivity matrix calculation
224 |
225 | % we start with the calculation of the reciprocal potential pos. misses
226 |
227 | if sens_calc == 1 % sensitivity calculation
228 |
229 | if param.flag.inv.p == 2
230 | if nb_electrode2 ~= 0 % calculate reciprocal potential if P1 or P2 are not used as C1 or C2
231 | for j = 1:nb_k
232 | A = A1 + sparse(1:nb_t,1:nb_t,Ak(:,j));
233 | [R,~,p] = chol(A,'vector'); % Cholesky decomposition with ordering
234 | [~,up] = sort(p); % ordering indices
235 | for i = 1:nb_electrode2
236 | q = qq(:,i+nb_electrode1);
237 | % Au = q
238 | uu = (R\(R'\(q(p))));
239 | uu = uu(up);
240 | u1(:,i+nb_electrode1+(j-1)*nb_electrode) = uu;
241 | end
242 | end
243 | end
244 |
245 | elseif param.flag.inv.p == 3
246 | if nb_electrode2 ~= 0 % calculate reciprocal potential if P1 or P2 are not used as C1 or C2
247 | for j = 1:nb_k
248 | A = A1 + sparse(1:nb_t,1:nb_t,Ak(:,j));
249 | [L,U,p] = lu(A,'vector');
250 | [~,up] = sort(p); % ordering indices
251 | for i = 1:nb_electrode2
252 | q = qq(:,i+nb_electrode1);
253 | % Au = q
254 | uu = (U\(L\(q(p))));
255 | uu = uu(up);
256 | u1(:,i+nb_electrode1+(j-1)*nb_electrode) = uu;
257 | end
258 | end
259 | end
260 |
261 | end
262 |
263 | n = size(ind.meas,1);
264 |
265 | rho.xx = rho.xx';
266 | rho.xz = rho.xz';
267 | rho.zz = rho.zz';
268 | rho.yy = rho.yy';
269 |
270 | rho.xx = rho.xx(:)'; % Mandatory step so that cells are considered
271 | rho.xz = rho.xz(:)'; % as an arranged vector as for inversion
272 | rho.zz = rho.zz(:)';
273 | rho.yy = rho.yy(:)';
274 |
275 | S.xx = zeros(nb_meas,nb_ligne*nb_col);
276 | S.zz = zeros(nb_meas,nb_ligne*nb_col);
277 | S.xz = zeros(nb_meas,nb_ligne*nb_col);
278 | % % Uncomment if lambda sensitivity is needed (if you don't know wether it is needed, assume it is not)
279 | % Slambda = zeros(nb_meas,nb_ligne*nb_col);
280 |
281 | rho.rho_1 = rho.rho_1';
282 | rho.rho_2 = rho.rho_2';
283 | rho.angle = rho.angle';
284 | rho.rho_1 = rho.rho_1(:)';
285 | rho.rho_2 = rho.rho_2(:)';
286 | rho.angle = rho.angle(:)';
287 |
288 | if strcmp(param.inv.invparam,'log resistivity')
289 |
290 | % dipole-dipole
291 | if ~isnan(XYZ.MEAS.C2(1,1)) && ~isnan(XYZ.MEAS.P2(1,1))
292 |
293 | parfor i = 1:n
294 |
295 | u_1 = (u1(:,ind.meas(i,1):nb_electrode:end)-u1(:,ind.meas(i,2):nb_electrode:end));% u(c1)-u(c2)
296 | u_1R = (u1(:,ind.meas(i,3):nb_electrode:end)-u1(:,ind.meas(i,4):nb_electrode:end));% u(p1)-u(p2)
297 |
298 | % Gradient calculation
299 | g = gradient_product_anis(u_1R, u_1, param.h_x, param.h_z, param.k);
300 |
301 | % xx
302 | g.xx = integration_U(g.xx,param.wk,param.k,param.nbk1); % Inverse Fourier transform
303 | g.xx = reshape(g.xx,nb_ligne,nb_col);
304 | g.xx = reshape(g.xx',(nb_ligne)*(nb_col),1)'; % horizontally arranged
305 |
306 | % xz
307 | g.xz = integration_U(g.xz,param.wk,param.k,param.nbk1); % Inverse Fourier transform
308 | g.xz = reshape(g.xz,nb_ligne,nb_col);
309 | g.xz = reshape(g.xz',(nb_ligne)*(nb_col),1)'; % horizontally arranged
310 |
311 | % zz
312 | g.zz = integration_U(g.zz,param.wk,param.k,param.nbk1); % Inverse Fourier transform
313 | g.zz = reshape(g.zz,nb_ligne,nb_col);
314 | g.zz = reshape(g.zz',(nb_ligne)*(nb_col),1)'; % horizontally arranged
315 |
316 | % yy
317 | g.yy = integration_U(g.yy,param.wk,param.k,param.nbk1); % tr. Fourier inv.
318 | g.yy = reshape(g.yy,nb_ligne,nb_col);
319 | g.yy = reshape(g.yy',(nb_ligne)*(nb_col),1)'; % horizontally arranged
320 |
321 | % Calculation of the sensitivity (ln(resistivity))
322 | Sxx(i,:) = (1./(rho.rho_1*u(i))).*(g.xx.*(cosd(rho.angle)).^2 + ...
323 | g.zz.*(sind(rho.angle)).^2 - ...
324 | g.xz.*cosd(rho.angle).*sind(rho.angle) + ...
325 | g.yy);
326 |
327 | Szz(i,:) = (1./(rho.rho_2*u(i))).*(g.xx.*(sind(rho.angle)).^2 + ...
328 | g.zz.*(cosd(rho.angle)).^2 + ...
329 | g.xz.*cosd(rho.angle).*sind(rho.angle));
330 |
331 | Sxz(i,:) = -(rho.angle./u(i)).*(g.xx.*(1./rho.rho_2-1./rho.rho_1).*sind(2*rho.angle) + ...
332 | g.zz.*(1./rho.rho_1-1./rho.rho_2).*sind(2*rho.angle) + ...
333 | g.xz.*(1./rho.rho_2-1./rho.rho_1).*cosd(2*rho.angle));
334 |
335 | % Uncomment if lambda sensitivity is needed (if you don't know wether it is needed, assume it is not)
336 | % s_m = sqrt(rho.rho_1.*rho.rho_2);
337 | % lambd = sqrt(rho.rho_2./rho.rho_1);
338 | % Slambda(i,:) = - ( d_phi.xx.*s_m.*(cosd(rho.angle).^2 - 1./lambd.^2.*sind(rho.angle).^2) ...
339 | % + d_phi.zz.*s_m.*(sind(rho.angle).^2 - 1./lambd.^2.*cosd(rho.angle).^2) ...
340 | % - d_phi.xz.*0.5.*s_m.*(1 + 1./lambd.^2).*sind(2*rho.angle));
341 |
342 | end
343 |
344 | S.xx = Sxx;
345 | S.xz = Sxz;
346 | S.zz = Szz;
347 | % Uncomment if lambda sensitivity is needed
348 | % S.lambda = Slambda;
349 |
350 | % pole-pole
351 | elseif isnan(XYZ.MEAS.C2(1,1)) && isnan(XYZ.MEAS.P2(1,1))
352 |
353 | parfor i = 1:n
354 |
355 | u_1 = u1(:,ind.meas(i,1):nb_electrode:end); % u(c1)
356 | u_1R = u1(:,ind.meas(i,2):nb_electrode:end); % u(p1)
357 |
358 | % Gradient calculation
359 | g = gradient_product_anis(u_1R, u_1, param.h_x, param.h_z, param.k, param.flag.inv.p);
360 |
361 | % xx
362 | g.xx = integration_U(g.xx,param.wk,param.k,param.nbk1); % Inverse Fourier transform
363 | g.xx = reshape(g.xx,nb_ligne,nb_col);
364 | g.xx = reshape(g.xx',(nb_ligne)*(nb_col),1)'; % horizontally arranged
365 |
366 | % xz
367 | g.xz = integration_U(g.xz,param.wk,param.k,param.nbk1); % Inverse Fourier transform
368 | g.xz = reshape(g.xz,nb_ligne,nb_col);
369 | g.xz = reshape(g.xz',(nb_ligne)*(nb_col),1)'; % horizontally arranged
370 |
371 | % zz
372 | g.zz = integration_U(g.zz,param.wk,param.k,param.nbk1); % Inverse Fourier transform
373 | g.zz = reshape(g.zz,nb_ligne,nb_col);
374 | g.zz = reshape(g.zz',(nb_ligne)*(nb_col),1)'; % horizontally arranged
375 |
376 | % yy
377 | g.yy = integration_U(g.yy,param.wk,param.k,param.nbk1); % tr. Fourier inv.
378 | g.yy = reshape(g.yy,nb_ligne,nb_col);
379 | g.yy = reshape(g.yy',(nb_ligne)*(nb_col),1)'; % horizontally arranged
380 |
381 | % Calculation of the sensitivity (ln(resistivity))
382 | Sxx(i,:) = (1./(rho.rho_1*u(i))).*(g.xx.*(cosd(rho.angle)).^2 + ...
383 | g.zz.*(sind(rho.angle)).^2 - ...
384 | g.xz.*cosd(rho.angle).*sind(rho.angle) + ...
385 | g.yy);
386 |
387 | Szz(i,:) = (1./(rho.rho_2*u(i))).*(g.xx.*(sind(rho.angle)).^2 + ...
388 | g.zz.*(cosd(rho.angle)).^2 + ...
389 | g.xz.*cosd(rho.angle).*sind(rho.angle));
390 |
391 | Sxz(i,:) = -(rho.angle./u(i)).*(g.xx.*(1./rho.rho_2-1./rho.rho_1).*sind(2*rho.angle) + ...
392 | g.zz.*(1./rho.rho_1-1./rho.rho_2).*sind(2*rho.angle) + ...
393 | g.xz.*(1./rho.rho_2-1./rho.rho_1).*cosd(2*rho.angle));
394 |
395 | % Uncomment if lambda sensitivity is needed (if you don't know wether it's needed, assume it is not)
396 | % s_m = sqrt(rho.rho_1.*rho.rho_2);
397 | % lambd = sqrt(rho.rho_2./rho.rho_1);
398 | % Slambda(i,:) = - ( d_phi.xx.*s_m.*(cosd(rho.angle).^2 - 1./lambd.^2.*sind(rho.angle).^2) ...
399 | % + d_phi.zz.*s_m.*(sind(rho.angle).^2 - 1./lambd.^2.*cosd(rho.angle).^2) ...
400 | % - d_phi.xz.*0.5.*s_m.*(1 + 1./lambd.^2).*sind(2*rho.angle));
401 |
402 | end
403 |
404 | S.xx = Sxx;
405 | S.xz = Sxz;
406 | S.zz = Szz;
407 | % Uncomment if lambda sensitivity is needed
408 | % S.lambda = Slambda;
409 |
410 | % pole-dipole
411 | elseif isnan(XYZ.MEAS.C2(1,1)) && ~isnan(XYZ.MEAS.P2(1,1))
412 |
413 | parfor i = 1:n
414 |
415 | u_1 = u1(:,ind.meas(i,1):nb_electrode:end); % u(c1)
416 | u_1R = (u1(:,ind.meas(i,2):nb_electrode:end)-u1(:,ind.meas(i,3):nb_electrode:end)); % u(p1)-u(p2)
417 |
418 | % Gradient calculation
419 | g = gradient_product_anis(u_1R, u_1, param.h_x, param.h_z, param.k, param.flag.inv.p);
420 |
421 | % xx
422 | g.xx = integration_U(g.xx,param.wk,param.k,param.nbk1); % Inverse Fourier transform
423 | g.xx = reshape(g.xx,nb_ligne,nb_col);
424 | g.xx = reshape(g.xx',(nb_ligne)*(nb_col),1)'; % horizontally arranged
425 |
426 | % xz
427 | g.xz = integration_U(g.xz,param.wk,param.k,param.nbk1); % Inverse Fourier transform
428 | g.xz = reshape(g.xz,nb_ligne,nb_col);
429 | g.xz = reshape(g.xz',(nb_ligne)*(nb_col),1)'; % horizontally arranged
430 |
431 | % zz
432 | g.zz = integration_U(g.zz,param.wk,param.k,param.nbk1); % Inverse Fourier transform
433 | g.zz = reshape(g.zz,nb_ligne,nb_col);
434 | g.zz = reshape(g.zz',(nb_ligne)*(nb_col),1)'; % horizontally arranged
435 |
436 | % yy
437 | g.yy = integration_U(g.yy,param.wk,param.k,param.nbk1); % tr. Fourier inv.
438 | g.yy = reshape(g.yy,nb_ligne,nb_col);
439 | g.yy = reshape(g.yy',(nb_ligne)*(nb_col),1)'; % horizontally arranged
440 |
441 | % Calculation of the sensitivity (ln(resistivity))
442 | Sxx(i,:) = (1./(rho.rho_1*u(i))).*(g.xx.*(cosd(rho.angle)).^2 + ...
443 | g.zz.*(sind(rho.angle)).^2 - ...
444 | g.xz.*cosd(rho.angle).*sind(rho.angle) + ...
445 | g.yy);
446 |
447 | Szz(i,:) = (1./(rho.rho_2*u(i))).*(g.xx.*(sind(rho.angle)).^2 + ...
448 | g.zz.*(cosd(rho.angle)).^2 + ...
449 | g.xz.*cosd(rho.angle).*sind(rho.angle));
450 |
451 | Sxz(i,:) = -(rho.angle./u(i)).*(g.xx.*(1./rho.rho_2-1./rho.rho_1).*sind(2*rho.angle) + ...
452 | g.zz.*(1./rho.rho_1-1./rho.rho_2).*sind(2*rho.angle) + ...
453 | g.xz.*(1./rho.rho_2-1./rho.rho_1).*cosd(2*rho.angle));
454 |
455 | % Uncomment if lambda sensitivity is needed (if you don't know wether it's needed, assume it is not)
456 | % s_m = sqrt(rho.rho_1.*rho.rho_2);
457 | % lambd = sqrt(rho.rho_2./rho.rho_1);
458 | % Slambda(i,:) = - ( d_phi.xx.*s_m.*(cosd(rho.angle).^2 - 1./lambd.^2.*sind(rho.angle).^2) ...
459 | % + d_phi.zz.*s_m.*(sind(rho.angle).^2 - 1./lambd.^2.*cosd(rho.angle).^2) ...
460 | % - d_phi.xz.*0.5.*s_m.*(1 + 1./lambd.^2).*sind(2*rho.angle));
461 |
462 | end
463 |
464 | S.xx = Sxx;
465 | S.xz = Sxz;
466 | S.zz = Szz;
467 | % Uncomment if lambda sensitivity is needed
468 | % S.lambda = Slambda;
469 | end
470 | end
471 | end
472 |
473 | end
474 |
--------------------------------------------------------------------------------
/functions/cglscd.m:
--------------------------------------------------------------------------------
1 | function [x, error, iter] = cglscd(J, x, b, BETA, CTC, dxc, D, P, max_it, tol, appl_fct_reg)
2 |
3 | %%========================================================================%
4 | % %
5 | % This function calculate resistivity perturabation by cg %
6 | % it resolves : %
7 | % for model reg. (J'*D'*D*J+ BETA CTC) x= J'*D'*D (d-dobs)-BETA(CTC*dxc) %
8 | % for model pert. reg. (J'*D'*D*J+ BETA CTC) x= J'*D'*D (d-dobs) %
9 | % %
10 | %%========================================================================%
11 | % %
12 | % In: %
13 | % ----------- %
14 | % J : Jacobian matrix %
15 | % x : initial guess vector %
16 | % b : d-dobs %
17 | % BETA : regularization coefficient %
18 | % CTC : C'*C where C is regularization matrix %
19 | % dxc : rho-rho_ref %
20 | % D : data weigthing matrix %
21 | % P : constraints vector to fix resistivity ( 0 fix, 1 unfix) %
22 | % max_it : maximum number of iteration %
23 | % tol : error tolerance %
24 | % appl_fct_reg : applied regularization ( model or model perturbation) %
25 | % %
26 | % Out: %
27 | % ----------- %
28 | % x REAL solution vector %
29 | % error REAL error norm %
30 | % iter INTEGER number of iterations performed %
31 | % %
32 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 | %=========================================================================%
34 | % Copyright (C) 2008 Abderrezak BOUCHEDDA %
35 | %=====oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo====%
36 | % contact: ---------->\\\//// %
37 | % |_ _| %
38 | % (@ @) %
39 | % **********oooO***(_)***Oooo********** %
40 | % * -----> Abderrezak BOUCHEDDA<----- * %
41 | % * Abderrezak.Bouchedda@ete.inrs.ca * %
42 | % * INRS-ETE * %
43 | % * http://www.ete.inrs.ca/ete * %
44 | % ************************************* %
45 | % |_______| %
46 | % |__|__| %
47 | % () () %
48 | % ooO Ooo %
49 | % This program is free software; you can redistribute it and/or modify %
50 | % it under the terms of the GNU General Public License as published by %
51 | % the Free Software Foundation; either version 2 of the License, or %
52 | % (at your option) any later version. %
53 | % %
54 | % This program is distributed in the hope that it will be useful, %
55 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
56 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
57 | % GNU General Public License for more details. %
58 | % %
59 | % You should have received a copy of the GNU General Public License %
60 | % along with this program; if not, write to the Free Software %
61 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
62 | % %
63 | %%========================================================================%
64 |
65 | %% Calculation
66 |
67 | iter = 0;
68 |
69 | if isempty(P)
70 | P = ones(size(x));
71 | end
72 |
73 | x = P.*x;
74 | % M : jacoby preconditioner
75 | M = (sum((D*J).^2)'+BETA*diag(CTC));
76 | M(M==0) = eps;
77 | M = 1./M;
78 | %
79 | zz = D*(b - J*x); % gradient initialisation
80 |
81 | if strcmp(appl_fct_reg,'model')
82 |
83 | b1 = (((D.^2)*b)'*J)' - BETA*CTC*(dxc);
84 | bnrm2 = norm( b1 );
85 |
86 | if ( bnrm2 == 0.0 )
87 | bnrm2 = 1.0;
88 | end
89 |
90 | r= P.*(((zz' * D )*J)'- BETA*CTC * (x+dxc));
91 |
92 | error = norm( r ) / bnrm2; % error initialisation
93 |
94 | if ( error < tol )
95 | return
96 | end
97 |
98 | for iter = 1:max_it
99 |
100 | z = M.* r; % modified gradient
101 | rho = (r'*z);
102 |
103 | if ( iter > 1 )
104 | beta = rho / rho_1; % beta_k coefficient
105 | p = z + beta*p; % direction
106 | else
107 | p = z; % direction initialisation
108 | end
109 |
110 | q = D*(J*p);
111 | alpha = rho / (q'*q + (p'*BETA*CTC*p)); % step
112 | x = x + alpha * p; % descent
113 | zz = zz - alpha*q;
114 | r = P.*(((zz'*D)*J)' - BETA*CTC*(x+dxc)); % gradient
115 | error = norm( r ) / bnrm2;
116 |
117 | if ( error <= tol )
118 | break
119 | end % stop criterion
120 |
121 | rho_1 = rho;
122 |
123 | end
124 |
125 |
126 | elseif strcmp(appl_fct_reg,'model perturbation')
127 |
128 | r= P.*((zz' * D )*J)'- BETA*CTC * x;
129 | b1=(((D.^2)*b)'*J)';
130 | bnrm2 = norm( b1 );
131 | error = norm( r ) / bnrm2; % error initialisation
132 |
133 | if ( error < tol )
134 | return
135 | end
136 |
137 | for iter = 1:max_it
138 |
139 | z = M.* r; % modified gradient
140 | rho = (r'*z);
141 |
142 | if ( iter > 1 )
143 | beta = rho / rho_1; % beta_k coefficient
144 | p = z + beta*p; % direction
145 | else
146 | p = z; % direction initialisation
147 | end
148 |
149 | q = D*J*p;
150 | alpha = rho / (q'*q + BETA *(p'*CTC*p)); % step
151 | x = x + alpha * p; % descent
152 | zz = zz - alpha*q;
153 | r = P.*((zz'*D)*J)'- BETA * CTC * x; % gradient
154 | error = norm( r ) / bnrm2;
155 | if ( error <= tol )
156 | break
157 | end % stop criterion
158 |
159 | rho_1 = rho;
160 |
161 | end
162 |
163 | end
164 | end
--------------------------------------------------------------------------------
/functions/deriv2D.m:
--------------------------------------------------------------------------------
1 | function [Cx,Cz] = deriv2D(pasx,pasz,flag)
2 |
3 |
4 | nxx=numel(pasx); % nombre d'elements dans la direction x
5 | nzz=numel(pasz); % nombre d'elements dans la direction z
6 | N=nxx*nzz; % nombre total d'elements
7 | %nx=(nxx-1)*nzz;
8 | nz=nxx*(nzz-1);
9 | Cx=sparse(N,N);
10 |
11 |
12 |
13 |
14 |
15 | if flag ==1 % first derivative
16 |
17 | pasz=(pasz(1:end-1)+pasz(1:end-1))/2;
18 | pasx=(pasx(1:end-1)+pasx(1:end-1))/2;
19 | pasx=1./pasx(:); %
20 | pasz=1./pasz(:);
21 |
22 | % in x direction
23 | for i=1:nzz
24 |
25 | Cx1 = sparse(1+(i-1)*nxx:nxx-1+(i-1)*nxx , 1+nxx*(i-1):nxx-1+nxx*(i-1) , -pasx , N , N);
26 | Cx2 = sparse(1+(i-1)*nxx:nxx-1+(i-1)*nxx , 2+nxx*(i-1):nxx+nxx*(i-1) , pasx , N , N);
27 | Cx=Cx+Cx1+Cx2;
28 |
29 | end
30 |
31 | % in z direction
32 | pasz=pasz';
33 |
34 | pasz=repmat(pasz,nxx,1);
35 | pasz=pasz(:); % mise sous forme de vecteur
36 | %
37 | %
38 | Cz=sparse(N,N);
39 | Cz1 = sparse(1:(nzz-1)*nxx,1:(nzz-1)*nxx,-pasz,N,N);
40 | Cz2 = sparse(1:(nzz-1)*nxx,1+nxx:N,pasz,N,N);
41 | Cz=Cz+Cz1+Cz2;
42 |
43 | elseif flag==2 % second derivative
44 |
45 | ax=zeros(nxx,1); bx=ax; az=zeros(nzz,1);bz=az;
46 | ax(1)=0;
47 | ax(end)=3/((pasx(end-1)+2*pasx(end))*pasx(end));
48 | bx(1)=3/((pasx(2)+2*pasx(1))*pasx(1));
49 | bx(end)=0;
50 |
51 | az(1)=0;
52 | az(end)=3./((pasz(end-1)+2*pasz(end))*pasz(end));
53 |
54 | bz(1)=3./((pasz(2)+2*pasz(1))*pasz(1));
55 | bz(end)=0;
56 |
57 |
58 | ax(2:end-1)=4./((pasx(3:end)+2*pasx(2:end-1)+pasx(1:end-2)).*(pasx(2:end-1)+pasx(1:end-2)));
59 | bx(2:end-1)=4./((pasx(3:end)+2*pasx(2:end-1)+pasx(1:end-2)).*(pasx(2:end-1)+pasx(3:end)));
60 | az(2:end-1)=4./((pasz(3:end)+2*pasz(2:end-1)+pasz(1:end-2)).*(pasz(2:end-1)+pasz(1:end-2)));
61 | bz(2:end-1)=4./((pasz(3:end)+2*pasz(2:end-1)+pasz(1:end-2)).*(pasz(2:end-1)+pasz(3:end)));
62 |
63 | ax=kron(ones(nzz,1),ax);
64 | bx=kron(ones(nzz,1),bx);
65 | az=kron(az,ones(nxx,1));
66 | bz=kron(bz,ones(nxx,1));
67 |
68 |
69 | cx=-(ax+bx);
70 | cz=-(az+bz);
71 | % reordering to use spdiags function
72 | ax=[ax(2:end);0];
73 | az=[az(nxx+1:end);zeros(nxx,1)];
74 | bx=[0;bx(1:end-1)]; bx(2)=0; % to avoid null space matrix
75 | bz=[zeros(nxx,1);bz(1:end-nxx)]; bz(2)=0; % to avoid null space matrix
76 |
77 | Cx = spdiags([ax cx bx],-1:1, N, N);
78 | Cz = spdiags([az cz bz],[-nxx 0 nxx], N, N);
79 |
80 | end
81 |
82 | end
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/functions/distance_weighting.m:
--------------------------------------------------------------------------------
1 | function Q=distance_weighting(param,beta)
2 |
3 | %%========================================================================%
4 | % %
5 | % Calculation of distance weigthing values %
6 | % %
7 | %%========================================================================%
8 | % %
9 | % In: %
10 | % ----------- %
11 | % param: parameters structure %
12 | % beta: weigthing coefficient %
13 | % %
14 | % Out: %
15 | % ----------- %
16 | % Q = weigthing values %
17 | % %
18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19 | %%========================================================================%
20 | % Copyright (C) 2019 Simon GERNEZ and Abderrezak BOUCHEDDA %
21 | %%========================================================================%
22 | % %
23 | % Contacts: %
24 | % %
25 | % Simon GERNEZ %
26 | % simon.gernez@ete.inrs.ca %
27 | % Institut National de la Recherche Scientifique %
28 | % Centre Eau-Terre-Environnement %
29 | % http://www.ete.inrs.ca/ %
30 | % %
31 | % Abderrezak BOUCHEDDA %
32 | % Abderrezak.Bouchedda@ete.inrs.ca %
33 | % Institut National de la Recherche Scientifique %
34 | % Centre Eau-Terre-Environnement %
35 | % http://www.ete.inrs.ca/ %
36 | % %
37 | % This program is free software; you can redistribute it and/or modify %
38 | % it under the terms of the GNU General Public License as published by %
39 | % the Free Software Foundation; either version 2 of the License, or %
40 | % (at your option) any later version. %
41 | % %
42 | % This program is distributed in the hope that it will be useful, %
43 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
44 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
45 | % GNU General Public License for more details. %
46 | % %
47 | % You should have received a copy of the GNU General Public License %
48 | % along with this program; if not, write to the Free Software %
49 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
50 |
51 | %%========================================================================%
52 |
53 | %% Calculation
54 |
55 | % Li and Oldenburg, 2000,Joint inversion of surface and three-component
56 | % borehole magnetic data, Geophysics.
57 |
58 | X = param.grille(:,1);
59 | X = reshape(X,param.nb_ligne,param.nb_col);
60 | X = X';
61 | X = X(:);
62 |
63 | Z = param.grille(:,2);
64 | Z = reshape(Z,param.nb_ligne,param.nb_col);
65 | Z = Z';
66 | Z = Z(:);
67 |
68 | h_x = [param.h_x ; param.h_x(end)];
69 | h_z = [param.h_z ; param.h_z(end)];
70 |
71 | h_xr = repmat(h_x(:)',length(h_z),1);
72 | h_zr = repmat(h_z(:),1,length(h_x));
73 | dV = (h_xr.*h_zr)';
74 | dV = dV(:);
75 |
76 | R0=min(dV)^(1/3);
77 | Q=0;
78 | pos = [param.pos.C ; param.pos.P];
79 | % pos = pos(pos(:,2)==0 , :);
80 | % pos(pos(:,2)==0 , :) = [];
81 | n=length(pos);
82 |
83 | for i=1:n
84 | R = sqrt((X-pos(i,1)).^2 + (Z-pos(i,2)).^2);
85 |
86 | R=(R+R0).^3;
87 | R=(dV./R).^2;
88 | Q=Q+R;
89 | end
90 |
91 | Q=Q.^(beta/4);
92 | % Q(Q<1e-3) = 1e-3;
93 |
94 | Q = reshape(Q,param.nb_col,param.nb_ligne)';
95 | Q(:,[1:param.nb_pad_bloc+param.nb_surr end-(param.nb_pad_bloc+param.nb_surr):end]) = 1;
96 | Q(end-(param.nb_pad_bloc+param.nb_surr):end,:) = 1;
97 | % Q(:,[1:param.nb_pad_bloc+param.nb_surr-3 end-(param.nb_pad_bloc+param.nb_surr)+3:end]) = 1;
98 | % Q(end-(param.nb_pad_bloc+param.nb_surr)+3:end,:) = 1;
99 | end
--------------------------------------------------------------------------------
/functions/find_k.m:
--------------------------------------------------------------------------------
1 | function [k,wk,N] = find_k(N,k2)
2 |
3 | %%========================================================================%
4 | % %
5 | % 2.5D frequency process %
6 | % %
7 | %%========================================================================%
8 | % %
9 | % In: %
10 | % ----------- %
11 | % N : number of frequencies considered %
12 | % k2 : reference frequency %
13 | % %
14 | % Out: %
15 | % ----------- %
16 | % k : number of frequencies considered %
17 | % wk : reference frequency %
18 | % N : number of frequencies considered %
19 | % %
20 | %%========================================================================%
21 | % Copyright (C) 2019 Simon GERNEZ and Abderrezak BOUCHEDDA %
22 | %%========================================================================%
23 | % %
24 | % Contacts: %
25 | % %
26 | % Simon GERNEZ %
27 | % simon.gernez@ete.inrs.ca %
28 | % Institut National de la Recherche Scientifique %
29 | % Centre Eau-Terre-Environnement %
30 | % http://www.ete.inrs.ca/ %
31 | % %
32 | % Abderrezak BOUCHEDDA %
33 | % Abderrezak.Bouchedda@ete.inrs.ca %
34 | % Institut National de la Recherche Scientifique %
35 | % Centre Eau-Terre-Environnement %
36 | % http://www.ete.inrs.ca/ %
37 | % %
38 | % This program is free software; you can redistribute it and/or modify %
39 | % it under the terms of the GNU General Public License as published by %
40 | % the Free Software Foundation; either version 2 of the License, or %
41 | % (at your option) any later version. %
42 | % %
43 | % This program is distributed in the hope that it will be useful, %
44 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
45 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
46 | % GNU General Public License for more details. %
47 | % %
48 | % You should have received a copy of the GNU General Public License %
49 | % along with this program; if not, write to the Free Software %
50 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
51 |
52 | %% Code
53 |
54 | kk2=k2;
55 | k2=sqrt(k2);
56 | k1=0;
57 |
58 | [xk1,wk1]=Gausslp(N);
59 | [xk2,wk2]=Gausslgp(N-3);
60 |
61 | k=[(((k2-k1)*xk1+k1+k2)/2).^2 xk2+kk2]';
62 | wk=[(k2-k1)*wk1/2 wk2];
63 |
64 | end
65 |
66 |
67 | %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 | function p=Lgndrp(N) % Legendre polynomial
69 | if N<=0
70 | p=1; % n*Ln(t)=(2n-1)t Ln-1(t)-(n-1)Ln-2(t)
71 | elseif N==1
72 | p=[1 0];
73 | else
74 | p=((2*N-1)*[Lgndrp(N-1) 0]-(N-1)*[0 0 Lgndrp(N-2)])/N;
75 | end
76 | end
77 |
78 | %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 | function p=Laguerp(N) %Legendre polynomial
80 | M=N:-1:0;
81 | p=factorial(N)*(((-1).^M)./factorial(M)).*((factorial(N))./(factorial(N-M).*factorial(M)));
82 | end
83 |
84 | %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 | function [t,w]=Gausslp(N)
86 | if N<0
87 | error('Gauss-Legendre polynomial of negative order?');
88 | end
89 | t=roots(Lgndrp(N))'; % make it a row vector
90 | A(1,:)= ones(1,N); b(1)=2;
91 | for n=2:N
92 | A(n,:)=A(n-1,:).*t;
93 | if mod(n,2)==0
94 | b(n)=0;
95 | else
96 | b(n)=2/n;
97 | end
98 | end
99 | w= b/A';
100 | end
101 |
102 | %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 | function [t,w]=Gausslgp(N)
104 | if N<0
105 | error('Gauss-Laguerre polynomial of negative order?');
106 | end
107 | t=roots(Laguerp(N))'; % make it a row vector
108 | A(1,:)= ones(1,N); b(1)=1;
109 | for n=2:N
110 | A(n,:)=A(n-1,:).*t;
111 | b(n)=(n-1)*b(n-1);
112 | end
113 | w= b/A';
114 | end
--------------------------------------------------------------------------------
/functions/gauss_newton_inversion_anis.m:
--------------------------------------------------------------------------------
1 | function [param, XYZ, Inv] = gauss_newton_inversion_anis(param,XYZ)
2 |
3 | %%========================================================================%
4 | % %
5 | % Gauss Newton inversion %
6 | % %
7 | %%========================================================================%
8 | % %
9 | % In : %
10 | % ----------- %
11 | % param: parameters structure %
12 | % XYZ: electrodes position structure %
13 | % draw_plots: 0: no figure ; 1: dray figures %
14 | % %
15 | % Out : %
16 | % ----------- %
17 | % These structures are saved after each iteration in a iter_#.mat file: %
18 | % param: parameters structure %
19 | % XYZ: electrodes position structure %
20 | % Inv: inversion results at each iteration: %
21 | % Inv.rho: different rho components sections %
22 | % Inv.D: data weighting matrix (from Calc_data_weight.m) %
23 | % Inv.d_cal: apparent resistivities calculated at the ith iteration%
24 | % Inv.rho_app_pos_index: data considered. Negative apparent %
25 | % resistivities are ignored at each iter. %
26 | % Inv.rms: rms value %
27 | % Inv.beta_weighting: weigthing coefficients %
28 | % Inv.sens_weighting: weigthing section %
29 | % Inv.Ki2: Ki^2 value %
30 | % Inv.CTC: model regularization matrix (from CtC_anis.m) %
31 | % %
32 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 | %%========================================================================%
34 | % Copyright (C) 2019 Simon GERNEZ and Abderrezak BOUCHEDDA %
35 | %%========================================================================%
36 | % %
37 | % Contacts: %
38 | % %
39 | % Simon GERNEZ %
40 | % simon.gernez@ete.inrs.ca %
41 | % Institut National de la Recherche Scientifique %
42 | % Centre Eau-Terre-Environnement %
43 | % http://www.ete.inrs.ca/ %
44 | % %
45 | % Abderrezak BOUCHEDDA %
46 | % Abderrezak.Bouchedda@ete.inrs.ca %
47 | % Institut National de la Recherche Scientifique %
48 | % Centre Eau-Terre-Environnement %
49 | % http://www.ete.inrs.ca/ %
50 | % %
51 | % This program is free software; you can redistribute it and/or modify %
52 | % it under the terms of the GNU General Public License as published by %
53 | % the Free Software Foundation; either version 2 of the License, or %
54 | % (at your option) any later version. %
55 | % %
56 | % This program is distributed in the hope that it will be useful, %
57 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
58 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
59 | % GNU General Public License for more details. %
60 | % %
61 | % You should have received a copy of the GNU General Public License %
62 | % along with this program; if not, write to the Free Software %
63 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
64 |
65 | %%========================================================================%
66 |
67 | %% ------ Initialize -----------------------------------------
68 |
69 | tic
70 |
71 | X = reshape(param.grille(:,1),param.nb_ligne,param.nb_col);
72 | Z = -reshape(param.grille(:,2),param.nb_ligne,param.nb_col);
73 |
74 | if strcmp(param.inv.invparam,'log resistivity')
75 |
76 | if isempty(param.const.rho_init) % if no initial model
77 | [K] = geometric_factor(XYZ,param.flag.geo_factor);
78 | nb_meas = length(param.MEAS.Res);
79 | mm = median(K.*param.MEAS.Res);
80 |
81 | if param.flag.inv.p == 2
82 | % solution_vector : [rho1_init ; rho2_init]
83 | solution_vector = log(mm)*ones(param.nb_ligne*param.nb_col,1);
84 | solution_vector = [solution_vector ; log(param.anis_init*mm)*ones(param.nb_ligne*param.nb_col,1)]; % + rho_2 initial
85 | elseif param.flag.inv.p == 3
86 | % solution_vector : [rho1_init ; rho2_init ; angles_init]
87 | solution_vector = log(mm)*ones(param.nb_ligne*param.nb_col,1); % rho_1 initial
88 | solution_vector = [solution_vector ; log(param.anis_init*mm)*ones(param.nb_ligne*param.nb_col,1)]; % + rho_2 initial
89 | solution_vector = [solution_vector ; log(60)*ones(param.nb_ligne*param.nb_col,1)]; % + angle initial
90 | end
91 |
92 | [rho]= vec2model(exp(solution_vector),param.nb_ligne,param.nb_col, param.flag.inv.p);
93 |
94 | % constraints
95 | if param.const_TrueFalse == true
96 | param.const.vect = log(param.const_vect);
97 | end
98 |
99 | else % if initial model (has to be a structure)
100 | nb_meas = length(param.MEAS.Res);
101 |
102 | if param.flag.inv.p == 2
103 | param.const.rho_init.xx = param.const.rho_init.xx';
104 | param.const.rho_init.zz = param.const.rho_init.zz';
105 | solution_vector = [param.const.rho_init.xx(:) ; param.const.rho_init.zz(:)];
106 | end
107 |
108 | solution_vector = log(solution_vector(:));
109 | [rho] = vec2model(exp(solution_vector),param.nb_ligne,param.nb_col, param.flag.inv.p);
110 |
111 | if param.const_TrueFalse == true
112 | param.const.vect = log(param.const_vect);
113 | end
114 | end
115 |
116 | if ~isempty(param.const.rho_ref) && param.const.rho_ref ~= 0
117 | param.const.rho_ref = log(param.const.rho_ref);
118 | end
119 |
120 | else
121 | errordlg('gauss_newton_inversion_anis function : inversion parameter type is not defined or not suitable',...
122 | 'inversion parameter Error');
123 |
124 | end
125 |
126 | % define reference model
127 | if isempty(param.const.rho_ref)
128 | param.const.rho_ref=0;
129 | end
130 |
131 | % Set the constraints values
132 | if isfield(param,'const_ind') && param.const_TrueFalse == true
133 | param.const.P = ones(length(solution_vector),1);
134 | param.const.P(param.const_ind) = 0;
135 | solution_vector(param.const_ind) = param.const.vect;
136 | cglscd_init = ones(length(solution_vector),1);
137 | cglscd_init(param.const_ind) = param.const.vect;
138 | disp('Constraints added')
139 | else
140 | param.const.P = [];
141 | cglscd_init = ones(length(solution_vector),1);
142 | end
143 |
144 | % weight for matrix C
145 | wt = ones(size(solution_vector));
146 |
147 | % allocate some numbers
148 | gc = 1;
149 | normg0 = 1;
150 | Ki2 = [];
151 |
152 | % data weight matrix calculation
153 | [D,dtw_pre] = Calc_data_weight(param);
154 | D_orig = D;
155 | dtw_pre_orig = dtw_pre;
156 |
157 | % flatness or smoothness or covariance matrix calculation
158 | [CTC,~,~] = CtC_anis(wt,param,param.flag.inv.p);
159 |
160 | %% Start Gauss-Newton loop
161 |
162 | itc = 0;
163 |
164 | while(norm(gc)/normg0 > param.inv.tol && itc < param.inv.maxit && norm(gc) > 1e-20)
165 | %% iteration count
166 |
167 | itc = itc+1;
168 | disp(['Iteration #',num2str(itc)])
169 | toc
170 |
171 | if itc > 1
172 | param.inv.BETA = max(param.inv.BETA/2,10^-6);
173 | end
174 |
175 | % potential and sensitivity calculation
176 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 |
178 | disp(['Sensitivity calculus iteration #',num2str(itc)]);
179 | [d,S] = calcul_u_S_anis(param,XYZ,rho,1);
180 |
181 | K = geometric_factor(XYZ,param.flag.geo_factor);
182 | if strcmp(param.inv.invparam,'log resistivity')
183 | dobs = log((K.*param.MEAS.Res));
184 | else
185 | dobs = (K.*param.MEAS.Res);
186 | end
187 | D = D_orig;
188 | dtw_pre = dtw_pre_orig;
189 |
190 | % We ignore for this each iteration the quadripoles measuring a negative apparent resistivity
191 | rho_app = (K'.*d);
192 | if strcmp(param.inv.invparam,'log resistivity')
193 | rho_app_pos_index = (rho_app > .1);
194 | end
195 |
196 | d = d(rho_app_pos_index);
197 | K = K(rho_app_pos_index);
198 | dobs = dobs(rho_app_pos_index);
199 | D = D(rho_app_pos_index,rho_app_pos_index);
200 | dtw_pre = dtw_pre(rho_app_pos_index);
201 |
202 | if param.flag.inv.p == 2
203 | J = [S.xx(rho_app_pos_index,:) S.zz(rho_app_pos_index,:)];
204 | elseif param.flag.inv.p == 3
205 | J = [S.xx(rho_app_pos_index,:) S.zz(rho_app_pos_index,:) S.xz(rho_app_pos_index,:)];
206 | end
207 |
208 | %% Weigthing ------------------------------------------------------
209 |
210 | if param.inv.weight == true && itc >= param.inv.weightMinit && itc <= param.inv.weightMaxit
211 | % -----------------------------------------------------------------
212 |
213 | % Distance weighting - recommended
214 | if strcmp(param.inv.weightFun,'distance')
215 | beta_weight_1 = .1;
216 | beta_weight_2 = .1;
217 | message_weight = strcat('Weighting based weighting function applied (iter #',num2str(itc),')');
218 | disp(message_weight)
219 | wt1 = distance_weighting(param,beta_weight_1);
220 | wt2 = distance_weighting(param,beta_weight_2);
221 | wt1 = wt1';
222 | wt2 = wt2';
223 | % figure
224 | % imagesc(0:40,0:9,wt1(param.h_x==1/x, param.h_z==1/z));colormap jet;colorbar
225 | % wt = [wt1 , ones(size(wt2))];
226 | % wt = [ones(size(wt1)) , wt2];
227 | wt = [wt1 , wt2];
228 |
229 | wt = wt(:);
230 |
231 | [CTC,~,~] = CtC_anis(wt,param,param.flag.inv.p); %
232 |
233 |
234 | % Sensitivity weighting
235 | elseif strcmp(param.inv.weightFun,'sensitivity')
236 | % message_weight = strcat('Sensitivity based weighting function applied (iter #',num2str(itc),', Ki = ',num2str(Ki),')');
237 | % disp(message_weight)
238 |
239 | wt = (sum(J.*J));
240 |
241 | beta_weight_1 = 0.1;
242 | beta_weight_2 = 0.1;
243 |
244 | wt1 = wt(1:param.nb_col*param.nb_ligne).^(beta_weight_1/4);
245 | wt1 = reshape(wt1,param.nb_col,param.nb_ligne)';
246 | wt1(:,[1:param.nb_pad_bloc+20+1 , end-(param.nb_pad_bloc+16):end]) = 1;
247 | % wt1(end-(param.nb_pad_bloc+1):end,:) = 1;
248 | % wt1(:,[1:param.nb_pad_bloc+param.nb_raff(1)*(param.nb_surr) , end-(param.nb_pad_bloc+param.nb_raff(1)*(param.nb_surr)-1):end]) = 1;
249 | wt1(end-(param.nb_pad_bloc+param.nb_raff(2)*param.nb_surr):end,:) = 1;
250 |
251 | wt2 = wt(param.nb_col*param.nb_ligne+1:end).^(beta_weight_2/4);
252 | wt2 = reshape(wt2,param.nb_col,param.nb_ligne)';
253 | wt2(:,[1:param.nb_pad_bloc+20+1 , end-(param.nb_pad_bloc+16):end]) = 1;
254 | % wt2(end-(param.nb_pad_bloc+1):end,:) = 1;
255 | % wt2(:,[1:param.nb_pad_bloc+param.nb_raff(1)*(param.nb_surr) , end-(param.nb_pad_bloc+param.nb_raff(1)*(param.nb_surr)-1):end]) = 1;
256 | wt2(end-(param.nb_pad_bloc+param.nb_raff(2)*param.nb_surr):end,:) = 1;
257 |
258 | wt = [wt1' , wt2'];
259 | % wt = [wt1' , ones(size(wt2'))];
260 |
261 | fig1 = figure('visible','off');
262 | subplot(121)
263 | imagesc(wt1);
264 | title('\omega_1')
265 | colormap jet;
266 | colorbar
267 |
268 | subplot(122)
269 | imagesc(wt2);
270 | title('\omega_2')
271 | colormap jet;
272 | colorbar
273 |
274 | set(gcf,'Visible','off','CreateFcn','set(gcf,''Visible'',''on'')')
275 | iterName = num2str(itc);
276 | pathName = strcat('./savefig/weightings',iterName,'.fig');
277 | savefig(fig1,pathName)
278 | close
279 |
280 | [CTC,~,~] = CtC_anis(wt,param,param.flag.inv.p); %
281 |
282 | else
283 | error('Weighting function has to be param.inv.weightFun=''distance'' or param.inv.weightFun=''sensitivity''')
284 |
285 | end
286 |
287 |
288 | % Unweight the model after max_itc_weights iterations
289 | elseif param.inv.weight == true && itc > param.inv.weightMaxit
290 | beta_weight_1 = nan;
291 | beta_weight_2 = nan;
292 | wt = ones(size(solution_vector));
293 |
294 | [CTC,~,~] = CtC_anis(wt,param,param.flag.inv.p); %
295 |
296 |
297 | % Conserve last applied weighting vector after max_itc_weights iterations
298 | else
299 | beta_weight_1 = nan;
300 | beta_weight_2 = nan;
301 |
302 | end
303 |
304 | if ~all(K'.*d > 0)
305 | disp('Negative apparent resistivity')
306 | disp(' ')
307 | end
308 |
309 | d = log(K'.*d)';
310 |
311 | clear S
312 |
313 | %% Evaluate model perturbation
314 |
315 | [s,error_cglscd,~] = cglscd(J,cglscd_init, (dobs-d),param.inv.BETA,CTC,solution_vector-param.const.rho_ref,D,param.const.P, 1000, 10^-6,param.inv.appl_fct_reg);
316 | error_cglscd % indication of the iteration efficiency
317 |
318 | if itc == 1
319 | normg0 = norm(gc);
320 | end
321 |
322 | %% Test for convergence
323 |
324 | if max(abs(s)) < 1e-6
325 | errordlg('gauss_newton_inversion_anis function : STEP size too small CONVERGE ',...
326 | 'inversion stop');
327 | end;
328 |
329 | % Try the step
330 | mu1 = 1;
331 |
332 | % Calculate the value of data objective function
333 | fd = 0.5*(d-dobs)'*(D.^2)*(d-dobs);
334 |
335 | %% Armijo Line search
336 |
337 | % Calculate the value of model objective function
338 | fm = 0.5*( (solution_vector-param.const.rho_ref)'*param.inv.BETA*CTC*(solution_vector-param.const.rho_ref) );
339 |
340 | % Add them for the total Objective function
341 | fc = fd + fm;
342 |
343 | % Evaluate the gradient
344 | gc = (((D.^2)*(d-dobs))'*J)' + param.inv.BETA*CTC*(solution_vector-param.const.rho_ref);
345 | clear J
346 |
347 | for ils = 1 : 6
348 |
349 | disp(['Line search calculation #',num2str(ils)]);
350 |
351 | xt = solution_vector + mu1*s;
352 |
353 | %% Evaluate the new objective function
354 |
355 | if strcmp(param.inv.invparam,'log resistivity') == 1 % log parameters
356 | if ~isempty(param.const.rho_min)
357 | xt(exp(xt) < param.const.rho_min) = param.const.rho_min;
358 | end
359 | if ~isempty(param.const.rho_max)
360 | xt(exp(xt) > param.const.rho_max) = param.const.rho_max;
361 | end
362 | rho = vec2model(exp(xt),param.nb_ligne,param.nb_col,param.flag.inv.p);
363 | end
364 |
365 | [d] = calcul_u_S_anis(param,XYZ,rho,0);
366 |
367 | K = geometric_factor(XYZ,param.flag.geo_factor);
368 | dobs = log(K.*param.MEAS.Res);
369 | D = D_orig;
370 | dtw_pre = dtw_pre_orig;
371 |
372 | % We ignore for each iteration the quadripoles producing a negative apparent resistivity
373 | rho_app = (K'.*d);
374 | rho_app_pos_index = (rho_app > .1);
375 |
376 | d = d(rho_app_pos_index);
377 | K = K(rho_app_pos_index);
378 | dobs = dobs(rho_app_pos_index);
379 | D = D(rho_app_pos_index,rho_app_pos_index);
380 | dtw_pre = dtw_pre(rho_app_pos_index);
381 |
382 | if ~all(K'.*d > 0)
383 | disp('Negative apparent resistivity')
384 | disp(' ')
385 | end
386 |
387 | d = log(K'.*d)';
388 |
389 | fd = 0.5*(d-dobs)'*(D.^2)*(d-dobs);
390 | fm = 0.5*((xt-param.const.rho_ref)'*param.inv.BETA*CTC*(xt-param.const.rho_ref));
391 | ft = fd+fm;
392 |
393 | fgoal = fc - param.inv.alp*mu1*(s'*gc);
394 |
395 | if ft < fgoal
396 | break
397 | else
398 | mu1 = mu1/2;
399 | end;
400 |
401 | end % end line search
402 |
403 | rms_model = 100*sum(sqrt((((solution_vector-xt).^2)./(1e-10+solution_vector.^2))/(param.nb_ligne*param.nb_col)));
404 |
405 | if rms_model < param.inv.rms_model
406 | errordlg('gauss_newton_inversion function : rms_model < desired rms_model',...
407 | 'inversion convergence');
408 | break;
409 | end
410 |
411 | %% Update model
412 |
413 | solution_vector = xt;
414 |
415 | e = (D*(d-dobs));
416 | Ki = sum(e.^2) / nb_meas;
417 |
418 | % data reweigthing ( L1 or W-estimator)
419 | if ~strcmp(param.inv.dataweight.type,'const.weight')
420 | [D,~] = Calc_data_weight(param,e,dtw_pre);
421 | end
422 |
423 | Ki2 = [Ki2;Ki];
424 | rms_data = 100*sqrt(sum((d-dobs).^2))/(norm(dobs)); % misfit in percentages
425 |
426 | % Stock inv. infos into Inv structure
427 | Inv.rho{itc} = rho;
428 | Inv.D{itc} = D;
429 | Inv.d_cal{itc} = d;
430 | Inv.rho_app_pos_index{itc} = rho_app_pos_index;
431 | Inv.rms{itc} = rms_data;
432 | Inv.beta_weighting{itc} = [beta_weight_1 ; beta_weight_2];
433 | Inv.sens_weighting{itc} = wt;
434 | Inv.Ki2 = Ki2;
435 | Inv.CTC{itc} = CTC;
436 |
437 | % Display convergence info : # iter, Ki2, rmse
438 | [(1:itc)' , Ki2 , cell2mat(Inv.rms)'] %#ok
439 |
440 | str_save = strcat('iter_',num2str(itc),'.mat');
441 | save(str_save,'param','XYZ','Inv')
442 |
443 | end
444 |
445 | end
--------------------------------------------------------------------------------
/functions/geometric_factor.m:
--------------------------------------------------------------------------------
1 | function K = geometric_factor(XYZ,C1C2_config)
2 |
3 | %%========================================================================%
4 | % %
5 | % Geometric factor calculation %
6 | % %
7 | %%========================================================================%
8 | % %
9 | % In: %
10 | % ----------- %
11 | % XYZ: electrodes position structure %
12 | % C1C2_config: %
13 | % C1C2_config==1 (C1,C2) borehole electrodes %
14 | % C1C2_config==2 (C1,C2) surface electrodes %
15 | % C1C2_config==3 (C1) borehole electrodes ; (C2) surface electrodes %
16 | % C1C2_config==4 (C2) borehole electrodes ; (C2) surface electrodes %
17 | % %
18 | % Out: %
19 | % ----------- %
20 | % K: vector of the geometric factors corresponding to each quadrupole %
21 | % (Guo et al. 2014) %
22 | % %
23 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 | % Copyright (C) 2009 Abderrezak BOUCHEDDA
25 | %=====oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo====%
26 | % contact: ---------->\\\//// %
27 | % |_ _| %
28 | % (@ @) %
29 | % **********oooO***(_)***Oooo********** %
30 | % * -----> Abderrezak BOUCHEDDA<----- * %
31 | % * Abderrezak.Bouchedda@ete.inrs.ca * %
32 | % * INRS-ETE * %
33 | % * http://www.ete.inrs.ca/ete * %
34 | % ************************************* %
35 | % |_______| %
36 | % |__|__| %
37 | % () () %
38 | % ooO Ooo %
39 | % This program is free software; you can redistribute it and/or modify %
40 | % it under the terms of the GNU General Public License as published by %
41 | % the Free Software Foundation; either version 2 of the License, or %
42 | % (at your option) any later version. %
43 | % %
44 | % This program is distributed in the hope that it will be useful, %
45 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
46 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
47 | % GNU General Public License for more details. %
48 | % %
49 | % You should have received a copy of the GNU General Public License %
50 | % along with this program; if not, write to the Free Software %
51 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
52 | % %
53 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 | %%========================================================================%
55 |
56 | %% Calculation
57 |
58 | ind1 = find(C1C2_config == 1);
59 | ind2 = find(C1C2_config == 2);
60 | ind3 = find(C1C2_config == 3);
61 | ind4 = find(C1C2_config == 4);
62 |
63 | K = zeros(size(C1C2_config));
64 |
65 |
66 | if ~isempty(ind1)
67 | if isnan(XYZ.MEAS.C2(1,1)) && isnan(XYZ.MEAS.P2(1,1)) % pole-pole
68 | r2=0;
69 | r3=0;
70 | r4=0;
71 | r21=0;
72 | r31=0;
73 | r41=0;
74 | elseif isnan(XYZ.MEAS.C2(1,1)) && ~isnan(XYZ.MEAS.P2(1,1)) % pole-dipole
75 | r2=0;
76 | r4=0;
77 | r21=0;
78 | r41=0;
79 | r3=1./((XYZ.MEAS.C1(ind1,1)-XYZ.MEAS.P2(ind1,1)).^2 +(XYZ.MEAS.C1(ind1,2)-XYZ.MEAS.P2(ind1,2)).^2).^.5; % C1-P2
80 | r31=1./((XYZ.MEAS.C1(ind1,1)-XYZ.MEAS.P2(ind1,1)).^2 +(-XYZ.MEAS.C1(ind1,2)-XYZ.MEAS.P2(ind1,2)).^2).^.5; %C1 mirror -P2
81 | elseif ~isnan(XYZ.MEAS.C2(1,1)) && ~isnan(XYZ.MEAS.P2(1,1)) % dipole-dipole
82 | r2=1./((XYZ.MEAS.C2(ind1,1)-XYZ.MEAS.P1(ind1,1)).^2 +(XYZ.MEAS.C2(ind1,2)-XYZ.MEAS.P1(ind1,2)).^2).^.5; % C2-P1
83 | r3=1./((XYZ.MEAS.C1(ind1,1)-XYZ.MEAS.P2(ind1,1)).^2 +(XYZ.MEAS.C1(ind1,2)-XYZ.MEAS.P2(ind1,2)).^2).^.5; % C1-P2
84 | r4=1./((XYZ.MEAS.C2(ind1,1)-XYZ.MEAS.P2(ind1,1)).^2 +(XYZ.MEAS.C2(ind1,2)-XYZ.MEAS.P2(ind1,2)).^2).^.5; % C2-P2
85 | r21=1./((XYZ.MEAS.C2(ind1,1)-XYZ.MEAS.P1(ind1,1)).^2 +(-XYZ.MEAS.C2(ind1,2)-XYZ.MEAS.P1(ind1,2)).^2).^.5; %C2 mirror -P1
86 | r31=1./((XYZ.MEAS.C1(ind1,1)-XYZ.MEAS.P2(ind1,1)).^2 +(-XYZ.MEAS.C1(ind1,2)-XYZ.MEAS.P2(ind1,2)).^2).^.5; %C1 mirror -P2
87 | r41=1./((XYZ.MEAS.C2(ind1,1)-XYZ.MEAS.P2(ind1,1)).^2 +(-XYZ.MEAS.C2(ind1,2)-XYZ.MEAS.P2(ind1,2)).^2).^.5; %C2 mirror -P2
88 | else
89 | errordlg('geometric factor function : array type is not defined ');
90 | end
91 |
92 | r1=1./((XYZ.MEAS.C1(ind1,1)-XYZ.MEAS.P1(ind1,1)).^2 +(XYZ.MEAS.C1(ind1,2)-XYZ.MEAS.P1(ind1,2)).^2).^.5; % C1-P1
93 | r11=1./((XYZ.MEAS.C1(ind1,1)-XYZ.MEAS.P1(ind1,1)).^2 +(-XYZ.MEAS.C1(ind1,2)-XYZ.MEAS.P1(ind1,2)).^2).^.5; % C1 mirror -P1
94 |
95 | K(ind1)=(4*pi)./(r1+r11-r2-r21-r3-r31+r4+r41);
96 | end
97 |
98 | if ~isempty(ind2)
99 | if isnan(XYZ.MEAS.C2(1,1)) && isnan(XYZ.MEAS.P2(1,1)) % pole-pole
100 | r2=0;
101 | r3=0;
102 | r4=0;
103 | elseif isnan(XYZ.MEAS.C2(1,1)) && ~isnan(XYZ.MEAS.P2(1,1)) % pole-dipole
104 | r2=0;
105 | r4=0;
106 | r3=1./((XYZ.MEAS.C1(ind2,1)-XYZ.MEAS.P2(ind2,1)).^2 +(XYZ.MEAS.C1(ind2,2)-XYZ.MEAS.P2(ind2,2)).^2).^.5; % C1-P2
107 | elseif ~isnan(XYZ.MEAS.C2(1,1)) && ~isnan(XYZ.MEAS.P2(1,1)) % dipole-dipole
108 | r2=1./((XYZ.MEAS.C2(ind2,1)-XYZ.MEAS.P1(ind2,1)).^2 +(XYZ.MEAS.C2(ind2,2)-XYZ.MEAS.P1(ind2,2)).^2).^.5; % C2-P1
109 | r3=1./((XYZ.MEAS.C1(ind2,1)-XYZ.MEAS.P2(ind2,1)).^2 +(XYZ.MEAS.C1(ind2,2)-XYZ.MEAS.P2(ind2,2)).^2).^.5; % C1-P2
110 | r4=1./((XYZ.MEAS.C2(ind2,1)-XYZ.MEAS.P2(ind2,1)).^2 +(XYZ.MEAS.C2(ind2,2)-XYZ.MEAS.P2(ind2,2)).^2).^.5; % C2-P2
111 | else
112 | errordlg('geometric_factor function : array type is not defined ');
113 | end
114 |
115 | r1=1./((XYZ.MEAS.C1(ind2,1)-XYZ.MEAS.P1(ind2,1)).^2 +(XYZ.MEAS.C1(ind2,2)-XYZ.MEAS.P1(ind2,2)).^2).^.5; % C1-P1
116 |
117 | K(ind2)=(2*pi)./(r1-r2-r3+r4);
118 | end
119 |
120 | if ~isempty(ind3)
121 | if ~isnan(XYZ.MEAS.C2(1,1)) && ~isnan(XYZ.MEAS.P2(1,1)) % dipole-dipole
122 | r2=1./((XYZ.MEAS.C2(ind3,1)-XYZ.MEAS.P1(ind3,1)).^2 +(XYZ.MEAS.C2(ind3,2)-XYZ.MEAS.P1(ind3,2)).^2).^.5; % C2-P1
123 | r3=1./((XYZ.MEAS.C1(ind3,1)-XYZ.MEAS.P2(ind3,1)).^2 +(XYZ.MEAS.C1(ind3,2)-XYZ.MEAS.P2(ind3,2)).^2).^.5; % C1-P2
124 | r4=1./((XYZ.MEAS.C2(ind3,1)-XYZ.MEAS.P2(ind3,1)).^2 +(XYZ.MEAS.C2(ind3,2)-XYZ.MEAS.P2(ind3,2)).^2).^.5; % C2-P2
125 | r21=0; %C2 mirror -P1
126 | r31=1./((XYZ.MEAS.C1(ind3,1)-XYZ.MEAS.P2(ind3,1)).^2 +(-XYZ.MEAS.C1(ind3,2)-XYZ.MEAS.P2(ind3,2)).^2).^.5; %C1 mirror -P2
127 | r41=0; %C2 mirror -P2
128 | else
129 | errordlg('geometric factor function : array type is not defined ');
130 | end
131 |
132 | r1=1./((XYZ.MEAS.C1(ind3,1)-XYZ.MEAS.P1(ind3,1)).^2 +(XYZ.MEAS.C1(ind3,2)-XYZ.MEAS.P1(ind3,2)).^2).^.5; % C1-P1
133 | r11=1./((XYZ.MEAS.C1(ind3,1)-XYZ.MEAS.P1(ind3,1)).^2 +(-XYZ.MEAS.C1(ind3,2)-XYZ.MEAS.P1(ind3,2)).^2).^.5; % C1 mirror -P1
134 |
135 | K(ind3)=(2*pi)./(.5*(r1+r11)-r2-r21-.5*(r3+r31)+r4+r41);
136 | end
137 |
138 | if ~isempty(ind4)
139 |
140 | if ~isnan(XYZ.MEAS.C2(1,1)) && ~isnan(XYZ.MEAS.P2(1,1)) % dipole-dipole
141 | r2=1./((XYZ.MEAS.C2(ind4,1)-XYZ.MEAS.P1(ind4,1)).^2 +(XYZ.MEAS.C2(ind4,2)-XYZ.MEAS.P1(ind4,2)).^2).^.5; % C2-P1
142 | r3=1./((XYZ.MEAS.C1(ind4,1)-XYZ.MEAS.P2(ind4,1)).^2 +(XYZ.MEAS.C1(ind4,2)-XYZ.MEAS.P2(ind4,2)).^2).^.5; % C1-P2
143 | r4=1./((XYZ.MEAS.C2(ind4,1)-XYZ.MEAS.P2(ind4,1)).^2 +(XYZ.MEAS.C2(ind4,2)-XYZ.MEAS.P2(ind4,2)).^2).^.5; % C2-P2
144 |
145 | r21=1./((XYZ.MEAS.C2(ind4,1)-XYZ.MEAS.P1(ind4,1)).^2 +(-XYZ.MEAS.C2(ind4,2)-XYZ.MEAS.P1(ind4,2)).^2).^.5;%C2 mirror -P1
146 | r31=0; %C1 mirror -P2
147 | r41=1./((XYZ.MEAS.C2(ind4,1)-XYZ.MEAS.P2(ind4,1)).^2 +(-XYZ.MEAS.C2(ind4,2)-XYZ.MEAS.P2(ind4,2)).^2).^.5; %C2 mirror -P2
148 | else
149 | errordlg('geometric factor function : array type is not defined ');
150 | end
151 |
152 | r1=1./((XYZ.MEAS.C1(ind4,1)-XYZ.MEAS.P1(ind4,1)).^2 +(XYZ.MEAS.C1(ind4,2)-XYZ.MEAS.P1(ind4,2)).^2).^.5; % C1-P1
153 | r11=0; % C1 mirror -P1
154 |
155 | K(ind4)=(2*pi)./((r1+r11)-.5*(r2+r21)-(r3+r31)+.5*(r4+r41));
156 | end
157 |
158 | end
--------------------------------------------------------------------------------
/functions/getAperture.m:
--------------------------------------------------------------------------------
1 | function aperture = getAperture(quadril_points, linearArea_coef)
2 |
3 | %%========================================================================%
4 | % %
5 | % Gauss Newton inversion %
6 | % %
7 | %%========================================================================%
8 | % %
9 | % In : %
10 | % ----------- %
11 | % quadril_points: 4 points forming the quadrilateral of which we want %
12 | % to determine the surface. %
13 | % (row vector) -> 4 points, 8 coordinates %
14 | % [(xC1,zC1), (xC2,zC2), (xP1,zP1), (xP2,zP2)] %
15 | % linearArea_coef: coefficient applied on the inline quadrilateral %
16 | % to make its length comparable to a surface %
17 | % %
18 | % Out : %
19 | % ----------- %
20 | % aperture: area of the quadrilateral %
21 | % %
22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23 | %%========================================================================%
24 | % Copyright (C) 2019 Simon GERNEZ and Abderrezak BOUCHEDDA %
25 | %%========================================================================%
26 | % %
27 | % Contacts: %
28 | % %
29 | % Simon GERNEZ %
30 | % simon.gernez@ete.inrs.ca %
31 | % Institut National de la Recherche Scientifique %
32 | % Centre Eau-Terre-Environnement %
33 | % http://www.ete.inrs.ca/ %
34 | % %
35 | % Abderrezak BOUCHEDDA %
36 | % Abderrezak.Bouchedda@ete.inrs.ca %
37 | % Institut National de la Recherche Scientifique %
38 | % Centre Eau-Terre-Environnement %
39 | % http://www.ete.inrs.ca/ %
40 | % %
41 | % This program is free software; you can redistribute it and/or modify %
42 | % it under the terms of the GNU General Public License as published by %
43 | % the Free Software Foundation; either version 2 of the License, or %
44 | % (at your option) any later version. %
45 | % %
46 | % This program is distributed in the hope that it will be useful, %
47 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
48 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
49 | % GNU General Public License for more details. %
50 | % %
51 | % You should have received a copy of the GNU General Public License %
52 | % along with this program; if not, write to the Free Software %
53 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
54 |
55 | %%========================================================================%
56 |
57 | %% Calculation
58 |
59 | quadril_points = reshape(quadril_points,2,4)'; % 4x2 matrix : c1 : x coord ; c2 : z coord
60 |
61 | % Lengths
62 |
63 | % if length(unique(quadril_points(:,1))) == 1 || length(unique(quadril_points(:,2))) == 1 % Test colinearity vectors better
64 | % Inline electrodes: no proper area calculable
65 | if length(unique(quadril_points(:,1))) == 1
66 | Pmax = max(quadril_points(:,2));
67 | Pmin = min(quadril_points(:,2));
68 | aperture = (Pmax - Pmin)*linearArea_coef;
69 | return
70 | elseif length(unique(quadril_points(:,2))) == 1
71 | Pmax = max(quadril_points(:,1));
72 | Pmin = min(quadril_points(:,1));
73 | aperture = (Pmax - Pmin)*linearArea_coef;
74 | return
75 | end
76 |
77 | % Areas
78 |
79 | indP = convhull(quadril_points);
80 |
81 | quadril_points = quadril_points(indP(1:end-1),:);
82 |
83 | x = quadril_points(:,1);
84 | y = quadril_points(:,2);
85 |
86 | % area : http://www.mathopenref.com/coordpolygonarea.html
87 |
88 | x2 = circshift(x,-1);
89 | y2 = circshift(y,-1);
90 |
91 | aperture = abs(sum(x.*y2 - y.*x2)/2);
92 |
93 |
94 | end
--------------------------------------------------------------------------------
/functions/gradient_product_anis.m:
--------------------------------------------------------------------------------
1 | function gpa = gradient_product_anis(G,u,h_x,h_z,k)
2 |
3 | %%========================================================================%
4 | % %
5 | % Calculation of the finite-differences gradient needed for sensitivity %
6 | % in anisotropic media using the adjoint equation approach %
7 | % for each discrete frequency %
8 | % %
9 | %%========================================================================%
10 | % %
11 | % In: %
12 | % ----------- %
13 | % G : adjoint Green's function. %
14 | % For the electrical resistivity problem, G is the reciprocal %
15 | % potentials %
16 | % u : potential data %
17 | % h_x : x step vector %
18 | % h_z : z step vector %
19 | % k : wave number vector %
20 | % %
21 | % Out: %
22 | % ----------- %
23 | % g : anisotropic gradient product %
24 | % %
25 | %%========================================================================%
26 | % Copyright (C) 2019 Simon GERNEZ and Abderrezak BOUCHEDDA %
27 | %%========================================================================%
28 | % %
29 | % Contacts: %
30 | % %
31 | % Simon GERNEZ %
32 | % simon.gernez@ete.inrs.ca %
33 | % Institut National de la Recherche Scientifique %
34 | % Centre Eau-Terre-Environnement %
35 | % http://www.ete.inrs.ca/ %
36 | % %
37 | % Abderrezak BOUCHEDDA %
38 | % Abderrezak.Bouchedda@ete.inrs.ca %
39 | % Institut National de la Recherche Scientifique %
40 | % Centre Eau-Terre-Environnement %
41 | % http://www.ete.inrs.ca/ %
42 | % %
43 | % This program is free software; you can redistribute it and/or modify %
44 | % it under the terms of the GNU General Public License as published by %
45 | % the Free Software Foundation; either version 2 of the License, or %
46 | % (at your option) any later version. %
47 | % %
48 | % This program is distributed in the hope that it will be useful, %
49 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
50 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
51 | % GNU General Public License for more details. %
52 | % %
53 | % You should have received a copy of the GNU General Public License %
54 | % along with this program; if not, write to the Free Software %
55 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
56 |
57 | %%========================================================================%
58 |
59 | %% Initialisation
60 |
61 | n = length(h_z)+1;
62 | m = length(h_x)+1;
63 | la = n*m;
64 | nb_k = length(k);
65 | gpa.xx = zeros(n*m,nb_k); %m-n ; phi : McGillivray's notation
66 | gpa.xz = zeros(n*m,nb_k);
67 | gpa.zz = zeros(n*m,nb_k);
68 | gpa.yy = zeros(n*m,nb_k);
69 | %A = zeros(n*m,nb_k);
70 | %Sk = zeros(n*m,nb_k);
71 | h_x = h_x(:);
72 | h_z = h_z(:);
73 | k = k(:)';
74 | nb_k = length(k);
75 |
76 | % Index nodes for boundary condition (bc)
77 | ind_Rtc = sub2ind([n m],1,m); % index right top corner
78 | ind_Ltc = sub2ind([n m],1,1); % index left top corner
79 | ind_Rbc = sub2ind([n m],n,m); % index right bottom corner
80 | ind_Lbc = sub2ind([n m],n,1); % index left bottom corner
81 | %ind_T = sub2ind([n m],ones(1,m-2),[2:m-1]); % index top edge
82 | ind_B = sub2ind([n m],n*ones(1,m-2),2:m-1); % index bottom edge
83 | ind_R = sub2ind([n m],2:n-1,m*ones(1,n-2)); % index right edge
84 | ind_L = sub2ind([n m],2:n-1,ones(1,n-2)); % index left edge
85 | ind = 1:n*m; % index for all nodes
86 | ind_wbc = ind;
87 | ind_wbc ([ind_Ltc ind_Lbc ind_L ind_R ind_Rtc ind_Rbc ind_B]) = []; % index without bc
88 |
89 | dz = repmat([h_z;h_z(end)],m,1);
90 | dx = repmat([h_x' h_x(end)],n,1);
91 | dx = dx(:);
92 |
93 | dx = dx(ind_wbc,ones(1,nb_k));
94 | dz = dz(ind_wbc,ones(1,nb_k));
95 |
96 | U = zeros((n+2)*(m+1),nb_k);
97 | g = U;
98 |
99 | for i=1:nb_k
100 | u1 = reshape(u(:,i),n,m);
101 | u1 = [u1(2,:);u1;u1(end,:)];
102 | u1 = [u1 u1(:,end)];
103 | U(:,i) = u1(:);
104 |
105 | G1 = reshape(G(:,i),n,m);
106 | G1 = [G1(2,:) ; G1 ; G1(end,:)];
107 | G1 = [G1 G1(:,end)];
108 | g(:,i) = G1(:);
109 | end
110 |
111 | G = g;
112 | u = U;
113 | clear G1 u1 U g
114 |
115 | ind_wbc1 = ind_wbc;
116 | n = n+2;
117 | m = m+1;
118 | ind_wbc = 1:n*m; % index for all nodes
119 | ind_wbc = reshape(ind_wbc,n,m);
120 | ind_wbc = ind_wbc(2:end-2,2:end-2);
121 | ind_wbc = ind_wbc(:);
122 |
123 | %% Calculation
124 |
125 | gpa.xx(ind_wbc1,:) = ( ...
126 | (u(ind_wbc+n,:)-u(ind_wbc,:)) .* (G(ind_wbc+n,:)-G(ind_wbc,:)) ...
127 | + (u(ind_wbc+n+1,:)-u(ind_wbc+1,:)) .* (G(ind_wbc+n+1,:)-G(ind_wbc+1,:)) ...
128 | + ((u(ind_wbc+n,:)+u(ind_wbc+n+1,:)-u(ind_wbc-n,:)-u(ind_wbc-n+1,:))/4).*((G(ind_wbc+n,:)+G(ind_wbc+n+1,:)-G(ind_wbc-n,:)-G(ind_wbc-n+1,:))/4) ...
129 | + ((u(ind_wbc+2*n,:)+u(ind_wbc+2*n+1,:)-u(ind_wbc,:)-u(ind_wbc+1,:))/4).*((G(ind_wbc+2*n,:)+G(ind_wbc+2*n+1,:)-G(ind_wbc,:)-G(ind_wbc+1,:))/4) ...
130 | ).*dz./dx;
131 |
132 | gpa.zz(ind_wbc1,:) = ( ...
133 | (u(ind_wbc+1,:)-u(ind_wbc,:)).*(G(ind_wbc+1,:)-G(ind_wbc,:)) ...
134 | + (u(ind_wbc+n+1,:)-u(ind_wbc+n,:)).*(G(ind_wbc+n+1,:)-G(ind_wbc+n,:)) ...
135 | + ((u(ind_wbc+1,:)+u(ind_wbc+n+1,:)-u(ind_wbc-1,:)-u(ind_wbc+n-1,:))/4).*((G(ind_wbc+1,:)+G(ind_wbc+n+1,:)-G(ind_wbc-1,:)-G(ind_wbc+n-1,:))/4) ...
136 | + ((u(ind_wbc+2,:)+u(ind_wbc+n+2,:)-u(ind_wbc,:)-u(ind_wbc+n,:))/4).*((G(ind_wbc+2,:)+G(ind_wbc+n+2,:)-G(ind_wbc,:)-G(ind_wbc+n,:))/4) ...
137 | ).*dx./dz;
138 |
139 | gpa.xz(ind_wbc1,:) = ( ...
140 | + ((u(ind_wbc+n,:)-u(ind_wbc,:))).* ...
141 | ((G(ind_wbc+1,:)+G(ind_wbc+n+1,:)-G(ind_wbc-1,:)-G(ind_wbc+n-1,:))/4) ...
142 | + ((u(ind_wbc+n+1,:)-u(ind_wbc+1,:))).* ...
143 | ((G(ind_wbc+2,:)+G(ind_wbc+n+2,:)-G(ind_wbc,:)-G(ind_wbc+n,:))/4) ...
144 | + (u(ind_wbc+1,:)-u(ind_wbc,:)).* ...
145 | ((G(ind_wbc+n,:)+G(ind_wbc+n+1,:)-G(ind_wbc-n,:)-G(ind_wbc-n+1,:))/4) ...
146 | + (u(ind_wbc+n+1,:)-u(ind_wbc+1,:)).* ...
147 | ((G(ind_wbc+n,:)+G(ind_wbc+n+1,:)-G(ind_wbc-n,:)-G(ind_wbc-n+1,:))/4) ...
148 | + ((G(ind_wbc+n,:)-G(ind_wbc,:))).* ...
149 | ((u(ind_wbc+1,:)+u(ind_wbc+n+1,:)-u(ind_wbc-1,:)-u(ind_wbc+n-1,:))/4) ...
150 | + ((G(ind_wbc+n+1,:)-G(ind_wbc+1,:))).* ...
151 | ((u(ind_wbc+2,:)+u(ind_wbc+n+2,:)-u(ind_wbc,:)-u(ind_wbc+n,:))/4) ...
152 | + (G(ind_wbc+1,:)-G(ind_wbc,:)).* ...
153 | ((u(ind_wbc+n,:)+u(ind_wbc+n+1,:)-u(ind_wbc-n,:)-u(ind_wbc-n+1,:))/4) ...
154 | + (G(ind_wbc+n+1,:)-G(ind_wbc+1,:)).* ...
155 | ((u(ind_wbc+n,:)+u(ind_wbc+n+1,:)-u(ind_wbc-n,:)-u(ind_wbc-n+1,:))/4) ...
156 | );
157 |
158 | k1 = (k.^2)/4;
159 | gpa.yy(ind_wbc1,:) = 2*( G(ind_wbc,:).*u(ind_wbc,:) + G(ind_wbc+n,:).*u(ind_wbc+n,:) +...
160 | G(ind_wbc+1,:).*u(ind_wbc+1,:) + G(ind_wbc+n+1,:).*u(ind_wbc+n+1,:) ...
161 | ).*dx.*dz;
162 | gpa.yy = k1(ones(la,1),:).*gpa.yy;
163 |
164 | return
165 |
166 | end
--------------------------------------------------------------------------------
/functions/grille2d_elect.m:
--------------------------------------------------------------------------------
1 | function [grille,h_x,h_z] =grille2d_elect(hx,hz,fact,nb_pad_bloc,nb_raff,nb_surr,grid_plot)
2 |
3 | %%========================================================================%
4 | % %
5 | % % In: %
6 | % ----------- %
7 | % hx : bloc thick in x direction of interesting region %
8 | % hz : bloc thick in z direction of interesting region %
9 | % fact : pad factor %
10 | % nb_pad_bloc : nb of padded blocs %
11 | % nb_raff : refine the blocs in the intersting region by nb_aff(1) %
12 | % nb_aff(2) in z direction %
13 | % nb_surr : number of surrounding blocs %
14 | % %
15 | % such as: %
16 | % %
17 | % nb_pad_bloc nb_surr hx1 hx2 hx1 nb_surr nb_pad_bloc %
18 | % _____________________x0________________________________________ %
19 | % | | |surr b | | | |surr b | | | %
20 | % |_____|______|______ |____|____|____|_______|_______|_______|hz1 %
21 | % | | |surr b | | | |surr b | | | %
22 | % |_____|______|_______|____|____|____|_______|_______|_______|hz2 %
23 | % | | |surr b | | | |surr b | | | %
24 | % |_____|______|_______|____|____|____|_______|_______|_______|hz3 %
25 | % | | |surr |surr|surr|surr| surr | | | %
26 | % |padded blocs| b | b | b | b | b |padded blocs | %
27 | % |_____|______|_______|____|____|____|_______|_______|_______| %
28 | % | | | |padded blocs | | | | %
29 | % |_____|______|_______|____|____|____|_______|_______|_______| %
30 | % | | | | | | | | | | %
31 | % |_____|______|_______|____|____|____|_______|_______|_______| %
32 | % %
33 | % % Out: %
34 | % ----------- %
35 | % grille : grid ( ordered column by column %
36 | % h_x : mesh bloc thick in x direction %
37 | % h_z : mesh bloc thick in z direction %
38 | % %
39 | % % test: %
40 | % ----------- %
41 | % hz=ones(10,1); %
42 | % hx=ones(10,1); %
43 | % [X,Y] = meshgrid(0:9,0:9); %
44 | % x=X(:); %
45 | % y=Y(:);grille=[]; %
46 | % grille(:,1)=x; %
47 | % grille(:,2)=y; %
48 | % sigma=ones(10,10); %
49 | % [grille,h_x,h_z] = grille2d_elect(hx,hz,1.3,10,[1;1],0,1); %
50 | % %
51 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 | % Copyright (C) 2007 Abderrezak BOUCHEDDA
53 | %=====oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo====%
54 | % contact: \\\//// %
55 | % |_ _| %
56 | % (@ @) %
57 | % **********oooO***(_)***Oooo********** %
58 | % * -----> Abderrezak BOUCHEDDA<----- * %
59 | % * Abderrezak.Bouchedda@ete.inrs.ca * %
60 | % * INRS-ETE * %
61 | % * http://www.ete.inrs.ca/ete * %
62 | % ************************************* %
63 | % |_______| %
64 | % |__|__| %
65 | % () () %
66 | % ooO Ooo %
67 | % This program is free software; you can redistribute it and/or modify %
68 | % it under the terms of the GNU General Public License as published by %
69 | % the Free Software Foundation; either version 2 of the License, or %
70 | % (at your option) any later version. %
71 | % %
72 | % This program is distributed in the hope that it will be useful, %
73 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
74 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
75 | % GNU General Public License for more details. %
76 | % %
77 | % You should have received a copy of the GNU General Public License %
78 | % along with this program; if not, write to the Free Software %
79 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
80 | % %
81 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 | %%========================================================================%
83 |
84 | %% Calculation
85 |
86 | ind_x0 = nb_raff(1)*(nb_surr) + nb_pad_bloc + 1; % first electrode position in grid
87 | hx=hx(:);
88 | hz=hz(:);
89 | pwr = 1:nb_pad_bloc;
90 | factor = fact.^pwr;
91 | factor=factor(:);
92 |
93 | if isempty(nb_raff)
94 | nb_raff=[1;1];
95 | end
96 |
97 | hx1 = hx(1);
98 | hx2 = hx(end);
99 | hz1 = hz(end);
100 | % ind_x0 = ind_x0-3;
101 | hx=[hx1*ones(nb_surr,1);
102 | hx;
103 | hx2*ones(nb_surr,1)];
104 | hz=[hz;hz1*ones(nb_surr,1)];
105 |
106 | hx=repmat(hx',nb_raff(1),1);
107 | hx=hx(:)/nb_raff(1);
108 | hz=repmat(hz',nb_raff(2),1);
109 | hz=hz(:)/nb_raff(2);
110 |
111 | h_x = [hx1*factor(end:-1:1);hx;hx2*factor];
112 | h_z = [hz;hz1*factor];
113 | hx = [0;h_x];
114 | hz = [0;h_z];
115 |
116 | hx=cumsum(hx);
117 | hz=cumsum(hz);
118 |
119 | [X,Z]=meshgrid(hx,hz);
120 | x0=X(1,ind_x0);
121 | grille(:,1)=X(:)-x0; % x=0 position of first electrode (on the left)
122 | grille(:,2)=Z(:);
123 |
124 | if grid_plot==1
125 | plot(grille(:,1),-grille(:,2),'s','MarkerFaceColor','g','MarkerSize',2);
126 | gridxy(hx-x0,-hz);
127 | axis([min(grille(:,1)) max(grille(:,1)) min(-grille(:,2)) max(-grille(:,2))])
128 | end
129 | end
130 |
--------------------------------------------------------------------------------
/functions/integration_U.m:
--------------------------------------------------------------------------------
1 | function u = integration_U(U,wk,k,nbk1)
2 |
3 | %%========================================================================%
4 | % %
5 | % Integration of potential u, inverse Fourier transform %
6 | % %
7 | % ======================================================================= %
8 | % %
9 | % In: %
10 | % ----------- %
11 | % U : potential in wave number domain (matrix or vector) %
12 | % %
13 | % for one current electrode %
14 | % U = [U1_k1 U1_k2 ..... U1_kn] %
15 | % [U2_k1 U2_k2 ..... U2_kn] %
16 | % [. . . ] %
17 | % [. . . ] %
18 | % [Um_k1 U2_k2 ..... Um_kn] %
19 | % %
20 | % for nb current electrodes %
21 | % U = [U11_k1 U12_k1 ...U1nb_k1 U11_k2 U12_k2 ..... U1nb_kn] %
22 | % [U21_k1 U22_k1 ...U2nb_k1 U21_k2 U22_k2 ..... U2nb_kn] %
23 | % [. . . ] %
24 | % [. . . ] %
25 | % [Um1_k1 Um2_k1 ...Umnb_k1 Um1_k2 Um2_k2 ..... Umnb_kn] %
26 | % %
27 | % k : wave number %
28 | % k = [k1 k2 .... kn] %
29 | % %
30 | % Out: %
31 | % ----------- %
32 | % u : integrated potential into the spatial domain %
33 | % %
34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 | % Copyright (C) 2007 Abderrezak BOUCHEDDA %
36 | %=====oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo====%
37 | % contact: ---------->\\\//// %
38 | % |_ _| %
39 | % (@ @) %
40 | % **********oooO***(_)***Oooo********** %
41 | % * -----> Abderrezak BOUCHEDDA<----- * %
42 | % * Abderrezak.Bouchedda@ete.inrs.ca * %
43 | % * INRS-ETE * %
44 | % * http://www.ete.inrs.ca/ete * %
45 | % ************************************* %
46 | % |_______| %
47 | % |__|__| %
48 | % () () %
49 | % ooO Ooo %
50 | % This program is free software; you can redistribute it and/or modify %
51 | % it under the terms of the GNU General Public License as published by %
52 | % the Free Software Foundation; either version 2 of the License, or %
53 | % (at your option) any later version. %
54 | % %
55 | % This program is distributed in the hope that it will be useful, %
56 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
57 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
58 | % GNU General Public License for more details. %
59 | % %
60 | % You should have received a copy of the GNU General Public License %
61 | % along with this program; if not, write to the Free Software %
62 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
63 | % %
64 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 | %%========================================================================%
66 |
67 | %% Calculation
68 |
69 | [h,l]=size(U);
70 | k1=sqrt(k(1:nbk1));
71 | k1=k1(:)';
72 |
73 | % potential integration using gauss quadrature
74 | u = (4/pi) * ( wk(1:nbk1) * (U(:,1:nbk1).*k1(ones(h,1),:))' ) ...
75 | + (2/pi) * ( wk(nbk1+1:end) * U(:,1+nbk1:end)' );
76 |
77 | end
78 |
79 |
80 |
--------------------------------------------------------------------------------
/functions/matrix_coeff_anis.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/functions/matrix_coeff_anis.m
--------------------------------------------------------------------------------
/functions/tri_electr_pos.m:
--------------------------------------------------------------------------------
1 | function [pos,ind,L,sign]= tri_electr_pos(meas_posC1 , meas_posC2 , elect_bh1 , elect_bh2 , elect_sur , meas_posP1 , meas_posP2 , grille)
2 |
3 | %%========================================================================%
4 | % %
5 | % Electrode sorting function %
6 | % %
7 | %%========================================================================%
8 | % %
9 | % Sorts electrodes in order to model with a pole-pole, which allows for %
10 | % potential recombination in order to obtain the potential of a dipolar %
11 | % device %
12 | % %
13 | % In: %
14 | % ----------- %
15 | % meas_posC1: C1 measurement position %
16 | % meas_posC2: C2 measurement position %
17 | % elect_bh1 : borehole 1 electrodes position %
18 | % elect_bh2 : borehole 2 electrodes position %
19 | % elect_sur : surface electrodes position %
20 | % grille : grid nodes position %
21 | % %
22 | % Out: %
23 | % ----------- %
24 | % pos.C : current electrodes position for forward problem %
25 | % pos.P : potential electrodes position used as current electrodes %
26 | % for the calculation of reciprocal potential %
27 | % (sensit. calculation) %
28 | % ind.C1C2: index of current electrodes (pos.C) in meas_posC1 and %
29 | % meas_posC2 %
30 | % L : Contains the number of measures identified in 'ind' for %
31 | % each 'pos' position %
32 | % sign : +1 for a C1 electrode and -1 for a C2 electrode %
33 | % flag : 1 for borehole electrodes and 2 for surface electrodes %
34 | % %
35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 | % Copyright (C) 2007 Abderrezak BOUCHEDDA %
37 | %=====oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo====%
38 | % contact: ---------->\\\//// %
39 | % |_ _| %
40 | % (@ @) %
41 | % **********oooO***(_)***Oooo********** %
42 | % * -----> Abderrezak BOUCHEDDA<----- * %
43 | % * Abderrezak.Bouchedda@ete.inrs.ca * %
44 | % * INRS-ETE * %
45 | % * http://www.ete.inrs.ca/ete * %
46 | % ************************************* %
47 | % |_______| %
48 | % |__|__| %
49 | % () () %
50 | % ooO Ooo %
51 | % This program is free software; you can redistribute it and/or modify %
52 | % it under the terms of the GNU General Public License as published by %
53 | % the Free Software Foundation; either version 2 of the License, or %
54 | % (at your option) any later version. %
55 | % %
56 | % This program is distributed in the hope that it will be useful, %
57 | % but WITHOUT ANY WARRANTY; without even the implied warranty of %
58 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
59 | % GNU General Public License for more details. %
60 | % %
61 | % You should have received a copy of the GNU General Public License %
62 | % along with this program; if not, write to the Free Software %
63 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%
64 | % %
65 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 | %%========================================================================%
67 |
68 | %% Initialisation
69 |
70 | eps=.0001;
71 | [nh1,~]=size(elect_bh1);
72 | [nh2,~]=size(elect_bh2);
73 | [nsr,~]=size(elect_sur);
74 |
75 | ind=[];
76 | L=[];
77 | sign=[];
78 | I=[];
79 | pos1=[];
80 | flag=[];
81 |
82 | %% Calculation
83 |
84 | % find first borehole electrodes that are used in the measurements
85 | for i=1:nh1
86 | ind11 = find(meas_posC1(:,1) == elect_bh1(i,1) & meas_posC1(:,2) == elect_bh1(i,2));
87 | l1=length(ind11);
88 | ind12 = find(meas_posC2(:,1) == elect_bh1(i,1) & meas_posC2(:,2) == elect_bh1(i,2));
89 | l2=length(ind12);
90 |
91 | if (l1==0 && l2==0)
92 | I=[I,i]; % indices to throw electrodes that do not contribute to the measurements
93 | end
94 |
95 | L11=length(ind11); sign1= 1*ones(size(ind11)); % times that electrode elect_bh1(i,1) is used in meas.PosC1
96 | L12=length(ind12); sign2=-1*ones(size(ind12)); % times that electrode elect_bh1(i,1) is used in meas.PosC2
97 |
98 | L1=L11+L12;
99 | if L1==0
100 | L1=[];
101 | end
102 |
103 | ind=[ind;ind11;ind12];
104 | L=[L;L1];
105 | sign=[sign;sign1;sign2];
106 | end
107 |
108 | pos1=elect_bh1(I,:);flagg=ones(length(pos1),1);
109 | elect_bh1(I,:)=[]; I=[];
110 | flag=ones(length(elect_bh1),1);
111 |
112 | % find second borehole electrodes that are used in the measurement (C1 ou C2)
113 | for i=1:nh2
114 |
115 | ind11 = find(meas_posC1(:,1) == elect_bh2(i,1) & meas_posC1(:,2) == elect_bh2(i,2));
116 | l1=length(ind11);
117 | ind12 = find(meas_posC2(:,1) == elect_bh2(i,1) & meas_posC2(:,2) == elect_bh2(i,2));
118 | l2=length(ind12);
119 |
120 | if (l1==0 && l2==0)
121 | I=[I,i];
122 | end
123 |
124 | L11=length(ind11); sign1=1*ones(size(ind11));
125 | L12=length(ind12); sign2=-1*ones(size(ind12));
126 |
127 | L1=L11+L12;
128 | if L1==0
129 | L1=[];
130 | end
131 |
132 | ind=[ind;ind11;ind12];
133 | L=[L;L1];
134 | sign=[sign;sign1;sign2];
135 |
136 | end
137 | pos1=[pos1;elect_bh2(I,:)];
138 | flagg=[flagg;ones(length(elect_bh2(I,1)),1)];
139 | elect_bh2(I,:)=[];
140 | I=[];
141 | flag=[flag;ones(length(elect_bh2),1)];
142 |
143 | % find surface electrodes that are used in the measurement (C1 ou C2)
144 | for i=1:nsr
145 |
146 | ind11 = find(elect_sur(i,1) == meas_posC1(:,1) & elect_sur(i,2) == meas_posC1(:,2));
147 | l1=length(ind11);
148 | ind12 = find(elect_sur(i,1) == meas_posC2(:,1) & elect_sur(i,2) == meas_posC2(:,2));
149 | l2=length(ind12);
150 |
151 | if (l1==0 && l2==0)
152 | I=[I,i];
153 | end
154 |
155 | L11=length(ind11);
156 | sign1=1*ones(size(ind11));
157 | L12=length(ind12);
158 | sign2=-1*ones(size(ind12));
159 |
160 | L1=L11+L12;
161 | if L1==0
162 | L1=[];
163 | end
164 |
165 | ind=[ind;ind11;ind12];
166 | L=[L;L1];
167 | sign=[sign;sign1;sign2];
168 |
169 | end
170 |
171 | pos1=[pos1;elect_sur(I,:)];
172 | flagg=[flagg;2*ones(length(elect_sur(I,1)),1)];
173 | elect_sur(I,:)=[];
174 | I=[];
175 | flag=[flag;2*ones(length(elect_sur),1)];
176 | pos=[elect_bh1;elect_bh2;elect_sur];
177 |
178 | warning off
179 | ind_tmp = ind;
180 | clear ind
181 | ind.C1C2 = ind_tmp;
182 |
183 | % Search for nodes corresponding to potential electrodes (P1 & P2)
184 | n=length(ind.C1C2);
185 | ind_P1=[];
186 | ind_P2=[];
187 |
188 | if isnan(meas_posP2)
189 | for i=1:n
190 | k=ind.C1C2(i);
191 | ind11 = find( abs(grille(:,1)- meas_posP1(k,1)) < eps & abs(grille(:,2)- meas_posP1(k,2))< eps);
192 | ind_P1=[ind_P1;ind11];
193 | ind_P2=[];
194 | end
195 |
196 | else
197 | for i=1:n
198 | k=ind.C1C2(i);
199 | ind11 = find( abs(grille(:,1) - meas_posP1(k,1)) < eps & abs(grille(:,2) - meas_posP1(k,2)) < eps);
200 | ind12 = find( abs(grille(:,1) - meas_posP2(k,1)) < eps & abs(grille(:,2) - meas_posP2(k,2)) < eps);
201 |
202 | ind_P1=[ind_P1;ind11];
203 | ind_P2=[ind_P2;ind12];
204 | end
205 | end
206 |
207 | ind.P1 = ind_P1;
208 | if isempty(ind_P2)
209 | ind.P2=ones(size(ind_P1)); % P2 dummy values for pole-pole
210 | else
211 | ind.P2 = ind_P2;
212 | end
213 |
214 | % Search for P1 & P2 electrodes position for sensitivity calculation
215 | n_ele=size(pos1);
216 | n_ele=n_ele(1,1);
217 |
218 | if n_ele ~=0
219 | for i=1:n_ele
220 | ind11 = find(meas_posP1(:,1) == pos1(i,1) & meas_posP1(:,2) == pos1(i,2));l1=length(ind11);
221 | ind12 = find(meas_posP2(:,1) == pos1(i,1) & meas_posP2(:,2) == pos1(i,2));l2=length(ind12);
222 | if (l1==0 && l2==0)
223 | I=[I,i];
224 | end
225 | end
226 | pos1(I,:) = [];
227 | flagg(I) = [];
228 | end
229 |
230 | nb_meas=size(meas_posC1,1);
231 | position = [pos;pos1];
232 |
233 | pos_tmp = pos;
234 | clear pos
235 | pos.C = pos_tmp;
236 | pos.P = pos1;
237 | pos.flag = [flag;flagg];
238 | warning on
239 |
240 | % Take electrodes indices in position touse them in order to rebuild
241 | % the data (for the sensitivity calculation)
242 | if isnan(meas_posP2(1,1)) && isnan(meas_posC2(1,1)) % pole-pole
243 | ind_meas = zeros(nb_meas,2);
244 | for i=1:nb_meas
245 | ind1 = find(position(:,1) == meas_posC1(i,1) & position(:,2)== meas_posC1(i,2));
246 | ind3 = find(position(:,1) == meas_posP1(i,1) & position(:,2)== meas_posP1(i,2));
247 | ind_meas(i,:) = [ind1 ind3];
248 | end
249 |
250 | elseif isnan(meas_posC2(1,1)) && ~isnan(meas_posP2(1,1)) % pole-dipole
251 | ind_meas=zeros(nb_meas,3);
252 | for i=1:nb_meas
253 | ind1 = find(position(:,1) == meas_posC1(i,1) & position(:,2) == meas_posC1(i,2));
254 | ind3 = find(position(:,1) == meas_posP1(i,1) & position(:,2) == meas_posP1(i,2));
255 | ind4 = find(position(:,1) == meas_posP2(i,1) & position(:,2) == meas_posP2(i,2));
256 | ind_meas(i,:)=[ind1 ind3 ind4];
257 | end
258 |
259 | else % dipole-dipole (default)
260 | ind_meas=zeros(nb_meas,4);
261 | for i=1:nb_meas
262 | ind1 = find(position(:,1) == meas_posC1(i,1) & position(:,2) == meas_posC1(i,2));
263 | ind2 = find(position(:,1) == meas_posC2(i,1) & position(:,2) == meas_posC2(i,2));
264 | ind3 = find(position(:,1) == meas_posP1(i,1) & position(:,2) == meas_posP1(i,2));
265 | ind4 = find(position(:,1) == meas_posP2(i,1) & position(:,2) == meas_posP2(i,2));
266 | ind_meas(i,:) = [ind1 ind2 ind3 ind4];
267 | end
268 |
269 | end
270 |
271 | ind.meas = ind_meas;
272 |
273 | end
--------------------------------------------------------------------------------
/functions/vec2model.m:
--------------------------------------------------------------------------------
1 | function [rho]= vec2model(solution_vector,nb_ligne,nb_col,flag)
2 |
3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 | %
5 | % Convert the resistivity solution vector to a structure which elements are
6 | % s.xx, s.zz and s.xz
7 | %
8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9 |
10 |
11 | % flag == 2 rhoxx rhozz
12 | % flag == 3 rhoxx rhozz rhoxz
13 |
14 | if flag == 2
15 | n = length(solution_vector)/2;
16 | rho.xx = reshape(solution_vector(1:n),nb_col,nb_ligne)';
17 | % rho.xx(rho.xx < 1)=1;
18 | rho.yy = rho.xx;
19 | rho.zz = reshape(solution_vector(1+n:n*2),nb_col,nb_ligne)';
20 | % rho.zz(rho.zz < 1)=1;
21 | rho.xz = zeros(nb_ligne,nb_col);
22 | rho.angle = zeros(nb_ligne,nb_col);
23 | rho.rho_1 = rho.xx;
24 | rho.rho_2 = rho.zz;
25 | elseif flag == 3
26 | n = length(solution_vector)/3;
27 | rho.rho_1 = reshape(solution_vector(1:n),nb_col,nb_ligne)';
28 | rho.rho_2 = reshape(solution_vector(1+n:n*2),nb_col,nb_ligne)';
29 | rho.rho_1(rho.rho_1 < 1) = 1;
30 | rho.rho_2(rho.rho_2 < 1) = 1;
31 | rho.angle = reshape(solution_vector(1+2*n:end),nb_col,nb_ligne)';
32 | rho.xx = rho.rho_1.*cosd(rho.angle).^2 + rho.rho_2.*sind(rho.angle).^2;
33 | rho.zz = rho.rho_1.*sind(rho.angle).^2 + rho.rho_2.*cosd(rho.angle).^2;
34 | rho.xz = (rho.rho_2-rho.rho_1).*cosd(rho.angle).*sind(rho.angle);
35 | rho.yy = rho.rho_1;
36 |
37 | end
38 | end
--------------------------------------------------------------------------------
/scripts/drawing/script_drawing_aniso.m:
--------------------------------------------------------------------------------
1 | %% Inversion plots for anisotropic models
2 |
3 | graphFontSize = 20;
4 |
5 | param.cell_size = [4 4];
6 |
7 | disp('Ki2 and rms values :')
8 | Ki2_rms = [(1:length(Inv.rho))' Inv.Ki2 cell2mat(Inv.rms)']
9 |
10 | n = length(Inv.rho);
11 |
12 | x = param.nb_raff(1)*param.cell_size(1); % cell number in 1m
13 | z = param.nb_raff(2)*param.cell_size(2); % cell number in 1m
14 | dist_from_xborders = 15;
15 | dist_from_surface1 = 0; % should be = 0 to run the whole script, else you'll have an error
16 | dist_from_surface2 = 15;
17 | margin_h = (dist_from_xborders+param.nb_surr./param.cell_size(1))*x;
18 | depth1 = (dist_from_surface1)*z+1;
19 | depth2 = (dist_from_surface2)*z;
20 | inv_xx = Inv.rho{1,n}.rho_1(param.h_z==1/param.cell_size(2), param.h_x==1/param.cell_size(1));
21 | inv_zz = Inv.rho{1,n}.rho_2(param.h_z==1/param.cell_size(2), param.h_x==1/param.cell_size(1));
22 | inv_xx = inv_xx(depth1:depth2, margin_h+1:(size(inv_xx,2)-margin_h+1));
23 | inv_zz = inv_zz(depth1:depth2, margin_h+1:(size(inv_zz,2)-margin_h+1));
24 | coef_anis = sqrt(inv_zz./inv_xx);
25 |
26 |
27 | % figure
28 | figure('units','normalized','outerposition',[0 0 1 1]);
29 |
30 | subplot(2,3,1)
31 | % subplot(222)
32 | imagesc(0:10:50, 0:15, param.rho.xx(1:(15*param.cell_size(1)),1:(50*param.cell_size(2))))
33 | xticks(0:10:50)
34 | title('Synthetic anisotropic model')
35 | colormap jet(64)
36 | set(gca,'fontsize',graphFontSize)
37 | ylabel('z (m)')
38 | xlabel('x (m)')
39 | text(2,2,'\rho_H = 400 \Omega.m','FontSize',graphFontSize,'FontWeight','bold','Color','w')
40 | text(28,2,'\rho_V = 100 \Omega.m','FontSize',graphFontSize,'FontWeight','bold','Color','w')
41 | text(2,10,'\rho_H = 40 \Omega.m','FontSize',graphFontSize,'FontWeight','bold','Color','w')
42 | text(28,10,'\rho_V = 10 \Omega.m','FontSize',graphFontSize,'FontWeight','bold','Color','w')
43 | xm = [25*ones(1,15) 0:2:50];
44 | ym = [1:15 zeros(1,length(0:2:50))];
45 | hold on
46 | plot(xm,ym,'ok','MarkerFaceColor','w','MarkerSize',7);
47 | axis tight
48 |
49 | subplot(2,3,2)
50 | minv = log(ceil(min(inv_xx(:))));
51 | maxv = log(floor(max(inv_xx(:))));
52 | imagesc(dist_from_xborders:size(inv_xx,2)/x+dist_from_xborders, 0:dist_from_surface2, log(inv_xx))
53 | title('\rho_H')
54 | colormap jet(128)
55 | h = colorbar('FontSize',16,'YTick',linspace(minv,maxv,8)...
56 | ,'YTickLabel',round(exp(linspace(minv,maxv,8))));
57 | title(h, '\Omega/m')
58 | set(gca,'fontsize',graphFontSize)
59 | ylabel('z (m)')
60 | xlabel('x (m)')
61 | axis tight
62 |
63 | subplot(2,3,3)
64 | minv = log(ceil(min(inv_zz(:))));
65 | maxv = log(floor(max(inv_zz(:))));
66 | imagesc(dist_from_xborders:size(inv_zz,2)/x+dist_from_xborders, 0:dist_from_surface2, log(inv_zz))
67 | title('\rho_V')
68 | colormap jet(128)
69 | h = colorbar('FontSize',16,'YTick',linspace(minv,maxv,8),'YTickLabel',round(exp(linspace(minv,maxv,8))));
70 | title(h, '\Omega/m')
71 | set(gca,'fontsize',graphFontSize)
72 | ylabel('z (m)')
73 | xlabel('x (m)')
74 | axis tight
75 |
76 | subplot(2,3,4)
77 | imagesc(dist_from_xborders:size(inv_zz,2)/x+dist_from_xborders, 0:.25:(dist_from_surface2-0.25), (coef_anis))
78 | colorbar
79 | colormap jet(128)
80 | title('\lambda')
81 | set(gca, 'fontsize',graphFontSize)
82 | h = colorbar;
83 | title(h, '[-]')
84 | xlabel('x (m)')
85 | ylabel('z (m)')
86 | caxis([0 4])
87 | axis tight
88 |
89 | subplot(2,3,5)
90 | his = histogram(coef_anis,10);
91 | title('\lambda distribution')
92 | xlabel('\lambda')
93 | ylabel('# cells')
94 | set(gca,'fontsize',graphFontSize)
95 | axis([0 max(his.Data(:))+.5 0 max(his.Values)+10])
96 | box off
97 |
98 | %% Data fit plots
99 |
100 | [K] = geometric_factor(XYZ,param.flag.geo_factor);
101 | param.K = K;
102 | res_num = Inv.d_cal{n};
103 | res_obs = log(param.K.*param.MEAS.Res);
104 | res_obs = res_obs(Inv.rho_app_pos_index{n});
105 |
106 | subplot(2,3,6)
107 | his = histogram(2*(res_obs-res_num)./(abs(res_obs)+abs(res_num))*100,10);
108 | title('Relative error')
109 | xlabel('error (%)')
110 | ylabel('# cells')
111 | box off
112 | ylim([0 max(his.Values)+10])
113 | set(gca,'FontSize',graphFontSize)
--------------------------------------------------------------------------------
/scripts/drawing/script_drawing_iso.m:
--------------------------------------------------------------------------------
1 | %% Inversion plots for isotropic models
2 |
3 | graphFontSize = 20;
4 |
5 | param.cell_size = [4 4];
6 |
7 | disp('Ki2 and rms values :')
8 | Ki2_rms = [(1:length(Inv.rho))' Inv.Ki2 cell2mat(Inv.rms)']
9 |
10 | n = length(Inv.rho);
11 |
12 | res_num = Inv.d_cal{n};
13 | res_obs = log(param.K.*param.MEAS.Res);
14 |
15 | x = param.nb_raff(1)*param.cell_size(1);
16 | z = param.nb_raff(2)*param.cell_size(2);
17 | dist_from_xborders = 15;
18 | dist_from_surface1 = 0; % should be = 0 to run the whole script, else you'll have an error
19 | dist_from_surface2 = 15;
20 | margin_h = (dist_from_xborders+param.nb_surr./param.cell_size(1))*x;
21 | depth1 = (dist_from_surface1)*z+1;
22 | depth2 = (dist_from_surface2)*z;
23 | inv = Inv.rho{1,n}(param.h_z==1/param.cell_size(2), param.h_x==1/param.cell_size(1));
24 | inv = inv(depth1:depth2, margin_h+1:(size(inv,2)-margin_h+1));
25 |
26 | % figure
27 | figure('units','normalized','outerposition',[0 0 1 1]);
28 |
29 | subplot(1,3,1)
30 | imagesc(0:10:50, 0:15, param.rho.xx(1:(15*param.cell_size(1)),1:(50*param.cell_size(2))))
31 | xticks(0:10:50)
32 | title('Synthetic anisotropic model')
33 | colormap jet(64)
34 | set(gca,'fontsize',graphFontSize)
35 | ylabel('z (m)')
36 | xlabel('x (m)')
37 | text(2,2,'\rho = 200 \Omega.m','FontSize',graphFontSize,'FontWeight','bold','Color','w')
38 | text(2,10,'\rho = 20 \Omega.m','FontSize',graphFontSize,'FontWeight','bold','Color','w')
39 | xm = [25*ones(1,15) 0:2:50];
40 | ym = [1:15 zeros(1,length(0:2:50))];
41 | hold on
42 | plot(xm,ym,'ok','MarkerFaceColor','w','MarkerSize',7);
43 | axis square
44 |
45 | subplot(1,3,2)
46 | minv = log(10);
47 | maxv = log(300);
48 | imagesc(dist_from_xborders:size(inv_xx,2)/x+dist_from_xborders, 0:dist_from_surface2, log(inv))
49 | title('\rho_H')
50 | colormap jet(128)
51 | h = colorbar('FontSize',16,'YTick',linspace(minv,maxv,8)...
52 | ,'YTickLabel',round(exp(linspace(minv,maxv,8))));
53 | title(h, '\Omega/m')
54 | set(gca,'fontsize',graphFontSize)
55 | ylabel('z (m)')
56 | xlabel('x (m)')
57 | caxis([minv maxv])
58 | axis square
59 | ax = gca;
60 | axpos = ax.Position;
61 | ax.Position = axpos;
62 |
63 | subplot(1,3,3)
64 | his = histogram(2*(res_obs-res_num)./(abs(res_obs)+abs(res_num))*100);
65 | title('Relative error')
66 | xlabel('error (%)')
67 | ylabel('# cells')
68 | box off
69 | xlim([-10 10])
70 | ylim([0 max(his.Values)+10])
71 | set(gca,'FontSize',graphFontSize)
--------------------------------------------------------------------------------
/scripts/forward/script_analytical_anis_2layers.m:
--------------------------------------------------------------------------------
1 | %% 2 layer model analytical solution (Telford)
2 |
3 | rhoX = param.rho.xx;
4 | rho_calc = param.K(:).*u_num(:);
5 |
6 | nb_points = 50;
7 | nb_images = 100;
8 |
9 | rho_h1 = 100;
10 | rho_v1 = 400;
11 | rho_n1 = sqrt(rho_v1*rho_h1);
12 | rho_h2 = 10;
13 | rho_v2 = 40;
14 | rho_n2 = sqrt(rho_v2*rho_h2);
15 | kn = (rho_n2-rho_n1)/(rho_n2+rho_n1);
16 | f = sqrt(rho_v1/rho_h1);
17 | z = 4;
18 | n = 2; % dipole-dipole separation
19 |
20 | rho_aa = zeros(nb_points,1);
21 | summ = zeros(nb_points,1);
22 | p = zeros(nb_points,1);
23 | r1 = zeros(nb_points,1);
24 | r2 = zeros(nb_points,1);
25 | r3 = zeros(nb_points,1);
26 | r4 = zeros(nb_points,1);
27 |
28 | for i = 1:nb_points
29 | % Wenner
30 | j = i;
31 | r1(i) = j;
32 | r2(i) = 2*j;
33 | r3(i) = 2*j;
34 | r4(i) = j;
35 | ABs2(i) = 3*j/2;
36 |
37 | p(i) = (1/r1(i)-1/r2(i)-1/r3(i)+1/r4(i))^(-1);
38 | summ(i) = 0;
39 | operande = 0;
40 | for m = 1:nb_images
41 | operande = 1/sqrt(r1(i)^2+4*m^2*f^2*z^2) - 1/sqrt(r2(i)^2+4*m^2*f^2*z^2)...
42 | -1/sqrt(r3(i)^2+4*m^2*f^2*z^2) + 1/sqrt(r4(i)^2+4*m^2*f^2*z^2);
43 | operande = kn^m*operande;
44 | summ(i) = summ(i) + operande;
45 | end
46 | rho_aa(i) = rho_n1*(1+2*p(i)*summ(i));
47 |
48 | end
49 |
50 | ABs2 = ABs2(2:end)';
51 | rho_aa = rho_aa(2:end);
52 | rho_calc = rho_calc(2:end);
53 |
54 | %% Plots
55 |
56 | figure
57 | subplot(4,3,[1 4 7])
58 | imagesc(0:25:150,0:5:15,rhoX(1:60,:))
59 | colormap jet
60 | hold on
61 | xm = 0:10:150;
62 | ym = -.1*ones(1,16);
63 | plot(xm,ym,'ok','MarkerFaceColor','w','MarkerSize',10);
64 | xlabel('x (m)')
65 | ylabel('z (m)')
66 | set(gca,'FontSize',20)
67 | title('Resistivity model')
68 | text(10,2,'\rho_H = 100 \Omega.m','FontSize',20,'FontWeight','bold','Color','w')
69 | text(80,2,'\rho_V = 400 \Omega.m','FontSize',20,'FontWeight','bold','Color','w')
70 | text(10,10,'\rho_H = 10 \Omega.m','FontSize',20,'FontWeight','bold','Color','w')
71 | text(80,10,'\rho_V = 40 \Omega.m','FontSize',20,'FontWeight','bold','Color','w')
72 | subplot(4,3,[2 3 5 6])
73 | semilogx(ABs2,rho_aa,'ok')
74 | set(gca,'FontSize',20,'YTick',0:50:220)
75 | xticklabels({})
76 | ylabel('\rho_a (\Omega.m)')
77 | ylim([0 220])
78 | hold on
79 | x = (6:3:150)/2;
80 | semilogx(x,rho_calc,'LineWidth',4)
81 | legend('Analytical','Numerical')
82 | subplot(4,3,[8 9])
83 | semilogx(ABs2,(rho_calc-rho_aa)./rho_aa*100,'.-')
84 | set(gca,'FontSize',20,'YTick',-1:2)
85 | xlabel('AB/2 (m)')
86 | ylabel('error (%)')
87 | ylim([-1 2])
--------------------------------------------------------------------------------
/scripts/forward/script_analytical_anis_semiInfiniteSpace.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/scripts/forward/script_analytical_anis_semiInfiniteSpace.m
--------------------------------------------------------------------------------
/scripts/inversion/script_preparation_inversion.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/scripts/inversion/script_preparation_inversion.m
--------------------------------------------------------------------------------
/scripts/script_drawing.m:
--------------------------------------------------------------------------------
1 | %% Script that calls the suitable drawing script for the inverted results graphic representation
2 |
3 | close all
4 | clear
5 |
6 | disp('Drawing inverted results:')
7 | disp('1. Load anisotropic inversion of anisotropic model')
8 | disp('2. Load anisotropic inversion of isotropic model')
9 | disp('3. Load isotropic inversion of isotropic model')
10 | prompt = '';
11 |
12 | val = input(prompt);
13 |
14 | if val == 1
15 | load inv_aniso_model_aniso
16 | script_drawing_aniso
17 | elseif val == 2
18 | load inv_aniso_model_iso
19 | script_drawing_aniso
20 | elseif val == 3
21 | load inv_iso_model_iso
22 | script_drawing_iso
23 | else
24 | error('Please enter 1, 2 or 3')
25 | end
--------------------------------------------------------------------------------
/scripts/script_forward_validation.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simoger/AIM4RES/940b771bc74b5e8bb41aadf90db59591a5dfc957/scripts/script_forward_validation.m
--------------------------------------------------------------------------------
/scripts/script_inversion.m:
--------------------------------------------------------------------------------
1 | %% Anisotropic inversion
2 |
3 | clear
4 | close all
5 |
6 | disp('Input data already existing ?')
7 | disp('1. No: launch script_preparation_inversion.m to create synthetic data')
8 | disp('2. Yes: import existing input data')
9 | val = input('');
10 |
11 | if val == 1
12 | script_preparation_inversion
13 | elseif val == 2
14 | load synt_data_for_inversion
15 | end
16 |
17 | tic
18 |
19 | gauss_newton_inversion_anis(param, XYZ)
--------------------------------------------------------------------------------