Neko 1.99.9
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, bc_dirichlet
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 call this%init_from_components(coef, 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
95 this%bc_type = bc_dirichlet
97
100 subroutine dirichlet_apply_scalar(this, x, n, time, strong)
101 class(dirichlet_t), intent(inout) :: this
102 integer, intent(in) :: n
103 real(kind=rp), intent(inout), dimension(n) :: x
104 type(time_state_t), intent(in), optional :: time
105 logical, intent(in), optional :: strong
106 integer :: i, m, k
107 logical :: strong_
108
109 if (present(strong)) then
110 strong_ = strong
111 else
112 strong_ = .true.
113 end if
114
115 if (strong_) then
116 m = this%msk(0)
117 !$omp do
118 do i = 1, m
119 k = this%msk(i)
120 x(k) = this%g
121 end do
122 !$omp end do
123 end if
124 end subroutine dirichlet_apply_scalar
125
128 subroutine dirichlet_apply_vector(this, x, y, z, n, time, strong)
129 class(dirichlet_t), intent(inout) :: this
130 integer, intent(in) :: n
131 real(kind=rp), intent(inout), dimension(n) :: x
132 real(kind=rp), intent(inout), dimension(n) :: y
133 real(kind=rp), intent(inout), dimension(n) :: z
134 type(time_state_t), intent(in), optional :: time
135 logical, intent(in), optional :: strong
136 integer :: i, m, k
137 logical :: strong_
138
139 if (present(strong)) then
140 strong_ = strong
141 else
142 strong_ = .true.
143 end if
144
145 if (strong_) then
146 m = this%msk(0)
147 !$omp do
148 do i = 1, m
149 k = this%msk(i)
150 x(k) = this%g
151 y(k) = this%g
152 z(k) = this%g
153 end do
154 !$omp end do
155 end if
156
157 end subroutine dirichlet_apply_vector
158
161 subroutine dirichlet_apply_scalar_dev(this, x_d, time, strong, strm)
162 class(dirichlet_t), intent(inout), target :: this
163 type(c_ptr), intent(inout) :: x_d
164 type(time_state_t), intent(in), optional :: time
165 logical, intent(in), optional :: strong
166 type(c_ptr), intent(inout) :: strm
167 logical :: strong_
168
169 if (present(strong)) then
170 strong_ = strong
171 else
172 strong_ = .true.
173 end if
174
175 if (strong_ .and. this%msk(0) .gt. 0) then
176 call device_dirichlet_apply_scalar(this%msk_d, x_d, &
177 this%g, size(this%msk), strm)
178 end if
179
180 end subroutine dirichlet_apply_scalar_dev
181
184 subroutine dirichlet_apply_vector_dev(this, x_d, y_d, z_d, &
185 time, strong, strm)
186 class(dirichlet_t), intent(inout), target :: this
187 type(c_ptr), intent(inout) :: x_d
188 type(c_ptr), intent(inout) :: y_d
189 type(c_ptr), intent(inout) :: z_d
190 type(time_state_t), intent(in), optional :: time
191 logical, intent(in), optional :: strong
192 type(c_ptr), intent(inout) :: strm
193 logical :: strong_
194
195 if (present(strong)) then
196 strong_ = strong
197 else
198 strong_ = .true.
199 end if
200
201 if (strong_ .and. this%msk(0) .gt. 0) then
202 call device_dirichlet_apply_vector(this%msk_d, x_d, y_d, z_d, this%g, &
203 size(this%msk), strm)
204 end if
205
206 end subroutine dirichlet_apply_vector_dev
207
209 subroutine dirichlet_set_g(this, g)
210 class(dirichlet_t), intent(inout) :: this
211 real(kind=rp), intent(in) :: g
212
213 this%g = g
214
215 end subroutine dirichlet_set_g
216
218 subroutine dirichlet_free(this)
219 class(dirichlet_t), target, intent(inout) :: this
220
221 call this%free_base
222
223 end subroutine dirichlet_free
224
226 subroutine dirichlet_finalize(this)
227 class(dirichlet_t), target, intent(inout) :: this
228 call this%finalize_base()
229 end subroutine dirichlet_finalize
230
231end module dirichlet
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_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_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_finalize(this)
Finalize.
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:14
Module with things related to the simulation time.
Base type for a boundary condition.
Definition bc.f90:72
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
A struct that contains all info about the time, expand as needed.