Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
simulation.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!
34! Here, we simply march forward to steady state solutions
36 use case, only: case_t
37 use neko, only: neko_init, neko_finalize, neko_solve
39 use fluid_scheme_incompressible, only: fluid_scheme_incompressible_t
40 use fluid_pnpn, only: fluid_pnpn_t
42 use fld_file_output, only: fld_file_output_t
44 use simcomp_executor, only: neko_simcomps
45 use neko_ext, only: reset
46 use field_math, only: field_rzero
47 use json_file_module, only: json_file
48 use json_utils, only: json_extract_item
49 use num_types, only: rp, sp
50 implicit none
51 private
52
55 type(case_t), public :: neko_case
58
60 class(fluid_scheme_incompressible_t), public, pointer :: &
61 fluid_scheme => null()
62
65 type(fld_file_output_t), public :: output_forward
68 type(fld_file_output_t), public :: output_adjoint
69
70 contains
72 procedure, pass(this) :: init => simulation_init
74 procedure, pass(this) :: free => simulation_free
76 procedure, pass(this) :: run_forward => simulation_run_forward
78 procedure, pass(this) :: run_backward => simulation_run_backward
80 procedure, pass(this) :: reset => simulation_reset
82 procedure, pass(this) :: write => simulation_write
83 end type simulation_t
84
85 public :: simulation_t
86contains
87
89 subroutine simulation_init(this, parameters)
90 class(simulation_t), intent(inout) :: this
91 type(json_file), intent(inout) :: parameters
92 type(steady_simcomp_t), allocatable :: steady_comp
93 type(json_file) :: simcomp_settings
94
95 ! initialize the primal
96 call neko_init(this%neko_case)
97 ! initialize the adjoint
98 call adjoint_init(this%adjoint_case, this%neko_case)
99
100 select type (fluid => this%neko_case%fluid)
101 type is (fluid_pnpn_t)
102 this%fluid_scheme => fluid
103
104 end select
105
107 allocate(steady_comp)
108 call json_extract_item(parameters, &
109 "case.simulation_components", 1, simcomp_settings)
110
111 call steady_comp%init(simcomp_settings, this%neko_case)
112
113 call neko_simcomps%add_user_simcomp(steady_comp)
114
115 ! init the sampler
116 !---------------------------------------------------------
117 ! TODO
118 ! obviously when we do the mappings properly, to many coefficients, we'll
119 ! also have to modify this
120 ! for now:
121 ! - forward (p,u,v,w) 1,2,3,4 p,vx,vy,vz
122 ! - adjoint (p,u,v,w) 5,6,7,8 t,s1,s2,s3
123
124 ! Allocate the output type
125 call this%output_forward%init(sp, 'forward_fields', 4)
126 call this%output_adjoint%init(sp, 'adjoint_fields', 4)
127 call this%output_forward%fields%assign(1, this%fluid_scheme%p)
128 call this%output_forward%fields%assign(2, this%fluid_scheme%u)
129 call this%output_forward%fields%assign(3, this%fluid_scheme%v)
130 call this%output_forward%fields%assign(4, this%fluid_scheme%w)
131 call this%output_adjoint%fields%assign(1, this%adjoint_case%scheme%p_adj)
132 call this%output_adjoint%fields%assign(2, this%adjoint_case%scheme%u_adj)
133 call this%output_adjoint%fields%assign(3, this%adjoint_case%scheme%v_adj)
134 call this%output_adjoint%fields%assign(4, this%adjoint_case%scheme%w_adj)
135
136 end subroutine simulation_init
137
139 subroutine simulation_free(this)
140 class(simulation_t), intent(inout) :: this
141
142 call adjoint_free(this%adjoint_case)
143 call neko_finalize(this%neko_case)
144
145 end subroutine simulation_free
146
148 subroutine simulation_run_forward(this)
149 class(simulation_t), intent(inout) :: this
150
151 ! run the primal
152 call neko_solve(this%neko_case)
153
154 end subroutine simulation_run_forward
155
157 subroutine simulation_run_backward(this)
158 class(simulation_t), intent(inout) :: this
159
160 ! run the adjoint
161 call solve_adjoint(this%adjoint_case)
162
163 end subroutine simulation_run_backward
164
166 subroutine simulation_reset(this)
167 class(simulation_t), intent(inout) :: this
168
169 call reset(this%neko_case)
170
171 ! TODO
172 ! reset for the adjoint
173 ! call reset(this%adjoint_case)
174 call field_rzero(this%adjoint_case%scheme%u_adj)
175 call field_rzero(this%adjoint_case%scheme%v_adj)
176 call field_rzero(this%adjoint_case%scheme%w_adj)
177
178 end subroutine simulation_reset
179
181 subroutine simulation_write(this, idx)
182 class(simulation_t), intent(inout) :: this
183 integer, intent(in) :: idx
184
185 call this%output_forward%sample(real(idx, kind=rp))
186 call this%output_adjoint%sample(real(idx, kind=rp))
187
188 end subroutine simulation_write
189
190end module simulation
subroutine, public adjoint_free(this)
Contains extensions to the neko library required to run the topology optimization code.
Definition neko_ext.f90:9
subroutine, public reset(neko_case)
Reset the case data structure.
Definition neko_ext.f90:42
Adjoint simulation driver.
subroutine, public solve_adjoint(this)
Implements the steady_problem_t type.
subroutine simulation_init(this, parameters)
Initialize the simulation.
subroutine simulation_run_forward(this)
Run the simulation.
subroutine simulation_write(this, idx)
Write current state of the simulation to disk.
subroutine simulation_run_backward(this)
Run the simulation.
subroutine simulation_free(this)
Free the simulation.
subroutine simulation_reset(this)
Reset the simulation.
Implements the steady_simcomp_t type.
Adjoint case type. Todo: This should Ideally be a subclass of case_t, however, that is not yet suppoe...
The steady_simcomp_t type is a simulation component that terminates a simulation when the normed diff...