Skip to content

Commit

Permalink
improve performance for large models
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed May 17, 2024
1 parent 19888b5 commit b95cb87
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* Changed processing of stress field results to iterate of rows grouped per part.

### Removed


Expand Down
2 changes: 1 addition & 1 deletion src/compas_fea2/model/parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def find_element_by_key(self, key):
return element

def find_elements_by_name(self, name):
# type: (str) -> list(_Element)
# type: (str) -> list[_Element]
"""Find all elements with a given name.
Parameters
Expand Down
39 changes: 23 additions & 16 deletions src/compas_fea2/results/fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from itertools import groupby
from typing import Iterable
import numpy as np

Expand Down Expand Up @@ -364,9 +365,11 @@ def _get_results_from_db(self, members, steps):
raise ValueError("Not an element")

results_set = self.rdb.get_rows(field_name, columns, {"key": members_keys, "part": parts_names, "step": steps_names})
return self._to_fea2_results(results_set=results_set)
part_results = {k: list(g) for k, g in groupby(results_set, lambda row: row[1])}

def _to_fea2_results(self, results_set):
return self._to_fea2_results(part_results)

def _to_fea2_results(self, part_results):
"""Convert a set of results from database format to the appropriate
result object.
Expand All @@ -381,21 +384,25 @@ def _to_fea2_results(self, results_set):
Dictiorany grouping the results per Step.
"""
results = {}
for r in results_set:
step = self.problem.find_step_by_name(r[0])
results.setdefault(step, [])
part = self.model.find_part_by_name(r[1]) or self.model.find_part_by_name(r[1], casefold=True)
for name, results in part_results.items():
part = self.model.find_part_by_name(name) or self.model.find_part_by_name(name, casefold=True)

if not part:
raise ValueError(f"Part {r[1]} not in model")
m = getattr(part, self._results_func)(r[2])
if isinstance(m, _Element3D):
cls = self._results_class_3d
columns = self._components_names_3d
else:
cls = self._results_class_2d
columns = self._components_names_2d
values = {k.lower(): v for k, v in zip(columns, r[3:])}
results[step].append(cls(m, **values))
raise ValueError(f"Part {name} not in model")

key_element = {e.key: e for e in part.elements}
for r in results:
step = self.problem.find_step_by_name(r[0])
results.setdefault(step, [])
m = key_element[r[2]]
if isinstance(m, _Element3D):
cls = self._results_class_3d
columns = self._components_names_3d
else:
cls = self._results_class_2d
columns = self._components_names_2d
values = {k.lower(): v for k, v in zip(columns, r[3:])}
results[step].append(cls(m, **values))
return results

def get_max_component(self, component, step):
Expand Down

0 comments on commit b95cb87

Please sign in to comment.