@@ -120,7 +120,6 @@ def test_nonlinear_poisson(poly_order):
120
120
l2_error = np .zeros_like (N_vals , dtype = np .double )
121
121
for run_no , N in enumerate (N_vals ):
122
122
mesh = dolfinx .mesh .create_unit_square (MPI .COMM_WORLD , N , N )
123
-
124
123
V = dolfinx .fem .functionspace (mesh , ("Lagrange" , poly_order ))
125
124
u_bc = dolfinx .fem .Function (V )
126
125
u_bc .x .array [:] = 0.0
@@ -132,17 +131,6 @@ def test_nonlinear_poisson(poly_order):
132
131
bc = dolfinx .fem .dirichletbc (zero , topological_dofs , V )
133
132
bcs = [bc ]
134
133
135
- # Define variational problem
136
- u = dolfinx .fem .Function (V )
137
- v = ufl .TestFunction (V )
138
- x = ufl .SpatialCoordinate (mesh )
139
-
140
- u_soln = ufl .sin (ufl .pi * x [0 ]) * ufl .sin (ufl .pi * x [1 ])
141
- f = - ufl .div ((1 + u_soln ** 2 ) * ufl .grad (u_soln ))
142
-
143
- F = ufl .inner ((1 + u ** 2 ) * ufl .grad (u ), ufl .grad (v )) * ufl .dx - ufl .inner (f , v ) * ufl .dx
144
- J = ufl .derivative (F , u )
145
-
146
134
# -- Impose the pi/2 rotational symmetry of the solution as a constraint,
147
135
# -- except at the centre DoF
148
136
def periodic_boundary (x ):
@@ -160,6 +148,22 @@ def periodic_relation(x):
160
148
mpc .create_periodic_constraint_geometrical (V , periodic_boundary , periodic_relation , bcs )
161
149
mpc .finalize ()
162
150
151
+ # Define variational problem
152
+ V_mpc = mpc .function_space
153
+
154
+ # NOTE: The unknown function should always live in the MPC space,
155
+ # but to be compatible with the dirichlet bc the arguments (test and trial function)
156
+ # has to live in the original space V
157
+ u = dolfinx .fem .Function (V_mpc )
158
+ v = ufl .TestFunction (V )
159
+ x = ufl .SpatialCoordinate (mesh )
160
+
161
+ u_soln = ufl .sin (ufl .pi * x [0 ]) * ufl .sin (ufl .pi * x [1 ])
162
+ f = - ufl .div ((1 + u_soln ** 2 ) * ufl .grad (u_soln ))
163
+
164
+ F = ufl .inner ((1 + u ** 2 ) * ufl .grad (u ), ufl .grad (v )) * ufl .dx - ufl .inner (f , v ) * ufl .dx
165
+ J = ufl .derivative (F , u , ufl .TrialFunction (V ))
166
+
163
167
# Sanity check that the MPC class has some constraints to impose
164
168
num_slaves_global = mesh .comm .allreduce (len (mpc .slaves ), op = MPI .SUM )
165
169
num_masters_global = mesh .comm .allreduce (len (mpc .masters .array ), op = MPI .SUM )
0 commit comments