Adding a homogenization scheme
Which cell does your scheme serve?
homogenize accepts any AbstractHomogenizationCell — an RVE or a Laminate. Schemes stay typed on the concrete cell they serve (_evaluate(rve::RVE, ::MyScheme, …)), so a scheme applied to a cell it does not serve falls through to the error-raising fallback instead of dispatching somewhere wrong. Type the scheme argument too: leaving it untyped is ambiguous with that fallback.
MeanFieldHomogenization.Schemes ships Voigt/Reuss, dilute (direct and dual), Mori-Tanaka, Maxwell, Ponte-Castañeda–Willis, self-consistent (symmetric and asymmetric) and differential, each in an elastic and an ageing-viscoelastic flavor. A new scheme slots in beside them:
Create
src/Schemes/<scheme_name>.jlandincludeit fromsrc/Schemes/Schemes.jl.Declare the scheme type (
struct MyScheme <: HomogenizationScheme) insrc/Schemes/scheme_types.jl, and register its symbol alias inSCHEME_ALIAS(src/Schemes/homogenize.jl) if you wanthomogenize(rve, :myscheme, :C)to work.Implement
_evaluate(rve, ::MyScheme, ::Val{p}; kw...). Provide one method per tensor order — dispatch on the order ofreference_property(rve, scheme, p)— so the scheme serves elasticity and transport from one implementation, as_mt_dispatchdoes inmori_tanaka.jl.Go through
contribution_helpers.jl. Never callstiffness_contributionand friends directly on a phase geometry: the_phase_*helpers apply the amount, honor thesymmetrizesetting, hand the kernel the correctly pre-projected reference medium, and branch onis_homogeneous_inclusion. Two invariants stated in that file's header must hold in your kernel too — all helpers of a given evaluation must share the same projectedP₀, and orientation averaging must never be folded into a tensor product.Prefer the bundled seams (
_phase_dilute_and_contribution,_phase_dilute_and_stress_average,_phase_compliance_and_contribution) when you need two objects per phase: they share the single expensive solve.Consider what your kernel requires of an inclusion. Needing only the contribution tensors keeps the scheme usable with inclusions entered through gate C of the inclusion contract; needing the concentration tensor restricts it.
Export through
src/Schemes/Schemes.jland re-export fromsrc/MeanFieldHomogenization.jl.Add a unit test under
test/Schemes/and a section indocs/src/manual/schemes.md.
A scheme need not act on an RVE
Two cells other than RVE carry scheme kernels, and both follow the same split: the scheme type is declared in src/Schemes/scheme_types.jl (so the hierarchy and SCHEME_ALIAS stay in one place) while its _evaluate method lives with the cell it acts on — Laminated in src/Laminates/, and the two N-body schemes ClusterModel / EquivalentInclusion in src/Assemblies/. If your scheme needs microstructural information an RVE does not carry — positions, in the N-body case — add a cell rather than widening RVE, and remember that MFH Studio discovers every concrete HomogenizationScheme automatically: a scheme the interface cannot drive must be listed in ASSEMBLY_SCHEMES (tools/mfhstudio/mfhstudio/model.py) so it is filtered out of its catalog.