~fluidity-core/fluidity/adjoint

« back to all changes in this revision

Viewing changes to tests/burgers_mms_steady_adjoint_gradient_init_revolve/mms_D.bml

Merge the fluidity_revolve branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version='1.0' encoding='utf-8'?>
 
2
<burgers_equation>
 
3
  <simulation_name>
 
4
    <string_value lines="1">mms_adjoint_D</string_value>
 
5
  </simulation_name>
 
6
  <geometry>
 
7
    <dimension>
 
8
      <integer_value rank="0">1</integer_value>
 
9
    </dimension>
 
10
    <mesh name="CoordinateMesh">
 
11
      <from_file file_name="mms_D">
 
12
        <format name="triangle"/>
 
13
        <stat>
 
14
          <include_in_stat/>
 
15
        </stat>
 
16
      </from_file>
 
17
    </mesh>
 
18
    <mesh name="VelocityMesh">
 
19
      <from_mesh>
 
20
        <mesh name="CoordinateMesh"/>
 
21
        <stat>
 
22
          <exclude_from_stat/>
 
23
        </stat>
 
24
      </from_mesh>
 
25
    </mesh>
 
26
    <quadrature>
 
27
      <degree>
 
28
        <integer_value rank="0">4</integer_value>
 
29
      </degree>
 
30
    </quadrature>
 
31
  </geometry>
 
32
  <io>
 
33
    <dump_format>vtk</dump_format>
 
34
    <dump_period_in_timesteps>
 
35
      <constant>
 
36
        <integer_value rank="0">1</integer_value>
 
37
      </constant>
 
38
    </dump_period_in_timesteps>
 
39
    <output_mesh name="VelocityMesh"/>
 
40
  </io>
 
41
  <timestepping>
 
42
    <current_time>
 
43
      <real_value rank="0">0</real_value>
 
44
    </current_time>
 
45
    <timestep>
 
46
      <real_value rank="0">0.125</real_value>
 
47
    </timestep>
 
48
    <finish_time>
 
49
      <real_value rank="0">1</real_value>
 
50
    </finish_time>
 
51
    <nonlinear_iterations>
 
52
      <integer_value rank="0">4</integer_value>
 
53
    </nonlinear_iterations>
 
54
  </timestepping>
 
55
  <material_phase name="Fluid">
 
56
    <scalar_field name="Velocity" rank="0">
 
57
      <prognostic>
 
58
        <mesh name="VelocityMesh"/>
 
59
        <temporal_discretisation>
 
60
          <theta>
 
61
            <real_value rank="0">0.5</real_value>
 
62
          </theta>
 
63
          <relaxation>
 
64
            <real_value rank="0">0.5</real_value>
 
65
          </relaxation>
 
66
        </temporal_discretisation>
 
67
        <solver>
 
68
          <iterative_method name="preonly"/>
 
69
          <preconditioner name="lu"/>
 
70
          <relative_error>
 
71
            <real_value rank="0">1e-16</real_value>
 
72
          </relative_error>
 
73
          <absolute_error>
 
74
            <real_value rank="0">1e-12</real_value>
 
75
          </absolute_error>
 
76
          <max_iterations>
 
77
            <integer_value rank="0">10000</integer_value>
 
78
          </max_iterations>
 
79
          <never_ignore_solver_failures/>
 
80
          <diagnostics>
 
81
            <monitors/>
 
82
          </diagnostics>
 
83
        </solver>
 
84
        <initial_condition name="WholeMesh">
 
85
          <python>
 
86
            <string_value lines="20" type="python">def val(X, t):
 
87
  from math import sin, cos
 
88
  x = X[0]
 
89
  return sin(x) + cos(x)</string_value>
 
90
          </python>
 
91
        </initial_condition>
 
92
        <boundary_conditions name="bc">
 
93
          <surface_ids>
 
94
            <integer_value shape="2" rank="1">1 2</integer_value>
 
95
          </surface_ids>
 
96
          <type name="dirichlet">
 
97
            <python>
 
98
              <string_value lines="20" type="python">def val(X, t):
 
99
  from math import sin, cos
 
100
  x = X[0]
 
101
  return sin(x) + cos(x)</string_value>
 
102
            </python>
 
103
          </type>
 
104
        </boundary_conditions>
 
105
        <viscosity>
 
106
          <real_value rank="0">1</real_value>
 
107
        </viscosity>
 
108
        <stat/>
 
109
        <adjoint_storage>
 
110
          <exists_in_both/>
 
111
        </adjoint_storage>
 
