2015-06-03 23:00:31 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2019-03-12 16:06:18 +05:30
|
|
|
!> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH
|
2015-06-03 23:00:31 +05:30
|
|
|
!> @author Pratheek Shanthraj, Max-Planck-Institut für Eisenforschung GmbH
|
|
|
|
!> @author Shaokang Zhang, Max-Planck-Institut für Eisenforschung GmbH
|
|
|
|
!> @brief Spectral solver for thermal conduction
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2019-03-12 04:07:06 +05:30
|
|
|
module grid_thermal_spectral
|
2018-05-17 15:34:21 +05:30
|
|
|
#include <petsc/finclude/petscsnes.h>
|
|
|
|
#include <petsc/finclude/petscdmda.h>
|
2021-07-08 18:51:35 +05:30
|
|
|
use PETScDMDA
|
|
|
|
use PETScSNES
|
2021-07-09 22:18:25 +05:30
|
|
|
#if (PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR>14) && !defined(PETSC_HAVE_MPI_F90MODULE_VISIBILITY)
|
2021-07-08 18:51:35 +05:30
|
|
|
use MPI_f08
|
|
|
|
#endif
|
2019-06-10 00:50:38 +05:30
|
|
|
|
|
|
|
use prec
|
2020-09-13 13:49:38 +05:30
|
|
|
use parallelization
|
2020-06-18 00:16:03 +05:30
|
|
|
use IO
|
2022-04-24 08:13:44 +05:30
|
|
|
use CLI
|
2022-01-11 01:04:50 +05:30
|
|
|
use HDF5_utilities
|
2022-02-02 03:26:34 +05:30
|
|
|
use HDF5
|
2019-06-10 00:50:38 +05:30
|
|
|
use spectral_utilities
|
2020-03-20 11:28:55 +05:30
|
|
|
use discretization_grid
|
2021-01-17 19:49:36 +05:30
|
|
|
use homogenization
|
2020-06-18 00:16:03 +05:30
|
|
|
use YAML_types
|
2020-08-15 19:32:10 +05:30
|
|
|
use config
|
2021-01-17 17:05:47 +05:30
|
|
|
|
2022-06-22 02:41:22 +05:30
|
|
|
#if (PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR>14) && !defined(PETSC_HAVE_MPI_F90MODULE_VISIBILITY)
|
2022-06-22 02:16:54 +05:30
|
|
|
implicit none(type,external)
|
2022-06-22 02:41:22 +05:30
|
|
|
#else
|
|
|
|
implicit none
|
|
|
|
#endif
|
2019-03-12 16:06:18 +05:30
|
|
|
private
|
2019-06-10 00:50:38 +05:30
|
|
|
|
2020-06-29 18:39:13 +05:30
|
|
|
type :: tNumerics
|
2020-06-29 20:35:11 +05:30
|
|
|
integer :: &
|
2020-09-19 11:50:29 +05:30
|
|
|
itmax !< maximum number of iterations
|
2020-06-24 20:09:09 +05:30
|
|
|
real(pReal) :: &
|
2020-09-19 11:50:29 +05:30
|
|
|
eps_thermal_atol, & !< absolute tolerance for thermal equilibrium
|
|
|
|
eps_thermal_rtol !< relative tolerance for thermal equilibrium
|
2020-06-24 20:09:09 +05:30
|
|
|
end type tNumerics
|
|
|
|
|
2020-06-29 18:39:13 +05:30
|
|
|
type(tNumerics) :: num
|
2020-06-24 20:09:09 +05:30
|
|
|
|
2020-09-19 11:50:29 +05:30
|
|
|
type(tSolutionParams) :: params
|
2015-06-03 23:00:31 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
! PETSc data
|
2022-01-19 23:28:46 +05:30
|
|
|
SNES :: SNES_thermal
|
2022-01-19 23:19:47 +05:30
|
|
|
Vec :: solution_vec
|
2020-06-29 18:39:13 +05:30
|
|
|
real(pReal), dimension(:,:,:), allocatable :: &
|
2022-11-27 21:37:25 +05:30
|
|
|
T, & !< field of current temperature
|
2020-01-31 03:37:45 +05:30
|
|
|
T_lastInc, & !< field of previous temperature
|
2022-09-23 21:45:47 +05:30
|
|
|
T_stagInc, & !< field of staggered temperature
|
|
|
|
dotT_lastInc
|
2015-06-03 23:00:31 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2021-01-17 17:05:47 +05:30
|
|
|
! reference diffusion tensor, mobility etc.
|
2021-04-11 19:02:17 +05:30
|
|
|
integer :: totalIter = 0 !< total iteration in current increment
|
2020-06-29 18:39:13 +05:30
|
|
|
real(pReal), dimension(3,3) :: K_ref
|
|
|
|
real(pReal) :: mu_ref
|
2021-01-17 17:05:47 +05:30
|
|
|
|
2019-03-12 16:06:18 +05:30
|
|
|
public :: &
|
|
|
|
grid_thermal_spectral_init, &
|
|
|
|
grid_thermal_spectral_solution, &
|
2022-01-11 01:04:50 +05:30
|
|
|
grid_thermal_spectral_restartWrite, &
|
2019-03-12 16:06:18 +05:30
|
|
|
grid_thermal_spectral_forward
|
2015-06-03 23:00:31 +05:30
|
|
|
|
|
|
|
contains
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2019-03-12 10:23:12 +05:30
|
|
|
!> @brief allocates all neccessary fields and fills them with data
|
2015-06-03 23:00:31 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-03-10 01:59:40 +05:30
|
|
|
subroutine grid_thermal_spectral_init()
|
2019-03-09 14:24:33 +05:30
|
|
|
|
2021-01-17 17:05:47 +05:30
|
|
|
PetscInt, dimension(0:worldsize-1) :: localK
|
|
|
|
integer :: i, j, k, ce
|
2019-03-09 14:24:33 +05:30
|
|
|
DM :: thermal_grid
|
2022-11-25 18:19:50 +05:30
|
|
|
real(pReal), dimension(:,:,:), pointer :: T_PETSc
|
2022-01-13 17:11:11 +05:30
|
|
|
integer(MPI_INTEGER_KIND) :: err_MPI
|
|
|
|
PetscErrorCode :: err_PETSc
|
2022-01-11 01:04:50 +05:30
|
|
|
integer(HID_T) :: fileHandle, groupHandle
|
2022-11-27 21:37:25 +05:30
|
|
|
real(pReal), dimension(1,product(cells(1:2))*cells3) :: tempN
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tDict), pointer :: &
|
2020-06-19 06:02:33 +05:30
|
|
|
num_grid
|
2015-06-03 23:00:31 +05:30
|
|
|
|
2021-11-15 23:05:44 +05:30
|
|
|
print'(/,1x,a)', '<<<+- grid_thermal_spectral init -+>>>'
|
2019-03-09 15:32:12 +05:30
|
|
|
|
2021-11-15 23:05:44 +05:30
|
|
|
print'(/,1x,a)', 'P. Shanthraj et al., Handbook of Mechanics of Materials, 2019'
|
|
|
|
print'( 1x,a)', 'https://doi.org/10.1007/978-981-10-6855-3_80'
|
2019-03-12 04:07:06 +05:30
|
|
|
|
2022-12-30 00:38:05 +05:30
|
|
|
if (.not. homogenization_thermal_active()) call IO_error(501,ext_msg='thermal')
|
|
|
|
|
2020-06-18 02:30:03 +05:30
|
|
|
!-------------------------------------------------------------------------------------------------
|
2020-09-19 11:50:29 +05:30
|
|
|
! read numerical parameters and do sanity checks
|
2022-10-25 21:39:36 +05:30
|
|
|
num_grid => config_numerics%get_dict('grid',defaultVal=emptyDict)
|
2020-06-29 20:35:11 +05:30
|
|
|
num%itmax = num_grid%get_asInt ('itmax', defaultVal=250)
|
2020-06-24 20:09:09 +05:30
|
|
|
num%eps_thermal_atol = num_grid%get_asFloat ('eps_thermal_atol',defaultVal=1.0e-2_pReal)
|
|
|
|
num%eps_thermal_rtol = num_grid%get_asFloat ('eps_thermal_rtol',defaultVal=1.0e-6_pReal)
|
2020-06-24 20:39:15 +05:30
|
|
|
|
2021-04-11 19:02:17 +05:30
|
|
|
if (num%itmax <= 1) call IO_error(301,ext_msg='itmax')
|
|
|
|
if (num%eps_thermal_atol <= 0.0_pReal) call IO_error(301,ext_msg='eps_thermal_atol')
|
|
|
|
if (num%eps_thermal_rtol <= 0.0_pReal) call IO_error(301,ext_msg='eps_thermal_rtol')
|
2020-06-24 20:39:15 +05:30
|
|
|
|
2019-03-12 04:07:06 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
! set default and user defined options for PETSc
|
2021-05-05 20:38:31 +05:30
|
|
|
call PetscOptionsInsertString(PETSC_NULL_OPTIONS,'-thermal_snes_type newtonls -thermal_snes_mf &
|
2022-01-13 17:11:11 +05:30
|
|
|
&-thermal_snes_ksp_ew -thermal_ksp_type fgmres',err_PETSc)
|
|
|
|
CHKERRQ(err_PETSc)
|
|
|
|
call PetscOptionsInsertString(PETSC_NULL_OPTIONS,num_grid%get_asString('petsc_options',defaultVal=''),err_PETSc)
|
|
|
|
CHKERRQ(err_PETSc)
|
2021-01-17 17:05:47 +05:30
|
|
|
|
2022-01-19 21:16:13 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
! init fields
|
2022-11-27 21:37:25 +05:30
|
|
|
T = discretization_grid_getInitialCondition('T')
|
|
|
|
T_lastInc = T
|
|
|
|
T_stagInc = T
|
|
|
|
dotT_lastInc = 0.0_pReal * T
|
2022-01-19 21:16:13 +05:30
|
|
|
|
2015-06-03 23:00:31 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
! initialize solver specific parts of PETSc
|
2022-01-26 16:48:26 +05:30
|
|
|
call SNESCreate(PETSC_COMM_WORLD,SNES_thermal,err_PETSc)
|
|
|
|
CHKERRQ(err_PETSc)
|
|
|
|
call SNESSetOptionsPrefix(SNES_thermal,'thermal_',err_PETSc)
|
|
|
|
CHKERRQ(err_PETSc)
|
2021-12-22 03:31:00 +05:30
|
|
|
localK = 0_pPetscInt
|
2022-01-29 19:35:07 +05:30
|
|
|
localK(worldrank) = int(cells3,pPetscInt)
|
2022-01-13 17:11:11 +05:30
|
|
|
call MPI_Allreduce(MPI_IN_PLACE,localK,worldsize,MPI_INTEGER,MPI_SUM,MPI_COMM_WORLD,err_MPI)
|
|
|
|
if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error'
|
2019-03-09 14:24:33 +05:30
|
|
|
call DMDACreate3D(PETSC_COMM_WORLD, &
|
|
|
|
DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, & ! cut off stencil at boundary
|
|
|
|
DMDA_STENCIL_BOX, & ! Moore (26) neighborhood around central point
|
2022-01-29 19:35:07 +05:30
|
|
|
int(cells(1),pPetscInt),int(cells(2),pPetscInt),int(cells(3),pPetscInt), & ! global cells
|
2021-12-22 03:31:00 +05:30
|
|
|
1_pPetscInt, 1_pPetscInt, int(worldsize,pPetscInt), &
|
|
|
|
1_pPetscInt, 0_pPetscInt, & ! #dof (T, scalar), ghost boundary width (domain overlap)
|
2022-01-29 19:35:07 +05:30
|
|
|
[int(cells(1),pPetscInt)],[int(cells(2),pPetscInt)],localK, & ! local cells
|
2022-01-13 17:11:11 +05:30
|
|
|
thermal_grid,err_PETSc) ! handle, error
|
|
|
|
CHKERRQ(err_PETSc)
|
2022-01-26 16:48:26 +05:30
|
|
|
call DMsetFromOptions(thermal_grid,err_PETSc)
|
|
|
|
CHKERRQ(err_PETSc)
|
|
|
|
call DMsetUp(thermal_grid,err_PETSc)
|
|
|
|
CHKERRQ(err_PETSc)
|
2022-01-29 19:35:07 +05:30
|
|
|
call DMCreateGlobalVector(thermal_grid,solution_vec,err_PETSc) ! global solution vector (cells x 1, i.e. every def grad tensor)
|
2022-01-13 17:11:11 +05:30
|
|
|
CHKERRQ(err_PETSc)
|
|
|
|
call DMDASNESSetFunctionLocal(thermal_grid,INSERT_VALUES,formResidual,PETSC_NULL_SNES,err_PETSc) ! residual vector of same shape as solution vector
|
|
|
|
CHKERRQ(err_PETSc)
|
2022-01-26 16:48:26 +05:30
|
|
|
call SNESSetDM(SNES_thermal,thermal_grid,err_PETSc)
|
|
|
|
CHKERRQ(err_PETSc)
|
|
|
|
call SNESSetFromOptions(SNES_thermal,err_PETSc) ! pull it all together with additional CLI arguments
|
|
|
|
CHKERRQ(err_PETSc)
|
2015-06-03 23:00:31 +05:30
|
|
|
|
2022-01-11 01:04:50 +05:30
|
|
|
|
2022-04-23 18:22:10 +05:30
|
|
|
restartRead: if (CLI_restartInc > 0) then
|
|
|
|
print'(/,1x,a,i0,a)', 'reading restart data of increment ', CLI_restartInc, ' from file'
|
2022-01-11 01:04:50 +05:30
|
|
|
|
|
|
|
fileHandle = HDF5_openFile(getSolverJobName()//'_restart.hdf5','r')
|
|
|
|
groupHandle = HDF5_openGroup(fileHandle,'solver')
|
|
|
|
|
2022-11-27 21:37:25 +05:30
|
|
|
call HDF5_read(tempN,groupHandle,'T',.false.)
|
|
|
|
T = reshape(tempN,[cells(1),cells(2),cells3])
|
|
|
|
call HDF5_read(tempN,groupHandle,'T_lastInc',.false.)
|
|
|
|
T_lastInc = reshape(tempN,[cells(1),cells(2),cells3])
|
|
|
|
call HDF5_read(tempN,groupHandle,'dotT_lastInc',.false.)
|
|
|
|
dotT_lastInc = reshape(tempN,[cells(1),cells(2),cells3])
|
2022-02-03 13:31:33 +05:30
|
|
|
end if restartRead
|
2021-04-11 19:02:17 +05:30
|
|
|
|
2021-01-17 17:05:47 +05:30
|
|
|
ce = 0
|
2022-02-03 13:31:33 +05:30
|
|
|
do k = 1, cells3; do j = 1, cells(2); do i = 1, cells(1)
|
2021-01-17 17:05:47 +05:30
|
|
|
ce = ce + 1
|
2022-11-27 21:37:25 +05:30
|
|
|
call homogenization_thermal_setField(T(i,j,k),0.0_pReal,ce)
|
2021-11-15 23:05:44 +05:30
|
|
|
end do; end do; end do
|
2021-04-11 19:02:17 +05:30
|
|
|
|
2022-01-13 17:11:11 +05:30
|
|
|
call DMDAVecGetArrayF90(thermal_grid,solution_vec,T_PETSc,err_PETSc)
|
|
|
|
CHKERRQ(err_PETSc)
|
2022-11-27 21:37:25 +05:30
|
|
|
T_PETSc = T
|
2022-01-13 17:11:11 +05:30
|
|
|
call DMDAVecRestoreArrayF90(thermal_grid,solution_vec,T_PETSc,err_PETSc)
|
|
|
|
CHKERRQ(err_PETSc)
|
2015-06-03 23:00:31 +05:30
|
|
|
|
2022-01-19 23:28:46 +05:30
|
|
|
call updateReference()
|
2015-06-03 23:00:31 +05:30
|
|
|
|
2019-03-12 04:07:06 +05:30
|
|
|
end subroutine grid_thermal_spectral_init
|
2019-03-12 16:06:18 +05:30
|
|
|
|
2021-01-17 17:05:47 +05:30
|
|
|
|
2015-06-03 23:00:31 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2016-06-27 21:20:43 +05:30
|
|
|
!> @brief solution for the spectral thermal scheme with internal iterations
|
2015-06-03 23:00:31 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2021-07-20 02:00:20 +05:30
|
|
|
function grid_thermal_spectral_solution(Delta_t) result(solution)
|
2021-01-17 17:05:47 +05:30
|
|
|
|
2019-03-09 14:24:33 +05:30
|
|
|
real(pReal), intent(in) :: &
|
2021-07-20 02:00:20 +05:30
|
|
|
Delta_t !< increment in time for current solution
|
2021-01-17 17:05:47 +05:30
|
|
|
integer :: i, j, k, ce
|
2019-03-12 04:07:06 +05:30
|
|
|
type(tSolutionState) :: solution
|
2020-01-31 03:37:45 +05:30
|
|
|
PetscInt :: devNull
|
2021-12-11 16:07:17 +05:30
|
|
|
PetscReal :: T_min, T_max, stagNorm
|
2016-06-27 21:20:43 +05:30
|
|
|
|
2022-01-13 17:11:11 +05:30
|
|
|
integer(MPI_INTEGER_KIND) :: err_MPI
|
|
|
|
PetscErrorCode :: err_PETSc
|
2019-03-09 14:24:33 +05:30
|
|
|
SNESConvergedReason :: reason
|
2016-06-27 21:20:43 +05:30
|
|
|
|
2019-03-12 04:07:06 +05:30
|
|
|
solution%converged =.false.
|
2021-01-17 17:05:47 +05:30
|
|
|
|
2015-06-03 23:00:31 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2021-01-17 17:05:47 +05:30
|
|
|
! set module wide availabe data
|
2021-07-20 02:00:20 +05:30
|
|
|
params%Delta_t = Delta_t
|
2015-06-03 23:00:31 +05:30
|
|
|
|
2022-01-19 23:28:46 +05:30
|
|
|
call SNESSolve(SNES_thermal,PETSC_NULL_VEC,solution_vec,err_PETSc)
|
2022-01-13 17:11:11 +05:30
|
|
|
CHKERRQ(err_PETSc)
|
2022-01-19 23:28:46 +05:30
|
|
|
call SNESGetConvergedReason(SNES_thermal,reason,err_PETSc)
|
2022-01-13 17:11:11 +05:30
|
|
|
CHKERRQ(err_PETSc)
|
2015-06-03 23:00:31 +05:30
|
|
|
|
2019-03-09 14:24:33 +05:30
|
|
|
if (reason < 1) then
|
2019-03-12 04:07:06 +05:30
|
|
|
solution%converged = .false.
|
2020-06-29 20:35:11 +05:30
|
|
|
solution%iterationsNeeded = num%itmax
|
2019-03-09 14:24:33 +05:30
|
|
|
else
|
2019-03-12 04:07:06 +05:30
|
|
|
solution%converged = .true.
|
|
|
|
solution%iterationsNeeded = totalIter
|
2021-11-15 23:05:44 +05:30
|
|
|
end if
|
2022-11-27 21:37:25 +05:30
|
|
|
stagNorm = maxval(abs(T - T_stagInc))
|
2022-01-13 18:20:30 +05:30
|
|
|
call MPI_Allreduce(MPI_IN_PLACE,stagNorm,1_MPI_INTEGER_KIND,MPI_DOUBLE,MPI_MAX,MPI_COMM_WORLD,err_MPI)
|
2022-01-13 17:11:11 +05:30
|
|
|
if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error'
|
2022-11-27 21:37:25 +05:30
|
|
|
solution%stagConverged = stagNorm < max(num%eps_thermal_atol, num%eps_thermal_rtol*maxval(T))
|
2022-01-13 18:20:30 +05:30
|
|
|
call MPI_Allreduce(MPI_IN_PLACE,solution%stagConverged,1_MPI_INTEGER_KIND,MPI_LOGICAL,MPI_LAND,MPI_COMM_WORLD,err_MPI)
|
2022-01-13 17:11:11 +05:30
|
|
|
if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error'
|
2022-11-27 21:37:25 +05:30
|
|
|
T_stagInc = T
|
2015-06-03 23:00:31 +05:30
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2021-01-17 17:05:47 +05:30
|
|
|
! updating thermal state
|
|
|
|
ce = 0
|
2022-01-29 19:35:07 +05:30
|
|
|
do k = 1, cells3; do j = 1, cells(2); do i = 1,cells(1)
|
2021-01-17 17:05:47 +05:30
|
|
|
ce = ce + 1
|
2022-11-27 21:37:25 +05:30
|
|
|
call homogenization_thermal_setField(T(i,j,k),(T(i,j,k)-T_lastInc(i,j,k))/params%Delta_t,ce)
|
2021-11-15 23:05:44 +05:30
|
|
|
end do; end do; end do
|
2015-06-03 23:00:31 +05:30
|
|
|
|
2022-01-26 16:48:26 +05:30
|
|
|
call VecMin(solution_vec,devNull,T_min,err_PETSc)
|
|
|
|
CHKERRQ(err_PETSc)
|
|
|
|
call VecMax(solution_vec,devNull,T_max,err_PETSc)
|
|
|
|
CHKERRQ(err_PETSc)
|
2019-03-12 04:07:06 +05:30
|
|
|
if (solution%converged) &
|
2021-11-15 23:05:44 +05:30
|
|
|
print'(/,1x,a)', '... thermal conduction converged ..................................'
|
|
|
|
print'(/,1x,a,f8.4,2x,f8.4,2x,f8.4)', 'Minimum|Maximum|Delta Temperature / K = ', T_min, T_max, stagNorm
|
|
|
|
print'(/,1x,a)', '==========================================================================='
|
2021-01-17 17:05:47 +05:30
|
|
|
flush(IO_STDOUT)
|
2015-06-03 23:00:31 +05:30
|
|
|
|
2019-03-12 04:07:06 +05:30
|
|
|
end function grid_thermal_spectral_solution
|
2015-06-03 23:00:31 +05:30
|
|
|
|
|
|
|
|
2019-03-12 10:23:12 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief forwarding routine
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2019-10-30 03:54:12 +05:30
|
|
|
subroutine grid_thermal_spectral_forward(cutBack)
|
2021-01-17 17:05:47 +05:30
|
|
|
|
2019-10-30 03:54:12 +05:30
|
|
|
logical, intent(in) :: cutBack
|
2022-11-19 13:55:06 +05:30
|
|
|
|
2021-01-17 17:05:47 +05:30
|
|
|
integer :: i, j, k, ce
|
2019-03-12 16:06:18 +05:30
|
|
|
DM :: dm_local
|
2022-11-25 18:19:50 +05:30
|
|
|
real(pReal), dimension(:,:,:), pointer :: T_PETSc
|
2022-01-13 17:11:11 +05:30
|
|
|
PetscErrorCode :: err_PETSc
|
2021-01-17 17:05:47 +05:30
|
|
|
|
2022-11-19 13:55:06 +05:30
|
|
|
|
2021-01-17 17:05:47 +05:30
|
|
|
if (cutBack) then
|
2022-11-27 21:37:25 +05:30
|
|
|
T = T_lastInc
|
2020-01-31 03:37:45 +05:30
|
|
|
T_stagInc = T_lastInc
|
2019-03-12 10:23:12 +05:30
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2021-01-17 17:05:47 +05:30
|
|
|
! reverting thermal field state
|
2022-01-19 23:28:46 +05:30
|
|
|
call SNESGetDM(SNES_thermal,dm_local,err_PETSc)
|
2022-01-13 17:11:11 +05:30
|
|
|
CHKERRQ(err_PETSc)
|
2022-01-20 00:13:54 +05:30
|
|
|
call DMDAVecGetArrayF90(dm_local,solution_vec,T_PETSc,err_PETSc) !< get the data out of PETSc to work with
|
2022-01-13 17:11:11 +05:30
|
|
|
CHKERRQ(err_PETSc)
|
2022-11-27 21:37:25 +05:30
|
|
|
T_PETSc = T
|
2022-01-20 00:13:54 +05:30
|
|
|
call DMDAVecRestoreArrayF90(dm_local,solution_vec,T_PETSc,err_PETSc)
|
2022-01-13 17:11:11 +05:30
|
|
|
CHKERRQ(err_PETSc)
|
2021-04-11 19:02:17 +05:30
|
|
|
ce = 0
|
2022-01-29 19:35:07 +05:30
|
|
|
do k = 1, cells3; do j = 1, cells(2); do i = 1,cells(1)
|
2021-01-17 17:05:47 +05:30
|
|
|
ce = ce + 1
|
2022-11-27 21:37:25 +05:30
|
|
|
call homogenization_thermal_setField(T(i,j,k),dotT_lastInc(i,j,k),ce)
|
2021-11-15 23:05:44 +05:30
|
|
|
end do; end do; end do
|
2019-03-12 16:06:18 +05:30
|
|
|
else
|
2022-11-27 21:37:25 +05:30
|
|
|
dotT_lastInc = (T - T_lastInc)/params%Delta_t
|
|
|
|
T_lastInc = T
|
2020-01-31 03:37:45 +05:30
|
|
|
call updateReference
|
2021-11-15 23:05:44 +05:30
|
|
|
end if
|
2021-01-17 17:05:47 +05:30
|
|
|
|
2019-03-12 10:23:12 +05:30
|
|
|
end subroutine grid_thermal_spectral_forward
|
|
|
|
|
|
|
|
|
2022-01-11 01:04:50 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-12-05 16:22:59 +05:30
|
|
|
!> @brief Write current solver and constitutive data for restart to file.
|
2022-01-11 01:04:50 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
subroutine grid_thermal_spectral_restartWrite
|
|
|
|
|
2022-02-02 03:26:34 +05:30
|
|
|
PetscErrorCode :: err_PETSc
|
2022-01-11 01:04:50 +05:30
|
|
|
DM :: dm_local
|
|
|
|
integer(HID_T) :: fileHandle, groupHandle
|
2022-11-25 18:19:50 +05:30
|
|
|
real(pReal), dimension(:,:,:), pointer :: T
|
2022-01-11 01:04:50 +05:30
|
|
|
|
2022-02-03 13:31:33 +05:30
|
|
|
call SNESGetDM(SNES_thermal,dm_local,err_PETSc);
|
2022-02-02 03:26:34 +05:30
|
|
|
CHKERRQ(err_PETSc)
|
2022-02-03 13:31:33 +05:30
|
|
|
call DMDAVecGetArrayF90(dm_local,solution_vec,T,err_PETSc);
|
2022-02-02 03:26:34 +05:30
|
|
|
CHKERRQ(err_PETSc)
|
2022-01-11 01:04:50 +05:30
|
|
|
|
2022-01-13 01:12:37 +05:30
|
|
|
print'(1x,a)', 'writing thermal solver data required for restart to file'; flush(IO_STDOUT)
|
2022-01-11 01:04:50 +05:30
|
|
|
|
2022-01-13 01:12:37 +05:30
|
|
|
fileHandle = HDF5_openFile(getSolverJobName()//'_restart.hdf5','a')
|
|
|
|
groupHandle = HDF5_openGroup(fileHandle,'solver')
|
2022-11-27 21:37:25 +05:30
|
|
|
call HDF5_write(reshape(T,[1,product(cells(1:2))*cells3]),groupHandle,'T')
|
|
|
|
call HDF5_write(reshape(T_lastInc,[1,product(cells(1:2))*cells3]),groupHandle,'T_lastInc')
|
|
|
|
call HDF5_write(reshape(dotT_lastInc,[1,product(cells(1:2))*cells3]),groupHandle,'dotT_lastInc')
|
2022-01-11 01:04:50 +05:30
|
|
|
call HDF5_closeGroup(groupHandle)
|
|
|
|
call HDF5_closeFile(fileHandle)
|
|
|
|
|
2022-02-03 13:31:33 +05:30
|
|
|
call DMDAVecRestoreArrayF90(dm_local,solution_vec,T,err_PETSc);
|
2022-02-02 03:26:34 +05:30
|
|
|
CHKERRQ(err_PETSc)
|
2022-01-11 01:04:50 +05:30
|
|
|
|
|
|
|
end subroutine grid_thermal_spectral_restartWrite
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-06-03 23:00:31 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-12-05 16:22:59 +05:30
|
|
|
!> @brief Construct the residual vector.
|
2015-06-03 23:00:31 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-12-05 15:08:36 +05:30
|
|
|
subroutine formResidual(residual_subdomain,x_scal,r,dummy,err_PETSc)
|
2021-01-17 17:05:47 +05:30
|
|
|
|
2019-03-12 16:06:18 +05:30
|
|
|
DMDALocalInfo, dimension(DMDA_LOCAL_INFO_SIZE) :: &
|
2022-12-05 15:08:36 +05:30
|
|
|
residual_subdomain
|
|
|
|
real(pReal), dimension(cells(1),cells(2),cells3), intent(in) :: &
|
2019-03-12 16:06:18 +05:30
|
|
|
x_scal
|
2022-12-05 15:08:36 +05:30
|
|
|
real(pReal), dimension(cells(1),cells(2),cells3), intent(out) :: &
|
|
|
|
r !< residual
|
2019-03-12 16:06:18 +05:30
|
|
|
PetscObject :: dummy
|
2022-11-19 13:55:06 +05:30
|
|
|
PetscErrorCode, intent(out) :: err_PETSc
|
|
|
|
|
2021-01-17 17:05:47 +05:30
|
|
|
integer :: i, j, k, ce
|
2022-11-19 17:35:12 +05:30
|
|
|
real(pReal), dimension(3,cells(1),cells(2),cells3) :: vectorField
|
2015-06-03 23:00:31 +05:30
|
|
|
|
2022-11-19 13:55:06 +05:30
|
|
|
|
2022-11-27 21:37:25 +05:30
|
|
|
T = x_scal
|
|
|
|
vectorField = utilities_ScalarGradient(T)
|
2021-01-17 17:05:47 +05:30
|
|
|
ce = 0
|
2022-01-29 19:35:07 +05:30
|
|
|
do k = 1, cells3; do j = 1, cells(2); do i = 1,cells(1)
|
2021-01-17 17:05:47 +05:30
|
|
|
ce = ce + 1
|
2022-11-19 17:35:12 +05:30
|
|
|
vectorField(1:3,i,j,k) = matmul(homogenization_K_T(ce) - K_ref, vectorField(1:3,i,j,k))
|
2021-11-15 23:05:44 +05:30
|
|
|
end do; end do; end do
|
2022-11-19 17:35:12 +05:30
|
|
|
r = utilities_VectorDivergence(vectorField)
|
2021-01-17 17:05:47 +05:30
|
|
|
ce = 0
|
2022-01-29 19:35:07 +05:30
|
|
|
do k = 1, cells3; do j = 1, cells(2); do i = 1,cells(1)
|
2021-01-17 17:05:47 +05:30
|
|
|
ce = ce + 1
|
2022-11-19 17:35:12 +05:30
|
|
|
r(i,j,k) = params%Delta_t*(r(i,j,k) + homogenization_f_T(ce)) &
|
2022-11-27 21:37:25 +05:30
|
|
|
+ homogenization_mu_T(ce) * (T_lastInc(i,j,k) - T(i,j,k)) &
|
|
|
|
+ mu_ref*T(i,j,k)
|
2021-11-15 23:05:44 +05:30
|
|
|
end do; end do; end do
|
2015-06-03 23:00:31 +05:30
|
|
|
|
2022-11-27 21:37:25 +05:30
|
|
|
r = T &
|
2022-11-19 16:54:16 +05:30
|
|
|
- utilities_GreenConvolution(r, K_ref, mu_ref, params%Delta_t)
|
2022-01-20 12:26:45 +05:30
|
|
|
err_PETSc = 0
|
2015-06-03 23:00:31 +05:30
|
|
|
|
2019-03-12 10:23:12 +05:30
|
|
|
end subroutine formResidual
|
2015-06-03 23:00:31 +05:30
|
|
|
|
2020-01-31 03:37:45 +05:30
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-12-05 16:22:59 +05:30
|
|
|
!> @brief Update reference viscosity and conductivity.
|
2020-01-31 03:37:45 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2021-04-11 19:02:17 +05:30
|
|
|
subroutine updateReference()
|
2020-01-31 03:37:45 +05:30
|
|
|
|
2022-01-13 17:11:11 +05:30
|
|
|
integer :: ce
|
|
|
|
integer(MPI_INTEGER_KIND) :: err_MPI
|
2021-04-11 13:16:11 +05:30
|
|
|
|
2021-01-17 17:05:47 +05:30
|
|
|
|
2020-01-31 03:37:45 +05:30
|
|
|
K_ref = 0.0_pReal
|
|
|
|
mu_ref = 0.0_pReal
|
2022-01-29 19:35:07 +05:30
|
|
|
do ce = 1, product(cells(1:2))*cells3
|
2021-04-09 03:10:20 +05:30
|
|
|
K_ref = K_ref + homogenization_K_T(ce)
|
|
|
|
mu_ref = mu_ref + homogenization_mu_T(ce)
|
2021-11-15 23:05:44 +05:30
|
|
|
end do
|
2021-04-11 13:16:11 +05:30
|
|
|
|
2020-01-31 03:37:45 +05:30
|
|
|
K_ref = K_ref*wgt
|
2022-01-13 18:20:30 +05:30
|
|
|
call MPI_Allreduce(MPI_IN_PLACE,K_ref,9_MPI_INTEGER_KIND,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD,err_MPI)
|
2022-01-13 17:11:11 +05:30
|
|
|
if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error'
|
2020-01-31 03:37:45 +05:30
|
|
|
mu_ref = mu_ref*wgt
|
2022-01-13 18:20:30 +05:30
|
|
|
call MPI_Allreduce(MPI_IN_PLACE,mu_ref,1_MPI_INTEGER_KIND,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD,err_MPI)
|
2022-01-13 17:11:11 +05:30
|
|
|
if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error'
|
2020-01-31 03:37:45 +05:30
|
|
|
|
|
|
|
end subroutine updateReference
|
|
|
|
|
|
|
|
|
2019-03-12 04:07:06 +05:30
|
|
|
end module grid_thermal_spectral
|