Runs unit tests on remapping functions. Should only be called from a single/root thread Returns True if a test fails, otherwise False.
1617 logical,
intent(in) :: verbose
1619 integer,
parameter :: n0 = 4, n1 = 3, n2 = 6
1620 real :: h0(n0), x0(n0+1), u0(n0)
1621 real :: h1(n1), x1(n1+1), u1(n1), hn1(n1), dx1(n1+1)
1622 real :: h2(n2), x2(n2+1), u2(n2), hn2(n2), dx2(n2+1)
1623 data u0 /9., 3., -3., -9./
1627 type(remapping_cs) :: cs
1628 real,
allocatable,
dimension(:,:) :: ppoly0_e, ppoly0_s, ppoly0_coefs
1629 logical :: answers_2018
1631 real :: err, h_neglect, h_neglect_edge
1632 logical :: thistest, v
1635 answers_2018 = .false.
1636 h_neglect = hneglect_dflt
1637 h_neglect_edge = hneglect_dflt ;
if (answers_2018) h_neglect_edge = 1.0e-10
1639 write(*,*)
'==== MOM_remapping: remapping_unit_tests =================' 1640 remapping_unit_tests = .false.
1643 call buildgridfromh(n0, h0, x0)
1645 err=x0(i)-0.75*
real(i-1)
1646 if (abs(err)>
real(i-1)*epsilon(err)) thistest = .true.
1648 if (thistest)
write(*,*)
'remapping_unit_tests: Failed buildGridFromH() 1' 1649 remapping_unit_tests = remapping_unit_tests .or. thistest
1650 call buildgridfromh(n1, h1, x1)
1653 if (abs(err)>
real(i-1)*epsilon(err)) thistest = .true.
1655 if (thistest)
write(*,*)
'remapping_unit_tests: Failed buildGridFromH() 2' 1656 remapping_unit_tests = remapping_unit_tests .or. thistest
1659 call initialize_remapping(cs,
'PPM_H4', answers_2018=answers_2018)
1660 if (verbose)
write(*,*)
'h0 (test data)' 1661 if (verbose)
call dumpgrid(n0,h0,x0,u0)
1663 call dzfromh1h2( n0, h0, n1, h1, dx1 )
1664 call remapping_core_w( cs, n0, h0, u0, n1, dx1, u1, h_neglect, h_neglect_edge)
1666 err=u1(i)-8.*(0.5*
real(1+n1)-
real(i))
1667 if (abs(err)>
real(n1-1)*epsilon(err)) thistest = .true.
1669 if (verbose)
write(*,*)
'h1 (by projection)' 1670 if (verbose)
call dumpgrid(n1,h1,x1,u1)
1671 if (thistest)
write(*,*)
'remapping_unit_tests: Failed remapping_core_w()' 1672 remapping_unit_tests = remapping_unit_tests .or. thistest
1675 allocate(ppoly0_e(n0,2))
1676 allocate(ppoly0_s(n0,2))
1677 allocate(ppoly0_coefs(n0,cs%degree+1))
1681 ppoly0_coefs(:,:) = 0.0
1683 call edge_values_explicit_h4( n0, h0, u0, ppoly0_e, h_neglect=1e-10, answers_2018=answers_2018 )
1684 call ppm_reconstruction( n0, h0, u0, ppoly0_e, ppoly0_coefs, h_neglect, answers_2018=answers_2018 )
1685 call ppm_boundary_extrapolation( n0, h0, u0, ppoly0_e, ppoly0_coefs, h_neglect )
1687 call remapbyprojection( n0, h0, u0, ppoly0_e, ppoly0_coefs, &
1688 n1, h1, integration_ppm, u1, h_neglect )
1690 err=u1(i)-8.*(0.5*
real(1+n1)-
real(i))
1691 if (abs(err)>2.*epsilon(err)) thistest = .true.
1693 if (thistest)
write(*,*)
'remapping_unit_tests: Failed remapByProjection()' 1694 remapping_unit_tests = remapping_unit_tests .or. thistest
1698 call remapbydeltaz( n0, h0, u0, ppoly0_e, ppoly0_coefs, &
1699 n1, x1-x0(1:n1+1), &
1700 integration_ppm, u1, hn1, h_neglect )
1701 if (verbose)
write(*,*)
'h1 (by delta)' 1702 if (verbose)
call dumpgrid(n1,h1,x1,u1)
1705 err=u1(i)-8.*(0.5*
real(1+n1)-
real(i))
1706 if (abs(err)>2.*epsilon(err)) thistest = .true.
1708 if (thistest)
write(*,*)
'remapping_unit_tests: Failed remapByDeltaZ() 1' 1709 remapping_unit_tests = remapping_unit_tests .or. thistest
1712 call buildgridfromh(n2, h2, x2)
1713 dx2(1:n0+1) = x2(1:n0+1) - x0
1714 dx2(n0+2:n2+1) = x2(n0+2:n2+1) - x0(n0+1)
1715 call remapbydeltaz( n0, h0, u0, ppoly0_e, ppoly0_coefs, &
1717 integration_ppm, u2, hn2, h_neglect )
1718 if (verbose)
write(*,*)
'h2' 1719 if (verbose)
call dumpgrid(n2,h2,x2,u2)
1720 if (verbose)
write(*,*)
'hn2' 1721 if (verbose)
call dumpgrid(n2,hn2,x2,u2)
1724 err=u2(i)-8./2.*(0.5*
real(1+n2)-
real(i))
1725 if (abs(err)>2.*epsilon(err)) thistest = .true.
1727 if (thistest)
write(*,*)
'remapping_unit_tests: Failed remapByDeltaZ() 2' 1728 remapping_unit_tests = remapping_unit_tests .or. thistest
1730 if (verbose)
write(*,*)
'Via sub-cells' 1732 call remap_via_sub_cells( n0, h0, u0, ppoly0_e, ppoly0_coefs, &
1733 n2, h2, integration_ppm, .false., u2, err )
1734 if (verbose)
call dumpgrid(n2,h2,x2,u2)
1737 err=u2(i)-8./2.*(0.5*
real(1+n2)-
real(i))
1738 if (abs(err)>2.*epsilon(err)) thistest = .true.
1740 if (thistest)
write(*,*)
'remapping_unit_tests: Failed remap_via_sub_cells() 2' 1741 remapping_unit_tests = remapping_unit_tests .or. thistest
1743 call remap_via_sub_cells( n0, h0, u0, ppoly0_e, ppoly0_coefs, &
1744 6, (/.125,.125,.125,.125,.125,.125/), integration_ppm, .false., u2, err )
1745 if (verbose)
call dumpgrid(6,h2,x2,u2)
1747 call remap_via_sub_cells( n0, h0, u0, ppoly0_e, ppoly0_coefs, &
1748 3, (/2.25,1.5,1./), integration_ppm, .false., u2, err )
1749 if (verbose)
call dumpgrid(3,h2,x2,u2)
1751 if (.not. remapping_unit_tests)
write(*,*)
'Pass' 1753 write(*,*)
'===== MOM_remapping: new remapping_unit_tests ==================' 1755 deallocate(ppoly0_e, ppoly0_s, ppoly0_coefs)
1756 allocate(ppoly0_coefs(5,6))
1757 allocate(ppoly0_e(5,2))
1758 allocate(ppoly0_s(5,2))
1760 call pcm_reconstruction(3, (/1.,2.,4./), ppoly0_e(1:3,:), &
1761 ppoly0_coefs(1:3,:) )
1762 remapping_unit_tests = remapping_unit_tests .or. &
1763 test_answer(v, 3, ppoly0_e(:,1), (/1.,2.,4./),
'PCM: left edges')
1764 remapping_unit_tests = remapping_unit_tests .or. &
1765 test_answer(v, 3, ppoly0_e(:,2), (/1.,2.,4./),
'PCM: right edges')
1766 remapping_unit_tests = remapping_unit_tests .or. &
1767 test_answer(v, 3, ppoly0_coefs(:,1), (/1.,2.,4./),
'PCM: P0')
1769 call plm_reconstruction(3, (/1.,1.,1./), (/1.,3.,5./), ppoly0_e(1:3,:), &
1770 ppoly0_coefs(1:3,:), h_neglect )
1771 remapping_unit_tests = remapping_unit_tests .or. &
1772 test_answer(v, 3, ppoly0_e(:,1), (/1.,2.,5./),
'Unlim PLM: left edges')
1773 remapping_unit_tests = remapping_unit_tests .or. &
1774 test_answer(v, 3, ppoly0_e(:,2), (/1.,4.,5./),
'Unlim PLM: right edges')
1775 remapping_unit_tests = remapping_unit_tests .or. &
1776 test_answer(v, 3, ppoly0_coefs(:,1), (/1.,2.,5./),
'Unlim PLM: P0')
1777 remapping_unit_tests = remapping_unit_tests .or. &
1778 test_answer(v, 3, ppoly0_coefs(:,2), (/0.,2.,0./),
'Unlim PLM: P1')
1780 call plm_reconstruction(3, (/1.,1.,1./), (/1.,2.,7./), ppoly0_e(1:3,:), &
1781 ppoly0_coefs(1:3,:), h_neglect )
1782 remapping_unit_tests = remapping_unit_tests .or. &
1783 test_answer(v, 3, ppoly0_e(:,1), (/1.,1.,7./),
'Left lim PLM: left edges')
1784 remapping_unit_tests = remapping_unit_tests .or. &
1785 test_answer(v, 3, ppoly0_e(:,2), (/1.,3.,7./),
'Left lim PLM: right edges')
1786 remapping_unit_tests = remapping_unit_tests .or. &
1787 test_answer(v, 3, ppoly0_coefs(:,1), (/1.,1.,7./),
'Left lim PLM: P0')
1788 remapping_unit_tests = remapping_unit_tests .or. &
1789 test_answer(v, 3, ppoly0_coefs(:,2), (/0.,2.,0./),
'Left lim PLM: P1')
1791 call plm_reconstruction(3, (/1.,1.,1./), (/1.,6.,7./), ppoly0_e(1:3,:), &
1792 ppoly0_coefs(1:3,:), h_neglect )
1793 remapping_unit_tests = remapping_unit_tests .or. &
1794 test_answer(v, 3, ppoly0_e(:,1), (/1.,5.,7./),
'Right lim PLM: left edges')
1795 remapping_unit_tests = remapping_unit_tests .or. &
1796 test_answer(v, 3, ppoly0_e(:,2), (/1.,7.,7./),
'Right lim PLM: right edges')
1797 remapping_unit_tests = remapping_unit_tests .or. &
1798 test_answer(v, 3, ppoly0_coefs(:,1), (/1.,5.,7./),
'Right lim PLM: P0')
1799 remapping_unit_tests = remapping_unit_tests .or. &
1800 test_answer(v, 3, ppoly0_coefs(:,2), (/0.,2.,0./),
'Right lim PLM: P1')
1802 call plm_reconstruction(3, (/1.,2.,3./), (/1.,4.,9./), ppoly0_e(1:3,:), &
1803 ppoly0_coefs(1:3,:), h_neglect )
1804 remapping_unit_tests = remapping_unit_tests .or. &
1805 test_answer(v, 3, ppoly0_e(:,1), (/1.,2.,9./),
'Non-uniform line PLM: left edges')
1806 remapping_unit_tests = remapping_unit_tests .or. &
1807 test_answer(v, 3, ppoly0_e(:,2), (/1.,6.,9./),
'Non-uniform line PLM: right edges')
1808 remapping_unit_tests = remapping_unit_tests .or. &
1809 test_answer(v, 3, ppoly0_coefs(:,1), (/1.,2.,9./),
'Non-uniform line PLM: P0')
1810 remapping_unit_tests = remapping_unit_tests .or. &
1811 test_answer(v, 3, ppoly0_coefs(:,2), (/0.,4.,0./),
'Non-uniform line PLM: P1')
1813 call edge_values_explicit_h4( 5, (/1.,1.,1.,1.,1./), (/1.,3.,5.,7.,9./), ppoly0_e, &
1814 h_neglect=1e-10, answers_2018=answers_2018 )
1816 thistest = test_answer(v, 5, ppoly0_e(:,1), (/0.,2.,4.,6.,8./),
'Line H4: left edges', tol=8.0e-15)
1817 remapping_unit_tests = remapping_unit_tests .or. thistest
1818 thistest = test_answer(v, 5, ppoly0_e(:,2), (/2.,4.,6.,8.,10./),
'Line H4: right edges', tol=1.0e-14)
1819 remapping_unit_tests = remapping_unit_tests .or. thistest
1820 ppoly0_e(:,1) = (/0.,2.,4.,6.,8./)
1821 ppoly0_e(:,2) = (/2.,4.,6.,8.,10./)
1822 call ppm_reconstruction(5, (/1.,1.,1.,1.,1./), (/1.,3.,5.,7.,9./), ppoly0_e(1:5,:), &
1823 ppoly0_coefs(1:5,:), h_neglect, answers_2018=answers_2018 )
1824 remapping_unit_tests = remapping_unit_tests .or. &
1825 test_answer(v, 5, ppoly0_coefs(:,1), (/1.,2.,4.,6.,9./),
'Line PPM: P0')
1826 remapping_unit_tests = remapping_unit_tests .or. &
1827 test_answer(v, 5, ppoly0_coefs(:,2), (/0.,2.,2.,2.,0./),
'Line PPM: P1')
1828 remapping_unit_tests = remapping_unit_tests .or. &
1829 test_answer(v, 5, ppoly0_coefs(:,3), (/0.,0.,0.,0.,0./),
'Line PPM: P2')
1831 call edge_values_explicit_h4( 5, (/1.,1.,1.,1.,1./), (/1.,1.,7.,19.,37./), ppoly0_e, &
1832 h_neglect=1e-10, answers_2018=answers_2018 )
1834 thistest = test_answer(v, 5, ppoly0_e(:,1), (/3.,0.,3.,12.,27./),
'Parabola H4: left edges', tol=2.7e-14)
1835 remapping_unit_tests = remapping_unit_tests .or. thistest
1836 thistest = test_answer(v, 5, ppoly0_e(:,2), (/0.,3.,12.,27.,48./),
'Parabola H4: right edges', tol=4.8e-14)
1837 remapping_unit_tests = remapping_unit_tests .or. thistest
1838 ppoly0_e(:,1) = (/0.,0.,3.,12.,27./)
1839 ppoly0_e(:,2) = (/0.,3.,12.,27.,48./)
1840 call ppm_reconstruction(5, (/1.,1.,1.,1.,1./), (/0.,1.,7.,19.,37./), ppoly0_e(1:5,:), &
1841 ppoly0_coefs(1:5,:), h_neglect, answers_2018=answers_2018 )
1842 remapping_unit_tests = remapping_unit_tests .or. &
1843 test_answer(v, 5, ppoly0_e(:,1), (/0.,0.,3.,12.,37./),
'Parabola PPM: left edges')
1844 remapping_unit_tests = remapping_unit_tests .or. &
1845 test_answer(v, 5, ppoly0_e(:,2), (/0.,3.,12.,27.,37./),
'Parabola PPM: right edges')
1846 remapping_unit_tests = remapping_unit_tests .or. &
1847 test_answer(v, 5, ppoly0_coefs(:,1), (/0.,0.,3.,12.,37./),
'Parabola PPM: P0')
1848 remapping_unit_tests = remapping_unit_tests .or. &
1849 test_answer(v, 5, ppoly0_coefs(:,2), (/0.,0.,6.,12.,0./),
'Parabola PPM: P1')
1850 remapping_unit_tests = remapping_unit_tests .or. &
1851 test_answer(v, 5, ppoly0_coefs(:,3), (/0.,3.,3.,3.,0./),
'Parabola PPM: P2')
1853 ppoly0_e(:,1) = (/0.,0.,6.,10.,15./)
1854 ppoly0_e(:,2) = (/0.,6.,12.,17.,15./)
1855 call ppm_reconstruction(5, (/1.,1.,1.,1.,1./), (/0.,5.,7.,16.,15./), ppoly0_e(1:5,:), &
1856 ppoly0_coefs(1:5,:), h_neglect, answers_2018=answers_2018 )
1857 remapping_unit_tests = remapping_unit_tests .or. &
1858 test_answer(v, 5, ppoly0_e(:,1), (/0.,3.,6.,16.,15./),
'Limits PPM: left edges')
1859 remapping_unit_tests = remapping_unit_tests .or. &
1860 test_answer(v, 5, ppoly0_e(:,2), (/0.,6.,9.,16.,15./),
'Limits PPM: right edges')
1861 remapping_unit_tests = remapping_unit_tests .or. &
1862 test_answer(v, 5, ppoly0_coefs(:,1), (/0.,3.,6.,16.,15./),
'Limits PPM: P0')
1863 remapping_unit_tests = remapping_unit_tests .or. &
1864 test_answer(v, 5, ppoly0_coefs(:,2), (/0.,6.,0.,0.,0./),
'Limits PPM: P1')
1865 remapping_unit_tests = remapping_unit_tests .or. &
1866 test_answer(v, 5, ppoly0_coefs(:,3), (/0.,-3.,3.,0.,0./),
'Limits PPM: P2')
1868 call plm_reconstruction(4, (/0.,1.,1.,0./), (/5.,4.,2.,1./), ppoly0_e(1:4,:), &
1869 ppoly0_coefs(1:4,:), h_neglect )
1870 remapping_unit_tests = remapping_unit_tests .or. &
1871 test_answer(v, 4, ppoly0_e(1:4,1), (/5.,5.,3.,1./),
'PPM: left edges h=0110')
1872 remapping_unit_tests = remapping_unit_tests .or. &
1873 test_answer(v, 4, ppoly0_e(1:4,2), (/5.,3.,1.,1./),
'PPM: right edges h=0110')
1874 call remap_via_sub_cells( 4, (/0.,1.,1.,0./), (/5.,4.,2.,1./), ppoly0_e(1:4,:), &
1875 ppoly0_coefs(1:4,:), &
1876 2, (/1.,1./), integration_plm, .false., u2, err )
1877 remapping_unit_tests = remapping_unit_tests .or. &
1878 test_answer(v, 2, u2, (/4.,2./),
'PLM: remapped h=0110->h=11')
1880 deallocate(ppoly0_e, ppoly0_s, ppoly0_coefs)
1882 if (.not. remapping_unit_tests)
write(*,*)
'Pass'