Hybrid constitutive equations conceptual implementation

For a project I want to have a single domain where I switch between which constitutive model is used. Conceptually this is something like:

if A:
   C = C_A
elif B:
   C = C_B
else:
   C = gamma*C_A + (1-gamma) * C_B

where C represents the constitutive model (e.g. C_A = hyperelasticity). condition and gamma are defined over the field and change each iteration. I am currently thinking that it might be best to represent this hybrid constitutive model as a single constitutive model, where I pass the conditions and gamma as additional parameters to each gauss point. Alternatively, I could perhaps create separate functions for each constitutive model, and then ‘post-process’ combine both.

What is a good way to implement this in dolfinx?

If A, B and else represent 3 conditions on the spatial coordinate, create 3 subdomains (say, subdomain 1, 2 and 3), and write the integrals in the residual separately on each one of them (say expression1 * dx(1) + expression2 * dx(2) + expression3 * dx(3)).

If you don’t know how to create subdomains, search in the forum with this keyword and you will find plenty of examples, including some links to demos or tutorials.

If instead A and B represent conditions on the solution itself (rather than a position on the domain), you may want to have a look at ufl.conditional