Coefficients¶
Introduction¶
Coefficients represent fields defined on the mesh. These can be either scalar or vector-valued. They are used in various components of μfem, including reports, boundary conditions, and models.
Coefficients are registered to the Coefficient Manager either automatically by
models or manually by users.
Coefficient Manager¶
The mufem.CoefficientFunctionManager manages all scalar and vector coefficient
functions used in the simulation.
Once registered, coefficients can be used in reports or exported using the
Field Exporter
Coefficients are registered in two main ways:
-
Via a model:
Models automatically register coefficients when added to the simulation. As an example, the Refinement Model registers several coefficients
-
Manually by user:
Users can define and register their own coefficients (see User Coefficients):
User Coefficients¶
Several types of coefficients are available in μfem.
Constant Scalar Coefficient¶
mufem.CffConstantScalar defines a scalar field with a constant value:
Sinusoidal Coefficient¶
mufem.CffSinusoidal defines a time-varying sinusoidal scalar field:
Time Table Coefficient¶
mufem.CffTimeTable defines a piecewise scalar function over time:
Expression-Based Coefficient¶
mufem.CffExpressionScalar defines a scalar field via a mathematical
expression:
Expressions support standard functions and mesh coordinates.
Constant Vector Coefficient¶
mufem.CffConstantVector defines a constant 3D vector field:
Composite Vector Coefficient¶
mufem.CffVectorComponent builds a vector field from three scalar coefficients:
x = mufem.CffConstantScalar(1.0)
y = mufem.CffConstantScalar(2.0)
z = mufem.CffConstantScalar(3.0)
cff_composite = mufem.CffVectorComponent(cff_x=x, cff_y=y, cff_z=z)
Example¶
import mufem
sim = mufem.Simulation.New("My Case", f"data/geometry.mesh", print_only_warnings=True)
cff_manager = sim.get_coefficient_manager()
# Scalar coefficients
cff_manager.register_user("MyCffConstantScalar", mufem.CffConstantScalar(1.23))
cff_manager.register_user("MyCffSinusoidal", mufem.CffSinusoidal(amplitude=2., frequency=50., phase=30.))
cff_manager.register_user("MyCffTimeTable", mufem.CffTimeTable(time=[0.1, 0.2, 0.3], value=[1.0, 2.0, 3.0]))
cff_manager.register_user("MyCffExpression", mufem.CffExpressionScalar("sqrt(x()^2 + y()^2)"))
# Vector coefficients
cff_vector = mufem.CffConstantVector(x=1.0, y=2.0, z=3.0)
cff_manager.register_user("MyCffConstantVector", cff_vector)
x = mufem.CffConstantScalar(1.0)
y = mufem.CffConstantScalar(2.0)
z = mufem.CffConstantScalar(3.0)
composite = mufem.CffVectorComponent(cff_x=x, cff_y=y, cff_z=z)
cff_manager.register_user("MyCffCompositeVector", composite)
# List all available coefficient names
print(cff_manager.list_functions())