!/*****************************************************************************/1! *2! * Elmer, A Finite Element Software for Multiphysical Problems3! *4! * Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland5! *6! * This library is free software; you can redistribute it and/or7! * modify it under the terms of the GNU Lesser General Public8! * License as published by the Free Software Foundation; either9! * version 2.1 of the License, or (at your option) any later version.10! *11! * This library is distributed in the hope that it will be useful,12! * but WITHOUT ANY WARRANTY; without even the implied warranty of13! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14! * Lesser General Public License for more details.15! *16! * You should have received a copy of the GNU Lesser General Public17! * License along with this library (in file ../LGPL-2.1); if not, write18! * to the Free Software Foundation, Inc., 51 Franklin Street,19! * Fifth Floor, Boston, MA 02110-1301 USA20! *21! *****************************************************************************/22!2324#include "huti_fdefs.h"2526!------------------------------------------------------------------------------27!> The normwise relative backward error err = ||b-Ax||/(||A|| ||x|| + ||b||)28!> where ||.|| is the 2-norm29!------------------------------------------------------------------------------30FUNCTION NormwiseBackwardError2( x,b,r,ipar,dpar ) RESULT(err)31!------------------------------------------------------------------------------32USE ParallelUtils3334INTEGER :: ipar(*),n35DOUBLE PRECISION :: x(HUTI_NDIM),b(HUTI_NDIM),r(HUTI_NDIM),dpar(*),err36DOUBLE PRECISION :: res(HUTI_NDIM)3738n = HUTI_NDIM3940IF(ParEnv % PEs>1) THEN41CALL SParMatrixVector(x,res,ipar)42ELSE43CALL CRS_MatrixVectorMultiply(GlobalMatrix,x,res)44END IF45res = res - b(1:n)4647err = SQRT(ParallelReduction(SUM( res(1:n)**2) )) / &48SQRT(ParallelReduction(SUM(GlobalMatrix % Values**2))) * &49SQRT(ParallelReduction(SUM(x(1:n)**2))) + &50SQRT(ParallelReduction((SUM(b(1:n)**2))) )5152!------------------------------------------------------------------------------53END FUNCTION NormwiseBackwardError254!------------------------------------------------------------------------------555657!------------------------------------------------------------------------------58!> The normwise relative backward error err = ||r||/(||A|| ||x|| + ||b||)59!> where ||.|| is the supremum norm and A is assumed to be scaled such that its60!> norm is the unity (setting Linear System Row Equilibration = Logical True).61!> Here the residual r = b - Ax should be known when calling this function.62!------------------------------------------------------------------------------63FUNCTION NormwiseBackwardError( x,b,r,ipar,dpar ) RESULT(err)64!------------------------------------------------------------------------------65USE ParallelUtils6667INTEGER :: ipar(*),n68DOUBLE PRECISION :: x(HUTI_NDIM),b(HUTI_NDIM),r(HUTI_NDIM),dpar(*),err6970n = HUTI_NDIM7172err = ParallelReduction(MAXVAL(ABS(r(1:n))),2) / &73(ParallelReduction(MAXVAL(ABS(x(1:n))),2) + &74ParallelReduction(MAXVAL(ABS(b(1:n))),2))7576!------------------------------------------------------------------------------77END FUNCTION NormwiseBackwardError78!------------------------------------------------------------------------------7980!------------------------------------------------------------------------------81!> The complex-valued version of the normwise relative backward error err =82!> ||r||/(||A|| ||x|| + ||b||) where ||.|| is the supremum norm and A is83!> assumed to be scaled such that its norm is the unity (setting Linear System84!> Row Equilibration = Logical True). Here the residual r = b - Ax should85!> be known when calling this function.86!------------------------------------------------------------------------------87FUNCTION NormwiseBackwardError_Z( x,b,r,ipar,dpar ) RESULT(err)88!------------------------------------------------------------------------------89USE ParallelUtils90IMPLICIT NONE9192DOUBLE COMPLEX :: x(*),b(*),r(*)93INTEGER :: ipar(*)94DOUBLE PRECISION :: dpar(*)95DOUBLE PRECISION :: err9697INTEGER :: n9899! n = HUTI_NDIM100n = ipar(3)101102err = ParallelReduction(MAXVAL(ABS(r(1:n))),2) / &103(ParallelReduction(MAXVAL(ABS(x(1:n))),2) + &104ParallelReduction(MAXVAL(ABS(b(1:n))),2))105!------------------------------------------------------------------------------106END FUNCTION NormwiseBackwardError_Z107!------------------------------------------------------------------------------108109110!------------------------------------------------------------------------------111!> The normwise relative backward error err = ||b-Ax||/(||A|| ||x|| + ||b||)112!> where ||.|| is the supremum norm. The matrix norm of A is computed within113!> this subroutine.114!------------------------------------------------------------------------------115FUNCTION NormwiseBackwardErrorGeneralized( x,b,r,ipar,dpar ) RESULT(err)116!------------------------------------------------------------------------------117USE ParallelUtils118119INTEGER :: ipar(*),n120DOUBLE PRECISION :: x(HUTI_NDIM),b(HUTI_NDIM),r(HUTI_NDIM),dpar(*),err121DOUBLE PRECISION :: res(HUTI_NDIM)122DOUBLE PRECISION :: d(HUTI_NDIM), ANorm123124n = HUTI_NDIM125126d = 1.0d0127res = 0.0d0128IF(ParEnv % PEs>1) THEN129CALL SParABSMatrixVector(d,res,ipar)130ELSE131CALL CRS_ABSMatrixVectorMultiply(GlobalMatrix,d,res)132END IF133ANorm = ParallelReduction(MAXVAL(ABS(res(1:n))),2)134135res = 0.0d0136IF(ParEnv % PEs>1) THEN137CALL SParMatrixVector(x,res,ipar)138ELSE139CALL CRS_MatrixVectorMultiply(GlobalMatrix,x,res)140END IF141res = res - b(1:n)142143err = ParallelReduction(MAXVAL(ABS(res(1:n))),2) / &144(ANorm * ParallelReduction(MAXVAL(ABS(x(1:n))),2) + &145ParallelReduction(MAXVAL(ABS(b(1:n))),2))146147!------------------------------------------------------------------------------148END FUNCTION NormwiseBackwardErrorGeneralized149!------------------------------------------------------------------------------150151152!------------------------------------------------------------------------------153!> The componentwise relative backward error err = max_j{|r|_j /(|A| |x| + |b|)_j}154!> with r the residual r = b-Ax.155!------------------------------------------------------------------------------156FUNCTION ComponentwiseBackwardError( x,b,r,ipar,dpar ) RESULT(err)157!------------------------------------------------------------------------------158USE ParallelUtils159160INTEGER :: ipar(*),n161DOUBLE PRECISION :: x(HUTI_NDIM),b(HUTI_NDIM),r(HUTI_NDIM),dpar(*),err162DOUBLE PRECISION :: d(HUTI_NDIM),res(HUTI_NDIM)163164n = HUTI_NDIM165166IF(ParEnv % PEs>1) THEN167CALL SParMatrixVector(x,res,ipar)168ELSE169CALL CRS_MatrixVectorMultiply(GlobalMatrix,x,res)170END IF171res = res - b(1:n)172173IF(ParEnv % PEs>1) THEN174CALL SParABSMatrixVector(ABS(x),d,ipar)175ELSE176CALL CRS_ABSMatrixVectorMultiply(GlobalMatrix,ABS(x),d)177END IF178179d = d + ABS(b(1:n))180181err = 0.0d0182DO i=1,n183IF ( ABS(d(i)) < AEPS) THEN184IF ( ABS(res(i)) > AEPS ) THEN185err = HUGE(err)186RETURN187ELSE188err = MAX(err,0.0d0)189END IF190ELSE191err = MAX(err,ABS(res(i))/d(i))192END IF193END DO194195err = ParallelReduction(err,2)196!------------------------------------------------------------------------------197END FUNCTION ComponentwiseBackwardError198!------------------------------------------------------------------------------199200201