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

Trampoline class for mfem::VectorCoefficient. More...

#include <PyCoefficient.h>

Inheritance diagram for serif::pybind::PyVectorCoefficient:

Public Member Functions

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

Detailed Description

Trampoline class for mfem::VectorCoefficient.

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

See also
mfem::VectorCoefficient
Python Usage Example:
import mfem.ser_ext as mfem
import numpy as np
class MyPythonVectorCoefficient(mfem.VectorCoefficient):
def __init__(self, dim):
super().__init__(dim) # Call the base C++ constructor, pass vector dimension
self.dim = dim
def Eval(self, V, T, ip):
# V is a mfem.Vector (output parameter, must be filled)
# T is a mfem.ElementTransformation
# ip is a mfem.IntegrationPoint
# Example: return a constant vector [1.0, 2.0, ...]
for i in range(self.dim):
V[i] = float(i + 1)
def SetTime(self, t):
super().SetTime(t)
print(f"VectorCoefficient time set to: {t}")
# Using the Python vector coefficient
vec_dim = 2
py_vec_coeff = MyPythonVectorCoefficient(vec_dim)
# py_vec_coeff can now be passed to MFEM functions expecting a mfem::VectorCoefficient

Definition at line 121 of file PyCoefficient.h.

Member Function Documentation

◆ Eval()

void serif::pybind::PyVectorCoefficient::Eval ( mfem::Vector & V,
mfem::ElementTransformation & T,
const mfem::IntegrationPoint & ip )
override

Evaluate the vector coefficient at a given IntegrationPoint in an ElementTransformation.

< Inherit constructors from mfem::VectorCoefficient.

This method is called by MFEM when the value of the vector coefficient is needed. If a Python class inherits from PyVectorCoefficient, it must override this method. The result should be stored in the output Vector V.

Parameters
VOutput vector to store the result. Its size should match the coefficient's dimension.
TThe element transformation.
ipThe integration 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 33 of file PyCoefficient.cpp.

◆ SetTime()

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

Set the current time for time-dependent vector coefficients.

This method is called by MFEM to update the time for time-dependent vector coefficients. Python classes inheriting from PyVectorCoefficient 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 43 of file PyCoefficient.cpp.


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