Using External Materials in Physics Interfaces
In order for a physics interface to make use of external materials, it must contain one or more features that provide input quantity definitions and make use of returned output quantities in equations and results-processing expressions. Such features are currently available in the Solid Mechanics; Membrane; Magnetic Fields; and Magnetic Fields, No Currents interfaces.
External Material Interface Types
Given that a physics feature requires certain output quantities and defines certain input quantities, there are many possible ways to set up a call to an external function, including declarations of material properties and states. The required interface specification, or interface type, is contained in an external material socket, which does a number of different things:
The call syntax is in general not fixed for a given socket. Most sockets allow socket parameters to control certain aspects of the socket behavior, including:
It is not necessary for a socket to define all output quantities required by a physics feature. The socket and external library may compute only some quantities, while others are left to be specified by property groups under the External Material feature. For example, the built-in General stress-strain relation socket only returns second Piola–Kirchhoff stress as output, while the physics features using this interface type also may require the material density. The density may instead be specified as an expression in the Basic property group.
It is also possible to set the Interface type to None to select no socket and instead set up the relation between input and output quantities as expressions directly in an external material feature. This behavior is intended mostly for testing and debugging of multiphysics models. Note that no external material function will be called in this case.
Solver Iterations and State Updates
This section describes quantities as being evaluated either at the current step or at the previous converged step. This is related to the iteration pattern of the solvers. The external material functionality is primarily intended for modeling materials with some kind of memory or path dependence (for example, inelastic solid materials or materials exhibiting electromagnetic hysteresis). This means that simulations must be performed in steps over an interval of time or some parameter (which can often be interpreted as a pseudo-time).
Whether a time-dependent or parametric solver is used, taking a step forward requires solving a nonlinear problem, which is typically an iterative procedure. In order for the convergence to be efficient, the modified Newton solver used needs correct Jacobian information (the Jacobian is sometimes called the tangential stiffness matrix), which must be provided by the external material functions in the form of partial derivatives of output argument components with respect to input argument components. When the nonlinear iteration converges, the solution for that time step or parameter step is stored, and the solver moves on to the next step.
The external material functions are typically called in each iteration in the inner nonlinear loop. Arguments that are evaluated at the current step are reevaluated at each inner iteration, while arguments defined at the previous converged step retain the value they had when the previous nonlinear iteration converged; that is, the value that was last stored. State variable arguments are passed to the external material function with the same previous converged values in each inner nonlinear iteration. The external material function is expected to overwrite this previous value with a new value corresponding to the current iteration, but this value will only be stored and the states updated when the inner nonlinear iteration converges.
Result Presentation
The external material function may also be called during result presentation. In COMSOL Multiphysics, the stored solution consists of the degrees of freedom plus any possible state variables.
As an example, if you have coded your own elastoplastic material model for solid mechanics, you will typically store the plastic strains as states. If you then during result presentation make a plot of the stresses, the material function is called in order to compute the stresses from the displacements and plastic strains. This will happen at a large number of locations in the mesh.
The states are stored at the integration points, so if you request integration point results of the right order, there will be a call to the external material with a consistent already converged state. If the function is well coded, it will then return the stress state after a single iteration.
Often the material function is called from a location that is not an integration point (for example, a mesh node). In that case, the values of the state variables are taken from the closest integration point, while the total strains are computed from the displacement field gradients at the evaluation location. This combination does in general not provide a converged state, so iterations will be needed inside the material function in order to find the stress state. This can have several negative effects:
For these reasons it is advantageous, both from a performance and an accuracy point of view, to evaluate results only at the appropriate integration points. In order to ensure that, you can add the gpeval operator to your expressions. Instead of plotting for example solid.mises, use an expression like gpeval(4,solid.mises).