-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #347 from Exawind/restart_from_file
Added restart capability for CFD Interface.
- Loading branch information
Showing
5 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include <istream> | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "state.hpp" | ||
|
||
namespace openturbine { | ||
|
||
inline void ReadStateFromFile(std::istream& input, State& state) { | ||
auto num_system_nodes = size_t{}; | ||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) | ||
input.read(reinterpret_cast<char*>(&num_system_nodes), sizeof(size_t)); | ||
|
||
if (num_system_nodes != state.num_system_nodes) { | ||
throw std::length_error("Number of system nodes in file is not the same as in model"); | ||
} | ||
|
||
auto mirror_7 = Kokkos::View<double* [7]>::HostMirror("mirror_7", num_system_nodes); | ||
auto out_7 = Kokkos::View<double* [7], Kokkos::HostSpace>("out_7", num_system_nodes); | ||
|
||
auto mirror_6 = Kokkos::View<double* [6]>::HostMirror("mirror_6", num_system_nodes); | ||
auto out_6 = Kokkos::View<double* [6], Kokkos::HostSpace>("out_6", num_system_nodes); | ||
|
||
auto read_7 = [&](const Kokkos::View<double* [7]>& data) { | ||
const auto stream_size = static_cast<long>(7U * num_system_nodes * sizeof(double)); | ||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) | ||
input.read(reinterpret_cast<char*>(out_7.data()), stream_size); | ||
|
||
Kokkos::deep_copy(mirror_7, out_7); | ||
Kokkos::deep_copy(data, mirror_7); | ||
}; | ||
|
||
auto read_6 = [&](const Kokkos::View<double* [6]>& data) { | ||
const auto stream_size = static_cast<long>(6U * num_system_nodes * sizeof(double)); | ||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) | ||
input.read(reinterpret_cast<char*>(out_6.data()), stream_size); | ||
|
||
Kokkos::deep_copy(mirror_6, out_6); | ||
Kokkos::deep_copy(data, mirror_6); | ||
}; | ||
|
||
read_7(state.x0); | ||
read_7(state.x); | ||
read_6(state.q_delta); | ||
read_7(state.q_prev); | ||
read_7(state.q); | ||
read_6(state.v); | ||
read_6(state.vd); | ||
read_6(state.a); | ||
read_6(state.f); | ||
} | ||
|
||
} // namespace openturbine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
#include <ostream> | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "state.hpp" | ||
|
||
namespace openturbine { | ||
|
||
inline void WriteStateToFile(std::ostream& output, const State& state) { | ||
auto num_system_nodes = state.num_system_nodes; | ||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) | ||
output.write(reinterpret_cast<char*>(&num_system_nodes), sizeof(size_t)); | ||
|
||
auto mirror_7 = Kokkos::View<double* [7]>::HostMirror("mirror_7", num_system_nodes); | ||
auto out_7 = Kokkos::View<double* [7], Kokkos::HostSpace>("out_7", num_system_nodes); | ||
|
||
auto mirror_6 = Kokkos::View<double* [6]>::HostMirror("mirror_6", num_system_nodes); | ||
auto out_6 = Kokkos::View<double* [6], Kokkos::HostSpace>("out_6", num_system_nodes); | ||
|
||
auto write_7 = [&](const Kokkos::View<double* [7]>& data) { | ||
Kokkos::deep_copy(mirror_7, data); | ||
Kokkos::deep_copy(out_7, mirror_7); | ||
|
||
const auto stream_size = static_cast<long>(7U * num_system_nodes * sizeof(double)); | ||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) | ||
output.write(reinterpret_cast<char*>(out_7.data()), stream_size); | ||
}; | ||
|
||
auto write_6 = [&](const Kokkos::View<double* [6]>& data) { | ||
Kokkos::deep_copy(mirror_6, data); | ||
Kokkos::deep_copy(out_6, mirror_6); | ||
|
||
const auto stream_size = static_cast<long>(6U * num_system_nodes * sizeof(double)); | ||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) | ||
output.write(reinterpret_cast<char*>(out_6.data()), stream_size); | ||
}; | ||
|
||
write_7(state.x0); | ||
write_7(state.x); | ||
write_6(state.q_delta); | ||
write_7(state.q_prev); | ||
write_7(state.q); | ||
write_6(state.v); | ||
write_6(state.vd); | ||
write_6(state.a); | ||
write_6(state.f); | ||
} | ||
|
||
} // namespace openturbine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters