~fluidity-core/fluidity/sea-ice-branch

« back to all changes in this revision

Viewing changes to tests/burgers_mms_diffusion_time_integral/mms_C.bml

  • Committer: Simon Mouradian
  • Date: 2012-10-19 10:35:59 UTC
  • mfrom: (3520.32.371 fluidity)
  • Revision ID: simon.mouradian06@imperial.ac.uk-20121019103559-y36qa47phc69q8sc
mergeĀ fromĀ trunk

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_diffusion_adjoint_C</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_C">
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.0</real_value>
44
 
    </current_time>
45
 
    <timestep>
46
 
      <real_value rank="0">0.5</real_value>
47
 
    </timestep>
48
 
    <finish_time>
49
 
      <real_value rank="0">10.0</real_value>
50
 
    </finish_time>
51
 
  </timestepping>
52
 
  <material_phase name="Fluid">
53
 
    <scalar_field name="Velocity" rank="0">
54
 
      <prognostic>
55
 
        <mesh name="VelocityMesh"/>
56
 
        <temporal_discretisation>
57
 
          <theta>
58
 
            <real_value rank="0">0.5</real_value>
59
 
          </theta>
60
 
          <relaxation>
61
 
            <real_value rank="0">0.5</real_value>
62
 
          </relaxation>
63
 
        </temporal_discretisation>
64
 
        <solver>
65
 
          <iterative_method name="gmres">
66
 
            <restart>
67
 
              <integer_value rank="0">30</integer_value>
68
 
            </restart>
69
 
          </iterative_method>
70
 
          <preconditioner name="sor"/>
71
 
          <relative_error>
72
 
            <real_value rank="0">1.0e-16</real_value>
73
 
          </relative_error>
74
 
          <absolute_error>
75
 
            <real_value rank="0">1.0e-12</real_value>
76
 
          </absolute_error>
77
 
          <max_iterations>
78
 
            <integer_value rank="0">10000</integer_value>
79
 
          </max_iterations>
80
 
          <never_ignore_solver_failures/>
81
 
          <diagnostics>
82
 
            <monitors/>
83
 
          </diagnostics>
84
 
        </solver>
85
 
        <remove_advection_term/>
86
 
        <initial_condition name="WholeMesh">
87
 
          <python>
88
 
            <string_value lines="20" type="code" language="python">def val(X, t):
89
 
  from math import sin
90
 
  x = X[0]
91
 
  return sin(x+t)</string_value>
92
 
          </python>
93
 
        </initial_condition>
94
 
        <boundary_conditions name="bc">
95
 
          <surface_ids>
96
 
            <integer_value shape="2" rank="1">1 2</integer_value>
97
 
          </surface_ids>
98
 
          <type name="dirichlet">
99
 
            <python>
100
 
              <string_value lines="20" type="code" language="python">def val(X, t):
101
 
  from math import sin
102
 
  x = X[0]
103
 
  return sin(x+t)</string_value>
104
 
            </python>
105
 
          </type>
106
 
        </boundary_conditions>
107
 
        <viscosity>
108
 
          <real_value rank="0">1.0</real_value>
109
 
        </viscosity>
110
 
        <stat/>
111
 
        <adjoint_storage>
112
 
          <exists_in_both/>
113
 
        </adjoint_storage>
114
 
        <scalar_field name="Source" rank="0">
115
 
          <prescribed>
116
 
            <value name="WholeMesh">
117
 
              <python>
118
 
                <string_value lines="20" type="code" language="python">def val(X, t):
119
 
  from math import sin, cos
120
 
  x = X[0]
121
 
  return sin(x+t) + cos(x+t)</string_value>
122
 
              </python>
123
 
            </value>
124
 
          </prescribed>
125
 
        </scalar_field>
126
 
      </prognostic>
127
 
    </scalar_field>
128
 
    <scalar_field name="AnalyticalSolution" rank="0">
129
 
      <prescribed>
130
 
        <mesh name="VelocityMesh"/>
131
 
        <value name="WholeMesh">
132
 
          <python>
133
 
            <string_value lines="20" type="code" language="python">def val(X, t):
134
 
  from math import sin
135
 
  x = X[0]
136
 
  return sin(x+t)</string_value>
137
 
          </python>
138
 
        </value>
139
 
        <adjoint_storage>
140
 
          <exists_in_forward/>
141
 
        </adjoint_storage>
142
 
      </prescribed>
143
 
    </scalar_field>
144
 
    <scalar_field name="Error" rank="0">
145
 
      <diagnostic>
146
 
        <mesh name="VelocityMesh"/>
147
 
        <algorithm name="scalar_python_diagnostic" material_phase_support="single">
148
 
          <string_value lines="20" type="code" language="python">soln = state.scalar_fields["Velocity"]
149
 
exact = state.scalar_fields["AnalyticalSolution"]
150
 
# The problem is only specified up to a constant, so add on the constant
151
 
constant = exact.node_val(0) - soln.node_val(0)
152
 
 
153
 
for i in range(field.node_count):
154
 
  field.set(i, soln.node_val(i) + constant - exact.node_val(i))</string_value>
155
 
        </algorithm>
156
 
        <stat/>
157
 
        <adjoint_storage>
158
 
          <exists_in_forward/>
159
 
        </adjoint_storage>
160
 
      </diagnostic>
161
 
    </scalar_field>
162
 
  </material_phase>
163
 
  <adjoint>
164
 
    <functional name="time_integral_ad">
165
 
      <functional_value>
166
 
        <algorithm name="functional_value">
167
 
          <string_value lines="20" type="code" language="python">import numpy
168
 
 
169
 
coord = states[0]["Fluid"].vector_fields["Coordinate"]
170
 
u = states[n]["Fluid"].scalar_fields["Velocity"]
171
 
u_prev = states[n-1]["Fluid"].scalar_fields["Velocity"]
172
 
int_u = 0.0
173
 
int_u_prev = 0.0
174
 
 
175
 
for ele in range(coord.element_count):
176
 
  t = Transform(ele, coord)
177
 
  shape = u.ele_shape(ele)
178
 
  mass = t.shape_shape(shape, shape)
179
 
  int_u = int_u + sum(numpy.dot(mass, u.ele_val(ele)))
180
 
  int_u_prev = int_u_prev + sum(numpy.dot(mass, u_prev.ele_val(ele)))
181
 
 
182
 
J = dt * (int_u + int_u_prev) * 0.5
183
 
#if not hasattr(J, "nominal_value"): 
184
 
#  print "J(%d): %s" % (n, J)
185
 
#  print "int(u[%d]): %s" % (n, int_u)
186
 
#  print "int(u[%d]): %s" % (n-1, int_u_prev)</string_value>
187
 
        </algorithm>
188
 
        <reduction>
189
 
          <sum/>
190
 
        </reduction>
191
 
      </functional_value>
192
 
      <functional_dependencies>
193
 
        <algorithm name="functional_dependencies">
194
 
          <string_value lines="20" type="code" language="python">def dependencies(times, timestep):
195
 
  return {"Fluid::Coordinate": [0],
196
 
          "Fluid::Velocity": [timestep-1, timestep]}</string_value>
197
 
        </algorithm>
198
 
      </functional_dependencies>
199
 
    </functional>
200
 
    <functional name="time_integral_hc">
201
 
      <functional_derivative>
202
 
        <algorithm name="functional_derivative">
203
 
          <string_value lines="20" type="code" language="python">import numpy
204
 
 
205
 
if n == 0 or n == len(times) - 1:
206
 
  multiple = 1
207
 
else:
208
 
  multiple = 2
209
 
  
210
 
dt = times[1] - times[0]
211
 
  
212
 
coord = states[0]["Fluid"].vector_fields["Coordinate"]
213
 
derivative.val[:] = 0.0
214
 
 
215
 
if derivative.name == "Fluid::Velocity":
216
 
  for ele in range(coord.element_count):
217
 
    t = Transform(ele, coord)
218
 
    shape = derivative.ele_shape(ele)
219
 
    derivative.addto(derivative.ele_nodes(ele), numpy.dot(shape.n, t.detwei))
220
 
    
221
 
  derivative.val[:] = (dt/2.0) * multiple * derivative.val</string_value>
222
 
        </algorithm>
223
 
      </functional_derivative>
224
 
      <functional_dependencies>
225
 
        <algorithm name="functional_dependencies">
226
 
          <string_value lines="20" type="code" language="python">def dependencies(times, timestep):
227
 
  return {"Fluid::Coordinate": [0],
228
 
          "Fluid::Velocity": [timestep-1, timestep]}</string_value>
229
 
        </algorithm>
230
 
      </functional_dependencies>
231
 
    </functional>
232
 
  </adjoint>
233
 
</burgers_equation>