Skip to content

Commit

Permalink
fix: adding interpolator builder.
Browse files Browse the repository at this point in the history
helper class for building an interpolator and adding constraints.
Can be chained together for easy one line code
  • Loading branch information
lachlangrose committed Jan 15, 2025
1 parent fc5d22a commit 169545b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LoopStructural/interpolators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@ class InterpolatorType(IntEnum):
}

from ._interpolator_factory import InterpolatorFactory

from ._interpolator_builder import InterpolatorBuilder
# from ._api import LoopInterpolator
55 changes: 55 additions & 0 deletions LoopStructural/interpolators/_interpolator_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from LoopStructural.interpolators import (
GeologicalInterpolator,
InterpolatorFactory,
InterpolatorType,
)
from LoopStructural.datatypes import BoundingBox
from typing import Optional, Union
import numpy as np


class InterpolatorBuilder:
def __init__(
self,
interpolatortype: Union[str, InterpolatorType],
bounding_box: BoundingBox,
nelements: int = 1000,
buffer: float = 0.2,
**kwargs,
):
self.interpolatortype = interpolatortype
self.bounding_box = bounding_box
self.nelements = nelements
self.buffer = buffer
self.kwargs = kwargs
self.interpolator : Optional[GeologicalInterpolator]= None

def create_interpolator(self) -> 'InterpolatorBuilder':
self.interpolator = InterpolatorFactory.create_interpolator(
interpolatortype=self.interpolatortype,
boundingbox=self.bounding_box,
nelements=self.nelements,
buffer=self.buffer,
**self.kwargs,
)
return self

def set_value_constraints(self, value_constraints: np.ndarray) -> 'InterpolatorBuilder':
if self.interpolator:
self.interpolator.set_value_constraints(value_constraints)
return self

def set_gradient_constraints(self, gradient_constraints: np.ndarray) -> 'InterpolatorBuilder':
if self.interpolator:
self.interpolator.set_gradient_constraints(gradient_constraints)
return self

def set_normal_constraints(self, normal_constraints: np.ndarray) -> 'InterpolatorBuilder':
if self.interpolator:
self.interpolator.set_normal_constraints(normal_constraints)
return self

def setup_interpolator(self, **kwargs) -> Optional[GeologicalInterpolator]:
if self.interpolator:
self.interpolator.setup(**kwargs)
return self.interpolator

0 comments on commit 169545b

Please sign in to comment.