Skip to content

Commit

Permalink
Merge branch 'simplify-PETSc-access' into 'development'
Browse files Browse the repository at this point in the history
Simplify pet sc access

See merge request damask/DAMASK!773
  • Loading branch information
sharanroongta committed Jul 11, 2023
2 parents bb49289 + 15e5bce commit ad6220c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 39 deletions.
6 changes: 3 additions & 3 deletions src/grid/grid_damage_spectral.f90
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ end subroutine grid_damage_spectral_forward
!--------------------------------------------------------------------------------------------------
!> @brief Write current solver and constitutive data for restart to file.
!--------------------------------------------------------------------------------------------------
subroutine grid_damage_spectral_restartWrite
subroutine grid_damage_spectral_restartWrite()

PetscErrorCode :: err_PETSc
DM :: dm_local
Expand All @@ -316,7 +316,7 @@ subroutine grid_damage_spectral_restartWrite

call SNESGetDM(SNES_damage,dm_local,err_PETSc);
CHKERRQ(err_PETSc)
call DMDAVecGetArrayF90(dm_local,solution_vec,phi,err_PETSc);
call DMDAVecGetArrayReadF90(dm_local,solution_vec,phi,err_PETSc);
CHKERRQ(err_PETSc)

print'(1x,a)', 'saving damage solver data required for restart'; flush(IO_STDOUT)
Expand All @@ -328,7 +328,7 @@ subroutine grid_damage_spectral_restartWrite
call HDF5_closeGroup(groupHandle)
call HDF5_closeFile(fileHandle)

call DMDAVecRestoreArrayF90(dm_local,solution_vec,phi,err_PETSc);
call DMDAVecRestoreArrayReadF90(dm_local,solution_vec,phi,err_PETSc);
CHKERRQ(err_PETSc)

