Skip to content

Conversation

@sshiraiwa
Copy link
Member

This PR includes

  • particleset.hpp, particlevector.hpp wrapper
  • fixed GetDataArray of Vector/DenseMatrix/DenseTensor/SparseMatrix so that
    destructore is not pre-maturely called when return value is not stored to
    a variable.
  • miniapp/dpg/utils/*.hpp is wrapped.
  • Python version of pmaxwell.py in miniapp/dpg directory

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Python wrappers for MFEM's Discontinuous Petrov-Galerkin (DPG) miniapp utilities and includes a complete Python implementation of the parallel Maxwell DPG example. The key changes include:

  • New Python DPG Maxwell example (pmaxwell.py) with support for various problem types (plane wave, Fichera oven, PML)
  • Python wrappers for DPG utility classes (weakform, complexweakform, blockstaticcond, etc.)
  • Wrappers for particleset and particlevector modules
  • Fixes to GetDataArray methods to prevent premature object destruction
  • Build system updates to enable miniapp compilation
  • Support for non-square matrix coefficients

Reviewed changes

Copilot reviewed 51 out of 51 changed files in this pull request and generated 23 comments.

Show a summary per file
File Description
miniapps/dpg/pmaxwell.py Complete Python implementation of parallel Maxwell DPG example with multiple problem types
miniapps/dpg/meshes/*.mesh Mesh files for DPG examples (scatter.mesh, fichera-waveguide.mesh)
mfem/ser.py, mfem/par.py Added imports for new dpg, particleset, particlevector modules
mfem/_ser/dpg.i, mfem/_par/dpg.i SWIG interface files for DPG utilities wrapping
mfem/_ser/vector.i, mfem/_par/vector.i Fixed GetDataArray to prevent premature destructor calls
mfem/_ser/densemat.i, mfem/_par/densemat.i Fixed GetDataArray for DenseMatrix and DenseTensor
mfem/_ser/sparsemat.i, mfem/_par/sparsemat.i Fixed GetDataArray, GetJArray, GetIArray for SparseMatrix
mfem/common/numba_coefficient*.* Removed square matrix requirement for MatrixCoefficient
mfem/_ser/setup.py, mfem/_par/setup.py Added build_miniapps configuration and library dependencies
_build_system/*.py Build system updates for miniapp support
docs/changelog.txt Documentation of changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

warning.warn("Rectangular matrix coefficient is experimental", UserWarning)
#if shape[0] != shape[1]:
# import warnings
# warnings.warn("Rectangular matrix coefficient is experimental", UserWarning)
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in variable name: "warning" should be "warnings". The code should use "warnings.warn(...)" instead of "warning.warn(...)".

Copilot uses AI. Check for mistakes.
Comment on lines +138 to +143
def load_module(module_name, module_code):
spec = importlib.util.spec_from_loader(module_name, loader=None, origin="dynamic")
module = types.ModuleType(module_name)
spec.loader.exec_module(module) if spec.loader else exec(module_code, module.__dict__)
sys.modules[module_name] = module
return module
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The load_module function is defined but never used in this file. If this is intended for future use or as a utility, it should be documented. Otherwise, it should be removed to avoid dead code.

Copilot uses AI. Check for mistakes.
Comment on lines +67 to +68
if build_miniapps == '0':
libraries.append("mfem-common")
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here appears inverted. When build_miniapps == '0' (False), the code adds "mfem-common" to libraries. This seems backwards - shouldn't "mfem-common" be added when miniapps ARE being built (build_miniapps == '1')? Please verify this logic is correct.

Copilot uses AI. Check for mistakes.
mpiinc = ''

libraries = ['mfem',]
if build_miniapps == '0':
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here appears inverted. When build_miniapps == '0' (False), the code adds "mfem-common" to libraries. This seems backwards - shouldn't "mfem-common" be added when miniapps ARE being built (build_miniapps == '1')? Please verify this logic is correct.

Suggested change
if build_miniapps == '0':
if build_miniapps == '1':

Copilot uses AI. Check for mistakes.
command_obj.mfem_branch = ''
command_obj.mfem_debug = False
command_obj.mfem_build_miniapps = False
command_obj.mfem_miniapps = True
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value for mfem_miniapps is changed from False to True. This is a significant behavior change that could affect existing workflows. Consider whether this should default to False for backward compatibility, or ensure this change is well-documented in the PR description.

Suggested change
command_obj.mfem_miniapps = True
command_obj.mfem_miniapps = False

Copilot uses AI. Check for mistakes.


try:
import mfem._par.dpg as dpg
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'dpg' is not used.

Copilot uses AI. Check for mistakes.
from numba import njit, void, int32, int64, float64, complex128, types
from mfem.common.bessel import yv as yn
from mfem.common.bessel import jv as jn
import os
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'os' is not used.

Copilot uses AI. Check for mistakes.
try:
import mfem._ser.complexweakform as complexweakform
import mfem._ser.commlexstaticcond as complexstaticcond
import mfem._ser.dpg as dpg
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'dpg' is not used.

Copilot uses AI. Check for mistakes.

try:
import mfem._par.dpg as dpg
except:
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except block directly handles BaseException.

Copilot uses AI. Check for mistakes.

try:
import mfem._par.dpg as dpg
except:
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants