Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
user_source_term.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!
36 use num_types, only : rp
37 use utils, only : neko_error
38 use source_term, only : source_term_t
39 use json_module, only : json_file
40 use field_list, only : field_list_t
41 use coefs, only : coef_t
43 use dofmap, only : dofmap_t
45 use time_state, only : time_state_t
46 use, intrinsic :: iso_c_binding
47 implicit none
48 private
49
56 type, public, extends(source_term_t) :: user_source_term_t
58 character(len=:), allocatable :: scheme_name
60 type(dofmap_t), pointer :: dof
63 type(field_list_t) :: user_fields
65 procedure(user_source_term_intf), nopass, pointer :: compute_user_ &
66 => null()
67 contains
69 procedure, pass(this) :: init => user_source_term_init
71 procedure, pass(this) :: init_from_components => &
74 procedure, pass(this) :: free => user_source_term_free
76 procedure, pass(this) :: compute_ => user_source_term_compute
77 end type user_source_term_t
78
79contains
80
85 subroutine user_source_term_init(this, json, fields, coef, &
86 variable_name)
87 class(user_source_term_t), intent(inout) :: this
88 type(json_file), intent(inout) :: json
89 type(field_list_t), intent(in), target :: fields
90 type(coef_t), intent(in), target :: coef
91 character(len=*), intent(in) :: variable_name
92
93 call neko_error("The user source term should be initialized from " // &
94 "components")
95
96 end subroutine user_source_term_init
97
103 subroutine user_source_term_init_from_components(this, fields, coef, &
104 user_proc, scheme_name)
105 class(user_source_term_t), intent(inout) :: this
106 type(field_list_t), intent(in), target :: fields
107 type(coef_t), intent(in), target :: coef
108 procedure(user_source_term_intf) :: user_proc
109 character(len=*), intent(in) :: scheme_name
110 integer :: i
111
112 call this%free()
113 call this%init_base(fields, coef, 0.0_rp, huge(0.0_rp))
114
115 this%scheme_name = scheme_name
116 this%dof => fields%dof(1)
117
118 call this%user_fields%init(this%fields%size())
119
120 do i = 1, this%fields%size()
121 allocate(this%user_fields%items(i)%ptr)
122 call this%user_fields%items(i)%ptr%init(this%dof)
123 end do
124
125 this%compute_user_ => user_proc
127
129 subroutine user_source_term_free(this)
130 class(user_source_term_t), intent(inout) :: this
131
132 call this%user_fields%free()
133
134 if (allocated(this%scheme_name)) deallocate(this%scheme_name)
135
136 nullify(this%compute_user_)
137 nullify(this%dof)
138
139 call this%free_base()
140 end subroutine user_source_term_free
141
144 subroutine user_source_term_compute(this, time)
145 class(user_source_term_t), intent(inout) :: this
146 type(time_state_t), intent(in) :: time
147 integer :: i
148
149 if (time%t .ge. this%start_time .and. time%t .le. this%end_time) then
150 do i = 1, this%fields%size()
151 call field_rzero(this%user_fields%items(i)%ptr)
152 end do
153
154 call this%compute_user_(this%scheme_name, this%user_fields, time)
155
156 do i = 1, this%fields%size()
157 call field_add2(this%fields%items(i)%ptr, &
158 this%user_fields%items(i)%ptr)
159 end do
160 end if
161 end subroutine user_source_term_compute
162
163end module user_source_term
Abstract interface for user defined source term.
Coefficients.
Definition coef.f90:34
Defines a mapping of the degrees of freedom.
Definition dofmap.f90:35
subroutine, public field_rzero(a, n)
Zero a real vector.
subroutine, public field_add2(a, b, n)
Vector addition .
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Implements the source_term_t type and a wrapper source_term_wrapper_t.
Module with things related to the simulation time.
Interfaces for user interaction with NEKO.
Definition user_intf.f90:34
Implements the user_source_term_t type.
subroutine user_source_term_init(this, json, fields, coef, variable_name)
Costructor from JSON.
subroutine user_source_term_init_from_components(this, fields, coef, user_proc, scheme_name)
Costructor from components.
subroutine user_source_term_free(this)
Destructor.
subroutine user_source_term_compute(this, time)
Computes the source term and adds the result to fields.
Utilities.
Definition utils.f90:35
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:58
field_list_t, To be able to group fields together
Base abstract type for source terms.
A struct that contains all info about the time, expand as needed.
A source term wrapping the user source term routine. Stores fields that are passed to the user routin...