Skip to content

Commit 07901be

Browse files
committed
Add logic to deal with moving meshes with coupled_cv.
Also add a couple of tests that use coupled_cv with a moving mesh. These both only advect a single "coupled" field so don't really test coupled cv beyond checking that it works with a moving mesh.
1 parent 072babe commit 07901be

File tree

9 files changed

+1169
-25
lines changed

9 files changed

+1169
-25
lines changed

assemble/Field_Equations_CV.F90

+41-25
Original file line numberDiff line numberDiff line change
@@ -1974,16 +1974,15 @@ subroutine assemble_advectiondiffusion_m_cv(A_m, rhs, D_m, diff_rhs, &
19741974
if(include_advection) then
19751975

19761976
! u.n
1977+
divudotn = dot_product(u_bdy_f(:,ggi), normal_bdy(:,ggi))
19771978
if(move_mesh) then
1978-
divudotn = dot_product(u_bdy_f(:,ggi), normal_bdy(:,ggi))
19791979
if((tfield_bc_type(sele)==BC_TYPE_ZEROFLUX .or. tfield_bc_type(sele)==BC_TYPE_FLUX)) then
19801980
! If we have zero flux, or a flux BC, set u.n = 0
19811981
udotn = 0.0
19821982
else
19831983
udotn = dot_product((u_bdy_f(:,ggi)-ug_bdy_f(:,ggi)), normal_bdy(:,ggi))
19841984
end if
19851985
else
1986-
divudotn = dot_product(u_bdy_f(:,ggi), normal_bdy(:,ggi))
19871986
if((tfield_bc_type(sele)==BC_TYPE_ZEROFLUX .or. tfield_bc_type(sele)==BC_TYPE_FLUX)) then
19881987
udotn = 0.0
19891988
else
@@ -2642,7 +2641,6 @@ subroutine solve_coupled_cv(field_name, nfields, state, global_it)
26422641

26432642
move_mesh = have_option("/mesh_adaptivity/mesh_movement")
26442643
if(move_mesh) then
2645-
FLExit("Moving meshes not fully set-up with coupled cv.")
26462644
if(.not.include_advection) then
26472645
FLExit("Moving the mesh but not including advection is not possible yet.")
26482646
end if
@@ -2769,12 +2767,11 @@ subroutine solve_coupled_cv(field_name, nfields, state, global_it)
27692767
tdensity, oldtdensity, tdensity_options, &
27702768
cvfaces, x_cvshape, x_cvbdyshape, &
27712769
u_cvshape, u_cvbdyshape, t_cvshape, &
2772-
state, advu, x, x_tfield, cfl_no, &
2770+
ug_cvshape, ug_cvbdyshape, &
2771+
state, advu, ug, x, x_tfield, cfl_no, &
27732772
getmat, sub_dt, &
27742773
mesh_sparsity_x)
27752774

2776-
2777-
27782775
do f = 1, nfields
27792776

27802777
! assemble it all into a coherent equation
@@ -2866,7 +2863,8 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
28662863
tdensity, oldtdensity, tdensity_options, &
28672864
cvfaces, x_cvshape, x_cvbdyshape, &
28682865
u_cvshape, u_cvbdyshape, t_cvshape, &
2869-
state, advu, x, x_tfield, cfl_no, getmat, dt, &
2866+
ug_cvshape, ug_cvbdyshape, &
2867+
state, advu, ug, x, x_tfield, cfl_no, getmat, dt, &
28702868
mesh_sparsity)
28712869

28722870
!!< This subroutine assembles the advection matrix and rhs for
@@ -2898,11 +2896,13 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
28982896
! shape functions for region and surface
28992897
type(element_type), intent(in) :: x_cvshape, x_cvbdyshape
29002898
type(element_type), intent(in) :: u_cvshape, u_cvbdyshape
2899+
type(element_type), intent(in) :: ug_cvshape, ug_cvbdyshape
29012900
type(element_type), intent(in) :: t_cvshape
29022901
! bucket full of fields
29032902
type(state_type), dimension(:), intent(inout) :: state
29042903
! the advection velocity
29052904
type(vector_field), intent(in) :: advu
2905+
type(vector_field), pointer :: ug
29062906
! the coordinates
29072907
type(vector_field), intent(inout) :: x, x_tfield
29082908
! the cfl number
@@ -2921,6 +2921,7 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
29212921
! and the cfl number at the gauss pts and nodes
29222922
real, dimension(:,:), allocatable :: x_ele, x_ele_bdy
29232923
real, dimension(:,:), allocatable :: x_f, u_f, u_bdy_f
2924+
real, dimension(:,:), allocatable :: ug_f, ug_bdy_f
29242925
real, dimension(:,:), allocatable :: normal, normal_bdy
29252926
real, dimension(:), allocatable :: detwei, detwei_bdy
29262927
real, dimension(:), allocatable :: normgi
@@ -2954,7 +2955,7 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
29542955
oldtfield_upwind, tdensity_upwind, oldtdensity_upwind
29552956

