Howto: Deterministic Inversion with AD
Here you find a step, by step introduction howto create a Input File for using ad
mode, similar to Howto: Forward computation. This mode uses Automatic Differentiation.
For a in depth description of all key-words look at Deterministic Inversion Input
For internal users the pages Deterministic Inversion Output and Inversion Code Workflow may also be interesting.
Table of Contents
Compilation
At first you need to create a executable which was compiled with flag ad
. Therefore you have to checkout your SHEMAT-Suite repository like this:
git checkout master-all
Now you can compile your executable. Best practice is to use a Compilation Shell Script, which combines all necessary steps. One can be found in the SHEMAT-Suite_Models repository: compilequick.sh. Here you have to set shem_type="ad"
. For this tutorial you have to set shem_type="ad"
, mode="head"
, props="const"
, user="none"
, compiler_name="ifort"
, flags="-Dhdf=ON -Domp=OFF -j16"
Also make sure to change model_dir
and make_dir
to your personal directories. Maybe you should create a new model directory for this tutorial.
./compilequick.sh
Now shem_ad_ifort_const_none_head_master-all_quick.x
is in your model directory. (Note: Naming convention may have changed)
Creating Input File
Run Forward Model
At first you need a model, which you want to calculate a deterministic inversion for. In this tutorial we will use oed_perth_init. With all existing keywords you should be familiar, if not you may first should take a look at Howto: Forward computation, where a example Input File is created. If you want to look up specific keywords go to Input File. Copy oed_perth_init
in your model directory. Make sure the repository contains a file named shemade.job
which only contains the model name: oed_perth_init
.
./shem_ad_ifort_const_none_head_master-all_quick.x > out.txt
The values of this solution will be used as starting values for the deterministic inversion. For the the next steps you will only need oed_perth_init_final.h5
, shemade.job
, oed_perth_init
and the executable, maybe you should create a new sub-folder and cut all other files there.
Create AD Input File
Now you need to add some keywords to the Input File to create an AD Input File. You also need to adjust some boundary conditions. At first change the name of the Input File oed_perth_init
to oed_inv
and change # runmode
from 0
to 2
. You also have to change the name in shemade.job
to the new Input File name.
Let's first change the Input File so that head is activated and the results we calculated before are used as initial conditions.
If you want, you can change the name under # title
, e.g. OED Perth
. Now activate the variable head
; in the previous run only temp was set active.
# active temp head
Next you should set boundary conditions for the head
variable. Got to !==========>>>>> FLOW
and remove !
before these hashtags, so that SHEMAT will work with them:
# head bcd, simple=right, value=init
# head bcd, simple=left, bcindex=1
Go to !==========>>>>> define boundary properties
and also remove the !
, so that SHEMAT reads the boundary condition for the head variable. Don't forget to change the number of records to 3
.
1 3005 head
Under !==========>>>>> TEMPERATURE
you also have to remove two !
to activate these temp boundary conditions:
# temp bcd, simple=left, value=init
# temp bcd, simple=right, value=init
Finally go to !==========>>>>> INITIAL VALUES
and delete
# temp init
12000*19.0
# head init
12000*3000
or put a !
before these hashtags. Remove the existing !
so that the new initial conditions are defined like this:
# head init, HDF5=oed_perth_init_final.h5
# temp init, HDF5=oed_perth_init_final.h5
Adding new keywords
# enable unit
# enable unit
0 0 0 0 1 0
This keyword activates Unit 5. 0
means, that this unit is disabled and 1
enables the specific unit for deterministic inversion.
# enable property
# enable property
0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0
Here the 4th property, permeability in z-direction, is enabled as logarithmic (2
) for inversion. All other properties are disabled due to 0
.
# errors
# errors
0.0 0.0 0.0 6.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 6.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 6.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 6.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 6.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 6.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
With this keyword the apriori variance of each unit-property is defined. In this case the permeability in z-direction of all units is given a variance of 6. If the parameter is set to logarithmic in # enable property
you have to set the variance for the logarithmic converted parameter here. All other properties don´t have a variance and will be constant. This variance can be understood as weighting factor of the minimizing function. The higher the value, the more changes will appear in that specific unit.
In this model only the permeability in z-direction, of unit 5 is enabled, as logarithmic, for deterministic inversion.
# inverse
# inverse
1
5 0.0001
0 0
1
The meaning of the input is described from top to bottom. 1
does not have a meaning, it should always be set to 1.
The next line defines the break-off criteria: 5 0.0001
The maximum number of iterations is set with 5
. If the difference between two iteration steps is below 0.0001
it stops at that point.
The next entry 0 0
disables computation of the resolution matrix and computation of the covariance matrix. The last entry 1
defines the output frequency. It means that the results of every calculated iteration will be saved in a separate file. If you are not interested in these iterations replace 1
with 5 or a greater number. The calculation results will be saved in separate files anyway.
# data
With this keyword you add observed/measured data. For a runmode greater or equal to 1 this keyword is expected. The first column, which starts with 23.7769395446154
defines the data value. It is followed by the error, which is 0.5
for all records. I don`t know what the error is used for. The next three entries are the position, the order is x, y, z: 180 1 59
. It is followed by pv-type, the type index for the physical value, ``2`` stands for temperature. The last column``1`` (index of observation zone) does not matter in this example.
# data, records=39
23.7769395446154 0.5 180 1 59 2 1
25.7835948927898 0.5 180 1 58 2 1
29.6464343633434 0.5 180 1 57 2 1
32.8980733238002 0.5 180 1 56 2 1
37.0441520969052 0.5 180 1 55 2 1
40.1958306183938 0.5 180 1 54 2 1
43.2004118563349 0.5 180 1 53 2 1
47.3345145469068 0.5 180 1 52 2 1
50.4663910323358 0.5 180 1 51 2 1
54.3502163386361 0.5 180 1 50 2 1
56.9763728781437 0.5 180 1 49 2 1
60.2000806193018 0.5 180 1 48 2 1
62.1693047887311 0.5 180 1 47 2 1
64.3518333535011 0.5 180 1 46 2 1
66.0470389598390 0.5 180 1 45 2 1
68.3113717965326 0.5 180 1 44 2 1
71.6165654756868 0.5 180 1 43 2 1
73.1905011904131 0.5 180 1 42 2 1
75.5838716443921 0.5 180 1 41 2 1
77.3779825157971 0.5 180 1 40 2 1
79.9560905906124 0.5 180 1 39 2 1
81.9764239222050 0.5 180 1 38 2 1
84.6770489667531 0.5 180 1 37 2 1
86.6014390650205 0.5 180 1 36 2 1
88.0575024522982 0.5 180 1 35 2 1
89.8501516927985 0.5 180 1 34 2 1
90.4531359954323 0.5 180 1 33 2 1
93.3551807344220 0.5 180 1 32 2 1
93.8766008010106 0.5 180 1 31 2 1
95.1298597921857 0.5 180 1 30 2 1
99.0483995564033 0.5 180 1 29 2 1
99.1151966560339 0.5 180 1 28 2 1
100.071301662074 0.5 180 1 27 2 1
101.811362947280 0.5 180 1 26 2 1
103.205624709550 0.5 180 1 25 2 1
103.460235983707 0.5 180 1 24 2 1
105.423304967974 0.5 180 1 23 2 1
107.294489726684 0.5 180 1 22 2 1
108.260490155576 0.5 180 1 21 2 1
Execution
You finished your first Deterministic Inversion Input File, execute it. Make sure your working directory contains the files shemade.job
, oed_inv
, oed_perth_init_final.h5
and the executable.
./shem_ad_ifort_const_none_head_master-all_quick.x > out.txt