Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
base_functional.f90
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
35 use design, only: design_t
36 use json_module, only: json_file
37 use json_utils, only: json_get
38 use num_types, only: rp
39 use point_zone, only: point_zone_t
40 use simulation_m, only: simulation_t
41 use vector, only: vector_t
42 use utils, only: neko_error
43 implicit none
44 private
45
56 type, abstract, public :: base_functional_t
57
59 real(kind=rp) :: value
61 type(vector_t) :: sensitivity
63 character(len=25) :: name
65 logical :: has_mask
67 class(point_zone_t), pointer :: mask => null()
68
69 contains
70
71 ! ----------------------------------------------------------------------- !
72 ! Derived class interfaces
73
74 generic :: init => init_json, init_json_sim
75
77 procedure, pass(this) :: init_json => functional_init_json
79 procedure, pass(this) :: init_json_sim => functional_init_json_sim
81 procedure(functional_free), pass(this), deferred :: free
82
84 procedure(functional_update_value), pass(this), deferred :: update_value
86 procedure(functional_update_sensitivity), pass(this), deferred :: &
87 update_sensitivity
88
90 procedure, pass(this) :: get_value => functional_get_value
92 procedure, pass(this) :: get_sensitivity => functional_get_sensitivity
93
94 end type base_functional_t
95
96 ! -------------------------------------------------------------------------- !
97 ! Interface specifications for the derived types, these are the constructors
98 ! for the different types of objective functions.
99
100 abstract interface
101
103 subroutine functional_free(this)
104 import base_functional_t
105 class(base_functional_t), intent(inout) :: this
106 end subroutine functional_free
107
109 subroutine functional_update_value(this, design)
111 class(base_functional_t), intent(inout) :: this
112 class(design_t), intent(in) :: design
113 end subroutine functional_update_value
114
116 subroutine functional_update_sensitivity(this, design)
118 class(base_functional_t), intent(inout) :: this
119 class(design_t), intent(in) :: design
120 end subroutine functional_update_sensitivity
121
122 end interface
123
124contains
125
127 subroutine functional_init_json(this, json, design)
128 class(base_functional_t), intent(inout) :: this
129 type(json_file), intent(inout) :: json
130 class(design_t), intent(in) :: design
131 character(len=:), allocatable :: type
132
133 call json_get(json, 'type', type)
134 call neko_error("Functional type: '" // type // &
135 "' does not support initialization without simulation")
136 end subroutine functional_init_json
137
139 subroutine functional_init_json_sim(this, json, design, simulation)
140 class(base_functional_t), intent(inout) :: this
141 type(json_file), intent(inout) :: json
142 class(design_t), intent(in) :: design
143 type(simulation_t), target, intent(inout) :: simulation
144 character(len=:), allocatable :: type
145
146 call json_get(json, 'type', type)
147 call neko_error("Functional type: '" // type // &
148 "' does not support initialization with simulation")
149 end subroutine functional_init_json_sim
150
151
153 function functional_get_value(this) result(v)
154 class(base_functional_t), intent(in) :: this
155 real(kind=rp) :: v
156
157 v = this%value
158 end function functional_get_value
159
161 subroutine functional_get_sensitivity(this, sensitivity)
162 class(base_functional_t), intent(in) :: this
163 type(vector_t), intent(inout) :: sensitivity
164
165 sensitivity = this%sensitivity
166 end subroutine functional_get_sensitivity
167end module base_functional
Defines the abstract the base_functional_t type.
Implements the design_t.
Definition design.f90:34
Implements the steady_problem_t type.
An abstract design type.
Definition design.f90:52