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

Python BCs #2170

Merged
merged 23 commits into from
Aug 17, 2018
Merged

Python BCs #2170

merged 23 commits into from
Aug 17, 2018

Conversation

chleh
Copy link
Collaborator

@chleh chleh commented Jul 31, 2018

Python code for BCs

Limitations (not solved in this PR)

  • Only works if all physical fields have the same ansatz functions, i.e., not for HM.
  • The normal traction BC is special and not covered by this PR.
  • Constraint boundary conditions (First version of constraint boundary conditions #2145) cope with secondary variables (fluxes). Fluxes cannot be passed to the Python scripts by the code of this PR.

TODO

  • finish Hertz contact test
  • test with nonlinear BC
  • test with multi-variable process
  • input file documentation
  • maybe fix possible Python version mismatch (presumably between VTK and OGS)
  • fix git lfs tricks (*.pnK)
  • squash

Review

  • attribute used
  • VTK Python version mismatch
  • discuss NLSolver changes.
  • Large tests & Python?

Issues to open

  • Maybe the two versions of deriveBCMap could be merged into one?
  • Python BC for normal traction
  • Python BC for mixed FEM ansatz functions
  • passing secondary variables to Python BC

Don't review yet! Soon: review commit-wise.

@endJunction
Copy link
Member

I'm afraid to ask, but 132kloc?

@chleh
Copy link
Collaborator Author

chleh commented Aug 2, 2018

Yes. I copied OGS, and Python (2 and 3), and combined the two, and now there are Python BCs. 🤣
No. I assume its due to WIP ParaView state files. I'll remove them. Maybe I'll keep some of them to simplify the validation of (changed) reference solutions.

@chleh chleh force-pushed the python-bcs-for-pr branch 3 times, most recently from 2cced46 to ca03670 Compare August 7, 2018 17:26
# snprintf might be defined even though it's not needed. Precompiled headers
# cause that this macro definition is visible in all of ProcessLib.
# That might lead to clashes with jsoncpp. In particular the following
# compilation error was observed on MSVC:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could imagine that msvc version and python version would be helpful...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue solved. Code and comment removed.

@chleh chleh force-pushed the python-bcs-for-pr branch from 1a1e493 to f0ca87c Compare August 8, 2018 12:26
"script.");
return;
}
if (val.first)
Copy link
Member

@endJunction endJunction Aug 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!val,first) return ✅

// gather primary variable values
primary_variables.clear();
auto const num_var = _dof_table_boundary->getNumberOfVariables();
for (int var = 0; var < num_var; ++var)
Copy link
Member

@endJunction endJunction Aug 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for HM ✅


add_library(ogs_python_bindings STATIC ogs_python_bindings.cpp)
target_link_libraries(ogs_python_bindings PRIVATE pybind11::embed)
target_include_directories(ogs_python_bindings PRIVATE ${PYTHON_INCLUDE_DIRS})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up.

target_link_libraries(ogs PRIVATE pybind11::embed)

