Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
field_dirichlet.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
46 use utils, only : neko_error
47 use json_module, only : json_file
48 use field_list, only : field_list_t
49 use json_utils, only : json_get
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
65 type, public, extends(bc_t) :: field_dirichlet_t
68 type(field_t) :: field_bc
73 procedure(field_dirichlet_update), nopass, pointer :: update => null()
74 contains
76 procedure, pass(this) :: init => field_dirichlet_init
78 procedure, pass(this) :: init_from_components => &
81 procedure, pass(this) :: free => field_dirichlet_free
83 procedure, pass(this) :: finalize => field_dirichlet_finalize
85 procedure, pass(this) :: apply_scalar => field_dirichlet_apply_scalar
87 procedure, pass(this) :: apply_vector => field_dirichlet_apply_vector
89 procedure, pass(this) :: apply_vector_dev => &
92 procedure, pass(this) :: apply_scalar_dev => &
94
95 end type field_dirichlet_t
96
105 abstract interface
106 subroutine field_dirichlet_update(fields, bc, time)
108 type(field_list_t), intent(inout) :: fields
109 type(field_dirichlet_t), intent(in) :: bc
110 type(time_state_t), intent(in) :: time
111 end subroutine field_dirichlet_update
112 end interface
113
114 public :: field_dirichlet_update
115
116contains
120 subroutine field_dirichlet_init(this, coef, json)
121 class(field_dirichlet_t), intent(inout), target :: this
122 type(coef_t), target, intent(in) :: coef
123 type(json_file), intent(inout) ::json
124 character(len=:), allocatable :: field_name
125
126 call json_get(json, "field_name", field_name)
127 call this%init_from_components(coef, field_name)
128
129 end subroutine field_dirichlet_init
130
133 subroutine field_dirichlet_init_from_components(this, coef, field_name)
134 class(field_dirichlet_t), intent(inout), target :: this
135 type(coef_t), intent(in) :: coef
136 character(len=*), intent(in) :: field_name
137
138 call this%init_base(coef)
139 this%bc_type = bc_dirichlet
140
141 call this%field_bc%init(this%dof, field_name)
142 call this%field_list%init(1)
143 call this%field_list%assign_to_field(1, this%field_bc)
145
148 subroutine field_dirichlet_free(this)
149 class(field_dirichlet_t), target, intent(inout) :: this
150
151 call this%free_base
152 call this%field_bc%free()
153 call this%field_list%free()
154
155 if (associated(this%update)) then
156 this%update => null()
157 end if
158
159 end subroutine field_dirichlet_free
160
165 subroutine field_dirichlet_apply_scalar(this, x, n, time, strong)
166 class(field_dirichlet_t), intent(inout) :: this
167 integer, intent(in) :: n
168 real(kind=rp), intent(inout), dimension(n) :: x
169 type(time_state_t), intent(in), optional :: time
170 logical, intent(in), optional :: strong
171 logical :: strong_
172
173 if (present(strong)) then
174 strong_ = strong
175 else
176 strong_ = .true.
177 end if
178
179 if (strong_) then
180
181 if (.not. this%updated) then
182 call this%update(this%field_list, this, time)
183 this%updated = .true.
184 end if
185
186 call masked_copy_0(x, this%field_bc%x, this%msk, n, this%msk(0))
187 end if
188
189 end subroutine field_dirichlet_apply_scalar
190
195 subroutine field_dirichlet_apply_scalar_dev(this, x_d, time, strong, strm)
196 class(field_dirichlet_t), intent(inout), target :: this
197 type(c_ptr), intent(inout) :: x_d
198 type(time_state_t), intent(in), optional :: time
199 logical, intent(in), optional :: strong
200 type(c_ptr), intent(inout) :: strm
201 logical :: strong_
202
203 if (present(strong)) then
204 strong_ = strong
205 else
206 strong_ = .true.
207 end if
208
209 if (strong_) then
210 if (.not. this%updated) then
211 call this%update(this%field_list, this, time)
212 this%updated = .true.
213 end if
214
215 if (this%msk(0) .gt. 0) then
216 call device_masked_copy_0(x_d, this%field_bc%x_d, this%msk_d, &
217 this%field_bc%dof%size(), this%msk(0), strm)
218 end if
219 end if
220
222
229 subroutine field_dirichlet_apply_vector(this, x, y, z, n, time, strong)
230 class(field_dirichlet_t), intent(inout) :: this
231 integer, intent(in) :: n
232 real(kind=rp), intent(inout), dimension(n) :: x
233 real(kind=rp), intent(inout), dimension(n) :: y
234 real(kind=rp), intent(inout), dimension(n) :: z
235 type(time_state_t), intent(in), optional :: time
236 logical, intent(in), optional :: strong
237
238 call neko_error("field_dirichlet cannot apply vector BCs.&
239 & Use field_dirichlet_vector instead!")
240
241 end subroutine field_dirichlet_apply_vector
242
249 subroutine field_dirichlet_apply_vector_dev(this, x_d, y_d, z_d, time, &
250 strong, strm)
251 class(field_dirichlet_t), intent(inout), target :: this
252 type(c_ptr), intent(inout) :: x_d
253 type(c_ptr), intent(inout) :: y_d
254 type(c_ptr), intent(inout) :: z_d
255 type(time_state_t), intent(in), optional :: time
256 logical, intent(in), optional :: strong
257 type(c_ptr), intent(inout) :: strm
258 call neko_error("field_dirichlet cannot apply vector BCs.&
259 & Use field_dirichlet_vector instead!")
260
262
265 class(field_dirichlet_t), target, intent(inout) :: this
266 call this%finalize_base()
267 end subroutine field_dirichlet_finalize
268end module field_dirichlet
Abstract interface defining a dirichlet condition on a list of fields.
Retrieves a parameter by name or throws an error.
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 user dirichlet condition for a scalar field.
subroutine field_dirichlet_apply_vector_dev(this, x_d, y_d, z_d, time, strong, strm)
(No-op) Apply vector (device).
subroutine field_dirichlet_finalize(this)
Finalize.
subroutine field_dirichlet_apply_vector(this, x, y, z, n, time, strong)
(No-op) Apply vector.
subroutine field_dirichlet_init_from_components(this, coef, field_name)
Constructor from components.
subroutine field_dirichlet_apply_scalar(this, x, n, time, strong)
Apply scalar by performing a masked copy.
subroutine field_dirichlet_init(this, coef, json)
Constructor.
subroutine field_dirichlet_free(this)
Destructor. Currently thisfield_bc is being freed in fluid_scheme_incompressible::free
subroutine field_dirichlet_apply_scalar_dev(this, x_d, time, strong, strm)
Apply scalar (device).
Defines a field.
Definition field.f90:34
Utilities for retrieving parameters from the case files.
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....
field_list_t, To be able to group fields together
A struct that contains all info about the time, expand as needed.