diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 00000000..006a3515 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,2 @@ +[codespell] +ignore-words-list = precice diff --git a/.github/workflows/check-pep8.yml b/.github/workflows/check-pep8.yml index 6f6e71bc..96a8cff8 100644 --- a/.github/workflows/check-pep8.yml +++ b/.github/workflows/check-pep8.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: autopep8 + - name: autopep8 id: autopep8 uses: peter-evans/autopep8@v1 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 08cdde0a..8f323212 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,4 +38,4 @@ jobs: name: dist path: dist - name: Publish package distributions to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/run-solverdummy.yml b/.github/workflows/run-solverdummy.yml index 69b18094..8c268ada 100644 --- a/.github/workflows/run-solverdummy.yml +++ b/.github/workflows/run-solverdummy.yml @@ -36,4 +36,4 @@ jobs: - name: Run solverdummies run: | cd examples/solverdummy/ - python3 solverdummy.py precice-config.xml SolverOne & python3 solverdummy.py precice-config.xml SolverTwo \ No newline at end of file + python3 solverdummy.py precice-config.xml SolverOne & python3 solverdummy.py precice-config.xml SolverTwo diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..4e826827 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,33 @@ +repos: +# Official repo for the clang-format hook +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: 'v20.1.0' + hooks: + - id: clang-format + name: format C/C++ + types_or: [c++] +# Official repo for default hooks +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: 'v5.0.0' + hooks: + - id: check-merge-conflict + - id: mixed-line-ending + - id: trailing-whitespace + args: [--markdown-linebreak-ext=md] + - id: end-of-file-fixer +# black repo for python formatting +- repo: https://github.com/ambv/black + rev: 25.1.0 + hooks: + - id: black + name: format python +- repo: https://github.com/codespell-project/codespell + rev: v2.4.1 + hooks: + - id: codespell + name: check spelling +- repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.33.2 + hooks: + - id: check-github-workflows + args: ["--verbose"] diff --git a/CHANGELOG.md b/CHANGELOG.md index cfefbf93..2ac2bfaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,7 +82,7 @@ All notable changes to this project will be documented in this file. ## 2.2.0.2 -* Improved error messgaes for all assertions. https://github.com/precice/python-bindings/pull/9 +* Improved error messages for all assertions. https://github.com/precice/python-bindings/pull/9 * Improve CI w.r.t spack package. https://github.com/precice/python-bindings/pull/89 ## 2.2.0.1 @@ -118,7 +118,7 @@ All notable changes to this project will be documented in this file. ## 2.0.0.2 -* Improvement of PyPI intergration. +* Improvement of PyPI integration. ## 2.0.0.1 diff --git a/README.md b/README.md index b2509839..9e7f9c33 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ If preCICE (the C++ library) was installed in a custom prefix, or only built but * `LIBRARY_PATH`, `LD_LIBRARY_PATH` to the library location, or `$prefix/lib` * `CPATH` either to the `src` directory or the `$prefix/include` -The preCICE documentation provides more informaiton on [linking preCICE](https://precice.org/installation-linking.html). +The preCICE documentation provides more information on [linking preCICE](https://precice.org/installation-linking.html). ### Using Spack diff --git a/cyprecice/Participant.pxd b/cyprecice/Participant.pxd index 51bf9571..8be9774f 100644 --- a/cyprecice/Participant.pxd +++ b/cyprecice/Participant.pxd @@ -74,7 +74,7 @@ cdef extern from "precice/precice.hpp" namespace "precice": void readData (const string& meshName, const string& dataName, vector[int] vertices, const double relativeReadTime, vector[double]& values) except + # Just-in-time mapping - + void writeAndMapData (const string& meshName, const string& dataName, vector[double] coordinates, vector[double] values) except + void mapAndReadData (const string& meshName, const string& dataName, vector[double] coordinates, double relativeReadTime, vector[double]& values) except + diff --git a/cyprecice/cyprecice.pyx b/cyprecice/cyprecice.pyx index 06095e46..da1bdf2d 100644 --- a/cyprecice/cyprecice.pyx +++ b/cyprecice/cyprecice.pyx @@ -272,7 +272,7 @@ cdef class Participant: Returns ------- tag : bool - Returns True if inital data is required. + Returns True if initial data is required. Notes ----- @@ -284,10 +284,10 @@ cdef class Participant: def requires_writing_checkpoint (self): """ Checks if the participant is required to write an iteration checkpoint. - + If true, the participant is required to write an iteration checkpoint before calling advance(). - + preCICE refuses to proceed if writing a checkpoint is required, but this method isn't called prior to advance(). @@ -1062,7 +1062,7 @@ cdef class Participant: vertex_ids : array_like Indices of the vertices. gradients : array_like - Gradient values differentiated in the spacial direction (dx, dy) for 2D space, (dx, dy, dz) for 3D space + Gradient values differentiated in the spatial direction (dx, dy) for 2D space, (dx, dy, dz) for 3D space Notes ----- @@ -1117,7 +1117,7 @@ cdef class Participant: def requires_gradient_data_for(self, mesh_name, data_name): """ - Checks if the given data set requires gradient data. We check if the data object has been intialized with the gradient flag. + Checks if the given data set requires gradient data. We check if the data object has been initialized with the gradient flag. Parameters ---------- @@ -1229,7 +1229,7 @@ cdef class Participant: def start_profiling_section(self, event_name): """ Starts a profiling section with the given event name. - + Parameters ---------- event_name : str @@ -1239,7 +1239,7 @@ cdef class Participant: -------- Start a profiling section with the event name "EventOne": >>> event_name = "EventOne" - >>> participant.start_profiling_section(event_name) + >>> participant.start_profiling_section(event_name) """ self.thisptr.startProfilingSection(convert(event_name)) diff --git a/docs/ReleaseGuide.md b/docs/ReleaseGuide.md index 7006ff15..82126500 100644 --- a/docs/ReleaseGuide.md +++ b/docs/ReleaseGuide.md @@ -43,16 +43,16 @@ The release of the `python-bindings` repository is made directly from a release commit 44b715dde4e3194fa69e61045089ca4ec6925fe3 (HEAD -> master, origin/master) Author: Benjamin Rodenberg Date: Wed Oct 20 10:52:41 2021 +0200 - + post-tag bump - + commit d2645cc51f84ad5eda43b9c673400aada8e1505a (tag: v2.3.0.1) Merge: 2039557 aca2354 Author: Benjamin Rodenberg Date: Tue Oct 19 12:57:24 2021 +0200 - + Merge pull request #132 from precice/python-bindings-v2.3.0.1 - + Release v2.3.0.1 ``` diff --git a/examples/solverdummy/solverdummy.py b/examples/solverdummy/solverdummy.py index 7143617d..ae48cc12 100644 --- a/examples/solverdummy/solverdummy.py +++ b/examples/solverdummy/solverdummy.py @@ -5,8 +5,9 @@ import precice parser = argparse.ArgumentParser() -parser.add_argument("configurationFileName", - help="Name of the xml config file.", type=str) +parser.add_argument( + "configurationFileName", help="Name of the xml config file.", type=str +) parser.add_argument("participantName", help="Name of the solver.", type=str) try: @@ -19,29 +20,34 @@ configuration_file_name = args.configurationFileName participant_name = args.participantName -if participant_name == 'SolverOne': - write_data_name = 'Data-One' - read_data_name = 'Data-Two' - mesh_name = 'SolverOne-Mesh' +if participant_name == "SolverOne": + write_data_name = "Data-One" + read_data_name = "Data-Two" + mesh_name = "SolverOne-Mesh" -if participant_name == 'SolverTwo': - read_data_name = 'Data-One' - write_data_name = 'Data-Two' - mesh_name = 'SolverTwo-Mesh' +if participant_name == "SolverTwo": + read_data_name = "Data-One" + write_data_name = "Data-Two" + mesh_name = "SolverTwo-Mesh" num_vertices = 3 # Number of vertices solver_process_index = 0 solver_process_size = 1 -participant = precice.Participant(participant_name, configuration_file_name, - solver_process_index, solver_process_size) +participant = precice.Participant( + participant_name, configuration_file_name, solver_process_index, solver_process_size +) -assert (participant.requires_mesh_connectivity_for(mesh_name) is False) +assert participant.requires_mesh_connectivity_for(mesh_name) is False vertices = np.zeros((num_vertices, participant.get_mesh_dimensions(mesh_name))) -read_data = np.zeros((num_vertices, participant.get_data_dimensions(mesh_name, read_data_name))) -write_data = np.zeros((num_vertices, participant.get_data_dimensions(mesh_name, write_data_name))) +read_data = np.zeros( + (num_vertices, participant.get_data_dimensions(mesh_name, read_data_name)) +) +write_data = np.zeros( + (num_vertices, participant.get_data_dimensions(mesh_name, write_data_name)) +) for x in range(num_vertices): for y in range(participant.get_mesh_dimensions(mesh_name)): diff --git a/setup.py b/setup.py index c6a82483..0013d62f 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ def get_extensions(): compile_args += pkgconfig.cflags("libprecice").split() if os.environ.get(MOCKED_ENV) is not None: - print(f"Builing mocked pyprecice as {MOCKED_ENV} is set") + print(f"Building mocked pyprecice as {MOCKED_ENV} is set") bindings_sources.append("test/Participant.cpp") else: link_args += pkgconfig.libs("libprecice").split() diff --git a/test/Participant.cpp b/test/Participant.cpp index 8d031295..dd24d5c3 100644 --- a/test/Participant.cpp +++ b/test/Participant.cpp @@ -1,12 +1,11 @@ #include "precice/Participant.hpp" #include "precice/Tooling.hpp" +#include #include #include -#include #include -bool operator==(const ::precice::string_view& sv, const std::string& s) -{ +bool operator==(const ::precice::string_view &sv, const std::string &s) { return std::string(sv.begin(), sv.end()) == s; } @@ -26,17 +25,13 @@ std::vector fake_coordinates; namespace precice { -namespace impl{ -class ParticipantImpl{}; -} +namespace impl { +class ParticipantImpl {}; +} // namespace impl -Participant:: Participant -( - precice::string_view participantName, - precice::string_view configurationFileName, - int solverProcessIndex, - int solverProcessSize ) -{ +Participant::Participant(precice::string_view participantName, + precice::string_view configurationFileName, + int solverProcessIndex, int solverProcessSize) { fake_version = "dummy"; fake_read_write_buffer = std::vector(); fake_mesh_dimensions = 3; @@ -49,19 +44,16 @@ Participant:: Participant n_fake_vertices = 3; fake_ids.resize(n_fake_vertices); std::iota(fake_ids.begin(), fake_ids.end(), 0); - fake_bounding_box.resize(fake_mesh_dimensions*2); + fake_bounding_box.resize(fake_mesh_dimensions * 2); std::iota(fake_bounding_box.begin(), fake_bounding_box.end(), 0); - fake_coordinates.resize(n_fake_vertices*fake_mesh_dimensions); + fake_coordinates.resize(n_fake_vertices * fake_mesh_dimensions); std::iota(fake_coordinates.begin(), fake_coordinates.end(), 0); } -Participant::Participant( - precice::string_view participantName, - precice::string_view configurationFileName, - int solverProcessIndex, - int solverProcessSize, - void * communicator) -{ +Participant::Participant(precice::string_view participantName, + precice::string_view configurationFileName, + int solverProcessIndex, int solverProcessSize, + void *communicator) { fake_version = "dummy"; fake_read_write_buffer = std::vector(); fake_mesh_dimensions = 3; @@ -74,37 +66,24 @@ Participant::Participant( n_fake_vertices = 3; fake_ids.resize(n_fake_vertices); std::iota(fake_ids.begin(), fake_ids.end(), 0); - fake_bounding_box.resize(fake_mesh_dimensions*2); + fake_bounding_box.resize(fake_mesh_dimensions * 2); std::iota(fake_bounding_box.begin(), fake_bounding_box.end(), 0); } Participant::~Participant() = default; -void Participant:: initialize() -{ -} +void Participant::initialize() {} -void Participant:: advance -( - double computedTimestepLength) -{ -} +void Participant::advance(double computedTimestepLength) {} -void Participant:: finalize() -{} +void Participant::finalize() {} -int Participant:: getMeshDimensions -( - precice::string_view meshName) const -{ +int Participant::getMeshDimensions(precice::string_view meshName) const { return fake_mesh_dimensions; } -int Participant:: getDataDimensions -( - precice::string_view meshName, - precice::string_view dataName) const -{ +int Participant::getDataDimensions(precice::string_view meshName, + precice::string_view dataName) const { if (dataName.data() == fake_scalar_data_name) { return fake_scalar_data_dimensions; } else if (dataName.data() == fake_vector_data_name) { @@ -114,168 +93,102 @@ int Participant:: getDataDimensions } } -bool Participant:: isCouplingOngoing() const -{ - return 0; -} +bool Participant::isCouplingOngoing() const { return 0; } -bool Participant:: isTimeWindowComplete() const -{ - return 0; -} +bool Participant::isTimeWindowComplete() const { return 0; } -double Participant:: getMaxTimeStepSize() const -{ - return -1.0; -} +double Participant::getMaxTimeStepSize() const { return -1.0; } -bool Participant:: requiresInitialData() -{ - return 0; -} +bool Participant::requiresInitialData() { return 0; } -bool Participant:: requiresReadingCheckpoint() -{ - return 0; -} +bool Participant::requiresReadingCheckpoint() { return 0; } -bool Participant:: requiresWritingCheckpoint() -{ - return 0; -} +bool Participant::requiresWritingCheckpoint() { return 0; } -bool Participant:: requiresMeshConnectivityFor -( - precice::string_view meshName) const -{ +bool Participant::requiresMeshConnectivityFor( + precice::string_view meshName) const { return 0; } -bool Participant:: requiresGradientDataFor -( - precice::string_view meshName, - precice::string_view dataName) const -{ +bool Participant::requiresGradientDataFor(precice::string_view meshName, + precice::string_view dataName) const { return 0; } -int Participant:: setMeshVertex -( - precice::string_view meshName, - precice::span position ) -{ +int Participant::setMeshVertex(precice::string_view meshName, + precice::span position) { return 0; } -int Participant:: getMeshVertexSize -( - precice::string_view meshName) const -{ +int Participant::getMeshVertexSize(precice::string_view meshName) const { return n_fake_vertices; } -void Participant:: setMeshVertices -( - precice::string_view meshName, - precice::span positions, - precice::span ids) -{ - if(ids.size() > 0) { - assert (ids.size() == fake_ids.size()); +void Participant::setMeshVertices(precice::string_view meshName, + precice::span positions, + precice::span ids) { + if (ids.size() > 0) { + assert(ids.size() == fake_ids.size()); std::copy(fake_ids.begin(), fake_ids.end(), ids.data()); } } -void Participant:: setMeshEdge -( - precice::string_view meshName, - int firstVertexID, - int secondVertexID) -{} +void Participant::setMeshEdge(precice::string_view meshName, int firstVertexID, + int secondVertexID) {} void Participant::setMeshEdges( precice::string_view meshName, - precice::span vertices) -{} - -void Participant:: setMeshTriangle -( - precice::string_view meshName, - int firstVertexID, - int secondVertexID, - int thirdVertexID ) -{} - -void Participant:: setMeshTriangles -( - precice::string_view meshName, - precice::span vertices ) -{} - -void Participant:: setMeshQuad -( - precice::string_view meshName, - int firstVertexID, - int secondVertexID, - int thirdVertexID, - int fourthVertexID ) -{} - -void Participant:: setMeshQuads -( - precice::string_view meshName, - precice::span vertices) -{} - -void Participant::setMeshTetrahedron -( + precice::span vertices) {} + +void Participant::setMeshTriangle(precice::string_view meshName, + int firstVertexID, int secondVertexID, + int thirdVertexID) {} + +void Participant::setMeshTriangles( precice::string_view meshName, - int firstVertexID, - int secondVertexID, - int thirdVertexID, - int fourthVertexID) -{} - -void Participant::setMeshTetrahedra -( + precice::span vertices) {} + +void Participant::setMeshQuad(precice::string_view meshName, int firstVertexID, + int secondVertexID, int thirdVertexID, + int fourthVertexID) {} + +void Participant::setMeshQuads( precice::string_view meshName, - precice::span vertices) -{} - -void Participant::resetMesh -( - precice::string_view meshName) -{} - -void Participant:: writeData -( - precice::string_view meshName, - precice::string_view dataName, - precice::span vertices, - precice::span values) -{ + precice::span vertices) {} + +void Participant::setMeshTetrahedron(precice::string_view meshName, + int firstVertexID, int secondVertexID, + int thirdVertexID, int fourthVertexID) {} + +void Participant::setMeshTetrahedra( + precice::string_view meshName, + precice::span vertices) {} + +void Participant::resetMesh(precice::string_view meshName) {} + +void Participant::writeData(precice::string_view meshName, + precice::string_view dataName, + precice::span vertices, + precice::span values) { fake_read_write_buffer.clear(); - for(const double value: values) { + for (const double value : values) { fake_read_write_buffer.push_back(value); } } -void Participant:: readData -( - precice::string_view meshName, - precice::string_view dataName, - precice::span vertices, - double relativeReadTime, - precice::span values) const -{ +void Participant::readData(precice::string_view meshName, + precice::string_view dataName, + precice::span vertices, + double relativeReadTime, + precice::span values) const { if (dataName.data() == fake_scalar_data_name) { - for(const int id: vertices) { + for (const int id : vertices) { values[id] = fake_read_write_buffer[id]; } } else if (dataName.data() == fake_vector_data_name) { - for(const int id: vertices) { - for(int d = 0; d < fake_vector_data_dimensions; d++) { + for (const int id : vertices) { + for (int d = 0; d < fake_vector_data_dimensions; d++) { const int linearized_id = fake_vector_data_dimensions * id + d; values[linearized_id] = fake_read_write_buffer[linearized_id]; } @@ -283,85 +196,65 @@ void Participant:: readData } } -void Participant:: writeAndMapData -( - precice::string_view meshName, - precice::string_view dataName, - precice::span coordinates, - precice::span values) -{ +void Participant::writeAndMapData(precice::string_view meshName, + precice::string_view dataName, + precice::span coordinates, + precice::span values) { fake_read_write_buffer.clear(); - for(const double value: values) { + for (const double value : values) { fake_read_write_buffer.push_back(value); } } -void Participant:: mapAndReadData -( - precice::string_view meshName, - precice::string_view dataName, - precice::span coordinates, - double relativeReadTime, - precice::span values) const -{ - std::copy(fake_read_write_buffer.begin(), fake_read_write_buffer.end(), values.begin()); +void Participant::mapAndReadData(precice::string_view meshName, + precice::string_view dataName, + precice::span coordinates, + double relativeReadTime, + precice::span values) const { + std::copy(fake_read_write_buffer.begin(), fake_read_write_buffer.end(), + values.begin()); } -void Participant:: setMeshAccessRegion -( - precice::string_view meshName, - precice::span boundingBox ) const -{ - assert(meshName == fake_mesh_name); +void Participant::setMeshAccessRegion( + precice::string_view meshName, + precice::span boundingBox) const { + assert(meshName == fake_mesh_name); - for(std::size_t i = 0; i < fake_bounding_box.size(); i++){ - assert(boundingBox[i] == fake_bounding_box[i]); - } + for (std::size_t i = 0; i < fake_bounding_box.size(); i++) { + assert(boundingBox[i] == fake_bounding_box[i]); + } } -void Participant:: getMeshVertexIDsAndCoordinates -( - precice::string_view meshName, - precice::span valueIndices, - precice::span coordinates ) const -{ - assert(meshName == fake_mesh_name); - assert(valueIndices.size() == fake_ids.size()); - assert(coordinates.size() == fake_coordinates.size()); - - for(std::size_t i = 0; i < fake_ids.size(); i++){ - valueIndices[i] = fake_ids[i]; - } - for(std::size_t i = 0; i < fake_coordinates.size(); i++){ - coordinates[i] = fake_coordinates[i]; - } +void Participant::getMeshVertexIDsAndCoordinates( + precice::string_view meshName, precice::span valueIndices, + precice::span coordinates) const { + assert(meshName == fake_mesh_name); + assert(valueIndices.size() == fake_ids.size()); + assert(coordinates.size() == fake_coordinates.size()); + + for (std::size_t i = 0; i < fake_ids.size(); i++) { + valueIndices[i] = fake_ids[i]; + } + for (std::size_t i = 0; i < fake_coordinates.size(); i++) { + coordinates[i] = fake_coordinates[i]; + } } void Participant::writeGradientData( - precice::string_view meshName, - precice::string_view dataName, + precice::string_view meshName, precice::string_view dataName, precice::span vertices, - precice::span gradients) -{ + precice::span gradients) { fake_read_write_buffer.clear(); - for (const double gradient: gradients) { + for (const double gradient : gradients) { fake_read_write_buffer.push_back(gradient); } } -void Participant::startProfilingSection( - precice::string_view sectionName) -{ -} +void Participant::startProfilingSection(precice::string_view sectionName) {} -void Participant::stopLastProfilingSection() -{ -} +void Participant::stopLastProfilingSection() {} -std::string getVersionInformation() -{ - return fake_version; -} +std::string getVersionInformation() { return fake_version; } } // namespace precice diff --git a/test/test_bindings_module.py b/test/test_bindings_module.py index ee2287ee..9c9f865a 100644 --- a/test/test_bindings_module.py +++ b/test/test_bindings_module.py @@ -14,8 +14,7 @@ def test_constructor(self): self.assertTrue(True) def test_constructor_custom_mpi_comm(self): - participant = precice.Participant( - "test", "dummy.xml", 0, 1, MPI.COMM_WORLD) + participant = precice.Participant("test", "dummy.xml", 0, 1, MPI.COMM_WORLD) self.assertTrue(True) def test_version(self): @@ -32,16 +31,28 @@ def test_get_mesh_dimensions(self): def test_get_data_dimensions(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_scalar_data_dimension = 1 # compare to test/Participant.hpp, fake_scalar_data_dimension - self.assertEqual(fake_scalar_data_dimension, participant.get_data_dimensions("dummy", "FakeScalarData")) - fake_vector_data_dimension = 3 # compare to test/Participant.hpp, fake_vector_data_dimension - self.assertEqual(fake_vector_data_dimension, participant.get_data_dimensions("dummy", "FakeVectorData")) + fake_scalar_data_dimension = ( + 1 # compare to test/Participant.hpp, fake_scalar_data_dimension + ) + self.assertEqual( + fake_scalar_data_dimension, + participant.get_data_dimensions("dummy", "FakeScalarData"), + ) + fake_vector_data_dimension = ( + 3 # compare to test/Participant.hpp, fake_vector_data_dimension + ) + self.assertEqual( + fake_vector_data_dimension, + participant.get_data_dimensions("dummy", "FakeVectorData"), + ) def test_requires_mesh_connectivity_for(self): participant = precice.Participant("test", "dummy.xml", 0, 1) fake_bool = 0 # compare to output in test/SolverInterface.cpp fake_mesh_name = "FakeMesh" - self.assertEqual(fake_bool, participant.requires_mesh_connectivity_for(fake_mesh_name)) + self.assertEqual( + fake_bool, participant.requires_mesh_connectivity_for(fake_mesh_name) + ) def test_reset_mesh(self): participant = precice.Participant("test", "dummy.xml", 0, 1) @@ -50,7 +61,9 @@ def test_reset_mesh(self): def test_set_mesh_vertices(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) fake_dimension = 3 # compare to test/SolverInterface.cpp, fake_dimensions n_fake_vertices = 3 # compare to test/SolverInterface.cpp, n_fake_vertices positions = np.random.rand(n_fake_vertices, fake_dimension) @@ -60,7 +73,9 @@ def test_set_mesh_vertices(self): def test_set_mesh_vertices_empty(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) fake_dimension = 3 # compare to test/SolverInterface.cpp, fake_dimensions n_fake_vertices = 0 # compare to test/SolverInterface.cpp, n_fake_vertices positions = np.zeros((n_fake_vertices, fake_dimension)) @@ -70,19 +85,25 @@ def test_set_mesh_vertices_empty(self): def test_set_mesh_vertices_list(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) fake_dimension = 3 # compare to test/SolverInterface.cpp, fake_dimensions n_fake_vertices = 3 # compare to test/SolverInterface.cpp, n_fake_vertices positions = np.random.rand(n_fake_vertices, fake_dimension) - positions = list(list(positions[i, j] for j in range( - positions.shape[1])) for i in range(positions.shape[0])) + positions = list( + list(positions[i, j] for j in range(positions.shape[1])) + for i in range(positions.shape[0]) + ) expected_output = np.array(range(n_fake_vertices)) actual_output = participant.set_mesh_vertices(fake_mesh_name, positions) self.assertTrue(np.array_equal(expected_output, actual_output)) def test_set_mesh_vertices_empty_list(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) positions = [] n_fake_vertices = 0 expected_output = np.array(range(n_fake_vertices)) @@ -91,19 +112,25 @@ def test_set_mesh_vertices_empty_list(self): def test_set_mesh_vertices_tuple(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) fake_dimension = 3 # compare to test/SolverInterface.cpp, fake_dimensions n_fake_vertices = 3 # compare to test/SolverInterface.cpp, n_fake_vertices positions = np.random.rand(n_fake_vertices, fake_dimension) - positions = tuple(tuple(positions[i, j] for j in range( - positions.shape[1])) for i in range(positions.shape[0])) + positions = tuple( + tuple(positions[i, j] for j in range(positions.shape[1])) + for i in range(positions.shape[0]) + ) expected_output = np.array(range(n_fake_vertices)) actual_output = participant.set_mesh_vertices(fake_mesh_name, positions) self.assertTrue(np.array_equal(expected_output, actual_output)) def test_set_mesh_vertices_empty_tuple(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) positions = () n_fake_vertices = 0 expected_output = np.array(range(n_fake_vertices)) @@ -112,19 +139,25 @@ def test_set_mesh_vertices_empty_tuple(self): def test_set_mesh_vertices_mixed(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) fake_dimension = 3 # compare to test/SolverInterface.cpp, fake_dimensions n_fake_vertices = 3 # compare to test/SolverInterface.cpp, n_fake_vertices positions = np.random.rand(n_fake_vertices, fake_dimension) - positions = list(tuple(positions[i, j] for j in range( - positions.shape[1])) for i in range(positions.shape[0])) + positions = list( + tuple(positions[i, j] for j in range(positions.shape[1])) + for i in range(positions.shape[0]) + ) expected_output = np.array(range(n_fake_vertices)) actual_output = participant.set_mesh_vertices(fake_mesh_name, positions) self.assertTrue(np.array_equal(expected_output, actual_output)) def test_set_mesh_vertex(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) fake_dimension = 3 # compare to test/SolverInterface.cpp, fake_dimensions position = np.random.rand(fake_dimension) vertex_id = participant.set_mesh_vertex(fake_mesh_name, position) @@ -132,7 +165,9 @@ def test_set_mesh_vertex(self): def test_set_mesh_vertex_empty(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) fake_dimension = 0 # compare to test/SolverInterface.cpp, fake_dimensions position = np.random.rand(fake_dimension) vertex_id = participant.set_mesh_vertex(fake_mesh_name, position) @@ -140,7 +175,9 @@ def test_set_mesh_vertex_empty(self): def test_set_mesh_vertex_list(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) fake_dimension = 3 # compare to test/SolverInterface.cpp, fake_dimensions position = list(np.random.rand(fake_dimension)) vertex_id = participant.set_mesh_vertex(fake_mesh_name, position) @@ -148,14 +185,18 @@ def test_set_mesh_vertex_list(self): def test_set_mesh_vertex_empty_list(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) position = [] vertex_id = participant.set_mesh_vertex(fake_mesh_name, position) self.assertTrue(0 == vertex_id) def test_set_mesh_vertex_tuple(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) fake_dimension = 3 # compare to test/SolverInterface.cpp, fake_dimensions position = tuple(np.random.rand(fake_dimension)) vertex_id = participant.set_mesh_vertex(fake_mesh_name, position) @@ -163,14 +204,18 @@ def test_set_mesh_vertex_tuple(self): def test_set_mesh_vertex_empty_tuple(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) position = () vertex_id = participant.set_mesh_vertex(fake_mesh_name, position) self.assertTrue(0 == vertex_id) def test_get_mesh_vertex_size(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) n_fake_vertices = 3 # compare to test/SolverInterface.cpp, n_fake_vertices n_vertices = participant.get_mesh_vertex_size(fake_mesh_name) self.assertTrue(n_fake_vertices == n_vertices) @@ -178,9 +223,13 @@ def test_get_mesh_vertex_size(self): def test_read_write_block_scalar_data(self): participant = precice.Participant("test", "dummy.xml", 0, 1) write_data = np.array([3, 7, 8], dtype=np.double) - participant.write_data("FakeMesh", "FakeScalarData", np.array([0, 1, 2]), write_data) + participant.write_data( + "FakeMesh", "FakeScalarData", np.array([0, 1, 2]), write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeScalarData", np.array([0, 1, 2]), dt) + read_data = participant.read_data( + "FakeMesh", "FakeScalarData", np.array([0, 1, 2]), dt + ) self.assertTrue(np.array_equal(write_data, read_data)) def test_read_write_block_scalar_data_single_float(self): @@ -208,10 +257,14 @@ def test_read_write_block_scalar_data_non_contiguous(self): participant = precice.Participant("test", "dummy.xml", 0, 1) dummy_array = np.random.rand(3, 3) write_data = dummy_array[:, 1] - assert (write_data.flags["C_CONTIGUOUS"] is False) - participant.write_data("FakeMesh", "FakeScalarData", np.array([0, 1, 2]), write_data) + assert write_data.flags["C_CONTIGUOUS"] is False + participant.write_data( + "FakeMesh", "FakeScalarData", np.array([0, 1, 2]), write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeScalarData", np.array([0, 1, 2]), dt) + read_data = participant.read_data( + "FakeMesh", "FakeScalarData", np.array([0, 1, 2]), dt + ) self.assertTrue(np.array_equal(write_data, read_data)) def test_read_write_scalar_data(self): @@ -224,11 +277,14 @@ def test_read_write_scalar_data(self): def test_read_write_block_vector_data(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - write_data = np.array([[3, 7, 8], - [7, 6, 5]], dtype=np.double) - participant.write_data("FakeMesh", "FakeVectorData", np.array([0, 1]), write_data) + write_data = np.array([[3, 7, 8], [7, 6, 5]], dtype=np.double) + participant.write_data( + "FakeMesh", "FakeVectorData", np.array([0, 1]), write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeVectorData", np.array([0, 1]), dt) + read_data = participant.read_data( + "FakeMesh", "FakeVectorData", np.array([0, 1]), dt + ) self.assertTrue(np.array_equal(write_data, read_data)) def test_read_write_block_vector_data_empty(self): @@ -242,25 +298,37 @@ def test_read_write_block_vector_data_empty(self): def test_read_write_block_vector_data_list(self): participant = precice.Participant("test", "dummy.xml", 0, 1) write_data = [[3, 7, 8], [7, 6, 5]] - participant.write_data("FakeMesh", "FakeVectorData", np.array([0, 1]), write_data) + participant.write_data( + "FakeMesh", "FakeVectorData", np.array([0, 1]), write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeVectorData", np.array([0, 1]), dt) + read_data = participant.read_data( + "FakeMesh", "FakeVectorData", np.array([0, 1]), dt + ) self.assertTrue(np.array_equal(write_data, read_data)) def test_read_write_block_vector_data_tuple(self): participant = precice.Participant("test", "dummy.xml", 0, 1) write_data = ((3, 7, 8), (7, 6, 5)) - participant.write_data("FakeMesh", "FakeVectorData", np.array([0, 1]), write_data) + participant.write_data( + "FakeMesh", "FakeVectorData", np.array([0, 1]), write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeVectorData", np.array([0, 1]), dt) + read_data = participant.read_data( + "FakeMesh", "FakeVectorData", np.array([0, 1]), dt + ) self.assertTrue(np.array_equal(write_data, read_data)) def test_read_write_block_vector_data_mixed(self): participant = precice.Participant("test", "dummy.xml", 0, 1) write_data = [(3, 7, 8), (7, 6, 5)] - participant.write_data("FakeMesh", "FakeVectorData", np.array([0, 1]), write_data) + participant.write_data( + "FakeMesh", "FakeVectorData", np.array([0, 1]), write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeVectorData", np.array([0, 1]), dt) + read_data = participant.read_data( + "FakeMesh", "FakeVectorData", np.array([0, 1]), dt + ) self.assertTrue(np.array_equal(write_data, read_data)) def test_read_write_block_vector_data_non_contiguous(self): @@ -273,7 +341,7 @@ def test_read_write_block_vector_data_non_contiguous(self): size = 6 dummy_array = np.random.rand(size, 5) write_data = dummy_array[:, 1:4] - assert (write_data.flags["C_CONTIGUOUS"] is False) + assert write_data.flags["C_CONTIGUOUS"] is False vertex_ids = np.arange(size) participant.write_data("FakeMesh", "FakeVectorData", vertex_ids, write_data) dt = 1 @@ -313,7 +381,7 @@ def test_read_write_vector_data_non_contiguous(self): participant = precice.Participant("test", "dummy.xml", 0, 1) dummy_array = np.random.rand(3, 3) write_data = dummy_array[:, 1] - assert (write_data.flags["C_CONTIGUOUS"] is False) + assert write_data.flags["C_CONTIGUOUS"] is False write_data = [write_data] participant.write_data("FakeMesh", "FakeVectorData", [0], write_data) dt = 1 @@ -323,9 +391,13 @@ def test_read_write_vector_data_non_contiguous(self): def test_jit_mapping(self): participant = precice.Participant("test", "dummy.xml", 0, 1) write_data = [1, 2, 3] - participant.write_and_map_data("FakeMesh", "FakeScalarData", [0, 1, 2], write_data) + participant.write_and_map_data( + "FakeMesh", "FakeScalarData", [0, 1, 2], write_data + ) dt = 1 - read_data = participant.map_and_read_data("FakeMesh", "FakeScalarData", [0, 1, 2], dt) + read_data = participant.map_and_read_data( + "FakeMesh", "FakeScalarData", [0, 1, 2], dt + ) self.assertTrue(np.array_equal(write_data, read_data)) def test_get_version_information(self): @@ -335,14 +407,18 @@ def test_get_version_information(self): def test_set_mesh_access_region(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) fake_dimension = 3 # compare to test/SolverInterface.cpp, fake_dimensions fake_bounding_box = np.arange(fake_dimension * 2) participant.set_mesh_access_region(fake_mesh_name, fake_bounding_box) def test_get_mesh_vertex_ids_and_coordinates(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + fake_mesh_name = ( + "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name + ) n_fake_vertices = 3 # compare to test/SolverInterface.cpp, n_fake_vertices fake_dimension = 3 # compare to test/SolverInterface.cpp, fake_dimensions vertex_ids = np.arange(n_fake_vertices) @@ -351,7 +427,9 @@ def test_get_mesh_vertex_ids_and_coordinates(self): coordinates[i, 0] = i * fake_dimension coordinates[i, 1] = i * fake_dimension + 1 coordinates[i, 2] = i * fake_dimension + 2 - fake_ids, fake_coordinates = participant.get_mesh_vertex_ids_and_coordinates(fake_mesh_name) + fake_ids, fake_coordinates = participant.get_mesh_vertex_ids_and_coordinates( + fake_mesh_name + ) self.assertTrue(np.array_equal(fake_ids, vertex_ids)) self.assertTrue(np.array_equal(fake_coordinates, coordinates)) @@ -360,15 +438,24 @@ def test_requires_gradient_data_for(self): fake_bool = 0 # compare to output in test/SolverInterface.cpp fake_mesh_name = "FakeMesh" fake_data_name = "FakeName" - self.assertEqual(fake_bool, participant.requires_gradient_data_for(fake_mesh_name, fake_data_name)) + self.assertEqual( + fake_bool, + participant.requires_gradient_data_for(fake_mesh_name, fake_data_name), + ) def test_write_block_scalar_gradient_data(self): participant = precice.Participant("test", "dummy.xml", 0, 1) write_data = np.array([[0, 1, 2], [6, 7, 8], [9, 10, 11]], dtype=np.double) - participant.write_gradient_data("FakeMesh", "FakeScalarData", np.array([0, 1, 2]), write_data) + participant.write_gradient_data( + "FakeMesh", "FakeScalarData", np.array([0, 1, 2]), write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeScalarData", np.array(range(9)), dt) - self.assertTrue(np.array_equiv(np.array(write_data).flatten(), read_data.flatten())) + read_data = participant.read_data( + "FakeMesh", "FakeScalarData", np.array(range(9)), dt + ) + self.assertTrue( + np.array_equiv(np.array(write_data).flatten(), read_data.flatten()) + ) def test_write_block_scalar_gradient_data_single_float(self): participant = precice.Participant("test", "dummy.xml", 0, 1) @@ -376,9 +463,16 @@ def test_write_block_scalar_gradient_data_single_float(self): n_fake_vertices = 1 vertex_ids = np.arange(n_fake_vertices) write_data = np.random.rand(n_fake_vertices, fake_dimension) - participant.write_gradient_data("FakeMesh", "FakeScalarData", vertex_ids, write_data) + participant.write_gradient_data( + "FakeMesh", "FakeScalarData", vertex_ids, write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeScalarData", np.arange(n_fake_vertices * fake_dimension), dt) + read_data = participant.read_data( + "FakeMesh", + "FakeScalarData", + np.arange(n_fake_vertices * fake_dimension), + dt, + ) self.assertTrue(np.array_equal(write_data.flatten(), read_data)) def test_write_block_scalar_gradient_data_empty(self): @@ -387,7 +481,9 @@ def test_write_block_scalar_gradient_data_empty(self): participant.write_gradient_data("FakeMesh", "FakeScalarData", [], write_data) dt = 1 read_data = participant.read_data("FakeMesh", "FakeScalarData", [], dt) - self.assertTrue(np.array_equiv(np.array(write_data).flatten(), read_data.flatten())) + self.assertTrue( + np.array_equiv(np.array(write_data).flatten(), read_data.flatten()) + ) def test_write_block_scalar_gradient_data_non_contiguous(self): """ @@ -398,10 +494,16 @@ def test_write_block_scalar_gradient_data_non_contiguous(self): dummy_array = np.random.rand(3, 9) write_data = dummy_array[:, 3:6] assert write_data.flags["C_CONTIGUOUS"] is False - participant.write_gradient_data("FakeMesh", "FakeScalarData", np.array([0, 1, 2]), write_data) + participant.write_gradient_data( + "FakeMesh", "FakeScalarData", np.array([0, 1, 2]), write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeScalarData", np.array(range(9)), dt) - self.assertTrue(np.array_equiv(np.array(write_data).flatten(), read_data.flatten())) + read_data = participant.read_data( + "FakeMesh", "FakeScalarData", np.array(range(9)), dt + ) + self.assertTrue( + np.array_equiv(np.array(write_data).flatten(), read_data.flatten()) + ) def test_write_scalar_gradient_data(self): participant = precice.Participant("test", "dummy.xml", 0, 1) @@ -419,10 +521,16 @@ def test_write_block_vector_gradient_data(self): n_fake_vertices = 4 vertex_ids = np.arange(n_fake_vertices) write_data = np.random.rand(n_fake_vertices, fake_dimension * fake_dimension) - participant.write_gradient_data("FakeMesh", "FakeVectorData", vertex_ids, write_data) + participant.write_gradient_data( + "FakeMesh", "FakeVectorData", vertex_ids, write_data + ) dt = 1 read_data = participant.read_data( - "FakeMesh", "FakeVectorData", np.array(range(n_fake_vertices * fake_dimension)), dt) + "FakeMesh", + "FakeVectorData", + np.array(range(n_fake_vertices * fake_dimension)), + dt, + ) self.assertTrue(np.array_equiv(write_data.flatten(), read_data.flatten())) def test_write_block_vector_gradient_data_empty(self): @@ -435,27 +543,54 @@ def test_write_block_vector_gradient_data_empty(self): def test_write_block_vector_gradient_data_list(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - write_data = [[3.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 6.0, 5.0]] - participant.write_gradient_data("FakeMesh", "FakeVectorData", np.array([0, 1]), write_data) + write_data = [ + [3.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0], + [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 6.0, 5.0], + ] + participant.write_gradient_data( + "FakeMesh", "FakeVectorData", np.array([0, 1]), write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeVectorData", np.array(range(6)), dt) - self.assertTrue(np.array_equiv(np.array(write_data).flatten(), read_data.flatten())) + read_data = participant.read_data( + "FakeMesh", "FakeVectorData", np.array(range(6)), dt + ) + self.assertTrue( + np.array_equiv(np.array(write_data).flatten(), read_data.flatten()) + ) def test_write_block_vector_gradient_data_tuple(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - write_data = ((1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 3.0, 7.0, 8.0), (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 6.0, 5.0)) - participant.write_gradient_data("FakeMesh", "FakeVectorData", np.array([0, 1]), write_data) + write_data = ( + (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 3.0, 7.0, 8.0), + (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 6.0, 5.0), + ) + participant.write_gradient_data( + "FakeMesh", "FakeVectorData", np.array([0, 1]), write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeVectorData", np.array(range(6)), dt) - self.assertTrue(np.array_equiv(np.array(write_data).flatten(), read_data.flatten())) + read_data = participant.read_data( + "FakeMesh", "FakeVectorData", np.array(range(6)), dt + ) + self.assertTrue( + np.array_equiv(np.array(write_data).flatten(), read_data.flatten()) + ) def test_write_block_vector_gradient_data_mixed(self): participant = precice.Participant("test", "dummy.xml", 0, 1) - write_data = [(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 3.0, 7.0, 8.0), (4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 7.0, 6.0, 5.0)] - participant.write_gradient_data("FakeMesh", "FakeVectorData", np.array([0, 1]), write_data) + write_data = [ + (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 3.0, 7.0, 8.0), + (4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 7.0, 6.0, 5.0), + ] + participant.write_gradient_data( + "FakeMesh", "FakeVectorData", np.array([0, 1]), write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeVectorData", np.array(range(6)), dt) - self.assertTrue(np.array_equiv(np.array(write_data).flatten(), read_data.flatten())) + read_data = participant.read_data( + "FakeMesh", "FakeVectorData", np.array(range(6)), dt + ) + self.assertTrue( + np.array_equiv(np.array(write_data).flatten(), read_data.flatten()) + ) def test_write_block_vector_gradient_data_non_contiguous(self): """ @@ -467,34 +602,52 @@ def test_write_block_vector_gradient_data_non_contiguous(self): write_data = dummy_array[:, 2:11] assert write_data.flags["C_CONTIGUOUS"] is False vertex_ids = np.arange(3) - participant.write_gradient_data("FakeMesh", "FakeVectorData", vertex_ids, write_data) + participant.write_gradient_data( + "FakeMesh", "FakeVectorData", vertex_ids, write_data + ) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeVectorData", np.array(range(9)), dt) - self.assertTrue(np.array_equiv(np.array(write_data).flatten(), read_data.flatten())) + read_data = participant.read_data( + "FakeMesh", "FakeVectorData", np.array(range(9)), dt + ) + self.assertTrue( + np.array_equiv(np.array(write_data).flatten(), read_data.flatten()) + ) def test_write_vector_gradient_data(self): participant = precice.Participant("test", "dummy.xml", 0, 1) write_data = [np.arange(0, 9, dtype=np.double)] participant.write_gradient_data("FakeMesh", "FakeVectorData", [0], write_data) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeVectorData", np.array(range(3)), dt) - self.assertTrue(np.array_equiv(np.array(write_data).flatten(), read_data.flatten())) + read_data = participant.read_data( + "FakeMesh", "FakeVectorData", np.array(range(3)), dt + ) + self.assertTrue( + np.array_equiv(np.array(write_data).flatten(), read_data.flatten()) + ) def test_write_vector_gradient_data_list(self): participant = precice.Participant("test", "dummy.xml", 0, 1) write_data = [[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]] participant.write_gradient_data("FakeMesh", "FakeVectorData", [0], write_data) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeVectorData", np.array(range(3)), dt) - self.assertTrue(np.array_equiv(np.array(write_data).flatten(), read_data.flatten())) + read_data = participant.read_data( + "FakeMesh", "FakeVectorData", np.array(range(3)), dt + ) + self.assertTrue( + np.array_equiv(np.array(write_data).flatten(), read_data.flatten()) + ) def test_write_vector_gradient_data_tuple(self): participant = precice.Participant("test", "dummy.xml", 0, 1) write_data = [(1.0, 2.0, 3.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0)] participant.write_gradient_data("FakeMesh", "FakeVectorData", [0], write_data) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeVectorData", np.array(range(3)), dt) - self.assertTrue(np.array_equiv(np.array(write_data).flatten(), read_data.flatten())) + read_data = participant.read_data( + "FakeMesh", "FakeVectorData", np.array(range(3)), dt + ) + self.assertTrue( + np.array_equiv(np.array(write_data).flatten(), read_data.flatten()) + ) def test_write_vector_gradient_data_non_contiguous(self): """ @@ -508,5 +661,9 @@ def test_write_vector_gradient_data_non_contiguous(self): write_data = [write_data] participant.write_gradient_data("FakeMesh", "FakeVectorData", [0], write_data) dt = 1 - read_data = participant.read_data("FakeMesh", "FakeVectorData", np.array(range(3)), dt) - self.assertTrue(np.array_equiv(np.array(write_data).flatten(), read_data.flatten())) + read_data = participant.read_data( + "FakeMesh", "FakeVectorData", np.array(range(3)), dt + ) + self.assertTrue( + np.array_equiv(np.array(write_data).flatten(), read_data.flatten()) + )