add_library(ogs_python_bindings STATIC ogs_python_bindings.cpp)
target_link_libraries(ogs_python_bindings PRIVATE pybind11::embed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider PUBLIC.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up.

@chleh chleh force-pushed the python-bcs-for-pr branch from 9aaea6a to f925e71 Compare August 13, 2018 13:55
// OpenGeoSys Python module. The name is generated by pybind11. If it is not
// obvious that this symbol is actually used, the linker might remove it
// under certain circumstances.
mark_used(&pybind11_init_impl_OpenGeoSys);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just an idea...
Maybe declaring the pybind11_init_impl_OpenGeoSys function with __attribute__((used)) helps (at least for gcc and clang).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__attribute__(used) is gcc-specific. I didn't find the same for MSVC:
https://msdn.microsoft.com/de-de/library/74f4886t.aspx

Maybe __declspec(dllexport) might help?
https://msdn.microsoft.com/de-de/library/3y1sfaz2.aspx
But is that also applicable for static libs?

Anyway, we'd have to distinguish between different compilers, which is also kind of hackish...


for (int i = 0; i < getNumberOfComponents(); ++i)
{
global_component_ids.push_back(i);
Copy link
Member

@endJunction endJunction Aug 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::iota(begin(global_component_ids), end(global_component_ids), getNumberOfComponents())
Ups...

A "slightly" verbose version would be something like

std::generate_n(std::back_inserter(global_component_ids), getNumberOfComponents(),
                [n = 0] () mutable { return n++; });

Nevermind

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, verbose 😄

}

std::unique_ptr<LocalToGlobalIndexMap>
LocalToGlobalIndexMap::deriveBoundaryConstrainedMap(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the two versions of deriveBCMap could be merged into one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open an issue.

"bulk_node_ids");

// gather primary variables
Eigen::MatrixXd primary_variables_mat(num_nodes, num_comp_total);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionally use compile time size for nodes' size...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... I think, I'd like to leave it all dynamic:
Eigen::Matrix<double, ShapeFunction::size /*?*/, Eigen::Dynamic> doesn't really look more pleasant.

# self.GetOutputDataObject(0).GetPointData().AddArray(r2)
# self.GetOutputDataObject(0).GetPointData().AddArray(c2)

# self.GetOutputDataObject(0).SetPoints(pts) #.SetData(c2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe some debug comments could be removed...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed by now.

Copy link
Member

@endJunction endJunction left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could open few issues for the remaining modifications after/close to the merge.

Especially one for the deriveBCMap unification...

Copy link
Member

@wenqing wenqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

for (unsigned element_node_id = 0; element_node_id < num_nodes;
++element_node_id)
{
auto* node = _element.getNode(element_node_id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be auto const* const node

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

_data.dof_table_bulk.getGlobalIndex(loc, var, comp);
if (dof_idx == NumLib::MeshComponentMap::nop)
{
// TODO extend Python BC to mixed FEM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far we do not have mixed FEM implemented. Maybe it can be said as "extend Python BC to processes using Taylor-Hood elements".

Copy link
Collaborator Author

@chleh chleh Aug 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO extend Python BC to mixed FEM ansatz functions still fits on a single line (and therefore is displayed completely in QtCreator's todo list). I'd suggest that wording.

values in every load step.
Due to symmetry reasons a flat circular contact area of radius $a$ forms.

{{< img src="../hertz-contact.pnK" >}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file names now are fixed.

@bilke
Copy link
Member

bilke commented Aug 14, 2018

Regarding VTK Python version mismatch:

In your VTK installation there is a file lib/cmake/vtk-8.1/VTKConfig.cmake. Can you please check if there is some info about Python version. If yes (e.g. in the variable VTK_PYTHON_VERSION) you can write a check in our CMake similar to this:

if (NOT ${VTK_PYTHON_VERSION} VERSION_EQUAL ${PYTHON_VERSION_STRING})
...
endif()

if (!_flush)
return;

using namespace pybind11::literals;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with pybind11 and I wonder why the namespace here is needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the line below, e.g. "end"_a is the equivalent to a Python named argument.

return;

using namespace pybind11::literals;
pybind11::print("end"_a = "", "flush"_a = true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain this line, please?

Copy link
Collaborator Author

@chleh chleh Aug 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's equivalent to (Python) print(end="", flush=True), i.e., no end-of-line will be printed and output will be flushed.
So the behaviour is described in the docu of the destructor. Is that sufficient?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. Is my understanding correct that _a means that the previous characters is a python argument name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. _a is a user-defined literal.
There are also other such literals, e.g. s in C++14.
E.g. in

using namespace std::string_literals;
auto str = "test"s;

str is a std::string, not a character array.

Copy link
Member

@bilke bilke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is still a ParaView state file in this PR. Is it intended to keep? Other than that, very good work!

PUBLIC BaseLib MathLib MeshLib NumLib logog)

target_link_libraries(ProcessLibBoundaryConditionPython
PRIVATE pybind11::pybind11)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can merge this command with the previous one:

target_link_libraries(ProcessLibBoundaryConditionPython
    PUBLIC BaseLib MathLib MeshLib NumLib logog
    PRIVATE pybind11::pybind11)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All pvsm files will be deleted.
Thanks for the hint. I'll change it.

MeshLib::MeshItemType::Node,
bulk_node_id};
auto const dof_idx =
_bc_data.dof_table_bulk.getGlobalIndex(loc, var, comp);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to compute the dof_idx also from the boundary dof table?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it's not. I think I tried, but the dof table for the boundary is for a hypothetical equation system that is assembled solely on the boundary (i.e., with no connection to the bulk). Therefore all boundary dof indices would be wrong. @endJunction, is that right? If unsure, I can also check that.

a = np.empty(coords.shape[0])

for i, (x, y, z) in enumerate(coords):
r = np.sqrt(x**2 + y**2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is r used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some old version of this script, long, long time ago. I'll remove it.

Copy link
Member

@TomFischer TomFischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. 👍

@ufz ufz deleted a comment from bilke Aug 15, 2018
@ufz ufz deleted a comment from bilke Aug 15, 2018
@ufz ufz deleted a comment from bilke Aug 15, 2018
@chleh chleh force-pushed the python-bcs-for-pr branch from bf64d94 to 7007188 Compare August 17, 2018 07:50
@chleh chleh mentioned this pull request Aug 17, 2018
1 task
@chleh
Copy link
Collaborator Author

chleh commented Aug 17, 2018

I just rebased and squashed this PR. Thank you for the quick reviewing process and for your help.
Lately, netlify failed because hugo could not resolve some page reference. Locally, at my machine it works, however. @bilke, could you please have a look.

Unfortunately I had to exclude the Hertz contact test, because it requires a non-trivial change to the non-linear solver, cf. #2184.

Remaining for this PR are:

  • I decided not to use __attribute__(used) because it's not portable and I don't know of a version that works for MSVC.
  • The Elder test case is a LARGE one. Are LARGE tests tested with a Python build?

If this PR builds successfully, from my perspective it's ready to be merged if you agree.

@endJunction
Copy link
Member

LARGE tests are not tested.

@chleh chleh force-pushed the python-bcs-for-pr branch from cd5dbf1 to 7eda63e Compare August 17, 2018 11:30
@bilke
Copy link
Member

bilke commented Aug 17, 2018

For the failing web build merge this: chleh#10

[web] Updated Hugo to 0.47.
@chleh chleh removed the WIP 🏗️ label Aug 17, 2018
@endJunction endJunction merged commit 3b1cb39 into ufz:master Aug 17, 2018
@chleh chleh deleted the python-bcs-for-pr branch August 18, 2018 10:57
@ogsbot
Copy link
Member

ogsbot commented Jun 19, 2020

OpenGeoSys development has been moved to GitLab.

See this pull request on GitLab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants