1 | #module imports
|
---|
2 | from fielddisplay import fielddisplay
|
---|
3 |
|
---|
4 | class inversion(object):
|
---|
5 | #properties
|
---|
6 | def __init__(self):
|
---|
7 | # {{{ Properties
|
---|
8 | self.iscontrol = 0
|
---|
9 | self.tao = 0
|
---|
10 | self.incomplete_adjoint = 0
|
---|
11 | self.control_parameters = float('NaN')
|
---|
12 | self.nsteps = 0
|
---|
13 | self.maxiter_per_step = float('NaN')
|
---|
14 | self.cost_functions = float('NaN')
|
---|
15 | self.cost_functions_coefficients = float('NaN')
|
---|
16 | self.gradient_scaling = float('NaN')
|
---|
17 | self.cost_function_threshold = 0
|
---|
18 | self.min_parameters = float('NaN')
|
---|
19 | self.max_parameters = float('NaN')
|
---|
20 | self.step_threshold = float('NaN')
|
---|
21 | self.gradient_only = 0
|
---|
22 | self.vx_obs = float('NaN')
|
---|
23 | self.vy_obs = float('NaN')
|
---|
24 | self.vz_obs = float('NaN')
|
---|
25 | self.vel_obs = float('NaN')
|
---|
26 | self.thickness_obs = float('NaN')
|
---|
27 | #}}}
|
---|
28 | def __repr__(obj):
|
---|
29 | # {{{ Display
|
---|
30 | string='\n Inversion parameters:'
|
---|
31 | string="%s\n%s"%(string,fielddisplay(obj,'iscontrol','is inversion activated?'))
|
---|
32 | string="%s\n%s"%(string,fielddisplay(obj,'incomplete_adjoint','do we assume linear viscosity?'))
|
---|
33 | string="%s\n%s"%(string,fielddisplay(obj,'control_parameters','parameter where inverse control is carried out; ex: {''FrictionCoefficient''}, or {''MaterialsRheologyBbar''}'))
|
---|
34 | string="%s\n%s"%(string,fielddisplay(obj,'nsteps','number of optimization searches'))
|
---|
35 | string="%s\n%s"%(string,fielddisplay(obj,'cost_functions','indicate the type of response for each optimization step'))
|
---|
36 | string="%s\n%s"%(string,fielddisplay(obj,'cost_functions_coefficients','cost_functions_coefficients applied to the misfit of each vertex and for each control_parameter'))
|
---|
37 | string="%s\n%s"%(string,fielddisplay(obj,'cost_function_threshold','misfit convergence criterion. Default is 1%, NaN if not applied'))
|
---|
38 | string="%s\n%s"%(string,fielddisplay(obj,'maxiter_per_step','maximum iterations during each optimization step'))
|
---|
39 | string="%s\n%s"%(string,fielddisplay(obj,'gradient_scaling','scaling factor on gradient direction during optimization, for each optimization step'))
|
---|
40 | string="%s\n%s"%(string,fielddisplay(obj,'step_threshold','decrease threshold for misfit, default is 30%'))
|
---|
41 | string="%s\n%s"%(string,fielddisplay(obj,'min_parameters','absolute minimum acceptable value of the inversed parameter on each vertex'))
|
---|
42 | string="%s\n%s"%(string,fielddisplay(obj,'max_parameters','absolute maximum acceptable value of the inversed parameter on each vertex'))
|
---|
43 | string="%s\n%s"%(string,fielddisplay(obj,'gradient_only','stop control method solution at gradient'))
|
---|
44 | string="%s\n%s"%(string,fielddisplay(obj,'vx_obs','observed velocity x component [m/a]'))
|
---|
45 | string="%s\n%s"%(string,fielddisplay(obj,'vy_obs','observed velocity y component [m/a]'))
|
---|
46 | string="%s\n%s"%(string,fielddisplay(obj,'vel_obs','observed velocity magnitude [m/a]'))
|
---|
47 | string="%s\n%s"%(string,fielddisplay(obj,'thickness_obs','observed thickness [m]'))
|
---|
48 | string="%s\n%s"%(string,'Available cost functions:')
|
---|
49 | string="%s\n%s"%(string,' 101: SurfaceAbsVelMisfit')
|
---|
50 | string="%s\n%s"%(string,' 102: SurfaceRelVelMisfit')
|
---|
51 | string="%s\n%s"%(string,' 103: SurfaceLogVelMisfit')
|
---|
52 | string="%s\n%s"%(string,' 104: SurfaceLogVxVyMisfit')
|
---|
53 | string="%s\n%s"%(string,' 105: SurfaceAverageVelMisfit')
|
---|
54 | string="%s\n%s"%(string,' 201: ThicknessAbsMisfit')
|
---|
55 | string="%s\n%s"%(string,' 501: DragCoefficientAbsGradient')
|
---|
56 | string="%s\n%s"%(string,' 502: RheologyBbarAbsGradient')
|
---|
57 | string="%s\n%s"%(string,' 503: ThicknessAbsGradient')
|
---|
58 | return string
|
---|
59 | #}}}
|
---|
60 |
|
---|
61 | def setdefaultparameters(obj):
|
---|
62 | # {{{setdefaultparameters
|
---|
63 |
|
---|
64 | #default is incomplete adjoint for now
|
---|
65 | obj.incomplete_adjoint=1
|
---|
66 |
|
---|
67 | #parameter to be inferred by control methods (only
|
---|
68 | #drag and B are supported yet)
|
---|
69 | obj.control_parameters=['FrictionCoefficient']
|
---|
70 |
|
---|
71 | #number of steps in the control methods
|
---|
72 | obj.nsteps=20
|
---|
73 |
|
---|
74 | #maximum number of iteration in the optimization algorithm for
|
---|
75 | #each step
|
---|
76 | obj.maxiter_per_step=20*ones(obj.nsteps)
|
---|
77 |
|
---|
78 | #the inversed parameter is updated as follows:
|
---|
79 | #new_par=old_par + gradient_scaling(n)*C*gradient with C in [0 1];
|
---|
80 | #usually the gradient_scaling must be of the order of magnitude of the
|
---|
81 | #inversed parameter (10^8 for B, 50 for drag) and can be decreased
|
---|
82 | #after the first iterations
|
---|
83 | obj.gradient_scaling=50*ones(obj.nsteps)
|
---|
84 |
|
---|
85 | #several responses can be used:
|
---|
86 | obj.cost_functions=101*ones(obj.nsteps)
|
---|
87 |
|
---|
88 | #step_threshold is used to speed up control method. When
|
---|
89 | #misfit(1)/misfit(0) < obj.step_threshold, we go directly to
|
---|
90 | #the next step
|
---|
91 | obj.step_threshold=.7*ones(obj.nsteps) #30 per cent decrement
|
---|
92 |
|
---|
93 | #stop control solution at the gradient computation and return it?
|
---|
94 | obj.gradient_only=0
|
---|
95 |
|
---|
96 | #cost_function_threshold is a criteria to stop the control methods.
|
---|
97 | #if J[n]-J[n-1]/J[n] < criteria, the control run stops
|
---|
98 | #NaN if not applied
|
---|
99 | obj.cost_function_threshold=NaN #not activated
|
---|
100 |
|
---|
101 | return obj
|
---|
102 | #}}}
|
---|
103 |
|
---|
104 |
|
---|