Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User statistics #1519

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/.depends
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ io/fld_file_output.o : io/fld_file_output.f90 io/output.o device/device.o config
io/chkp_output.o : io/chkp_output.f90 config/num_types.o io/output.o common/checkpoint.o
io/mean_flow_output.o : io/mean_flow_output.f90 io/output.o device/device.o config/num_types.o fluid/mean_flow.o
io/fluid_stats_output.o : io/fluid_stats_output.f90 math/matrix.o io/output.o device/device.o io/fld_file_data.o sem/map_2d.o sem/map_1d.o config/num_types.o config/neko_config.o fluid/fluid_stats.o
io/mean_field_output.o : io/mean_field_output.f90 io/output.o field/mean_field.o device/device.o config/neko_config.o field/field_list.o config/num_types.o
io/mean_sqr_flow_output.o : io/mean_sqr_flow_output.f90 io/output.o config/num_types.o fluid/mean_sqr_flow.o
io/data_streamer.o : io/data_streamer.F90 config/neko_config.o comm/mpi_types.o comm/comm.o device/device.o common/utils.o sem/coef.o field/field.o config/num_types.o
common/sampler.o : common/sampler.f90 common/time_based_controller.o config/num_types.o common/profiler.o common/utils.o common/log.o comm/comm.o io/fld_file.o io/output.o
Expand Down Expand Up @@ -187,6 +188,7 @@ common/rhs_maker_fctry.o : common/rhs_maker_fctry.f90 config/neko_config.o commo
simulation_components/probes.o : simulation_components/probes.F90 case.o io/csv_file.o io/file.o device/device.o comm/comm.o mesh/point_zone_registry.o mesh/point_zone.o math/tensor.o common/global_interpolation.o common/json_utils.o sem/dofmap.o field/field_registry.o simulation_components/simulation_component.o field/field_list.o common/utils.o common/log.o math/matrix.o config/num_types.o
simulation_components/force_torque.o : simulation_components/force_torque.f90 device/device.o math/bcknd/device/device_math.o math/math.o comm/comm.o qoi/drag_torque.o bc/dirichlet.o math/vector.o sem/coef.o simulation_components/field_writer.o common/json_utils.o io/fld_file_output.o case.o math/operators.o field/field.o field/field_registry.o simulation_components/simulation_component.o config/num_types.o
simulation_components/fluid_stats_simcomp.o : simulation_components/fluid_stats_simcomp.f90 common/json_utils.o common/log.o comm/comm.o sem/coef.o case.o io/fluid_stats_output.o fluid/fluid_stats.o field/field.o field/field_registry.o simulation_components/simulation_component.o config/num_types.o
simulation_components/user_stats.o : simulation_components/user_stats.f90 field/mean_field.o common/json_utils.o io/mean_field_output.o case.o field/field.o field/field_registry.o simulation_components/simulation_component.o config/num_types.o
simulation_components/field_writer.o : simulation_components/field_writer.f90 common/json_utils.o io/fld_file_output.o case.o math/operators.o field/field.o field/field_registry.o simulation_components/simulation_component.o config/num_types.o
common/bcknd/cpu/rhs_maker_cpu.o : common/bcknd/cpu/rhs_maker_cpu.f90 field/scratch_registry.o config/num_types.o field/field.o field/field_series.o common/rhs_maker.o
common/bcknd/sx/rhs_maker_sx.o : common/bcknd/sx/rhs_maker_sx.f90 field/scratch_registry.o config/num_types.o field/field.o field/field_series.o common/rhs_maker.o
Expand Down Expand Up @@ -281,7 +283,7 @@ simulation_components/lambda2.o : simulation_components/lambda2.f90 device/devic
simulation_components/weak_grad.o : simulation_components/weak_grad.f90 simulation_components/field_writer.o common/json_utils.o io/fld_file_output.o case.o math/operators.o field/field.o field/field_registry.o simulation_components/simulation_component.o config/num_types.o
simulation_components/derivative.o : simulation_components/derivative.f90 common/utils.o simulation_components/field_writer.o common/json_utils.o io/fld_file_output.o case.o math/operators.o field/field.o field/field_registry.o simulation_components/simulation_component.o config/num_types.o
simulation_components/les_simcomp.o : simulation_components/les_simcomp.f90 simulation_components/field_writer.o common/json_utils.o les/les_model.o case.o simulation_components/simulation_component.o config/num_types.o
simulation_components/simulation_component_fctry.o : simulation_components/simulation_component_fctry.f90 simulation_components/derivative.o simulation_components/weak_grad.o simulation_components/field_writer.o common/utils.o simulation_components/les_simcomp.o simulation_components/probes.o simulation_components/lambda2.o simulation_components/fluid_stats_simcomp.o simulation_components/force_torque.o simulation_components/vorticity.o simulation_components/simulation_component.o
simulation_components/simulation_component_fctry.o : simulation_components/simulation_component_fctry.f90 simulation_components/derivative.o simulation_components/weak_grad.o simulation_components/field_writer.o common/utils.o simulation_components/les_simcomp.o simulation_components/probes.o simulation_components/lambda2.o simulation_components/user_stats.o simulation_components/fluid_stats_simcomp.o simulation_components/force_torque.o simulation_components/vorticity.o simulation_components/simulation_component.o
source_terms/source_term.o : source_terms/source_term.f90 field/field_list.o sem/coef.o config/num_types.o
source_terms/coriolis_source_term.o : source_terms/coriolis_source_term.f90 source_terms/bcknd/cpu/coriolis_source_term_cpu.o common/utils.o config/neko_config.o sem/coef.o source_terms/source_term.o common/json_utils.o field/field_list.o config/num_types.o
source_terms/bcknd/cpu/coriolis_source_term_cpu.o : source_terms/bcknd/cpu/coriolis_source_term_cpu.f90 field/field.o math/math.o field/field_list.o config/num_types.o
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ neko_fortran_SOURCES = \
io/chkp_output.f90\
io/mean_flow_output.f90\
io/fluid_stats_output.f90\
io/mean_field_output.f90\
io/mean_sqr_flow_output.f90\
io/data_streamer.F90\
common/sampler.f90\
Expand Down Expand Up @@ -190,6 +191,7 @@ neko_fortran_SOURCES = \
simulation_components/probes.F90\
simulation_components/force_torque.f90\
simulation_components/fluid_stats_simcomp.f90\
simulation_components/user_stats.f90\
simulation_components/field_writer.f90\
common/bcknd/cpu/rhs_maker_cpu.f90\
common/bcknd/sx/rhs_maker_sx.f90\
Expand Down
192 changes: 192 additions & 0 deletions src/io/mean_field_output.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
! Copyright (c) 2020-2023, The Neko Authors
! All rights reserved.
!
! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions
! are met:
!
! * Redistributions of source code must retain the above copyright
! notice, this list of conditions and the following disclaimer.
!
! * Redistributions in binary form must reproduce the above
! copyright notice, this list of conditions and the following
! disclaimer in the documentation and/or other materials provided
! with the distribution.
!
! * Neither the name of the authors nor the names of its
! contributors may be used to endorse or promote products derived
! from this software without specific prior written permission.
!
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! POSSIBILITY OF SUCH DAMAGE.
!
!> Defines an output for a fluid
module mean_field_output
use num_types, only : rp
use field_list, only : field_list_t
use neko_config, only : NEKO_BCKND_DEVICE
use fld_file_data, only : fld_file_data_t
use map_2d, only : map_2d_t
use map_1d, only : map_1d_t
use coefs, only : coef_t
use device
use mean_field, only : mean_field_t
use output, only : output_t
use matrix, only : matrix_t
implicit none
private

