FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
hecmw_mat_resid_contact.f90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
2 ! Copyright (c) 2019 FrontISTR Commons
3 ! This software is released under the MIT License, see LICENSE.txt
4 !-------------------------------------------------------------------------------
6  use hecmw_util
10  use m_hecmw_comm_f
11  implicit none
12 
13  private
17 
18 contains
19 
20  subroutine hecmw_get_residual_contact(hecMESH, hecMAT, hecLagMAT, r, rlag)
21  implicit none
22  type(hecmwst_local_mesh) :: hecmesh
23  type(hecmwst_matrix) :: hecmat
24  type(hecmwst_matrix_lagrange), intent(in) :: heclagmat
25  real(kind=kreal), intent(out) :: r(:)
26  real(kind=kreal), intent(out) :: rlag(:)
27  real(kind=kreal) :: tcomm, sum
28  integer(kind=kint) :: i, idof, ii, i0, ls, le, l, loc0, ll, j, loc, l0, k
29  integer(kind=kint) :: ndof, npndof
30  !! r = b - K x - Ulag lag
31  !! rlag = blag - Llag x
32  ndof=hecmat%NDOF
33  npndof=hecmat%NP*ndof
34  do i=1,npndof
35  r(i)=0.d0
36  enddo
37  ! r = b - K x
38  tcomm = 0.d0
39  call hecmw_matresid(hecmesh, hecmat, hecmat%X, hecmat%B, r, tcomm)
40  if (heclagmat%num_lagrange > 0) then
41  ! r = r - Ulag lag
42  do i=1,hecmat%N
43  i0=(i-1)*ndof
44  do idof=1,ndof
45  ii=i0+idof
46  ls=heclagmat%indexU_lagrange(i-1)+1
47  le=heclagmat%indexU_lagrange(i)
48  sum=0.d0
49  do l=ls,le
50  loc=(l-1)*ndof+idof
51  ll=heclagmat%itemU_lagrange(l)
52  !sum=sum+hecLagMAT%AU_lagrange(loc)*hecLagMAT%Lagrange(ll)
53  sum=sum+heclagmat%AU_lagrange(loc)*hecmat%X(npndof+ll)
54  enddo
55  r(ii)=r(ii)-sum
56  enddo
57  enddo
58  ! rlag = blag - Llag x
59  do i=1,heclagmat%num_lagrange
60  ls=heclagmat%indexL_lagrange(i-1)+1
61  le=heclagmat%indexL_lagrange(i)
62  sum=0.d0
63  do l=ls,le
64  loc0=(l-1)*ndof
65  j=heclagmat%itemL_lagrange(l)
66  l0=(j-1)*ndof
67  do k=1,ndof
68  loc=loc0+k
69  ll=l0+k
70  sum=sum+heclagmat%AL_lagrange(loc)*hecmat%X(ll)
71  enddo
72  enddo
73  rlag(i)=hecmat%B(npndof+i)-sum
74  enddo
75  end if
76  end subroutine hecmw_get_residual_contact
77 
79  function hecmw_get_rel_resid_l2_contact(hecMESH, hecMAT, hecLagMAT)
80  implicit none
82  type(hecmwst_local_mesh) :: hecmesh
83  type(hecmwst_matrix) :: hecmat
84  type(hecmwst_matrix_lagrange), intent(in) :: heclagmat
85  real(kind=kreal), allocatable :: r(:)
86  real(kind=kreal), allocatable :: rlag(:)
87  real(kind=kreal) :: bnorm2, rnorm2
88  real(kind=kreal) :: rlagnorm2
89  real(kind=kreal) :: tcomm
90  integer(kind=kint) :: i
91  allocate(r(hecmat%NDOF*hecmat%NP),rlag(heclagmat%num_lagrange))
92  ! |b|^2
93  call hecmw_innerproduct_r(hecmesh, hecmat%NDOF, hecmat%B, hecmat%B, bnorm2, tcomm)
94  call hecmw_get_residual_contact(hecmesh, hecmat, heclagmat, r, rlag)
95  ! |r|^2
96  call hecmw_innerproduct_r(hecmesh, hecmat%NDOF, r, r, rnorm2, tcomm)
97  ! |rlag|^2
98  rlagnorm2=0.d0
99  do i=1,heclagmat%num_lagrange
100  rlagnorm2=rlagnorm2+rlag(i)*rlag(i)
101  enddo
102  deallocate(r,rlag)
103  call hecmw_allreduce_r1(hecmesh, rlagnorm2, hecmw_sum)
104  ! |r_total|^2 = |r|^2 + |rlag|^2
105  if (heclagmat%num_lagrange > 0) rnorm2=rnorm2+rlagnorm2
106  ! |r_total| / |b|
107  hecmw_get_rel_resid_l2_contact = sqrt(rnorm2 / bnorm2)
108  end function hecmw_get_rel_resid_l2_contact
109 
111  function hecmw_get_resid_max_contact(hecMESH, hecMAT, hecLagMAT)
112  implicit none
113  real(kind=kreal) :: hecmw_get_resid_max_contact
114  type(hecmwst_local_mesh) :: hecmesh
115  type(hecmwst_matrix) :: hecmat
116  type(hecmwst_matrix_lagrange), intent(in) :: heclagmat
117  real(kind=kreal), allocatable :: r(:)
118  real(kind=kreal), allocatable :: rlag(:)
119  real(kind=kreal) :: rmax, rlagmax
120  real(kind=kreal) :: tcomm
121  allocate(r(hecmat%NDOF*hecmat%NP),rlag(heclagmat%num_lagrange))
122  call hecmw_get_residual_contact(hecmesh, hecmat, heclagmat, r, rlag)
123  rmax = maxval(dabs(r))
124  if (heclagmat%num_lagrange > 0) then
125  rlagmax = maxval(dabs(rlag))
126  if (rlagmax > rmax) rmax = rlagmax
127  endif
128  deallocate(r,rlag)
129  call hecmw_allreduce_r1(hecmesh, rmax, hecmw_max)
131  end function hecmw_get_resid_max_contact
132 
133 end module m_hecmw_mat_resid_contact
hecmw_util::hecmw_max
integer(kind=kint), parameter hecmw_max
Definition: hecmw_util_f.F90:25
m_hecmw_mat_resid_contact
Definition: hecmw_mat_resid_contact.f90:5
m_hecmw_mat_resid_contact::hecmw_get_residual_contact
subroutine, public hecmw_get_residual_contact(hecMESH, hecMAT, hecLagMAT, r, rlag)
Definition: hecmw_mat_resid_contact.f90:21
hecmw_util::hecmw_sum
integer(kind=kint), parameter hecmw_sum
Definition: hecmw_util_f.F90:23
hecmw_solver_las
Definition: hecmw_solver_las.f90:6
m_hecmw_mat_resid_contact::hecmw_get_resid_max_contact
real(kind=kreal) function, public hecmw_get_resid_max_contact(hecMESH, hecMAT, hecLagMAT)
This function calculates maximum residual.
Definition: hecmw_mat_resid_contact.f90:112
hecmw_solver_las::hecmw_matresid
subroutine, public hecmw_matresid(hecMESH, hecMAT, X, B, R, COMMtime)
Definition: hecmw_solver_las.f90:95
hecmw_solver_misc::hecmw_innerproduct_r
subroutine hecmw_innerproduct_r(hecMESH, ndof, X, Y, sum, COMMtime)
Definition: hecmw_solver_misc.f90:47
hecmw_util
I/O and Utility.
Definition: hecmw_util_f.F90:7
hecmw_util::hecmwst_local_mesh
Definition: hecmw_util_f.F90:234
m_hecmw_comm_f::hecmw_allreduce_r1
subroutine hecmw_allreduce_r1(hecMESH, s, ntag)
Definition: hecmw_comm_f.F90:403
m_hecmw_comm_f
Definition: hecmw_comm_f.F90:6
hecmw_util::kreal
integer(kind=4), parameter kreal
Definition: hecmw_util_f.F90:16
hecmw_matrix_misc
Definition: hecmw_matrix_misc.f90:6
hecmw_solver_misc
Definition: hecmw_solver_misc.f90:6
hecmw_util::hecmwst_matrix_lagrange
Structure for Lagrange multiplier-related part of stiffness matrix (Lagrange multiplier-related matri...
Definition: hecmw_util_f.F90:427
hecmw_util::hecmwst_matrix
Definition: hecmw_util_f.F90:444
m_hecmw_mat_resid_contact::hecmw_get_rel_resid_l2_contact
real(kind=kreal) function, public hecmw_get_rel_resid_l2_contact(hecMESH, hecMAT, hecLagMAT)
This function calculates relative L2 residual.
Definition: hecmw_mat_resid_contact.f90:80