end subroutine grid_damage_spectral_restartWrite
Expand Down
31 changes: 10 additions & 21 deletions src/grid/grid_mech_FEM.f90
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,8 @@ subroutine grid_mechanical_FEM_forward(cutBack,guess,Delta_t,Delta_t_old,t_remai
rotation_BC

PetscErrorCode :: err_PETSc
PetscScalar, pointer, dimension(:,:,:,:) :: &
u,u_lastInc


call DMDAVecGetArrayF90(mechanical_grid,solution_current,u,err_PETSc)
CHKERRQ(err_PETSc)
call DMDAVecGetArrayF90(mechanical_grid,solution_lastInc,u_lastInc,err_PETSc)
CHKERRQ(err_PETSc)

if (cutBack) then
C_volAvg = C_volAvgLastInc
else
Expand Down Expand Up @@ -408,10 +401,6 @@ subroutine grid_mechanical_FEM_forward(cutBack,guess,Delta_t,Delta_t_old,t_remai

call VecAXPY(solution_current,Delta_t,solution_rate,err_PETSc)
CHKERRQ(err_PETSc)
call DMDAVecRestoreArrayF90(mechanical_grid,solution_current,u,err_PETSc)
CHKERRQ(err_PETSc)
call DMDAVecRestoreArrayF90(mechanical_grid,solution_lastInc,u_lastInc,err_PETSc)
CHKERRQ(err_PETSc)

!--------------------------------------------------------------------------------------------------
! set module wide available data
Expand All @@ -425,7 +414,7 @@ end subroutine grid_mechanical_FEM_forward
!--------------------------------------------------------------------------------------------------
!> @brief Update coordinates
!--------------------------------------------------------------------------------------------------
subroutine grid_mechanical_FEM_updateCoords
subroutine grid_mechanical_FEM_updateCoords()

call utilities_updateCoords(F)

Expand All @@ -435,16 +424,16 @@ end subroutine grid_mechanical_FEM_updateCoords
!--------------------------------------------------------------------------------------------------
!> @brief Write current solver and constitutive data for restart to file
!--------------------------------------------------------------------------------------------------
subroutine grid_mechanical_FEM_restartWrite
subroutine grid_mechanical_FEM_restartWrite()

PetscErrorCode :: err_PETSc
integer(HID_T) :: fileHandle, groupHandle
PetscScalar, dimension(:,:,:,:), pointer :: u,u_lastInc


call DMDAVecGetArrayF90(mechanical_grid,solution_current,u,err_PETSc)
call DMDAVecGetArrayReadF90(mechanical_grid,solution_current,u,err_PETSc)
CHKERRQ(err_PETSc)
call DMDAVecGetArrayF90(mechanical_grid,solution_lastInc,u_lastInc,err_PETSc)
call DMDAVecGetArrayReadF90(mechanical_grid,solution_lastInc,u_lastInc,err_PETSc)
CHKERRQ(err_PETSc)

print'(1x,a)', 'saving solver data required for restart'; flush(IO_STDOUT)
Expand All @@ -471,9 +460,9 @@ subroutine grid_mechanical_FEM_restartWrite
call HDF5_closeFile(fileHandle)
end if

call DMDAVecRestoreArrayF90(mechanical_grid,solution_current,u,err_PETSc)
call DMDAVecRestoreArrayReadF90(mechanical_grid,solution_current,u,err_PETSc)
CHKERRQ(err_PETSc)
call DMDAVecRestoreArrayF90(mechanical_grid,solution_lastInc,u_lastInc,err_PETSc)
call DMDAVecRestoreArrayReadF90(mechanical_grid,solution_lastInc,u_lastInc,err_PETSc)
CHKERRQ(err_PETSc)

end subroutine grid_mechanical_FEM_restartWrite
Expand Down Expand Up @@ -566,7 +555,7 @@ subroutine formResidual(da_local,x_local, &

!--------------------------------------------------------------------------------------------------
! get deformation gradient
call DMDAVecGetArrayF90(da_local,x_local,x_scal,err_PETSc)
call DMDAVecGetArrayReadF90(da_local,x_local,x_scal,err_PETSc)
CHKERRQ(err_PETSc)
do k = cells3Offset+1, cells3Offset+cells3; do j = 1, cells(2); do i = 1, cells(1)
ctr = 0
Expand All @@ -576,7 +565,7 @@ subroutine formResidual(da_local,x_local, &
end do; end do; end do
F(1:3,1:3,i,j,k-cells3Offset) = params%rotation_BC%rotate(F_aim,active=.true.) + transpose(matmul(BMat,x_elem))
end do; end do; end do
call DMDAVecRestoreArrayF90(da_local,x_local,x_scal,err_PETSc)
call DMDAVecRestoreArrayReadF90(da_local,x_local,x_scal,err_PETSc)
CHKERRQ(err_PETSc)

!--------------------------------------------------------------------------------------------------
Expand All @@ -596,7 +585,7 @@ subroutine formResidual(da_local,x_local, &
! constructing residual
call DMDAVecGetArrayF90(da_local,f_local,r,err_PETSc)
CHKERRQ(err_PETSc)
call DMDAVecGetArrayF90(da_local,x_local,x_scal,err_PETSc)
call DMDAVecGetArrayReadF90(da_local,x_local,x_scal,err_PETSc)
CHKERRQ(err_PETSc)
ele = 0
r = 0.0_pREAL
Expand All @@ -617,7 +606,7 @@ subroutine formResidual(da_local,x_local, &
r(0:2,i+ii,j+jj,k+kk) = r(0:2,i+ii,j+jj,k+kk) + f_elem(ctr,1:3)
end do; end do; end do
end do; end do; end do
call DMDAVecRestoreArrayF90(da_local,x_local,x_scal,err_PETSc)
call DMDAVecRestoreArrayReadF90(da_local,x_local,x_scal,err_PETSc)
CHKERRQ(err_PETSc)

!--------------------------------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions src/grid/grid_mech_spectral_basic.f90
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,15 @@ end subroutine grid_mechanical_spectral_basic_forward
!--------------------------------------------------------------------------------------------------
!> @brief Update coordinates
!--------------------------------------------------------------------------------------------------
subroutine grid_mechanical_spectral_basic_updateCoords
subroutine grid_mechanical_spectral_basic_updateCoords()

PetscErrorCode :: err_PETSc
real(pREAL), dimension(:,:,:,:), pointer :: F

call DMDAVecGetArrayF90(da,solution_vec,F,err_PETSc)
call DMDAVecGetArrayReadF90(da,solution_vec,F,err_PETSc)
CHKERRQ(err_PETSc)
call utilities_updateCoords(F)
call DMDAVecRestoreArrayF90(da,solution_vec,F,err_PETSc)
call DMDAVecRestoreArrayReadF90(da,solution_vec,F,err_PETSc)
CHKERRQ(err_PETSc)

end subroutine grid_mechanical_spectral_basic_updateCoords
Expand All @@ -394,13 +394,13 @@ end subroutine grid_mechanical_spectral_basic_updateCoords
!--------------------------------------------------------------------------------------------------
!> @brief Write current solver and constitutive data for restart to file
!--------------------------------------------------------------------------------------------------
subroutine grid_mechanical_spectral_basic_restartWrite
subroutine grid_mechanical_spectral_basic_restartWrite()

PetscErrorCode :: err_PETSc
integer(HID_T) :: fileHandle, groupHandle
real(pREAL), dimension(:,:,:,:), pointer :: F

call DMDAVecGetArrayF90(da,solution_vec,F,err_PETSc)
call DMDAVecGetArrayReadF90(da,solution_vec,F,err_PETSc)
CHKERRQ(err_PETSc)

if (num%update_gamma) C_minMaxAvgRestart = C_minMaxAvg
Expand Down Expand Up @@ -428,7 +428,7 @@ subroutine grid_mechanical_spectral_basic_restartWrite
call HDF5_closeFile(fileHandle)
end if

call DMDAVecRestoreArrayF90(da,solution_vec,F,err_PETSc)
call DMDAVecRestoreArrayReadF90(da,solution_vec,F,err_PETSc)
CHKERRQ(err_PETSc)

end subroutine grid_mechanical_spectral_basic_restartWrite
Expand Down
12 changes: 6 additions & 6 deletions src/grid/grid_mech_spectral_polarisation.f90
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,15 @@ end subroutine grid_mechanical_spectral_polarisation_forward
!--------------------------------------------------------------------------------------------------
!> @brief Update coordinates
!--------------------------------------------------------------------------------------------------
subroutine grid_mechanical_spectral_polarisation_updateCoords
subroutine grid_mechanical_spectral_polarisation_updateCoords()

PetscErrorCode :: err_PETSc
real(pREAL), dimension(:,:,:,:), pointer :: FandF_tau

call DMDAVecGetArrayF90(da,solution_vec,FandF_tau,err_PETSc)
call DMDAVecGetArrayReadF90(da,solution_vec,FandF_tau,err_PETSc)
CHKERRQ(err_PETSc)
call utilities_updateCoords(FandF_tau(0:8,:,:,:))
call DMDAVecRestoreArrayF90(da,solution_vec,FandF_tau,err_PETSc)
call DMDAVecRestoreArrayReadF90(da,solution_vec,FandF_tau,err_PETSc)
CHKERRQ(err_PETSc)

end subroutine grid_mechanical_spectral_polarisation_updateCoords
Expand All @@ -451,13 +451,13 @@ end subroutine grid_mechanical_spectral_polarisation_updateCoords
!--------------------------------------------------------------------------------------------------
!> @brief Write current solver and constitutive data for restart to file
!--------------------------------------------------------------------------------------------------
subroutine grid_mechanical_spectral_polarisation_restartWrite
subroutine grid_mechanical_spectral_polarisation_restartWrite()

PetscErrorCode :: err_PETSc
integer(HID_T) :: fileHandle, groupHandle
real(pREAL), dimension(:,:,:,:), pointer :: FandF_tau, F, F_tau

call DMDAVecGetArrayF90(da,solution_vec,FandF_tau,err_PETSc)
call DMDAVecGetArrayReadF90(da,solution_vec,FandF_tau,err_PETSc)
CHKERRQ(err_PETSc)
F => FandF_tau(0: 8,:,:,:)
F_tau => FandF_tau(9:17,:,:,:)
Expand Down Expand Up @@ -489,7 +489,7 @@ subroutine grid_mechanical_spectral_polarisation_restartWrite
call HDF5_closeFile(fileHandle)
end if

call DMDAVecRestoreArrayF90(da,solution_vec,FandF_tau,err_PETSc)
call DMDAVecRestoreArrayReadF90(da,solution_vec,FandF_tau,err_PETSc)
CHKERRQ(err_PETSc)

end subroutine grid_mechanical_spectral_polarisation_restartWrite
Expand Down
6 changes: 3 additions & 3 deletions src/grid/grid_thermal_spectral.f90
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ end subroutine grid_thermal_spectral_forward
!--------------------------------------------------------------------------------------------------
!> @brief Write current solver and constitutive data for restart to file.
!--------------------------------------------------------------------------------------------------
subroutine grid_thermal_spectral_restartWrite
subroutine grid_thermal_spectral_restartWrite()

PetscErrorCode :: err_PETSc
DM :: dm_local
Expand All @@ -294,7 +294,7 @@ subroutine grid_thermal_spectral_restartWrite

call SNESGetDM(SNES_thermal,dm_local,err_PETSc);
CHKERRQ(err_PETSc)
call DMDAVecGetArrayF90(dm_local,solution_vec,T,err_PETSc);
call DMDAVecGetArrayReadF90(dm_local,solution_vec,T,err_PETSc);
CHKERRQ(err_PETSc)

print'(1x,a)', 'saving thermal solver data required for restart'; flush(IO_STDOUT)
Expand All @@ -307,7 +307,7 @@ subroutine grid_thermal_spectral_restartWrite
call HDF5_closeGroup(groupHandle)
call HDF5_closeFile(fileHandle)

call DMDAVecRestoreArrayF90(dm_local,solution_vec,T,err_PETSc);
call DMDAVecRestoreArrayReadF90(dm_local,solution_vec,T,err_PETSc);
CHKERRQ(err_PETSc)

end subroutine grid_thermal_spectral_restartWrite
Expand Down

0 comments on commit ad6220c

Please sign in to comment.