!> Output for a list of mean fields
type, public, extends(output_t) :: mean_field_output_t
!> list of mean fields
type(mean_field_t), pointer :: mean_fields(:)
type(field_list_t) :: fields
real(kind=rp) :: start_time !> Time to start output
integer :: n_fields !> Number of fields
!> Space averaging object for 2 homogeneous directions.
type(map_1d_t) :: map_1d
!> Space averaging object for 1 homogeneous direction.
type(map_2d_t) :: map_2d
!> The dimension of the output fields. Either 1, 2, or 3.
integer :: output_dim
contains
procedure, pass(this) :: sample => mean_field_output_write
procedure, pass(this) :: init => mean_field_output_init
end type mean_field_output_t

contains

subroutine mean_field_output_init(this,mean_fields, n_fields, start_time, coef, avg_dir, name, path)
class(mean_field_output_t), intent(inout):: this
integer, intent(in) :: n_fields
class(mean_field_t), intent(inout), target :: mean_fields(n_fields)
type(coef_t), intent(inout) :: coef
character(len=*), intent(in) :: avg_dir
character(len=*), intent(in), optional :: name
character(len=*), intent(in), optional :: path
real(kind=rp), intent(in) :: start_time
character(len=1024) :: fname
integer :: i

if (trim(avg_dir) .eq. 'none' .or. &
trim(avg_dir) .eq. 'x' .or.&
trim(avg_dir) .eq. 'y' .or.&
trim(avg_dir) .eq. 'z'&
) then
if (present(name) .and. present(path)) then
fname = trim(path) // trim(name) // '.fld'
else if (present(name)) then
fname = trim(name) // '.fld'
else if (present(path)) then
fname = trim(path) // 'user_stats.fld'
else
fname = 'user_stats.fld'
end if

this%output_dim = 3

