Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ numpy
# include fourcipp from github
git+https://github.com/4C-multiphysics/fourcipp.git
lnmmeshio>=5.6.3
numexpr

# development
pytest
Expand Down
30 changes: 16 additions & 14 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
aiohappyeyeballs==2.6.1
# via aiohttp
aiohttp==3.11.18
aiohttp==3.12.2
# via wslink
aiosignal==1.3.2
# via aiohttp
Expand Down Expand Up @@ -34,15 +34,15 @@ distlib==0.3.9
# via virtualenv
filelock==3.18.0
# via virtualenv
fonttools==4.57.0
fonttools==4.58.0
# via matplotlib
fourcipp @ git+https://github.com/4C-multiphysics/fourcipp.git
# via -r requirements.in
frozenlist==1.6.0
# via
# aiohttp
# aiosignal
identify==2.6.10
identify==2.6.12
# via pre-commit
idna==3.10
# via
Expand All @@ -68,7 +68,7 @@ loguru==0.7.3
# lnmmeshio
markdown-it-py==3.0.0
# via rich
matplotlib==3.10.1
matplotlib==3.10.3
# via
# pyvista
# vtk
Expand All @@ -80,14 +80,16 @@ more-itertools==10.7.0
# via trame-server
msgpack==1.1.0
# via wslink
multidict==6.4.3
multidict==6.4.4
# via
# aiohttp
# yarl
narwhals==1.38.0
narwhals==1.41.0
# via plotly
nodeenv==1.9.1
# via pre-commit
numexpr==2.10.2
# via -r requirements.in
numpy==2.2.5
# via
# -r requirements.in
Expand All @@ -96,6 +98,7 @@ numpy==2.2.5
# lnmmeshio
# matplotlib
# meshio
# numexpr
# pandas
# pyvista
packaging==25.0
Expand All @@ -116,7 +119,7 @@ platformdirs==4.3.8
# via
# pooch
# virtualenv
plotly==6.0.1
plotly==6.1.2
# via
# -r requirements.in
# trame-plotly
Expand Down Expand Up @@ -144,15 +147,14 @@ python-utils==3.9.1
# via lnmmeshio
pytz==2025.2
# via pandas
pyvista==0.45.0
pyvista==0.45.2
# via -r requirements.in
pyyaml==6.0.2
# via trame
rapidyaml==0.9.0
# via
# lnmmeshio
# pre-commit
# trame
rapidyaml==0.9.0
# via fourcipp
referencing==0.36.2
# via
Expand Down Expand Up @@ -180,16 +182,16 @@ six==1.17.0
# via python-dateutil
tqdm==4.66.5
# via lnmmeshio
trame==3.9.0
trame==3.9.1
# via -r requirements.in
trame-client==3.8.2
trame-client==3.9.0
# via
# trame
# trame-components
# trame-plotly
# trame-vtk
# trame-vuetify
trame-common==0.2.0
trame-common==1.0.0
# via
# trame
# trame-client
Expand Down Expand Up @@ -219,7 +221,7 @@ vtk==9.4.2
# via
# -r requirements.in
# pyvista
wslink==2.3.3
wslink==2.3.4
# via
# trame
# trame-server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from pathlib import Path

import lnmmeshio
import numexpr as ne
import numpy as np
import plotly.express as px

from fourc_webviewer.input_file_utils.io_utils import (
add_fourc_yaml_file_data_to_dis,
safely_parse_string,
)


Expand Down Expand Up @@ -161,14 +161,20 @@ def funct_using_eval(x, y, z, t):
# replace the used power sign
funct_string_copy = funct_string_copy.replace("^", "**")

# replace variables
funct_string_copy = (
funct_string_copy.replace("x", str(x))
.replace("y", str(y))
.replace("z", str(z))
.replace("t", str(t))
)

# for heaviside: np.heaviside takes two arguments -> second argument denotes the function value at the first argument -> we set it by default to 0
funct_string_copy = re.sub(
r"heaviside\((.*?)\)", r"heaviside(\1,0)", funct_string_copy
) # usage of raw strings, (.*?) is a non greedy capturing, and \1 replaces the captured value

return safely_parse_string(
funct_string_copy
) # this parses string in as a function
return ne.evaluate(funct_string_copy) # this parses string in as a function

return np.frompyfunc(funct_using_eval, 4, 1)

Expand Down
22 changes: 0 additions & 22 deletions src/fourc_webviewer/input_file_utils/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,25 +398,3 @@ def get_master_and_linked_material_indices(materials_section):
"master_mat_indices": master_mat_indices,
"linked_mat_indices": linked_mat_indices,
}


def safely_parse_string(string):
"""Safely evaluate a string containing a Python literal expression.

This function attempts to parse the input string using ast.literal_eval,
which safely evaluates strings containing Python literals such as strings,
numbers, tuples, lists, dicts, booleans, and None.

Parameters:
string (str): The string to evaluate.

Returns:
The evaluated Python object.

Raises:
ValueError: If the input string is not a valid Python literal.
"""
try:
return ast.literal_eval(string)
except (ValueError, SyntaxError):
raise ValueError("Invalid input for literal_eval")