Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowshippo committed May 24, 2024
2 parents 3479d91 + 9d14c8f commit 875759d
Show file tree
Hide file tree
Showing 12 changed files with 6,449 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ image: registry.ritc.jp/ricos/simulation/femio/fistr_ricos:0.3.2py3.9
default:
before_script:
- poetry config virtualenvs.create false
- python3.9 -m pip install vtk==9.2.6
- python3.9 -m pip install mayavi==4.8.1
- poetry build
- python3.9 -m pip install dist/femio-*.whl # Only install root project, not dependencies
# - poetry env use /usr/bin/python3.9
Expand Down
4 changes: 3 additions & 1 deletion femio/fem_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,9 @@ def flatten(indices, element_type):
surface_indices, _ = self.extract_surface()
if isinstance(surface_indices, dict):
unique_indices = np.unique(np.concatenate([
flatten(v, k) for k, v in surface_indices.items()]))
flatten(v, k) for k, v in surface_indices.items()
if len(v) > 0
]))
surface_ids = {
t: self.nodes.ids[ids] for t, ids in surface_indices.items()
if t != 'polygon'}
Expand Down
6 changes: 0 additions & 6 deletions femio/formats/polyvtk/write_polyvtk.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

import fileinput

import numpy as np
from tvtk.api import tvtk

Expand Down Expand Up @@ -62,10 +60,6 @@ def write(self, file_name=None, *, overwrite=False):
writer.set_input_data(unstructured_grid)
writer.write()

# Replace int64 with int32 because tvtk has trouble to read it
with fileinput.input(file_name, inplace=True) as file:
for line in file:
print(line.replace('Int64', 'Int32'), end='')
return file_name

def _reorder_cell_data(self, data):
Expand Down
16 changes: 8 additions & 8 deletions femio/graph_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def calculate_element_degree(self):

@functools.lru_cache(maxsize=2)
def calculate_adjacency_matrix(
self, *, mode='elemental', order1_only=True):
self, *, mode='elemental', order1_only=False):
"""Calculate graph adjacency matrix.
Parameters
Expand Down Expand Up @@ -528,7 +528,7 @@ def calculate_adjacency_matrix(
return adj

@functools.lru_cache(maxsize=1)
def calculate_adjacency_matrix_element(self):
def calculate_adjacency_matrix_element(self, order1_only=False):
"""Calculate graph adjacency matrix regarding elements sharing the same
node as connected.
Expand All @@ -541,11 +541,11 @@ def calculate_adjacency_matrix_element(self):
print(dt.datetime.now())
# raise ValueError(node_ids, element_data, )
incidence_matrix = self.calculate_incidence_matrix(
order1_only=True)
order1_only=order1_only)
return incidence_matrix.T.dot(incidence_matrix).tocsr()

@functools.lru_cache(maxsize=1)
def calculate_adjacency_matrix_node(self, order1_only=True):
def calculate_adjacency_matrix_node(self, order1_only=False):
"""Calculate graph adjacency matrix regarding nodes connected with
edges. Edges are defined by element shearing.
Expand All @@ -567,7 +567,7 @@ def calculate_adjacency_matrix_node(self, order1_only=True):
return incidence_matrix.dot(incidence_matrix.T)

@functools.lru_cache(maxsize=1)
def calculate_incidence_matrix(self, order1_only=True):
def calculate_incidence_matrix(self, order1_only=False):
"""Calculate graph incidence matrix, which is
(n_node, n_element)-shaped matrix with bool.
Expand Down Expand Up @@ -617,7 +617,7 @@ def calculate_incidence_matrix(self, order1_only=True):
return incidence_matrix

@functools.lru_cache(maxsize=2)
def calculate_laplacian_matrix(self, mode='nodal', order1_only=True):
def calculate_laplacian_matrix(self, mode='nodal', order1_only=False):
"""Calculate edge-based graph incidence matrix, which is
(n_edge, n_node)-shaped matrix with bool.
Expand Down Expand Up @@ -645,7 +645,7 @@ def calculate_laplacian_matrix(self, mode='nodal', order1_only=True):
return adj_wo_loop - degree

@functools.lru_cache(maxsize=1)
def calculate_edge_gradient_matrix(self, mode='nodal', order1_only=True):
def calculate_edge_gradient_matrix(self, mode='nodal', order1_only=False):
"""Calculate edge-based graph gradient matrix, which is
(n_edge, n_vertex)-shaped matrix with bool. n_vertex can be either
n_node or n_element, depending on the `mode` option.
Expand Down Expand Up @@ -682,7 +682,7 @@ def calculate_edge_gradient_matrix(self, mode='nodal', order1_only=True):
@functools.lru_cache(maxsize=15)
def calculate_n_hop_adj(
self, mode='elemental', n_hop=1, include_self_loop=True,
order1_only=True):
order1_only=False):
if mode == 'elemental':
adj = self.calculate_adjacency_matrix_element()