29562957
! incoming or outgoing flow
2957-
real :: udotn, income, udotn_bdy
2958+
real :: udotn, divudotn, income, udotn_bdy
29582959
logical :: inflow
29592960
! time and face discretisation
29602961
real, dimension(size(tfield)) :: ptheta, beta
@@ -2979,6 +2980,7 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
29792980
allocate(x_ele(x%dim,ele_loc(x,1)), &
29802981
x_f(x%dim, x_cvshape%ngi), &
29812982
u_f(advu%dim, u_cvshape%ngi), &
2983+
ug_f(advu%dim, ug_cvshape%ngi), &
29822984
detwei(x_cvshape%ngi), &
29832985
normal(x%dim, x_cvshape%ngi), &
29842986
normgi(x%dim))
@@ -3053,6 +3055,7 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
30533055
u_f=ele_val_at_quad(advu, ele, u_cvshape)
30543056
nodes=>ele_nodes(tfield(1)%ptr, ele)
30553057
x_nodes=>ele_nodes(x_tfield, ele)
3058+
if(move_mesh) ug_f=ele_val_at_quad(ug, ele, ug_cvshape)
30563059
if((tfield_options(1)%upwind_scheme==CV_UPWINDVALUE_PROJECT_POINT).or.&
30573060
(tfield_options(1)%upwind_scheme==CV_UPWINDVALUE_PROJECT_GRAD)) then
30583061
upwind_nodes=>x_nodes
@@ -3107,7 +3110,13 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
31073110
normgi=orientate_cvsurf_normgi(node_val(x_tfield, x_nodes(iloc)),x_f(:,ggi),normal(:,ggi))
31083111

31093112
! calculate u.n
3110-
udotn=dot_product(u_f(:,ggi), normgi(:))
3113+
if(move_mesh) then
3114+
udotn=dot_product((u_f(:,ggi)-ug_f(:,ggi)), normgi(:))
3115+
divudotn=dot_product(u_f(:,ggi), normgi(:))
3116+
else
3117+
udotn=dot_product(u_f(:,ggi), normgi(:))
3118+
divudotn=udotn
3119+
end if
31113120

31123121
inflow = (udotn<=0.0)
31133122

@@ -3188,22 +3197,22 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
31883197

31893198
call addto_diag(A_m(f), nodes(iloc), &
31903199
ptheta(f)*detwei(ggi)*udotn*(1.0-income)*tdensity_theta_val &
3191-
-ftheta*(1.-beta(f))*detwei(ggi)*udotn*tdensity_theta_val)
3200+
-ftheta*(1.-beta(f))*detwei(ggi)*divudotn*tdensity_theta_val)
31923201
call addto_diag(A_m(f), nodes(oloc), &
31933202
ptheta(f)*detwei(ggi)*(-udotn)*income*tdensity_theta_val &
3194-
-ftheta*(1.-beta(f))*detwei(ggi)*(-udotn)*tdensity_theta_val) ! notvisited
3203+
-ftheta*(1.-beta(f))*detwei(ggi)*(-divudotn)*tdensity_theta_val) ! notvisited
31953204

31963205
end if
31973206

31983207
! assemble the rhs
31993208
call addto(rhs(f), nodes(iloc), &
32003209
ptheta(f)*udotn*detwei(ggi)*tdensity_theta_val*tfield_pivot_val &
32013210
- udotn*detwei(ggi)*tfield_theta_val*tdensity_theta_val &
3202-
+ (1.-ftheta)*(1.-beta(f))*detwei(ggi)*udotn*tdensity_theta_val*oldtfield_ele(f,iloc))
3211+
+ (1.-ftheta)*(1.-beta(f))*detwei(ggi)*divudotn*tdensity_theta_val*oldtfield_ele(f,iloc))
32033212
call addto(rhs(f), nodes(oloc), &
32043213
ptheta(f)*(-udotn)*detwei(ggi)*tdensity_theta_val*tfield_pivot_val &
32053214
- (-udotn)*detwei(ggi)*tfield_theta_val*tdensity_theta_val &
3206-
+ (1.-ftheta)*(1.-beta(f))*detwei(ggi)*(-udotn)*tdensity_theta_val*oldtfield_ele(f,oloc)) ! notvisited
3215+
+ (1.-ftheta)*(1.-beta(f))*detwei(ggi)*(-divudotn)*tdensity_theta_val*oldtfield_ele(f,oloc)) ! notvisited
32073216
else
32083217
! if we need the matrix then assemble it now
32093218
if(getmat(f)) then
@@ -3214,22 +3223,22 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
32143223

