35 use num_types,
only: rp, sp
36 use field,
only: field_t
40 use coefs,
only: coef_t
41 use scratch_registry,
only: neko_scratch_registry
42 use point_zone_registry,
only: neko_point_zone_registry
43 use point_zone,
only: point_zone_t
45 use neko_config,
only: neko_bcknd_device
46 use device,
only: device_memcpy, host_to_device, device_to_host
50 use comm,
only: pe_size
51 use json_module,
only: json_file
52 use json_utils,
only: json_get, json_get_or_default
54 use vector,
only: vector_t
56 use field_registry,
only: neko_field_registry
57 use mpi_f08,
only: mpi_comm_size, mpi_comm_world
58 use utils,
only: neko_error
66 type(vector_t) :: values
67 type(vector_t) :: x_coord
68 type(vector_t) :: y_coord
69 type(vector_t) :: z_coord
80 generic,
public :: init => init_from_json, init_from_components
82 procedure, pass(this) :: init_from_json => &
83 design_simple_init_from_json
85 procedure, pass(this) :: init_from_components => &
86 design_simple_init_from_components
89 procedure, pass(this) :: add_mapping => design_simple_add_mapping
92 procedure, pass(this) :: get_values => design_simple_get_values
94 procedure, pass(this) :: design_get_x => design_simple_get_x
96 procedure, pass(this) :: design_get_y => design_simple_get_y
98 procedure, pass(this) :: design_get_z => design_simple_get_z
101 procedure, pass(this) :: update_design => design_simple_update_design
104 procedure, pass(this) :: map_forward => design_simple_map_forward
107 procedure, pass(this) :: map_backward => design_simple_map_backward
110 procedure, pass(this) :: write => design_simple_write
113 procedure, pass(this) :: free => design_simple_free
120 subroutine design_simple_init_from_json(this, parameters)
122 type(json_file),
intent(inout) :: parameters
123 character(len=:),
allocatable ::
type, name
124 integer :: n, nx, ny, nz, i, j, k, index
125 real(kind=rp),
dimension(:),
allocatable :: limits
126 type(vector_t) :: x, y, z
128 call json_get(parameters,
'domain.type', type)
129 call json_get_or_default(parameters,
'name', name,
'Simple Design')
131 select case (trim(type))
133 call json_get(parameters,
'optimization.design.domain.nx', nx)
134 call json_get(parameters,
'optimization.design.domain.ny', ny)
135 call json_get(parameters,
'optimization.design.domain.nz', nz)
136 call json_get(parameters,
'optimization.design.domain.limits', limits)
137 n = (nx + 1) * (ny + 1) * (nz + 1)
150 x%x(index) = limits(1) + (limits(2) - limits(1)) * &
151 real(i - 1, kind=rp) / real(nx, kind=rp)
152 y%x(index) = limits(3) + (limits(4) - limits(3)) * &
153 real(j - 1, kind=rp) / real(ny, kind=rp)
154 z%x(index) = limits(5) + (limits(6) - limits(5)) * &
155 real(k - 1, kind=rp) / real(nz, kind=rp)
161 if (neko_bcknd_device .eq. 1)
then
162 call device_memcpy(x%x, x%x_d, n, host_to_device, sync = .false.)
163 call device_memcpy(y%x, y%x_d, n, host_to_device, sync = .false.)
164 call device_memcpy(z%x, z%x_d, n, host_to_device, sync = .true.)
169 call this%init_from_components(name, n, x, y, z)
171 end subroutine design_simple_init_from_json
173 subroutine design_simple_init_from_components(this, name, n, x, y, z)
175 character(len=*),
intent(in) :: name
176 integer,
intent(in) :: n
177 type(vector_t),
intent(in) :: x, y, z
178 integer :: nproc, ierr
181 call mpi_comm_size(mpi_comm_world, nproc, ierr)
182 if (nproc .gt. 1)
then
183 call neko_error(
'simple_design_t can only be used on a single MPI rank')
186 if (pe_size .ne. 1)
then
187 call neko_error(
"Simple design can only be used with a single MPI " // &
191 call this%init_base(name, n)
193 call this%values%init(n)
198 end subroutine design_simple_init_from_components
201 subroutine design_simple_free(this)
204 call this%free_base()
205 call this%values%free()
206 call this%x_coord%free()
207 call this%y_coord%free()
208 call this%z_coord%free()
210 end subroutine design_simple_free
213 subroutine design_simple_add_mapping(this, parameters, simulation)
215 type(json_file),
intent(inout) :: parameters
218 end subroutine design_simple_add_mapping
221 subroutine design_simple_map_forward(this)
225 end subroutine design_simple_map_forward
227 subroutine design_simple_get_values(this, values)
229 type(vector_t),
intent(inout) :: values
233 end subroutine design_simple_get_values
235 subroutine design_simple_get_x(this, x)
237 type(vector_t),
intent(inout) :: x
241 end subroutine design_simple_get_x
243 subroutine design_simple_get_y(this, y)
245 type(vector_t),
intent(inout) :: y
249 end subroutine design_simple_get_y
251 subroutine design_simple_get_z(this, z)
253 type(vector_t),
intent(inout) :: z
257 end subroutine design_simple_get_z
259 subroutine design_simple_update_design(this, values)
261 type(vector_t),
intent(inout) :: values
265 end subroutine design_simple_update_design
267 subroutine design_simple_map_backward(this, sensitivity)
269 type(vector_t),
intent(in) :: sensitivity
271 end subroutine design_simple_map_backward
273 subroutine design_simple_write(this, idx)
275 integer,
intent(in) :: idx
278 integer :: npts, nx, ny, nz
279 character(len=100) :: filename
280 integer :: ios, funit
288 if (neko_bcknd_device .eq. 1)
then
289 call device_memcpy(this%x_coord%x, this%x_coord%x_d, npts, &
290 device_to_host, sync = .false.)
291 call device_memcpy(this%y_coord%x, this%y_coord%x_d, npts, &
292 device_to_host, sync = .false.)
293 call device_memcpy(this%z_coord%x, this%z_coord%x_d, npts, &
294 device_to_host, sync = .false.)
295 call device_memcpy(this%values%x, this%values%x_d, npts, &
296 device_to_host, sync = .true.)
299 write(filename,
'(A,I4.4,A)')
'design_', idx,
'.vtk'
301 open(newunit=funit, file=filename, status=
'replace', action=
'write', iostat=ios)
303 call neko_error(
'Error opening file ' // filename)
307 write(funit,
'(A)')
'# vtk DataFile Version 3.0'
308 write(funit,
'(A)')
'Simple Scalar Field'
309 write(funit,
'(A)')
'ASCII'
310 write(funit,
'(A)')
'DATASET STRUCTURED_GRID'
311 write(funit,
'(A,3(1X,I0))')
'DIMENSIONS', nx, ny, nz
314 write(funit,
'(A,1X,I0,1X,A)')
'POINTS', npts,
'float'
316 write(funit,
'(3(F20.12,1X))') this%x_coord%x(i), this%y_coord%x(i), &
321 write(funit,
'(A,1X,I0)')
'POINT_DATA', npts
322 write(funit,
'(A)')
'SCALARS density float 1'
323 write(funit,
'(A)')
'LOOKUP_TABLE default'
325 write(funit,
'(F20.12)') this%values%x(i)
329 end subroutine design_simple_write
331end module simple_design
Mappings to be applied to a scalar field.
Some common Masking operations we may need.
A RAMP mapping of coefficients.
Implements the simple_brinkman_source_term_t type.
Implements the steady_problem_t type.
Base abstract class for mapping.
A PDE based filter mapping , see Lazarov & O. Sigmund 2010, by solving an equation of the form .
A RAMP mapping of coefficients This is the standard RAMP described in https://doi....
A simple Brinkman source term.
A topology optimization design variable.