bem_collision Module

粒子軌道セグメントと三角形要素の交差判定を提供する衝突検出モジュール。


Uses

  • module~~bem_collision~~UsesGraph module~bem_collision bem_collision module~bem_kinds bem_kinds module~bem_collision->module~bem_kinds module~bem_string_utils bem_string_utils module~bem_collision->module~bem_string_utils module~bem_types bem_types module~bem_collision->module~bem_types iso_fortran_env iso_fortran_env module~bem_kinds->iso_fortran_env module~bem_types->module~bem_kinds

Used by

  • module~~bem_collision~~UsedByGraph module~bem_collision bem_collision module~bem_injection bem_injection module~bem_injection->module~bem_collision module~bem_simulator bem_simulator module~bem_simulator->module~bem_collision module~bem_app_config bem_app_config module~bem_simulator->module~bem_app_config module~bem_app_config_runtime bem_app_config_runtime module~bem_app_config_runtime->module~bem_injection module~bem_sheath_injection_model bem_sheath_injection_model module~bem_app_config_runtime->module~bem_sheath_injection_model module~bem_sheath_model_core bem_sheath_model_core module~bem_sheath_model_core->module~bem_injection module~bem_simulator_io bem_simulator_io module~bem_simulator_io->module~bem_simulator module~bem_simulator_loop bem_simulator_loop module~bem_simulator_loop->module~bem_simulator module~bem_simulator_stats bem_simulator_stats module~bem_simulator_stats->module~bem_simulator program~main main program~main->module~bem_simulator program~main->module~bem_app_config module~bem_app_config->module~bem_app_config_runtime module~bem_sheath_runtime bem_sheath_runtime module~bem_sheath_runtime->module~bem_sheath_model_core module~bem_sheath_injection_model->module~bem_sheath_runtime

Functions

public pure function segment_bbox_overlap(p0, p1, bb_min, bb_max)

線分のAABBと要素AABBの重なりを先に判定し、詳細交差計算を枝刈りする。

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: p0(3)
real(kind=dp), intent(in) :: p1(3)
real(kind=dp), intent(in) :: bb_min(3)
real(kind=dp), intent(in) :: bb_max(3)

Return Value logical

public pure function segment_bbox_overlap_precomputed(seg_min, seg_max, bb_min, bb_max)

事前計算済みの線分AABBと要素AABBの重なりを判定する。

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: seg_min(3)
real(kind=dp), intent(in) :: seg_max(3)
real(kind=dp), intent(in) :: bb_min(3)
real(kind=dp), intent(in) :: bb_max(3)

Return Value logical

public pure function coord_to_cell(mesh, x, axis) result(idx)

座標をグリッドセル添字へ変換し、範囲外は端セルへ丸める。

Arguments

Type IntentOptional Attributes Name
type(mesh_type), intent(in) :: mesh
real(kind=dp), intent(in) :: x
integer(kind=i32), intent(in) :: axis

Return Value integer(kind=i32)

public pure function cell_id(ix, iy, iz, nx, ny) result(cid)

3次元セル添字 (ix,iy,iz) をCSR一次元インデックスへ変換する。

Arguments

Type IntentOptional Attributes Name
integer(kind=i32), intent(in) :: ix
integer(kind=i32), intent(in) :: iy
integer(kind=i32), intent(in) :: iz
integer(kind=i32), intent(in) :: nx
integer(kind=i32), intent(in) :: ny

Return Value integer(kind=i32)

public pure function point_inside_box(p, box_min, box_max, tol)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: p(3)
real(kind=dp), intent(in) :: box_min(3)
real(kind=dp), intent(in) :: box_max(3)
real(kind=dp), intent(in) :: tol

Return Value logical

public pure function point_inside_box_periodic2(p, box_min, box_max, tol, periodic_axes, require_half_open)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: p(3)
real(kind=dp), intent(in) :: box_min(3)
real(kind=dp), intent(in) :: box_max(3)
real(kind=dp), intent(in) :: tol
integer(kind=i32), intent(in) :: periodic_axes(2)
logical, intent(in) :: require_half_open

Return Value logical

