 Applies to: COMSOL Multiphysics®, Structural Mechanics Module Versions: All versions

## Problem Description

I have a implemented an external material for use with Structural Mechanics, but my model is not solving.

## Solution

External materials are coded in C, and then compiled into a shared library that COMSOL Multiphysics uses at runtime. If you are having problems compiling the external material code, please consult the section in the How to Compile and Link an External Material Model in the COMSOL Multiphysics Reference Manual.

The purpose of the external material is twofold:

• To compute mechanical stresses that will be used to determine if equilibrium has been reached between internal and external forces.
• To compute the derivative of stress with respect to strain (the Jacobian) so that the equation solver can iterate to establish force equilibrium.

When COMSOL Multiphysics uses an external material, parameters and states (internal variables) are passed between the program and the external material function, and this has to be done in a consistent manner. For example, the number of states defined in COMSOL Multiphysics has to match the number of states that you use inside the external material. See the section Working with External Materials in the COMSOL Multiphysics Reference Manual. Also, consult the examples provided in the links at the further down on this page. Try compiling one of the example external materials and use it in a simple case to make sure that your model definition is sound.

If the model does not solve or converge, try to understand if it is the stress computation or the Jacobian computation that is problematic. To make it easier to test your external material code do the following:

• Make a model that is as small as possible, preferably using a single mesh element.
• Subject the model to displacement-controlled loading. This way, you have exact control over the strains that enter into the external material code. Moreover, if the material model that you are implementing includes softening, a displacement-controlled model is necessary.
• Use simple cases of deformation, such as uniaxial tension and pure shear.

#### Stress Computation

There are a couple of things to check that have to do with the computation of stresses:

• If the external material works well under uniaxial loading, but either fails or produces incorrect results in other modes of deformation, make sure that you use the correct definitions and ordering of shear strain components in the external material code.
• Are there any risks of division by zero in your code? In the beginning of an analysis, the external material can be called for a zero displacement field (zero strains), and you need to safeguard your code to identify problems that may arise.
• Many inelastic material models require local iterations to compute stresses. This is often called the stress update algorithm. COMSOL Multiphysics has no control over these local iterations, so it is useful to pay close attention to the robustness of the iterative method that you have implemented. Are there any risks of numerical overflow? In creep models, the stress is typically raised to a power (greater than one). During the local iterations, the non-converged stresses can be high enough to cause an overflow when raised to a power. It is useful to place safeguards in your code to identify these types of problems.
• If you believe that the stress update algorithm is problematic, you can print information from the local iterations to a separate file using the `fprintf` statement in C. Be careful, however, as this can generate large volumes of output.

#### Jacobian Computation

A sign that the Jacobian is incorrect is that the model runs without problem for a portion of the analysis, and then experiences convergence problems. This behavior suggests that the inelastic portion of the Jacobian is incorrect. There are a few ways to identify and remedy problems that pertain to the Jacobian computation:

• First, it must be pointed out that in many situations, an approximate Jacobian, that deviates slightly from the correct Jacobian is often good enough to reach convergence. Only the rate of convergence is affected, and not the accuracy of the solution.
• The most common cause of convergence problems is that the Jacobian is not correctly defined. Formally, the Jacobian is the derivative of 2nd Piola-Kirchhoff stress with respect Green-Lagrange strain (or with respect to the deformation gradient). The derivative has to be computed so that it is consistent with the stress update algorithm used to compute stresses.
• Just like with the stress update algorithm, pay close attention to the definition and ordering of shear strains.
• A common pitfall when differentiating quantities such as the equivalent stress is to omit the symmetry of the stress tensor. Problems can arise when a compact vector format is used for stresses and strains.
• The differentiation of stress with respect to strain can be quite involved (and error prone). You can try making controlled simplifications to the Jacobian expression.
• If the expressions for the Jacobian terms are very involved, you can use the `fprintf` statement to print values to a separate file and then compare to manually computed values. However, be careful, as this can generate large volumes of output.