Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
heat_source.f90
Go to the documentation of this file.
1
5
7module user
8 use neko
9
10 use, intrinsic :: iso_c_binding, only: c_ptr, c_null_ptr
11
12 implicit none
13
14 real(kind=rp), dimension(:), allocatable :: resistance
15 type(c_ptr) :: resistance_d = c_null_ptr
16 logical :: is_initialized = .false.
17 real(kind=rp) :: pe, target_temperature
18
19 real(kind=rp) :: ramp_time_end = 0.0_rp
20
21contains
22
24 subroutine user_setup(usr)
25 type(user_t), intent(inout) :: usr
26 usr%scalar_user_f_vector => heat_source
27 usr%material_properties => set_material_properties
28 end subroutine user_setup
29
31 subroutine set_material_properties(t, tstep, rho, mu, cp, lambda, params)
32 real(kind=rp), intent(in) :: t
33 integer, intent(in) :: tstep
34 real(kind=rp), intent(inout) :: rho, mu, cp, lambda
35 type(json_file), intent(inout) :: params
36
37 real(kind=rp) :: re
38
39 call json_get(params, "case.fluid.Re", re)
40 call json_get(params, "case.scalar.Pe", pe)
41 call json_get(params, "case.scalar.target_temperature", target_temperature)
42 call json_get(params, "case.end_time", ramp_time_end)
44
45 mu = 1.0_rp/re
46 lambda = 1.0_rp/pe
47 rho = 1.0_rp
48 cp = 1.0_rp
49 end subroutine set_material_properties
50
52 subroutine heat_source(rhs, t)
53 use math_ext, only: sub3_mask
55
56 class(scalar_user_source_term_t), intent(inout) :: rhs
57 real(kind=rp), intent(in) :: t
58 type(field_t), pointer :: s
59
60 integer :: i
61 class(point_zone_t), pointer :: cyl, ball
62
63 real(kind=rp) :: current_temperature
64
65 cyl => neko_point_zone_registry%get_point_zone("cylinder")
66 ball => neko_point_zone_registry%get_point_zone("ball")
67
68 if (.not. allocated(resistance)) then
69
70 allocate (resistance(rhs%dm%size()))
71 call rzero(resistance, rhs%dm%size())
72
73 ! Set the resistance to 1.0 in the cylinder
74 do i = 1, cyl%size
75 resistance(cyl%mask(i)) = target_temperature
76 end do
77
78 ! Set the resistance to 1.0 in the ball
79 do i = 1, ball%size
80 resistance(ball%mask(i)) = target_temperature
81 end do
82
83 ! Copy to device
84 if (neko_bcknd_device .eq. 1) then
85 call device_map(resistance, resistance_d, rhs%dm%size())
86 call device_memcpy(resistance, resistance_d, rhs%dm%size(), &
87 host_to_device, .true.)
88 end if
89 end if
90
91 s => neko_field_registry%get_field('s')
92
93 current_temperature = min(1.0_rp, t / ramp_time_end) * target_temperature
94
95 if (neko_bcknd_device .eq. 1) then
96 call device_cfill_mask(s%x_d, current_temperature, rhs%dm%size(), &
97 cyl%mask_d, cyl%size)
98 call device_cfill_mask(s%x_d, current_temperature, rhs%dm%size(), &
99 ball%mask_d, ball%size)
100
101
102 ! call device_cfill(rhs%s_d, 0.0_rp, rhs%dm%size())
103 ! call device_sub3_mask(rhs%s_d, resistance_d, s%x_d, rhs%dm%size(), &
104 ! cyl%mask_d, cyl%size)
105 ! call device_sub3_mask(rhs%s_d, resistance_d, s%x_d, rhs%dm%size(), &
106 ! ball%mask_d, ball%size)
107 else
108
109 call cfill_mask(s%x, current_temperature, rhs%dm%size(), cyl%mask, &
110 cyl%size)
111 call cfill_mask(s%x, current_temperature, rhs%dm%size(), ball%mask, &
112 ball%size)
113
114 ! call cfill(rhs%s, 0.0_rp, rhs%dm%size())
115 ! call sub3_mask(rhs%s, resistance, s%x, rhs%dm%size(), cyl%mask, &
116 ! cyl%size)
117 ! call sub3_mask(rhs%s, resistance, s%x, rhs%dm%size(), ball%mask, &
118 ! ball%size)
119 end if
120
121 end subroutine heat_source
122end module user
subroutine device_sub3_mask(a_d, b_d, c_d, size, mask_d, mask_size)
subroutine sub3_mask(a, b, c, size, mask, mask_size)
Subtract 2 masked vectors. Save the result in a new vector. .
Definition math_ext.f90:102
User defined user region.
Definition user.f90:2
subroutine heat_source(rhs, t)
Heat source.
real(kind=rp) ramp_time_end
subroutine user_setup(user)
Register user defined functions (see nekos user_intf.f90)
Definition user.f90:22
real(kind=rp), dimension(:), allocatable resistance
subroutine set_material_properties(t, tstep, rho, mu, cp, lambda, params)
Read the material properties from the JSON file.
type(c_ptr) resistance_d
logical is_initialized
real(kind=rp) target_temperature
real(kind=rp) pe