## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

# Material model interface

The material model interface is a set of C functions that are used to configure, initialize and run a material model. These functions are implemented in `interface.cpp`.

### Overview of interface functions

Each user material consists of five functions, which are all called by IMPETUS Solver:

1. `mat_user_X_config`: Get the configuration parameters required for the material model.
2. `init_mat_user_X`: Initializes the material state.
3. `mat_user_X`: Evaluates the material response.
4. `init_mat_user_X_gpu`: Currently not being used, but reserved for future GPU implementation.
5. `mat_user_X_gpu`: Evaluates the material behavior on a GPU device.

### Implementing Your Own User Material

1. Create an instance of your derived `MatUser` class.
2. Choose an available slot (e.g., `mat_user_1`).
3. Link the the following functions with your material model’s corresponding functions:
   - `mat_user_X_config`
   - `init_mat_user_X`
   - `mat_user_X`
   - `init_mat_user_X_gpu`
   - `mat_user_X_gpu`

### Example Use Case

Suppose you want to link your user material (e.g. `MatMetal`). You would:

1. Create an instance of `MatMetal` class (don’t forget the namespace).
2. Choose slot `mat_user_1`.
3. Link each of the functions for this material ID with its corresponding class functions:

    static user_metal::MatMetal metal;

    void mat_user_1_config(UserMatConfig* config, UserMatProp* properties)
    {
        metal.getConfig(config, properties);
    }

    void init_mat_user_1(UserMatInitCPU data)
    {
        metal.runInit(data);
    }

    void mat_user_1(UserMatCPU data)
    {
        metal.runMat(data);
    }

    void init_mat_user_1_gpu(UserMatHost host, UserMatDevice device, cudaStream_t stream)
    {
        metal.runInitGPU(host, device, stream);
    }

    void mat_user_1_gpu(UserMatHost host, UserMatDevice device, cudaStream_t stream)
    {
        metal.runMatGPU(host, device, stream);
    }