Skip to content

Commit

Permalink
Added some limit checks to be on the safe side.
Browse files Browse the repository at this point in the history
  • Loading branch information
raback committed Oct 25, 2024
1 parent 7daef97 commit 3da4fb1
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions fem/src/modules/SaveData/SaveProjection.F90
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ SUBROUTINE SaveProjection( Model,Solver,dt,Transient )
END DO
NoVar = i-1
CALL Info('SaveProjection','Saving projections from '//I2S(NoVar)//' fields')
IF(NoVar==0) RETURN

Nrm = 0.0_dp
DO i=1,NoVar
VarName = ListGetString( Params,'Variable '//I2S(i), Found )
Var => VariableGet( Model % Variables, TRIM(VarName) )
Var => VariableGet( Model % Variables, TRIM(VarName), ThisOnly = .TRUE.)
CALL info('SaveProjection','Doing variable: '//TRIM(VarName),Level=8)

TargetName = ListGetString( Params,'Target Variable '//I2S(i), Found )
Expand All @@ -120,7 +121,7 @@ SUBROUTINE SaveProjection( Model,Solver,dt,Transient )
ToSlave = ListGetLogical( Params,'Project To Slave '//I2S(i),Found )
ToMaster = ListGetLogical( Params,'Project To Master '//I2S(i),Found )

TargetVar => VariableGet( Model % Variables, TRIM(TargetName) )
TargetVar => VariableGet( Model % Variables, TRIM(TargetName), ThisOnly = .TRUE.)
IF(.NOT. ASSOCIATED(TargetVar)) THEN
IF(.NOT. ASSOCIATED(Var % Perm) ) THEN
UnitPerm => NULL()
Expand All @@ -143,7 +144,7 @@ SUBROUTINE SaveProjection( Model,Solver,dt,Transient )
CALL ProjectToVariable()
Nrm = Nrm + SUM(TargetVar % Values**2)
END DO

Nrm = SQRT(Nrm)
IF(SIZE(Solver % Variable % Values) == 1 ) THEN
Solver % Variable % Values = Nrm
Expand All @@ -157,7 +158,7 @@ SUBROUTINE SaveProjection( Model,Solver,dt,Transient )

SUBROUTINE ProjectToVariable()
TYPE(Matrix_t), POINTER :: A
INTEGER :: bc, dofs, i, j, k, pi, pj
INTEGER :: bc, dofs, i, j, k, pi, pj, m
INTEGER, POINTER :: Rows(:), Cols(:)
LOGICAL :: acti, actj, AddThis
REAL(KIND=dp) :: r1
Expand Down Expand Up @@ -200,27 +201,34 @@ SUBROUTINE ProjectToVariable()
END IF

! Create table telling which is slave/master dof.
ALLOCATE(IsInvInvPerm(MAXVAL(Cols)))
m = MAXVAL(Cols)
ALLOCATE(IsInvInvPerm(m))
IsInvInvPerm = .FALSE.
DO i=1,n
pi = A % InvPerm(i)
IF(pi > 0 ) IsInvInvPerm(pi) = .TRUE.
IF(pi > 0 .AND. pi <= m) IsInvInvPerm(pi) = .TRUE.
END DO


DO k=1,dofs
DO i=1,n
pi = A % InvPerm(i)
IF(pi == 0) CYCLE
IF(pi == 0 .OR. pi > m) CYCLE
acti = IsInvInvPerm(pi)
IF(ASSOCIATED(Var % Perm)) pi = Var % Perm(pi)
IF(pi==0) CYCLE
IF(ASSOCIATED(Var % Perm)) THEN
IF(pi > SIZE(Var % Perm)) CYCLE
pi = Var % Perm(pi)
IF(pi==0) CYCLE
END IF
pi = dofs*(pi-1)+k
r1 = 0.0_dp
DO j=Rows(i),Rows(i+1)-1
pj = Cols(j)
IF(ASSOCIATED(Var % Perm)) pj = Var % Perm(pj)
IF(pj==0) CYCLE
IF(ASSOCIATED(Var % Perm)) THEN
IF(pj > SIZE(Var % Perm)) CYCLE
pj = Var % Perm(pj)
IF(pj==0) CYCLE
END IF
pj = dofs*(pj-1)+k
actj = IsInvInvPerm(Cols(j))

Expand Down

0 comments on commit 3da4fb1

Please sign in to comment.