Neko 1.99.1
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
custom_types.f90
Go to the documentation of this file.
1! Copyright (c) 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
37!! After compiling this file with makeneko, you can add the following to your
38!! JSON file to use this custom source term:
39!! "source_terms": [
40!! {
41!! "type": "my_source_term",
42!! "greeting": "Hello there!"
43!!
44!! }
45!! ],
46!! NOTE: the module name must be the same as the file name sans the extension.
48 use num_types, only : rp
49 use json_module, only : json_file
51 use field_list, only : field_list_t
52 use time_state, only : time_state_t
53
54 ! These imports are needed for registering our new type with Neko
55 use source_term, only : source_term_t, register_source_term, &
57
58 use coefs, only : coef_t
59 implicit none
60 private
61
62 type, public, extends(source_term_t) :: my_source_term_t
63 ! We will read this greeting from the JSON file.
64 character(len=:), allocatable :: greeting
65 contains
68 procedure, pass(this) :: init => my_source_term_init_from_json
70 procedure, pass(this) :: free => my_source_term_free
72 procedure, pass(this) :: compute_ => my_source_term_compute
73 end type my_source_term_t
74
75 ! Have to make this public!
77
78contains
83 subroutine my_source_term_init_from_json(this, json, fields, coef, &
84 variable_name)
85 class(my_source_term_t), intent(inout) :: this
86 type(json_file), intent(inout) :: json
87 type(field_list_t), intent(in), target :: fields
88 type(coef_t), intent(in), target :: coef
89 character(len=*), intent(in) :: variable_name
90 real(kind=rp) :: start_time, end_time
91
92 call json_get_or_default(json, "start_time", start_time, 0.0_rp)
93 call json_get_or_default(json, "end_time", end_time, huge(0.0_rp))
94
95 ! Start fresh
96 call this%free()
97 ! Initialize the base class source_term_t
98 call this%init_base(fields, coef, start_time, end_time)
99
100 call json_get(json, "greeting", this%greeting)
101
102 end subroutine my_source_term_init_from_json
103
105 subroutine my_source_term_free(this)
106 class(my_source_term_t), intent(inout) :: this
107
108 if (allocated(this%greeting)) then
109 deallocate(this%greeting)
110 end if
111 call this%free_base()
112 end subroutine my_source_term_free
113
116 subroutine my_source_term_compute(this, time)
117 class(my_source_term_t), intent(inout) :: this
118 type(time_state_t), intent(in) :: time
119
120 write(*,*) this%greeting
121
122 end subroutine my_source_term_compute
123
124 ! The name of this routine follows a convention: the name of the module +
125 ! register_types. This is where we call the register_source_term routine, or
126 ! a similar routine for other types. You can register as much types as you
127 ! want in this routine, in case you have several types in the module.
129 ! Just a helper variable
130 procedure(source_term_allocate), pointer :: allocator
131
132 allocator => my_source_term_allocate
133
134 ! Based on this the name of the source term will be "my_source_term",
135 ! This is what you set in the JSON file, in the type keyword
136 call register_source_term("my_source_term", allocator)
137 end subroutine custom_types_register_types
138
139 ! This thing does nothing except allocate a polymorphic object to our new
140 ! custom type.
142 class(source_term_t), allocatable, intent(inout) :: obj
143 allocate(my_source_term_t::obj)
144 end subroutine my_source_term_allocate
145end module custom_types
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.
Source term factory. Both constructs and initializes the object.
Coefficients.
Definition coef.f90:34
In this module we implement a custom source term, my_source_term and prep it for being recognized by ...
subroutine my_source_term_compute(this, time)
Will just bring our greeting to the console.
subroutine my_source_term_allocate(obj)
subroutine, public custom_types_register_types()
subroutine my_source_term_free(this)
Destructor.
subroutine my_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
Implements the source_term_t type and a wrapper source_term_wrapper_t.
Module with things related to the simulation time.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:55
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.