112
        <scalar_field name="Source" rank="0">
 
113
          <prescribed>
 
114
            <value name="WholeMesh">
 
115
              <python>
 
116
                <string_value lines="20" type="python">def val(X, t):
 
117
  from math import sin, cos
 
118
  x = X[0]
 
119
  y = sin(x) + cos(x)
 
120
  return y</string_value>
 
121
              </python>
 
122
            </value>
 
123
          </prescribed>
 
124
        </scalar_field>
 
125
      </prognostic>
 
126
    </scalar_field>
 
127
    <scalar_field name="AnalyticalSolution" rank="0">
 
128
      <prescribed>
 
129
        <mesh name="VelocityMesh"/>
 
130
        <value name="WholeMesh">
 
131
          <python>
 
132
            <string_value lines="20" type="python">def val(X, t):
 
133
  from math import sin, cos
 
134
  x = X[0]
 
135
  return sin(x) + cos(x)</string_value>
 
136
          </python>
 
137
        </value>
 
138
        <adjoint_storage>
 
139
          <exists_in_forward/>
 
140
        </adjoint_storage>
 
141
      </prescribed>
 
142
    </scalar_field>
 
143
    <scalar_field name="Error" rank="0">
 
144
      <diagnostic>
 
145
        <mesh name="VelocityMesh"/>
 
146
        <algorithm name="scalar_python_diagnostic" material_phase_support="single">
 
147
          <string_value lines="20" type="python">soln = state.scalar_fields["Velocity"]
 
148
exact = state.scalar_fields["AnalyticalSolution"]
 
149
 
 
150
for i in range(field.node_count):
 
151
  field.set(i, abs(soln.node_val(i) - exact.node_val(i)))</string_value>
 
152
        </algorithm>
 
153
        <stat/>
 
154
        <adjoint_storage>
 
155
          <exists_in_forward/>
 
156
        </adjoint_storage>
 
157
      </diagnostic>
 
158
    </scalar_field>
 
159
  </material_phase>
 
160
  <adjoint>
 
161
    <checkpointing>
 
162
      <max_memory_checkpoints>
 
163
        <integer_value rank="0">3</integer_value>
 
164
      </max_memory_checkpoints>
 
165
      <max_disk_checkpoints>
 
166
        <integer_value rank="0">0</integer_value>
 
167
      </max_disk_checkpoints>
 
168
    </checkpointing>
 
169
    <functional name="time_integral_ad">
 
170
      <functional_value>
 
171
        <algorithm name="functional_value">
 
172
          <string_value lines="20" type="python">import numpy
 
173
 
 
174
J = 0.0
 
175
 
 
176
if time &lt; 1.0 &lt;= time+dt:
 
177
  coord = states[0]["Fluid"].vector_fields["Coordinate"]
 
178
  u = states[n]["Fluid"].scalar_fields["Velocity"]
 
179
  
 
180
  for ele in range(coord.element_count):
 
181
    t = Transform(ele, coord)
 
182
    shape = u.ele_shape(ele)
 
183
    mass = t.shape_shape(shape, shape)
 
184
    J = J + 0.5 * numpy.dot(u.ele_val(ele), numpy.dot(mass, u.ele_val(ele)))
 
185
#  print "Got functional value: ", J
 
186
    
 
187
#if hasattr(J, "nominal_value"):
 
188
#  print "u.val: ", u.val
 
189
#  print "delJ/delu: ", [J.derivatives[x] for x in u.val]
 
190
#  print "J.nominal_value: ", J.nominal_value</string_value>
 
191
        </algorithm>
 
192
        <reduction>
 
193
          <sum/>
 
194
        </reduction>
 
195
      </functional_value>
 
196
      <functional_dependencies>
 
197
        <algorithm name="functional_dependencies">
 
198
          <string_value lines="20" type="python">def dependencies(times, timestep):
 
199
  if times[0] &lt; 1.0 &lt;= times[1]:
 
200
    return {"Fluid::Coordinate": [0],
 
201
            "Fluid::Velocity": [timestep]}
 
202
  else:
 
203
    return {}</string_value>
 
204
        </algorithm>
 
205
      </functional_dependencies>
 
206
    </functional>
 
207
    <controls>
 
208
      <control name="InitialCondition">
 
209
        <type field_name="Fluid::Velocity" name="initial_condition"/>
 
210
      </control>
 
211
    </controls>
 
212
    <debug>
 
213
      <html_output/>
 
214
    </debug>
 
215
  </adjoint>
 
216
</burgers_equation>
 
 
b'\\ No newline at end of file'