32153224
call addto_diag(A_m(f), nodes(iloc), &
32163225
ptheta(f)*detwei(ggi)*udotn*(1.0-income)*tdensity_theta_val &
3217-
-ftheta*(1.-beta(f))*detwei(ggi)*udotn)
3226+
-ftheta*(1.-beta(f))*detwei(ggi)*divudotn)
32183227
call addto_diag(A_m(f), nodes(oloc), &
32193228
ptheta(f)*detwei(ggi)*(-udotn)*income*tdensity_theta_val &
3220-
-ftheta*(1.-beta(f))*detwei(ggi)*(-udotn)) ! notvisited
3229+
-ftheta*(1.-beta(f))*detwei(ggi)*(-divudotn)) ! notvisited
32213230

32223231
end if
32233232

32243233
! assemble the rhs
32253234
call addto(rhs(f), nodes(iloc), &
32263235
ptheta(f)*udotn*detwei(ggi)*tfield_pivot_val &
32273236
- udotn*detwei(ggi)*tfield_theta_val &
3228-
+ (1.-ftheta)*(1.-beta(f))*detwei(ggi)*udotn*oldtfield_ele(f,iloc))
3237+
+ (1.-ftheta)*(1.-beta(f))*detwei(ggi)*divudotn*oldtfield_ele(f,iloc))
32293238
call addto(rhs(f), nodes(oloc), &
32303239
ptheta(f)*(-udotn)*detwei(ggi)*tfield_pivot_val &
32313240
- (-udotn)*detwei(ggi)*tfield_theta_val &
3232-
+ (1.-ftheta)*(1.-beta(f))*detwei(ggi)*(-udotn)*oldtfield_ele(f,oloc)) ! notvisited
3241+
+ (1.-ftheta)*(1.-beta(f))*detwei(ggi)*(-divudotn)*oldtfield_ele(f,oloc)) ! notvisited
32333242

32343243
end if
32353244

@@ -3247,6 +3256,7 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
32473256
detwei_bdy(x_cvbdyshape%ngi), &
32483257
normal_bdy(x%dim, x_cvbdyshape%ngi), &
32493258
u_bdy_f(advu%dim, u_cvbdyshape%ngi), &
3259+
ug_bdy_f(advu%dim, ug_cvbdyshape%ngi), &
32503260
tdensity_ele_bdy(nfields,face_loc(tdensity(1)%ptr,1)), &
32513261
oldtdensity_ele_bdy(nfields,face_loc(oldtdensity(1)%ptr,1)), &
32523262
tfield_ele_bdy(nfields,face_loc(tfield(1)%ptr,1)), &
@@ -3283,6 +3293,7 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
32833293
x_cvbdyshape, normal_bdy, detwei_bdy)
32843294

32853295
u_bdy_f=face_val_at_quad(advu, sele, u_cvbdyshape)
3296+
if(move_mesh) ug_bdy_f=face_val_at_quad(ug, sele, ug_cvbdyshape)
32863297

32873298
do f = 1, nfields
32883299
! deal with bcs for tfield
@@ -3335,8 +3346,13 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
33353346
ggi = (face-1)*cvfaces%shape%ngi + gi
33363347

