Calculating drag and lift on cylinder with cs_user subroutin

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
spal
Posts: 10
Joined: Sun Feb 19, 2017 2:55 am

Calculating drag and lift on cylinder with cs_user subroutin

Post by spal »

I am using the following subroutine with version 4.2. I put the file in SRC directory. It compiles but does not write out anything in the temporary directories. Is this subroutine the right one to use in version 4.2 ?

!-------------------------------------------------------------------------------

! Code_Saturne version 4.2.0
! --------------------------
! This file is part of Code_Saturne, a general-purpose CFD tool.
!
! Copyright (C) 1998-2015 EDF S.A.
!
! This program is free software; you can redistribute it and/or modify it under
! the terms of the GNU General Public License as published by the Free Software
! Foundation; either version 2 of the License, or (at your option) any later
! version.
!
! This program is distributed in the hope that it will be useful, but WITHOUT
! ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
! FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
! details.
!
! You should have received a copy of the GNU General Public License along with
! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
! Street, Fifth Floor, Boston, MA 02110-1301, USA.

!-------------------------------------------------------------------------------

!===============================================================================
! Purpose:
! -------

! \file cs_user_extra_operations-global_efforts.f90
! This is an example of cs_user_extra_operations.f90 which
! performs global efforts

!-------------------------------------------------------------------------------

!-------------------------------------------------------------------------------
! Arguments
!______________________________________________________________________________.
! mode name role !
!______________________________________________________________________________!
!> \param[in] nvar total number of variables
!> \param[in] nscal total number of scalars
!> \param[in] dt time step (per cell)
!_______________________________________________________________________________

subroutine cs_f_user_extra_operations &
( nvar , nscal , &
dt )

!===============================================================================

!===============================================================================
! Module files
!===============================================================================

use paramx
use dimens, only: ndimfb
use pointe
use numvar
use optcal
use cstphy
use cstnum
use entsor
use lagpar
use lagran
use lagdim
use parall
use period
use ppppar
use ppthch
use ppincl
use mesh
use field
use field_operator
use turbomachinery

!===============================================================================

implicit none

! Arguments

integer nvar , nscal

double precision dt(ncelet)

! Local variables

!< [loc_var_dec]
integer ifac
integer ii
integer ilelt , nlelt

double precision xfor(3)
double precision, dimension(:,:), pointer :: bfprp_for

integer, allocatable, dimension(:) :: lstelt
!< [loc_var_dec]

!===============================================================================

!===============================================================================
! Initialization
!===============================================================================

if (ntcabs.eq.1) then
open(file='drag_lift.dat',unit=impusr(1))
write(impusr(1),'(4(A,1X))') ' time ', ' Drag ', ' Lift ',' Lift2 '
close(unit=impusr(1))
endif

if (iforbr.ge.0) call field_get_val_v(iforbr, bfprp_for)

! Allocate a temporary array for cells or interior/boundary faces selection
allocate(lstelt(max(ncel,nfac,nfabor)))

!===============================================================================
! Example: compute global efforts on a subset of faces
!===============================================================================

! If efforts have been calculated correctly:

!< [example_1]
if (iforbr.ge.0) then

do ii = 1, ndim
xfor(ii) = 0.d0
enddo

call getfbr('wall', nlelt, lstelt)
!==========

do ilelt = 1, nlelt

ifac = lstelt(ilelt)

do ii = 1, ndim
xfor(ii) = xfor(ii) + bfprp_for(ii, ifac)
enddo

enddo

if (irangp.ge.0) then
call parrsm(ndim,xfor)
endif

do ii = 1, ndim
xfor(ii) = 2.0*xfor(ii)
enddo

open(file='drag_lift.dat',unit=impusr(1),position='append')
write(impusr(1),'(4(E12.5,1X))') ttcabs,xfor(1),xfor(2),xfor(3)
write(nfecra,'(4(E12.5,1X))') ttcabs,xfor(1),xfor(2),xfor(3)
close (unit=impusr(1))

endif
!< [example_1]

! Deallocate the temporary array
deallocate(lstelt)


