API Reference#
Core Classes#
- class zefir.potential.ComplexPotential[source]#
Bases:
objectBase class for complex potential flows with GUI metadata support.
All potential flow classes should inherit from this base class. It provides common functionality for evaluating the complex potential and velocity field, along with parameter management for GUI integration.
- metadata#
Metadata describing the flow type and its parameters
- Type:
Examples
>>> from zefir.typing import ParamType >>> class MyFlow(ComplexPotential): ... metadata = FlowMetadata("My Flow", {"param": {"type": ParamType.FLOAT, "default": 1.0}}) ... def __init__(self, param=1.0): ... self._param = param ... def __call__(self, z, deriv=0): ... return self._param * z
- metadata = <zefir.potential.flows.base.FlowMetadata object>#
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity potential
- Returns:
Complex potential values at the given points
- Return type:
ndarray[Any,dtype[complex128]]- Raises:
InvalidDerivLevel – If deriv is not 0 or 1
- velocity(z, frame=FrameType.CARTESIAN)[source]#
Returns the complex velocity field.
If the requested frame is the cartesian one, vx +i vy is returned. If it is cylindrical, vr +i vtheta is returned.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where velocity is evaluatedframe (
FrameType) – Coordinate frame: CARTESIAN (vx + i*vy) or CYLINDRICAL (vr + i*vtheta)
- Returns:
Complex velocity values at the given points
- Return type:
ndarray[Any,dtype[complex128]]
Examples
>>> flow = UniformFlow((1.0, 0.0)) >>> z = np.array([0+0j, 1+0j, 0+1j]) >>> v = flow.velocity(z) >>> v array([1.+0.j, 1.+0.j, 1.+0.j])
- class zefir.potential.FlowMetadata(name, parameters, has_position=False)[source]#
Bases:
objectMetadata for a flow type to enable automatic GUI generation.
This class stores information about flow parameters including their types, default values, ranges, and labels for GUI widget generation.
- Parameters:
name (
str) – Display name for the flow type in the GUIparameters (
dict) – Dictionary of parameter definitions where keys are parameter names and values are dicts with keys: type, default, min, max, labels (optional)has_position (
bool) – Whether the flow has a position parameter that can be set via mouse click
Examples
>>> from zefir.typing import ParamType >>> metadata = FlowMetadata( ... "Source Flow", ... { ... "flow_rate": {"type": ParamType.FLOAT, "default": 1.0, "min": -100, "max": 100}, ... "center": {"type": ParamType.VECTOR2, "default": [0.0, 0.0], "min": -10, "max": 10} ... }, ... has_position=True ... )
- class zefir.potential.UniformFlow(infinite_velocity)[source]#
Bases:
ComplexPotentialUniform flow with constant velocity.
A uniform flow represents a fluid flow with constant velocity vector throughout the entire domain. The complex potential is given by:
\[f(z) = V_\infty z\]where \(V_\infty\) is the complex velocity at infinity.
- Parameters:
infinite_velocity (
Tuple[float,float]) – Velocity vector (Vx, Vy) at infinity
- _vinf#
Complex representation of the velocity at infinity
- Type:
complex
Examples
>>> flow = UniformFlow((1.0, 0.0)) >>> z = np.array([0+0j, 1+0j, 0+1j]) >>> potential = flow(z) >>> potential array([0.+0.j, 1.+0.j, 0.+1.j]) >>> velocity = flow.velocity(z) >>> velocity array([1.+0.j, 1.+0.j, 1.+0.j])
- metadata = <zefir.potential.flows.base.FlowMetadata object>#
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity
- Returns:
Complex potential (deriv=0) or velocity (deriv=1)
- Return type:
ndarray[Any,dtype[complex128]]- Raises:
InvalidDerivLevel – If deriv is not 0 or 1
- class zefir.potential.SourceFlow(flow_rate, center)[source]#
Bases:
ComplexPotentialA source/sink flow defined by its flow rate and center.
A source (or sink) flow represents fluid emanating from (or converging to) a point. The complex potential is given by:
\[f(z) = \frac{q_v}{2\pi} \log(z - z_0)\]where \(q_v\) is the flow rate (positive for source, negative for sink) and \(z_0\) is the center position.
- Parameters:
flow_rate (
float) – Flow rate q_v (positive for source, negative for sink)center (
Union[Tuple[float,float],complex]) – Position (x, y) or complex number representing the center
- _center#
Complex representation of the center position
- Type:
complex
- _intensity#
Scaled intensity (flow_rate / 2π)
- Type:
float
- _original_flow_rate#
Original flow rate value
- Type:
float
Examples
>>> flow = SourceFlow(1.0, (0.5, 0.0)) >>> z = np.array([1+0j, 2+0j, 0+1j]) >>> potential = flow(z) >>> velocity = flow.velocity(z)
- metadata = <zefir.potential.flows.base.FlowMetadata object>#
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity
- Returns:
Complex potential (deriv=0) or velocity (deriv=1)
- Return type:
ndarray[Any,dtype[complex128]]- Raises:
InvalidDerivLevel – If deriv is not 0 or 1
- class zefir.potential.DoubletFlow(intensity, center)[source]#
Bases:
ComplexPotentialA doublet flow defined by its intensity and center.
A doublet (or dipole) flow represents the limiting case of a source and sink of equal strength brought infinitely close together. The complex potential is:
\[f(z) = \frac{K}{2\pi} \frac{1}{z - z_0}\]where \(K\) is the intensity and \(z_0\) is the center position.
- Parameters:
intensity (
float) – Doublet intensity Kcenter (
Union[Tuple[float,float],complex]) – Position (x, y) or complex number representing the center
- _center#
Complex representation of the center position
- Type:
complex
- _intensity#
Scaled intensity (intensity / 2π)
- Type:
float
- _original_intensity#
Original intensity value
- Type:
float
Examples
>>> flow = DoubletFlow(1.0, (0.0, 0.0)) >>> z = np.array([1+0j, 2+0j, 0+1j]) >>> potential = flow(z) >>> velocity = flow.velocity(z)
- metadata = <zefir.potential.flows.base.FlowMetadata object>#
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity
- Returns:
Complex potential (deriv=0) or velocity (deriv=1)
- Return type:
ndarray[Any,dtype[complex128]]- Raises:
InvalidDerivLevel – If deriv is not 0 or 1
- class zefir.potential.SingularVortexFlow(intensity, center)[source]#
Bases:
ComplexPotentialA vortex flow defined by its intensity and center.
A potential vortex (or line vortex) represents irrotational flow with circular streamlines around a center point. The complex potential is:
\[f(z) = -\frac{iK}{2\pi} \log(z - z_0)\]where \(K\) is the circulation intensity and \(z_0\) is the center.
- Parameters:
intensity (
float) – Vortex intensity K (circulation)center (
Union[Tuple[float,float],complex]) – Position (x, y) or complex number representing the vortex center
- _center#
Complex representation of the vortex center
- Type:
complex
- _intensity#
Scaled intensity (intensity / 2π)
- Type:
float
- _original_intensity#
Original intensity value
- Type:
float
Examples
>>> flow = SingularVortexFlow(1.0, (0.0, 0.0)) >>> z = np.array([1+0j, 0+1j, -1+0j]) >>> potential = flow(z) >>> velocity = flow.velocity(z)
- metadata = <zefir.potential.flows.base.FlowMetadata object>#
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity
- Returns:
Complex potential (deriv=0) or velocity (deriv=1)
- Return type:
ndarray[Any,dtype[complex128]]- Raises:
InvalidDerivLevel – If deriv is not 0 or 1
- class zefir.potential.PowerFlow(alpha=1.0, beta=1.0)[source]#
Bases:
ComplexPotentialA potential flow of the form αz^β.
The power law flow represents a family of potential flows defined by:
\[f(z) = \alpha z^\beta\]Special cases include:
β = 1: Uniform flow (when α is real)
β = 2: Flow around a 90° corner
β = n/2: Flow around a corner with angle π/n
- Parameters:
alpha (
float) – Coefficient α (default: 1.0)beta (
float) – Exponent β (default: 1.0, must be > 0)
- _alpha#
Coefficient α
- Type:
float
- _beta#
Exponent β
- Type:
float
Examples
>>> # Uniform flow >>> flow1 = PowerFlow(alpha=1.0, beta=1.0) >>> # 90 degree corner flow >>> flow2 = PowerFlow(alpha=1.0, beta=2.0) >>> z = np.array([1+0j, 1+1j, 2+0j]) >>> potential = flow2(z)
- metadata = <zefir.potential.flows.base.FlowMetadata object>#
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity
- Returns:
Complex potential (deriv=0) or velocity (deriv=1)
- Return type:
ndarray[Any,dtype[complex128]]- Raises:
InvalidDerivLevel – If deriv is not 0 or 1
- class zefir.potential.PotentialSuperposition(flows=None)[source]#
Bases:
ComplexPotentialSuperposition of multiple potential flows.
This class allows combining multiple potential flows into a single flow field by linear superposition. Since the potential flow equations are linear, the sum of valid potential flows is also a valid potential flow.
- Parameters:
flows (
Optional[List[ComplexPotential]]) – List of flow objects to superpose (default: empty list)
- _flows#
List of constituent flows
- Type:
List[ComplexPotential]
Examples
>>> from zefir.potential import UniformFlow, SourceFlow, DoubletFlow >>> # Create a flow around a cylinder (uniform + doublet) >>> flow = PotentialSuperposition() >>> flow.append(UniformFlow((1.0, 0.0))) >>> flow.append(DoubletFlow(1.0, (0.0, 0.0))) >>> z = np.array([2+0j, 0+2j, -2+0j]) >>> potential = flow(z) >>> velocity = flow.velocity(z)
- append(flow)[source]#
Add a flow to the superposition.
- Parameters:
flow (
ComplexPotential) – Flow object to add to the superposition
Examples
>>> superposition = PotentialSuperposition() >>> superposition.append(UniformFlow((1.0, 0.0)))
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity
- Returns:
Sum of potentials/velocities from all flows
- Return type:
ndarray[Any,dtype[complex128]]
Flow Implementations#
Base Class#
Base classes for complex potential flows.
This module provides the foundation for implementing potential flow types with metadata support for automatic GUI generation.
- class zefir.potential.flows.base.FlowMetadata(name, parameters, has_position=False)[source]#
Bases:
objectMetadata for a flow type to enable automatic GUI generation.
This class stores information about flow parameters including their types, default values, ranges, and labels for GUI widget generation.
- Parameters:
name (
str) – Display name for the flow type in the GUIparameters (
dict) – Dictionary of parameter definitions where keys are parameter names and values are dicts with keys: type, default, min, max, labels (optional)has_position (
bool) – Whether the flow has a position parameter that can be set via mouse click
Examples
>>> from zefir.typing import ParamType >>> metadata = FlowMetadata( ... "Source Flow", ... { ... "flow_rate": {"type": ParamType.FLOAT, "default": 1.0, "min": -100, "max": 100}, ... "center": {"type": ParamType.VECTOR2, "default": [0.0, 0.0], "min": -10, "max": 10} ... }, ... has_position=True ... )
- class zefir.potential.flows.base.ComplexPotential[source]#
Bases:
objectBase class for complex potential flows with GUI metadata support.
All potential flow classes should inherit from this base class. It provides common functionality for evaluating the complex potential and velocity field, along with parameter management for GUI integration.
- metadata#
Metadata describing the flow type and its parameters
- Type:
Examples
>>> from zefir.typing import ParamType >>> class MyFlow(ComplexPotential): ... metadata = FlowMetadata("My Flow", {"param": {"type": ParamType.FLOAT, "default": 1.0}}) ... def __init__(self, param=1.0): ... self._param = param ... def __call__(self, z, deriv=0): ... return self._param * z
- metadata = <zefir.potential.flows.base.FlowMetadata object>#
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity potential
- Returns:
Complex potential values at the given points
- Return type:
ndarray[Any,dtype[complex128]]- Raises:
InvalidDerivLevel – If deriv is not 0 or 1
- velocity(z, frame=FrameType.CARTESIAN)[source]#
Returns the complex velocity field.
If the requested frame is the cartesian one, vx +i vy is returned. If it is cylindrical, vr +i vtheta is returned.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where velocity is evaluatedframe (
FrameType) – Coordinate frame: CARTESIAN (vx + i*vy) or CYLINDRICAL (vr + i*vtheta)
- Returns:
Complex velocity values at the given points
- Return type:
ndarray[Any,dtype[complex128]]
Examples
>>> flow = UniformFlow((1.0, 0.0)) >>> z = np.array([0+0j, 1+0j, 0+1j]) >>> v = flow.velocity(z) >>> v array([1.+0.j, 1.+0.j, 1.+0.j])
Uniform Flow#
Uniform flow implementation.
This module provides the UniformFlow class representing a flow with constant velocity throughout the entire domain.
- class zefir.potential.flows.uniform.UniformFlow(infinite_velocity)[source]#
Bases:
ComplexPotentialUniform flow with constant velocity.
A uniform flow represents a fluid flow with constant velocity vector throughout the entire domain. The complex potential is given by:
\[f(z) = V_\infty z\]where \(V_\infty\) is the complex velocity at infinity.
- Parameters:
infinite_velocity (
Tuple[float,float]) – Velocity vector (Vx, Vy) at infinity
- _vinf#
Complex representation of the velocity at infinity
- Type:
complex
Examples
>>> flow = UniformFlow((1.0, 0.0)) >>> z = np.array([0+0j, 1+0j, 0+1j]) >>> potential = flow(z) >>> potential array([0.+0.j, 1.+0.j, 0.+1.j]) >>> velocity = flow.velocity(z) >>> velocity array([1.+0.j, 1.+0.j, 1.+0.j])
- metadata = <zefir.potential.flows.base.FlowMetadata object>#
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity
- Returns:
Complex potential (deriv=0) or velocity (deriv=1)
- Return type:
ndarray[Any,dtype[complex128]]- Raises:
InvalidDerivLevel – If deriv is not 0 or 1
Source/Sink Flow#
Source/Sink flow implementation.
This module provides the SourceFlow class representing a source or sink flow with radial flow pattern emanating from or converging to a point.
- class zefir.potential.flows.source.SourceFlow(flow_rate, center)[source]#
Bases:
ComplexPotentialA source/sink flow defined by its flow rate and center.
A source (or sink) flow represents fluid emanating from (or converging to) a point. The complex potential is given by:
\[f(z) = \frac{q_v}{2\pi} \log(z - z_0)\]where \(q_v\) is the flow rate (positive for source, negative for sink) and \(z_0\) is the center position.
- Parameters:
flow_rate (
float) – Flow rate q_v (positive for source, negative for sink)center (
Union[Tuple[float,float],complex]) – Position (x, y) or complex number representing the center
- _center#
Complex representation of the center position
- Type:
complex
- _intensity#
Scaled intensity (flow_rate / 2π)
- Type:
float
- _original_flow_rate#
Original flow rate value
- Type:
float
Examples
>>> flow = SourceFlow(1.0, (0.5, 0.0)) >>> z = np.array([1+0j, 2+0j, 0+1j]) >>> potential = flow(z) >>> velocity = flow.velocity(z)
- metadata = <zefir.potential.flows.base.FlowMetadata object>#
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity
- Returns:
Complex potential (deriv=0) or velocity (deriv=1)
- Return type:
ndarray[Any,dtype[complex128]]- Raises:
InvalidDerivLevel – If deriv is not 0 or 1
Doublet Flow#
Doublet flow implementation.
This module provides the DoubletFlow class representing a doublet (dipole) flow pattern commonly used to model flow around cylinders.
- class zefir.potential.flows.doublet.DoubletFlow(intensity, center)[source]#
Bases:
ComplexPotentialA doublet flow defined by its intensity and center.
A doublet (or dipole) flow represents the limiting case of a source and sink of equal strength brought infinitely close together. The complex potential is:
\[f(z) = \frac{K}{2\pi} \frac{1}{z - z_0}\]where \(K\) is the intensity and \(z_0\) is the center position.
- Parameters:
intensity (
float) – Doublet intensity Kcenter (
Union[Tuple[float,float],complex]) – Position (x, y) or complex number representing the center
- _center#
Complex representation of the center position
- Type:
complex
- _intensity#
Scaled intensity (intensity / 2π)
- Type:
float
- _original_intensity#
Original intensity value
- Type:
float
Examples
>>> flow = DoubletFlow(1.0, (0.0, 0.0)) >>> z = np.array([1+0j, 2+0j, 0+1j]) >>> potential = flow(z) >>> velocity = flow.velocity(z)
- metadata = <zefir.potential.flows.base.FlowMetadata object>#
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity
- Returns:
Complex potential (deriv=0) or velocity (deriv=1)
- Return type:
ndarray[Any,dtype[complex128]]- Raises:
InvalidDerivLevel – If deriv is not 0 or 1
Vortex Flow#
Vortex flow implementation.
This module provides the SingularVortexFlow class representing a potential vortex with circular streamlines around a center point.
- class zefir.potential.flows.vortex.SingularVortexFlow(intensity, center)[source]#
Bases:
ComplexPotentialA vortex flow defined by its intensity and center.
A potential vortex (or line vortex) represents irrotational flow with circular streamlines around a center point. The complex potential is:
\[f(z) = -\frac{iK}{2\pi} \log(z - z_0)\]where \(K\) is the circulation intensity and \(z_0\) is the center.
- Parameters:
intensity (
float) – Vortex intensity K (circulation)center (
Union[Tuple[float,float],complex]) – Position (x, y) or complex number representing the vortex center
- _center#
Complex representation of the vortex center
- Type:
complex
- _intensity#
Scaled intensity (intensity / 2π)
- Type:
float
- _original_intensity#
Original intensity value
- Type:
float
Examples
>>> flow = SingularVortexFlow(1.0, (0.0, 0.0)) >>> z = np.array([1+0j, 0+1j, -1+0j]) >>> potential = flow(z) >>> velocity = flow.velocity(z)
- metadata = <zefir.potential.flows.base.FlowMetadata object>#
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity
- Returns:
Complex potential (deriv=0) or velocity (deriv=1)
- Return type:
ndarray[Any,dtype[complex128]]- Raises:
InvalidDerivLevel – If deriv is not 0 or 1
Power Law Flow#
Power law flow implementation.
This module provides the PowerFlow class representing flows of the form αz^β, which can model corner flows and other power-law potential flows.
- class zefir.potential.flows.power.PowerFlow(alpha=1.0, beta=1.0)[source]#
Bases:
ComplexPotentialA potential flow of the form αz^β.
The power law flow represents a family of potential flows defined by:
\[f(z) = \alpha z^\beta\]Special cases include:
β = 1: Uniform flow (when α is real)
β = 2: Flow around a 90° corner
β = n/2: Flow around a corner with angle π/n
- Parameters:
alpha (
float) – Coefficient α (default: 1.0)beta (
float) – Exponent β (default: 1.0, must be > 0)
- _alpha#
Coefficient α
- Type:
float
- _beta#
Exponent β
- Type:
float
Examples
>>> # Uniform flow >>> flow1 = PowerFlow(alpha=1.0, beta=1.0) >>> # 90 degree corner flow >>> flow2 = PowerFlow(alpha=1.0, beta=2.0) >>> z = np.array([1+0j, 1+1j, 2+0j]) >>> potential = flow2(z)
- metadata = <zefir.potential.flows.base.FlowMetadata object>#
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity
- Returns:
Complex potential (deriv=0) or velocity (deriv=1)
- Return type:
ndarray[Any,dtype[complex128]]- Raises:
InvalidDerivLevel – If deriv is not 0 or 1
Superposition#
Potential superposition implementation.
This module provides the PotentialSuperposition class for combining multiple potential flows into a single composite flow field.
- class zefir.potential.flows.superposition.PotentialSuperposition(flows=None)[source]#
Bases:
ComplexPotentialSuperposition of multiple potential flows.
This class allows combining multiple potential flows into a single flow field by linear superposition. Since the potential flow equations are linear, the sum of valid potential flows is also a valid potential flow.
- Parameters:
flows (
Optional[List[ComplexPotential]]) – List of flow objects to superpose (default: empty list)
- _flows#
List of constituent flows
- Type:
List[ComplexPotential]
Examples
>>> from zefir.potential import UniformFlow, SourceFlow, DoubletFlow >>> # Create a flow around a cylinder (uniform + doublet) >>> flow = PotentialSuperposition() >>> flow.append(UniformFlow((1.0, 0.0))) >>> flow.append(DoubletFlow(1.0, (0.0, 0.0))) >>> z = np.array([2+0j, 0+2j, -2+0j]) >>> potential = flow(z) >>> velocity = flow.velocity(z)
- append(flow)[source]#
Add a flow to the superposition.
- Parameters:
flow (
ComplexPotential) – Flow object to add to the superposition
Examples
>>> superposition = PotentialSuperposition() >>> superposition.append(UniformFlow((1.0, 0.0)))
- __call__(z, deriv=0)[source]#
Evaluate the complex potential or its derivative.
- Parameters:
z (
ndarray[Any,dtype[complex128]]) – Complex array of points where the potential is evaluatedderiv (
int) – Derivative level: 0 for potential, 1 for velocity
- Returns:
Sum of potentials/velocities from all flows
- Return type:
ndarray[Any,dtype[complex128]]