-
Notifications
You must be signed in to change notification settings - Fork 238
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 source terms #2234
Python source terms #2234
Conversation
7635fd3
to
44ba88e
Compare
e9552e7
to
901db7b
Compare
@@ -189,7 +189,7 @@ void Process::assemble(const double t, GlobalVector const& x, GlobalMatrix& M, | |||
(_coupled_solutions) != nullptr ? _coupled_solutions->process_id : 0; | |||
_boundary_conditions[pcs_id].applyNaturalBC(t, x, K, b, nullptr); | |||
|
|||
_source_term_collections[pcs_id].integrate(t, b); | |||
_source_term_collections[pcs_id].integrate(t, x, b, nullptr); |
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 add a comment to this and foregoing nullptr
, please? Something like /* unused jacobian */
✅
#include "CreatePythonSourceTerm.h" | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <iostream> |
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.
Logog for cout... Maybe you need it for flushing, though.
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, it is needed for flushing to keep the C++ output and the python output in the correct sequence.
if (!flush) | ||
return; | ||
|
||
LOGOG_COUT << std::flush; |
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::flush is in <ostream>
...
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.
Since the macro LOGOG_COUT is defined as #define LOGOG_COUT std::cout
in ThirdParty/logog/include/string.hpp:39
it is necessary to include iostream.
//! Optionally flushes the standard output upon creation and destruction. | ||
//! Can be used to improve the debug output readability when printing debug | ||
//! messages both from OGS and from Python. | ||
class FlushStdoutGuard |
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.
final, just for safety
} | ||
catch (MethodNotOverriddenInDerivedClassException const& /*e*/) | ||
{ | ||
DBUG("Method `getFlux' not overridden in Python script."); |
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 would either call OGS_FATAL
or rethrow the exception, since the whole class' purpose is to call that getFlux
...
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 might be completely wrong here....
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 MethodNotOverriddenInDerivedClassException
won't be thrown anyway, b/c @TomFischer removed that "feature".
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.
Will remove the try-catch block.
#pragma once | ||
|
||
#include "NumLib/DOF/LocalToGlobalIndexMap.h" | ||
#include "NumLib/IndexValueVector.h" |
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 like this particular one is not needed. Can you try to put some of the includes into cpp and use fwd decls here?
These should be possible to put as fwd decls:
PythonSourceTermPythonSideInterface
LocalToGlobalIndexMap
unsigned const num_integration_points = | ||
_integration_method.getNumberOfPoints(); | ||
auto const num_var = _data.dof_table_bulk.getNumberOfVariables(); | ||
auto const num_nodes = _element.getNumberOfNodes(); |
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.
Use ShapeFunction::NPOINTS.
} | ||
} | ||
|
||
Eigen::VectorXd local_rhs = Eigen::VectorXd::Zero(num_nodes); |
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.
NodalVectorType, or does it have to be dynamic for the python bindings?
|
||
for (unsigned ip = 0; ip < num_integration_points; ip++) | ||
{ | ||
auto const ip_data = _ip_data[ip]; |
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.
should be a ref, not a copy. Same for the following definitions in the for-loop scope.
initial and boundary conditions. It also references the bulk mesh and the | ||
boundary meshes associated with the bulk mesh. The source term $Q$ is defined | ||
in the Python script | ||
`Elliptic/square_1x1_GroundWaterFlow_Python/sinx_siny_source_term.py`. The |
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'd add links to the repo, so the files are downloadable.
``` | ||
|
||
The Python script | ||
`Elliptic/square_1x1_GroundWaterFlow_Python/sin_x_sin_y_source_term.py` is |
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.
sin_x_sin_y vs. sinx_siny above... Links would resolve the issue...
|
||
The Python script | ||
`Elliptic/square_1x1_GroundWaterFlow_Python/sin_x_sin_y_source_term.py` is | ||
``` |
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 you add python
after the three backticks, would it then do the syntax highlighting?
|
||
## Results and evaluation | ||
|
||
### Comparison of the numerical and analytical solution |
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.
solutions
to the prescribed boundary conditions. | ||
{{< img src="../square_1e3_poisson_sin_x_sin_y_sourceterm_Diff_Pressure_AnalyticalSolution_PythonSourceTerm.png" >}} | ||
Since a coarse mesh ($32 \times 32$ elements) is used for the simulation the | ||
difference between the numerical and the analytical solution is relative large. |
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.
relatively
af20ef2
to
0cba195
Compare
c4c485b
to
ddfafe6
Compare
1b73b27
to
2630526
Compare
int const component_id, unsigned const integration_order, | ||
unsigned const shapefunction_order, unsigned const global_dim) | ||
{ | ||
std::cout << "createPythonSourceTerm" << std::endl; |
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.
INFO, DBUG? Then iostream is not needed in this file
pybind11 could not cast python tuple to C++ pair<double, std::array<double, 3>>
Method getFlux has to be overwritten in Python, else a error is thrown.
2630526
to
9bb1531
Compare
Thanks @chleh for the support! |
OpenGeoSys development has been moved to GitLab. |
A first version of Python source term implementation.
ToDo:
Thanks to @chleh for the support!