public pure function bbox_inside_box(bb_min, bb_max, box_min, box_max, tol)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: bb_min(3)
real(kind=dp), intent(in) :: bb_max(3)
real(kind=dp), intent(in) :: box_min(3)
real(kind=dp), intent(in) :: box_max(3)
real(kind=dp), intent(in) :: tol

Return Value logical

public pure function cross(a, b) result(c)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: a(3)
real(kind=dp), intent(in) :: b(3)

Return Value real(kind=dp), (3)

public pure function prefer_periodic_candidate(t, elem_idx, image_shift, best_hit)

候補 hit が現在の best より優先されるかを deterministic に判定する。

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: t
integer(kind=i32), intent(in) :: elem_idx
integer(kind=i32), intent(in) :: image_shift(2)
type(hit_info), intent(in) :: best_hit

Return Value logical


Subroutines

public subroutine find_first_hit(mesh, p0, p1, hit, sim, box_min, box_max, require_elem_inside)

線分 [p0,p1] に対して最初に衝突する三角形要素を探索し、命中情報を返す。

Arguments

Type IntentOptional Attributes Name
type(mesh_type), intent(in) :: mesh

三角形要素とAABB情報を保持した衝突判定対象メッシュ。

real(kind=dp), intent(in) :: p0(3)
real(kind=dp), intent(in) :: p1(3)
type(hit_info), intent(out) :: hit

最初に命中した要素インデックス・命中位置・線分パラメータを格納。

type(sim_config), intent(in), optional :: sim
real(kind=dp), intent(in), optional :: box_min(3)
real(kind=dp), intent(in), optional :: box_max(3)
logical, intent(in), optional :: require_elem_inside

public subroutine find_first_hit_base(mesh, p0, p1, hit, box_min, box_max, require_elem_inside)

通常メッシュに対する最初の命中要素探索を行う。

Arguments

Type IntentOptional Attributes Name
type(mesh_type), intent(in) :: mesh
real(kind=dp), intent(in) :: p0(3)
real(kind=dp), intent(in) :: p1(3)
type(hit_info), intent(out) :: hit
real(kind=dp), intent(in), optional :: box_min(3)
real(kind=dp), intent(in), optional :: box_max(3)
logical, intent(in), optional :: require_elem_inside

public subroutine find_first_hit_periodic2(mesh, p0, p1, hit, sim, box_min, box_max, require_elem_inside)

periodic2 用に image shift を列挙し、base collision の結果を統合する。

Arguments

Type IntentOptional Attributes Name
type(mesh_type), intent(in) :: mesh
real(kind=dp), intent(in) :: p0(3)
real(kind=dp), intent(in) :: p1(3)
type(hit_info), intent(out) :: hit
type(sim_config), intent(in) :: sim
real(kind=dp), intent(in), optional :: box_min(3)
real(kind=dp), intent(in), optional :: box_max(3)
logical, intent(in), optional :: require_elem_inside

public subroutine find_first_hit_base_linear(mesh, p0, p1, seg_min, seg_max, hit, best_t, use_box_filter, box_min, box_max, box_tol, require_elem_inside)

旧実装と同じ線形探索で最初の命中要素を探索する。

Arguments

Type IntentOptional Attributes Name
type(mesh_type), intent(in) :: mesh
real(kind=dp), intent(in) :: p0(3)
real(kind=dp), intent(in) :: p1(3)
real(kind=dp), intent(in) :: seg_min(3)
real(kind=dp), intent(in) :: seg_max(3)
type(hit_info), intent(inout) :: hit
real(kind=dp), intent(inout) :: best_t
logical, intent(in) :: use_box_filter
real(kind=dp), intent(in) :: box_min(3)
real(kind=dp), intent(in) :: box_max(3)
real(kind=dp), intent(in) :: box_tol
logical, intent(in) :: require_elem_inside

public subroutine find_first_hit_base_grid(mesh, p0, p1, d, seg_min, seg_max, hit, best_t, use_box_filter, box_min, box_max, box_tol, require_elem_inside)

一様グリッド + 3D-DDA で候補セルのみ探索し、最初の命中要素を返す。

Arguments

