20 real(kind=kreal),
intent(in) :: xyz(3)
21 integer,
intent(in) :: etype
22 integer,
intent(in) :: nn
23 real(kind=kreal),
intent(in) :: elemt(:,:)
24 real(kind=kreal),
intent(in) :: reflen
26 logical,
intent(out) :: isin
27 real(kind=kreal),
intent(in) :: distclr
28 real(kind=kreal),
optional :: ctpos(2)
29 real(kind=kreal),
optional :: localclr
31 integer :: count,order, initstate
32 real(kind=kreal) :: determ, inverse(2,2)
33 real(kind=kreal) :: sfunc(nn), curv(3,2,2)
34 real(kind=kreal) :: r(2), dr(2), r_tmp(2)
35 real(kind=kreal) :: xyz_out(3)
36 real(kind=kreal) :: dist_last,dist_now, dxyz(3)
37 real(kind=kreal) :: tangent(3,2)
38 real(kind=kreal) :: df(2),d2f(2,2),normal(3)
39 real(kind=kreal),
parameter :: eps = 1.0d-8
40 real(kind=kreal) :: clr, tol, factor
42 initstate = cstate%state
44 if(
present( localclr ) ) clr=localclr
45 if(
present( ctpos ) )
then
54 xyz_out = matmul( elemt(1:3,1:nn), sfunc )
55 dxyz(1:3) = xyz_out(1:3) - xyz(1:3)
56 dist_last = dot_product( dxyz, dxyz(:) )
58 call tangentbase( etype, nn, r, elemt(1:3,1:nn), tangent )
59 call curvature( etype, nn, r, elemt(1:3,1:nn), curv )
62 df(1:2) = -matmul( dxyz(:), tangent(:,:) )
64 d2f(1,1)= dot_product( tangent(:,1), tangent(:,1) ) - dot_product( dxyz, curv(:,1,1) )
65 d2f(1,2)= dot_product( tangent(:,1), tangent(:,2) ) - dot_product( dxyz, curv(:,1,2) )
66 d2f(2,1)= dot_product( tangent(:,2), tangent(:,1) ) - dot_product( dxyz, curv(:,2,1) )
67 d2f(2,2)= dot_product( tangent(:,2), tangent(:,2) ) - dot_product( dxyz, curv(:,2,2) )
70 determ = d2f(1,1)*d2f(2,2) - d2f(1,2)*d2f(2,1)
71 if( determ==0.d0 ) stop
"Math error in contact searching"
72 inverse(1,1) = d2f(2,2) / determ
73 inverse(2,2) = d2f(1,1) / determ
74 inverse(1,2) = -d2f(1,2) / determ
75 inverse(2,1) = -d2f(2,1) / determ
78 tol=dot_product(dr,dr)
79 if( dsqrt(tol)> 3.d0 )
then
85 r_tmp(1:2) = r(1:2) + factor*dr(1:2)
87 xyz_out(1:3) = matmul( elemt(1:3,1:nn), sfunc(:) )
88 dxyz(1:3) = xyz(1:3)-xyz_out(:)
89 dist_now = dot_product( dxyz, dxyz )
90 if(dist_now <= dist_last)
exit
101 dxyz(:)=xyz_out(:)-xyz(:)
103 normal(:) = normal(:)/dsqrt( dot_product(normal, normal) )
105 if( dabs(normal(count))<1.d-10 ) normal(count) =0.d0
106 if( dabs(1.d0-dabs(normal(count)))<1.d-10 ) normal(count) =sign(1.d0, normal(count))
108 cstate%distance = dot_product( dxyz, normal )
110 if( cstate%interference_flag ==
c_if_slave)
then
111 if( cstate%init_pos == 0.d0 .and. cstate%distance < cstate%end_pos)
then
112 cstate%init_pos = cstate%distance
113 cstate%time_factor = (cstate%end_pos - cstate%distance) / cstate%time_factor
114 cstate%shrink_factor = cstate%distance
118 if( cstate%interference_flag == 0)
then
119 if( cstate%distance < distclr*reflen .and. cstate%distance > -5.0d-01*reflen ) isin = .true.
121 if( cstate%distance < cstate%shrink_factor + distclr*reflen ) isin = .true.
128 cstate%state = initstate
130 cstate%gpos(:)=xyz_out(:)
131 cstate%lpos(1:2)=r(:)
132 cstate%direction(:) = normal(:)
133 cstate%wkdist = cstate%distance
141 real(kind=kreal),
intent(in) :: xyz(3)
142 integer,
intent(in) :: etype
143 integer,
intent(in) :: nn
144 real(kind=kreal),
intent(in) :: elemt(:,:)
145 real(kind=kreal),
intent(in) :: reflen
147 logical,
intent(out) :: isin
148 real(kind=kreal),
intent(in) :: distclr
149 real(kind=kreal),
optional :: ctpos(3)
150 real(kind=kreal),
optional :: localclr
152 integer :: count,order, initstate
153 real(kind=kreal) :: inverse(3,3)
154 real(kind=kreal) :: sfunc(nn), deriv(nn,3)
155 real(kind=kreal) :: r(3), dr(3), r_tmp(3)
156 real(kind=kreal) :: xyz_out(3)
157 real(kind=kreal) :: dist_last,dist_now, dxyz(3)
158 real(kind=kreal),
parameter :: eps = 1.0d-8
159 real(kind=kreal) :: clr, tol, factor
161 initstate = cstate%state
163 if(
present( localclr ) ) clr=localclr
164 if(
present( ctpos ) )
then
173 xyz_out = matmul( elemt(1:3,1:nn), sfunc(1:nn) )
174 dxyz(1:3) = xyz_out(1:3) - xyz(1:3)
175 dist_last = dot_product( dxyz, dxyz(:) )
178 inverse(1:3,1:3) = matmul(elemt(1:3,1:nn),deriv(1:nn,1:3))
180 dr(1:3) = -matmul(inverse(1:3,1:3),dxyz(1:3))
182 tol=dot_product(dr,dr)
183 if( count > 1 .and. dsqrt(tol)> 3.d0 )
then
189 r_tmp(1:3) = r(1:3) + factor*dr(1:3)
191 xyz_out(1:3) = matmul( elemt(1:3,1:nn), sfunc(1:nn) )
192 dxyz(1:3) = xyz(1:3)-xyz_out(1:3)
193 dist_now = dot_product( dxyz, dxyz )
194 if(dist_now <= dist_last)
exit
195 factor = factor*0.7d0
205 dxyz(:)=xyz_out(:)-xyz(:)
206 cstate%distance = dsqrt(dot_product( dxyz, dxyz ))
208 if( cstate%distance < distclr ) isin = .true.
214 cstate%state = initstate
216 cstate%gpos(:)=xyz_out(:)
217 cstate%direction(:) = (/1.d0,0.d0,0.d0/)
218 cstate%lpos(1:3)=r(:)
226 real(kind=kreal),
intent(in) :: xyz(3)
227 type(tsurfelement),
intent(in) :: surf
228 real(kind=kreal),
intent(in) :: currpos(:)
230 logical,
intent(out) :: isin
231 real(kind=kreal),
intent(in) :: distclr
232 real(kind=kreal),
optional,
intent(in) :: ctpos(2)
233 real(kind=kreal),
optional,
intent(in) :: localclr
234 integer(kind=kint),
intent(in) :: smoothing
236 integer(kind=kint) :: nn, j, iss, etype_use, nn_use
237 real(kind=kreal) :: elem(3, l_max_elem_node)
238 real(kind=kreal) :: elem_tri3n(3, 3)
241 nn =
size(surf%nodes)
244 elem(1:3, j) = currpos(3*iss-2:3*iss)
249 elem_tri3n = elem(1:3, 1:3)
255 elem(1:3, nn+j) = surf%intermediate_points(1:3, j)
260 etype_use = surf%etype
264 etype_use = surf%etype
269 isin, distclr, ctpos, localclr)
275 real(kind=kreal),
intent(in) :: pos(2)
276 integer,
intent(in) :: etype
277 real(kind=kreal),
intent(in) :: ele(:,:)
278 real(kind=kreal),
intent(out) :: tensor(2,2)
281 real(kind=kreal) :: tangent(3,2)
284 tensor(1,1)= dot_product( tangent(:,1), tangent(:,1) )
285 tensor(1,2)= dot_product( tangent(:,1), tangent(:,2) )
286 tensor(2,1)= dot_product( tangent(:,2), tangent(:,1) )
287 tensor(2,2)= dot_product( tangent(:,2), tangent(:,2) )
293 real(kind=kreal),
intent(in) :: pos(2)
294 integer,
intent(in) :: etype
295 integer,
intent(in) :: nnode
296 real(kind=kreal),
intent(in) :: ele(3,nnode)
297 real(kind=kreal),
intent(out) :: tangent(3,2)
298 real(kind=kreal),
intent(out) :: tensor(2,2)
299 real(kind=kreal),
intent(out) :: matrix(2,nnode*3+3)
302 real(kind=kreal) :: det
303 real(kind=kreal) :: shapefunc(nnode), t1(nnode*3+3), t2(nnode*3+3)
304 call tangentbase( etype, nnode, pos, ele, tangent )
305 tensor(1,1)= dot_product( tangent(:,1), tangent(:,1) )
306 tensor(1,2)= dot_product( tangent(:,1), tangent(:,2) )
307 tensor(2,1)= dot_product( tangent(:,2), tangent(:,1) )
308 tensor(2,2)= dot_product( tangent(:,2), tangent(:,2) )
309 det = tensor(1,1)*tensor(2,2)-tensor(1,2)*tensor(2,1)
310 if( det==0.d0 ) stop
"Error in calculate DispIncreMatrix"
318 t1( j ) = tangent(j,1)
319 t2( j ) = tangent(j,2)
321 forall( i=1:nnode, j=1:3 )
322 t1( i*3+j ) = -tangent(j,1)*shapefunc(i)
323 t2( i*3+j ) = -tangent(j,2)*shapefunc(i)
326 matrix(1,:) = (tensor(2,2)*t1(:)-tensor(1,2)*t2(:))/det
327 matrix(2,:) = (tensor(1,1)*t2(:)-tensor(2,1)*t1(:))/det
328 tangent(:,1) = tangent(:,1)/dsqrt(dot_product(tangent(:,1),tangent(:,1)))
329 tangent(:,2) = tangent(:,2)/dsqrt(dot_product(tangent(:,2),tangent(:,2)))
334 integer,
intent(in) :: nslave
335 type(
tcontact ),
intent(inout) :: contact
336 real(kind=kreal),
intent(in) :: currpos(:)
338 integer(kind=kint) :: slave, sid0, etype, iSS
339 real(kind=kreal) :: coord(3)
343 slave = contact%slave(nslave)
344 coord(:) = currpos(3*slave-2:3*slave)
346 sid0 = contact%states(nslave)%surface
348 cstate_tmp = contact%states(nslave)
350 cstate_tmp, isin, contact%cparam%DISTCLR_NOCHECK, &
351 contact%states(nslave)%lpos, contact%cparam%CLR_SAME_ELEM, &
352 smoothing=contact%smoothing )
355 etype = contact%master(sid0)%etype
356 iss =
isinsideelement( etype, cstate_tmp%lpos, contact%cparam%CLR_CAL_NORM )
358 call cal_node_normal( cstate_tmp%surface, iss, contact%master, currpos, &
359 cstate_tmp%lpos, cstate_tmp%direction(:) )
362 contact%states(nslave)%direction = cstate_tmp%direction
369 integer,
intent(in) :: csurf
370 integer,
intent(in) :: isin
371 type(tsurfelement),
intent(in) :: surf(:)
372 real(kind=kreal),
intent(in) :: currpos(:)
373 real(kind=kreal),
intent(in) :: lpos(:)
374 real(kind=kreal),
intent(out) :: normal(3)
375 integer(kind=kint) :: cnode, i, j, cnt, nd1, gn, etype, iss, nn,
cgn
376 real(kind=kreal) :: cnpos(2), elem(3, l_max_elem_node)
377 integer(kind=kint) :: cnode1, cnode2, gn1, gn2, nsurf, cgn1, cgn2, isin_n
378 real(kind=kreal) :: x, normal_n(3), lpos_n(2)
380 if( 1 <= isin .and. isin <= 4 )
then
382 gn = surf(csurf)%nodes(cnode)
383 etype = surf(csurf)%etype
385 nn =
size( surf(csurf)%nodes )
387 iss = surf(csurf)%nodes(j)
388 elem(1:3,j)=currpos(3*iss-2:3*iss)
392 do i=1,surf(csurf)%n_neighbor
393 nd1 = surf(csurf)%neighbor(i)
394 nn =
size( surf(nd1)%nodes )
395 etype = surf(nd1)%etype
398 iss = surf(nd1)%nodes(j)
399 elem(1:3,j)=currpos(3*iss-2:3*iss)
406 normal = normal+normal_n
411 elseif( 12 <= isin .and. isin <= 41 )
then
413 cnode2 = mod(isin, 10)
414 gn1 = surf(csurf)%nodes(cnode1)
415 gn2 = surf(csurf)%nodes(cnode2)
416 etype = surf(csurf)%etype
417 nn =
size( surf(csurf)%nodes )
419 iss = surf(csurf)%nodes(j)
420 elem(1:3,j)=currpos(3*iss-2:3*iss)
424 case (fe_tri3n, fe_tri6n, fe_tri6nc)
425 if ( isin==12 ) then; x=lpos(2)-lpos(1)
426 elseif( isin==23 ) then; x=1.d0-2.d0*lpos(2)
427 elseif( isin==31 ) then; x=2.d0*lpos(1)-1.d0
428 else; stop
"Error: cal_node_normal: invalid isin"
430 case (fe_quad4n, fe_quad8n)
431 if ( isin==12 ) then; x=lpos(1)
432 elseif( isin==23 ) then; x=lpos(2)
433 elseif( isin==34 ) then; x=-lpos(1)
434 elseif( isin==41 ) then; x=-lpos(2)
435 else; stop
"Error: cal_node_normal: invalid isin"
440 neib_loop:
do i=1, surf(csurf)%n_neighbor
441 nd1 = surf(csurf)%neighbor(i)
442 nn =
size( surf(nd1)%nodes )
443 etype = surf(nd1)%etype
447 iss = surf(nd1)%nodes(j)
448 elem(1:3,j)=currpos(3*iss-2:3*iss)
449 if( iss==gn1 ) cgn1=j
450 if( iss==gn2 ) cgn2=j
452 if( cgn1>0 .and. cgn2>0 )
then
454 isin_n = 10*cgn2 + cgn1
457 case (fe_tri3n, fe_tri6n, fe_tri6nc)
458 if ( isin_n==12 ) then; lpos_n(1)=0.5d0*(1.d0-x); lpos_n(2)=0.5d0*(1.d0+x)
459 elseif( isin_n==23 ) then; lpos_n(1)=0.d0; lpos_n(2)=0.5d0*(1.d0-x)
460 elseif( isin_n==31 ) then; lpos_n(1)=0.5d0*(1.d0+x); lpos_n(2)=0.d0
461 else; stop
"Error: cal_node_normal: invalid isin_n"
463 case (fe_quad4n, fe_quad8n)
464 if ( isin_n==12 ) then; lpos_n(1)= x; lpos_n(2)=-1.d0
465 elseif( isin_n==23 ) then; lpos_n(1)= 1.d0; lpos_n(2)= x
466 elseif( isin_n==34 ) then; lpos_n(1)=-x; lpos_n(2)= 1.d0
467 elseif( isin_n==41 ) then; lpos_n(1)=-1.d0; lpos_n(2)=-x
468 else; stop
"Error: cal_node_normal: invalid isin_n"
473 normal = normal+normal_n
480 normal = normal/ dsqrt( dot_product( normal, normal ) )
This module encapsulate the basic functions of all elements provide by this software.
subroutine getshapefunc(fetype, localcoord, func)
Calculate the shape function in natural coordinate system.
integer(kind=kind(2)) function getnumberofnodes(etype)
Obtain number of nodes of the element.
integer function isinside3delement(fetype, localcoord, clearance)
if a point is inside a surface element -1: No; 0: Yes; >0: Node's (vertex) number
subroutine getelementcenter(fetype, localcoord)
Return natural coordinate of the center of element.
integer, parameter fe_tri6n
subroutine getshapederiv(fetype, localcoord, shapederiv)
Calculate derivatives of shape function in natural coordinate system.
subroutine getvertexcoord(fetype, cnode, localcoord)
Get the natural coord of a vertex node.
integer, parameter fe_tri3n
subroutine tangentbase(fetype, nn, localcoord, elecoord, tangent)
Calculate base vector of tangent space of 3d surface.
integer, parameter fe_quad4n
integer function isinsideelement(fetype, localcoord, clearance)
if a point is inside a surface element -1: No; 0: Yes; >0: Node's (vertex) number
real(kind=kreal) function, dimension(3) surfacenormal(fetype, nn, localcoord, elecoord)
Calculate normal of 3d-surface.
subroutine curvature(fetype, nn, localcoord, elecoord, l2ndderiv, normal, curv)
Calculate curvature tensor at a point along 3d surface.
integer, parameter fe_quad8n
This module provides aux functions.
subroutine calinverse(NN, A)
calculate inverse of matrix a