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
42 use scalar_pnpn,
only: scalar_pnpn_t
44 use fluid_pnpn,
only: fluid_pnpn_t
46 use fld_file_output,
only: fld_file_output_t
48 use simcomp_executor,
only: neko_simcomps
50 use field_math,
only: field_rzero
51 use json_file_module,
only: json_file
52 use json_utils,
only: json_extract_item
53 use num_types,
only: rp, sp
54 use user_intf,
only: user_t, simulation_component_user_settings
60 type(case_t),
public :: neko_case
64 class(fluid_scheme_incompressible_t),
public,
pointer :: fluid => null()
66 type(scalar_pnpn_t),
public,
pointer :: scalar => null()
73 type(fld_file_output_t),
public :: output_forward
76 type(fld_file_output_t),
public :: output_adjoint
80 procedure, pass(this) :: init => simulation_init
82 procedure, pass(this) :: free => simulation_free
84 procedure, pass(this) :: run_forward => simulation_run_forward
86 procedure, pass(this) :: run_backward => simulation_run_backward
88 procedure, pass(this) ::
reset => simulation_reset
90 procedure, pass(this) :: write => simulation_write
96 subroutine user_simcomp(params)
97 type(json_file),
intent(inout) :: params
99 type(json_file) :: simcomp_settings
102 allocate(steady_comp)
103 simcomp_settings = simulation_component_user_settings(
"steady", params)
104 call neko_simcomps%add_user_simcomp(steady_comp, simcomp_settings)
106 end subroutine user_simcomp
109 subroutine simulation_init(this, parameters)
111 type(json_file),
intent(inout) :: parameters
113 this%neko_case%usr%init_user_simcomp => user_simcomp
116 call neko_init(this%neko_case)
120 select type (fluid => this%neko_case%fluid)
121 type is (fluid_pnpn_t)
126 select type (adjoint_fluid => this%adjoint_case%fluid_adj)
128 this%adjoint_fluid => adjoint_fluid
132 if (
allocated(this%neko_case%scalar))
then
133 this%scalar => this%neko_case%scalar
136 if (
allocated(this%adjoint_case%scalar_adj))
then
137 this%adjoint_scalar => this%adjoint_case%scalar_adj
143 if (
allocated(this%neko_case%scalar))
then
144 call this%output_forward%init(sp,
'forward_fields', 5)
145 call this%output_forward%fields%assign(5, this%scalar%s)
147 call this%output_forward%init(sp,
'forward_fields', 4)
150 call this%output_forward%fields%assign(1, this%fluid%p)
151 call this%output_forward%fields%assign(2, this%fluid%u)
152 call this%output_forward%fields%assign(3, this%fluid%v)
153 call this%output_forward%fields%assign(4, this%fluid%w)
155 if (
allocated(this%adjoint_case%scalar_adj))
then
156 call this%output_adjoint%init(sp,
'adjoint_fields', 5)
157 call this%output_adjoint%fields%assign(5, this%adjoint_scalar%s_adj)
159 call this%output_adjoint%init(sp,
'adjoint_fields', 4)
161 call this%output_adjoint%fields%assign(1, this%adjoint_fluid%p_adj)
162 call this%output_adjoint%fields%assign(2, this%adjoint_fluid%u_adj)
163 call this%output_adjoint%fields%assign(3, this%adjoint_fluid%v_adj)
164 call this%output_adjoint%fields%assign(4, this%adjoint_fluid%w_adj)
166 end subroutine simulation_init
169 subroutine simulation_free(this)
172 call adjoint_free(this%adjoint_case)
173 call neko_finalize(this%neko_case)
175 end subroutine simulation_free
178 subroutine simulation_run_forward(this)
182 call neko_solve(this%neko_case)
184 end subroutine simulation_run_forward
187 subroutine simulation_run_backward(this)
191 call solve_adjoint(this%adjoint_case)
193 end subroutine simulation_run_backward
196 subroutine simulation_reset(this)
199 call reset(this%neko_case)
204 call field_rzero(this%adjoint_case%fluid_adj%u_adj)
205 call field_rzero(this%adjoint_case%fluid_adj%v_adj)
206 call field_rzero(this%adjoint_case%fluid_adj%w_adj)
207 if (
allocated(this%neko_case%scalar))
then
208 call field_rzero(this%adjoint_case%scalar_adj%s_adj)
211 end subroutine simulation_reset
214 subroutine simulation_write(this, idx)
216 integer,
intent(in) :: idx
218 call this%output_forward%sample(real(idx, kind=rp))
219 call this%output_adjoint%sample(real(idx, kind=rp))
221 end subroutine simulation_write
Adjoint Pn/Pn formulation.
Contains the adjoint_scalar_pnpn_t type.
Contains extensions to the neko library required to run the topology optimization code.
subroutine, public reset(neko_case)
Reset the case data structure.
Adjoint simulation driver.
Implements the steady_problem_t type.
Implements the steady_simcomp_t type.
Adjoint case type. Todo: This should Ideally be a subclass of case_t, however, that is not yet suppor...
Base type of all fluid formulations.
The steady_simcomp_t type is a simulation component that terminates a simulation when the normed diff...