Neko 1.99.2
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
source_term_fctry.f90
Go to the documentation of this file.
1! Copyright (c) 2023-2024, 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!
33!
35submodule(source_term) source_term_fctry
44 use json_utils, only : json_get
46 implicit none
47
48 ! List of all possible types created by the factory routine
49 character(len=25) :: SOURCE_KNOWN_TYPES(8) = [character(len=25) :: &
50 "constant", &
51 "boussinesq", &
52 "coriolis", &
53 "centrifugal", &
54 "gradient_jump_penalty", &
55 "brinkman", &
56 "sponge", &
57 "field" &
58 ]
59
60contains
61
66 module subroutine source_term_factory(object, json, fields, coef, &
67 variable_name)
68 class(source_term_t), allocatable, intent(inout) :: object
69 type(json_file), intent(inout) :: json
70 type(field_list_t), intent(inout) :: fields
71 type(coef_t), intent(inout) :: coef
72 character(len=*), intent(in) :: variable_name
73 character(len=:), allocatable :: type_name
74 character(len=:), allocatable :: type_string
75
76 call json_get(json, "type", type_name)
77
78 ! Allocate
79 call source_term_allocator(object, type_name)
80
81 ! Initialize
82 call object%init(json, fields, coef, variable_name)
83
84 end subroutine source_term_factory
85
89 module subroutine source_term_allocator(object, type_name)
90 class(source_term_t), allocatable, intent(inout) :: object
91 character(len=:), allocatable, intent(in) :: type_name
92 integer :: i
93
94 if (allocated(object)) then
95 call object%free()
96 deallocate(object)
97 end if
98
99 select case (trim(type_name))
100 case ("constant")
101 allocate(const_source_term_t::object)
102 case ("boussinesq")
103 allocate(boussinesq_source_term_t::object)
104 case ("coriolis")
105 allocate(coriolis_source_term_t::object)
106 case ("centrifugal")
107 allocate(centrifugal_source_term_t::object)
108 case ("brinkman")
109 allocate(brinkman_source_term_t::object)
110 case ("sponge")
111 allocate(sponge_source_term_t::object)
112 case ("gradient_jump_penalty")
113 allocate(gradient_jump_penalty_t::object)
114 case ("field")
115 allocate(field_source_term_t::object)
116 case default
117 do i = 1, source_term_registry_size
118 if (trim(type_name) .eq. trim(source_term_registry(i)%type_name)) then
119 call source_term_registry(i)%allocator(object)
120 return
121 end if
122 end do
123
124 call neko_type_error("source term", type_name, source_known_types)
125 end select
126 end subroutine source_term_allocator
127
133 module subroutine register_source_term(type_name, allocator)
134 character(len=*), intent(in) :: type_name
135 procedure(source_term_allocate), pointer, intent(in) :: allocator
136 type(allocator_entry), allocatable :: temp(:)
137 integer :: i
138
139 do i = 1, size(source_known_types)
140 if (trim(type_name) .eq. trim(source_known_types(i))) then
141 call neko_type_registration_error("source term", type_name, .true.)
142 end if
143 end do
144
145 do i = 1, source_term_registry_size
146 if (trim(type_name) .eq. trim(source_term_registry(i)%type_name)) then
147 call neko_type_registration_error("source term", type_name, .false.)
148 end if
149 end do
150
151 ! Expand registry
152 if (source_term_registry_size .eq. 0) then
153 allocate(source_term_registry(1))
154 else
155 allocate(temp(source_term_registry_size + 1))
156 temp(1:source_term_registry_size) = source_term_registry
157 call move_alloc(temp, source_term_registry)
158 end if
159
160 source_term_registry_size = source_term_registry_size + 1
161 source_term_registry(source_term_registry_size)%type_name = type_name
162 source_term_registry(source_term_registry_size)%allocator => allocator
163 end subroutine register_source_term
164
165end submodule source_term_fctry
Retrieves a parameter by name or throws an error.
Implements the boussinesq_source_term_t type.
Implements the brinkman_source_term_t type.
Implements the centrifugal_source_term_t type. Maintainer: Adam Peplinski.
Implements the const_source_term_t type.
Implements the coriolis_source_term_t type. Maintainer: Timofey Mukha.
Implements the field_source_term_t type.
Implements gradient_jump_penalty_t.
Utilities for retrieving parameters from the case files.
Implements the source_term_t type and a wrapper source_term_wrapper_t.
Implements the sponge_t type.
Utilities.
Definition utils.f90:35
subroutine, public neko_type_registration_error(base_type, wrong_type, known)
Definition utils.f90:328
subroutine, public neko_type_error(base_type, wrong_type, known_types)
Reports an error allocating a type for a particular base pointer class.
Definition utils.f90:313
Bouyancy source term accroding to the Boussinesq approximation.
A Brinkman source term. The region and strength are controlled by assigning regions types and brinkma...
This source term adds the centrifugal force.
A constant source term. The strength is specified with the values keyword, which should be an array,...
This source term adds the Coriolis force.
A source term that grabs the values from fields in the registry. The fields are specified with the fi...