module huti_aux12!3! *4! * Elmer, A Finite Element Software for Multiphysical Problems5! *6! * Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland7! *8! * This library is free software; you can redistribute it and/or9! * modify it under the terms of the GNU Lesser General Public10! * License as published by the Free Software Foundation; either11! * version 2.1 of the License, or (at your option) any later version.12! *13! * This library is distributed in the hope that it will be useful,14! * but WITHOUT ANY WARRANTY; without even the implied warranty of15! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU16! * Lesser General Public License for more details.17! *18! * You should have received a copy of the GNU Lesser General Public19! * License along with this library (in file ../LGPL-2.1); if not, write20! * to the Free Software Foundation, Inc., 51 Franklin Street,21! * Fifth Floor, Boston, MA 02110-1301 USA22! *23! **************************************************************************/2425! Auxiliary routines for HUTI26!2728#include "huti_fdefs.h"2930contains3132!*************************************************************************33!*************************************************************************34!35! This is a dummy preconditioning routine copying only the vector3637subroutine huti_sdummy_pcondfun ( u, v, ipar )3839implicit none4041real, dimension(*) :: u, v42integer, dimension(*) :: ipar4344integer :: i4546!*************************************************************************4748do i = 1, HUTI_NDIM49u(i) = v(i)50end do5152return5354end subroutine huti_sdummy_pcondfun5556!*************************************************************************5758!*************************************************************************59!*************************************************************************60!61! This routine fills a vector with pseudo random numbers6263subroutine huti_srandvec ( u, ipar )6465implicit none6667real, dimension(*) :: u68integer, dimension(*) :: ipar6970integer :: i71real :: harvest7273!*************************************************************************7475do i = 1, HUTI_NDIM76call random_number( harvest )77u(i) = harvest78end do7980return8182end subroutine huti_srandvec8384!*************************************************************************85!*************************************************************************86!87! Construct LU decomposition of the given matrix and solve LUu = v88!8990subroutine huti_slusolve ( n, lumat, u, v )9192implicit none9394integer :: n95real, dimension(n,n) :: lumat96real, dimension(n) :: u, v9798integer :: i, j, k99100!*************************************************************************101102!103! This is from Saad''s book, Algorithm 10.4104!105106do i = 2,n107do k = 1, i - 1108109! Check for small pivot110111if ( abs(lumat(k,k)) .lt. 1.0e-16 ) then112print *, '(libhuti.a) GMRES: small pivot', lumat(k,k)113end if114115! Compute a_ik = a_ik / a_kk116117lumat(i,k) = lumat(i,k) / lumat(k,k)118119do j = k + 1, n120121! Compute a_ij = a_ij - a_ik * a_kj122123lumat(i,j) = lumat(i,j) - lumat(i,k) * lumat(k,j)124end do125126end do127end do128129! Forward solve, Lu = v130131do i = 1, n132133! Compute u(i) = v(i) - sum L(i,j) u(j)134135u(i) = v(i)136do k = 1, i - 1137u(i) = u(i) - lumat(i,k) * u(k)138end do139end do140141! Backward solve, u = inv(U) u142143do i = n, 1, -1144145! Compute u(i) = u(i) - sum U(i,j) u(j)146147do k = i + 1, n148u(i) = u(i) - lumat(i,k) * u(k)149end do150151! Compute u(i) = u(i) / U(i,i)152153u(i) = u(i) / lumat(i,i)154end do155156return157158end subroutine huti_slusolve159160161!*************************************************************************162!*************************************************************************163!164! This is a dummy preconditioning routine copying only the vector165166subroutine huti_ddummy_pcondfun ( u, v, ipar )167168implicit none169170double precision, dimension(*) :: u, v171integer, dimension(*) :: ipar172173integer :: i174175!*************************************************************************176!$OMP PARALLEL DO177do i = 1, HUTI_NDIM178u(i) = v(i)179end do180!$OMP END PARALLEL DO181182return183184end subroutine huti_ddummy_pcondfun185186!*************************************************************************187188!*************************************************************************189!*************************************************************************190!191! This routine fills a vector with pseudo random numbers192193subroutine huti_drandvec ( u, ipar )194195implicit none196197double precision, dimension(*) :: u198integer, dimension(*) :: ipar199200integer :: i201real :: harvest202203!*************************************************************************204205do i = 1, HUTI_NDIM206call random_number( harvest )207u(i) = harvest208end do209210return211212end subroutine huti_drandvec213214!*************************************************************************215!*************************************************************************216!217! Construct LU decomposition of the given matrix and solve LUu = v218!219220subroutine huti_dlusolve ( n, lumat, u, v )221222implicit none223224integer :: n225double precision, dimension(n,n) :: lumat226double precision, dimension(n) :: u, v227228integer :: i, j, k229230!*************************************************************************231232!233! This is from Saad''s book, Algorithm 10.4234!235236do i = 2,n237do k = 1, i - 1238239! Check for small pivot240241if ( abs(lumat(k,k)) .lt. 1.0e-16 ) then242print *, '(libhuti.a) GMRES: small pivot', lumat(k,k)243end if244245! Compute a_ik = a_ik / a_kk246247lumat(i,k) = lumat(i,k) / lumat(k,k)248249do j = k + 1, n250251! Compute a_ij = a_ij - a_ik * a_kj252253lumat(i,j) = lumat(i,j) - lumat(i,k) * lumat(k,j)254end do255256end do257end do258259! Forward solve, Lu = v260261do i = 1, n262263! Compute u(i) = v(i) - sum L(i,j) u(j)264265u(i) = v(i)266do k = 1, i - 1267u(i) = u(i) - lumat(i,k) * u(k)268end do269end do270271! Backward solve, u = inv(U) u272273do i = n, 1, -1274275! Compute u(i) = u(i) - sum U(i,j) u(j)276277do k = i + 1, n278u(i) = u(i) - lumat(i,k) * u(k)279end do280281! Compute u(i) = u(i) / U(i,i)282283u(i) = u(i) / lumat(i,i)284end do285286return287288end subroutine huti_dlusolve289290291!*************************************************************************292!*************************************************************************293!294! This is a dummy preconditioning routine copying only the vector295296subroutine huti_cdummy_pcondfun ( u, v, ipar )297298implicit none299300complex, dimension(*) :: u, v301integer, dimension(*) :: ipar302303integer :: i304305!*************************************************************************306307do i = 1, HUTI_NDIM308u(i) = v(i)309end do310311return312313end subroutine huti_cdummy_pcondfun314315!*************************************************************************316317!*************************************************************************318!*************************************************************************319!320! This routine fills a vector with pseudo random numbers321322subroutine huti_crandvec ( u, ipar )323324implicit none325326complex, dimension(*) :: u327integer, dimension(*) :: ipar328329integer :: i330real :: harvest331332!*************************************************************************333334do i = 1, HUTI_NDIM335call random_number( harvest )336u(i) = harvest337call random_number( harvest )338u(i) = cmplx( 0, harvest )339end do340341return342343end subroutine huti_crandvec344345!*************************************************************************346!*************************************************************************347!348! Construct LU decomposition of the given matrix and solve LUu = v349!350351subroutine huti_clusolve ( n, lumat, u, v )352353implicit none354355integer :: n356complex, dimension(n,n) :: lumat357complex, dimension(n) :: u, v358359integer :: i, j, k360361!*************************************************************************362363!364! This is from Saad''s book, Algorithm 10.4365!366367do i = 2,n368do k = 1, i - 1369370! Check for small pivot371372if ( abs(lumat(k,k)) .lt. 1.0e-16 ) then373print *, '(libhuti.a) GMRES: small pivot', lumat(k,k)374end if375376! Compute a_ik = a_ik / a_kk377378lumat(i,k) = lumat(i,k) / lumat(k,k)379380do j = k + 1, n381382! Compute a_ij = a_ij - a_ik * a_kj383384lumat(i,j) = lumat(i,j) - lumat(i,k) * lumat(k,j)385end do386387end do388end do389390! Forward solve, Lu = v391392do i = 1, n393394! Compute u(i) = v(i) - sum L(i,j) u(j)395396u(i) = v(i)397do k = 1, i - 1398u(i) = u(i) - lumat(i,k) * u(k)399end do400end do401402! Backward solve, u = inv(U) u403404do i = n, 1, -1405406! Compute u(i) = u(i) - sum U(i,j) u(j)407408do k = i + 1, n409u(i) = u(i) - lumat(i,k) * u(k)410end do411412! Compute u(i) = u(i) / U(i,i)413414u(i) = u(i) / lumat(i,i)415end do416417return418419end subroutine huti_clusolve420421422!*************************************************************************423!*************************************************************************424!425! This is a dummy preconditioning routine copying only the vector426427subroutine huti_zdummy_pcondfun ( u, v, ipar )428429implicit none430431double complex, dimension(*) :: u, v432integer, dimension(*) :: ipar433434integer :: i435436!*************************************************************************437438do i = 1, HUTI_NDIM439u(i) = v(i)440end do441442return443444end subroutine huti_zdummy_pcondfun445446!*************************************************************************447448!*************************************************************************449!*************************************************************************450!451! This routine fills a vector with pseudo random numbers452453subroutine huti_zrandvec ( u, ipar )454455implicit none456457double complex, dimension(*) :: u458integer, dimension(*) :: ipar459460integer :: i461real :: harvest462463!*************************************************************************464465do i = 1, HUTI_NDIM466call random_number( harvest )467u(i) = harvest468call random_number( harvest )469u(i) = cmplx( 0, harvest )470end do471472return473474end subroutine huti_zrandvec475476!*************************************************************************477!*************************************************************************478!479! Construct LU decomposition of the given matrix and solve LUu = v480!481482subroutine huti_zlusolve ( n, lumat, u, v )483484implicit none485486integer :: n487double complex, dimension(n,n) :: lumat488double complex, dimension(n) :: u, v489490integer :: i, j, k491492!*************************************************************************493494!495! This is from Saad''s book, Algorithm 10.4496!497498do i = 2,n499do k = 1, i - 1500501! Check for small pivot502503if ( abs(lumat(k,k)) .lt. 1.0e-16 ) then504print *, '(libhuti.a) GMRES: small pivot', lumat(k,k)505end if506507! Compute a_ik = a_ik / a_kk508509lumat(i,k) = lumat(i,k) / lumat(k,k)510511do j = k + 1, n512513! Compute a_ij = a_ij - a_ik * a_kj514515lumat(i,j) = lumat(i,j) - lumat(i,k) * lumat(k,j)516end do517518end do519end do520521! Forward solve, Lu = v522523do i = 1, n524525! Compute u(i) = v(i) - sum L(i,j) u(j)526527u(i) = v(i)528do k = 1, i - 1529u(i) = u(i) - lumat(i,k) * u(k)530end do531end do532533! Backward solve, u = inv(U) u534535do i = n, 1, -1536537! Compute u(i) = u(i) - sum U(i,j) u(j)538539do k = i + 1, n540u(i) = u(i) - lumat(i,k) * u(k)541end do542543! Compute u(i) = u(i) / U(i,i)544545u(i) = u(i) / lumat(i,i)546end do547548return549550end subroutine huti_zlusolve551552end module huti_aux553554555