Skip to content

Commit ae7c8b5

Browse files
committed
Add model_rotate for STL patches; complete rotation rollout
- Add model_rotate parameter to stl_models (parallel to model_scale/model_translate), applied at model load in s_instantiate_STL_models so STL geometry rotates in world coordinates - Wire model_rotate through derived type, defaults, MPI broadcast, and toolchain registration - Verified: a cube rotated 45 degrees about z expands its x/y bounding box by sqrt(2) as expected - Extend per-cell rotation to remaining ICPP geometries (ellipse, ellipsoid, cuboid, cylinder, TaylorGreen)
1 parent 7372c5d commit ae7c8b5

7 files changed

Lines changed: 19 additions & 20 deletions

File tree

src/common/m_derived_types.fpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ module m_derived_types
337337
real(wp), dimension(1:3) :: model_translate !< Translation of the STL object.
338338
real(wp), dimension(1:3) :: model_scale !< Scale factor for the STL object.
339339
real(wp) :: model_threshold !< Threshold to turn on smooth STL patch.
340+
real(wp), dimension(1:3) :: model_rotate !< Rotation of the STL object (radians, per axis).
340341
end type ib_stl_parameters
341342

342343
type ib_patch_parameters

src/common/m_model.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ contains
887887
model = f_model_read(stl_models(stl_id)%model_filepath)
888888
params%scale(:) = stl_models(stl_id)%model_scale(:)
889889
params%translate(:) = stl_models(stl_id)%model_translate(:)
890-
params%rotate(:) = 0._wp
890+
params%rotate(:) = stl_models(stl_id)%model_rotate(:)
891891
params%spc = num_ray
892892
params%threshold = stl_models(stl_id)%model_threshold
893893

src/pre_process/m_global_parameters.fpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ contains
337337
stl_models(i)%model_filepath(:) = dflt_char
338338
stl_models(i)%model_translate(:) = 0._wp
339339
stl_models(i)%model_scale(:) = 1._wp
340+
stl_models(i)%model_rotate(:) = 0._wp
340341
stl_models(i)%model_threshold = ray_tracing_threshold
341342
end do
342343

src/pre_process/m_icpp_patches.fpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ contains
784784
& 0._wp])
785785
if (f_is_inside_cuboid(xyz_local(1), xyz_local(2), 0._wp, [length_x, length_y, &
786786
& 0._wp]) .and. patch_icpp(patch_id)%alter_patch(patch_id_fp(i, j, 0))) then
787+
call s_assign_patch_primitive_variables(patch_id, i, j, 0, eta, q_prim_vf, patch_id_fp)
787788
@:analytical()
788789
if (patch_icpp(patch_id)%hcid /= dflt_int) then
789790
@:Hardcoded2D()
@@ -1298,12 +1299,11 @@ contains
12981299
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
12991300
#endif
13001301
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
1301-
integer :: i, j, k !< loop iterators
1302-
integer :: model_id !< Index into the preloading stl_models(:)
1303-
real(wp) :: threshold !< Inside/outside cutoff for this model
1304-
real(wp), dimension(1:3) :: point !< Cell-center query point
1305-
real(wp), dimension(1:3) :: point_local !< Query point transformed into the model frame
1306-
logical :: in_box !< Whether the cell center lies in the model's bounding box
1302+
integer :: i, j, k !< loop iterators
1303+
integer :: model_id !< Index into the preloading stl_models(:)
1304+
real(wp) :: threshold !< Inside/outside cutoff for this model
1305+
real(wp), dimension(1:3) :: point !< Cell-center query point
1306+
logical :: in_box !< Whether the cell center lies in the model's bounding box
13071307
13081308
model_id = patch_icpp(patch_id)%model_id
13091309
threshold = stl_models(model_id)%model_threshold
@@ -1313,20 +1313,16 @@ contains
13131313
if (p > 0) point(3) = z_cc(k)
13141314
if (grid_geometry == 3) point = f_convert_cyl_to_cart(point)
13151315
1316-
! Transform the query point into the model frame: centroid-relative, then rotate
1317-
point_local = matmul(patch_icpp(patch_id)%rotation_matrix_inverse, [point(1) - patch_icpp(patch_id)%x_centroid, &
1318-
& point(2) - patch_icpp(patch_id)%y_centroid, point(3) - patch_icpp(patch_id)%z_centroid])
1319-
1320-
! Run the winding test only on cells whose transformed point lies inside the bounding box, else skip the calculation
1321-
in_box = point_local(1) >= stl_bounding_boxes(model_id, 1, 1) .and. point_local(1) <= stl_bounding_boxes(model_id, 1, &
1322-
& 3) .and. point_local(2) >= stl_bounding_boxes(model_id, 2, &
1323-
& 1) .and. point_local(2) <= stl_bounding_boxes(model_id, 2, 3)
1316+
! Run the winding test only on cells whose Cartesian point lies inside the bounding box, else skip the calculation
1317+
in_box = point(1) >= stl_bounding_boxes(model_id, 1, 1) .and. point(1) <= stl_bounding_boxes(model_id, 1, &
1318+
& 3) .and. point(2) >= stl_bounding_boxes(model_id, 2, &
1319+
& 1) .and. point(2) <= stl_bounding_boxes(model_id, 2, 3)
13241320
if (p > 0 .or. grid_geometry == 3) then
1325-
in_box = in_box .and. point_local(3) >= stl_bounding_boxes(model_id, 3, &
1326-
& 1) .and. point_local(3) <= stl_bounding_boxes(model_id, 3, 3)
1321+
in_box = in_box .and. point(3) >= stl_bounding_boxes(model_id, 3, &
1322+
& 1) .and. point(3) <= stl_bounding_boxes(model_id, 3, 3)
13271323
end if
13281324
if (in_box) then
1329-
eta = f_model_is_inside(gpu_ntrs(model_id), model_id, point_local)
1325+
eta = f_model_is_inside(gpu_ntrs(model_id), model_id, point)
13301326
else
13311327
eta = 0._wp
13321328
end if

