Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
source_term.f90
Go to the documentation of this file.
1! Copyright (c) 2023, 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 utils, only : neko_typename_len
36 use num_types, only : rp
37 use coefs, only : coef_t
38 use field_list, only : field_list_t
39 use json_module, only : json_file
40 use time_state, only : time_state_t
41 implicit none
42 private
43
45 type, abstract, public :: source_term_t
47 type(field_list_t) :: fields
49 type(coef_t), pointer :: coef => null()
51 real(kind=rp) :: start_time = 0.0_rp
53 real(kind=rp) :: end_time = huge(0.0_rp)
56 logical :: extrapolate = .true.
57 contains
59 procedure, pass(this) :: init_base => source_term_init_base
61 procedure, pass(this) :: free_base => source_term_free_base
63 procedure, pass(this) :: compute => source_term_compute_wrapper
65 procedure(source_term_init), pass(this), deferred :: init
67 procedure(source_term_free), pass(this), deferred :: free
69 procedure(source_term_compute), pass(this), deferred :: compute_
70 end type source_term_t
71
72
74 type, public :: source_term_wrapper_t
76 class(source_term_t), allocatable :: source_term
77 contains
79 procedure, pass(this) :: free => source_term_wrapper_free
81
82 abstract interface
83
89 subroutine source_term_init(this, json, fields, coef, variable_name)
90 import source_term_t, json_file, field_list_t, coef_t
91 class(source_term_t), intent(inout) :: this
92 type(json_file), intent(inout) :: json
93 type(field_list_t), intent(in), target :: fields
94 type(coef_t), intent(in), target :: coef
95 character(len=*), intent(in) :: variable_name
96 end subroutine source_term_init
97 end interface
98
99 abstract interface
100
101 subroutine source_term_free(this)
102 import source_term_t
103 class(source_term_t), intent(inout) :: this
104 end subroutine source_term_free
105 end interface
106
107 abstract interface
108
111 subroutine source_term_compute(this, time)
113 class(source_term_t), intent(inout) :: this
114 type(time_state_t), intent(in) :: time
115 end subroutine source_term_compute
116 end interface
117
118 interface
119
126 module subroutine source_term_factory(object, json, fields, coef, &
127 variable_name)
128 class(source_term_t), allocatable, intent(inout) :: object
129 type(json_file), intent(inout) :: json
130 type(field_list_t), intent(inout) :: fields
131 type(coef_t), intent(inout) :: coef
132 character(len=*), intent(in) :: variable_name
133 end subroutine source_term_factory
134 end interface
135
136 interface
137
140 module subroutine source_term_allocator(object, type_name)
141 class(source_term_t), allocatable, intent(inout) :: object
142 character(len=:), allocatable, intent(in) :: type_name
143 end subroutine source_term_allocator
144 end interface
145
146 !
147 ! Machinery for injecting user-defined types
148 !
149
153 abstract interface
154 subroutine source_term_allocate(obj)
155 import source_term_t
156 class(source_term_t), allocatable, intent(inout) :: obj
157 end subroutine source_term_allocate
158 end interface
159
160 interface
161
162 module subroutine register_source_term(type_name, allocator)
163 character(len=*), intent(in) :: type_name
164 procedure(source_term_allocate), pointer, intent(in) :: allocator
165 end subroutine register_source_term
166 end interface
167
168 ! A name-allocator pair for user-defined types. A helper type to define a
169 ! registry of custom allocators.
170 type allocator_entry
171 character(len=NEKO_TYPENAME_LEN) :: type_name
172 procedure(source_term_allocate), pointer, nopass :: allocator
173 end type allocator_entry
174
176 type(allocator_entry), allocatable :: source_term_registry(:)
177
179 integer :: source_term_registry_size = 0
180
181 public :: source_term_factory, source_term_allocator, register_source_term, &
182 source_term_allocate
183
184contains
185
192 subroutine source_term_init_base(this, fields, coef, start_time, end_time)
193 class(source_term_t), intent(inout) :: this
194 type(field_list_t) :: fields
195 type(coef_t), intent(in), target :: coef
196 real(kind=rp), intent(in) :: start_time
197 real(kind=rp), intent(in) :: end_time
198 integer :: n_fields, i
199
200 this%coef => coef
201 this%start_time = start_time
202 this%end_time = end_time
203 n_fields = fields%size()
204
205 call this%fields%init(n_fields)
206
207 ! A lot of attribute nesting here due to Fortran needing wrapper types
208 ! but this is just pointer assignement for the fields.
209 do i = 1, n_fields
210 call this%fields%assign(i, fields%get(i))
211 end do
212 end subroutine source_term_init_base
213
215 subroutine source_term_free_base(this)
216 class(source_term_t), intent(inout) :: this
217
218 call this%fields%free()
219 nullify(this%coef)
220 this%extrapolate = .true.
221 end subroutine source_term_free_base
222
224 subroutine source_term_wrapper_free(this)
225 class(source_term_wrapper_t), intent(inout) :: this
226 integer :: n_fields, i
227
228 if (allocated(this%source_term)) then
229 call this%source_term%free()
230 deallocate(this%source_term)
231 end if
232 end subroutine source_term_wrapper_free
233
236 subroutine source_term_compute_wrapper(this, time)
237 class(source_term_t), intent(inout) :: this
238 type(time_state_t), intent(in) :: time
239
240 if (time%t .ge. this%start_time .and. time%t .le. this%end_time) then
241 call this%compute_(time)
242 end if
243
244 end subroutine source_term_compute_wrapper
245end module source_term
Computes the source term and adds the result to fields.
The common constructor using a JSON object.
Coefficients.
Definition coef.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Implements the source_term_t type and a wrapper source_term_wrapper_t.
subroutine source_term_wrapper_free(this)
Destructor for the source_term_wrapper_t type.
subroutine source_term_compute_wrapper(this, time)
Executes compute_ based on time conditions.
subroutine source_term_free_base(this)
Destructor for the source_term_t (base) type.
subroutine source_term_init_base(this, fields, coef, start_time, end_time)
Constructor for the source_term_t (base) type.
Module with things related to the simulation time.
Utilities.
Definition utils.f90:35
integer, parameter, public neko_typename_len
Definition utils.f90:44
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136
field_list_t, To be able to group fields together
Base abstract type for source terms.
A helper type that is needed to have an array of polymorphic objects.
A struct that contains all info about the time, expand as needed.