porescene.model module¶
Pore Networks
- class porescene.model.PoreNetwork[source]¶
Bases:
object- classmethod from_mat(pth, vars_nwk, vars_state={}, no_states=[], *, swap_axes=True)[source]¶
Creates a
PoreNetworkinstance by importing the pore network data from a MATLAB.matfile.Attention
Variable import from
.matfiles is only supported for MATLAB files in version 7.3 that are based on HDF5. When saving the MATLAB file, make sure to set the-v7.3in MATLAB’ssavefunction.MATLAB¶1save('myfile.mat', "-v7.3");
Attention
While the first index in MATLAB arrays is
1, Python (and numpy) arrays are0-indexed. This importer function automatically converts the MATLAB indices into0-based Python indices.Note that this applies to following properties:
Attention
MATLAB stores multi-dimensional arrays in column-major order, while numpy defaults to row-major order. Dumping a voxel image out of MATLAB and reading it back with numpy (e.g. via
numpy.fromfile()followed byreshape()) therefore reverses the storage order of its dimensions, which swaps the array’s first and third (spatial) axes while leaving the second axis untouched – what MATLAB calls its first dimension ends up as numpy’s third axis, and vice versa, while the second dimension stays in place.Since
porescene.utility.volume2mesh()builds its mesh directly from such a numpy voxel array, meshes it produces have their first and third axes swapped relative to the coordinate frame the.matfile’s own variables (e.g.pos_p) were written in. By default (swap_axes=True), this importer swaps the first and third columns of every imported position array (PoreNetwork.pore_positionand its_top/_bottom/_left/_right/_front/_backvariants) to match, so pore/throat coordinates line up with meshes built byvolume2mesh(). Passswap_axes=Falseto import the coordinates verbatim in the MATLAB axis order instead, e.g. when no voxel-image mesh is involved.- Parameters:
pth (
Path) – Path to the MATLAB.matfile.vars_nwk (
dict[str,str]) – A map that specifies the corresponding variables in the.matfile for the properties of thePoreNetworkinstance.vars_state (
dict[str,tuple[str,str]]) –A map that relates the variables from the
.matfile toPoreNetworkPropertyinstances.The key in the
dicthas to be identical toPoreNetworkProperty.name, and the value is atuplecontaining twostring, mapping the variables names that hold the pore and throat data, respectively.As example: in case for
"temperature"field data, the.matfile contains a variableT_poresthat holds the temperature of each pore, while the variableT_throatsholds the temperature values of each throat.Imagine, also some acetone concentration has been computed, an additional key
"concentration_acetone"has to be added in a similar way to thedict.Python¶1state_vars = { 2 "temperature": ("T_pores", "T_throats") 3 "concentration_acetone": ("C_acetone_pores", "C_acetone_throats") 4}
By convention, the first array dimension is equal to the number of pores/ throats, while the second dimension contains the evolution of the field, e.g in case of the temperature field, it might be the temporal evolution (when the pore network contains 6274 pores and 149366 throats, and 1000 temperature steps have been calculated, variable
T_poreshas a size of6274 × 1000andT_throatshas a size of149366 × 1000).In case there is state data contained in the
.matfile, the state indices given instates, are wrapped intoPoreNetworkStateinstances.For example, if 1000 states have been calculated, but only every 100th state should be visualized, then
no_statescould be:Python¶1no_states = np.linspace(0, 1000, num=10)
swap_axes (
bool) – IfTrue(default), swaps the first and third columns of every imported position array to compensate for the MATLAB/numpy axis-order mismatch described above, e.g. aligning coordinates with meshes built byporescene.utility.volume2mesh(). Set toFalseto import the coordinates verbatim, in the MATLAB axis order.
- Returns:
PoreNetworkinstance created from given.matfile- Return type:
Self
- add_state(no_state)[source]¶
Adds a
PoreNetworkStateto the current model instance.- Return type:
Self
- get_state(no_state)[source]¶
Returns a
PoreNetworkStatefrom the instance.- Return type:
- throat_count(left=False, right=False, front=False, back=False, bottom=False, top=False)[source]¶
Number of throats in the network.
- Parameters:
left (
bool) – If true, outgoing throats on the left domain boundary are included in the throat count, by default False.right (
bool) – If true, outgoing throats on the right domain boundary are included in the throat count, by default False.front (
bool) – If true, outgoing throats on the front domain boundary are included in the throat count, by default False.back (
bool) – If true, outgoing throats on the back domain boundary are included in the throat count, by default False.bottom (
bool) – If true, outgoing throats on the bottom domain boundary are included in the throat count, by default False.top (
bool) – If true, outgoing throats on the top domain boundary are included in the throat count, by default False.
- Returns:
Number of throats.
- Return type:
- property pores_back: ndarray | None¶
Pores located at the back domain interface that have a connection to the surrounding.
- property pores_bottom: ndarray | None¶
Pores located at the sample bottom interface that have a connection to the surrounding.
- property pores_front: ndarray | None¶
Pores located at the front domain interface that have a connection to the surrounding.
- property pores_left: ndarray | None¶
Pores located at the left domain interface that have a connection to the surrounding.
- property pores_right: ndarray | None¶
Pores located at the right domain interface that have a connection to the surrounding.
- property pores_top: ndarray | None¶
Pores located at the sample top interface that have a connection to the surrounding.
- property states: list[PoreNetworkState]¶
- property throat_radius_back: ndarray | None¶
Radius of each throat connection into the surrounding at the back domain boundary.
- property throat_radius_bottom: ndarray | None¶
Radius of each throat connection into the surrounding at the bottom domain boundary.
- property throat_radius_front: ndarray | None¶
Radius of each throat connection into the surrounding at the front domain boundary.
- property throat_radius_left: ndarray | None¶
Radius of each throat connection into the surrounding at the left domain boundary.
- property throat_radius_right: ndarray | None¶
Radius of each throat connection into the surrounding at the right domain boundary.
- class porescene.model.PoreNetworkProperty(n)[source]¶
Bases:
objectA wrapper for a single property of one state of a pore network.
- class porescene.model.PoreNetworkState[source]¶
Bases:
objectA wrapper for one state of a pore network.
- add_property(prop)[source]¶
Add a
PoreNetworkProperty.- Return type:
Self
- get_property(name)[source]¶
Returns a
PoreNetworkPropertyby name.- Return type:
- property properties: list[PoreNetworkProperty]¶