return
end subroutine cs_f_user_extra_operations
Attachments
cs_user_extra_operations.f90
subroutine file
(4.56 KiB) Downloaded 240 times
Yvan Fournier
Posts: 4085
Joined: Mon Feb 20, 2012 3:25 pm

Re: Calculating drag and lift on cylinder with cs_user subro

Post by Yvan Fournier »

Hello,

Did you activate computation of stresses on the boundary (either by activing postprocessing of boundary efforts/stresses in the GUI or by setting iforbr to 1 in cs_user_parameters.f90 in the usipsu subroutine) ?

Also, it may not be an issue for you, but your subroutine won't work in parallel, as all your tests and sums assume you are running on a single rank.

Best regards,

Yvan Fournier
spal
Posts: 10
Joined: Sun Feb 19, 2017 2:55 am

Re: Calculating drag and lift on cylinder with cs_user subro

Post by spal »

Yes, I did turn it on in the GUI. I get stresses written out at the end of every time step. So based on what you are say, this should work in serial. I was running with four processors.
spal
Posts: 10
Joined: Sun Feb 19, 2017 2:55 am

Re: Calculating drag and lift on cylinder with cs_user subro

Post by spal »

I would like to know the changes needed to make to have it run in parallel.
Yvan Fournier
Posts: 4085
Joined: Mon Feb 20, 2012 3:25 pm

Re: Calculating drag and lift on cylinder with cs_user subro

Post by Yvan Fournier »

Hello,

You need to open and close the file only on the first rank.

You can use:
if (irangp.le.0) then
...
endif
Around open and close statements for this.

Regards,

Yvan
spal
Posts: 10
Joined: Sun Feb 19, 2017 2:55 am

Re: Calculating drag and lift on cylinder with cs_user subro

Post by spal »

Yvan,

For some reason I do not even get into the subroutine. I am running the code from the GUI ? The subroutine compiles and links. The file is not even created in the temporary_run directory.

Am I missing something ? I tried both a serial and multiprocessor run.
Yvan Fournier
Posts: 4085
Joined: Mon Feb 20, 2012 3:25 pm

Re: Calculating drag and lift on cylinder with cs_user subro

Post by Yvan Fournier »

Hello,

What system are you running on ? How did you build the code ?

Regards,

Yvan
spal
Posts: 10
Joined: Sun Feb 19, 2017 2:55 am

Re: Calculating drag and lift on cylinder with cs_user subro

Post by spal »

I am running on Ubuntu 16. I did not build the code though I intended to build it initially.

The code was installed using the ubuntu package manager. I had open-mpi, python and Java installed prior to getting code Saturne.
Yvan Fournier
Posts: 4085
Joined: Mon Feb 20, 2012 3:25 pm

Re: Calculating drag and lift on cylinder with cs_user subro

Post by Yvan Fournier »

Hello,

This is a known bug with Ubuntu, which others have encountered:
http://code-saturne.org/forum/search.ph ... d%5B0%5D=2

I just filed a bug with Ubuntu for this, as it makes the package half useless (sorry, I was hoping some user affected by the bug would bother to do this, rather than post on this forum, as it is an Ubuntu bug, and this shows the limits of packaging: Ubuntu packages modifed versions, which do not always work as well as the upstream version).

I just re-tested packages on both upstream Debian (Sid) and Ubuntu (15.10) virtual machines, and reproduce the issue on Ubuntu, while things are fine on Debian. I don't know what additional modification Ubuntu does, but it's a failure.

So the only solution on Ubuntu is either to wait for a fix or build the code yourself...

Regards,

Yvan
spal
Posts: 10
Joined: Sun Feb 19, 2017 2:55 am

Re: Calculating drag and lift on cylinder with cs_user subro

Post by spal »

I will rebuild the code later. For now I will calculate using the ensight format wall stresses that were written out.If I need to restart the run for a few more shedding I cycles, I assume I can restart from the checkpoint file. I had one question regarding the stresses, do the two of the three wall stresses, total, and normal stress include the pressure as well.
Post Reply