# How to use the Constitutive Law class

The constitutive law behaviour is dealt with in kratos by the use of the class "ConstitutiveLaw", with a public interface defined in the file

kratos/kratos/includes/constitutive_law.h

which also provides some rather extensive inline documentation (in the form of comments in the code).

By design such file aims to provide a very flexible interface to constitutive law modelling, with the specific goal of
**maximizing the flexibility in the implementation of complex constitutive behaviours**. While such approach provide obvious advantages, it
also implies that the API is more complex than what would be strictly needed for very simple constitutive laws.

The objective of current HowTo is to provide a brief introduction to the interface

### Conventions

Through the whole section, the following convenctions will be employed:

*voigt notation:*
- 3D case:

STRAINVoigt Notation: e00 e11 e22 2*e01 2*e12 2*e02STRESSVoigt Notation: s00 s11 s22 s01 s12 s02

- 2D plane strain/axisymmetric case (4 stress components)

STRAINVoigt Notation: e00 e11 e22 2*e01STRESSVoigt Notation: s00 s11 s22 s01

- 2D plane stress

STRAINVoigt Notation: e00 e11 2*e01STRESSVoigt Notation: s00 s11 s01

The constitutive law works on the basis of the **total deformation gradient F**, defined as

F := D(X) / D(X0)

that is, as the deformation gradient connecting the original and deformed configuration

where the initial position X0 is the one obtained by

const array_1d<double,3>& X0 = node->GetInitialPosition()

and the deformed one by

const array_1d<double,3>& X = node->Coordinates() //must coincide with X = node->GetInitialPosition() + node.FastGetSolutionStepValue(DISPLACEMENT);

The ConstitutiveLaw **always returns the total stress**. Formulations expressed in terms of strain increments shall store internally the strain stresses from which the increment
shall be computed

## Usage API

The constitutive law API is based on the use of an auxiliary "Parameters" data structure, designed to encapsulate the data to be passed to the CL and received from it. The parameters data structure should be initialized using the following constructor:

Parameters (const GeometryType& rElementGeometry

,const Properties& rMaterialProperties ,const ProcessInfo& rCurrentProcessInfo) Thus allowing to encapsulate the pointer to the elemental properties, to the element geometry and to the process info.

The data structure **does not contain any internal storage** and should be initialized with pointers to memory *owned by the caller element*.
Full documentation of the code can be found in the file constitutive_law.h constitutive_law.h https://kratos.cimne.upc.es/projects/kratos/repository/entry/kratos/kratos/includes/constitutive_law.h.
For ease, the getter interface, *returning a reference to the encapsulated data*, is reported here

GetOptions() //returns a reference to a flag container, to be employed in passing options to the CL GetDeterminantF() GetDeformationGradientF() GetShapeFunctionsValues() GetShapeFunctionsDerivatives() GetStrainVector() //INPUT/OUTPUT -- note that F will be used preferentially instead of the input strain GetStressVector() GetConstitutiveMatrix() GetProcessInfo() GetMaterialProperties() GetElementGeometry()

there are additionally the two functions

GetDeterminantF0() //DEPRECATED: please set to 1.0 GetDeformationGradientF0() //DEPRECATED: please set to the IdentityMatrix

that are currently **deprecated** to simplify the constitutive law usage. Until their complete removal please set them respectively to 1.0 and to the IdentityMatrix of correct size. They will be removed asap.

The "Options" flag represents the fundamental tool in steering the control of the constitutive law behaviour. The interface provides a number of boolean flags that can be passed to the constitutive law:

COMPUTE_STRAIN COMPUTE_STRESS COMPUTE_CONSTITUTIVE_TENSOR ISOCHORIC_TENSOR_ONLY VOLUMETRIC_TENSOR_ONLY TOTAL_TENSOR FINALIZE_MATERIAL_RESPONSE

there are 3 additional ones but are currently deprecated and not reported here.

A fundamental feature of the constitutive law is to implement internally the transformations between different stress measures. When a user writes an element he should decide what stress measure is desired. The list of available options is provided in the enum:

enum StressMeasure { StressMeasure_PK1, //stress related to reference configuration non-symmetric

StressMeasure_PK2, //stress related to reference configuration StressMeasure_Kirchhoff, //stress related to current configuration

StressMeasure_Cauchy //stress related to current configuration }

at the moment of writing the element the developer should hence query to the constitutive law for the desired stress measure. This is achieved by picking one of the functions:

CalculateMaterialResponsePK1( parameters ) CalculateMaterialResponsePK2( parameters ) CalculateMaterialResponseKirchhoff( parameters ) CalculateMaterialResponseCauchy( parameters )

the elasticity tensor and the corresponding stresses will be stored in the "parameters" and shall be accessed by the Getter funtions described above.

At the end of a given solution step (typically in the FinalizeSolutionStep function of the element), internal variables should be updated by calling the function

FinalizeMaterialResponsePK1( parameters ) FinalizeMaterialResponsePK2( parameters ) FinalizeMaterialResponseKirchhoff( parameters ) FinalizeMaterialResponseCauchy( parameters )

An example of usage of the ConstitutiveLaw from within a total lagrangian element could be as follows:

Parameters parameters(GetGeometry(), GetProperties(), rCurrentProcessInfo); //here we essentially set the input parameters parameters.SetDeterminantF(detF) //assuming the determinant is computed somewhere else parameters.SetDeformationGradientF(F) //F computed somewhere else //here we set the space on which the results shall be written Matrix ConstitutiveTensor(strain_size,strain_size); //note that C is allocated in the element Vector stress(strain_size); parameters.SetConstitutiveMatrix(ConstitutiveTensor) //assuming the determinant is computed somewhere else parameters.SetStressVector(stress) //F computed somewhere else //instruct the constitutive law that both stress and the constitutivetensor are needed parameters.GetOptions().Set(COMPUTE_STRESS, True) parameters.GetOptions().Set(COMPUTE_CONSTITUTIVE_TENSOR, True) //actually do the computations in the ConstitutiveLaw constitutivelaw->CalculateMaterialResponsePK2(parameters); //here the calculations are actually done //here stress and C are already updated since we passed them to the CL