Neko  0.8.1
A portable framework for high-order spectral element flow simulations
simulation_component.f90
Go to the documentation of this file.
1 ! Copyright (c) 2023, 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 !
39  use num_types, only : rp
40  use json_module, only : json_file
41  use case, only : case_t
44  implicit none
45  private
46 
48  type, abstract, public :: simulation_component_t
50  type(case_t), pointer :: case
52  type(time_based_controller_t) :: compute_controller
54  type(time_based_controller_t) :: output_controller
56  integer :: order
57  contains
59  procedure, pass(this) :: init_base => simulation_component_init_base
61  procedure, pass(this) :: free_base => simulation_component_free_base
64  procedure, pass(this) :: restart => simulation_component_restart_wrapper
67  procedure, pass(this) :: compute => simulation_component_compute_wrapper
69  procedure(simulation_component_init), pass(this), deferred :: init
71  procedure(simulation_component_free), pass(this), deferred :: free
73  procedure(simulation_component_compute), pass(this), deferred :: compute_
74  end type simulation_component_t
75 
78  class(simulation_component_t), allocatable :: simcomp
80 
81 
82  abstract interface
83 
86  subroutine simulation_component_init(this, json, case)
87  import simulation_component_t, json_file, case_t
88  class(simulation_component_t), intent(inout) :: this
89  type(json_file), intent(inout) :: json
90  class(case_t), intent(inout), target :: case
91  end subroutine simulation_component_init
92  end interface
93 
94  abstract interface
95 
96  subroutine simulation_component_free(this)
98  class(simulation_component_t), intent(inout) :: this
99  end subroutine simulation_component_free
100  end interface
101 
102  abstract interface
103 
106  subroutine simulation_component_compute(this, t, tstep)
107  import simulation_component_t, rp
108  class(simulation_component_t), intent(inout) :: this
109  real(kind=rp), intent(in) :: t
110  integer, intent(in) :: tstep
111  end subroutine simulation_component_compute
112  end interface
113 
114 contains
116  subroutine simulation_component_init_base(this, json, case)
117  class(simulation_component_t), intent(inout) :: this
118  type(json_file), intent(inout) :: json
119  class(case_t), intent(inout), target :: case
120  character(len=:), allocatable :: compute_control, output_control
121  real(kind=rp) :: compute_value, output_value
122  integer :: order
123 
124  this%case => case
125  call json_get_or_default(json, "compute_control", compute_control, &
126  "tsteps")
127  call json_get_or_default(json, "compute_value", compute_value, 1.0_rp)
128 
129  ! We default to output whenever we execute
130  call json_get_or_default(json, "output_control", output_control, &
131  compute_control)
132  call json_get_or_default(json, "output_value", output_value, &
133  compute_value)
134 
135 
136  if (output_control == "global") then
137  call json_get(this%case%params, 'case.fluid.output_control', &
138  output_control)
139  call json_get(this%case%params, 'case.fluid.output_value', &
140  output_value)
141  end if
142 
143  call json_get(json, "order", order)
144  this%order = order
145 
146  call this%compute_controller%init(case%end_time, compute_control, &
147  compute_value)
148  call this%output_controller%init(case%end_time, output_control, &
149  output_value)
150 
151  end subroutine simulation_component_init_base
152 
155  class(simulation_component_t), intent(inout) :: this
156 
157  nullify(this%case)
158  end subroutine simulation_component_free_base
159 
164  subroutine simulation_component_compute_wrapper(this, t, tstep)
165  class(simulation_component_t), intent(inout) :: this
166  real(kind=rp), intent(in) :: t
167  integer, intent(in) :: tstep
168 
169  if (this%compute_controller%check(t, tstep)) then
170  call this%compute_(t, tstep)
171  call this%compute_controller%register_execution()
172  end if
174 
179  class(simulation_component_t), intent(inout) :: this
180  real(kind=rp), intent(in) :: t
181 
182  call this%compute_controller%set_counter(t)
183  call this%output_controller%set_counter(t)
184 
186 
187 end module simulation_component
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Definition: json_utils.f90:53
Retrieves a parameter by name or throws an error.
Definition: json_utils.f90:44
The main function to be executed during the run.
The common constructor using a JSON dictionary.
Defines a simulation case.
Definition: case.f90:34
Utilities for retrieving parameters from the case files.
Definition: json_utils.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...
subroutine simulation_component_free_base(this)
Destructor for the simulation_component_t (base) class.
subroutine simulation_component_restart_wrapper(this, t)
Wrapper for calling set_counter_ based for the controllers. Serves as the public interface.
subroutine simulation_component_init_base(this, json, case)
Constructor for the simulation_component_t (base) class.
subroutine simulation_component_compute_wrapper(this, t, tstep)
Wrapper for calling compute_ based on the compute_controller. Serves as the public interface.
Contains the time_based_controller_t type.
Base abstract class for simulation components.
A helper type that is needed to have an array of polymorphic objects.
A utility type for determening whether an action should be executed based on the current time value....