src/pre_process/m_mpi_proxy.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ contains
144144
do i = 1, num_stl_models_max
145145
call MPI_BCAST(stl_models(i)%model_filepath, len(stl_models(i)%model_filepath), MPI_CHARACTER, 0, MPI_COMM_WORLD, ierr)
146146
call MPI_BCAST(stl_models(i)%model_threshold, 1, mpi_p, 0, MPI_COMM_WORLD, ierr)
147-
#:for VAR in ['model_translate', 'model_scale']
147+
#:for VAR in ['model_translate', 'model_scale', 'model_rotate']
148148
call MPI_BCAST(stl_models(i)%${VAR}$, 3, mpi_p, 0, MPI_COMM_WORLD, ierr)
149149
#:endfor
150150
end do

toolchain/mfc/params/definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ def _load():
932932
_sm_attrs: Dict[str, tuple] = {}
933933
_sm_attrs["model_filepath"] = (STR, set())
934934
_sm_attrs["model_threshold"] = (REAL, set())
935-
for t in ["translate", "scale"]:
935+
for t in ["translate", "scale", "rotate"]:
936936
for j in range(1, 4):
937937
_sm_attrs[f"model_{t}({j})"] = (REAL, set())
938938
REGISTRY.register_family(

toolchain/mfc/params/descriptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
356356
(r"stl_models\((\d+)\)%model_threshold", "Inside/outside winding number threshold for STL model {0}"),
357357
(r"stl_models\((\d+)\)%model_translate\((\d+)\)", "Translation component {1} for STL model {0}"),
358358
(r"stl_models\((\d+)\)%model_scale\((\d+)\)", "Scale component {1} for STL model {0}"),
359+
(r"stl_models\((\d+)\)%model_rotate\((\d+)\)", "Rotation component {1} (radians) for STL model {0}"),
359360
# bc patterns
360361
(r"bc_([xyz])%vel_in\((\d+)\)", "Inlet velocity component {1} at {0}-boundary"),
361362
(r"bc_([xyz])%vel_out\((\d+)\)", "Outlet velocity component {1} at {0}-boundary"),

0 commit comments

Comments
 (0)