Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update polyfem #14

Closed
wants to merge 9 commits into from
Closed
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
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################
# Check required CMake version
set(REQUIRED_CMAKE_VERSION "3.14.0")
set(REQUIRED_CMAKE_VERSION "3.25.0")
cmake_minimum_required(VERSION ${REQUIRED_CMAKE_VERSION})

if(INPUT_POLYFEMPY_DATA_ROOT)
Expand All @@ -13,11 +13,18 @@ if(NOT EXISTS ${POLYFEMPY_DATA_ROOT})
endif()

project(polyfempy)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

################################################################################

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/recipes/")

include(polyfem_cpm_cache)

# Color output
include(UseColors)

Expand Down Expand Up @@ -51,11 +58,9 @@ include(polyfem_data)
################################################################################
# Subdirectories
################################################################################
add_library(polyfempy MODULE src/binding.cpp src/raster.cpp)
pybind11_add_module(polyfempy)
add_subdirectory(src)
target_include_directories(polyfempy PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(polyfempy PRIVATE polyfem::polyfem pybind11::module pybind11::json)

set_target_properties(polyfempy PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" SUFFIX "${PYTHON_MODULE_EXTENSION}")




23 changes: 3 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,12 @@
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/polyfempy/badges/installer/conda.svg)](https://conda.anaconda.org/conda-forge)




The python bindings are in alpha. Expect a lot of API changes and possible bugs. Use at your own peril!
The Python bindings are in alpha. Expect a lot of API changes and possible bugs. Use at your own peril!

<br/>
I am making efforts to provide a simple python interface to Polyfem.

For doing so I am maintaining a *conda* package which can be easily installed [https://anaconda.org/conda-forge/polyfempy](https://anaconda.org/conda-forge/polyfempy).

Note that the conda deployment is slow and this tutorial will follow the deployment version.

If you hare in a hurry for the juicy latest feature you can clone the repository [Polyfem-python](https://github.com/polyfem/polyfem-python) and use `pip` to install:
To use the Python bindings, clone the current repository and use `pip` to install:
```
python setup.py install
pip install .
```
and
```
python setup.py test
```
for testing.

For python documentation [https://polyfem.github.io/python/](https://polyfem.github.io/python/).

For python jupyter notebook [https://polyfem.github.io/python_examples/](https://polyfem.github.io/python_examples/).

For full documentation see [https://polyfem.github.io/](https://polyfem.github.io/).
33 changes: 33 additions & 0 deletions cmake/recipes/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set(CPM_DOWNLOAD_VERSION 0.39.0)

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

function(download_cpm)
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endfunction()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
download_cpm()
else()
# resume download if it previously failed
file(READ ${CPM_DOWNLOAD_LOCATION} check)
if("${check}" STREQUAL "")
download_cpm()
endif()
unset(check)
endif()

include(${CPM_DOWNLOAD_LOCATION})
19 changes: 10 additions & 9 deletions cmake/recipes/polyfem.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ endif()

message(STATUS "Third-party: creating target 'polyfem::polyfem'")

include(FetchContent)
FetchContent_Declare(
polyfem
GIT_REPOSITORY https://github.com/polyfem/polyfem.git
GIT_TAG 12ac634833f91a3946cff26db01972fdb2ec3214
GIT_SHALLOW FALSE
)
FetchContent_MakeAvailable(polyfem)

# include(FetchContent)
# FetchContent_Declare(
# polyfem
# GIT_REPOSITORY https://github.com/polyfem/polyfem.git
# GIT_TAG 07ee824f836c445699bbc47ee6f19afbfe39bad4
# GIT_SHALLOW FALSE
# )
# FetchContent_MakeAvailable(polyfem)

include(CPM)
CPMAddPackage("gh:polyfem/polyfem#71b67e6416c59f498589ddc1633c11e6c246b392")
24 changes: 24 additions & 0 deletions cmake/recipes/polyfem_cpm_cache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright 2021 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#

if(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_SOURCE_CACHE_DEFAULT $ENV{CPM_SOURCE_CACHE})
else()
# Set CPM cache folder if unset
file(REAL_PATH "~/.cache/CPM" CPM_SOURCE_CACHE_DEFAULT EXPAND_TILDE)
endif()

set(CPM_SOURCE_CACHE
${CPM_SOURCE_CACHE_DEFAULT}
CACHE PATH "Directory to download CPM dependencies"
)
message(STATUS "Using CPM cache folder: ${CPM_SOURCE_CACHE}")
2 changes: 1 addition & 1 deletion cmake/recipes/polyfem_data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include(FetchContent)
FetchContent_Declare(
polyfem_data
GIT_REPOSITORY https://github.com/polyfem/polyfem-data
GIT_TAG 29a46df1fd90c237a82c219f346a956e72bd17d3
GIT_TAG f2089eb6eaa22071f7490e0f144e10afe85d4eba
GIT_SHALLOW FALSE
SOURCE_DIR ${POLYFEMPY_DATA_ROOT}
)
Expand Down
26 changes: 5 additions & 21 deletions cmake/recipes/pybind11.cmake
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
#
# Copyright 2020 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#
# pybind11 (https://github.com/pybind/pybind11)
# License: BSD-style
if(TARGET pybind11::pybind11)
return()
endif()

message(STATUS "Third-party: creating target 'pybind11::pybind11'")

include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.9.2
GIT_SHALLOW FALSE
)

if (POLICY CMP0094) # https://cmake.org/cmake/help/latest/policy/CMP0094.html
cmake_policy(SET CMP0094 NEW) # FindPython should return the first matching Python
endif ()
Expand All @@ -39,7 +22,8 @@ endif ()
# Pybind11 still uses the deprecated FindPythonInterp. So let's call CMake's
# new FindPython module and set PYTHON_EXECUTABLE for Pybind11 to pick up.
# This works well with conda environments.
find_package(Python REQUIRED COMPONENTS Interpreter Development)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})

FetchContent_MakeAvailable(pybind11)
include(CPM)
CPMAddPackage("gh:pybind/[email protected]")
18 changes: 3 additions & 15 deletions polyfempy/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def __init__(self, discr_order=1, pressure_discr_order=1, pde=polyfempy.PDEs.Lap

self.BDF_order = 1

self.scalar_formulation = "Laplacian"
self.tensor_formulation = "LinearElasticity"
self.formulation = "Laplacian"
self.has_collision = contact_problem
self.BDF_order = BDF_order

Expand All @@ -39,7 +38,6 @@ def __init__(self, discr_order=1, pressure_discr_order=1, pde=polyfempy.PDEs.Lap
self.pde = pde

self.selection = None
raise RuntimeError("Old Version Deprecated. Use version <0.5.2 on conda for the old interface")

def get_problem(self):
"""Get the problem"""
Expand All @@ -62,23 +60,13 @@ def set_problem(self, problem):

def get_pde(self, pde):
"""Get the PDE"""
if self._is_scalar:
return self.scalar_formulation
else:
self.tensor_formulation
return self.formulation

def set_pde(self, pde):
"""Sets the PDE to solve, use any of the polyfempy.PDEs"""

if pde == "NonLinearElasticity":
pde = "NeoHookean"

self._is_scalar = not polyfempy.polyfempy.is_tensor(pde)

if self._is_scalar:
self.scalar_formulation = pde
else:
self.tensor_formulation = pde
self.formulation = pde

def set_material_params(self, name, value):
"""set the material parameters, for instance set_material_params("E", 200) sets the Young's modulus E to 200. See https://polyfem.github.io/documentation/#formulations for full list"""
Expand Down
7 changes: 1 addition & 6 deletions polyfempy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
from .polyfempy import Solver
from .polyfempy import PDEs
from .polyfempy import ScalarFormulations
from .polyfempy import TensorFormulations
from .polyfempy import solve_febio
from .polyfempy import solve
from .polyfempy import *

from .Settings import Settings
from .Selection import Selection
Expand Down
82 changes: 16 additions & 66 deletions polyfempy/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,30 @@ def polyfem():
parser = argparse.ArgumentParser()

parser.add_argument("-j", "--json", type=str,
default="", help="Simulation json file")
parser.add_argument("-m", "--mesh", type=str, default="", help="Mesh path")
parser.add_argument("-b", "--febio", type=str,
default="", help="FEBio file path")
default="", help="Simulation JSON file")

parser.add_argument("--n_refs", type=int, default=0,
help="Number of refinements")
parser.add_argument("--not_norm", type=bool, default=True,
help="Skips mesh normalization")
parser.add_argument("-y", "--yaml", type=str,
default="", help="Simulation YAML file")

parser.add_argument("--problem", type=str,
default="", help="Problem name")
parser.add_argument("--sform", type=str,
default="", help="Scalar formulation")
parser.add_argument("--tform", type=str,
default="", help="Tensor formulation")
parser.add_argument("--max_threads", type=int, default=1,
help="Maximum number of threads")

parser.add_argument("--solver", type=str, default="", help="Solver to use")
parser.add_argument("-s", "--strict_validation", action='store_true',
help="Enables strict validation of input JSON")

parser.add_argument("-q", "-p", type=int, default=1,
help="Discretization order")
parser.add_argument("--p_ref", type=bool,
default=False, help="Use p refimenet")
# parser.add_argument("--spline", use_splines, "Use spline for quad/hex meshes");
parser.add_argument("--count_flipped_els", type=bool,
default=False, help="Count flippsed elements")
parser.add_argument("--lin_geom", type=bool, default=False,
help="Force use linear geometric mapping")
# parser.add_argument("--isoparametric", isoparametric, "Force use isoparametric basis");
# parser.add_argument("--serendipity", serendipity, "Use of serendipity elements, only for Q2");
# parser.add_argument("--stop_after_build_basis", stop_after_build_basis, "Stop after build bases");
parser.add_argument("--vis_mesh_res", type=float,
default=-1.0, help="Vis mesh resolution")
parser.add_argument("--project_to_psd", type=bool,
default=False, help="Project local matrices to psd")
parser.add_argument("--n_incr_load", type=int, default=-
1, help="Number of incremeltal load")

parser.add_argument("--output", type=str, default="",
help="Output json file")
parser.add_argument("--vtu", type=str, default="", help="Vtu output file")

parser.add_argument("--quiet", type=bool, default=False,
help="Disable cout for logging")
parser.add_argument("--log_file", type=str,
default="", help="Log to a file")
parser.add_argument("--log_level", type=int, default=1,
help="Log level 1 debug 2 info")

parser.add_argument("--export_material_params", type=bool,
default=False, help="Export material parameters")
parser.add_argument("-o", "--output_dir", type=str,
default="", help="Directory for output files")

args = parser.parse_args()

polyfem_command(
args.json,
args.febio,
args.mesh,
args.problem,
args.sform,
args.tform,
args.n_refs,
args.not_norm,
args.solver,
args.q,
args.p_ref,
args.count_flipped_els,
args.lin_geom,
args.vis_mesh_res,
args.project_to_psd,
args.n_incr_load,
args.output,
args.vtu,
args.log_level,
args.log_file,
args.quiet,
args.export_material_params)
json=args.json,
yaml=args.yaml,
log_level=args.log_level,
strict_validation=args.strict_validation,
max_threads=args.max_threads,
output_dir=args.output_dir
)
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ def build_extension(self, ext):
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DPYTHON_EXECUTABLE=' + sys.executable,
'-DPYTHON_INCLUDE_DIR=' + python_include_directory,
'-DPOLYSOLVE_WITH_PARDISO=OFF',
cholmod_str,
# '-DPOLYFEM_THREADING=NONE',
'-DPOLYFEM_NO_UI=ON',
'-DPOLYSOLVE_WITH_AMGCL=OFF',
'-DPOLYSOLVE_WITH_MKL=OFF',
'-DPOLYSOLVE_WITH_SPECTRA=OFF']
Expand Down
16 changes: 16 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set(SOURCES
binding.cpp
raster.cpp
)

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${SOURCES})
target_sources(polyfempy PRIVATE ${SOURCES})

################################################################################
# Subfolders
################################################################################

add_subdirectory(differentiable)
add_subdirectory(mesh)
add_subdirectory(state)
add_subdirectory(solver)
Loading
Loading