Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
objective.f90
Go to the documentation of this file.
1
34
38 use simulation_m, only: simulation_t
39 use design, only: design_t
40 use num_types, only: rp
41 use point_zone_registry, only: neko_point_zone_registry
42 use json_module, only: json_file
43 implicit none
44 private
45
47
52 type, abstract, extends(base_functional_t) :: objective_t
54 real(kind=rp) :: weight = 1.0_rp
55
56 contains
57
59 procedure, pass(this) :: init_base => objective_init_base
61 procedure, pass(this) :: free_base => objective_free_base
63 procedure, pass(this) :: get_weight => objective_get_weight
64
65 end type objective_t
66
69 class(objective_t), allocatable :: objective
70 contains
71 procedure, pass(this) :: free => objective_wrapper_free
72 end type objective_wrapper_t
73
74 ! -------------------------------------------------------------------------- !
75 ! Explicit interfaces
76
84 module subroutine objective_factory(object, json, design, simulation)
85 class(objective_t), allocatable, intent(inout) :: object
86 type(json_file), intent(inout) :: json
87 class(design_t), intent(in) :: design
88 type(simulation_t), target, optional, intent(inout) :: simulation
89 end subroutine objective_factory
90 end interface objective_factory
91
92contains
93
94 ! -------------------------------------------------------------------------- !
95 ! Implementations for the base class
96
103 subroutine objective_init_base(this, name, design_size, weight, mask_name)
104 class(objective_t), intent(inout) :: this
105 character(len=*), intent(in) :: name
106 integer, intent(in) :: design_size
107 real(kind=rp), intent(in) :: weight
108 character(len=*), intent(in), optional :: mask_name
109
110 call this%free_base()
111
112 this%name = name
113 call this%sensitivity%init(design_size)
114 call this%sensitivity_old%init(design_size)
115
116 this%weight = weight
117
118 if (present(mask_name)) then
119 if (mask_name .ne. "") then
120 this%has_mask = .true.
121 this%mask => neko_point_zone_registry%get_point_zone(mask_name)
122 end if
123 end if
124
125 end subroutine objective_init_base
126
128 subroutine objective_free_base(this)
129 class(objective_t), target, intent(inout) :: this
130
131 this%name = ""
132 this%weight = 1.0_rp
133
134 this%value = 0.0_rp
135 this%value_old = 0.0_rp
136 call this%sensitivity%free()
137 call this%sensitivity_old%free()
138
139 this%has_mask = .false.
140 if (associated(this%mask)) nullify(this%mask)
141
142 end subroutine objective_free_base
143
144 ! -------------------------------------------------------------------------- !
145 ! Implementations for the wrapper
146
148 subroutine objective_wrapper_free(this)
149 class(objective_wrapper_t), intent(inout) :: this
150 if (allocated(this%objective)) then
151 call this%objective%free()
152 deallocate(this%objective)
153 end if
154 end subroutine objective_wrapper_free
155
157 pure function objective_get_weight(this) result(w)
158 class(objective_t), intent(in) :: this
159 real(kind=rp) :: w
160 w = this%weight
161 end function objective_get_weight
162
163end module objective
164
Factory function Allocates and initializes an objective function object.
Definition objective.f90:83
Defines the abstract the base_functional_t type.
Implements the design_t.
Definition design.f90:36
Implements the objective_t type.
Definition objective.f90:36
Implements the steady_problem_t type.
An abstract design type.
Definition design.f90:54
The abstract objective type.
Definition objective.f90:52
Wrapper for objectives for use in lists.
Definition objective.f90:68