Skip to content

Commit

Permalink
Merge pull request firemodels#12252 from mcgratta/master
Browse files Browse the repository at this point in the history
FDS Source: Write atom imbalance info using MPI process 0 only
  • Loading branch information
mcgratta authored Nov 29, 2023
2 parents da0150c + 3c7387f commit b2f9f39
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 71 deletions.
104 changes: 34 additions & 70 deletions Source/data.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2987,11 +2987,14 @@ SUBROUTINE CHECK_REACTION_CHARACTERS(EXPRESSION)
END SUBROUTINE CHECK_REACTION_CHARACTERS


SUBROUTINE SHUTDOWN_ATOM(ATOM_COUNT,NR,ERR)
!> \brief Write out to both the .err and .out files information on stoichiometry imbalance
!> \param ATOM_COUNT Number of atoms
!> \param NR Reaction number with the problem
!> \param ERR Error tolerance

! Stops the code gracefully after writing a message
SUBROUTINE SHUTDOWN_ATOM(ATOM_COUNT,NR,ERR)

USE GLOBAL_CONSTANTS, ONLY: LU_ERR,FN_OUTPUT,LU_OUTPUT,CHID,N_SPECIES,N_TRACKED_SPECIES
USE GLOBAL_CONSTANTS, ONLY: LU_ERR,FN_OUTPUT,LU_OUTPUT,CHID,N_SPECIES,N_TRACKED_SPECIES,MY_RANK
USE TYPES, ONLY:SPECIES,SPECIES_TYPE,SPECIES_MIXTURE_TYPE,SPECIES_MIXTURE,REACTION_TYPE,REACTION
USE COMP_FUNCTIONS, ONLY:SHUTDOWN
INTEGER, INTENT(IN) :: NR
Expand All @@ -3001,106 +3004,67 @@ SUBROUTINE SHUTDOWN_ATOM(ATOM_COUNT,NR,ERR)
LOGICAL :: EX
TYPE (REACTION_TYPE), POINTER :: RN=>NULL()

WRITE(LU_ERR,'(/A,I3,A)') 'ERROR: Problem with REAC ',NR,'. Unbalanced stoichiometry.'

! Write out the transformation matrix that converts species mixtures to primitive species

WRITE(LU_ERR,'(//A)') ' Gas Phase Reaction Information'

RN=>REACTION(NR)

IF (RN%ID/='null') WRITE(LU_ERR,'(/3X,A,A)') 'Reaction ID: ', TRIM(RN%ID)

WRITE(LU_ERR,'(/3X,A)') 'Stoichiometry'

WRITE(LU_ERR,'(/3X,A)') 'Primitive Species'
WRITE(LU_ERR,'(3X,A)') 'Species ID Stoich. Coeff.'
DO NN=1,N_SPECIES
IF (ABS(RN%NU_SPECIES(NN))>=TWO_EPSILON_EB) WRITE(LU_ERR,'(3X,A,1X,F12.6)') SPECIES(NN)%ID,RN%NU_SPECIES(NN)
ENDDO

WRITE(LU_ERR,'(/3X,A)') 'Tracked (Lumped) Species'
WRITE(LU_ERR,'(3X,A)') 'Species ID Stoich. Coeff.'
DO NN=1,N_TRACKED_SPECIES
IF (ABS(RN%NU(NN)) < TWO_EPSILON_EB) CYCLE
IF (ABS(RN%NU(NN)) < 10000._EB) WRITE(LU_ERR,'(3X,A,1X,F12.6)') SPECIES_MIXTURE(NN)%ID,RN%NU(NN)
IF (ABS(RN%NU(NN)) > 10000._EB) WRITE(LU_ERR,'(3X,A,1X,E12.5)') SPECIES_MIXTURE(NN)%ID,RN%NU(NN)
ENDDO

WRITE(LU_ERR,'(//A)') 'Atom Balance Details'

