      ! ************************************************************************
      
      ! THIS MODULE IS A CONTAINER FOR THE INITIALISATION AND SOLUTION
      ! OF A MATERIAL MODELLING EQUATION/OPTION
      
      ! THE FOLLOWING ROUTINES ARE INCLUDED:

      ! MODULE ERO_USER_1
      !   DEFINE COMMON PARAMETERS TO BE ACCESSED IN ROUTINES BELOW

      ! SUBROUTINE INIT_ERO_USER_1
      !   ALLOCATE SPACE AND DEFINE THE PARAMETERS FOR A GIVEN FLAG

      ! SUBROUTINE CHECK_ERO_USER_1
      !   CHECK PARAMETERS ARE VALID FOR flagname

      ! SUBROUTINE SET_ERO_USER_1 (optional)
      !   SET PARAMETERS FOR SUBSEQUENT USE IN THE SOLVER

      ! SUBROUTINE SOLVE_ERO_USER_1_2D
      ! SUBROUTINE SOLVE_ERO_USER_1_3D
      !   SOLVE EQUATION (CALLED FROM SOLVER)

      ! BEFORE EACH ROUTINE IS CALLED, THE FOLLOWING POINTERS ARE SET-UP
      !   MTL - POINTER TO THE CURRENT MATERIAL
      !   EQ  - POINTER TO THE CURRENT FLAG/EQUATION/MATERIAL OPTION

      ! ************************************************************************

      MODULE ERO_USER_1
      USE kindef
      IMPLICIT NONE
      SAVE

      ! SPECIFY COMMON VARIABLES TO BE ACCESSED BY ROUITNES BELOW HERE
      !INTEGER(INT4) ::
      !REAL(REAL8) ::
      
      END MODULE ERO_USER_1

      SUBROUTINE INIT_ERO_USER_1(IFACT)

      USE material
      USE ero_user_1

      IMPLICIT NONE

      INTEGER (INT4) ::   IFACT

      ! ************************************************************************

      ! THIS SUBROUTINE INITIALISES (ALLOCATES) PARAMETERS AND DATA

      ! FLAG - IMF_ERO_USER_1

      ! INPUT - IFACT = 0 JUST GET NAME OF EQUATION AND DEPENDANT FLAGS
      !         IFACT = 1 EQUATION IS ACTIVE HENCE ALLOCATE

      ! ************************************************************************

      ! DEFINE PARAMETERS TO ALLOW ALLOCATION
      EQ%EQTYPE = IMF_ERO_USER_1
      EQ%NAME = 'User Erosion #1'
      EQ%NPAR = 0
      EQ%NUMOPT = 0
      EQ%NDEPFLG = 0
      EQ%NCHAR = 0
      EQ%NPAR_VEC = 0

      IF (IFACT==1) THEN
        ! ALLOCATE ARRAYS FOR EQUATION/FLAG
        CALL ALLOC_EQ

        ! SET PARAMETER NAMES
        !EQ%PAR(1)=PRMT(1,'Erosion Strain',0,0,0,0,BIG,SMALL,BIG,BIG,0,1)
      ENDIF

      ! SET IN ACTIVE SWITCH FOR APPROPRIATE PROCESSOR TYPE:: ALL ON BY DEFAULT
      EQ%IFSOLVER(ISLV_FCT) = 0
      EQ%IFSOLVER(ISLV_EULER) = 0
      EQ%IFSOLVER(ISLV_EULER_GOD) = 0

      RETURN
      END SUBROUTINE INIT_ERO_USER_1


      SUBROUTINE SET_ERO_USER_1

      USE material
      USE ero_user_1
      USE mdvar_all

      IMPLICIT NONE

      ! ************************************************************************

      ! THIS SUBROUTINE ASSIGNS EOS CONSTANTS FOR DIRECT USE IN THE SOLVER

      ! ************************************************************************

      EROMOD = 5 ! DO NOT MODIFY THIS LINE

      !EROSON = EQ%PAR(1)%VAL

      IF_IVAR_ALL(IVI_EROSION) = 2

      RETURN

      END SUBROUTINE SET_ERO_USER_1

      SUBROUTINE CHECK_ERO_USER_1

      USE material
      USE ero_user_1

      IMPLICIT NONE

      ! ************************************************************************

      ! THIS SUBROUTINE CHECKS EOS INPUT DATA

      ! ************************************************************************

      ! NO CHECKS REQUIRED

      RETURN

      END SUBROUTINE CHECK_ERO_USER_1

      SUBROUTINE SOLVE_ERO_USER_1_2D (ISTAT)

      USE material
      USE ero_user_1
      USE mdgrid
      USE wrapup
 
      IMPLICIT NONE

      INTEGER (INT4) ::  ISTAT

      ! ************************************************************************

      ! THIS IS A USER SUPPLIED SUBROUTINE WHICH CAN BE USED TO ERODE THE
      ! CURRENT CELL ACCORDING TO ANY CRITERIA THE USER DECIDES.

      ! OUTPUT PARAMETER

      !    ISTAT   EROSION SWITCH - ASSIGN TO NON-ZERO TO ERODE THE CURRENT CELL

      ! IN ADDITION TO THE FORMAL PARAMETERS, MODULE "MATDEF"
      ! CONTAINS THE FOLLOWING INFORMATION

      !    MATNO          THE MATERIAL NUMBER OF THE MATERIAL BEING PROCESSED
      !    MTL%NAME       THE MATERIAL NAME OF THE MATERIAL BEING PROCESSED

      ! ************************************************************************

      ! TEMPORARY ERROR MESSAGE - REPLACE NEXT TWO LINES WITH YOUR OWN CODE
      CALL USR_MESSAG ('User subroutine SOLVE_ERO_USER_1_2D missing')
      NSWRAP = 9

      ! UNCOMMENT THE NEXT LINE TO USE OLD V4.3 USER SUBROUITNE
      ! CALL EXEROD2 (ISTAT)

      RETURN

      END SUBROUTINE SOLVE_ERO_USER_1_2D

      SUBROUTINE SOLVE_ERO_USER_1_3D (ISTAT)

      USE material
      USE ero_user_1
      USE mdgrid3
      USE wrapup
 
      IMPLICIT NONE

      INTEGER (INT4) ::  ISTAT

      ! ************************************************************************

      ! THIS IS A USER SUPPLIED SUBROUTINE WHICH CAN BE USED TO ERODE THE
      ! CURRENT CELL ACCORDING TO ANY CRITERIA THE USER DECIDES.

      ! OUTPUT PARAMETER

      !    ISTAT   EROSION SWITCH - ASSIGN TO NON-ZERO TO ERODE THE CURRENT CELL

      ! IN ADDITION TO THE FORMAL PARAMETERS, MODULE "MATDEF"
      ! CONTAINS THE FOLLOWING INFORMATION

      !    MATNO          THE MATERIAL NUMBER OF THE MATERIAL BEING PROCESSED
      !    MTL%NAME       THE MATERIAL NAME OF THE MATERIAL BEING PROCESSED

      ! AN EXAMPLE OF USING USER EROSION WITH NBS TETRAHEDRA CAN BE FOUND IN
      ! THE APPENDIX OF THE USER SUBROUTINE MANUAL

      ! ************************************************************************

      ! TEMPORARY ERROR MESSAGE - REPLACE WITH YOUR OWN CODE
      CALL USR_MESSAG ('User subroutine SOLVE_ERO_USER_1_3D missing')
      NSWRAP = 9

      ! UNCOMMENT THE NEXT LINE TO USE OLD V4.3 USER SUBROUITNE
      ! CALL EXEROD (ISTAT)

      RETURN

      END SUBROUTINE SOLVE_ERO_USER_1_3D



