Path: blob/devel/elmerice/Solvers/Covarianceutils/CovarianceVectorMultiplySolver.F90
3206 views
!/*****************************************************************************/1! *2! * Elmer/Ice, a glaciological add-on to Elmer3! * http://elmerice.elmerfem.org4! *5! *6! * This program is free software; you can redistribute it and/or7! * modify it under the terms of the GNU General Public License8! * as published by the Free Software Foundation; either version 29! * of the License, or (at your option) any later version.10! *11! * This program 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 the14! * GNU General Public License for more details.15! *16! * You should have received a copy of the GNU General Public License17! * along with this program (in file fem/GPL-2); if not, write to the18! * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,19! * Boston, MA 02110-1301, USA.20! *21! *****************************************************************************/22! ******************************************************************************23! ******************************************************************************24! *25! * Authors: F. Gillet-Chaulet26! * Web: http://elmerice.elmerfem.org27! *28! * Original Date: 24/06/202429! *30! *****************************************************************************31!***********************************************************************************************32! Comput the product of a covariance matrix with a vector33!***********************************************************************************************34!***********************************************************************************************35SUBROUTINE CovarianceVectorMultiplySolver( Model,Solver,dt,TransientSimulation )36!***********************************************************************************************37USE GeneralUtils38USE CovarianceUtils39IMPLICIT NONE40!------------------------------------------------------------------------------41TYPE(Solver_t) :: Solver4243TYPE(Model_t) :: Model44REAL(KIND=dp) :: dt45LOGICAL :: TransientSimulation4647TYPE(ValueList_t), POINTER :: SolverParams4849TYPE(Variable_t), POINTER :: Var50REAL(KIND=dp), POINTER :: Values(:)51INTEGER, POINTER :: Perm(:)52CHARACTER(LEN=MAX_NAME_LEN) :: Varname53INTEGER :: DOFs545556TYPE(Solver_t), POINTER, SAVE :: MSolver,KMSolver57REAL(kind=dp),allocatable,save :: aap(:) ! matrix in packed format58REAL(kind=dp),allocatable,save :: x(:),y(:),norm(:)5960INTEGER,SAVE :: nn61INTEGER, ALLOCATABLE, SAVE :: ActiveNodes(:),InvPerm(:)62INTEGER,SAVE :: PbDim6364CHARACTER(LEN=MAX_NAME_LEN),SAVE :: CovType65REAL(kind=dp),SAVE :: std66REAL(kind=dp) :: sigma267INTEGER :: Op6869LOGICAL, SAVE :: Firsttime=.TRUE.70LOGICAL, SAVE :: Normalize71LOGICAL :: Parallel72LOGICAL :: Found7374CHARACTER(LEN=MAX_NAME_LEN) :: SolverName="Cov.x Solver"7576! check Parallel/Serial77Parallel=(ParEnv % PEs > 1)7879SolverParams => GetSolverParams()8081VarName = ListGetString(SolverParams,"Input Variable",UnFoundFatal=.TRUE.)8283Normalize = ListGetLogical(SolverParams,"Normalize",Found)84IF (.NOT.Found) Normalize=.FALSE.8586Var => VariableGet( Solver % Mesh % Variables,TRIM(VarName), UnFoundFatal=.TRUE. )87Values => Var % Values88Perm => Var % Perm89DOFs = Var % DOFs90IF (DOFS.GT.1) &91CALL FATAL(SolverName,'Sorry 1DOFs variables')9293!! some initialisation94IF (Firsttime) THEN9596CALL GetActiveNodesSet(Solver,nn,ActiveNodes,InvPerm,PbDim)9798!Sanity check99IF (ANY(Perm(ActiveNodes(1:nn)).LT.0)) &100CALL FATAL(SolverName,"Pb with input variable perm")101102!! The covariance type103CovType = ListGetString(SolverParams,"Covariance type",UnFoundFatal=.TRUE.)104std = ListGetConstReal(SolverParams,"standard deviation",UnFoundFatal=.TRUE.)105106SELECT CASE (CovType)107108CASE('diagonal')109CALL INFO(SolverName,"Using diagonal covariance",level=3)110111CASE('full matrix')112CALL INFO(SolverName,"Using full matrix covariance",level=3)113114Op=1115ALLOCATE(aap(nn*(nn+1)/2))116CALL CovarianceInit(Solver,nn,InvPerm,aap,Op,PbDim)117118CASE('diffusion operator')119CALL INFO(SolverName,"Using diffusion operator covariance",level=3)120121CALL CovarianceInit(Solver,MSolver,KMSolver)122123END SELECT124125allocate(x(nn),y(nn))126127IF (Normalize) THEN128allocate(norm(nn))129130!input vector131x(:) = 1._dp132133! C . x134SELECT CASE (CovType)135136CASE('diagonal')137sigma2=std**2138norm(:)=sigma2*x(:)139140CASE('full matrix')141CALL CovarianceVectorMultiply(Solver,nn,aap,x,norm)142143CASE('diffusion operator')144! y = SIGMA C SIGMA . x145CALL CovarianceVectorMultiply(Solver,MSolver,KMSolver,nn,x,norm)146147END SELECT148END IF149150Firsttime=.FALSE.151END IF152153!input vector154x(Solver%Variable%Perm(ActiveNodes(1:nn))) = Values(Perm(ActiveNodes(1:nn)))155156! C . x157SELECT CASE (CovType)158159CASE('diagonal')160sigma2=std**2161y(:)=sigma2*x(:)162163CASE('full matrix')164CALL CovarianceVectorMultiply(Solver,nn,aap,x,y)165166CASE('diffusion operator')167! y = SIGMA C SIGMA . x168CALL CovarianceVectorMultiply(Solver,MSolver,KMSolver,nn,x,y)169170END SELECT171172IF (Normalize) y(:)=y(:)/norm(:)173174Solver % Variable % Values(Solver%Variable%Perm(ActiveNodes(1:nn)))=&175y(Solver%Variable%Perm(ActiveNodes(1:nn)))176177END SUBROUTINE CovarianceVectorMultiplySolver178179180