Skip to content

Commit

Permalink
update polyfem
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangzhongshi committed Jun 15, 2022
1 parent 5cf3dbc commit a6da4cf
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 113 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ __pycache__
temp-plot.html
data*
*libTracyClient.*
.cache/
2 changes: 1 addition & 1 deletion cmake/recipes/polyfem.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include(FetchContent)
FetchContent_Declare(
polyfem
GIT_REPOSITORY https://github.com/polyfem/polyfem.git
GIT_TAG ffb1d130e70fc913ec4546c8683d6d22bd58a700
GIT_TAG ea0e5cc25f2ffba64ea47225cf106460935cda5f
GIT_SHALLOW FALSE
)
FetchContent_MakeAvailable(polyfem)
Expand Down
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 56e70d2d7199fe4822b259c47fada97f70e32a72
GIT_TAG 29a46df1fd90c237a82c219f346a956e72bd17d3
GIT_SHALLOW FALSE
SOURCE_DIR ${POLYFEMPY_DATA_ROOT}/data
)
Expand Down
1 change: 0 additions & 1 deletion polyfempy/test/test_pythonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def sideset(p):
diriclet_bc=[{"id": 4, "value": [0, 0]}],
materials=[{"id": 0, "E": 2100, "nu": 0.3}],
rhs=[0, 0.1],
pde=pf.PDEs.LinearElasticity,
discr_order=1
)

Expand Down
114 changes: 4 additions & 110 deletions src/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,126 +959,20 @@ PYBIND11_MODULE(polyfempy, m)
"runs FEBio", py::arg("febio_file"), py::arg("output_path") = std::string(""), py::arg("log_level") = 2);

m.def(
"solve", [](const Eigen::MatrixXd &vertices, const Eigen::MatrixXi &cells, const py::object &sidesets_func, const py::list &sidesets_selection, const py::list &body_selection, const py::list &materials, const std::string &pde, const py::list &diriclet_bc, const py::list &neumann_bc, const py::list &pressure_bc, const py::object &rhs, const bool is_time_dependent, const py::dict &expo, const int log_level, const py::kwargs &kwargs) {
"solve", [](const Eigen::MatrixXd &vertices, const Eigen::MatrixXi &cells, const py::object &sidesets_func, const int log_level, const py::kwargs &kwargs) {
std::string log_file = "";
const bool is2d = vertices.cols() == 2;

std::unique_ptr<polyfem::State> res = std::make_unique<polyfem::State>();
polyfem::State &state = *res;
state.init_logger(log_file, log_level, false);
// const int kwargs_size = std::distance(kwargs.begin(), kwargs.end());
json in_args = json(static_cast<py::dict>(kwargs));

if (!in_args.contains("normalize_mesh"))
in_args["normalize_mesh"] = false;

const bool is_scalar = polyfem::AssemblerUtils::is_scalar(pde);
in_args["scalar_formulation"] = "";
in_args["tensor_formulation"] = "";

if (is_scalar)
in_args["scalar_formulation"] = pde;
else
in_args["tensor_formulation"] = pde;
in_args["problem"] = is_scalar ? "GenericScalar" : "GenericTensor";

const int sidesets_selection_size = std::distance(sidesets_selection.begin(), sidesets_selection.end());

if (!sidesets_func.is_none())
{
}
else if (sidesets_selection_size > 0 && !in_args.contains("boundary_sidesets"))
{
json selections = json::array();

for (const auto &d : sidesets_selection)
{
selections.push_back(json(d));
}

in_args["boundary_sidesets"] = selections;
}

const int body_selection_size = std::distance(body_selection.begin(), body_selection.end());
if (body_selection_size > 0 && !in_args.contains("body_ids"))
{
json selections = json::array();

for (const auto &d : body_selection)
{
selections.push_back(json(d));
}

in_args["body_ids"] = selections;
}

const int materials_size = std::distance(materials.begin(), materials.end());
if (materials_size > 1 && !in_args.contains("body_params"))
{

json materialss = json::array();

for (const auto &d : materials)
{
materialss.push_back(json(d));
}

in_args["body_params"] = materialss;
}
else if (materials_size == 1 && !in_args.contains("params"))
{
in_args["params"] = json(materials[0]);
}

if (!in_args.contains("problem_params"))
in_args["problem_params"] = {};

if (!in_args["problem_params"].contains("is_time_dependent"))
in_args["problem_params"]["is_time_dependent"] = is_time_dependent;

const int diriclet_bc_size = std::distance(diriclet_bc.begin(), diriclet_bc.end());
if (diriclet_bc_size > 0 && !in_args["problem_params"].contains("dirichlet_boundary"))
{
json bcs = json::array();
for (const auto &d : diriclet_bc)
{
bcs.push_back(json(d));
}
in_args["problem_params"]["dirichlet_boundary"] = bcs;
}
const int neumann_bc_size = std::distance(neumann_bc.begin(), neumann_bc.end());
if (neumann_bc_size > 0 && !in_args["problem_params"].contains("neumann_boundary"))
{
json bcs = json::array();
for (const auto &d : neumann_bc)
{
bcs.push_back(json(d));
}
in_args["problem_params"]["neumann_boundary"] = bcs;
}
const int pressure_bc_size = std::distance(pressure_bc.begin(), pressure_bc.end());
if (pressure_bc_size > 0 && !in_args["problem_params"].contains("pressure_boundary"))
{
json bcs = json::array();
for (const auto &d : pressure_bc)
{
bcs.push_back(json(d));
}
in_args["problem_params"]["pressure_boundary"] = bcs;
}

if (!rhs.is_none() && !in_args["problem_params"].contains("rhs"))
in_args["problem_params"]["rhs"] = json(rhs);

json export_json = json(expo);

if (!in_args.contains("export"))
in_args["export"] = export_json;
json in_args = json(static_cast<py::dict>(kwargs));

state.init(in_args);

if (vertices.size() > 0 && cells.size() > 0)
{
const bool is2d = vertices.cols() == 2;
if (is2d)
state.mesh = std::make_unique<polyfem::CMesh2D>();
else
Expand Down Expand Up @@ -1140,5 +1034,5 @@ PYBIND11_MODULE(polyfempy, m)

return res;
},
"single solve function", py::kw_only(), py::arg("vertices") = Eigen::MatrixXd(), py::arg("cells") = Eigen::MatrixXi(), py::arg("sidesets_func") = py::none(), py::arg("sidesets_selection") = py::list(), py::arg("body_selection") = py::list(), py::arg("materials") = py::list(), py::arg("pde") = std::string("LinearElasticity"), py::arg("diriclet_bc") = py::list(), py::arg("neumann_bc") = py::list(), py::arg("pressure_bc") = py::list(), py::arg("rhs") = py::none(), py::arg("is_time_dependent") = bool(false), py::arg("export") = py::dict(), py::arg("log_level") = 2);
"single solve function", py::kw_only(), py::arg("vertices") = Eigen::MatrixXd(), py::arg("cells") = Eigen::MatrixXi(), py::arg("sidesets_func") = py::none(), py::arg("log_level") = 2);
}

0 comments on commit a6da4cf

Please sign in to comment.