Skip to content

Commit

Permalink
Contextmanager for mesh hfun constraints application
Browse files Browse the repository at this point in the history
  • Loading branch information
SorooshMani-NOAA committed Jan 17, 2024
1 parent f37b424 commit d4e13af
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ocsmesh/hfun/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import operator
import warnings
from collections import defaultdict
from contextlib import contextmanager
from typing import Union, Optional, Iterable, Literal
from multiprocessing import cpu_count, Pool
from time import time
Expand Down Expand Up @@ -111,6 +112,8 @@ def __init__(self, mesh: Mesh) -> None:
self._mesh = mesh
self._crs = mesh.crs
self._constraints = []
self._hold_const = False
self._hold_const_hit = 0

def msh_t(self) -> jigsaw_msh_t:
"""Return the size function specified on the underlying mesh
Expand Down Expand Up @@ -472,6 +475,18 @@ def add_feature(
self.mesh.msh_t.value = values


@contextmanager
def hold_applying_added_constratins(self):
try:
self._hold_const = True
yield
finally:
self._hold_const = False
if self._hold_const_hit > 0:
self.apply_added_constraints()
self._hold_const_hit = 0


def apply_added_constraints(self) -> None:
"""Apply all the added constraints
Expand All @@ -487,6 +502,9 @@ def apply_added_constraints(self) -> None:
None
"""

if self._hold_const:
self._hold_const_hit += 1
return
self.apply_constraints(self._constraints)


Expand Down

0 comments on commit d4e13af

Please sign in to comment.