Neko 1.99.2
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
field_source_term.f90
Go to the documentation of this file.
1! Copyright (c) 2026, 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 field_list, only : field_list_t
37 use json_module, only : json_file
39 use source_term, only : source_term_t
40 use coefs, only : coef_t
41 use utils, only : neko_error
42 use time_state, only : time_state_t
43 use registry, only : neko_registry
44 use field_math, only : field_add2
45 implicit none
46 private
47
51 type, public, extends(source_term_t) :: field_source_term_t
53 type(field_list_t) :: registry_fields
54 contains
56 procedure, pass(this) :: init => field_source_term_init_from_json
58 procedure, pass(this) :: init_from_compenents => &
61 procedure, pass(this) :: free => field_source_term_free
63 procedure, pass(this) :: compute_ => field_source_term_compute
64 end type field_source_term_t
65
66contains
73 subroutine field_source_term_init_from_json(this, json, fields, coef, &
74 variable_name)
75 class(field_source_term_t), intent(inout) :: this
76 type(json_file), intent(inout) :: json
77 type(field_list_t), intent(in), target :: fields
78 type(coef_t), intent(in), target :: coef
79 character(len=*), intent(in) :: variable_name
80 real(kind=rp) :: start_time, end_time
81 character(len=20), allocatable :: field_names(:)
82
83 call json_get(json, "field_names", field_names)
84 call json_get_or_default(json, "start_time", start_time, 0.0_rp)
85 call json_get_or_default(json, "end_time", end_time, huge(0.0_rp))
86
87
88 call field_source_term_init_from_components(this, fields, field_names, &
89 coef, start_time, end_time)
90
92
100 subroutine field_source_term_init_from_components(this, fields, field_names, &
101 coef, start_time, end_time)
102 class(field_source_term_t), intent(inout) :: this
103 class(field_list_t), intent(in), target :: fields
104 character(len=*), intent(in) :: field_names(:)
105 type(coef_t), target :: coef
106 real(kind=rp), intent(in) :: start_time
107 real(kind=rp), intent(in) :: end_time
108
109 integer :: i
110
111 call this%free()
112 call this%init_base(fields, coef, start_time, end_time)
113
114 if (size(field_names) .ne. fields%size()) then
115 call neko_error("Number of fields and field names inconsistent.")
116 end if
117
118 call this%registry_fields%init(size(field_names))
119
120 do i = 1, size(field_names)
121 ! Add zero-valued if doesn't exist.
122 ! May occur due to initialization order
123 call neko_registry%add_field(this%coef%dof, field_names(i), &
124 ignore_existing = .true.)
125 call this%registry_fields%assign(i, &
126 neko_registry%get_field(field_names(i)))
127 end do
128
130
132 subroutine field_source_term_free(this)
133 class(field_source_term_t), intent(inout) :: this
134
135 call this%free_base()
136 call this%registry_fields%free()
137
138 end subroutine field_source_term_free
139
142 subroutine field_source_term_compute(this, time)
143 class(field_source_term_t), intent(inout) :: this
144 type(time_state_t), intent(in) :: time
145 integer :: n_fields, i, n
146
147 n_fields = this%fields%size()
148
149 do i = 1, n_fields
150 call field_add2(this%fields%get(i), this%registry_fields%get(i))
151 end do
152 end subroutine field_source_term_compute
153
154end module field_source_term
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Retrieves a parameter by name or throws an error.
Coefficients.
Definition coef.f90:34
subroutine, public field_add2(a, b, n)
Vector addition .
Implements the field_source_term_t type.
subroutine field_source_term_compute(this, time)
Computes the source term and adds the result to fields.
subroutine field_source_term_init_from_components(this, fields, field_names, coef, start_time, end_time)
The constructor from type components.
subroutine field_source_term_free(this)
Destructor.
subroutine field_source_term_init_from_json(this, json, fields, coef, variable_name)
The common constructor using a JSON object.
Utilities for retrieving parameters from the case files.
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Defines a registry for storing solution fields.
Definition registry.f90:34
type(registry_t), target, public neko_registry
Global field registry.
Definition registry.f90:149
Implements the source_term_t type and a wrapper source_term_wrapper_t.
Module with things related to the simulation time.
Utilities.
Definition utils.f90:35
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:56
field_list_t, To be able to group fields together
A source term that grabs the values from fields in the registry. The fields are specified with the fi...
Base abstract type for source terms.
A struct that contains all info about the time, expand as needed.