testSparse_prg Program

program~~testsparse_prg~~UsesGraph program~testsparse_prg testSparse_prg module~array_mod array_mod module~array_mod->program~testsparse_prg module~plplotlib_mod plplotlib_mod module~array_mod->module~plplotlib_mod module~sparse_mod sparse_mod module~array_mod->module~sparse_mod module~plplotlib_mod->program~testsparse_prg module~solvers_mod solvers_mod module~solvers_mod->program~testsparse_prg module~basicsolvers_mod basicSolvers_mod module~basicsolvers_mod->program~testsparse_prg module~sparse_mod->program~testsparse_prg module~sparse_mod->module~solvers_mod module~sparse_mod->module~basicsolvers_mod module~kinds_mod kinds_mod module~kinds_mod->program~testsparse_prg module~kinds_mod->module~array_mod module~kinds_mod->module~plplotlib_mod module~kinds_mod->module~solvers_mod module~kinds_mod->module~basicsolvers_mod module~kinds_mod->module~sparse_mod module~text_mod text_mod module~kinds_mod->module~text_mod module~time_mod time_mod module~kinds_mod->module~time_mod plplot plplot plplot->module~plplotlib_mod module~text_mod->module~plplotlib_mod module~text_mod->module~solvers_mod module~text_mod->module~basicsolvers_mod module~time_mod->module~solvers_mod module~time_mod->module~text_mod iso_fortran_env iso_fortran_env iso_fortran_env->module~text_mod iso_c_binding iso_c_binding iso_c_binding->module~time_mod
Help


Calls

program~~testsparse_prg~~CallsGraph program~testsparse_prg testSparse_prg proc~testnewsparse testNewSparse program~testsparse_prg->proc~testnewsparse proc~testbasicsolvers testBasicSolvers program~testsparse_prg->proc~testbasicsolvers proc~setup setup program~testsparse_prg->proc~setup proc~testspvec testSpvec program~testsparse_prg->proc~testspvec proc~testsolvers testSolvers program~testsparse_prg->proc~testsolvers proc~show show program~testsparse_prg->proc~show proc~newsparse newSparse proc~testnewsparse->proc~newsparse proc~testbasicsolvers->proc~newsparse proc~conjugategradient conjugateGradient proc~testbasicsolvers->proc~conjugategradient proc~subplot subplot proc~testbasicsolvers->proc~subplot proc~linspace linspace proc~testbasicsolvers->proc~linspace proc~xylim xylim proc~testbasicsolvers->proc~xylim proc~successiveoverrelaxation successiveOverRelaxation proc~testbasicsolvers->proc~successiveoverrelaxation proc~biconjugategradientstabilized biConjugateGradientStabilized proc~testbasicsolvers->proc~biconjugategradientstabilized proc~ticks ticks proc~testbasicsolvers->proc~ticks proc~figure figure proc~testbasicsolvers->proc~figure interface~span span proc~testbasicsolvers->interface~span interface~mixval mixval proc~testbasicsolvers->interface~mixval proc~labels labels proc~testbasicsolvers->proc~labels proc~plot plot proc~testbasicsolvers->proc~plot plsfnam plsfnam proc~setup->plsfnam plsetopt plsetopt proc~setup->plsetopt plsfam plsfam proc~setup->plsfam plfontld plfontld proc~setup->plfontld plinit plinit proc~setup->plinit plsdev plsdev proc~setup->plsdev proc~testsolvers->proc~newsparse proc~testsolvers->proc~subplot proc~testsolvers->proc~linspace proc~testsolvers->proc~xylim proc~testsolvers->proc~ticks proc~testsolvers->proc~figure proc~testsolvers->interface~span proc~testsolvers->interface~mixval proc~testsolvers->proc~labels proc~testsolvers->proc~plot sor_t sor_t proc~testsolvers->sor_t conjugategradient_t conjugategradient_t proc~testsolvers->conjugategradient_t bicgstab_t bicgstab_t proc~testsolvers->bicgstab_t gaussseidel_t gaussseidel_t proc~testsolvers->gaussseidel_t plend plend proc~show->plend proc~newspvec newSpvec proc~newsparse->proc~newspvec proc~startreport startReport proc~conjugategradient->proc~startreport proc~solverprogress solverProgress proc~conjugategradient->proc~solverprogress pladv pladv proc~subplot->pladv plvasp plvasp proc~subplot->plvasp plssub plssub proc~subplot->plssub plvpor plvpor proc~subplot->plvpor plvsta plvsta proc~subplot->plvsta plwind plwind proc~xylim->plwind proc~successiveoverrelaxation->proc~startreport proc~successiveoverrelaxation->proc~solverprogress proc~biconjugategradientstabilized->proc~startreport proc~biconjugategradientstabilized->proc~solverprogress plbox plbox proc~ticks->plbox proc~figure->pladv proc~figure->plssub plbop plbop proc~figure->plbop pleop pleop proc~figure->pleop pllab pllab proc~labels->pllab plline plline proc~plot->plline plptex plptex proc~plot->plptex plssym plssym proc~plot->plssym proc~showprogress showProgress proc~startreport->proc~showprogress proc~solverprogress->proc~showprogress proc~walltime wallTime proc~showprogress->proc~walltime proc~realtochar realToChar proc~showprogress->proc~realtochar proc~colormap colorMap proc~showprogress->proc~colormap proc~realtotime realToTime proc~showprogress->proc~realtotime proc~colorize colorize proc~showprogress->proc~colorize proc~inttochar intToChar proc~realtotime->proc~inttochar proc~colorize->proc~inttochar
Help

