|
| 1 | +import inspect |
1 | 2 | import warnings |
| 3 | +from collections.abc import Callable |
2 | 4 | from pathlib import Path |
| 5 | +from typing import Union |
3 | 6 |
|
4 | 7 | from dolfinx import fem, io |
5 | 8 | import ufl |
6 | 9 |
|
7 | | -from festim.species import Species |
8 | 10 | from festim.helpers import get_interpolation_points |
| 11 | +from festim.species import Species |
9 | 12 | from festim.subdomain.volume_subdomain import VolumeSubdomain |
10 | | -import inspect |
11 | 13 |
|
12 | 14 |
|
13 | 15 | class ExportBaseClass: |
@@ -178,18 +180,47 @@ def get_functions(self) -> list[fem.Function]: |
178 | 180 |
|
179 | 181 |
|
180 | 182 | class CustomField(ExportBaseClass): |
| 183 | + """Export a custom field to a VTX file |
| 184 | +
|
| 185 | + Args: |
| 186 | + filename: The name of the output file |
| 187 | + expression: A function evaluating the custom field. Positional |
| 188 | + arguments of the function can be "t" (time), "x" (spatial coordinate), |
| 189 | + "T" (temperature), or any key from the `species_dependent_value` dictionary. |
| 190 | + species_dependent_value: A dictionary mapping argument names |
| 191 | + in `expression` to Species objects. Defaults to None. |
| 192 | + times: if provided, the field will be exported at these timesteps. Otherwise |
| 193 | + exports at all timesteps. Defaults to None. |
| 194 | + subdomain: The volume subdomain on which the custom |
| 195 | + field is evaluated. Defaults to None. |
| 196 | + checkpoint: If True, the export will be a checkpoint file using |
| 197 | + adios4dolfinx and won't be readable by ParaView. Default is False. |
| 198 | +
|
| 199 | + Attributes: |
| 200 | + filename: The name of the output file |
| 201 | + expression: A function evaluating the custom field. |
| 202 | + species_dependent_value: A dictionary mapping argument names to Species objects. |
| 203 | + subdomain: The volume subdomain on which the custom field is evaluated. |
| 204 | + checkpoint: If True, the export will be a checkpoint file. |
| 205 | + times: if provided, the field will be exported at these timesteps. Otherwise |
| 206 | + exports at all timesteps. |
| 207 | + function: the function containing the custom field values |
| 208 | + writer: The VTXWriter object used to write the file |
| 209 | + dolfinx_expression: the dolfinx expression used to evaluate the function |
| 210 | + """ |
| 211 | + |
181 | 212 | function: fem.Function |
182 | 213 | writer: io.VTXWriter |
183 | 214 | dolfinx_expression: fem.Expression |
184 | 215 |
|
185 | 216 | def __init__( |
186 | 217 | self, |
187 | | - filename, |
188 | | - expression, |
189 | | - species_dependent_value=None, |
190 | | - times=None, |
| 218 | + filename: Union[str, Path], |
| 219 | + expression: Callable, |
| 220 | + species_dependent_value: Union[dict[str, Species], None] = None, |
| 221 | + times: Union[list[float], list[int], None] = None, |
191 | 222 | subdomain: VolumeSubdomain = None, |
192 | | - checkpoint=False, |
| 223 | + checkpoint: bool = False, |
193 | 224 | ): |
194 | 225 | super().__init__( |
195 | 226 | filename=filename, |
|
0 commit comments