Neko  0.8.1
A portable framework for high-order spectral element flow simulations
neko.f90
Go to the documentation of this file.
1 ! Copyright (c) 2019-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 !
34 module neko
35  use num_types
36  use comm
37  use utils
38  use logger
39  use math
40  use speclib
41  use dofmap, only : dofmap_t
42  use space
43  use htable
44  use uset
45  use stack
46  use tuple
47  use mesh, only : mesh_t
48  use point
49  use mesh_field, only : mesh_fld_t
50  use map
51  use mxm_wrapper
53  use file
54  use field, only : field_t, field_ptr_t
55  use neko_mpi_types
56  use gather_scatter
57  use coefs
58  use bc
59  use wall
60  use dirichlet
61  use krylov_fctry
62  use precon_fctry
63  use ax_helm_fctry
64  use ax_product
65  use neko_config
66  use case
67  use sampler
68  use output
69  use simulation
70  use operators
71  use mathops
72  use projection
73  use user_intf
74  use parmetis
75  use signal
76  use jobctrl
77  use device
78  use device_math
79  use map_1d
80  use cpr
81  use fluid_stats
82  use field_list, only : field_list_t
85  use vector
86  use matrix
87  use tensor
89  use probes
91  use system
92  use drag_torque
96  use data_streamer
99  use point_zone, only: point_zone_t
103  use, intrinsic :: iso_fortran_env
104  !$ use omp_lib
105  implicit none
106 
107 contains
108 
109  subroutine neko_init(C)
110  type(case_t), target, intent(inout), optional :: C
111  character(len=NEKO_FNAME_LEN) :: case_file
112  character(len=LOG_SIZE) :: log_buf
113  character(len=10) :: suffix
114  character(10) :: time
115  character(8) :: date
116  integer :: argc, nthrds, rw, sw
117 
118  call date_and_time(time=time, date=date)
119 
120  call comm_init
122  call jobctrl_init
123  call device_init
124 
125  call neko_log%init()
126  call neko_field_registry%init()
127 
128  if (pe_rank .eq. 0) then
129  write(*,*) ''
130  write(*,*) ' _ __ ____ __ __ ____ '
131  write(*,*) ' / |/ / / __/ / //_/ / __ \'
132  write(*,*) ' / / / _/ / ,< / /_/ /'
133  write(*,*) '/_/|_/ /___/ /_/|_| \____/ '
134  write(*,*) ''
135  write(*,*) '(version: ', trim(neko_version),')'
136  write(*,*) trim(neko_build_info)
137  write(*,*) ''
138  end if
139 
140  if (present(c)) then
141 
142  argc = command_argument_count()
143 
144  if ((argc .lt. 1) .or. (argc .gt. 1)) then
145  if (pe_rank .eq. 0) write(*,*) 'Usage: ./neko <case file>'
146  stop
147  end if
148 
149  call get_command_argument(1, case_file)
150 
151  call filename_suffix(case_file, suffix)
152 
153  if (trim(suffix) .ne. 'case') then
154  call neko_error('Invalid case file')
155  end if
156 
157  !
158  ! Job information
159  !
160  call neko_log%section("Job Information")
161  write(log_buf, '(A,A,A,A,1x,A,1x,A,A,A,A,A)') 'Start time: ',&
162  time(1:2),':',time(3:4), '/', date(1:4),'-', date(5:6),'-',date(7:8)
163  call neko_log%message(log_buf, neko_log_quiet)
164  write(log_buf, '(a)') 'Running on: '
165  sw = 10
166  if (pe_size .lt. 1e1) then
167  write(log_buf(13:), '(i1,a)') pe_size, ' MPI '
168  if (pe_size .eq. 1) then
169  write(log_buf(19:), '(a)') 'rank'
170  sw = 9
171  else
172  write(log_buf(19:), '(a)') 'ranks'
173  end if
174  rw = 1
175  else if (pe_size .lt. 1e2) then
176  write(log_buf(13:), '(i2,a)') pe_size, ' MPI ranks'
177  rw = 2
178  else if (pe_size .lt. 1e3) then
179  write(log_buf(13:), '(i3,a)') pe_size, ' MPI ranks'
180  rw = 3
181  else if (pe_size .lt. 1e4) then
182  write(log_buf(13:), '(i4,a)') pe_size, ' MPI ranks'
183  rw = 4
184  else if (pe_size .lt. 1e5) then
185  write(log_buf(13:), '(i5,a)') pe_size, ' MPI ranks'
186  rw = 5
187  else
188  write(log_buf(13:), '(i6,a)') pe_size, ' MPI ranks'
189  rw = 6
190  end if
191 
192  nthrds = 1
193  !$omp parallel
194  !$omp master
195  !$ nthrds = omp_get_num_threads()
196  !$omp end master
197  !$omp end parallel
198 
199  if (nthrds .gt. 1) then
200  if (nthrds .lt. 1e1) then
201  write(log_buf(13 + rw + sw:), '(a,i1,a)') ', using ', &
202  nthrds, ' thrds each'
203  else if (nthrds .lt. 1e2) then
204  write(log_buf(13 + rw + sw:), '(a,i2,a)') ', using ', &
205  nthrds, ' thrds each'
206  else if (nthrds .lt. 1e3) then
207  write(log_buf(13 + rw + sw:), '(a,i3,a)') ', using ', &
208  nthrds, ' thrds each'
209  else if (nthrds .lt. 1e4) then
210  write(log_buf(13 + rw + sw:), '(a,i4,a)') ', using ', &
211  nthrds, ' thrds each'
212  end if
213  end if
214  call neko_log%message(log_buf, neko_log_quiet)
215 
216  write(log_buf, '(a)') 'CPU type : '
217  call system_cpu_name(log_buf(13:))
218  call neko_log%message(log_buf, neko_log_quiet)
219 
220  write(log_buf, '(a)') 'Bcknd type: '
221  if (neko_bcknd_sx .eq. 1) then
222  write(log_buf(13:), '(a)') 'SX-Aurora'
223  else if (neko_bcknd_xsmm .eq. 1) then
224  write(log_buf(13:), '(a)') 'CPU (libxsmm)'
225  else if (neko_bcknd_cuda .eq. 1) then
226  write(log_buf(13:), '(a)') 'Accelerator (CUDA)'
227  else if (neko_bcknd_hip .eq. 1) then
228  write(log_buf(13:), '(a)') 'Accelerator (HIP)'
229  else if (neko_bcknd_opencl .eq. 1) then
230  write(log_buf(13:), '(a)') 'Accelerator (OpenCL)'
231  else
232  write(log_buf(13:), '(a)') 'CPU'
233  end if
234  call neko_log%message(log_buf, neko_log_quiet)
235 
236  if (neko_bcknd_hip .eq. 1 .or. neko_bcknd_cuda .eq. 1 .or. &
237  neko_bcknd_opencl .eq. 1) then
238  write(log_buf, '(a)') 'Dev. name : '
239  call device_name(log_buf(13:))
240  call neko_log%message(log_buf, neko_log_quiet)
241  end if
242 
243  write(log_buf, '(a)') 'Real type : '
244  select case (rp)
245  case (real32)
246  write(log_buf(13:), '(a)') 'single precision'
247  case (real64)
248  write(log_buf(13:), '(a)') 'double precision'
249  case (real128)
250  write(log_buf(13:), '(a)') 'quad precision'
251  end select
252  call neko_log%message(log_buf, neko_log_quiet)
253 
254  call neko_log%end()
255 
256  !
257  ! Create case
258  !
259  call case_init(c, case_file)
260 
261  !
262  ! Create simulation components
263  !
264  call neko_simcomps%init(c)
265 
266  end if
267 
268  end subroutine neko_init
269 
270  subroutine neko_finalize(C)
271  type(case_t), intent(inout), optional :: C
272 
273  if (present(c)) then
274  call case_free(c)
275  end if
276 
277  call neko_field_registry%free()
278  call neko_scratch_registry%free()
279  call device_finalize
281  call comm_free
282  end subroutine neko_finalize
283 
284 end module neko
Defines a Matrix-vector product.
Definition: ax.f90:34
Defines a boundary condition.
Definition: bc.f90:34
Defines a simulation case.
Definition: case.f90:34
subroutine case_free(C)
Deallocate a case.
Definition: case.f90:486
Coefficients.
Definition: coef.f90:34
Definition: comm.F90:1
integer pe_rank
MPI rank.
Definition: comm.F90:26
subroutine comm_free
Definition: comm.F90:95
integer pe_size
MPI size of communicator.
Definition: comm.F90:29
subroutine comm_init
Definition: comm.F90:36
Compression.
Definition: cpr.f90:34
Implements type data_streamer_t.
Device abstraction, common interface for various accelerators.
Definition: device.F90:34
subroutine, public device_finalize
Definition: device.F90:122
subroutine, public device_name(name)
Definition: device.F90:138
subroutine, public device_init
Definition: device.F90:107
Defines a dirichlet boundary condition.
Definition: dirichlet.f90:34
Defines a mapping of the degrees of freedom.
Definition: dofmap.f90:35
Defines a registry for storing solution fields.
type(field_registry_t), target, public neko_field_registry
Global field registry.
Defines a field.
Definition: field.f90:34
Module for file I/O operations.
Definition: file.f90:34
Computes various statistics for the fluid fields. We use the Reynolds decomposition for a field u = ...
Definition: fluid_stats.f90:36
Implements the fluid_user_source_term_t type.
Gather-scatter.
Implements global_interpolation given a dofmap.
Implements a hash table ADT.
Definition: htable.f90:36
Job control.
Definition: jobctrl.f90:34
subroutine, public jobctrl_init()
Initialize jobctrl.
Definition: jobctrl.f90:54
Logging routines.
Definition: log.f90:34
integer, parameter, public neko_log_quiet
Always logged.
Definition: log.f90:63
type(log_t), public neko_log
Global log stream.
Definition: log.f90:61
Creates a 1d GLL point map along a specified direction based on the connectivity in the mesh.
Definition: map_1d.f90:3
NEKTON map.
Definition: map.f90:3
Definition: math.f90:60
Collection of vector field operations operating on and . Note that in general the indices and ....
Definition: mathops.f90:65
Defines a matrix.
Definition: matrix.f90:34
Defines a mesh field.
Definition: mesh_field.f90:35
Defines a mesh.
Definition: mesh.f90:34
Wrapper for all matrix-matrix product implementations.
Definition: mxm_wrapper.F90:2
Build configurations.
Definition: neko_config.f90:34
integer, parameter neko_bcknd_sx
Definition: neko_config.f90:39
integer, parameter neko_bcknd_hip
Definition: neko_config.f90:42
character(len=80), parameter neko_build_info
Definition: neko_config.f90:37
character(len=10), parameter neko_version
Definition: neko_config.f90:36
integer, parameter neko_bcknd_opencl
Definition: neko_config.f90:43
integer, parameter neko_bcknd_cuda
Definition: neko_config.f90:41
integer, parameter neko_bcknd_xsmm
Definition: neko_config.f90:40
MPI derived types.
Definition: mpi_types.f90:34
subroutine, public neko_mpi_types_init
Define all MPI derived types.
Definition: mpi_types.f90:86
subroutine, public neko_mpi_types_free
Deallocate all derived MPI types.
Definition: mpi_types.f90:523
Master module.
Definition: neko.f90:34
subroutine neko_finalize(C)
Definition: neko.f90:271
subroutine neko_init(C)
Definition: neko.f90:110
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
Operators.
Definition: operators.f90:34
Defines an output.
Definition: output.f90:34
Interface to ParMETIS.
Definition: parmetis.F90:34
Routines to interpolate fields on a given element on a point in that element with given r,...
type(point_zone_registry_t), target, public neko_point_zone_registry
Global point_zone registry.
Implements a point.
Definition: point.f90:35
Implements probes.
Definition: probes.F90:37
Project x onto X, the space of old solutions and back again.
Definition: projection.f90:63
Defines a sampler.
Definition: sampler.f90:34
Implements the scalar_user_source_term_t type.
Defines a registry for storing and requesting temporary fields This can be used when you have a funct...
type(scratch_registry_t), target, public neko_scratch_registry
Global scratch registry.
Interface to signal handler.
Definition: signal.f90:34
Contains the simcomp_executor_t type.
type(simcomp_executor_t), public neko_simcomps
Global variable for the simulation component driver.
Simulation components are objects that encapsulate functionality that can be fit to a particular comp...
Simulation driver.
Definition: simulation.f90:34
Defines a function space.
Definition: space.f90:34
LIBRARY ROUTINES FOR SPECTRAL METHODS.
Definition: speclib.f90:147
Implements type spectral_error_indicator_t.
Implements a dynamic stack ADT.
Definition: stack.f90:35
Interface to system information routines.
Definition: system.f90:34
subroutine, public system_cpu_name(name)
Retrieve the system's CPU name (type)
Definition: system.f90:59
Tensor operations.
Definition: tensor.f90:61
Implements type time_interpolator_t.
Implements a n-tuple.
Definition: tuple.f90:34
Interfaces for user interaction with NEKO.
Definition: user_intf.f90:34
Implements an unordered set ADT.
Definition: uset.f90:35
Utilities.
Definition: utils.f90:35
subroutine filename_suffix(fname, suffix)
Extract a filename's suffix.
Definition: utils.f90:62
Defines a vector.
Definition: vector.f90:34
Defines wall boundary conditions.
Definition: wall.f90:34
A box-shaped point zone.
field_ptr_t, To easily obtain a pointer to a field
Definition: field.f90:80
field_list_t, To be able to group fields together
Definition: field_list.f90:7
Field interpolator to arbitrary points within an element. Tailored for experimentation,...
Base abstract type for point zones.
Definition: point_zone.f90:47