33373348
! u.n
3338-
udotn_bdy=dot_product(u_bdy_f(:,ggi), normal_bdy(:,ggi))
3339-
3349+
divudotn = dot_product(u_bdy_f(:,ggi), normal_bdy(:,ggi))
3350+
if(move_mesh) then
3351+
udotn_bdy = dot_product((u_bdy_f(:,ggi)-ug_bdy_f(:,ggi)), normal_bdy(:,ggi))
3352+
else
3353+
udotn_bdy = divudotn
3354+
end if
3355+
33403356
if(udotn_bdy>0) then
33413357
income=0.0 ! flow leaving the domain
33423358
else
@@ -3372,27 +3388,27 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
33723388
if(getmat(f)) then
33733389
call addto_diag(A_m(f), nodes_bdy(iloc), &
33743390
ptheta(f)*detwei_bdy(ggi)*udotn*(1.-income)*tdensity_theta_val & ! if iloc is the donor we can do this implicitly
3375-
- ptheta(f)*(1.-beta(f))*detwei_bdy(ggi)*udotn_bdy*tdensity_theta_val)
3391+
- ptheta(f)*(1.-beta(f))*detwei_bdy(ggi)*divudotn*tdensity_theta_val)
33763392
end if
33773393

33783394
! assemble rhs
33793395
call addto(rhs(f), nodes_bdy(iloc), &
33803396
-ptheta(f)*udotn*detwei_bdy(ggi)*income*tdensity_theta_val*ghost_tfield_ele_bdy(f,iloc) & ! but we can't if it's the downwind
33813397
-(1.-ptheta(f))*udotn*detwei_bdy(ggi)*tdensity_theta_val*oldtfield_face_val(f) &
3382-
+(1.-ptheta(f))*(1.-beta(f))*udotn_bdy*detwei_bdy(ggi)*tdensity_theta_val*oldtfield_ele_bdy(f,iloc))
3398+
+(1.-ptheta(f))*(1.-beta(f))*divudotn*detwei_bdy(ggi)*tdensity_theta_val*oldtfield_ele_bdy(f,iloc))
33833399
else
33843400
! assemble matrix
33853401
if(getmat(f)) then
33863402
call addto_diag(A_m(f), nodes_bdy(iloc), &
33873403
ptheta(f)*detwei_bdy(ggi)*udotn*(1.-income) & ! if iloc is the donor we can do this implicitly
3388-
- ptheta(f)*(1.-beta(f))*detwei_bdy(ggi)*udotn_bdy)
3404+
- ptheta(f)*(1.-beta(f))*detwei_bdy(ggi)*divudotn)
33893405
end if
33903406

33913407
! assemble rhs
33923408
call addto(rhs(f), nodes_bdy(iloc), &
33933409
-ptheta(f)*udotn*detwei_bdy(ggi)*income*ghost_tfield_ele_bdy(f,iloc) & ! but we can't if it's the downwind
33943410
-(1.-ptheta(f))*udotn*detwei_bdy(ggi)*oldtfield_face_val(f) &
3395-
+(1.-ptheta(f))*(1.-beta(f))*udotn_bdy*detwei_bdy(ggi)*oldtfield_ele_bdy(f,iloc))
3411+
+(1.-ptheta(f))*(1.-beta(f))*divudotn*detwei_bdy(ggi)*oldtfield_ele_bdy(f,iloc))
33963412
end if
33973413

33983414
end do surface_field_loop
@@ -3407,7 +3423,7 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
34073423

34083424
end do surface_element_loop
34093425

3410-
deallocate(x_ele_bdy, detwei_bdy, normal_bdy, u_bdy_f)
3426+
deallocate(x_ele_bdy, detwei_bdy, normal_bdy, u_bdy_f, ug_bdy_f)
34113427
deallocate(nodes_bdy)
34123428
deallocate(tdensity_ele_bdy, oldtdensity_ele_bdy, tfield_ele_bdy, oldtfield_ele_bdy)
34133429
deallocate(ghost_tdensity_ele_bdy, ghost_oldtdensity_ele_bdy, &
@@ -3427,7 +3443,7 @@ subroutine assemble_coupled_advection_m_cv(A_m, rhs, &
34273443
call deallocate(oldtfield_upwind(f))
34283444
end do
34293445

3430-
deallocate(x_ele, x_f, detwei, normal, normgi, u_f)
3446+
deallocate(x_ele, x_f, detwei, normal, normgi, u_f, ug_f)
34313447
deallocate(cfl_ele, tfield_ele, oldtfield_ele, tdensity_ele, oldtdensity_ele)
34323448
deallocate(notvisited)
34333449

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
input: clean
2+
gmsh -2 src/2d_square.geo
3+
cp src/2d_square.msh .
4+
5+
clean:
6+
rm -rf *.stat *.vtu *.node *.ele *.edge *_checkpoint.flml *convergence* *.log-0 *.err-0 src/*.msh *.msh \
7+
matrixdump matrixdump.info

0 commit comments

Comments
 (0)