Skip to content

Commit fc87731

Browse files
committed
2 parents d205e08 + a40b7f3 commit fc87731

File tree

8 files changed

+95
-32
lines changed

8 files changed

+95
-32
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@
1010
The Python bindings are in alpha. Expect a lot of API changes and possible bugs. Use at your own peril!
1111

1212
<br/>
13-
To use the Python bindings, clone the current repository and use `pip` to install:
13+
To use the Python bindings, clone the current repository and use anaconda to install:
1414

1515
```
16+
conda create -n diffipc python=3.9
17+
conda activate diffipc
18+
conda install numpy scipy conda-forge::cython pytorch::pytorch
19+
20+
# optional
21+
export N_THREADS=16
22+
1623
cd polyfem-python/
17-
pip install .
24+
pip install . -v
1825
```
1926

2027
For full documentation see [https://polyfem.github.io/](https://polyfem.github.io/).

pyproject.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel", "pybind11", "cmake"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "polyfempy"
7+
version = "0.8"
8+
description="Polyfem Python Bindings"
9+
readme = "README.md"
10+
authors = [
11+
{ name = "Zizhou Huang", email = "zizhou@nyu.edu" },
12+
]
13+
requires-python = ">=3.6"
14+
classifiers = [
15+
"Programming Language :: Python :: 3",
16+
"License :: OSI Approved :: MIT License"
17+
]

setup.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,17 @@ def run(self):
3737
self.build_extension(ext)
3838

3939
def build_extension(self, ext):
40-
use_cholmod = os.environ.get( "USE_CHOLMOD", "1" )
4140
n_threads_str = os.environ.get( "N_THREADS", "1" )
4241
n_threads = int(n_threads_str)
4342

44-
cholmod_str = "-DPOLYSOLVE_WITH_CHOLMOD=OFF" if use_cholmod == "0" else "-DPOLYSOLVE_WITH_CHOLMOD=ON"
45-
46-
4743
extdir = os.path.join(os.path.abspath(os.path.dirname(
4844
self.get_ext_fullpath(ext.name))), "polyfempy")
4945

5046
python_include_directory = str(get_python_inc())
5147

5248
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
5349
'-DPYTHON_EXECUTABLE=' + sys.executable,
54-
'-DPYTHON_INCLUDE_DIR=' + python_include_directory,
55-
cholmod_str,
56-
'-DPOLYSOLVE_WITH_AMGCL=OFF',
57-
'-DPOLYSOLVE_WITH_MKL=OFF',
58-
'-DPOLYSOLVE_WITH_SPECTRA=OFF']
50+
'-DPYTHON_INCLUDE_DIR=' + python_include_directory]
5951

6052
cfg = 'Debug' if self.debug else 'Release'
6153
build_args = ['--config', cfg]
@@ -93,9 +85,6 @@ def build_extension(self, ext):
9385

9486
setup(
9587
name="polyfempy",
96-
version="0.7",
97-
author="Teseo Schneider",
98-
author_email="",
9988
description="Polyfem Python Bindings",
10089
long_description=long_description,
10190
long_description_content_type="text/markdown",
@@ -108,13 +97,5 @@ def build_extension(self, ext):
10897
"License :: OSI Approved :: MIT License"
10998
],
11099
python_requires='>=3.6',
111-
install_requires=[
112-
'numpy',
113-
'argparse'],
114-
entry_points={
115-
'console_scripts': [
116-
'polyfem = polyfempy.command:polyfem'
117-
]
118-
},
119100
test_suite="test"
120101
)

src/state/state.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
#include <polyfem/time_integrator/ImplicitTimeIntegrator.hpp>
1212
#include <polyfem/State.hpp>
1313

14-
// #include "raster.hpp"
15-
16-
#include <igl/boundary_facets.h>
17-
#include <igl/remove_unreferenced.h>
18-
1914
#include <stdexcept>
2015

