> For the complete documentation index, see [llms.txt](https://lbl-2.gitbook.io/tough4-user-manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lbl-2.gitbook.io/tough4-user-manual/appendix/a-relative-permeability-functions/irp-41-user-defined-relative-permeability-function.md).

# IRP=41 User-Defined relative permeability function

Users may use a relative permeability function defined by themselves without touching the TOUGH4 source codes. The input parameters are the same as other functions through variables *RP(1)-RP(10)* of data record [**ROCKS.1.2** and **ROCKS.1.2.1**](/tough4-user-manual/preparation-of-model-input/keywords-and-input-data/rocks.md)**.** The function must be defined in the PYTHON file: TOUGH\_python\_module.py.  A function named RelpFunction() is already included in the the PYTHON file. Users need to modify this function to their own function.   Following is the template of the function:

***def RelpFunction(double\_array, int\_array):***&#x20;

&#x20;      ***relpm = np.zeros(3, dtype='float64')***&#x20;

&#x20;      ***RelpParam=np.zeros(10, dtype='float64')***&#x20;

&#x20;      ***sg=double\_array\[13]                   # gas saturation***&#x20;

&#x20;      ***sl=double\_array\[14]                    # liquid saturation***&#x20;

&#x20;      ***nph=int\_array\[6]                         # phase number, 2 phase or 3 phase***&#x20;

&#x20;      ***nmat=int\_array\[7]                      # rock index defined in tough4 input***\
&#x20;      ***for i in range(0,10):***&#x20;

&#x20;            ***RelpParam\[i]=double\_array\[i]***    &#x20;

***#perform relative permeability calculations at following lines:***

***#results of relative permeabilities stored in***&#x20;

***#relpm\[0]: gas phase; relpm\[1]:aqueous phase; relpm(2): oil phase***

&#x20;     ***return relpm***

During runtime, the  PYTHON file must be stored at the same location where TOUGH4 executable is located.
