> 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/b-capillary-pressure-functions/icp-41-user-defined-capillary-pressure-function.md).

# ICP=41 User-Defined capillary pressure function

Users may use a capillary pressure function defined by themselves without touching the TOUGH4 source codes. The input parameters are the same as other functions through variables C*P(1)-CP(13)* of data record [**ROCKS.1.3** and **ROCKS.1.3.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 CapiFunction() 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 CapiFunction(double\_array, int\_array):***

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

&#x20;     ***CapiParam=np.zeros(13, 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,13):***&#x20;

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

***#capillary pressure calculation parameters: CapiParam\[0-12], input through record ROCKS.1.3***

***#performcapillary pressure calculations at following lines:***

***#results of capillary pressures stored in capiP\[0]:*****&#x20;:gas/aqu; capiP\[2]:gas/oil**

&#x20;     ***return capiP***

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