1*1e99f302SBen Matthews! This software is Copyright (c) 2012-2015 The Regents of the 2*1e99f302SBen Matthews! University of California. All Rights Reserved. 3*1e99f302SBen Matthews! 4*1e99f302SBen Matthews! Permission to copy and modify this software and its documentation 5*1e99f302SBen Matthews! for educational, research and non-profit purposes, without fee, 6*1e99f302SBen Matthews! and without a written agreement is hereby granted, provided that 7*1e99f302SBen Matthews! the above copyright notice, this paragraph and the following three 8*1e99f302SBen Matthews! paragraphs appear in all copies. 9*1e99f302SBen Matthews! 10*1e99f302SBen Matthews! Permission to make commercial use of this software may be obtained 11*1e99f302SBen Matthews! by contacting: 12*1e99f302SBen Matthews! 13*1e99f302SBen Matthews! Technology Transfer Office 14*1e99f302SBen Matthews! 9500 Gilman Drive, Mail Code 0910 15*1e99f302SBen Matthews! University of California 16*1e99f302SBen Matthews! La Jolla, CA 92093-0910 17*1e99f302SBen Matthews! (858) 534-5815 18*1e99f302SBen Matthews! invent@ucsd.edu 19*1e99f302SBen Matthews! 20*1e99f302SBen Matthews! This software program and documentation are copyrighted by The 21*1e99f302SBen Matthews! Regents of the University of California. The software program and 22*1e99f302SBen Matthews! documentation are supplied "as is", without any accompanying 23*1e99f302SBen Matthews! services from The Regents. The Regents does not warrant that the 24*1e99f302SBen Matthews! operation of the program will be uninterrupted or error-free. The 25*1e99f302SBen Matthews! end-user understands that the program was developed for research 26*1e99f302SBen Matthews! purposes and is advised not to rely exclusively on the program for 27*1e99f302SBen Matthews! any reason. 28*1e99f302SBen Matthews! 29*1e99f302SBen Matthews! IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY 30*1e99f302SBen Matthews! PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL 31*1e99f302SBen Matthews! DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS 32*1e99f302SBen Matthews! SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF 33*1e99f302SBen Matthews! CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34*1e99f302SBen Matthews! THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY 35*1e99f302SBen Matthews! WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 36*1e99f302SBen Matthews! OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE 37*1e99f302SBen Matthews! SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE 38*1e99f302SBen Matthews! UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE 39*1e99f302SBen Matthews! MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 40*1e99f302SBen Matthews 41*1e99f302SBen Matthews FUNCTION NORMV(dof, nNo, commu, U) 42*1e99f302SBen Matthews 43*1e99f302SBen Matthews INCLUDE "svLS_STD.h" 44*1e99f302SBen Matthews 45*1e99f302SBen Matthews INTEGER, INTENT(IN) :: dof, nNo 46*1e99f302SBen Matthews TYPE(svLS_commuType), INTENT(IN) :: commu 47*1e99f302SBen Matthews REAL*8, INTENT(IN) :: U(dof,nNo) 48*1e99f302SBen Matthews 49*1e99f302SBen Matthews INTEGER i, ierr 50*1e99f302SBen Matthews REAL*8 tmp, NORMV 51*1e99f302SBen Matthews 52*1e99f302SBen Matthews NORMV = 0D0 53*1e99f302SBen Matthews SELECT CASE(dof) 54*1e99f302SBen Matthews CASE(1) 55*1e99f302SBen Matthews DO i=1, nNo 56*1e99f302SBen Matthews NORMV = NORMV + U(1,i)*U(1,i) 57*1e99f302SBen Matthews END DO 58*1e99f302SBen Matthews CASE(2) 59*1e99f302SBen Matthews DO i=1, nNo 60*1e99f302SBen Matthews NORMV = NORMV + U(1,i)*U(1,i) + U(2,i)*U(2,i) 61*1e99f302SBen Matthews END DO 62*1e99f302SBen Matthews CASE(3) 63*1e99f302SBen Matthews DO i=1, nNo 64*1e99f302SBen Matthews NORMV = NORMV+ U(1,i)*U(1,i) + U(2,i)*U(2,i) + U(3,i)*U(3,i) 65*1e99f302SBen Matthews END DO 66*1e99f302SBen Matthews CASE(4) 67*1e99f302SBen Matthews DO i=1, nNo 68*1e99f302SBen Matthews NORMV = NORMV + U(1,i)*U(1,i) + U(2,i)*U(2,i) 69*1e99f302SBen Matthews 2 + U(3,i)*U(3,i) + U(4,i)*U(4,i) 70*1e99f302SBen Matthews END DO 71*1e99f302SBen Matthews CASE DEFAULT 72*1e99f302SBen Matthews DO i=1, nNo 73*1e99f302SBen Matthews NORMV = NORMV + SUM(U(:,i)*U(:,i)) 74*1e99f302SBen Matthews END DO 75*1e99f302SBen Matthews END SELECT 76*1e99f302SBen Matthews 77*1e99f302SBen Matthews IF (commu%nTasks .NE. 1) THEN 78*1e99f302SBen Matthews CALL MPI_ALLREDUCE(NORMV, tmp, 1, mpreal, MPI_SUM, 79*1e99f302SBen Matthews 2 commu%comm, ierr) 80*1e99f302SBen Matthews NORMV = tmp 81*1e99f302SBen Matthews END IF 82*1e99f302SBen Matthews 83*1e99f302SBen Matthews NORMV = SQRT(NORMV) 84*1e99f302SBen Matthews 85*1e99f302SBen Matthews RETURN 86*1e99f302SBen Matthews END FUNCTION NORMV 87*1e99f302SBen Matthews 88*1e99f302SBen Matthews!==================================================================== 89*1e99f302SBen Matthews 90*1e99f302SBen Matthews FUNCTION NORMS(nNo, commu, U) 91*1e99f302SBen Matthews 92*1e99f302SBen Matthews INCLUDE "svLS_STD.h" 93*1e99f302SBen Matthews 94*1e99f302SBen Matthews INTEGER, INTENT(IN) :: nNo 95*1e99f302SBen Matthews TYPE(svLS_commuType), INTENT(IN) :: commu 96*1e99f302SBen Matthews REAL*8, INTENT(IN) :: U(nNo) 97*1e99f302SBen Matthews 98*1e99f302SBen Matthews INTEGER i, ierr 99*1e99f302SBen Matthews REAL*8 tmp, NORMS 100*1e99f302SBen Matthews 101*1e99f302SBen Matthews NORMS = 0D0 102*1e99f302SBen Matthews DO i=1, nNo 103*1e99f302SBen Matthews NORMS = NORMS + U(i)*U(i) 104*1e99f302SBen Matthews END DO 105*1e99f302SBen Matthews 106*1e99f302SBen Matthews IF (commu%nTasks .NE. 1) THEN 107*1e99f302SBen Matthews CALL MPI_ALLREDUCE(NORMS, tmp, 1, mpreal, MPI_SUM, 108*1e99f302SBen Matthews 2 commu%comm, ierr) 109*1e99f302SBen Matthews NORMS = tmp 110*1e99f302SBen Matthews END IF 111*1e99f302SBen Matthews 112*1e99f302SBen Matthews NORMS = SQRT(NORMS) 113*1e99f302SBen Matthews 114*1e99f302SBen Matthews RETURN 115*1e99f302SBen Matthews END FUNCTION NORMS 116*1e99f302SBen Matthews 117*1e99f302SBen Matthews 118