-
-
Notifications
You must be signed in to change notification settings - Fork 64
[WIP] Add Python code for couple your code
section
#523
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
base: master
Are you sure you want to change the base?
Conversation
…ghlight association between tab headers and tab content when printed, issue precice#211
f5e0cac
to
80aabc0
Compare
@uekerman |
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 in principle. No need to also cover inline code. The code blocks are enough. And not need to bring the docstrings.
Be careful with details. The code should really run. Maybe test with a dummy on the side to be completely sure.
Where do the css changes come from? I am not saying that they don't make sense, I only want to understand better. Could you maybe add screenshots before and after?
I did not try to build the website.
You also pushed to #211. No need to update both. You could close #211 in favor of this one.
```python | ||
""" | ||
Parameters: | ||
participant_name: string | ||
Name of the solver | ||
configuration_file_name: string | ||
Name of preCICE config file | ||
rank: int | ||
Rank of the process | ||
size: int | ||
Size of the process | ||
""" | ||
participant = Participant(participant_name, configuration_file_name, rank, size) | ||
|
||
participant.initialize() | ||
|
||
""" | ||
Parameters: | ||
computed_timestep_size: double | ||
Length of timestep used by solver | ||
""" | ||
participant.advance(computed_timestep_size) | ||
|
||
participant.finalize() | ||
|
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 don't think we need the docstring here. This should not replace or copy the API documentation. The meaning of the functions is explained in the text. And we don't need a full code example. This one we have below anyway.
```python | ||
import precice | ||
|
||
turn_on_solver() # e.g. setup and partition mesh | ||
|
||
precice = precice.Interface( | ||
"FluidSolver", "precice-config.xml", rank, size | ||
) | ||
precice_dt = precice.initialize() | ||
|
||
u = initialize_solution() | ||
|
||
while t < t_end: # time loop | ||
dt = compute_adaptive_dt() | ||
dt = min(precice_dt, dt) # more about this in Step 5 | ||
u = solve_time_step(dt, u) # returns new solution | ||
precice_dt = precice.advance(dt) | ||
t = t + dt | ||
|
||
precice.finalize() # frees data structures and closes communication channels | ||
|
||
``` |
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.
This is still preCICE v2 (from when the original PR #211 was opened)
* `set_mesh_vertex` defines the coordinates of a single mesh vertex and returns a vertex ID, which you can use to refer to this vertex. | ||
* `set_mesh_vertices` defines multiple vertices at once. So, you can use this function instead of calling `set_mesh_vertex` multiple times. This is also good practice for performance reasons. |
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.
Let's better not change these inline function names. At least for now. This will get too complicated. Only changing the code blocks is enough. Meaning tabs for each code block here.
""" | ||
Parameters | ||
---------- | ||
mesh_name : str | ||
Name of the mesh to add the vertex to. | ||
position : array_like | ||
The coordinates of the vertex. | ||
|
||
Returns | ||
------- | ||
vertex_id : int | ||
ID of the vertex which is set. | ||
""" | ||
set_mesh_vertex(mesh_name, position) |
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.
No need for the docstring here, but please add the return value to the call.
""" | |
Parameters | |
---------- | |
mesh_name : str | |
Name of the mesh to add the vertex to. | |
position : array_like | |
The coordinates of the vertex. | |
Returns | |
------- | |
vertex_id : int | |
ID of the vertex which is set. | |
""" | |
set_mesh_vertex(mesh_name, position) | |
vertex_id = set_mesh_vertex(mesh_name, position) |
""" | ||
Parameters | ||
---------- | ||
mesh_name : str | ||
Name of the mesh to add the vertices to. | ||
positions : array_like | ||
The coordinates of the vertices in a numpy array [N x D] where | ||
N = number of vertices and D = dimensions of geometry. | ||
|
||
Returns | ||
------- | ||
vertex_ids : numpy.ndarray | ||
IDs of the created vertices. | ||
""" | ||
set_mesh_vertices(mesh_name, positions) |
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.
See above.
""" | ||
Parameters | ||
---------- | ||
mesh_name : str | ||
name of the mesh to write to. | ||
data_name : str | ||
Data name to write to. | ||
vertex_ids : array_like | ||
Indices of the vertices. | ||
values : array_like | ||
Values of data | ||
""" | ||
write_data(self, mesh_name, data_name, vertex_ids, values) |
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.
""" | |
Parameters | |
---------- | |
mesh_name : str | |
name of the mesh to write to. | |
data_name : str | |
Data name to write to. | |
vertex_ids : array_like | |
Indices of the vertices. | |
values : array_like | |
Values of data | |
""" | |
write_data(self, mesh_name, data_name, vertex_ids, values) | |
write_data(mesh_name, data_name, vertex_ids, values) |
|
||
```python | ||
turn_on_solver() # e.g. setup and partition mesh | ||
num_vertices = 3 |
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.
Let's keep the example really consistent with the CPP code. There this "3" is not used, for example.
|
||
mesh_dim = precice.get_mesh_dimensions("FluidMesh") | ||
|
||
vertices = np.zeros((num_vertices, participant.get_mesh_dimensions(mesh_name))) # coords of vertices at wet surface |
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.
Did you double-check that the order of dimensions is correct in such calls? I am not saying that it is wrong, but I did not test it 😄
displacements_dim = precice.get_data_dimensions("FluidMesh", "Displacements") | ||
displacements = np.zeros((num_vertices, displacements_dim)) | ||
|
||
|
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.
Let's avoid unnecessary empty lines.
precice_dt = precice.get_max_time_step_size() | ||
solver_dt = begin_time_step() # e.g. compute adaptive dt | ||
dt = min(precice_dt, solver_dt) | ||
precice.read_data("FluidMesh", "Displacements", vertex_ids, dt, displacements) |
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.
precice.read_data("FluidMesh", "Displacements", vertex_ids, dt, displacements) | |
displacements = precice.read_data("FluidMesh", "Displacements", vertex_ids, dt) |
no?
This PR implements the discussions of #211.
Add Python code examples for the
couple your code
section using nav tabs.