Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
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!
37 use num_types, only : rp
38 use bc, only : bc_t
39 use coefs, only : coef_t
40 use json_module, only : json_file
42 use, intrinsic :: iso_c_binding, only : c_ptr
43 use time_state, only : time_state_t
44 implicit none
45 private
46
49 type, public, extends(bc_t) :: dirichlet_t
50 real(kind=rp), private :: g
51 contains
52 procedure, pass(this) :: apply_scalar => dirichlet_apply_scalar
53 procedure, pass(this) :: apply_vector => dirichlet_apply_vector
54 procedure, pass(this) :: apply_scalar_dev => dirichlet_apply_scalar_dev
55 procedure, pass(this) :: apply_vector_dev => dirichlet_apply_vector_dev
56 procedure, pass(this) :: set_g => dirichlet_set_g
58 procedure, pass(this) :: init => dirichlet_init
60 procedure, pass(this) :: init_from_components => &
63 procedure, pass(this) :: free => dirichlet_free
65 procedure, pass(this) :: finalize => dirichlet_finalize
66 end type dirichlet_t
67
68contains
69
73 subroutine dirichlet_init(this, coef, json)
74 class(dirichlet_t), intent(inout), target :: this
75 type(coef_t), target, intent(in) :: coef
76 type(json_file), intent(inout) ::json
77 real(kind=rp) :: g
78
79 call this%init_base(coef)
80 call json_get_or_lookup(json , "value", g)
81
82 this%g = g
83 end subroutine dirichlet_init
84
88 subroutine dirichlet_init_from_components(this, coef, g)
89 class(dirichlet_t), intent(inout), target :: this
90 type(coef_t), target, intent(in) :: coef
91 real(kind=rp), intent(in) :: g
92
93 call this%init_base(coef)
94 this%g = g
96
99 subroutine dirichlet_apply_scalar(this, x, n, time, strong)
100 class(dirichlet_t), intent(inout) :: this
101 integer, intent(in) :: n
102 real(kind=rp), intent(inout), dimension(n) :: x
103 type(time_state_t), intent(in), optional :: time
104 logical, intent(in), optional :: strong
105 integer :: i, m, k
106 logical :: strong_
107
108 if (present(strong)) then
109 strong_ = strong
110 else
111 strong_ = .true.
112 end if
113
114 if (strong_) then
115 m = this%msk(0)
116 !$omp do
117 do i = 1, m
118 k = this%msk(i)
119 x(k) = this%g
120 end do
121 !$omp end do
122 end if
123 end subroutine dirichlet_apply_scalar
124
127 subroutine dirichlet_apply_vector(this, x, y, z, n, time, strong)
128 class(dirichlet_t), intent(inout) :: this
129 integer, intent(in) :: n
130 real(kind=rp), intent(inout), dimension(n) :: x
131 real(kind=rp), intent(inout), dimension(n) :: y
132 real(kind=rp), intent(inout), dimension(n) :: z
133 type(time_state_t), intent(in), optional :: time
134 logical, intent(in), optional :: strong
135 integer :: i, m, k
136 logical :: strong_
137
138 if (present(strong)) then
139 strong_ = strong
140 else
141 strong_ = .true.
142 end if
143
144 if (strong_) then
145 m = this%msk(0)
146 !$omp do
147 do i = 1, m
148 k = this%msk(i)
149 x(k) = this%g
150 y(k) = this%g
151 z(k) = this%g
152 end do
153 !$omp end do
154 end if
155
156 end subroutine dirichlet_apply_vector
157
160 subroutine dirichlet_apply_scalar_dev(this, x_d, time, strong, strm)
161 class(dirichlet_t), intent(inout), target :: this
162 type(c_ptr), intent(inout) :: x_d
163 type(time_state_t), intent(in), optional :: time
164 logical, intent(in), optional :: strong
165 type(c_ptr), intent(inout) :: strm
166 logical :: strong_
167
168 if (present(strong)) then
169 strong_ = strong
170 else
171 strong_ = .true.
172 end if
173
174 if (strong_ .and. this%msk(0) .gt. 0) then
175 call device_dirichlet_apply_scalar(this%msk_d, x_d, &
176 this%g, size(this%msk), strm)
177 end if
178
179 end subroutine dirichlet_apply_scalar_dev
180
183 subroutine dirichlet_apply_vector_dev(this, x_d, y_d, z_d, &
184 time, strong, strm)
185 class(dirichlet_t), intent(inout), target :: this
186 type(c_ptr), intent(inout) :: x_d
187 type(c_ptr), intent(inout) :: y_d
188 type(c_ptr), intent(inout) :: z_d
189 type(time_state_t), intent(in), optional :: time
190 logical, intent(in), optional :: strong
191 type(c_ptr), intent(inout) :: strm
192 logical :: strong_
193
194 if (present(strong)) then
195 strong_ = strong
196 else
197 strong_ = .true.
198 end if
199
200 if (strong_ .and. this%msk(0) .gt. 0) then
201 call device_dirichlet_apply_vector(this%msk_d, x_d, y_d, z_d, this%g, &
202 size(this%msk), strm)
203 end if
204
205 end subroutine dirichlet_apply_vector_dev
206
208 subroutine dirichlet_set_g(this, g)
209 class(dirichlet_t), intent(inout) :: this
210 real(kind=rp), intent(in) :: g
211
212 this%g = g
213
214 end subroutine dirichlet_set_g
215
217 subroutine dirichlet_free(this)
218 class(dirichlet_t), target, intent(inout) :: this
219
220 call this%free_base
221
222 end subroutine dirichlet_free
223
225 subroutine dirichlet_finalize(this, only_facets)
226 class(dirichlet_t), target, intent(inout) :: this
227 logical, optional, intent(in) :: only_facets
228 logical :: only_facets_
229
230 if (present(only_facets)) then
231 only_facets_ = only_facets
232 else
233 only_facets_ = .false.
234 end if
235
236 call this%finalize_base(only_facets_)
237 end subroutine dirichlet_finalize
238
239end module dirichlet
Defines a boundary condition.
Definition bc.f90:34
Coefficients.
Definition coef.f90:34
subroutine, public device_dirichlet_apply_scalar(msk, x, g, m, strm)
subroutine, public device_dirichlet_apply_vector(msk, x, y, z, g, m, strm)
Defines a dirichlet boundary condition.
Definition dirichlet.f90:34
subroutine dirichlet_apply_vector_dev(this, x_d, y_d, z_d, time, strong, strm)
Boundary condition apply for a generic Dirichlet condition to vectors x, y and z (device version)
subroutine dirichlet_finalize(this, only_facets)
Finalize.
subroutine dirichlet_apply_scalar_dev(this, x_d, time, strong, strm)
Boundary condition apply for a generic Dirichlet condition to a vector x (device version)
subroutine dirichlet_apply_scalar(this, x, n, time, strong)
Boundary condition apply for a generic Dirichlet condition to a vector x.
subroutine dirichlet_apply_vector(this, x, y, z, n, time, strong)
Boundary condition apply for a generic Dirichlet condition to vectors x, y and z.
subroutine dirichlet_free(this)
Destructor.
subroutine dirichlet_init_from_components(this, coef, g)
Constructor from components.
Definition dirichlet.f90:89
subroutine dirichlet_init(this, coef, json)
Constructor from JSON.
Definition dirichlet.f90:74
subroutine dirichlet_set_g(this, g)
Set value of .
Utilities for retrieving parameters from the case files.
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Module with things related to the simulation time.
Base type for a boundary condition.
Definition bc.f90:62
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:63
Generic Dirichlet boundary condition on .
Definition dirichlet.f90:49
A struct that contains all info about the time, expand as needed.