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 end type base_functional_t
89
90 ! -------------------------------------------------------------------------- !
91 ! Interface specifications for the derived types, these are the constructors
92 ! for the different types of objective functions.
93
94 abstract interface
95
97 subroutine functional_free(this)
99 class(base_functional_t), intent(inout) :: this
100 end subroutine functional_free
101
103 subroutine functional_update_value(this, design)
105 class(base_functional_t), intent(inout) :: this
106 class(design_t), intent(in) :: design
107 end subroutine functional_update_value
108
110 subroutine functional_update_sensitivity(this, design)
112 class(base_functional_t), intent(inout) :: this
113 class(design_t), intent(in) :: design
114 end subroutine functional_update_sensitivity
115
116 end interface
117
118contains
119
121 subroutine functional_init_json(this, json, design)
122 class(base_functional_t), intent(inout) :: this
123 type(json_file), intent(inout) :: json
124 class(design_t), intent(in) :: design
125 character(len=:), allocatable :: type
126
127 call json_get(json, 'type', type)
128 call neko_error("Functional type: '" // type // &
129 "' does not support initialization without simulation")
130 end subroutine functional_init_json
131
133 subroutine functional_init_json_sim(this, json, design, simulation)
134 class(base_functional_t), intent(inout) :: this
135 type(json_file), intent(inout) :: json
136 class(design_t), intent(in) :: design
137 type(simulation_t), target, intent(inout) :: simulation
138 character(len=:), allocatable :: type
139
140 call json_get(json, 'type', type)
141 call neko_error("Functional type: '" // type // &
142 "' does not support initialization with simulation")
143 end subroutine functional_init_json_sim
144
145end 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:50