@@ -260,35 +260,114 @@ function _get_cell_dof_ids_inner_space(s::TrialFESpace)
260
260
_get_cell_dof_ids_inner_space (s. space)
261
261
end
262
262
263
- function get_redistribute_free_values_cache (fv_new:: Union{PVector,Nothing} ,
264
- Uh_new:: Union{DistributedSingleFieldFESpace,Nothing} ,
265
- fv_old:: Union{PVector,Nothing} ,
266
- dv_old:: Union{AbstractArray,Nothing} ,
267
- Uh_old:: Union{DistributedSingleFieldFESpace,Nothing} ,
268
- model_new,
269
- glue:: RedistributeGlue ;
270
- reverse= false )
263
+ function redistribute_fe_function (uh_old:: Union{DistributedSingleFieldFEFunction,Nothing} ,
264
+ Uh_new:: Union{DistributedSingleFieldFESpace,Nothing} ,
265
+ model_new,
266
+ glue:: RedistributeGlue ;
267
+ reverse= false )
268
+
271
269
old_parts, new_parts = get_old_and_new_parts (glue,Val (reverse))
272
- cell_dof_values_old = i_am_in (old_parts) ? map (scatter_free_and_dirichlet_values,local_views (Uh_old),local_views (fv_old),dv_old) : nothing
273
- cell_dof_ids_new = i_am_in (new_parts) ? map (_get_cell_dof_ids_inner_space, local_views (Uh_new)) : nothing
274
- caches = get_redistribute_cell_dofs_cache (cell_dof_values_old,cell_dof_ids_new,model_new,glue;reverse= reverse)
275
- return caches
270
+ cell_dof_values_old = i_am_in (old_parts) ? map (get_cell_dof_values,local_views (uh_old)) : nothing
271
+ cell_dof_ids_new = i_am_in (new_parts) ? map (_get_cell_dof_ids_inner_space,local_views (Uh_new)) : nothing
272
+ cell_dof_values_new = redistribute_cell_dofs (cell_dof_values_old,cell_dof_ids_new,model_new,glue;reverse= reverse)
273
+
274
+ # Assemble the new FEFunction
275
+ if i_am_in (new_parts)
276
+ free_values, dirichlet_values = Gridap. FESpaces. gather_free_and_dirichlet_values (Uh_new,cell_dof_values_new)
277
+ free_values = PVector (free_values,partition (Uh_new. gids))
278
+ uh_new = FEFunction (Uh_new,free_values,dirichlet_values)
279
+ return uh_new
280
+ else
281
+ return nothing
282
+ end
283
+ end
284
+
285
+ for T in [:DistributedSingleFieldFESpace ,:DistributedMultiFieldFESpace ]
286
+ @eval begin
287
+ _get_fe_type (:: $T ,:: Nothing ) = $ T
288
+ _get_fe_type (:: Nothing ,:: $T ) = $ T
289
+ _get_fe_type (:: $T ,:: $T ) = $ T
290
+ end
276
291
end
277
292
278
293
function redistribute_free_values (fv_new:: Union{PVector,Nothing} ,
279
- Uh_new:: Union{DistributedSingleFieldFESpace,Nothing} ,
294
+ Uh_new:: Union{DistributedSingleFieldFESpace,DistributedMultiFieldFESpace, Nothing} ,
280
295
fv_old:: Union{PVector,Nothing} ,
281
296
dv_old:: Union{AbstractArray,Nothing} ,
282
- Uh_old:: Union{DistributedSingleFieldFESpace,Nothing} ,
297
+ Uh_old:: Union{DistributedSingleFieldFESpace,DistributedMultiFieldFESpace, Nothing} ,
283
298
model_new,
284
299
glue:: RedistributeGlue ;
285
300
reverse= false )
286
-
287
301
caches = get_redistribute_free_values_cache (fv_new,Uh_new,fv_old,dv_old,Uh_old,model_new,glue;reverse= reverse)
288
302
return redistribute_free_values! (caches,fv_new,Uh_new,fv_old,dv_old,Uh_old,model_new,glue;reverse= reverse)
289
303
end
290
304
305
+ function get_redistribute_free_values_cache (fv_new,Uh_new,
306
+ fv_old,dv_old,Uh_old,
307
+ model_new,glue:: RedistributeGlue ;
308
+ reverse= false )
309
+ T = _get_fe_type (Uh_new,Uh_old)
310
+ get_redistribute_free_values_cache (T,fv_new,Uh_new,fv_old,dv_old,Uh_old,model_new,glue;reverse= reverse)
311
+ end
312
+
313
+ function get_redistribute_free_values_cache (:: Type{DistributedSingleFieldFESpace} ,
314
+ fv_new,Uh_new,
315
+ fv_old,dv_old,Uh_old,
316
+ model_new,glue:: RedistributeGlue ;
317
+ reverse= false )
318
+ old_parts, new_parts = get_old_and_new_parts (glue,Val (reverse))
319
+ cell_dof_values_old = i_am_in (old_parts) ? map (scatter_free_and_dirichlet_values,local_views (Uh_old),local_views (fv_old),dv_old) : nothing
320
+ cell_dof_ids_new = i_am_in (new_parts) ? map (_get_cell_dof_ids_inner_space, local_views (Uh_new)) : nothing
321
+ caches = get_redistribute_cell_dofs_cache (cell_dof_values_old,cell_dof_ids_new,model_new,glue;reverse= reverse)
322
+ return caches
323
+ end
324
+
325
+ function get_redistribute_free_values_cache (:: Type{DistributedMultiFieldFESpace} ,
326
+ fv_new,Uh_new,
327
+ fv_old,dv_old,Uh_old,
328
+ model_new,glue:: RedistributeGlue ;
329
+ reverse= false )
330
+ old_parts, new_parts = get_old_and_new_parts (glue,Val (reverse))
331
+
332
+ if i_am_in (old_parts)
333
+ Uh_old_i = Uh_old. field_fe_space
334
+ fv_old_i = map (i-> restrict_to_field (Uh_old,fv_old,i),1 : num_fields (Uh_old))
335
+ dv_old_i = dv_old
336
+ else
337
+ nfields = num_fields (Uh_new) # The other is not Nothing
338
+ Uh_old_i = [nothing for i = 1 : nfields]
339
+ fv_old_i = [nothing for i = 1 : nfields]
340
+ dv_old_i = [nothing for i = 1 : nfields]
341
+ end
342
+
343
+ if i_am_in (new_parts)
344
+ Uh_new_i = Uh_new. field_fe_space
345
+ fv_new_i = map (i-> restrict_to_field (Uh_new,fv_new,i),1 : num_fields (Uh_new))
346
+ else
347
+ nfields = num_fields (Uh_old) # The other is not Nothing
348
+ Uh_new_i = [nothing for i = 1 : nfields]
349
+ fv_new_i = [nothing for i = 1 : nfields]
350
+ end
351
+
352
+ caches = map (Uh_new_i,Uh_old_i,fv_new_i,fv_old_i,dv_old_i) do Uh_new_i,Uh_old_i,fv_new_i,fv_old_i,dv_old_i
353
+ get_redistribute_free_values_cache (DistributedSingleFieldFESpace,fv_new_i,Uh_new_i,fv_old_i,dv_old_i,Uh_old_i,model_new,glue;reverse= reverse)
354
+ end
355
+
356
+ return caches
357
+ end
358
+
291
359
function redistribute_free_values! (caches,
360
+ fv_new,Uh_new,
361
+ fv_old,dv_old,Uh_old,
362
+ model_new,
363
+ glue:: RedistributeGlue ;
364
+ reverse= false )
365
+ T = _get_fe_type (Uh_new,Uh_old)
366
+ redistribute_free_values! (T,caches,fv_new,Uh_new,fv_old,dv_old,Uh_old,model_new,glue;reverse= reverse)
367
+ end
368
+
369
+ function redistribute_free_values! (:: Type{DistributedSingleFieldFESpace} ,
370
+ caches,
292
371
fv_new:: Union{PVector,Nothing} ,
293
372
Uh_new:: Union{DistributedSingleFieldFESpace,Nothing} ,
294
373
fv_old:: Union{PVector,Nothing} ,
@@ -310,24 +389,40 @@ function redistribute_free_values!(caches,
310
389
return fv_new
311
390
end
312
391
313
- function redistribute_fe_function (uh_old:: Union{DistributedSingleFieldFEFunction,Nothing} ,
314
- Uh_new:: Union{DistributedSingleFieldFESpace,Nothing} ,
315
- model_new,
316
- glue:: RedistributeGlue ;
317
- reverse= false )
392
+ function redistribute_free_values! (:: Type{DistributedMultiFieldFESpace} ,
393
+ caches,
394
+ fv_new:: Union{PVector,Nothing} ,
395
+ Uh_new:: Union{DistributedMultiFieldFESpace,Nothing} ,
396
+ fv_old:: Union{PVector,Nothing} ,
397
+ dv_old:: Union{AbstractArray,Nothing} ,
398
+ Uh_old:: Union{DistributedMultiFieldFESpace,Nothing} ,
399
+ model_new,
400
+ glue:: RedistributeGlue ;
401
+ reverse= false )
318
402
319
403
old_parts, new_parts = get_old_and_new_parts (glue,Val (reverse))
320
- cell_dof_values_old = i_am_in (old_parts) ? map (get_cell_dof_values,local_views (uh_old)) : nothing
321
- cell_dof_ids_new = i_am_in (new_parts) ? map (_get_cell_dof_ids_inner_space,local_views (Uh_new)) : nothing
322
- cell_dof_values_new = redistribute_cell_dofs (cell_dof_values_old,cell_dof_ids_new,model_new,glue;reverse= reverse)
323
404
324
- # Assemble the new FEFunction
405
+ if i_am_in (old_parts)
406
+ Uh_old_i = Uh_old. field_fe_space
407
+ fv_old_i = map (i-> restrict_to_field (Uh_old,fv_old,i),1 : num_fields (Uh_old))
408
+ dv_old_i = dv_old
409
+ else
410
+ nfields = num_fields (Uh_new) # The other is not Nothing
411
+ Uh_old_i = [nothing for i = 1 : nfields]
412
+ fv_old_i = [nothing for i = 1 : nfields]
413
+ dv_old_i = [nothing for i = 1 : nfields]
414
+ end
415
+
325
416
if i_am_in (new_parts)
326
- free_values, dirichlet_values = Gridap. FESpaces. gather_free_and_dirichlet_values (Uh_new,cell_dof_values_new)
327
- free_values = PVector (free_values,partition (Uh_new. gids))
328
- uh_new = FEFunction (Uh_new,free_values,dirichlet_values)
329
- return uh_new
417
+ Uh_new_i = Uh_new. field_fe_space
418
+ fv_new_i = map (i-> restrict_to_field (Uh_new,fv_new,i),1 : num_fields (Uh_new))
330
419
else
331
- return nothing
420
+ nfields = num_fields (Uh_old) # The other is not Nothing
421
+ Uh_new_i = [nothing for i = 1 : nfields]
422
+ fv_new_i = [nothing for i = 1 : nfields]
423
+ end
424
+
425
+ map (Uh_new_i,Uh_old_i,fv_new_i,fv_old_i,dv_old_i,caches) do Uh_new_i,Uh_old_i,fv_new_i,fv_old_i,dv_old_i,caches
426
+ redistribute_free_values! (DistributedSingleFieldFESpace,caches,fv_new_i,Uh_new_i,fv_old_i,dv_old_i,Uh_old_i,model_new,glue;reverse= reverse)
332
427
end
333
428
end
0 commit comments