SERiF 0.0.1a
3+1D Stellar Structure and Evolution
Loading...
Searching...
No Matches
serif::pybind::PyCoefficient Class Referencefinal

Trampoline class for mfem::Coefficient. More...

#include <PyCoefficient.h>

Inheritance diagram for serif::pybind::PyCoefficient:

Public Member Functions

mfem::real_t Eval (mfem::ElementTransformation &T, const mfem::IntegrationPoint &ip) override
 Evaluate the coefficient at a given IntegrationPoint in an ElementTransformation.
 
void SetTime (mfem::real_t t) override
 Set the current time for time-dependent coefficients.
 

Detailed Description

Trampoline class for mfem::Coefficient.

This class allows Python classes to inherit from mfem::Coefficient and override its virtual methods. This is essential for creating custom coefficients in Python that can be used by MFEM's C++ backend.

See also
mfem::Coefficient
Python Usage Example:
import mfem.ser_ext as mfem
class MyPythonCoefficient(mfem.Coefficient):
def __init__(self):
super().__init__() # Call the base C++ constructor
def Eval(self, T, ip):
# T is a mfem.ElementTransformation
# ip is a mfem.IntegrationPoint
# Example: return a constant value
return 1.0
def SetTime(self, t):
# Optionally handle time-dependent coefficients
super().SetTime(t) # Call base class method
print(f"Time set to: {t}")
# Using the Python coefficient
py_coeff = MyPythonCoefficient()
# py_coeff can now be passed to MFEM functions expecting an mfem::Coefficient

Definition at line 50 of file PyCoefficient.h.

Member Function Documentation

◆ Eval()

real_t serif::pybind::PyCoefficient::Eval ( mfem::ElementTransformation & T,
const mfem::IntegrationPoint & ip )
override

Evaluate the coefficient at a given IntegrationPoint in an ElementTransformation.

< Inherit constructors from mfem::Coefficient.

This method is called by MFEM when the value of the coefficient is needed. If a Python class inherits from PyCoefficient, it must override this method.

Parameters
TThe element transformation.
ipThe integration point.
Returns
The value of the coefficient at the given point.
Note
This method forwards the call to the Python override. PYBIND11_OVERRIDE_PURE is used in the .cpp file to handle this.

Definition at line 14 of file PyCoefficient.cpp.

◆ SetTime()

void serif::pybind::PyCoefficient::SetTime ( mfem::real_t t)
override

Set the current time for time-dependent coefficients.

This method is called by MFEM to update the time for time-dependent coefficients. Python classes inheriting from PyCoefficient can override this method to implement time-dependent behavior.

Parameters
tThe current time.
Note
This method forwards the call to the Python override if one exists. PYBIND11_OVERRIDE is used in the .cpp file to handle this.

Definition at line 24 of file PyCoefficient.cpp.


The documentation for this class was generated from the following files: