1467
1454
enddo !k=1,size(POD_state,1)
1469
open(51,file='pod_matrix_4000_2')
1470
write(51,*)(pod_matrix%val)
1472
open(52,file='pod_rhs_4000_2')
1473
write(52,*)(pod_rhs%val)
1479
print *,"before POD_u"
1480
POD_u=>extract_vector_field(POD_state(1,1,istate), "Velocity")
1481
print *,"before POD_u_scalar"
1482
!POD_u_scalar=extract_scalar_field(POD_u,1) !!need modify
1483
POD_num=size(POD_state)
1484
print *,"before allocate(X_val"
1485
allocate(X_val(POD_u%dim,ele_loc(POD_u,ele)))
1486
print *,"before allocate JJ"
1487
allocate(JJ(POD_u%dim,mesh_dim(POD_u)))
1488
!allocate(pod_coef(POD_u%dim*POD_num+POD_num))
1489
pod_umesh => extract_mesh(POD_state(1,1,istate), "Mesh", stat)
1490
TOTELE=pod_umesh%elements
1491
NLOC=pod_umesh%shape%loc
1492
NGI=pod_umesh%shape%ngi
1493
print *,"before allocate rhs_old"
1494
call allocate(pod_rhs_old, POD_u, POD_pressure)
1496
xf_shape=>ele_shape(POD_u,1)
1497
x_shape=>ele_shape(POD_u,1)
1498
print *, "timestep,, 2+++"
1500
!POD_u_scalar=>extract_scalar_field(POD_state(j), "PODPressure")
1501
!POD_u_scalar=extract_scalar_field(POD_u,j)
1502
X_val=ele_val(POD_u, j)
1503
xf_shape=>ele_shape(Pod_u,j) !!
1504
x_shape=>ele_shape(POD_u,j)!!
1506
!!new added for petro-galerkin
1458
!! Petrov-Galerkin POD
1460
POD_u=>extract_vector_field(POD_state(1,1,istate), "Velocity")
1461
POD_num=size(POD_state)
1462
allocate(X_val(POD_u%dim,ele_loc(POD_u,ele)))
1463
allocate(JJ(POD_u%dim,mesh_dim(POD_u)))
1464
pod_umesh => extract_mesh(POD_state(1,1,istate), "Mesh", stat)
1465
TOTELE=pod_umesh%elements
1466
NLOC=pod_umesh%shape%loc
1467
NGI=pod_umesh%shape%ngi
1468
call allocate(pod_rhs_old, POD_u, POD_pressure)
1470
xf_shape=>ele_shape(POD_u,1)
1471
x_shape=>ele_shape(POD_u,1)
1473
X_val=ele_val(POD_u, j)
1474
xf_shape=>ele_shape(Pod_u,j) !!
1475
x_shape=>ele_shape(POD_u,j)!!
1477
!!new added for petro-galerkin
1509
! allocate(pod_sol_velocity(u_nodes,POD_velocity%dim))
1510
allocate(theta_pet(NGI))
1511
allocate(leftsvd(TOTELE*NLOC+NLOC,nsvd))
1512
allocate(leftsvd_gi(NGI,nsvd))
1513
allocate(leftsvd_x_gi(NGI,nsvd))
1514
allocate(smean_gi(NGI))
1515
allocate(AMAT_pod(nsvd,nsvd))
1516
allocate(KMAT_pod(nsvd,nsvd))
1517
allocate(KB_pod(nsvd))
1518
allocate(b_pod(nsvd))
1519
allocate(PSI(TOTELE*NLOC+NLOC))
1520
allocate(PSI_GI(NGI))
1521
allocate(PSI_OLD_GI(NGI))
1522
allocate(psi_old(TOTELE*NLOC+NLOC))
1523
allocate(GRADX(NGI))
1524
allocate(GRADT(NGI))
1525
allocate(DIFFGI_pod(NGI))
1526
allocate(detwei(NGI))
1530
! allocate(dshape(noloc,nogas,POD_u%dim))
1531
allocate(dshape(x_shape%loc,x_shape%ngi,POD_u%dim)) !number of nodes, NO. of gussian
1480
! allocate(pod_sol_velocity(u_nodes,POD_velocity%dim))
1481
allocate(theta_pet(NGI))
1482
allocate(leftsvd(TOTELE*NLOC+NLOC,nsvd))
1483
allocate(leftsvd_gi(NGI,nsvd))
1484
allocate(leftsvd_x_gi(NGI,nsvd))
1485
allocate(smean_gi(NGI))
1486
allocate(AMAT_pod(nsvd,nsvd))
1487
allocate(KMAT_pod(nsvd,nsvd))
1488
allocate(KB_pod(nsvd))
1489
allocate(b_pod(nsvd))
1490
allocate(PSI(TOTELE*NLOC+NLOC))
1491
allocate(PSI_GI(NGI))
1492
allocate(PSI_OLD_GI(NGI))
1493
allocate(psi_old(TOTELE*NLOC+NLOC))
1494
allocate(GRADX(NGI))
1495
allocate(GRADT(NGI))
1496
allocate(DIFFGI_pod(NGI))
1497
allocate(detwei(NGI))
1499
allocate(dshape(x_shape%loc,x_shape%ngi,POD_u%dim)) !number of nodes, NO. of gussian
1534
! new added for petro-galerkin Residual, see Non-Linear Petrov-Galerkin Methods for
1535
! Hyperbolic Equations and Discontinuous Finite Element Methods .. eqn 102
1536
! get the result of Residual value"
1538
pod_rhs_old%val=pod_rhs%val
1539
call solve(pod_matrix%val, pod_rhs%val)
1540
! pod_coef=pod_rhs%val
1541
pod_rhs%val=pod_rhs%val-pod_rhs_old%val
1542
call SMLINN(pod_matrix%val,RES,pod_rhs%val,GI,GI) ! get the RES
1549
call transform_to_physical(POD_u, ele, ele_shape(POD_u,1), detwei=detwei, dshape=dshape)
1550
DO GI=1,NGI ! guassian points' number
1551
DO JLOC=1,NLOC ! NLOC points in one element
1552
GLOBJ=(ELE-1)*NLOC+JLOC
1502
! new added for petro-galerkin Residual, see Non-Linear Petrov-Galerkin Methods for
1503
! Hyperbolic Equations and Discontinuous Finite Element Methods .. eqn 102
1504
! get the result of Residual value"
1506
pod_rhs_old%val=pod_rhs%val
1507
call solve(pod_matrix%val, pod_rhs%val)
1508
! pod_coef=pod_rhs%val
1509
pod_rhs%val=pod_rhs%val-pod_rhs_old%val
1510
call SMLINN(pod_matrix%val,RES,pod_rhs%val,GI,GI) ! get the RES
1517
call transform_to_physical(POD_u, ele, ele_shape(POD_u,1), detwei=detwei, dshape=dshape)
1518
DO GI=1,NGI ! guassian points' number
1519
DO JLOC=1,NLOC ! NLOC points in one element
1520
GLOBJ=(ELE-1)*NLOC+JLOC
1523
leftsvd(GLOBJ,isvd)=POD_u%val(GLOBJ,isvd)
1524
leftsvd_gi(GI,isvd)=leftsvd_gi(GI,isvd)+xf_shape%dn(isvd,GI,1)*leftsvd(GLOBJ,isvd)
1525
!N shape function, leftsvd: podbasis, N(JLOC,GI): ele_shape(nu, ele)
1526
leftsvd_x_gi(GI,isvd)=leftsvd_gi(GI,isvd)+dshape(JLOC,GI,1)*leftsvd(GLOBJ,isvd)
1528
!smean_gi(gi)=smean_gi(gi)+ 1SMLINN(A,X,B,NMX,N)*smean(GLOBJ) !need modification
1529
!smean_gi(gi)=smean_gi(gi)+ 1*smean(GLOBJ)
1534
PSI_GI=0.0 ! quadrature point
1539
GLOBJ=(ELE-1)*NLOC+JLOC
1540
PSI_GI(GI)=PSI_GI(GI)+xf_shape%dn(isvd,GI,1)*PSI(GLOBJ)
1541
PSI_OLD_GI(GI)=PSI_OLD_GI(GI)+xf_shape%dn(isvd,GI,1)*PSI_OLD(GLOBJ)
1546
! calculate the GRADX and GRADT quadrature point
1549
DO GI=1,NGI ! ?? NGI and NLOC need input
1551
GLOBJ=(ELE-1)*NLOC+JLOC
1552
PSI_theta=theta_pet(GI)*PSI(GLOBJ)+(1.-theta_pet(GI))*PSI_OLD(GLOBJ)
1554
GRADX(GI)=GRADX(GI)+dshape(JLOC,GI,1)*PSI_theta
1555
GRADT(GI)=GRADT(GI)+xf_shape%dn(isvd,GI,1)*(PSI(GLOBJ)-PSI_OLD(GLOBJ))/DT1
1559
! get the result of AX_STAR cos P_STAR_POD need it
1562
A_STAR_COEF=(GRADX(GI)+GRADT(GI)*1.) &
1563
/MAX(1.E-6,GRADX(GI)**2+1.*GRADT(GI)**2)
1564
! AT_STAR=A_STAR_COEF*GRADT(GI)
1565
AX_STAR=A_STAR_COEF*GRADX(GI)
1570
P_STAR_POD = 0.25/abs(AX_STAR*leftsvd_x_gi(GI,isvd))
1572
P_STAR_POD = 0.25/max(P_STAR_POD,abs(AX_STAR*leftsvd_x_gi(GI,isvd)))
1575
DIFFGI_pod(GI) = 1.0e-4*P_STAR_POD*RES(GI)**2 &
1576
/ MAX(1.E-6,GRADX(GI)**2+GRADT(GI)**2)!!v_pod (eqn.100)
1582
KMAT_pod(isvd,jsvd) = KMAT_pod(isvd,jsvd) &
1583
+ detwei(GI)*leftsvd_x_gi(GI,isvd)*DIFFGI_pod(GI)*leftsvd_x_gi(GI,jsvd)
1584
! (eqn.99 left side,leftsvd_x_gi:delta N)
1594
!pod_rhs%val=0.001*pod_rhs%val
1595
! add K to (MT AM + K) fi *pod= MT b.
1599
pod_matrix%val(isvd,jsvd) = pod_matrix%val(isvd,jsvd)+KMAT_pod(isvd,jsvd)
1601
!b_pod(isvd) = b_pod(isvd)-KB_pod(isvd)
1604
call solve(pod_matrix%val,pod_rhs_old%val)
1605
pod_rhs%val=pod_rhs_old%val
1606
deallocate(theta_pet)
1608
deallocate(leftsvd_gi)
1609
deallocate(leftsvd_x_gi)
1610
deallocate(smean_gi)
1611
deallocate(AMAT_pod)
1612
deallocate(KMAT_pod)
1617
deallocate(PSI_OLD_GI)
1621
deallocate(DIFFGI_pod)
1626
call solve(pod_matrix%val,pod_rhs%val)
1630
! call solve(pod_matrix%val, pod_rhs%val)
1632
pod_coef_dt=pod_rhs%val
1635
pod_coef(:)=pod_coef(:)+dt*pod_coef_dt(:)
1636
!pod_coef(:)=pod_coef_dt(:)
1638
!save pod_coef, rewrite every timestep
1639
open(40,file='pod_coef')
1640
write(40,*)(pod_coef(i),i=1,(u%dim+1)*size(POD_state,1))
1644
call project_full(delta_u, delta_p, pod_sol_velocity, pod_sol_pressure, POD_state(:,:,istate), pod_coef)
1651
snapmean_velocity=>extract_vector_field(POD_state(1,1,istate),"SnapmeanVelocity")
1652
snapmean_pressure=>extract_Scalar_field(POD_state(1,2,istate),"SnapmeanPressure")
1653
!call addto(u, delta_u, dt)
1654
u%val=snapmean_velocity%val
1655
call addto(u, delta_u)
1656
p%val=snapmean_pressure%val
1657
call addto(p, delta_p)
1659
call deallocate(delta_p)
1660
call deallocate(delta_u)
1662
deallocate(pod_matrix_snapmean)
1663
deallocate(pod_rhs_snapmean)
1664
deallocate(pod_matrix_perturbed)
1665
deallocate(pod_matrix_adv_perturbed)
1666
deallocate(pod_rhs_perturbed)
1667
deallocate(pod_rhs_adv_perturbed)
1668
deallocate(pod_ct_m)
1669
call deallocate(pod_matrix)
1670
call deallocate(pod_matrix_mass)
1671
call deallocate(pod_rhs)
1674
endif ! prognostic velocity
1555
leftsvd(GLOBJ,isvd)=POD_u%val(GLOBJ,isvd)
1556
leftsvd_gi(GI,isvd)=leftsvd_gi(GI,isvd)+xf_shape%dn(isvd,GI,1)*leftsvd(GLOBJ,isvd)
1557
!N shape function, leftsvd: podbasis, N(JLOC,GI): ele_shape(nu, ele)
1558
leftsvd_x_gi(GI,isvd)=leftsvd_gi(GI,isvd)+dshape(JLOC,GI,1)*leftsvd(GLOBJ,isvd)
1560
!smean_gi(gi)=smean_gi(gi)+ 1SMLINN(A,X,B,NMX,N)*smean(GLOBJ) !need modification
1561
!smean_gi(gi)=smean_gi(gi)+ 1*smean(GLOBJ)
1566
PSI_GI=0.0 ! quadrature point
1571
GLOBJ=(ELE-1)*NLOC+JLOC
1572
PSI_GI(GI)=PSI_GI(GI)+xf_shape%dn(isvd,GI,1)*PSI(GLOBJ)
1573
PSI_OLD_GI(GI)=PSI_OLD_GI(GI)+xf_shape%dn(isvd,GI,1)*PSI_OLD(GLOBJ)
1578
! calculate the GRADX and GRADT quadrature point
1581
DO GI=1,NGI ! ?? NGI and NLOC need input
1583
GLOBJ=(ELE-1)*NLOC+JLOC
1584
PSI_theta=theta_pet(GI)*PSI(GLOBJ)+(1.-theta_pet(GI))*PSI_OLD(GLOBJ)
1586
GRADX(GI)=GRADX(GI)+dshape(JLOC,GI,1)*PSI_theta
1587
GRADT(GI)=GRADT(GI)+xf_shape%dn(isvd,GI,1)*(PSI(GLOBJ)-PSI_OLD(GLOBJ))/DT1
1591
! get the result of AX_STAR cos P_STAR_POD need it
1594
A_STAR_COEF=(GRADX(GI)+GRADT(GI)*1.) &
1595
/MAX(1.E-6,GRADX(GI)**2+1.*GRADT(GI)**2)
1596
! AT_STAR=A_STAR_COEF*GRADT(GI)
1597
AX_STAR=A_STAR_COEF*GRADX(GI)
1602
P_STAR_POD = 0.25/abs(AX_STAR*leftsvd_x_gi(GI,isvd))
1604
P_STAR_POD = 0.25/max(P_STAR_POD,abs(AX_STAR*leftsvd_x_gi(GI,isvd)))
1607
DIFFGI_pod(GI) = 1.0e-4*P_STAR_POD*RES(GI)**2 &
1608
/ MAX(1.E-6,GRADX(GI)**2+GRADT(GI)**2)!!v_pod (eqn.100)
1614
KMAT_pod(isvd,jsvd) = KMAT_pod(isvd,jsvd) &
1615
+ detwei(GI)*leftsvd_x_gi(GI,isvd)*DIFFGI_pod(GI)*leftsvd_x_gi(GI,jsvd)
1616
! (eqn.99 left side,leftsvd_x_gi:delta N)
1626
!pod_rhs%val=0.001*pod_rhs%val
1627
! add K to (MT AM + K) fi *pod= MT b.
1631
pod_matrix%val(isvd,jsvd) = pod_matrix%val(isvd,jsvd)+KMAT_pod(isvd,jsvd)
1633
!b_pod(isvd) = b_pod(isvd)-KB_pod(isvd)
1636
call solve(pod_matrix%val,pod_rhs_old%val)
1637
pod_rhs%val=pod_rhs_old%val
1638
deallocate(theta_pet)
1640
deallocate(leftsvd_gi)
1641
deallocate(leftsvd_x_gi)
1642
deallocate(smean_gi)
1643
deallocate(AMAT_pod)
1644
deallocate(KMAT_pod)
1649
deallocate(PSI_OLD_GI)
1653
deallocate(DIFFGI_pod)
1658
call solve(pod_matrix%val,pod_rhs%val)
1661
! call solve(pod_matrix%val, pod_rhs%val)
1663
pod_coef_dt=pod_rhs%val
1666
pod_coef(:)=pod_coef(:)+dt*pod_coef_dt(:)
1667
!pod_coef(:)=pod_coef_dt(:)
1669
!save pod_coef, rewrite every timestep
1670
open(40,file='pod_coef')
1671
write(40,*)(pod_coef(i),i=1,(u%dim+1)*size(POD_state,1))
1675
call project_full(delta_u, delta_p, pod_sol_velocity, pod_sol_pressure, POD_state(:,:,istate), pod_coef)
1682
snapmean_velocity=>extract_vector_field(POD_state(1,1,istate),"SnapmeanVelocity")
1683
snapmean_pressure=>extract_Scalar_field(POD_state(1,2,istate),"SnapmeanPressure")
1684
!call addto(u, delta_u, dt)
1685
u%val=snapmean_velocity%val
1686
call addto(u, delta_u)
1687
p%val=snapmean_pressure%val
1688
call addto(p, delta_p)
1690
call deallocate(delta_p)
1691
call deallocate(delta_u)
1693
deallocate(pod_matrix_snapmean)
1694
deallocate(pod_rhs_snapmean)
1695
deallocate(pod_matrix_perturbed)
1696
deallocate(pod_matrix_adv_perturbed)
1697
deallocate(pod_rhs_perturbed)
1698
deallocate(pod_rhs_adv_perturbed)
1699
deallocate(pod_ct_m)
1700
call deallocate(pod_matrix)
1701
call deallocate(pod_matrix_mass)
1702
call deallocate(pod_rhs)
1705
endif ! prognostic velocity
1707
enddo reduced_model_loop
1708
call profiler_toc("reduced_model_loop")
1710
! endif ! its=nonlinear_iterations
1711
end if ! end of 'if .not.reduced_model'
1676
enddo reduced_model_loop
1677
call profiler_toc("reduced_model_loop")
1679
! endif ! its=nonlinear_iterations
1680
end if ! end of 'if .not.reduced_model'
1714
1683
if(.not.reduced_model .or. (reduced_model .and. timestep_check))then