DO NS=1,N_TRACKED_SPECIES
WRITE(LU_ERR,'(/3X,A,A)') 'Tracked (Lumped) Species:',SPECIES_MIXTURE(NS)%ID
WRITE(LU_ERR,'(3X,A)') 'Element nu*Atom Count'
REACTION_BALANCE = RN%NU(NS)*SPECIES_MIXTURE(NS)%ATOMS
DO I=1,118
IF (ABS(REACTION_BALANCE(I))>TWO_EPSILON_EB) THEN
WRITE(LU_ERR,'(3X,A,3X,F12.6)') ELEMENT(I)%ABBREVIATION,REACTION_BALANCE(I)
ENDIF
ENDDO
ENDDO


WRITE(LU_ERR,'(//A)') 'The following elements are unbalanced:'
WRITE(LU_ERR,'(/A)') 'Element Atom Error'
IF (MY_RANK==0) THEN
CALL WRITE_ATOM_BALANCE_DIAGNOSTICS(LU_ERR)
INQUIRE(FILE=FN_OUTPUT,EXIST=EX)
IF (.NOT.EX) OPEN(LU_OUTPUT,FILE=TRIM(CHID)//'.out',STATUS='REPLACE',FORM='FORMATTED')
CALL WRITE_ATOM_BALANCE_DIAGNOSTICS(LU_OUTPUT)
ENDIF

DO I=1,118
IF (ABS(ATOM_COUNT(I)) > ERR) WRITE(LU_ERR,'(2X,A,4X,E10.3)') ELEMENT(I)%ABBREVIATION,ATOM_COUNT(I)
ENDDO
CONTAINS

! For those running FDS on a PC, ensure that error message gets written to the .out file, too.
SUBROUTINE WRITE_ATOM_BALANCE_DIAGNOSTICS(LU_OUT)

INQUIRE(FILE=FN_OUTPUT,EXIST=EX)
IF (.NOT.EX) OPEN(LU_OUTPUT,FILE=TRIM(CHID)//'.out',STATUS='REPLACE',FORM='FORMATTED')
INTEGER, INTENT(IN) :: LU_OUT

WRITE(LU_OUTPUT,'(/A,I3,A)') 'ERROR: Problem with REAC ',NR,'. Unbalanced stoichiometry.'
WRITE(LU_OUT,'(/A,I3,A)') 'ERROR: Problem with REAC ',NR,'. Unbalanced stoichiometry.'

! Write out the transformation matrix that converts species mixtures to primitive species

WRITE(LU_OUTPUT,'(//A)') ' Gas Phase Reaction Information'
WRITE(LU_OUT,'(//A)') ' Gas Phase Reaction Information'

RN=>REACTION(NR)

IF (RN%ID/='null') WRITE(LU_OUTPUT,'(/3X,A,A)') 'Reaction ID: ', TRIM(RN%ID)
IF (RN%ID/='null') WRITE(LU_OUT,'(/3X,A,A)') 'Reaction ID: ', TRIM(RN%ID)

WRITE(LU_OUTPUT,'(/3X,A)') 'Stoichiometry'
WRITE(LU_OUT,'(/3X,A)') 'Stoichiometry'

WRITE(LU_OUTPUT,'(/3X,A)') 'Primitive Species'
WRITE(LU_OUTPUT,'(3X,A)') 'Species ID Stoich. Coeff.'
WRITE(LU_OUT,'(/3X,A)') 'Primitive Species'
WRITE(LU_OUT,'(3X,A)') 'Species ID Stoich. Coeff.'
DO NN=1,N_SPECIES
IF (ABS(RN%NU_SPECIES(NN))>=TWO_EPSILON_EB) WRITE(LU_OUTPUT,'(3X,A,1X,F12.6)') SPECIES(NN)%ID,RN%NU_SPECIES(NN)
IF (ABS(RN%NU_SPECIES(NN))>=TWO_EPSILON_EB) WRITE(LU_OUT,'(3X,A,1X,F12.6)') SPECIES(NN)%ID,RN%NU_SPECIES(NN)
ENDDO

WRITE(LU_OUTPUT,'(/3X,A)') 'Tracked (Lumped) Species'
WRITE(LU_OUTPUT,'(3X,A)') 'Species ID Stoich. Coeff.'
WRITE(LU_OUT,'(/3X,A)') 'Tracked (Lumped) Species'
WRITE(LU_OUT,'(3X,A)') 'Species ID Stoich. Coeff.'
DO NN=1,N_TRACKED_SPECIES
IF (ABS(RN%NU(NN)) < TWO_EPSILON_EB) CYCLE
IF (ABS(RN%NU(NN)) < 10000._EB) WRITE(LU_OUTPUT,'(3X,A,1X,F12.6)') SPECIES_MIXTURE(NN)%ID,RN%NU(NN)
IF (ABS(RN%NU(NN)) > 10000._EB) WRITE(LU_OUTPUT,'(3X,A,1X,E12.5)') SPECIES_MIXTURE(NN)%ID,RN%NU(NN)
IF (ABS(RN%NU(NN)) < 10000._EB) WRITE(LU_OUT,'(3X,A,1X,F12.6)') SPECIES_MIXTURE(NN)%ID,RN%NU(NN)
IF (ABS(RN%NU(NN)) > 10000._EB) WRITE(LU_OUT,'(3X,A,1X,E12.5)') SPECIES_MIXTURE(NN)%ID,RN%NU(NN)
ENDDO

WRITE(LU_OUTPUT,'(//A)') 'Atom Balance Details'
WRITE(LU_OUT,'(//A)') 'Atom Balance Details'

DO NS=1,N_TRACKED_SPECIES
WRITE(LU_OUTPUT,'(/3X,A,A)') 'Tracked (Lumped) Species:',SPECIES_MIXTURE(NS)%ID
WRITE(LU_OUTPUT,'(3X,A)') 'Element nu*Atom Count'
WRITE(LU_OUT,'(/3X,A,A)') 'Tracked (Lumped) Species:',SPECIES_MIXTURE(NS)%ID
WRITE(LU_OUT,'(3X,A)') 'Element nu*Atom Count'
REACTION_BALANCE = RN%NU(NS)*SPECIES_MIXTURE(NS)%ATOMS
DO I=1,118
IF (ABS(REACTION_BALANCE(I))>TWO_EPSILON_EB) THEN
WRITE(LU_OUTPUT,'(3X,A,3X,F12.6)') ELEMENT(I)%ABBREVIATION,REACTION_BALANCE(I)
WRITE(LU_OUT,'(3X,A,3X,F12.6)') ELEMENT(I)%ABBREVIATION,REACTION_BALANCE(I)
ENDIF
ENDDO
ENDDO


WRITE(LU_OUTPUT,'(//A)') 'The following elements are unbalanced:'
WRITE(LU_OUTPUT,'(/A)') 'Element Atom Error'
WRITE(LU_OUT,'(//A)') 'The following elements are unbalanced:'
WRITE(LU_OUT,'(/A)') 'Element Atom Error'

DO I=1,118
IF (ABS(ATOM_COUNT(I)) > ERR) WRITE(LU_OUTPUT,'(2X,A,4X,E10.3)') ELEMENT(I)%ABBREVIATION,ATOM_COUNT(I)
IF (ABS(ATOM_COUNT(I)) > ERR) WRITE(LU_OUT,'(2X,A,4X,E10.3)') ELEMENT(I)%ABBREVIATION,ATOM_COUNT(I)
ENDDO

CALL SHUTDOWN('')
END SUBROUTINE WRITE_ATOM_BALANCE_DIAGNOSTICS

END SUBROUTINE SHUTDOWN_ATOM

Expand Down
3 changes: 2 additions & 1 deletion Source/read.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4830,7 +4830,8 @@ SUBROUTINE PROC_REAC_1
REACTION_BALANCE = REACTION_BALANCE + RN%NU(NS)*SPECIES_MIXTURE(NS)%ATOMS
ENDDO
IF (ANY(ABS(REACTION_BALANCE)>REAC_ATOM_ERROR) .AND. .NOT. SKIP_ATOM_BALANCE) THEN
CALL SHUTDOWN_ATOM(REACTION_BALANCE,NR,REAC_ATOM_ERROR) ; RETURN
CALL SHUTDOWN_ATOM(REACTION_BALANCE,NR,REAC_ATOM_ERROR)
CALL SHUTDOWN(' ') ; RETURN
ENDIF
ENDIF

Expand Down

0 comments on commit b2f9f39

Please sign in to comment.