-
Notifications
You must be signed in to change notification settings - Fork 239
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
Python BCs #2170
Conversation
I'm afraid to ask, but 132kloc? |
Yes. I copied OGS, and Python (2 and 3), and combined the two, and now there are Python BCs. 🤣 |
2cced46
to
ca03670
Compare
ProcessLib/CMakeLists.txt
Outdated
# 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: |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
1a1e493
to
f0ca87c
Compare
"script."); | ||
return; | ||
} | ||
if (val.first) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check for HM ✅
Applications/CLI/CMakeLists.txt
Outdated
|
||
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}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaned up.
Applications/CLI/CMakeLists.txt
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider PUBLIC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaned up.
9aaea6a
to
f925e71
Compare
// 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); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed by now.
There was a problem hiding this 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...
There was a problem hiding this 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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" >}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figures in this documentation are not displayed (see https://deploy-preview-2170--ogs.netlify.com/docs/benchmarks/python-bc/hertz-contact/hertz-contact/).
There was a problem hiding this comment.
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.
Regarding VTK Python version mismatch: In your VTK installation there is a file if (NOT ${VTK_PYTHON_VERSION} VERSION_EQUAL ${PYTHON_VERSION_STRING})
...
endif() |
if (!_flush) | ||
return; | ||
|
||
using namespace pybind11::literals; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is r
used?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. 👍
bf64d94
to
7007188
Compare
I just rebased and squashed this PR. Thank you for the quick reviewing process and for your help. 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:
If this PR builds successfully, from my perspective it's ready to be merged if you agree. |
LARGE tests are not tested. |
cd5dbf1
to
7eda63e
Compare
For the failing web build merge this: chleh#10 |
[web] Updated Hugo to 0.47.
OpenGeoSys development has been moved to GitLab. |
Python code for BCs
Limitations (not solved in this PR)
TODO
Review
Issues to open
Don't review yet! Soon: review commit-wise.