Type IntentOptional Attributes Name
type(mesh_type), intent(in) :: mesh
real(kind=dp), intent(in) :: p0(3)
real(kind=dp), intent(in) :: p1(3)
real(kind=dp), intent(in) :: d(3)
real(kind=dp), intent(in) :: seg_min(3)
real(kind=dp), intent(in) :: seg_max(3)
type(hit_info), intent(inout) :: hit
real(kind=dp), intent(inout) :: best_t
logical, intent(in) :: use_box_filter
real(kind=dp), intent(in) :: box_min(3)
real(kind=dp), intent(in) :: box_max(3)
real(kind=dp), intent(in) :: box_tol
logical, intent(in) :: require_elem_inside

public pure subroutine segment_aabb_intersection_t(p0, d, bb_min, bb_max, ok, t_entry, t_exit)

線分 p(t)=p0+t*d (0<=t<=1) とAABBの交差区間 [t_entry,t_exit] を返す。

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: p0(3)
real(kind=dp), intent(in) :: d(3)
real(kind=dp), intent(in) :: bb_min(3)
real(kind=dp), intent(in) :: bb_max(3)
logical, intent(out) :: ok
real(kind=dp), intent(out) :: t_entry
real(kind=dp), intent(out) :: t_exit

public subroutine segment_triangle_intersect(p0, p1, v0, v1, v2, ok, t, h)

Möller–Trumbore法で線分と三角形の交差有無・線分パラメータ t・交点座標を計算する。

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: p0(3)
real(kind=dp), intent(in) :: p1(3)
real(kind=dp), intent(in) :: v0(3)
real(kind=dp), intent(in) :: v1(3)
real(kind=dp), intent(in) :: v2(3)
logical, intent(out) :: ok

線分と三角形が交差した場合に .true.

real(kind=dp), intent(out) :: t

交点の線分内パラメータ(p0 + t*(p1-p0))。

real(kind=dp), intent(out) :: h(3)

交点の線分内パラメータ(p0 + t*(p1-p0))。

public subroutine initialize_hit(hit)

hit 構造体を未命中状態へ初期化する。

Arguments

Type IntentOptional Attributes Name
type(hit_info), intent(out) :: hit

public subroutine resolve_box_filter_args(box_min, box_max, require_elem_inside, use_box_filter, box_min_local, box_max_local, box_tol, require_inside_elem)

box filter 関連の optional 引数を検証付きで展開する。

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in), optional :: box_min(3)
real(kind=dp), intent(in), optional :: box_max(3)
logical, intent(in), optional :: require_elem_inside
logical, intent(out) :: use_box_filter
real(kind=dp), intent(out) :: box_min_local(3)
real(kind=dp), intent(out) :: box_max_local(3)
real(kind=dp), intent(out) :: box_tol
logical, intent(out) :: require_inside_elem

public subroutine resolve_periodic2_collision_config(sim, use_periodic2, periodic_axes, periodic_len)

periodic2 collision で必要な 2 軸周期設定を解決する。

Arguments

Type IntentOptional Attributes Name
type(sim_config), intent(in) :: sim
logical, intent(out) :: use_periodic2
integer(kind=i32), intent(out) :: periodic_axes(2)
real(kind=dp), intent(out) :: periodic_len(2)

public subroutine compute_periodic_shift_bounds(mesh, p0, p1, axis, period_len, nmin, nmax)

線分 AABB と canonical mesh AABB の重なりから必要な image shift 範囲を決める。

Arguments

Type IntentOptional Attributes Name
type(mesh_type), intent(in) :: mesh
real(kind=dp), intent(in) :: p0(3)
real(kind=dp), intent(in) :: p1(3)
integer(kind=i32), intent(in) :: axis
real(kind=dp), intent(in) :: period_len
integer(kind=i32), intent(out) :: nmin
integer(kind=i32), intent(out) :: nmax

public subroutine wrap_periodic2_point(point, box_min, periodic_axes, periodic_len)

point を primary cell へ折り返す。

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(inout) :: point(3)
real(kind=dp), intent(in) :: box_min(3)
integer(kind=i32), intent(in) :: periodic_axes(2)
real(kind=dp), intent(in) :: periodic_len(2)