Expand Down
16 changes: 8 additions & 8 deletions femio/signal_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def convert_nodal2elemental(
return elemental_data

def convert_elemental2nodal(
self, elemental_data, mode='mean', order1_only=True,
self, elemental_data, mode='mean', order1_only=False,
raise_negative_volume=True, weight=None, incidence=None):
"""Convert elemental data to nodal data.
Expand Down Expand Up @@ -283,7 +283,7 @@ def calculate_moving_average_elemental_data(
return averaged_data

def calculate_moving_average_nodal_data(
self, nodal_data, *, hops=1, weight=.1, order1_only=True):
self, nodal_data, *, hops=1, weight=.1, order1_only=False):
"""Perform moving average according with adjacency of the mesh.
Args:
Expand Down Expand Up @@ -324,7 +324,7 @@ def calculate_moving_average_nodal_data(
return averaged_data

def calculate_median_filter(
self, data, *, mode='elemental', hops=1, order1_only=True):
self, data, *, mode='elemental', hops=1, order1_only=False):
"""Perform median filter according with adjacency of the mesh.
Args:
Expand Down Expand Up @@ -358,7 +358,7 @@ def calculate_median_filter(
return filtered_data

def calculate_frame_expansion_adjs(
self, data, mode='nodal', n_hop=1, order1_only=True, **kwargs):
self, data, mode='nodal', n_hop=1, order1_only=False, **kwargs):
"""Calculate frame expansion adjacency matrices.
Parameters
Expand Down Expand Up @@ -402,7 +402,7 @@ def calculate_frame_expansion_adjs(

@functools.lru_cache(maxsize=10)
def calculate_frame_tensor_adjs(
self, mode='elemental', n_hop=1, order1_only=True, tensor_rank=1):
self, mode='elemental', n_hop=1, order1_only=False, tensor_rank=1):
"""Calculate frame adjacency matrices F s.t. phi = F phi,
based on frame which are set of relative vectors coming from mesh
topology.
Expand Down Expand Up @@ -654,7 +654,7 @@ def calculate_elemental_spatial_gradients(
grad_adj.dot(elemental_data) for grad_adj in grad_adjs], axis=1)

def calculate_nodal_spatial_gradients(
self, nodal_data, n_hop=1, kernel=None, order1_only=True,
self, nodal_data, n_hop=1, kernel=None, order1_only=False,
normals=None, **kwargs):
"""Calculate spatial gradient (not graph gradient) w.r.t nodal
data.
Expand Down Expand Up @@ -693,7 +693,7 @@ def calculate_nodal_spatial_gradients(
for grad_adj in grad_adjs], axis=1)

def calculate_spatial_gradient_adjacency_matrices(
self, mode='elemental', n_hop=1, kernel=None, order1_only=True,
self, mode='elemental', n_hop=1, kernel=None, order1_only=False,
use_effective_volume=True, moment_matrix=False,
consider_volume=True, normals=None, normal_weight=1.,
normal_weight_factor=None, adj=None,
Expand Down Expand Up @@ -897,7 +897,7 @@ def sum_axis_1_with_weight(x):
return grad_adjs

def calculate_spatial_gradient_incidence_matrix(
self, mode='nodal', order1_only=True,
self, mode='nodal', order1_only=False,
moment_matrix=True, normals=None, normal_weight=1., **kwargs):
"""Calculate spatial gradient (not graph gradient) incidence matrix.
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ numpy-stl = "^2.13"
pandas = "^1.0"
scipy = "^1.7.0"
lxml = "^4.6.3"
vtk = "^9.0.3"
mayavi = "^4.7.3"
vtk = "^9.2.6"
mayavi = "^4.8.1"
PyQt5 = {version = "^5.14.0", optional = true}

[tool.poetry.extras]
Expand Down
Loading

0 comments on commit 875759d

Please sign in to comment.