Neko 0.9.99
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
simulation_components/user_simcomp.f90

User defined simulation components.

User defined simulation components. Example of how to use the simcomp_executor to add a user defined simulation component to the list.

{
"version": 1.0,
"case":
{
"mesh_file": "512.nmsh",
"output_boundary": true,
"output_checkpoints": false,
"output_at_end": true,
"load_balance": false,
"job_timelimit": "00:00:00",
"end_time": 3.0,
"timestep": 1e-2,
"numerics": {
"time_order": 3,
"polynomial_order": 7,
"dealias": true
},
"fluid": {
"scheme": "pnpn",
"Re": 360,
"initial_condition": {
"type": "user"
},
"velocity_solver": {
"type": "cg",
"preconditioner": "jacobi",
"projection_space_size": 0,
"absolute_tolerance": 1e-7,
"max_iterations": 800
},
"pressure_solver": {
"type": "gmres",
"preconditioner": "hsmg",
"projection_space_size": 20,
"absolute_tolerance": 1e-7,
"max_iterations": 800
},
"output_control": "simulationtime",
"output_value": 1
},
"simulation_components":
[
{
"type": "vorticity"
},
{
"type": "my_comp",
"is_user": true,
"order": 1
// other settings if needed...
}
]
}
}
1! Copyright (c) 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! Implements the `user_simcomp_t` type.
34module simcomp_example
35 use num_types, only : rp
36 use json_module, only : json_file
38 use case, only : case_t
39 implicit none
40 private
41
42 ! An empty user defined simulation component.
43 ! This is a simple example of a user-defined simulation component.
44 type, public, extends(simulation_component_t) :: user_simcomp_t
45
46 contains
47 ! Constructor from json, wrapping the actual constructor.
48 procedure, pass(this) :: init => simcomp_test_init_from_json
49 ! Actual constructor.
50 procedure, pass(this) :: init_from_attributes => &
51 simcomp_test_init_from_attributes
52 ! Destructor.
53 procedure, pass(this) :: free => simcomp_test_free
54 ! Compute the simcomp_test field.
55 procedure, pass(this) :: compute_ => simcomp_test_compute
56 end type user_simcomp_t
57
58contains
59
60 ! Constructor from json.
61 subroutine simcomp_test_init_from_json(this, json, case)
62 class(user_simcomp_t), intent(inout) :: this
63 type(json_file), intent(inout) :: json
64 class(case_t), intent(inout), target :: case
65
66 call this%init_from_attributes()
67 call this%init_base(json, case)
68
69 end subroutine simcomp_test_init_from_json
70
71 ! Actual constructor.
72 subroutine simcomp_test_init_from_attributes(this)
73 class(user_simcomp_t), intent(inout) :: this
74
75 write(*,*) "Initializing simcomp_test field"
76 end subroutine simcomp_test_init_from_attributes
77
78 ! Destructor.
79 subroutine simcomp_test_free(this)
80 class(user_simcomp_t), intent(inout) :: this
81
82 write(*,*) "Freeing simcomp_test field"
83 call this%free_base()
84 end subroutine simcomp_test_free
85
86 ! Compute the simcomp_test field.
87 subroutine simcomp_test_compute(this, t, tstep)
88 class(user_simcomp_t), intent(inout) :: this
89 real(kind=rp), intent(in) :: t
90 integer, intent(in) :: tstep
91
92 write(*,*) "Computing simcomp_test field"
93
94 end subroutine simcomp_test_compute
95
96end module simcomp_example
97
98
99! User module for the user defined simulation component
100module user
101 use neko
102 use simcomp_example, only: user_simcomp_t
103 implicit none
104
105contains
106
107 ! Register user-defined functions (see user_intf.f90)
108 subroutine user_setup(user)
109 type(user_t), intent(inout) :: user
110 user%init_user_simcomp => user_simcomp
111 user%fluid_user_ic => user_ic
112 end subroutine user_setup
113
114 subroutine user_simcomp(params)
115 type(json_file), intent(inout) :: params
116 type(user_simcomp_t), allocatable :: my_simcomp
117 type(json_file) :: simcomp_settings
118
119 ! Allocate a simulation component
120 allocate(my_simcomp)
121 simcomp_settings = simulation_component_user_settings("my_comp", params)
122
123 call neko_simcomps%add_user_simcomp(my_simcomp, simcomp_settings)
124
125 end subroutine user_simcomp
126
127 ! User-defined initial condition
128 subroutine user_ic(u, v, w, p, params)
129 type(field_t), intent(inout) :: u
130 type(field_t), intent(inout) :: v
131 type(field_t), intent(inout) :: w
132 type(field_t), intent(inout) :: p
133 type(json_file), intent(inout) :: params
134 integer :: i, ntot
135 real(kind=rp) :: uvw(3)
136
137 ! u%dof%size() gives the total number of collocation points per rank
138 ntot = u%dof%size()
139 do i = 1, ntot
140 uvw = tgv_ic(u%dof%x(i,1,1,1),u%dof%y(i,1,1,1),u%dof%z(i,1,1,1))
141 u%x(i,1,1,1) = uvw(1)
142 v%x(i,1,1,1) = uvw(2)
143 w%x(i,1,1,1) = uvw(3)
144 end do
145 p = 0._rp
146 end subroutine user_ic
147
148 function tgv_ic(x, y, z) result(uvw)
149 real(kind=rp) :: x, y, z
150 real(kind=rp) :: ux, uy, uz
151 real(kind=rp) :: uvw(3)
152
153 uvw(1) = sin(x)*cos(y)*cos(z)
154 uvw(2) = -cos(x)*sin(y)*cos(z)
155 uvw(3) = 0._rp
156 end function tgv_ic
157end module user
Defines a simulation case.
Definition case.f90:34
Master module.
Definition neko.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Simulation components are objects that encapsulate functionality that can be fit to a particular comp...
Base abstract class for simulation components.