Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
field_dirichlet_vector.f90
Go to the documentation of this file.
1! Copyright (c) 2020-2025, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
35 use num_types, only : rp
36 use coefs, only : coef_t
37 use dirichlet, only : dirichlet_t
38 use bc, only : bc_t, bc_dirichlet
39 use bc_list, only : bc_list_t
40 use utils, only : split_string
41 use field, only : field_t
42 use field_list, only : field_list_t
43 use math, only : masked_copy_0
45 use dofmap, only : dofmap_t
47 use utils, only : neko_error
48 use json_module, only : json_file
49 use field_list, only : field_list_t
50 use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t
51 use time_state, only : time_state_t
52 implicit none
53 private
54
56 ! for the application on a vector field.
57 type, public, extends(bc_t) :: field_dirichlet_vector_t
58 ! The bc for the first compoent.
59 type(field_dirichlet_t) :: bc_u
60 ! The bc for the second compoent.
61 type(field_dirichlet_t) :: bc_v
62 ! The bc for the third compoent.
63 type(field_dirichlet_t) :: bc_w
68 procedure(field_dirichlet_update), nopass, pointer :: update => null()
69 contains
71 procedure, pass(this) :: init => field_dirichlet_vector_init
73 procedure, pass(this) :: init_from_components => &
76 procedure, pass(this) :: free => field_dirichlet_vector_free
78 procedure, pass(this) :: finalize => field_dirichlet_vector_finalize
80 procedure, pass(this) :: apply_scalar => &
83 procedure, pass(this) :: apply_vector => &
86 procedure, pass(this) :: apply_vector_dev => &
89 procedure, pass(this) :: apply_scalar_dev => &
92
93contains
94
98 subroutine field_dirichlet_vector_init(this, coef, json)
99 class(field_dirichlet_vector_t), intent(inout), target :: this
100 type(coef_t), target, intent(in) :: coef
101 type(json_file), intent(inout) ::json
102
103 call this%init_from_components(coef)
104
105 end subroutine field_dirichlet_vector_init
106
110 class(field_dirichlet_vector_t), intent(inout), target :: this
111 type(coef_t), intent(in) :: coef
112
113 call this%init_base(coef)
114 this%bc_type = bc_dirichlet
115
116 call this%bc_u%init_from_components(coef, "u")
117 call this%bc_v%init_from_components(coef, "v")
118 call this%bc_w%init_from_components(coef, "w")
119
120 ! TODO set to u v w values
121
122 call this%field_list%init(3)
123 call this%field_list%assign_to_field(1, this%bc_u%field_bc)
124 call this%field_list%assign_to_field(2, this%bc_v%field_bc)
125 call this%field_list%assign_to_field(3, this%bc_w%field_bc)
126
128
132 class(field_dirichlet_vector_t), target, intent(inout) :: this
133
134 call this%free_base()
135 call this%bc_u%free()
136 call this%bc_v%free()
137 call this%bc_w%free()
138
139 call this%field_list%free()
140
141 if (associated(this%update)) then
142 nullify(this%update)
143 end if
144 end subroutine field_dirichlet_vector_free
145
150 subroutine field_dirichlet_vector_apply_scalar(this, x, n, time, strong)
151 class(field_dirichlet_vector_t), intent(inout) :: this
152 integer, intent(in) :: n
153 real(kind=rp), intent(inout), dimension(n) :: x
154 type(time_state_t), intent(in), optional :: time
155 logical, intent(in), optional :: strong
156
157 call neko_error("field_dirichlet_vector cannot apply scalar BCs.&
158 & Use field_dirichlet instead!")
159
161
165 subroutine field_dirichlet_vector_apply_scalar_dev(this, x_d, time, &
166 strong, strm)
167 class(field_dirichlet_vector_t), intent(inout), target :: this
168 type(c_ptr), intent(inout) :: x_d
169 type(time_state_t), intent(in), optional :: time
170 logical, intent(in), optional :: strong
171 type(c_ptr), intent(inout) :: strm
172
173 call neko_error("field_dirichlet_vector cannot apply scalar BCs.&
174 & Use field_dirichlet instead!")
175
177
184 subroutine field_dirichlet_vector_apply_vector(this, x, y, z, n, time, &
185 strong)
186 class(field_dirichlet_vector_t), intent(inout) :: this
187 integer, intent(in) :: n
188 real(kind=rp), intent(inout), dimension(n) :: x
189 real(kind=rp), intent(inout), dimension(n) :: y
190 real(kind=rp), intent(inout), dimension(n) :: z
191 type(time_state_t), intent(in), optional :: time
192 logical, intent(in), optional :: strong
193 logical :: strong_
194
195 if (present(strong)) then
196 strong_ = strong
197 else
198 strong_ = .true.
199 end if
200
201 if (strong_) then
202
203 ! We can send any of the 3 bcs we have as argument, since they are all
204 ! the same boundary.
205 if (.not. this%updated) then
206 call this%update(this%field_list, this%bc_u, time)
207 this%updated = .true.
208 end if
209
210 call masked_copy_0(x, this%bc_u%field_bc%x, this%msk, n, this%msk(0))
211 call masked_copy_0(y, this%bc_v%field_bc%x, this%msk, n, this%msk(0))
212 call masked_copy_0(z, this%bc_w%field_bc%x, this%msk, n, this%msk(0))
213 end if
214
216
223 subroutine field_dirichlet_vector_apply_vector_dev(this, x_d, y_d, z_d, &
224 time, strong, strm)
225 class(field_dirichlet_vector_t), intent(inout), target :: this
226 type(c_ptr), intent(inout) :: x_d
227 type(c_ptr), intent(inout) :: y_d
228 type(c_ptr), intent(inout) :: z_d
229 type(time_state_t), intent(in), optional :: time
230 logical, intent(in), optional :: strong
231 type(c_ptr), intent(inout) :: strm
232 logical :: strong_
233
234 if (present(strong)) then
235 strong_ = strong
236 else
237 strong_ = .true.
238 end if
239
240 if (strong_) then
241 if (.not. this%updated) then
242 call this%update(this%field_list, this%bc_u, time)
243 this%updated = .true.
244 end if
245
246 if (this%msk(0) .gt. 0) then
247 call device_masked_copy_0(x_d, this%bc_u%field_bc%x_d, &
248 this%bc_u%msk_d, this%bc_u%dof%size(), this%msk(0), strm)
249 call device_masked_copy_0(y_d, this%bc_v%field_bc%x_d, &
250 this%bc_v%msk_d, this%bc_v%dof%size(), this%msk(0), strm)
251 call device_masked_copy_0(z_d, this%bc_w%field_bc%x_d, &
252 this%bc_w%msk_d, this%bc_w%dof%size(), this%msk(0), strm)
253 end if
254 end if
255
257
260 class(field_dirichlet_vector_t), target, intent(inout) :: this
261 call this%finalize_base()
262
263 call this%bc_u%mark_facets(this%marked_facet)
264 call this%bc_v%mark_facets(this%marked_facet)
265 call this%bc_w%mark_facets(this%marked_facet)
266
267 call this%bc_u%finalize()
268 call this%bc_v%finalize()
269 call this%bc_w%finalize()
270
272
273end module field_dirichlet_vector
Abstract interface defining a dirichlet condition on a list of fields.
Defines a list of bc_t.
Definition bc_list.f90:34
Defines a boundary condition.
Definition bc.f90:34
integer, parameter, public bc_dirichlet
Supported boundary condition types. The values are set in order of precedence for global resolution....
Definition bc.f90:66
Coefficients.
Definition coef.f90:34
subroutine, public device_masked_copy_0(a_d, b_d, mask_d, n, n_mask, strm)
Copy a masked vector .
Defines a dirichlet boundary condition.
Definition dirichlet.f90:34
Defines a mapping of the degrees of freedom.
Definition dofmap.f90:35
Defines inflow dirichlet conditions.
subroutine field_dirichlet_vector_apply_vector_dev(this, x_d, y_d, z_d, time, strong, strm)
Apply the boundary condition to a vector field on the device.
subroutine field_dirichlet_vector_finalize(this)
Finalize by building the mask arrays and propagating to underlying bcs.
subroutine field_dirichlet_vector_init_from_components(this, coef)
Constructor from components.
subroutine field_dirichlet_vector_apply_scalar_dev(this, x_d, time, strong, strm)
No-op apply scalar (device).
subroutine field_dirichlet_vector_init(this, coef, json)
Constructor.
subroutine field_dirichlet_vector_apply_vector(this, x, y, z, n, time, strong)
Apply the boundary condition to a vector field.
subroutine field_dirichlet_vector_apply_scalar(this, x, n, time, strong)
No-op apply scalar.
subroutine field_dirichlet_vector_free(this)
Destructor. Currently unused as is, all field_dirichlet attributes are freed in fluid_scheme_incompre...
Defines user dirichlet condition for a scalar field.
Defines a field.
Definition field.f90:34
Definition math.f90:60
subroutine, public masked_copy_0(a, b, mask, n, n_mask)
Copy a masked vector .
Definition math.f90:315
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Module with things related to the simulation time.
Utilities.
Definition utils.f90:35
character(len=100) function, dimension(:), allocatable, public split_string(string, delimiter)
Split a string based on delimiter (tokenizer) OBS: very hacky, this should really be improved,...
Definition utils.f90:251
Base type for a boundary condition.
Definition bc.f90:72
A list of allocatable `bc_t`. Follows the standard interface of lists.
Definition bc_list.f90:49
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:93
Generic Dirichlet boundary condition on .
Definition dirichlet.f90:49
User defined dirichlet condition, for which the user can work with an entire field....
Extension of the user defined dirichlet condition field_dirichlet
field_list_t, To be able to group fields together
A struct that contains all info about the time, expand as needed.