Skip to content

Inverse problems

frontx.InterpolatedSolution

Bases: Module, AbstractSolution

Source code in frontx/__init__.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
class InterpolatedSolution(eqx.Module, AbstractSolution):
    _sol: PchipInterpolator
    _do_dtheta: PchipInterpolator
    _Iodtheta: PchipInterpolator
    _c: float
    _oi: float

    def __init__(
        self,
        o: jax.Array | np.ndarray[Any, Any],
        theta: jax.Array | np.ndarray[Any, Any],
        /,
        *,
        b: float | None = None,
        i: float | None = None,
    ) -> None:
        self._sol = PchipInterpolator(x=o, y=theta, check=False)

        if b is not None:
            o = jnp.insert(o, 0, 0)
            theta = jnp.insert(theta, 0, b)

        if i is not None:
            o = jnp.append(o, o[-1] + 1)
            theta = jnp.append(theta, i)
        else:
            i = theta[-1]  # type: ignore[assignment]

        self._oi: float = o[-1]  # type: ignore[assignment]

        theta, indices = jnp.unique(theta, return_index=True)
        o = o[indices]

        inverse = PchipInterpolator(x=theta, y=o, extrapolate=False, check=False)
        self._do_dtheta = inverse.derivative()
        self._Iodtheta = inverse.antiderivative()
        self._c = self._Iodtheta(i)

    @boltzmannmethod
    def __call__(
        self,
        o: float | jax.Array | np.ndarray[Any, Any],
    ) -> float | jax.Array | np.ndarray[Any, Any]:
        return self._sol(o)  # type: ignore[no-any-return]

    def D(  # noqa: N802
        self,
        theta: float | jax.Array | np.ndarray[Any, Any],
        /,
    ) -> float | jax.Array | np.ndarray[Any, Any]:
        Iodtheta = self._Iodtheta(theta) - self._c  # noqa: N806
        do_dtheta = self._do_dtheta(theta)

        return jnp.squeeze(-(do_dtheta * Iodtheta) / 2)

    def sorptivity(
        self, o: float | jax.Array | np.ndarray[Any, Any] = 0
    ) -> float | jax.Array | np.ndarray[Any, Any]:
        Ithetado = self._sol.antiderivative()  # noqa: N806
        return (Ithetado(self._oi) - Ithetado(o)) - self.i * (self._oi - o)  # type: ignore[no-any-return]

    @property
    def oi(self) -> float:
        return self._oi

oi: float property

D(theta: float | jax.Array | np.ndarray[Any, Any]) -> float | jax.Array | np.ndarray[Any, Any]

Source code in frontx/__init__.py
159
160
161
162
163
164
165
166
167
def D(  # noqa: N802
    self,
    theta: float | jax.Array | np.ndarray[Any, Any],
    /,
) -> float | jax.Array | np.ndarray[Any, Any]:
    Iodtheta = self._Iodtheta(theta) - self._c  # noqa: N806
    do_dtheta = self._do_dtheta(theta)

    return jnp.squeeze(-(do_dtheta * Iodtheta) / 2)

__call__(o: float | jax.Array | np.ndarray[Any, Any]) -> float | jax.Array | np.ndarray[Any, Any]

Source code in frontx/__init__.py
152
153
154
155
156
157
@boltzmannmethod
def __call__(
    self,
    o: float | jax.Array | np.ndarray[Any, Any],
) -> float | jax.Array | np.ndarray[Any, Any]:
    return self._sol(o)  # type: ignore[no-any-return]

__init__(o: jax.Array | np.ndarray[Any, Any], theta: jax.Array | np.ndarray[Any, Any], /, *, b: float | None = None, i: float | None = None) -> None

Source code in frontx/__init__.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
def __init__(
    self,
    o: jax.Array | np.ndarray[Any, Any],
    theta: jax.Array | np.ndarray[Any, Any],
    /,
    *,
    b: float | None = None,
    i: float | None = None,
) -> None:
    self._sol = PchipInterpolator(x=o, y=theta, check=False)

    if b is not None:
        o = jnp.insert(o, 0, 0)
        theta = jnp.insert(theta, 0, b)

    if i is not None:
        o = jnp.append(o, o[-1] + 1)
        theta = jnp.append(theta, i)
    else:
        i = theta[-1]  # type: ignore[assignment]

    self._oi: float = o[-1]  # type: ignore[assignment]

    theta, indices = jnp.unique(theta, return_index=True)
    o = o[indices]

    inverse = PchipInterpolator(x=theta, y=o, extrapolate=False, check=False)
    self._do_dtheta = inverse.derivative()
    self._Iodtheta = inverse.antiderivative()
    self._c = self._Iodtheta(i)

sorptivity(o: float | jax.Array | np.ndarray[Any, Any] = 0) -> float | jax.Array | np.ndarray[Any, Any]

Source code in frontx/__init__.py
169
170
171
172
173
def sorptivity(
    self, o: float | jax.Array | np.ndarray[Any, Any] = 0
) -> float | jax.Array | np.ndarray[Any, Any]:
    Ithetado = self._sol.antiderivative()  # noqa: N806
    return (Ithetado(self._oi) - Ithetado(o)) - self.i * (self._oi - o)  # type: ignore[no-any-return]