From cec4655426ec68ee7f4ab2478baba1a81524a61c Mon Sep 17 00:00:00 2001 From: Daniel Bauer <daniel.j.bauer@fau.de> Date: Mon, 29 Jul 2024 09:56:55 +0200 Subject: [PATCH] add abstract __eq__ to FunctionSpace and remove type ignore comments; implement __eq__ for EG --- hog/forms.py | 30 +++++++++++++++--------------- hog/forms_boundary.py | 4 ++-- hog/function_space.py | 7 +++++++ hog/manifold_forms.py | 4 ++-- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/hog/forms.py b/hog/forms.py index 4b0d0ef..b959b21 100644 --- a/hog/forms.py +++ b/hog/forms.py @@ -84,7 +84,7 @@ Weak formulation geometry, symbolizer, blending=blending, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, docstring=docstring, ) @@ -118,7 +118,7 @@ Weak formulation geometry, symbolizer, blending=blending, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, docstring=docstring, ) @@ -164,7 +164,7 @@ Weak formulation symbolizer, blending=blending, fe_coefficients={"k": coefficient_function_space}, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, docstring=docstring, ) @@ -197,7 +197,7 @@ Note: :math:`a(c) = 1/8 + u^2` is currently hard-coded and the form is intended "The nonlinear-diffusion form does currently not support blending." ) - if trial != test: # type: ignore[comparison-overlap] + if trial != test: raise HOGException( "Trial space must be equal to test space to assemble non-linear diffusion matrix." ) @@ -228,7 +228,7 @@ Note: :math:`a(c) = 1/8 + u^2` is currently hard-coded and the form is intended geometry, symbolizer, blending=blending, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, docstring=docstring, fe_coefficients={"u": coefficient_function_space}, ) @@ -257,7 +257,7 @@ Weak formulation Note: :math:`a(k) = 1/8 + k^2` is currently hard-coded and the form is intended for :math:`k = u`. """ - if trial != test: # type: ignore[comparison-overlap] + if trial != test: raise HOGException( "Trial space must be equal to test space to assemble diffusion matrix." ) @@ -360,7 +360,7 @@ where geometry, symbolizer, blending=blending, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, docstring=docstring, fe_coefficients={"mu": coefficient_function_space}, ) @@ -397,7 +397,7 @@ Weak formulation geometry, symbolizer, blending=blending, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, docstring=docstring, ) @@ -455,7 +455,7 @@ for details. geometry, symbolizer, blending=blending, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, docstring=docstring, ) @@ -476,7 +476,7 @@ def linear_form( where psi a test function and k = k(x) a scalar, external function. """ - if trial != test: # type: ignore[comparison-overlap] + if trial != test: raise HOGException( "Trial space must be equal to test space to assemble linear form (jep this is weird, but linear forms are implemented as diagonal matrices)." ) @@ -654,7 +654,7 @@ where geometry, symbolizer, blending=blending, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, docstring=docstring, fe_coefficients={"mu": coefficient_function_space}, ) @@ -762,7 +762,7 @@ The resulting matrix must be multiplied with a vector of ones to be used as the "wy": velocity_function_space, "wz": velocity_function_space, }, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, docstring=docstring, ) @@ -807,7 +807,7 @@ Weak formulation geometry, symbolizer, blending=blending, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, docstring=docstring, ) @@ -1021,7 +1021,7 @@ Weak formulation ) mat[data.row, data.col] = form - return Form(mat, tabulation, symmetric=trial == test, docstring=docstring) # type: ignore[comparison-overlap] + return Form(mat, tabulation, symmetric=trial == test, docstring=docstring) def zero_form( @@ -1040,6 +1040,6 @@ def zero_form( geometry, symbolizer, blending=blending, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, docstring="", ) diff --git a/hog/forms_boundary.py b/hog/forms_boundary.py index 49a810d..5fde334 100644 --- a/hog/forms_boundary.py +++ b/hog/forms_boundary.py @@ -54,7 +54,7 @@ Weak formulation symbolizer, blending=blending, boundary_geometry=boundary_geometry, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, docstring=docstring, ) @@ -124,7 +124,7 @@ Geometry map: {blending} symbolizer, blending=blending, boundary_geometry=boundary_geometry, - is_symmetric=trial == test, # type: ignore[comparison-overlap] + is_symmetric=trial == test, fe_coefficients={"mu": function_space_mu}, docstring=docstring, ) diff --git a/hog/function_space.py b/hog/function_space.py index 1818c0f..af40883 100644 --- a/hog/function_space.py +++ b/hog/function_space.py @@ -131,6 +131,10 @@ class FunctionSpace(ABC): """The number of DoFs per element.""" return len(self.shape(geometry)) + @abstractmethod + def __eq__(self, other: Any) -> bool: + ... + TrialSpace = NewType("TrialSpace", FunctionSpace) TestSpace = NewType("TestSpace", FunctionSpace) @@ -543,6 +547,9 @@ class EnrichedGalerkinFunctionSpace(FunctionSpace): """Returns the number of DoFs per element.""" return len(self.shape(geometry)) + def __eq__(self, other: Any) -> bool: + return type(self) == type(other) + def __str__(self): return f"EnrichedDG" diff --git a/hog/manifold_forms.py b/hog/manifold_forms.py index f3e87d0..2273bba 100644 --- a/hog/manifold_forms.py +++ b/hog/manifold_forms.py @@ -59,7 +59,7 @@ Weak formulation ∫ ∇u · G^(-1) · ∇v · (det(G))^0.5 """ - if trial != test: # type: ignore[comparison-overlap] + if trial != test: raise HOGException( "Trial space must be equal to test space to assemble laplace beltrami matrix." ) @@ -135,7 +135,7 @@ Weak formulation ∫ uv · (det(G))^0.5 """ - if trial != test: # type: ignore[comparison-overlap] + if trial != test: raise HOGException( "Trial space must be equal to test space to assemble laplace beltrami matrix." ) -- GitLab