2116
#include <pybind11_json/pybind11_json.hpp>
@@ -285,7 +280,7 @@ void define_solver(py::module_ &m)
285280
py::arg("n_refs") = int(0),
286281
py::arg("boundary_id_threshold") = double(-1))
287282

288-
.def("nl_problem", [](State &s) { return s.solve_data.nl_problem; })
283+
.def("nl_problem", [](State &s) { return *(s.solve_data.nl_problem); }, py::return_value_policy::reference)
289284

290285
.def(
291286
"solve",

test/test.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# %%
2+
import polyfempy as pf
3+
import json
4+
import numpy as np
5+
6+
# %%
7+
root = "../data/differentiable/input"
8+
with open(root + "/initial-contact.json", "r") as f:
9+
config = json.load(f)
10+
11+
config["contact"]["use_convergent_formulation"] = True
12+
config["root_path"] = root + "/initial-contact.json"
13+
14+
solver = pf.Solver()
15+
solver.set_settings(json.dumps(config), True)
16+
solver.set_log_level(2)
17+
solver.load_mesh_from_settings()
18+
19+
# %%
20+
mesh = solver.mesh()
21+
22+
print(mesh.n_vertices())
23+
print(mesh.n_elements())
24+
print(mesh.n_cell_vertices(1))
25+
print(mesh.element_vertex(3, 0))
26+
print(mesh.boundary_element_vertex(3, 0))
27+
assert(mesh.is_boundary_vertex(1))
28+
29+
min, max = mesh.bounding_box()
30+
31+
# %%
32+
config = solver.settings()
33+
t0 = config["time"]["t0"]
34+
dt = config["time"]["dt"]
35+
36+
# inits stuff
37+
solver.build_basis()
38+
solver.assemble()
39+
sol = solver.init_timestepping(t0, dt)
40+
41+
for i in range(1, 5):
42+
43+
# substepping
44+
for t in range(1):
45+
sol = solver.step_in_time(sol, t0, dt, t+1)
46+
47+
t0 += dt
48+
solver.export_vtu("step_" + str(i) + ".vtu", sol, np.zeros((0, 0)), t0, dt)
49+
50+
prob = solver.nl_problem()
51+
52+
h = prob.hessian(sol)
53+
reduced_sol = prob.full_to_reduced(sol)
54+
full_sol = prob.reduced_to_full(reduced_sol)
55+
56+
assert(np.linalg.norm(full_sol - sol.flatten()) < 1e-12)
57+
58+
cache = solver.get_solution_cache()
59+
60+
print(cache.solution(1).shape)
61+
print(cache.velocity(2).shape)
62+
print(cache.acceleration(3).shape)
63+
print(cache.hessian(4).shape)

test/test_basic.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
"name": "python",
120120
"nbconvert_exporter": "python",
121121
"pygments_lexer": "ipython3",
122-
"version": "3.11.8"
122+
"version": "3.9.19"
123123
}
124124
},
125125
"nbformat": 4,

test/test_differentiable.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
"name": "python",
141141
"nbconvert_exporter": "python",
142142
"pygments_lexer": "ipython3",
143-
"version": "3.11.8"
143+
"version": "3.9.19"
144144
}
145145
},
146146
"nbformat": 4,

test/test_sim.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import json
33
import numpy as np
44

5-
pf.polyfem_command(json="/Users/zizhouhuang/Desktop/polyfem-python/data/contact/examples/2D/unit-tests/5-squares.json", log_level=2, max_threads=16)
5+
pf.polyfem_command(json="../data/contact/examples/2D/unit-tests/5-squares.json", log_level=2, max_threads=16)
66

7-
root = "/Users/zizhouhuang/Desktop/polyfem/data/contact/examples/2D/unit-tests"
7+
root = "../data/contact/examples/2D/unit-tests"
88
with open(root + "/5-squares.json", "r") as f:
99
config = json.load(f)
1010

0 commit comments

Comments
 (0)