diff --git a/docs/02_software_architecture_design.md b/docs/02_software_architecture_design.md index 795f8af..6f4987f 100644 --- a/docs/02_software_architecture_design.md +++ b/docs/02_software_architecture_design.md @@ -392,7 +392,7 @@ coupling 层职责: - 接触状态、接触力和接触功输出 - 隐式增量残差和迭代次数输出 -第三版当前接触模块保留刚性平面接触,并新增基于边界 facet 的面-面 contact pair force/tangent 路径。0.3.1 已补充多 master facet 权重分摊、Coulomb 摩擦和 facet 空间 broad-phase 过滤;完整接触状态、接触功、严格 mortar 和空间网格/BVH 仍属于后续输出与算法增强项。 +第三版当前接触模块保留刚性平面接触,并新增基于边界 facet 的面-面 contact pair force/tangent 路径。0.3.1 已补充投影裁剪面积积分、多 master 面积上限修正、Coulomb 摩擦、均匀空间网格候选搜索、facet 空间 broad-phase 精筛,以及接触状态/接触功 CSV 与 API 输出。完整 mortar 形函数积分、摩擦历史和并行 BVH 仍属于后续算法增强项。 输出控制: diff --git a/docs/03_detailed_design.md b/docs/03_detailed_design.md index 9b95dd2..cdca68a 100644 --- a/docs/03_detailed_design.md +++ b/docs/03_detailed_design.md @@ -897,6 +897,7 @@ elements_step_xxxxx.csv 至少包含: - `convergence.csv`:静力和隐式动力增量迭代历史。 - `reactions_step_xxxxx.csv`:节点反力。 - `contact_step_xxxxx.csv`:接触状态、接触力和接触功。 + 当前字段为 `kind,pair_id,active_count,max_penetration,force_norm,work_estimate,cumulative_work`,包含 summary 行和逐 contact pair 行。 - 静力求解结束后必须写出与显式结果一致的 VTK 场文件。 ## 19. 主程序模块 diff --git a/docs/04_mathematical_model_and_algorithms.md b/docs/04_mathematical_model_and_algorithms.md index 298b844..a6e35f9 100644 --- a/docs/04_mathematical_model_and_algorithms.md +++ b/docs/04_mathematical_model_and_algorithms.md @@ -796,10 +796,11 @@ K_eff Delta_u = R - 刚性平面接触仍采用节点到平面的 penalty/damping 法向接触。 - 面-面 contact pair 使用边界 facet 的当前构形坐标、速度、法向、面积、中心和等效半径。 -- slave facet 质心投影到 master facet 平面,投影点落在 master facet 等效半径和搜索距离内且法向间隙为负时激活;多个 master facet 同时激活时按投影权重分摊。 -- 接触力为 `penalty * penetration * area` 加可选法向阻尼项,并可叠加基于相对切向速度的 Coulomb 摩擦力。 +- slave facet 沿 master 法向投影到 master facet 平面,在局部二维坐标中执行多边形裁剪;裁剪面积大于零且法向间隙为负时激活。多个 master facet 同时激活时按裁剪面积贡献,且总面积不超过 slave facet 面积。 +- 接触力为 `penalty * penetration * clipped_area` 加可选法向阻尼项,并可叠加基于相对切向速度的 Coulomb 摩擦力。 - 接触切线采用法向 penalty/damping 块加切向摩擦近似块,装配 slave-slave、slave-master、master-slave 和 master-master 四类自由度耦合。 -- 当前实现包含 facet 中心/等效半径空间 broad-phase 过滤;严格 mortar 积分、精确面内投影裁剪、空间网格/BVH 和完整接触功统计仍为后续增强项。 +- 当前实现包含 master facet 均匀空间网格候选搜索和 facet 中心/等效半径 broad-phase 精筛。接触状态记录激活贡献数、最大穿透量、接触力范数和 `0.5 * |F_contact| * penetration` 形式的接触功估计。 +- 当前投影裁剪属于面积型 mortar 近似,尚未实现完整 mortar 形函数积分、摩擦粘滑历史变量和并行 BVH。 第一版不实现接触,只保留 fcontact 向量和接口位置。 diff --git a/docs/05_interface_control_document.md b/docs/05_interface_control_document.md index 6654ab0..f57adc0 100644 --- a/docs/05_interface_control_document.md +++ b/docs/05_interface_control_document.md @@ -544,10 +544,13 @@ end subroutine 第三版提供接触结果查询接口: ```fortran -subroutine fem_get_contact_summary(nactive_contact, contact_work, max_penetration, ierr) - integer, intent(out) :: nactive_contact - real(rk), intent(out) :: contact_work +subroutine fem_get_contact_summary(active_count, work_step, work_total, & + max_penetration, force_norm, ierr) + integer, intent(out) :: active_count + real(rk), intent(out) :: work_step + real(rk), intent(out) :: work_total real(rk), intent(out) :: max_penetration + real(rk), intent(out) :: force_norm integer, intent(out) :: ierr end subroutine ``` @@ -570,7 +573,17 @@ end subroutine - `contact_pair_search(pair)`:搜索距离,0 表示只按 facet 等效半径过滤。 - `contact_pair_friction(pair)`:Coulomb 摩擦系数,必须非负;0 表示无摩擦。 -当前 contact pair 支持多 master facet 权重分摊、Coulomb 摩擦和 facet 空间 broad-phase 过滤。查询统计仍以 `fem_get_contact_summary` 为目标接口,完整激活数量、最大穿透量和接触功统计将在接触输出阶段补齐。 +当前 contact pair 支持投影裁剪面积积分、多 master facet 面积上限修正、Coulomb 摩擦、均匀空间网格候选搜索和 facet 空间 broad-phase 精筛。 + +接触统计包括: + +- `contact_active_count`:最近一次接触力评估中的激活贡献数。 +- `contact_work_step`:最近一次接触力评估的接触功估计。 +- `contact_work_total`:累计接触功估计。 +- `contact_max_penetration`:最近一次接触力评估的最大穿透量。 +- `contact_force_norm`:最近一次接触力评估的接触力范数累加。 + +逐 contact pair 统计保存在 `contact_pair_active/work/max_penetration/force_norm` 数组中,并写入 `contact_step_xxxxx.csv`。 ## 13. 输出控制接口 diff --git a/docs/06_test_and_verification_plan.md b/docs/06_test_and_verification_plan.md index 4420f98..d607d1c 100644 --- a/docs/06_test_and_verification_plan.md +++ b/docs/06_test_and_verification_plan.md @@ -264,13 +264,15 @@ SPH总力映射测试 relative tolerance 1.0e-10 to 1.0e-8 - 面压力等效节点力。 - amplitude 常值和表格插值。 - 刚性平面 contact penalty/damping 力和切线。 -- 面-面 contact pair 法向力、阻尼项、Coulomb 摩擦、多 master 分摊、空间 broad-phase、CSR 图案和切线块。 +- 面-面 contact pair 法向力、阻尼项、Coulomb 摩擦、多 master 分摊、投影裁剪面积、空间网格候选、空间 broad-phase、CSR 图案和切线块。 输出测试: - `history.csv` 字段存在。 - `nodes_step_xxxxx.csv` 字段存在。 - `elements_step_xxxxx.csv` 字段存在。 +- `contact_step_xxxxx.csv` 字段存在,并包含 summary 与逐 contact pair 行。 +- `fem_get_contact_summary` 返回激活数、单步/累计接触功、最大穿透量和接触力范数。 - 删除单元状态可输出。 ## 11. 输入解析测试 diff --git a/docs/v3_development_plan.md b/docs/v3_development_plan.md index 3d3f899..a1e6745 100644 --- a/docs/v3_development_plan.md +++ b/docs/v3_development_plan.md @@ -273,7 +273,7 @@ K_eff = K_t + a0 M + a1 C 1. `*SURFACE` 输入子集。 2. `*CONTACT PAIR` 输入子集。 3. 接触面数据结构。 -4. 朴素接触搜索,后续再优化为空间网格或 BVH。 +4. 接触搜索,先采用均匀空间网格,后续可升级 BVH 或并行搜索。 5. 节点-面接触。 6. 面-面接触框架。 7. penalty 法默认接触力。 @@ -285,12 +285,13 @@ K_eff = K_t + a0 M + a1 C - 保留第二版刚性平面 penalty 接触路径。 - 新增 `contact_pair_slave/master/penalty/damping/search/friction` 集中式数据库数组,可通过 elset、element id 或 `ALL` 指定接触对目标。 -- 面-面接触采用边界 facet 的质心投影、法向间隙和 penalty/damping 法向力映射,并在 0.3.1 扩展为多 master facet 权重分摊。 +- 面-面接触采用边界 facet 的当前构形、法向间隙和 penalty/damping 法向力映射;0.3.1 已从质心权重推进到 master 平面局部二维投影裁剪面积积分,并对重复 master 面做从面面积上限修正。 - 0.3.1 支持基于相对切向速度的 Coulomb 摩擦力和切向近似切线。 -- 0.3.1 增加 facet 中心/等效半径空间 broad-phase 过滤,减少明显不可能接触的 facet 对。 +- 0.3.1 增加基于 master facet 桶的均匀空间网格候选搜索,并保留 facet 中心/等效半径 broad-phase 精筛。 +- 0.3.1 新增全局和逐 contact pair 的激活数、最大穿透量、接触力范数和接触功估计统计,并输出到 `history.csv` 与 `contact_step_xxxxx.csv`。 - CSR 稀疏图案会为 contact pair 预留 slave-slave、slave-master、master-slave 和 master-master 切线块。 -- 已补充 contact pair 法向力、摩擦力、多 master 分摊和切线装配测试。 -- 当前尚未实现严格 mortar 积分、精确面内投影裁剪、空间网格/BVH 加速、完整接触状态输出和工程级接触收敛控制。 +- 已补充 contact pair 法向力、摩擦力、多 master 分摊、投影裁剪面积、空间网格分支、接触统计和切线装配测试。 +- 当前仍未实现完整 mortar 形函数积分、摩擦粘滑历史变量、并行 BVH 和工程级接触收敛控制。 验收条件: @@ -324,12 +325,13 @@ K_eff = K_t + a0 M + a1 C - my - mz 3. `contact_step_xxxxx.csv`: - - contact_id - - node_id 或 facet_id - - penetration - - normal_force - - tangential_force - - contact_status + - kind + - pair_id + - active_count + - max_penetration + - force_norm + - work_estimate + - cumulative_work 4. 静力 VTK 输出: - displacement - rotation @@ -444,7 +446,7 @@ P2 测试: - 先实体,再壳;先 S4/S3,再 S6/S8。 - Scordelis-Lo 作为壳静力主基准,分网格逐步验证。 - 非线性静力先完成实体 J2 算法切线,再推进壳膜内塑性切线,0.3.1 补齐壳弯曲/剪切 section tangent 映射。 -- 接触先保留刚性平面和面-面框架,0.3.1 补充多 master 权重分摊、Coulomb 摩擦和空间 broad-phase,再继续推进节点-面、严格 mortar 和搜索加速。 +- 接触先保留刚性平面和面-面框架,0.3.1 补充投影裁剪面积、多 master 面积上限、Coulomb 摩擦、均匀空间网格和接触输出,再继续推进节点-面、完整 mortar 形函数积分、摩擦历史和并行 BVH。 - 输出字段先冻结格式,再增加内容。 - 每个阶段均保持 CTest 可通过。 diff --git a/include/femlite_c_api.h b/include/femlite_c_api.h index 72f086d..cef59b1 100644 --- a/include/femlite_c_api.h +++ b/include/femlite_c_api.h @@ -17,6 +17,11 @@ int femlite_estimate_stable_dt(double *dtcrit); int femlite_advance_explicit(double dt); int femlite_get_current_time(double *time, int *step); int femlite_get_model_size(int *num_nodes, int *num_elems, int *num_dof); +int femlite_get_contact_summary(int *active_count, + double *work_step, + double *work_total, + double *max_penetration, + double *force_norm); int femlite_clear_sph_forces(void); int femlite_apply_sph_nodal_forces(int num_force_nodes, diff --git a/src/base/fem_api.f90 b/src/base/fem_api.f90 index 97c16f0..60d3d09 100644 --- a/src/base/fem_api.f90 +++ b/src/base/fem_api.f90 @@ -288,6 +288,28 @@ contains ierr = FEM_SUCCESS end subroutine fem_get_sph_force_summary + subroutine fem_get_contact_summary(active_count, work_step, work_total, & + max_penetration, force_norm, ierr) + integer, intent(out) :: active_count + real(rk), intent(out) :: work_step + real(rk), intent(out) :: work_total + real(rk), intent(out) :: max_penetration + real(rk), intent(out) :: force_norm + integer, intent(out) :: ierr + + if (.not. api_initialized) then + call error_set(FEM_ERR_INTERNAL, 'fem_get_contact_summary called before fem_initialize', ierr) + return + end if + + active_count = contact_active_count + work_step = contact_work_step + work_total = contact_work_total + max_penetration = contact_max_penetration + force_norm = contact_force_norm + ierr = FEM_SUCCESS + end subroutine fem_get_contact_summary + subroutine fem_get_boundary_facet_count(num_facets, max_face_nodes, ierr) integer, intent(out) :: num_facets integer, intent(out) :: max_face_nodes diff --git a/src/boundary/fem_contact.f90 b/src/boundary/fem_contact.f90 index 77d822b..f1308c5 100644 --- a/src/boundary/fem_contact.f90 +++ b/src/boundary/fem_contact.f90 @@ -8,6 +8,8 @@ module fem_contact private + integer, parameter :: CONTACT_MAX_CLIP = 64 + public :: contact_apply_plane_forces public :: contact_apply_plane_tangent @@ -23,6 +25,7 @@ contains end if fcontact = ZERO + call contact_reset_status() do plane = 1, ncontact_plane call apply_contact_plane(plane, ierr) if (ierr .ne. FEM_SUCCESS) return @@ -49,6 +52,48 @@ contains ierr = FEM_SUCCESS end subroutine contact_apply_plane_tangent + subroutine contact_reset_status() + contact_active_count = 0 + contact_work_step = ZERO + contact_max_penetration = ZERO + contact_force_norm = ZERO + if (allocated(contact_pair_active)) contact_pair_active = 0 + if (allocated(contact_pair_work)) contact_pair_work = ZERO + if (allocated(contact_pair_max_penetration)) contact_pair_max_penetration = ZERO + if (allocated(contact_pair_force_norm)) contact_pair_force_norm = ZERO + end subroutine contact_reset_status + + subroutine contact_record_status(pair, penetration, force_vec) + integer, intent(in) :: pair + real(rk), intent(in) :: penetration + real(rk), intent(in) :: force_vec(NDIM) + real(rk) :: force_norm + real(rk) :: work_estimate + + if (penetration .le. ZERO) return + + force_norm = sqrt(sum(force_vec * force_vec)) + work_estimate = HALF * force_norm * penetration + + contact_active_count = contact_active_count + 1 + contact_max_penetration = max(contact_max_penetration, penetration) + contact_force_norm = contact_force_norm + force_norm + contact_work_step = contact_work_step + work_estimate + contact_work_total = contact_work_total + work_estimate + + if (pair .gt. 0) then + if (allocated(contact_pair_active)) then + if (pair .le. size(contact_pair_active)) then + contact_pair_active(pair) = contact_pair_active(pair) + 1 + contact_pair_work(pair) = contact_pair_work(pair) + work_estimate + contact_pair_max_penetration(pair) = & + max(contact_pair_max_penetration(pair), penetration) + contact_pair_force_norm(pair) = contact_pair_force_norm(pair) + force_norm + end if + end if + end if + end subroutine contact_record_status + subroutine apply_contact_plane(plane, ierr) integer, intent(in) :: plane integer, intent(out) :: ierr @@ -165,6 +210,7 @@ contains real(rk) :: gap real(rk) :: vn real(rk) :: force_mag + real(rk) :: force_vec(NDIM) integer :: idir integer :: dof @@ -197,10 +243,12 @@ contains vn = dot_product(normal, velocity) force_mag = contact_penalty(plane) * (-gap) if (vn .lt. ZERO) force_mag = force_mag + contact_damping(plane) * (-vn) + force_vec = force_mag * normal do idir = 1, NDIM dof = dof_id(idir,node) - if (dof .gt. 0) fcontact(dof) = fcontact(dof) + force_mag * normal(idir) + if (dof .gt. 0) fcontact(dof) = fcontact(dof) + force_vec(idir) end do + call contact_record_status(0, -gap, force_vec) end if ierr = FEM_SUCCESS @@ -317,6 +365,8 @@ contains integer, allocatable :: face_id(:) integer, allocatable :: fnnode(:) integer, allocatable :: fconn(:,:) + integer, allocatable :: grid_head(:) + integer, allocatable :: grid_next(:) real(rk), allocatable :: x(:,:,:) real(rk), allocatable :: vnod(:,:,:) real(rk), allocatable :: normal(:,:) @@ -330,13 +380,34 @@ contains real(rk) :: normal_mag real(rk) :: total_weight real(rk) :: pair_weight - real(rk) :: share + real(rk) :: area_scale + real(rk) :: contact_area real(rk) :: mu real(rk) :: vt_norm real(rk) :: nrm(NDIM) real(rk) :: tdir(NDIM) real(rk) :: force_vec(NDIM) + real(rk) :: grid_min(NDIM) + real(rk) :: grid_h(NDIM) + real(rk) :: max_master_radius + real(rk) :: candidate_radius integer :: q + integer :: grid_nx + integer :: grid_ny + integer :: grid_nz + integer :: grid_ncell + integer :: ix0 + integer :: ix1 + integer :: iy0 + integer :: iy1 + integer :: iz0 + integer :: iz1 + integer :: ix + integer :: iy + integer :: iz + integer :: cell + logical :: use_grid + logical :: active call cpl_build_facets(ierr) if (ierr .ne. FEM_SUCCESS) return @@ -366,54 +437,141 @@ contains radius(q) = facet_radius_value(q, nf, max_nodes, fnnode, x, center(:,q)) end do mu = contact_pair_friction_value(pair) + call contact_grid_dimensions(pair, nf, elem_id, center, radius, & + grid_min, grid_h, grid_nx, grid_ny, grid_nz, & + max_master_radius, use_grid) + if (use_grid) then + grid_ncell = grid_nx * grid_ny * grid_nz + allocate(grid_head(grid_ncell), grid_next(nf), stat=stat) + if (stat .ne. 0) then + call error_set(FEM_ERR_INTERNAL, 'failed to allocate contact spatial grid', ierr) + go to 900 + end if + call contact_grid_fill(pair, nf, elem_id, center, grid_min, grid_h, & + grid_nx, grid_ny, grid_nz, grid_head, grid_next) + end if do sf = 1, nf if (.not. facet_target_matches(elem_id(sf), contact_pair_slave(pair))) cycle total_weight = ZERO - do mf = 1, nf - if (sf .eq. mf) cycle - if (.not. facet_target_matches(elem_id(mf), contact_pair_master(pair))) cycle - if (.not. contact_spatial_candidate(pair, sf, mf, nf, center, radius)) cycle - if (facet_nodes_share(max_nodes, fnnode(sf), fconn(:,sf), & - fnnode(mf), fconn(:,mf))) cycle - call pair_contact_gap(pair, sf, mf, nf, max_nodes, fnnode, & - x, vnod, normal, gap, vn, pair_weight, ierr) - if (ierr .ne. FEM_SUCCESS) go to 900 - if (gap .lt. ZERO) total_weight = total_weight + pair_weight - end do + if (use_grid) then + candidate_radius = radius(sf) + max_master_radius + & + contact_pair_search_value(pair) + call contact_grid_range(center(:,sf), candidate_radius, grid_min, grid_h, & + grid_nx, grid_ny, grid_nz, ix0, ix1, iy0, iy1, & + iz0, iz1) + do iz = iz0, iz1 + do iy = iy0, iy1 + do ix = ix0, ix1 + cell = contact_grid_cell(ix, iy, iz, grid_nx, grid_ny, grid_nz) + mf = grid_head(cell) + do while (mf .gt. 0) + call contact_pair_candidate(pair, sf, mf, nf, max_nodes, fnnode, & + fconn, elem_id, x, vnod, normal, & + center, radius, gap, vn, pair_weight, & + active, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + if (active) total_weight = total_weight + pair_weight + mf = grid_next(mf) + end do + end do + end do + end do + else + do mf = 1, nf + call contact_pair_candidate(pair, sf, mf, nf, max_nodes, fnnode, & + fconn, elem_id, x, vnod, normal, & + center, radius, gap, vn, pair_weight, & + active, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + if (active) total_weight = total_weight + pair_weight + end do + end if if (total_weight .le. tiny(ONE)) cycle + area_scale = ONE + if (area(sf) .gt. tiny(ONE) .and. total_weight .gt. area(sf)) then + area_scale = area(sf) / total_weight + end if - do mf = 1, nf - if (sf .eq. mf) cycle - if (.not. facet_target_matches(elem_id(mf), contact_pair_master(pair))) cycle - if (.not. contact_spatial_candidate(pair, sf, mf, nf, center, radius)) cycle - if (facet_nodes_share(max_nodes, fnnode(sf), fconn(:,sf), & - fnnode(mf), fconn(:,mf))) cycle - call pair_contact_gap(pair, sf, mf, nf, max_nodes, fnnode, & - x, vnod, normal, gap, vn, pair_weight, ierr) - if (ierr .ne. FEM_SUCCESS) go to 900 - if (gap .ge. ZERO) cycle + if (use_grid) then + candidate_radius = radius(sf) + max_master_radius + & + contact_pair_search_value(pair) + call contact_grid_range(center(:,sf), candidate_radius, grid_min, grid_h, & + grid_nx, grid_ny, grid_nz, ix0, ix1, iy0, iy1, & + iz0, iz1) + do iz = iz0, iz1 + do iy = iy0, iy1 + do ix = ix0, ix1 + cell = contact_grid_cell(ix, iy, iz, grid_nx, grid_ny, grid_nz) + mf = grid_head(cell) + do while (mf .gt. 0) + call contact_pair_candidate(pair, sf, mf, nf, max_nodes, fnnode, & + fconn, elem_id, x, vnod, normal, & + center, radius, gap, vn, pair_weight, & + active, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + if (active) then + contact_area = pair_weight * area_scale + if (contact_area .gt. tiny(ONE)) then + nrm = normalized_contact_normal(normal(:,mf), ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + normal_mag = contact_pair_penalty(pair) * (-gap) * contact_area + if (vn .lt. ZERO) then + normal_mag = normal_mag + contact_pair_damping(pair) * & + (-vn) * contact_area + end if + call contact_tangent_direction(sf, mf, nf, max_nodes, fnnode, & + vnod, nrm, tdir, vt_norm) + force_vec = normal_mag * nrm + if (mu .gt. ZERO .and. vt_norm .gt. tiny(ONE) .and. & + normal_mag .gt. ZERO) then + force_mag = mu * normal_mag + force_vec = force_vec - force_mag * tdir + end if + call add_contact_pair_force_vec(max_nodes, fnnode(sf), & + fconn(:,sf), fnnode(mf), & + fconn(:,mf), force_vec, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + call contact_record_status(pair, -gap, force_vec) + end if + end if + mf = grid_next(mf) + end do + end do + end do + end do + else + do mf = 1, nf + call contact_pair_candidate(pair, sf, mf, nf, max_nodes, fnnode, & + fconn, elem_id, x, vnod, normal, & + center, radius, gap, vn, pair_weight, & + active, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + if (.not. active) cycle - share = pair_weight / total_weight - nrm = normalized_contact_normal(normal(:,mf), ierr) - if (ierr .ne. FEM_SUCCESS) go to 900 - normal_mag = contact_pair_penalty(pair) * (-gap) * area(sf) * share - if (vn .lt. ZERO) then - normal_mag = normal_mag + contact_pair_damping(pair) * & - (-vn) * area(sf) * share - end if - call contact_tangent_direction(sf, mf, nf, max_nodes, fnnode, & - vnod, nrm, tdir, vt_norm) - force_vec = normal_mag * nrm - if (mu .gt. ZERO .and. vt_norm .gt. tiny(ONE) .and. normal_mag .gt. ZERO) then - force_mag = mu * normal_mag - force_vec = force_vec - force_mag * tdir - end if - call add_contact_pair_force_vec(max_nodes, fnnode(sf), fconn(:,sf), & - fnnode(mf), fconn(:,mf), force_vec, ierr) - if (ierr .ne. FEM_SUCCESS) go to 900 - end do + contact_area = pair_weight * area_scale + if (contact_area .le. tiny(ONE)) cycle + nrm = normalized_contact_normal(normal(:,mf), ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + normal_mag = contact_pair_penalty(pair) * (-gap) * contact_area + if (vn .lt. ZERO) then + normal_mag = normal_mag + contact_pair_damping(pair) * & + (-vn) * contact_area + end if + call contact_tangent_direction(sf, mf, nf, max_nodes, fnnode, & + vnod, nrm, tdir, vt_norm) + force_vec = normal_mag * nrm + if (mu .gt. ZERO .and. vt_norm .gt. tiny(ONE) .and. normal_mag .gt. ZERO) then + force_mag = mu * normal_mag + force_vec = force_vec - force_mag * tdir + end if + call add_contact_pair_force_vec(max_nodes, fnnode(sf), fconn(:,sf), & + fnnode(mf), fconn(:,mf), force_vec, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + call contact_record_status(pair, -gap, force_vec) + end do + end if end do ierr = FEM_SUCCESS @@ -431,6 +589,8 @@ contains if (allocated(velc)) deallocate(velc) if (allocated(area)) deallocate(area) if (allocated(radius)) deallocate(radius) + if (allocated(grid_head)) deallocate(grid_head) + if (allocated(grid_next)) deallocate(grid_next) end subroutine apply_contact_pair_force_one subroutine apply_contact_pair_tan_one(pair, kmat, velocity_scale, ierr) @@ -448,6 +608,8 @@ contains integer, allocatable :: face_id(:) integer, allocatable :: fnnode(:) integer, allocatable :: fconn(:,:) + integer, allocatable :: grid_head(:) + integer, allocatable :: grid_next(:) real(rk), allocatable :: x(:,:,:) real(rk), allocatable :: vnod(:,:,:) real(rk), allocatable :: normal(:,:) @@ -457,16 +619,31 @@ contains real(rk), allocatable :: radius(:) real(rk) :: gap real(rk) :: vn - real(rk) :: coeff real(rk) :: total_weight real(rk) :: pair_weight - real(rk) :: share + real(rk) :: area_scale real(rk) :: mu - real(rk) :: nrm(NDIM) - real(rk) :: ktan(NDIM,NDIM) - integer :: idir - integer :: jdir + real(rk) :: grid_min(NDIM) + real(rk) :: grid_h(NDIM) + real(rk) :: max_master_radius + real(rk) :: candidate_radius integer :: q + integer :: grid_nx + integer :: grid_ny + integer :: grid_nz + integer :: grid_ncell + integer :: ix0 + integer :: ix1 + integer :: iy0 + integer :: iy1 + integer :: iz0 + integer :: iz1 + integer :: ix + integer :: iy + integer :: iz + integer :: cell + logical :: use_grid + logical :: active call cpl_build_facets(ierr) if (ierr .ne. FEM_SUCCESS) return @@ -496,56 +673,107 @@ contains radius(q) = facet_radius_value(q, nf, max_nodes, fnnode, x, center(:,q)) end do mu = contact_pair_friction_value(pair) + call contact_grid_dimensions(pair, nf, elem_id, center, radius, & + grid_min, grid_h, grid_nx, grid_ny, grid_nz, & + max_master_radius, use_grid) + if (use_grid) then + grid_ncell = grid_nx * grid_ny * grid_nz + allocate(grid_head(grid_ncell), grid_next(nf), stat=stat) + if (stat .ne. 0) then + call error_set(FEM_ERR_INTERNAL, 'failed to allocate contact tangent grid', ierr) + go to 900 + end if + call contact_grid_fill(pair, nf, elem_id, center, grid_min, grid_h, & + grid_nx, grid_ny, grid_nz, grid_head, grid_next) + end if do sf = 1, nf if (.not. facet_target_matches(elem_id(sf), contact_pair_slave(pair))) cycle total_weight = ZERO - do mf = 1, nf - if (sf .eq. mf) cycle - if (.not. facet_target_matches(elem_id(mf), contact_pair_master(pair))) cycle - if (.not. contact_spatial_candidate(pair, sf, mf, nf, center, radius)) cycle - if (facet_nodes_share(max_nodes, fnnode(sf), fconn(:,sf), & - fnnode(mf), fconn(:,mf))) cycle - call pair_contact_gap(pair, sf, mf, nf, max_nodes, fnnode, & - x, vnod, normal, gap, vn, pair_weight, ierr) - if (ierr .ne. FEM_SUCCESS) go to 900 - if (gap .lt. ZERO) total_weight = total_weight + pair_weight - end do - - if (total_weight .le. tiny(ONE)) cycle - - do mf = 1, nf - if (sf .eq. mf) cycle - if (.not. facet_target_matches(elem_id(mf), contact_pair_master(pair))) cycle - if (.not. contact_spatial_candidate(pair, sf, mf, nf, center, radius)) cycle - if (facet_nodes_share(max_nodes, fnnode(sf), fconn(:,sf), & - fnnode(mf), fconn(:,mf))) cycle - call pair_contact_gap(pair, sf, mf, nf, max_nodes, fnnode, & - x, vnod, normal, gap, vn, pair_weight, ierr) - if (ierr .ne. FEM_SUCCESS) go to 900 - if (gap .ge. ZERO) cycle - - share = pair_weight / total_weight - nrm = normalized_contact_normal(normal(:,mf), ierr) - if (ierr .ne. FEM_SUCCESS) go to 900 - coeff = contact_pair_penalty(pair) * area(sf) * share - if (vn .lt. ZERO) then - coeff = coeff + velocity_scale * contact_pair_damping(pair) * area(sf) * share - end if - ktan = ZERO - do idir = 1, NDIM - do jdir = 1, NDIM - ktan(idir,jdir) = coeff * nrm(idir) * nrm(jdir) - if (mu .gt. ZERO) then - if (idir .eq. jdir) ktan(idir,jdir) = ktan(idir,jdir) + mu * coeff - ktan(idir,jdir) = ktan(idir,jdir) - mu * coeff * nrm(idir) * nrm(jdir) - end if + if (use_grid) then + candidate_radius = radius(sf) + max_master_radius + & + contact_pair_search_value(pair) + call contact_grid_range(center(:,sf), candidate_radius, grid_min, grid_h, & + grid_nx, grid_ny, grid_nz, ix0, ix1, iy0, iy1, & + iz0, iz1) + do iz = iz0, iz1 + do iy = iy0, iy1 + do ix = ix0, ix1 + cell = contact_grid_cell(ix, iy, iz, grid_nx, grid_ny, grid_nz) + mf = grid_head(cell) + do while (mf .gt. 0) + call contact_pair_candidate(pair, sf, mf, nf, max_nodes, fnnode, & + fconn, elem_id, x, vnod, normal, & + center, radius, gap, vn, pair_weight, & + active, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + if (active) total_weight = total_weight + pair_weight + mf = grid_next(mf) + end do + end do end do end do - call add_contact_pair_tan_matrix(kmat, max_nodes, fnnode(sf), fconn(:,sf), & - fnnode(mf), fconn(:,mf), ktan, ierr) - if (ierr .ne. FEM_SUCCESS) go to 900 - end do + else + do mf = 1, nf + call contact_pair_candidate(pair, sf, mf, nf, max_nodes, fnnode, & + fconn, elem_id, x, vnod, normal, & + center, radius, gap, vn, pair_weight, & + active, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + if (active) total_weight = total_weight + pair_weight + end do + end if + + if (total_weight .le. tiny(ONE)) cycle + area_scale = ONE + if (area(sf) .gt. tiny(ONE) .and. total_weight .gt. area(sf)) then + area_scale = area(sf) / total_weight + end if + + if (use_grid) then + candidate_radius = radius(sf) + max_master_radius + & + contact_pair_search_value(pair) + call contact_grid_range(center(:,sf), candidate_radius, grid_min, grid_h, & + grid_nx, grid_ny, grid_nz, ix0, ix1, iy0, iy1, & + iz0, iz1) + do iz = iz0, iz1 + do iy = iy0, iy1 + do ix = ix0, ix1 + cell = contact_grid_cell(ix, iy, iz, grid_nx, grid_ny, grid_nz) + mf = grid_head(cell) + do while (mf .gt. 0) + call contact_pair_candidate(pair, sf, mf, nf, max_nodes, fnnode, & + fconn, elem_id, x, vnod, normal, & + center, radius, gap, vn, pair_weight, & + active, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + if (active) then + call contact_add_pair_tangent(kmat, pair, sf, mf, nf, max_nodes, & + fnnode, fconn, normal, gap, vn, & + pair_weight, area_scale, velocity_scale, & + mu, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + end if + mf = grid_next(mf) + end do + end do + end do + end do + else + do mf = 1, nf + call contact_pair_candidate(pair, sf, mf, nf, max_nodes, fnnode, & + fconn, elem_id, x, vnod, normal, & + center, radius, gap, vn, pair_weight, & + active, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + if (.not. active) cycle + call contact_add_pair_tangent(kmat, pair, sf, mf, nf, max_nodes, & + fnnode, fconn, normal, gap, vn, & + pair_weight, area_scale, velocity_scale, & + mu, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + end do + end if end do ierr = FEM_SUCCESS @@ -563,8 +791,70 @@ contains if (allocated(velc)) deallocate(velc) if (allocated(area)) deallocate(area) if (allocated(radius)) deallocate(radius) + if (allocated(grid_head)) deallocate(grid_head) + if (allocated(grid_next)) deallocate(grid_next) end subroutine apply_contact_pair_tan_one + subroutine contact_add_pair_tangent(kmat, pair, sf, mf, nf, max_nodes, & + fnnode, fconn, normal, gap, vn, & + pair_weight, area_scale, velocity_scale, & + mu, ierr) + type(csr_matrix), intent(inout) :: kmat + integer, intent(in) :: pair + integer, intent(in) :: sf + integer, intent(in) :: mf + integer, intent(in) :: nf + integer, intent(in) :: max_nodes + integer, intent(in) :: fnnode(nf) + integer, intent(in) :: fconn(max_nodes,nf) + real(rk), intent(in) :: normal(NDIM,nf) + real(rk), intent(in) :: gap + real(rk), intent(in) :: vn + real(rk), intent(in) :: pair_weight + real(rk), intent(in) :: area_scale + real(rk), intent(in) :: velocity_scale + real(rk), intent(in) :: mu + integer, intent(out) :: ierr + real(rk) :: contact_area + real(rk) :: coeff + real(rk) :: nrm(NDIM) + real(rk) :: ktan(NDIM,NDIM) + integer :: idir + integer :: jdir + + if (gap .ge. ZERO) then + ierr = FEM_SUCCESS + return + end if + + contact_area = pair_weight * area_scale + if (contact_area .le. tiny(ONE)) then + ierr = FEM_SUCCESS + return + end if + + nrm = normalized_contact_normal(normal(:,mf), ierr) + if (ierr .ne. FEM_SUCCESS) return + coeff = contact_pair_penalty(pair) * contact_area + if (vn .lt. ZERO) then + coeff = coeff + velocity_scale * contact_pair_damping(pair) * contact_area + end if + + ktan = ZERO + do idir = 1, NDIM + do jdir = 1, NDIM + ktan(idir,jdir) = coeff * nrm(idir) * nrm(jdir) + if (mu .gt. ZERO) then + if (idir .eq. jdir) ktan(idir,jdir) = ktan(idir,jdir) + mu * coeff + ktan(idir,jdir) = ktan(idir,jdir) - mu * coeff * nrm(idir) * nrm(jdir) + end if + end do + end do + + call add_contact_pair_tan_matrix(kmat, max_nodes, fnnode(sf), fconn(:,sf), & + fnnode(mf), fconn(:,mf), ktan, ierr) + end subroutine contact_add_pair_tangent + logical function facet_target_matches(elem_ext, target) integer, intent(in) :: elem_ext character(len=*), intent(in) :: target @@ -649,6 +939,210 @@ contains contact_pair_friction_value = max(ZERO, contact_pair_friction(pair)) end function contact_pair_friction_value + real(rk) function contact_pair_search_value(pair) + integer, intent(in) :: pair + + contact_pair_search_value = ZERO + if (.not. allocated(contact_pair_search)) return + if (pair .lt. 1 .or. pair .gt. size(contact_pair_search)) return + contact_pair_search_value = max(ZERO, contact_pair_search(pair)) + end function contact_pair_search_value + + subroutine contact_pair_candidate(pair, sf, mf, nf, max_nodes, fnnode, fconn, & + elem_id, x, vnod, normal, center, radius, & + gap, vn, pair_weight, active, ierr) + integer, intent(in) :: pair + integer, intent(in) :: sf + integer, intent(in) :: mf + integer, intent(in) :: nf + integer, intent(in) :: max_nodes + integer, intent(in) :: fnnode(nf) + integer, intent(in) :: fconn(max_nodes,nf) + integer, intent(in) :: elem_id(nf) + real(rk), intent(in) :: x(NDIM,max_nodes,nf) + real(rk), intent(in) :: vnod(NDIM,max_nodes,nf) + real(rk), intent(in) :: normal(NDIM,nf) + real(rk), intent(in) :: center(NDIM,nf) + real(rk), intent(in) :: radius(nf) + real(rk), intent(out) :: gap + real(rk), intent(out) :: vn + real(rk), intent(out) :: pair_weight + logical, intent(out) :: active + integer, intent(out) :: ierr + + active = .false. + gap = ZERO + vn = ZERO + pair_weight = ZERO + + if (sf .eq. mf) then + ierr = FEM_SUCCESS + return + end if + if (.not. facet_target_matches(elem_id(mf), contact_pair_master(pair))) then + ierr = FEM_SUCCESS + return + end if + if (.not. contact_spatial_candidate(pair, sf, mf, nf, center, radius)) then + ierr = FEM_SUCCESS + return + end if + if (facet_nodes_share(max_nodes, fnnode(sf), fconn(:,sf), & + fnnode(mf), fconn(:,mf))) then + ierr = FEM_SUCCESS + return + end if + + call pair_contact_gap(pair, sf, mf, nf, max_nodes, fnnode, & + x, vnod, normal, gap, vn, pair_weight, ierr) + if (ierr .ne. FEM_SUCCESS) return + active = gap .lt. ZERO .and. pair_weight .gt. tiny(ONE) + ierr = FEM_SUCCESS + end subroutine contact_pair_candidate + + subroutine contact_grid_dimensions(pair, nf, elem_id, center, radius, & + grid_min, grid_h, grid_nx, grid_ny, & + grid_nz, max_master_radius, use_grid) + integer, intent(in) :: pair + integer, intent(in) :: nf + integer, intent(in) :: elem_id(nf) + real(rk), intent(in) :: center(NDIM,nf) + real(rk), intent(in) :: radius(nf) + real(rk), intent(out) :: grid_min(NDIM) + real(rk), intent(out) :: grid_h(NDIM) + integer, intent(out) :: grid_nx + integer, intent(out) :: grid_ny + integer, intent(out) :: grid_nz + real(rk), intent(out) :: max_master_radius + logical, intent(out) :: use_grid + real(rk) :: bbox_min(NDIM) + real(rk) :: bbox_max(NDIM) + real(rk) :: extent(NDIM) + real(rk) :: pad + integer :: mf + integer :: nmaster + integer :: nc + + use_grid = .false. + grid_min = ZERO + grid_h = ONE + grid_nx = 1 + grid_ny = 1 + grid_nz = 1 + max_master_radius = ZERO + bbox_min = huge(ONE) + bbox_max = -huge(ONE) + nmaster = 0 + + do mf = 1, nf + if (.not. facet_target_matches(elem_id(mf), contact_pair_master(pair))) cycle + nmaster = nmaster + 1 + bbox_min = min(bbox_min, center(:,mf)) + bbox_max = max(bbox_max, center(:,mf)) + max_master_radius = max(max_master_radius, radius(mf)) + end do + + if (nmaster .le. 16) return + + nc = int(real(nmaster, rk) ** (ONE / 3.0_rk)) + 1 + nc = max(2, min(32, nc)) + pad = max_master_radius + contact_pair_search_value(pair) + sqrt(tiny(ONE)) + grid_min = bbox_min - pad + extent = bbox_max - bbox_min + 2.0_rk * pad + grid_h(1) = max(extent(1) / real(nc, rk), sqrt(tiny(ONE))) + grid_h(2) = max(extent(2) / real(nc, rk), sqrt(tiny(ONE))) + grid_h(3) = max(extent(3) / real(nc, rk), sqrt(tiny(ONE))) + grid_nx = nc + grid_ny = nc + grid_nz = nc + use_grid = .true. + end subroutine contact_grid_dimensions + + subroutine contact_grid_fill(pair, nf, elem_id, center, grid_min, grid_h, & + grid_nx, grid_ny, grid_nz, grid_head, grid_next) + integer, intent(in) :: pair + integer, intent(in) :: nf + integer, intent(in) :: elem_id(nf) + real(rk), intent(in) :: center(NDIM,nf) + real(rk), intent(in) :: grid_min(NDIM) + real(rk), intent(in) :: grid_h(NDIM) + integer, intent(in) :: grid_nx + integer, intent(in) :: grid_ny + integer, intent(in) :: grid_nz + integer, intent(inout) :: grid_head(grid_nx*grid_ny*grid_nz) + integer, intent(inout) :: grid_next(nf) + integer :: mf + integer :: ix + integer :: iy + integer :: iz + integer :: cell + + grid_head = 0 + grid_next = 0 + do mf = 1, nf + if (.not. facet_target_matches(elem_id(mf), contact_pair_master(pair))) cycle + ix = contact_grid_axis(center(1,mf), grid_min(1), grid_h(1), grid_nx) + iy = contact_grid_axis(center(2,mf), grid_min(2), grid_h(2), grid_ny) + iz = contact_grid_axis(center(3,mf), grid_min(3), grid_h(3), grid_nz) + cell = contact_grid_cell(ix, iy, iz, grid_nx, grid_ny, grid_nz) + grid_next(mf) = grid_head(cell) + grid_head(cell) = mf + end do + end subroutine contact_grid_fill + + subroutine contact_grid_range(point, radius_value, grid_min, grid_h, & + grid_nx, grid_ny, grid_nz, ix0, ix1, & + iy0, iy1, iz0, iz1) + real(rk), intent(in) :: point(NDIM) + real(rk), intent(in) :: radius_value + real(rk), intent(in) :: grid_min(NDIM) + real(rk), intent(in) :: grid_h(NDIM) + integer, intent(in) :: grid_nx + integer, intent(in) :: grid_ny + integer, intent(in) :: grid_nz + integer, intent(out) :: ix0 + integer, intent(out) :: ix1 + integer, intent(out) :: iy0 + integer, intent(out) :: iy1 + integer, intent(out) :: iz0 + integer, intent(out) :: iz1 + + ix0 = contact_grid_axis(point(1) - radius_value, grid_min(1), grid_h(1), grid_nx) + ix1 = contact_grid_axis(point(1) + radius_value, grid_min(1), grid_h(1), grid_nx) + iy0 = contact_grid_axis(point(2) - radius_value, grid_min(2), grid_h(2), grid_ny) + iy1 = contact_grid_axis(point(2) + radius_value, grid_min(2), grid_h(2), grid_ny) + iz0 = contact_grid_axis(point(3) - radius_value, grid_min(3), grid_h(3), grid_nz) + iz1 = contact_grid_axis(point(3) + radius_value, grid_min(3), grid_h(3), grid_nz) + end subroutine contact_grid_range + + integer function contact_grid_axis(value, axis_min, axis_h, ncell) + real(rk), intent(in) :: value + real(rk), intent(in) :: axis_min + real(rk), intent(in) :: axis_h + integer, intent(in) :: ncell + real(rk) :: scaled + + scaled = (value - axis_min) / max(axis_h, sqrt(tiny(ONE))) + contact_grid_axis = int(scaled) + 1 + if (contact_grid_axis .lt. 1) contact_grid_axis = 1 + if (contact_grid_axis .gt. ncell) contact_grid_axis = ncell + end function contact_grid_axis + + integer function contact_grid_cell(ix, iy, iz, nx, ny, nz) + integer, intent(in) :: ix + integer, intent(in) :: iy + integer, intent(in) :: iz + integer, intent(in) :: nx + integer, intent(in) :: ny + integer, intent(in) :: nz + + if (nz .le. 0) then + contact_grid_cell = 1 + return + end if + contact_grid_cell = ix + (iy - 1) * nx + (iz - 1) * nx * ny + end function contact_grid_cell + function normalized_contact_normal(raw_normal, ierr) result(nrm) real(rk), intent(in) :: raw_normal(NDIM) integer, intent(out) :: ierr @@ -719,13 +1213,10 @@ contains real(rk) :: mc(NDIM) real(rk) :: sv(NDIM) real(rk) :: mv(NDIM) - real(rk) :: projection(NDIM) real(rk) :: nrm(NDIM) real(rk) :: nlen - real(rk) :: radius real(rk) :: search - real(rk) :: dist - real(rk) :: support + real(rk) :: overlap_area pair_weight = ZERO call facet_center_velocity(sf, nf, max_nodes, fnnode, x, vnod, sc, sv) @@ -746,26 +1237,270 @@ contains return end if - search = contact_pair_search(pair) - radius = facet_radius_value(mf, nf, max_nodes, fnnode, x, mc) + search = ZERO + if (allocated(contact_pair_search)) then + if (pair .ge. 1 .and. pair .le. size(contact_pair_search)) then + search = contact_pair_search(pair) + end if + end if if (search .gt. ZERO .and. -gap .gt. search) then gap = ZERO ierr = FEM_SUCCESS return end if - projection = sc - gap * nrm - dist = sqrt(sum((projection - mc) * (projection - mc))) - support = radius + max(search, tiny(ONE)) - if (dist .gt. support) then + call contact_projected_overlap(sf, mf, nf, max_nodes, fnnode, x, nrm, & + overlap_area, ierr) + if (ierr .ne. FEM_SUCCESS) return + + if (overlap_area .le. tiny(ONE)) then gap = ZERO else - pair_weight = max(tiny(ONE), ONE - dist / max(support, tiny(ONE))) + pair_weight = overlap_area end if ierr = FEM_SUCCESS end subroutine pair_contact_gap + subroutine contact_projected_overlap(sf, mf, nf, max_nodes, fnnode, x, nrm, & + overlap_area, ierr) + integer, intent(in) :: sf + integer, intent(in) :: mf + integer, intent(in) :: nf + integer, intent(in) :: max_nodes + integer, intent(in) :: fnnode(nf) + real(rk), intent(in) :: x(NDIM,max_nodes,nf) + real(rk), intent(in) :: nrm(NDIM) + real(rk), intent(out) :: overlap_area + integer, intent(out) :: ierr + real(rk) :: basis1(NDIM) + real(rk) :: basis2(NDIM) + real(rk) :: origin(NDIM) + real(rk) :: point(NDIM) + real(rk) :: mpoly(2,CONTACT_MAX_CLIP) + real(rk) :: poly(2,CONTACT_MAX_CLIP) + real(rk) :: clipped(2,CONTACT_MAX_CLIP) + real(rk) :: signed_area + integer :: i + integer :: j + integer :: npoly + integer :: nclip + + overlap_area = ZERO + if (fnnode(sf) .gt. CONTACT_MAX_CLIP .or. & + fnnode(mf) .gt. CONTACT_MAX_CLIP) then + call error_set(FEM_ERR_COUPLING, 'contact clipping polygon buffer is too small', ierr) + return + end if + + origin = x(:,1,mf) + call contact_build_basis(mf, nf, max_nodes, fnnode, x, nrm, basis1, basis2, ierr) + if (ierr .ne. FEM_SUCCESS) return + + do i = 1, fnnode(mf) + point = x(:,i,mf) - origin + mpoly(1,i) = dot_product(point, basis1) + mpoly(2,i) = dot_product(point, basis2) + end do + + do i = 1, fnnode(sf) + point = x(:,i,sf) - dot_product(nrm, x(:,i,sf) - origin) * nrm - origin + poly(1,i) = dot_product(point, basis1) + poly(2,i) = dot_product(point, basis2) + end do + + npoly = fnnode(sf) + signed_area = polygon_signed_area(fnnode(mf), mpoly) + if (abs(signed_area) .le. tiny(ONE)) then + ierr = FEM_SUCCESS + return + end if + + do i = 1, fnnode(mf) + j = i + 1 + if (j .gt. fnnode(mf)) j = 1 + call clip_polygon_halfplane(poly, npoly, mpoly(:,i), mpoly(:,j), & + signed_area, clipped, nclip) + if (nclip .le. 2) then + overlap_area = ZERO + ierr = FEM_SUCCESS + return + end if + npoly = nclip + poly(:,1:npoly) = clipped(:,1:npoly) + end do + + overlap_area = abs(polygon_signed_area(npoly, poly)) + ierr = FEM_SUCCESS + end subroutine contact_projected_overlap + + subroutine contact_build_basis(mf, nf, max_nodes, fnnode, x, nrm, basis1, basis2, ierr) + integer, intent(in) :: mf + integer, intent(in) :: nf + integer, intent(in) :: max_nodes + integer, intent(in) :: fnnode(nf) + real(rk), intent(in) :: x(NDIM,max_nodes,nf) + real(rk), intent(in) :: nrm(NDIM) + real(rk), intent(out) :: basis1(NDIM) + real(rk), intent(out) :: basis2(NDIM) + integer, intent(out) :: ierr + real(rk) :: trial(NDIM) + real(rk) :: norm_b + + if (fnnode(mf) .ge. 2) then + trial = x(:,2,mf) - x(:,1,mf) + trial = trial - dot_product(trial, nrm) * nrm + else + trial = ZERO + end if + + norm_b = sqrt(sum(trial * trial)) + if (norm_b .le. tiny(ONE)) then + if (abs(nrm(1)) .lt. 0.9_rk) then + trial = (/ ONE, ZERO, ZERO /) + else + trial = (/ ZERO, ONE, ZERO /) + end if + trial = trial - dot_product(trial, nrm) * nrm + norm_b = sqrt(sum(trial * trial)) + end if + + if (norm_b .le. tiny(ONE)) then + call error_set(FEM_ERR_COUPLING, 'contact clipping basis is singular', ierr) + return + end if + + basis1 = trial / norm_b + call cross_contact(nrm, basis1, basis2) + norm_b = sqrt(sum(basis2 * basis2)) + if (norm_b .le. tiny(ONE)) then + call error_set(FEM_ERR_COUPLING, 'contact clipping basis has zero binormal', ierr) + return + end if + basis2 = basis2 / norm_b + ierr = FEM_SUCCESS + end subroutine contact_build_basis + + real(rk) function polygon_signed_area(npoly, poly) + integer, intent(in) :: npoly + real(rk), intent(in) :: poly(2,CONTACT_MAX_CLIP) + integer :: i + integer :: j + + polygon_signed_area = ZERO + if (npoly .le. 2) return + do i = 1, npoly + j = i + 1 + if (j .gt. npoly) j = 1 + polygon_signed_area = polygon_signed_area + & + poly(1,i) * poly(2,j) - poly(2,i) * poly(1,j) + end do + polygon_signed_area = HALF * polygon_signed_area + end function polygon_signed_area + + subroutine clip_polygon_halfplane(poly_in, nin, edge_a, edge_b, orient_area, & + poly_out, nout) + real(rk), intent(in) :: poly_in(2,CONTACT_MAX_CLIP) + integer, intent(in) :: nin + real(rk), intent(in) :: edge_a(2) + real(rk), intent(in) :: edge_b(2) + real(rk), intent(in) :: orient_area + real(rk), intent(out) :: poly_out(2,CONTACT_MAX_CLIP) + integer, intent(out) :: nout + real(rk) :: prev(2) + real(rk) :: curr(2) + real(rk) :: inter(2) + logical :: prev_inside + logical :: curr_inside + integer :: i + + nout = 0 + if (nin .le. 0) return + + prev = poly_in(:,nin) + prev_inside = clip_point_inside(prev, edge_a, edge_b, orient_area) + do i = 1, nin + curr = poly_in(:,i) + curr_inside = clip_point_inside(curr, edge_a, edge_b, orient_area) + if (curr_inside) then + if (.not. prev_inside) then + call clip_line_intersection(prev, curr, edge_a, edge_b, inter) + call clip_append_point(inter, poly_out, nout) + end if + call clip_append_point(curr, poly_out, nout) + else if (prev_inside) then + call clip_line_intersection(prev, curr, edge_a, edge_b, inter) + call clip_append_point(inter, poly_out, nout) + end if + prev = curr + prev_inside = curr_inside + end do + end subroutine clip_polygon_halfplane + + logical function clip_point_inside(point, edge_a, edge_b, orient_area) + real(rk), intent(in) :: point(2) + real(rk), intent(in) :: edge_a(2) + real(rk), intent(in) :: edge_b(2) + real(rk), intent(in) :: orient_area + real(rk) :: cross_val + + cross_val = (edge_b(1) - edge_a(1)) * (point(2) - edge_a(2)) - & + (edge_b(2) - edge_a(2)) * (point(1) - edge_a(1)) + if (orient_area .ge. ZERO) then + clip_point_inside = cross_val .ge. -1.0e-12_rk + else + clip_point_inside = cross_val .le. 1.0e-12_rk + end if + end function clip_point_inside + + subroutine clip_line_intersection(p0, p1, edge_a, edge_b, intersection) + real(rk), intent(in) :: p0(2) + real(rk), intent(in) :: p1(2) + real(rk), intent(in) :: edge_a(2) + real(rk), intent(in) :: edge_b(2) + real(rk), intent(out) :: intersection(2) + real(rk) :: dir(2) + real(rk) :: edge(2) + real(rk) :: denom + real(rk) :: t + + dir = p1 - p0 + edge = edge_b - edge_a + denom = edge(1) * dir(2) - edge(2) * dir(1) + if (abs(denom) .le. tiny(ONE)) then + intersection = HALF * (p0 + p1) + return + end if + t = (edge(1) * (edge_a(2) - p0(2)) - & + edge(2) * (edge_a(1) - p0(1))) / denom + t = max(ZERO, min(ONE, t)) + intersection = p0 + t * dir + end subroutine clip_line_intersection + + subroutine clip_append_point(point, poly, nout) + real(rk), intent(in) :: point(2) + real(rk), intent(inout) :: poly(2,CONTACT_MAX_CLIP) + integer, intent(inout) :: nout + + if (nout .ge. CONTACT_MAX_CLIP) return + if (nout .gt. 0) then + if (sum((poly(:,nout) - point) * (poly(:,nout) - point)) .le. & + 1.0e-24_rk) return + end if + nout = nout + 1 + poly(:,nout) = point + end subroutine clip_append_point + + subroutine cross_contact(a, b, c) + real(rk), intent(in) :: a(NDIM) + real(rk), intent(in) :: b(NDIM) + real(rk), intent(out) :: c(NDIM) + + c(1) = a(2) * b(3) - a(3) * b(2) + c(2) = a(3) * b(1) - a(1) * b(3) + c(3) = a(1) * b(2) - a(2) * b(1) + end subroutine cross_contact + subroutine facet_center_velocity(idx, nf, max_nodes, fnnode, x, vnod, & center, vel_center) integer, intent(in) :: idx diff --git a/src/interface/fem_c_api.c b/src/interface/fem_c_api.c index e25ee03..1aa4d70 100644 --- a/src/interface/fem_c_api.c +++ b/src/interface/fem_c_api.c @@ -20,6 +20,7 @@ #define F_ADVANCE_EXPLICIT FC_GLOBAL(femlite_f_advance_explicit, FEMLITE_F_ADVANCE_EXPLICIT) #define F_GET_TIME FC_GLOBAL(femlite_f_get_time, FEMLITE_F_GET_TIME) #define F_GET_SIZE FC_GLOBAL(femlite_f_get_size, FEMLITE_F_GET_SIZE) +#define F_GET_CONTACT_SUMMARY FC_GLOBAL(femlite_f_get_contact_summary, FEMLITE_F_GET_CONTACT_SUMMARY) #define F_CLEAR_SPH FC_GLOBAL(femlite_f_clear_sph, FEMLITE_F_CLEAR_SPH) #define F_APPLY_SPH_NODES FC_GLOBAL(femlite_f_apply_sph_nodes, FEMLITE_F_APPLY_SPH_NODES) #define F_GET_FACET_COUNT FC_GLOBAL(femlite_f_get_facet_count, FEMLITE_F_GET_FACET_COUNT) @@ -41,6 +42,12 @@ extern void F_ESTIMATE_DT(double *dtcrit, int *ierr); extern void F_ADVANCE_EXPLICIT(double *dt, int *ierr); extern void F_GET_TIME(double *time, int *step, int *ierr); extern void F_GET_SIZE(int *num_nodes, int *num_elems, int *num_dof, int *ierr); +extern void F_GET_CONTACT_SUMMARY(int *active_count, + double *work_step, + double *work_total, + double *max_penetration, + double *force_norm, + int *ierr); extern void F_CLEAR_SPH(int *ierr); extern void F_APPLY_SPH_NODES(int *num_force_nodes, const int *node_ids, @@ -198,6 +205,22 @@ int femlite_get_model_size(int *num_nodes, int *num_elems, int *num_dof) return ierr; } +int femlite_get_contact_summary(int *active_count, + double *work_step, + double *work_total, + double *max_penetration, + double *force_norm) +{ + int ierr = 0; + if (active_count == NULL || work_step == NULL || work_total == NULL || + max_penetration == NULL || force_norm == NULL) { + return -1; + } + F_GET_CONTACT_SUMMARY(active_count, work_step, work_total, + max_penetration, force_norm, &ierr); + return ierr; +} + int femlite_clear_sph_forces(void) { int ierr = 0; diff --git a/src/interface/fem_fortran_bridge.f90 b/src/interface/fem_fortran_bridge.f90 index 5ec8bd6..ada8ec0 100644 --- a/src/interface/fem_fortran_bridge.f90 +++ b/src/interface/fem_fortran_bridge.f90 @@ -188,6 +188,22 @@ subroutine femlite_f_get_facet_count(num_facets, max_fnodes, ierr) call fem_get_boundary_facet_count(num_facets, max_fnodes, ierr) end subroutine femlite_f_get_facet_count +subroutine femlite_f_get_contact_summary(active_count, work_step, work_total, & + max_penetration, force_norm, ierr) + use fem_api + use fem_precision + implicit none + integer, intent(out) :: active_count + real(rk), intent(out) :: work_step + real(rk), intent(out) :: work_total + real(rk), intent(out) :: max_penetration + real(rk), intent(out) :: force_norm + integer, intent(out) :: ierr + + call fem_get_contact_summary(active_count, work_step, work_total, & + max_penetration, force_norm, ierr) +end subroutine femlite_f_get_contact_summary + subroutine femlite_f_get_facets(nfacet, max_fnodes, facet_id, elem_id, & face_id, facet_nnode, facet_conn, x, vnod, & normal, area, ierr) diff --git a/src/mesh/fem_database.f90 b/src/mesh/fem_database.f90 index 1185d76..4402935 100644 --- a/src/mesh/fem_database.f90 +++ b/src/mesh/fem_database.f90 @@ -147,6 +147,15 @@ module fem_database real(rk), allocatable :: contact_pair_damping(:) real(rk), allocatable :: contact_pair_search(:) real(rk), allocatable :: contact_pair_friction(:) + integer :: contact_active_count = 0 + real(rk) :: contact_work_step = ZERO + real(rk) :: contact_work_total = ZERO + real(rk) :: contact_max_penetration = ZERO + real(rk) :: contact_force_norm = ZERO + integer, allocatable :: contact_pair_active(:) + real(rk), allocatable :: contact_pair_work(:) + real(rk), allocatable :: contact_pair_max_penetration(:) + real(rk), allocatable :: contact_pair_force_norm(:) contains @@ -614,13 +623,25 @@ contains if (allocated(contact_pair_damping)) deallocate(contact_pair_damping) if (allocated(contact_pair_search)) deallocate(contact_pair_search) if (allocated(contact_pair_friction)) deallocate(contact_pair_friction) + if (allocated(contact_pair_active)) deallocate(contact_pair_active) + if (allocated(contact_pair_work)) deallocate(contact_pair_work) + if (allocated(contact_pair_max_penetration)) deallocate(contact_pair_max_penetration) + if (allocated(contact_pair_force_norm)) deallocate(contact_pair_force_norm) ncontact_pair = num_pairs + contact_active_count = 0 + contact_work_step = ZERO + contact_work_total = ZERO + contact_max_penetration = ZERO + contact_force_norm = ZERO if (num_pairs .gt. 0) then allocate(contact_pair_slave(num_pairs), contact_pair_master(num_pairs), & contact_pair_penalty(num_pairs), contact_pair_damping(num_pairs), & contact_pair_search(num_pairs), contact_pair_friction(num_pairs), & + contact_pair_active(num_pairs), contact_pair_work(num_pairs), & + contact_pair_max_penetration(num_pairs), & + contact_pair_force_norm(num_pairs), & stat=stat) if (stat .ne. 0) then ncontact_pair = 0 @@ -633,6 +654,10 @@ contains contact_pair_damping = ZERO contact_pair_search = ZERO contact_pair_friction = ZERO + contact_pair_active = 0 + contact_pair_work = ZERO + contact_pair_max_penetration = ZERO + contact_pair_force_norm = ZERO end if ierr = FEM_SUCCESS @@ -828,6 +853,15 @@ contains if (allocated(contact_pair_damping)) contact_pair_damping = ZERO if (allocated(contact_pair_search)) contact_pair_search = ZERO if (allocated(contact_pair_friction)) contact_pair_friction = ZERO + contact_active_count = 0 + contact_work_step = ZERO + contact_work_total = ZERO + contact_max_penetration = ZERO + contact_force_norm = ZERO + if (allocated(contact_pair_active)) contact_pair_active = 0 + if (allocated(contact_pair_work)) contact_pair_work = ZERO + if (allocated(contact_pair_max_penetration)) contact_pair_max_penetration = ZERO + if (allocated(contact_pair_force_norm)) contact_pair_force_norm = ZERO ierr = FEM_SUCCESS end subroutine database_initialize @@ -1620,6 +1654,10 @@ contains if (allocated(contact_pair_damping)) deallocate(contact_pair_damping) if (allocated(contact_pair_search)) deallocate(contact_pair_search) if (allocated(contact_pair_friction)) deallocate(contact_pair_friction) + if (allocated(contact_pair_active)) deallocate(contact_pair_active) + if (allocated(contact_pair_work)) deallocate(contact_pair_work) + if (allocated(contact_pair_max_penetration)) deallocate(contact_pair_max_penetration) + if (allocated(contact_pair_force_norm)) deallocate(contact_pair_force_norm) nnode = 0 nelem = 0 @@ -1640,6 +1678,11 @@ contains nmpc_term = 0 ncontact_plane = 0 ncontact_pair = 0 + contact_active_count = 0 + contact_work_step = ZERO + contact_work_total = ZERO + contact_max_penetration = ZERO + contact_force_norm = ZERO ierr = FEM_SUCCESS end subroutine database_finalize diff --git a/src/output/fem_output_csv.f90 b/src/output/fem_output_csv.f90 index 995997b..e26ee34 100644 --- a/src/output/fem_output_csv.f90 +++ b/src/output/fem_output_csv.f90 @@ -69,7 +69,9 @@ contains if (.not. exists .and. .not. history_header_written) then write(unit_id,'(A)',iostat=ios) & - 'step,time,total_mass,kinetic_energy,max_displacement,max_velocity,max_acceleration' + 'step,time,total_mass,kinetic_energy,max_displacement,max_velocity,'// & + 'max_acceleration,contact_active_count,contact_work_step,'// & + 'contact_work_total,contact_max_penetration,contact_force_norm' if (ios .ne. 0) then close(unit_id) call error_set(FEM_ERR_OUTPUT, 'failed to write history CSV header', ierr) @@ -77,9 +79,12 @@ contains end if end if - write(unit_id,'(I12,A,5(ES24.16,A),ES24.16)',iostat=ios) step, ',', time, ',', & + write(unit_id,'(I12,A,5(ES24.16,A),ES24.16,A,I12,4(A,ES24.16))',iostat=ios) & + step, ',', time, ',', & total_mass, ',', kinetic_energy, ',', max_displacement, ',', & - max_velocity, ',', max_acceleration + max_velocity, ',', max_acceleration, ',', contact_active_count, & + ',', contact_work_step, ',', contact_work_total, ',', & + contact_max_penetration, ',', contact_force_norm if (ios .ne. 0) then close(unit_id) call error_set(FEM_ERR_OUTPUT, 'failed to write history CSV row', ierr) @@ -98,6 +103,9 @@ contains call output_csv_write_elements(step, ierr) if (ierr .ne. FEM_SUCCESS) return + call output_csv_write_contact(step, ierr) + if (ierr .ne. FEM_SUCCESS) return + ierr = FEM_SUCCESS end subroutine output_csv_write @@ -298,6 +306,76 @@ contains ierr = FEM_SUCCESS end subroutine output_csv_write_elements + subroutine output_csv_write_contact(step, ierr) + integer, intent(in) :: step + integer, intent(out) :: ierr + character(len=512) :: filename + integer :: unit_id + integer :: ios + integer :: pair + integer :: active + real(rk) :: max_pen + real(rk) :: force_sum + real(rk) :: work_sum + + if (ncontact_plane .le. 0 .and. ncontact_pair .le. 0) then + ierr = FEM_SUCCESS + return + end if + + call output_csv_step_filename('contact', step, filename) + unit_id = 66 + open(unit=unit_id, file=trim(filename), status='replace', & + action='write', iostat=ios) + if (ios .ne. 0) then + call error_set(FEM_ERR_OUTPUT, 'failed to open contact CSV output', ierr) + return + end if + + write(unit_id,'(A)',iostat=ios) & + 'kind,pair_id,active_count,max_penetration,force_norm,work_estimate,cumulative_work' + if (ios .ne. 0) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, 'failed to write contact CSV header', ierr) + return + end if + + write(unit_id,'(A,A,I12,A,I12,4(A,ES24.16))',iostat=ios) & + 'SUMMARY', ',', 0, ',', contact_active_count, & + ',', contact_max_penetration, ',', contact_force_norm, & + ',', contact_work_step, ',', contact_work_total + if (ios .ne. 0) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, 'failed to write contact CSV summary row', ierr) + return + end if + + do pair = 1, ncontact_pair + active = 0 + max_pen = ZERO + force_sum = ZERO + work_sum = ZERO + if (allocated(contact_pair_active)) active = contact_pair_active(pair) + if (allocated(contact_pair_max_penetration)) then + max_pen = contact_pair_max_penetration(pair) + end if + if (allocated(contact_pair_force_norm)) force_sum = contact_pair_force_norm(pair) + if (allocated(contact_pair_work)) work_sum = contact_pair_work(pair) + + write(unit_id,'(A,A,I12,A,I12,4(A,ES24.16))',iostat=ios) & + 'PAIR', ',', pair, ',', active, ',', max_pen, ',', force_sum, & + ',', work_sum, ',', ZERO + if (ios .ne. 0) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, 'failed to write contact CSV pair row', ierr) + return + end if + end do + + close(unit_id) + ierr = FEM_SUCCESS + end subroutine output_csv_write_contact + subroutine output_csv_average_element(elem, sig, eps, peps, eqps, damage) integer, intent(in) :: elem real(rk), intent(out) :: sig(NSTRESS) diff --git a/tests/interface/test_c_api.c b/tests/interface/test_c_api.c index 08f0602..2fa77a4 100644 --- a/tests/interface/test_c_api.c +++ b/tests/interface/test_c_api.c @@ -29,6 +29,7 @@ int main(void) int nfacet = 0; int max_face_nodes = 0; int step = 0; + int active_contact = -1; int node_ids[1] = {2}; int facet_id[8]; int elem_id[8]; @@ -45,6 +46,10 @@ int main(void) double acc[3] = {0.0, 0.0, 0.0}; double dtcrit = 0.0; double time = 0.0; + double contact_work_step = -1.0; + double contact_work_total = -1.0; + double contact_max_penetration = -1.0; + double contact_force_norm = -1.0; ierr = femlite_initialize(); if (ierr != 0) return check_ierr(ierr, 1); @@ -62,6 +67,15 @@ int main(void) if (ierr != 0) return check_ierr(ierr, 6); if (nnode != 4 || nelem != 1 || ndof != 12) return 7; + ierr = femlite_get_contact_summary(&active_contact, &contact_work_step, + &contact_work_total, + &contact_max_penetration, + &contact_force_norm); + if (ierr != 0) return check_ierr(ierr, 24); + if (active_contact != 0 || contact_work_step != 0.0 || + contact_work_total != 0.0 || contact_max_penetration != 0.0 || + contact_force_norm != 0.0) return 25; + ierr = femlite_compute_lumped_mass(); if (ierr != 0) return check_ierr(ierr, 8); ierr = femlite_estimate_stable_dt(&dtcrit); diff --git a/tests/module/test_contact.f90 b/tests/module/test_contact.f90 index 7aaaea0..85c0f70 100644 --- a/tests/module/test_contact.f90 +++ b/tests/module/test_contact.f90 @@ -17,6 +17,8 @@ program test_contact call check_surface_pair_tangent() call check_surface_pair_friction() call check_surface_pair_multimaster() + call check_pair_clipped() + call check_pair_grid() contains @@ -84,6 +86,11 @@ contains subroutine check_explicit_contact_step() integer :: ierr integer :: dof + integer :: active_count + real(rk) :: work_step + real(rk) :: work_total + real(rk) :: max_penetration + real(rk) :: force_norm call fem_initialize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(20) @@ -108,9 +115,16 @@ contains call check_close(a(dof), ONE, 24) call check_close(v(dof), 0.10_rk, 25) call check_close(u(dof), -0.095_rk, 26) + call fem_get_contact_summary(active_count, work_step, work_total, & + max_penetration, force_norm, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(27) + if (active_count .ne. 1) call fail(28) + call check_close(max_penetration, 0.10_rk, 29) + call check_close(force_norm, ONE, 30) + call check_close(work_step, 0.05_rk, 31) call fem_finalize(ierr) - if (ierr .ne. FEM_SUCCESS) call fail(27) + if (ierr .ne. FEM_SUCCESS) call fail(32) end subroutine check_explicit_contact_step subroutine check_surface_pair_force() @@ -245,6 +259,74 @@ contains if (ierr .ne. FEM_SUCCESS) call fail(65) end subroutine check_surface_pair_multimaster + subroutine check_pair_clipped() + integer :: ierr + integer :: node + integer :: dof + + call setup_contact_shell_pair(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(70) + + do node = 5, 8 + coord0(1,node) = coord0(1,node) + 0.5_rk + end do + coord = coord0 + + call contact_apply_plane_forces(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(71) + + do node = 5, 8 + dof = dof_id(3,node) + call check_close(fcontact(dof), 1.25_rk, 72) + end do + do node = 1, 4 + dof = dof_id(3,node) + call check_close(fcontact(dof), -1.25_rk, 73) + end do + + if (contact_active_count .ne. 1) call fail(74) + if (contact_pair_active(1) .ne. 1) call fail(75) + call check_close(contact_max_penetration, 0.01_rk, 76) + call check_close(contact_pair_max_penetration(1), 0.01_rk, 77) + call check_close(contact_force_norm, 5.0_rk, 78) + call check_close(contact_pair_force_norm(1), 5.0_rk, 79) + call check_close(contact_work_step, 0.025_rk, 80) + call check_close(contact_pair_work(1), 0.025_rk, 81) + + call database_finalize(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(82) + end subroutine check_pair_clipped + + subroutine check_pair_grid() + integer :: ierr + integer :: node + integer :: dof + + call setup_contact_grid_pair(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(90) + + call contact_apply_plane_forces(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(91) + + do node = 73, 76 + dof = dof_id(3,node) + call check_close(fcontact(dof), 2.5_rk, 92) + end do + do node = 1, 4 + dof = dof_id(3,node) + call check_close(fcontact(dof), -2.5_rk, 93) + end do + do node = 5, 72 + dof = dof_id(3,node) + call check_close(fcontact(dof), ZERO, 94) + end do + if (contact_active_count .ne. 1) call fail(95) + call check_close(contact_force_norm, 10.0_rk, 96) + + call database_finalize(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(97) + end subroutine check_pair_grid + subroutine setup_basic_nodes(num_nodes, ierr) integer, intent(in) :: num_nodes integer, intent(out) :: ierr @@ -399,6 +481,84 @@ contains ierr = FEM_SUCCESS end subroutine setup_contact_shell_multimaster + subroutine setup_contact_grid_pair(ierr) + integer, intent(out) :: ierr + integer :: master + integer :: node_base + integer :: xshift + + call database_allocate_model(76, 19, 0, 2, 0, 19, 1, 0, 1, & + 0, 0, 0, 0, 0, ierr) + if (ierr .ne. FEM_SUCCESS) return + + do master = 1, 18 + node_base = 4 * (master - 1) + xshift = 10 * (master - 1) + node_id_ext(node_base+1:node_base+4) = & + (/ node_base + 1, node_base + 2, node_base + 3, node_base + 4 /) + coord0(:,node_base+1) = (/ real(xshift, rk), ZERO, ZERO /) + coord0(:,node_base+2) = (/ real(xshift, rk) + ONE, ZERO, ZERO /) + coord0(:,node_base+3) = (/ real(xshift, rk) + ONE, ONE, ZERO /) + coord0(:,node_base+4) = (/ real(xshift, rk), ONE, ZERO /) + elem_id_ext(master) = master + elem_type(master) = 'S4' + elem_nnode(master) = 4 + elem_conn(:,master) = 0 + elem_conn(1:4,master) = & + (/ node_base + 1, node_base + 2, node_base + 3, node_base + 4 /) + elem_mat(master) = 1 + elem_sec(master) = 1 + end do + + node_id_ext(73:76) = (/ 73, 74, 75, 76 /) + coord0(:,73) = (/ ZERO, ZERO, -0.01_rk /) + coord0(:,74) = (/ ONE, ZERO, -0.01_rk /) + coord0(:,75) = (/ ONE, ONE, -0.01_rk /) + coord0(:,76) = (/ ZERO, ONE, -0.01_rk /) + coord = coord0 + + elem_id_ext(19) = 19 + elem_type(19) = 'S4' + elem_nnode(19) = 4 + elem_conn(:,19) = 0 + elem_conn(1:4,19) = (/ 73, 74, 75, 76 /) + elem_mat(19) = 1 + elem_sec(19) = 1 + + elset_name(1) = 'MASTER' + elset_start(1) = 1 + elset_count(1) = 18 + do master = 1, 18 + elset_items(master) = master + end do + elset_name(2) = 'SLAVE' + elset_start(2) = 19 + elset_count(2) = 1 + elset_items(19) = 19 + + mat_name(1) = 'MAT' + mat_density(1) = ONE + mat_e(1) = 30.0_rk + mat_nu(1) = 0.25_rk + + section_type(1) = 'SHELL' + section_elset_name(1) = 'ALL' + section_material_name(1) = 'MAT' + section_thickness(1) = 0.1_rk + + call database_assign_dofs(ierr) + if (ierr .ne. FEM_SUCCESS) return + call database_allocate_contact_pair(1, ierr) + if (ierr .ne. FEM_SUCCESS) return + contact_pair_slave(1) = 'SLAVE' + contact_pair_master(1) = 'MASTER' + contact_pair_penalty(1) = 1000.0_rk + contact_pair_damping(1) = ZERO + contact_pair_search(1) = 0.1_rk + contact_pair_friction(1) = ZERO + ierr = FEM_SUCCESS + end subroutine setup_contact_grid_pair + subroutine check_close(actual, expected, code) real(rk), intent(in) :: actual real(rk), intent(in) :: expected