Code Generator#
- neuralmag.common.engine.dA(dim=3, normal=2, region='rhoxy', idx=':', **kwargs)#
Surface integral measure.
- Parameters:
dim (int, optional) – Dimension of the mesh to integrate over.
normal (int, optional) – Principal axis normal to the integration surface.
region (str, optional) – Name of the cell function that acts as a region indicator.
idx (str, optional) – Index selecting the surface layer along the normal axis.
**kwargs – Additional meta information.
- Returns:
The integration measure.
- Return type:
sympy.Expr
- neuralmag.common.engine.dV(dim=3, region='rho', **kwargs)#
Volume integral measure.
- Parameters:
dim (int, optional) – Dimension of the mesh to integrate over.
region (str, optional) – Name of the cell function that acts as a region indicator.
**kwargs – Additional meta information.
- Returns:
The integration measure.
- Return type:
sympy.Expr
- neuralmag.common.engine.dX(**kwargs)#
Generic integration measure.
- Parameters:
**kwargs – Arbitrary meta information.
- Returns:
The integration measure.
- Return type:
sympy.Expr
- neuralmag.common.engine.Variable(name, spaces, shape=())#
Symbolic representation of a field given as SymPy expression.
- Parameters:
name (str) – The name of the field.
spaces (str) – The function spaces of the field in the principal coordinate directions given as string with ‘c’ representing a cell-based discretization and ‘n’ representing a node-based discretization.
shape (tuple, optional) – The shape (dimension) of the field, e.g. () for a scalar field and (3,) for a vector field.
- Returns:
The variable.
- Return type:
sympy.Expr
- neuralmag.common.engine.extract_kernel(form_fn, dim, options)#
Extract the pointwise integrand (kernel) of a weak form.
The magnetization
mis built as a nodal quadrature field and passed toform_fn(m, dim, options); every other fully or partially node-discretized field built viaVariable()(a hand-written testv, a coupling field, a projection source) is also interpolated to the quadrature point. The measure is stripped and each field’s value and gradient are rewritten into the independentqv_sym()/qg_sym()symbols, leaving a small pointwise expression. No differentiation happens here –form_fnmay be an energy density or a hand-written linear form.- Returns:
(kernel, meta, args)wherekernelis the integrand without the measure,metamaps every interpolated field name to(spaces, shape), andargsis the measure metadata (dims).- Return type:
tuple
- neuralmag.common.engine.variation(kernel, by, meta, dim)#
Variation (Gâteaux derivative) of a
kernelwith respect to a field.The variation is taken with respect to the field named
by: the coefficients of the test value and test gradient in the resulting linear form. For an energy density this turns the energy into its effective-field weak form; for a form already linear inbyit simply extracts that form’s coefficients.The symbolic
sp.diffhere is the explicit place where “vary the energy” happens; a future backend could compute the sameKv/Kgby runtime autodiff of the kernel without changing callers.- Returns:
(Kv, Kg, test)whereKv[l] = d kernel / d value_l,Kg[l][d] = d kernel / d grad_{l,d}andtest = (spaces, shape)of thebyfield.- Return type:
tuple