if (trim(avg_dir) .eq. 'x' .or.&
trim(avg_dir) .eq. 'y' .or.&
trim(avg_dir) .eq. 'z' ) then
call this%map_2d%init_char(coef, avg_dir, 1e-7_rp)
this%output_dim = 2
end if
else
if (present(name) .and. present(path)) then
fname = trim(path) // trim(name) // '.csv'
else if (present(name)) then
fname = trim(name) // '.csv'
else if (present(path)) then
fname = trim(path) // 'user_stats.csv'
else
fname = 'user_stats.csv'
end if
call this%map_1d%init_char(coef, avg_dir, 1e-7_rp)
this%output_dim = 1
end if



call this%init_base(fname)

call this%fields%init(n_fields)
this%n_fields = n_fields
this%mean_fields => mean_fields
do i = 1, n_fields
this%fields%items(i)%ptr => this%mean_fields(i)%mf
end do

end subroutine mean_field_output_init

!> Sample the mean solution at time @a t and reset
subroutine mean_field_output_write(this, t)
class(mean_field_output_t), intent(inout) :: this
real(kind=rp), intent(in) :: t
integer :: i
type(fld_file_data_t) :: output_2d
type(matrix_t) :: avg_output_1d
real(kind=rp) :: u, v, w, p

!if (NEKO_BCKND_DEVICE .eq. 1) then

! associate(fields => this%fields%items)
! do i = 1, size(fields)
! call device_memcpy(fields(i)%ptr%x, fields(i)%ptr%x_d, &
! fields(i)%ptr%dof%size(), DEVICE_TO_HOST, &
! sync=(i .eq. size(fields))) ! Sync on the last field
! end do
! end associate
!end if

!call this%file_%write(this%fields, t)
associate (out_fields => this%fields%items)
if (t .ge. this%start_time) then
if ( NEKO_BCKND_DEVICE .eq. 1) then
do i = 1, size(out_fields)
call device_memcpy(out_fields(i)%ptr%x, out_fields(i)%ptr%x_d,&
out_fields(i)%ptr%dof%size(), DEVICE_TO_HOST, &
sync = (i .eq. size(out_fields))) ! Sync on last field
end do
end if
if (this%output_dim .eq. 1) then
call this%map_1d%average_planes(avg_output_1d, &
this%fields)
call this%file_%write(avg_output_1d, t)
else if (this%output_dim .eq. 2) then
call this%map_2d%average(output_2d, this%fields)
!!Switch around fields to get correct orders
!!Put average direction mean_vel in scalar45
!do i = 1, this%map_2d%n_2d
! u = output_2d%v%x(i)
! v = output_2d%w%x(i)
! w = output_2d%p%x(i)
! p = output_2d%u%x(i)
! output_2d%p%x(i) = p
! output_2d%u%x(i) = u
! output_2d%v%x(i) = v
! output_2d%w%x(i) = w
!end do
Comment on lines +167 to +178
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a bit of cleanup is in order?

Suggested change
!!Switch around fields to get correct orders
!!Put average direction mean_vel in scalar45
!do i = 1, this%map_2d%n_2d
! u = output_2d%v%x(i)
! v = output_2d%w%x(i)
! w = output_2d%p%x(i)
! p = output_2d%u%x(i)
! output_2d%p%x(i) = p
! output_2d%u%x(i) = u
! output_2d%v%x(i) = v
! output_2d%w%x(i) = w
!end do


call this%file_%write(output_2d, t)
else
call this%file_%write(this%fields, t)
end if
do i = 1, this%n_fields
call this%mean_fields(i)%reset()
end do
end if
end associate

end subroutine mean_field_output_write

end module mean_field_output
6 changes: 5 additions & 1 deletion src/simulation_components/simulation_component_fctry.f90
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use vorticity, only : vorticity_t
use force_torque, only : force_torque_t
use fluid_stats_simcomp, only : fluid_stats_simcomp_t
use user_stats, only : user_stats_t
use lambda2, only : lambda2_t
use probes, only : probes_t
use les_simcomp, only : les_simcomp_t
Expand All @@ -45,13 +46,14 @@
use derivative, only : derivative_t

! List of all possible types created by the factory routine
character(len=20) :: SIMCOMPS_KNOWN_TYPES(7) = [character(len=20) :: &
character(len=20) :: SIMCOMPS_KNOWN_TYPES(8) = [character(len=20) :: &
"vorticity", &
"lambda2", &
"probes", &
"les_model", &
"field_writer", &
"fluid_stats", &
"user_stats", &
"force_torque"]

contains
Expand Down Expand Up @@ -92,6 +94,8 @@ module subroutine simulation_component_factory(object, json, case)
allocate(force_torque_t::object)
else if (trim(type_name) .eq. "fluid_stats") then
allocate(fluid_stats_simcomp_t::object)
else if (trim(type_name) .eq. "user_stats") then
allocate(user_stats_t::object)
else
type_string = concat_string_array(SIMCOMPS_KNOWN_TYPES, &
NEW_LINE('A') // "- ", .true.)
Expand Down
Loading
Loading