Source Code


Subroutines

subroutine testNewSparse()

Arguments

None

subroutine testSpvec()

Arguments

None

subroutine testBasicSolvers()

Arguments

None

subroutine testSolvers()

Arguments

None

Source Code

program testSparse_prg
	use kinds_mod
	use sparse_mod
	use basicSolvers_mod
	use solvers_mod
	use array_mod
	use plplotlib_mod
	implicit none
	
	call setup(fileName='testsSparse-%n.svg',figSize=[400,300])
	call testNewSparse
	call testSpvec
	call testBasicSolvers
	call testSolvers
	call show()
	
contains

	subroutine testNewSparse
		type(sparse_t)::A
		integer::N,M
		
		N = 3
		M = 5
		
		A = newSparse(N,M)
	end subroutine testNewSparse

	subroutine testSpvec
		type(spvec_t)::u,v,r
		
		u%i = [1,2,3]
		u%v = [1.0_wp,2.0_wp,3.0_wp]
		
		v%i = [2,3,4]
		v%v = [2.0_wp,3.0_wp,4.0_wp]
		
		write(*,*) u.o.v
		
		r = u+v
		write(*,*) r%i
		write(*,*) r%v
		
		r = 2.0_wp*u*2.0_wp
		write(*,*) r%i
		write(*,*) r%v
	end subroutine testSpvec

	subroutine testBasicSolvers
		real(wp),parameter::Tl  = 0.0_wp
		real(wp),parameter::Tr  = 1.0_wp
		real(wp),parameter::k   = 1.0_wp
		real(wp),parameter::q0  = 10.0_wp
		real(wp),parameter::tol = 1.0E-8_wp
		
		real(wp)::Ap,Ae,Aw,dx
		type(sparse_t)::A
		real(wp),dimension(:),allocatable::x,q
		real(wp),dimension(:),allocatable::T1,T2,T3
		integer::N,i,s
		
		N  = 1000
		s  = N/30
		allocate(x(0:N+1))
		x  = linspace(0.0_wp,1.0_wp,N+2)
		q  = [( q0     , i=1,N )]
		A  = newSparse(N,N)
		
		allocate(T1(0:N+1))
		allocate(T2(0:N+1))
		allocate(T3(0:N+1))
		
		T1(0)   = Tl
		T1(N+1) = Tr
		
		T2(0)   = Tl
		T2(N+1) = Tr
		
		T3(0)   = Tl
		T3(N+1) = Tr
		
		dx = x(2)-x(1)
		
		i = 1
		Ae = k/dx**2
		Aw = k/dx**2
		Ap = Ae+Aw
		call A%set(i,i  , Ap)
		call A%set(i,i+1,-Ae)
		q(i) = q(i)+Aw*Tl
		do i=2,N-1
			Ae = k/dx**2
			Aw = k/dx**2
			Ap = Ae+Aw
			call A%set(i,i-1,-Aw)
			call A%set(i,i  , Ap)
			call A%set(i,i+1,-Ae)
		end do
		i = N
		Ae = k/dx**2
		Aw = k/dx**2
		Ap = Ae+Aw
		call A%set(i,i-1,-Aw)
		call A%set(i,i  , Ap)
		q(i) = q(i)+Ae*Tr
		
		T1(1:N) = biConjugateGradientStabilized(A,q)
		T2(1:N) = conjugateGradient(A,q)
		T3(1:N) = successiveOverRelaxation(A,q,1.995_wp)
		
		
		call figure()
		call subplot(1,1,1)
		call xylim(mixval(x),mixval(T1)+[0.0_wp,0.05_wp]*span(T1))
		call plot(x(::s),T1(::s),lineStyle='-',lineColor='r',markStyle='x',markColor='r')
		call plot(x(::s),T2(::s),lineStyle='-',lineColor='b',markStyle='o',markColor='b')
		call plot(x(::s),T3(::s),lineStyle='-',lineColor='c',markStyle='s',markColor='c')
		call ticks()
		call labels('Position #fix#fn','Temperature #fiT#fn','1D Heat Conduction with Generation')
		
	end subroutine testBasicSolvers

	subroutine testSolvers
		real(wp),parameter::Tl  = 0.0_wp
		real(wp),parameter::Tr  = 1.0_wp
		real(wp),parameter::k   = 1.0_wp
		real(wp),parameter::q0  = 10.0_wp
		real(wp),parameter::tol = 1.0E-8_wp
		
		real(wp)::Ap,Ae,Aw,dx
		type(sparse_t)::A
		class(solver_t),allocatable::solver
		real(wp),dimension(:),allocatable::x,q
		real(wp),dimension(:),allocatable::T1
		integer::N,i,s
		
		N  = 100
		s  = N/30
		allocate(x(0:N+1))
		x  = linspace(0.0_wp,1.0_wp,N+2)
		q  = [( q0     , i=1,N )]
		A  = newSparse(N,N)
		
		allocate(T1(0:N+1))
		
		T1(0)   = Tl
		T1(N+1) = Tr
		
		dx = x(2)-x(1)
		
		i = 1
		Ae = k/dx**2
		Aw = k/dx**2
		Ap = Ae+Aw
		call A%set(i,i  , Ap)
		call A%set(i,i+1,-Ae)
		q(i) = q(i)+Aw*Tl
		do i=2,N-1
			Ae = k/dx**2
			Aw = k/dx**2
			Ap = Ae+Aw
			call A%set(i,i-1,-Aw)
			call A%set(i,i  , Ap)
			call A%set(i,i+1,-Ae)
		end do
		i = N
		Ae = k/dx**2
		Aw = k/dx**2
		Ap = Ae+Aw
		call A%set(i,i-1,-Aw)
		call A%set(i,i  , Ap)
		q(i) = q(i)+Ae*Tr
		
		allocate(solver,source=jacobi_t())
		call solver%setup(A)
		T1(1:N) = solver%solve(A,q)
		deallocate(solver)
		
		allocate(solver,source=gaussSeidel_t())
		call solver%setup(A)
		T1(1:N) = solver%solve(A,q)
		deallocate(solver)
		
		allocate(solver,source=SOR_t(1.99_wp))
		call solver%setup(A)
		T1(1:N) = solver%solve(A,q)
		deallocate(solver)
		
		allocate(solver,source=conjugateGradient_t())
		call solver%setup(A)
		T1(1:N) = solver%solve(A,q)
		deallocate(solver)
		
		allocate(solver,source=biCGSTAB_t())
		call solver%setup(A)
		T1(1:N) = solver%solve(A,q)
		deallocate(solver)
		
		call figure()
		call subplot(1,1,1)
		call xylim(mixval(x),mixval(T1)+[0.0_wp,0.05_wp]*span(T1))
		call plot(x(::s),T1(::s),lineStyle='-',lineColor='k',markStyle='x',markColor='r')
		call ticks()
		call labels('Position #fix#fn','Temperature #fiT#fn','1D Heat Conduction with Generation')
		
	end subroutine testSolvers

end program testSparse_prg