Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 2 additions & 40 deletions co_sim_io/c/co_sim_io_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ CoSimIO_Info CoSimIO_ExportData(
return ConvertInfo(CoSimIO::ExportData(ConvertInfo(I_Info), *p_container));
}

CoSimIO_Info CoSimIO_ImportMeshNEW(
CoSimIO_Info CoSimIO_ImportMesh(
const CoSimIO_Info I_Info,
CoSimIO_ModelPart O_ModelPart)
{
Expand All @@ -77,7 +77,7 @@ CoSimIO_Info CoSimIO_ImportMeshNEW(
return ConvertInfo(CoSimIO::ImportMesh(ConvertInfo(I_Info), cpp_model_part));
}

CoSimIO_Info CoSimIO_ExportMeshNEW(
CoSimIO_Info CoSimIO_ExportMesh(
const CoSimIO_Info I_Info,
const CoSimIO_ModelPart I_ModelPart)
{
Expand All @@ -86,44 +86,6 @@ CoSimIO_Info CoSimIO_ExportMeshNEW(
return ConvertInfo(CoSimIO::ExportMesh(ConvertInfo(I_Info), cpp_model_part));
}

CoSimIO_Info CoSimIO_ImportMesh(
const CoSimIO_Info I_Info,
int* I_NumberOfNodes,
int* I_NumberOfElements,
int* I_NumberOfElementConnectivities,
double** I_NodalCoordinates,
int** I_ElementConnectivities,
int** I_ElementTypes)
{
using namespace CoSimIO::Internals;
constexpr int coordinates_per_node = 3;
std::unique_ptr<DataContainer<double>> p_container_coords(new DataContainerRawMemory<double>(I_NodalCoordinates, *I_NumberOfNodes));
std::unique_ptr<DataContainer<int>> p_container_conn(new DataContainerRawMemory<int>(I_ElementConnectivities, *I_NumberOfElementConnectivities));
std::unique_ptr<DataContainer<int>> p_container_types(new DataContainerRawMemory<int>(I_ElementTypes, *I_NumberOfElements));
auto info = ConvertInfo(CoSimIO::ImportMesh(ConvertInfo(I_Info), *p_container_coords, *p_container_conn, *p_container_types));
*I_NumberOfNodes = static_cast<int>(p_container_coords->size()) / coordinates_per_node;
*I_NumberOfElementConnectivities = static_cast<int>(p_container_conn->size());
*I_NumberOfElements = static_cast<int>(p_container_types->size());
return info;
}

CoSimIO_Info CoSimIO_ExportMesh(
const CoSimIO_Info I_Info,
const int O_NumberOfNodes,
const int O_NumberOfElements,
const int O_NumberOfElementConnectivities,
const double* O_NodalCoordinates,
const int* O_ElementConnectivities,
const int* O_ElementTypes)
{
using namespace CoSimIO::Internals;
constexpr int coordinates_per_node = 3;
std::unique_ptr<DataContainer<double>> p_container_coords(new DataContainerRawMemoryReadOnly<double>(O_NodalCoordinates, O_NumberOfNodes * coordinates_per_node));
std::unique_ptr<DataContainer<int>> p_container_conn(new DataContainerRawMemoryReadOnly<int>(O_ElementConnectivities, O_NumberOfElementConnectivities));
std::unique_ptr<DataContainer<int>> p_container_types(new DataContainerRawMemoryReadOnly<int>(O_ElementTypes, O_NumberOfElements));
return ConvertInfo(CoSimIO::ExportMesh(ConvertInfo(I_Info), *p_container_coords, *p_container_conn, *p_container_types));
}

void CoSimIO_PrintInfo(FILE *Stream,
const CoSimIO_Info I_Info)
{
Expand Down
22 changes: 2 additions & 20 deletions co_sim_io/c/co_sim_io_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,13 @@ CoSimIO_Info CoSimIO_ExportData(
const int I_Size,
const double* I_Data);

CoSimIO_Info CoSimIO_ImportMeshNEW(
const CoSimIO_Info I_Info,
CoSimIO_ModelPart O_ModelPart);

CoSimIO_Info CoSimIO_ExportMeshNEW(
const CoSimIO_Info I_Info,
const CoSimIO_ModelPart I_ModelPart);

CoSimIO_Info CoSimIO_ImportMesh(
const CoSimIO_Info I_Info,
int* I_NumberOfNodes,
int* I_NumberOfElements,
int* I_NumberOfElementConnectivities,
double** I_NodalCoordinates,
int** I_ElementConnectivities,
int** I_ElementTypes);
CoSimIO_ModelPart O_ModelPart);

CoSimIO_Info CoSimIO_ExportMesh(
const CoSimIO_Info I_Info,
const int O_NumberOfNodes,
const int O_NumberOfElements,
const int O_NumberOfElementConnectivities,
const double* O_NodalCoordinates,
const int* O_ElementConnectivities,
const int* O_ElementTypes);
const CoSimIO_ModelPart I_ModelPart);


void CoSimIO_PrintInfo(FILE *Stream,
Expand Down
15 changes: 0 additions & 15 deletions co_sim_io/co_sim_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,6 @@ inline Info ExportMesh(
const Info& I_Info,
const ModelPart& I_ModelPart);

template<class TDoubleContainerType, class TIntContainerType>
inline Info ImportMesh(
const Info& I_Info,
TDoubleContainerType& rNodalCoordinates,
TIntContainerType& rElementConnectivities,
TIntContainerType& rElementTypes);

template<class TDoubleContainerType, class TIntContainerType>
inline Info ExportMesh(
const Info& I_Info,
const TDoubleContainerType& rNodalCoordinates,
const TIntContainerType& rElementConnectivities,
const TIntContainerType& rElementTypes);


inline Info ImportInfo(
const Info& I_Info);

Expand Down
26 changes: 0 additions & 26 deletions co_sim_io/impl/co_sim_io_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,32 +161,6 @@ inline Info ExportMesh(
return CoSimIO::Internals::GetConnection(connection_name).ExportMesh(I_Info, I_ModelPart);
}

template<>
inline Info ImportMesh(
const Info& I_Info,
CoSimIO::Internals::DataContainer<double>& rNodalCoordinates,
CoSimIO::Internals::DataContainer<int>& rElementConnectivities,
CoSimIO::Internals::DataContainer<int>& rElementTypes)
{
const std::string connection_name = I_Info.Get<std::string>("connection_name");
const std::string identifier = I_Info.Get<std::string>("identifier");
// TODO maybe pass the Info into the function (only changes under the hood necessary)
return Internals::GetConnection(connection_name).ImportMesh(identifier, rNodalCoordinates, rElementConnectivities, rElementTypes);
}

template<>
inline Info ExportMesh(
const Info& I_Info,
const CoSimIO::Internals::DataContainer<double>& rNodalCoordinates,
const CoSimIO::Internals::DataContainer<int>& rElementConnectivities,
const CoSimIO::Internals::DataContainer<int>& rElementTypes)
{
const std::string connection_name = I_Info.Get<std::string>("connection_name");
const std::string identifier = I_Info.Get<std::string>("identifier");
// TODO maybe pass the Info into the function (only changes under the hood necessary)
return Internals::GetConnection(connection_name).ExportMesh(identifier, rNodalCoordinates, rElementConnectivities, rElementTypes);
}

inline Info ImportInfo(
const Info& I_Info)
{
Expand Down
19 changes: 0 additions & 19 deletions co_sim_io/impl/communication/communication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,25 +205,6 @@ class Communication
CO_SIM_IO_ERROR << "ExportMeshImpl not implemented for this comm-type!" << std::endl;
return Info();
}

// old interface, functions need to be removed before release
virtual /*[[deprecated]]*/ Info ImportMeshImpl(
const std::string& rIdentifier,
CoSimIO::Internals::DataContainer<double>& rNodalCoordinates,
CoSimIO::Internals::DataContainer<int>& rElementConnectivities,
CoSimIO::Internals::DataContainer<int>& rElementTypes)
{
CO_SIM_IO_ERROR << "ImportDataImpl not implemented for this comm-type!" << std::endl;
}

virtual /*[[deprecated]]*/ Info ExportMeshImpl(
const std::string& rIdentifier,
const CoSimIO::Internals::DataContainer<double>& rNodalCoordinates,
const CoSimIO::Internals::DataContainer<int>& rElementConnectivities,
const CoSimIO::Internals::DataContainer<int>& rElementTypes)
{
CO_SIM_IO_ERROR << "ImportDataImpl not implemented for this comm-type!" << std::endl;
}
};

} // namespace Internals
Expand Down
197 changes: 0 additions & 197 deletions co_sim_io/impl/communication/file_communication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,6 @@ static void CheckStream(const T& rStream, const fs::path& rPath)
CO_SIM_IO_ERROR_IF_NOT(rStream.is_open()) << rPath << " could not be opened!" << std::endl;
}

/*deprecated*/static int GetNumNodesForVtkCellType(const int VtkCellType)
{
const std::unordered_map<int, int> vtk_cell_type_map {
{ /*Point3D, */ 1 , 1},
{ /*Line3D2, */ 3 , 2},
{ /*Triangle3D3, */ 5 , 3},
{ /*Quadrilateral3D4, */ 9 , 4},
{ /*Tetrahedra3D4, */ 10 , 4},
{ /*Hexahedra3D8, */ 12 , 8},
{ /*Prism3D6, */ 13 , 6},
{ /*Line3D3, */ 21 , 3},
{ /*Triangle3D6, */ 22 , 6},
{ /*Quadrilateral3D8, */ 23 , 7},
{ /*Tetrahedra3D10, */ 24, 10}
};

if (vtk_cell_type_map.count(VtkCellType) > 0) {
return vtk_cell_type_map.at(VtkCellType);
} else {
CO_SIM_IO_ERROR << "Unsupported cell type: " << VtkCellType << std::endl;
return 0;
}
}

} // helpers namespace


Expand Down Expand Up @@ -523,179 +499,6 @@ class FileCommunication : public Communication
return Info(); // TODO use
}

Info ImportMeshImpl(
const std::string& rIdentifier,
CoSimIO::Internals::DataContainer<double>& rNodalCoordinates,
CoSimIO::Internals::DataContainer<int>& rElementConnectivities,
CoSimIO::Internals::DataContainer<int>& rElementTypes) override
{
const std::string file_name(GetFullPath("CoSimIO_mesh_" + GetConnectionName() + "_" + rIdentifier + ".vtk"));

CO_SIM_IO_INFO_IF("CoSimIO", GetEchoLevel()>1) << "Attempting to receive mesh \"" << rIdentifier << "\" in file \"" << file_name << "\" ..." << std::endl;

WaitForPath(file_name);

const auto start_time(std::chrono::steady_clock::now());

std::ifstream input_file(file_name);
CheckStream(input_file, file_name);

// reading file
std::string current_line;
bool nodes_read = false;
bool cells_read = false;

while (std::getline(input_file, current_line)) {
// reading nodes
if (current_line.find("POINTS") != std::string::npos) {
CO_SIM_IO_ERROR_IF(nodes_read) << "The nodes were read already!" << std::endl;
CO_SIM_IO_ERROR_IF(cells_read) << "The cells were read already!" << std::endl;
nodes_read = true;

int num_nodes;
current_line = current_line.substr(current_line.find("POINTS") + 7); // removing "POINTS"
std::istringstream line_stream(current_line);
line_stream >> num_nodes;

CO_SIM_IO_INFO_IF("CoSimIO", GetEchoLevel()>1) << "Mesh contains " << num_nodes << " Nodes" << std::endl;

rNodalCoordinates.resize(3*num_nodes);

for (int i=0; i<num_nodes*3; ++i) {
input_file >> rNodalCoordinates[i];
}
}

// reading cells
if (current_line.find("CELLS") != std::string::npos) {
CO_SIM_IO_ERROR_IF_NOT(nodes_read) << "The nodes were not yet read!" << std::endl;
CO_SIM_IO_ERROR_IF(cells_read) << "The cells were read already!" << std::endl;
cells_read = true;

int num_nodes_per_cell, num_cells, elem_conn, cell_list_size;
current_line = current_line.substr(current_line.find("CELLS") + 6); // removing "CELLS"
std::istringstream line_stream(current_line);
line_stream >> num_cells;
line_stream >> cell_list_size;

rElementConnectivities.resize(cell_list_size-num_cells); // the first in number in each line is the number of connectivities, which is not needed bcs it can be derived form the elements-type
rElementTypes.resize(num_cells);

CO_SIM_IO_INFO_IF("CoSimIO", GetEchoLevel()>1) << "Mesh contains " << num_cells << " Elements" << std::endl;

int counter=0;
for (int i=0; i<num_cells; ++i) {
input_file >> num_nodes_per_cell;
for (int j=0; j<num_nodes_per_cell; ++j) {
input_file >> elem_conn;
rElementConnectivities[counter++] = elem_conn;
}
}
}

// reading cell types
if (current_line.find("CELL_TYPES") != std::string::npos) {
CO_SIM_IO_ERROR_IF_NOT(nodes_read) << "The nodes were not yet read!" << std::endl;
CO_SIM_IO_ERROR_IF_NOT(cells_read) << "The cells were not yet read!" << std::endl;

for (std::size_t i=0; i<rElementTypes.size(); ++i) { // rElementTypes was resized to correct size above
input_file >> rElementTypes[i];
}

}
}

input_file.close();
RemovePath(file_name);

CO_SIM_IO_INFO_IF("CoSimIO", GetEchoLevel()>1) << "Finished receiving mesh" << std::endl;

CO_SIM_IO_INFO_IF("CoSimIO", GetPrintTiming()) << "Receiving Mesh \"" << file_name << "\" took: " << ElapsedSeconds(start_time) << " [sec]" << std::endl;

return Info();
}

Info ExportMeshImpl(
const std::string& rIdentifier,
const CoSimIO::Internals::DataContainer<double>& rNodalCoordinates,
const CoSimIO::Internals::DataContainer<int>& rElementConnectivities,
const CoSimIO::Internals::DataContainer<int>& rElementTypes) override
{
const std::string file_name(GetFullPath("CoSimIO_mesh_" + GetConnectionName() + "_" + rIdentifier + ".vtk"));

WaitUntilFileIsRemoved(file_name); // TODO maybe this can be queued somehow ... => then it would not block the sender

const std::size_t num_nodes = rNodalCoordinates.size()/3;
const std::size_t num_elems = rElementTypes.size();

CO_SIM_IO_INFO_IF("CoSimIO", GetEchoLevel()>1) << "Attempting to send mesh \"" << rIdentifier << "\" with " << num_nodes << " Nodes | " << num_elems << " Elements in file \"" << file_name << "\" ..." << std::endl;

const auto start_time(std::chrono::steady_clock::now());

std::ofstream output_file;
output_file.open(GetTempFileName(file_name));
CheckStream(output_file, file_name);

output_file << std::scientific << std::setprecision(7); // TODO maybe this should be configurable

// write file header
output_file << "# vtk DataFile Version 4.0\n";
output_file << "vtk output\n";
output_file << "ASCII\n";
output_file << "DATASET UNSTRUCTURED_GRID\n\n";

// write nodes
output_file << "POINTS " << num_nodes << " float\n";
for (std::size_t i=0; i<num_nodes; ++i) {
output_file << rNodalCoordinates[i*3] << " " << rNodalCoordinates[i*3+1] << " " << rNodalCoordinates[i*3+2] << "\n";
}
output_file << "\n";

// get connectivity information
std::size_t cell_list_size = 0;
std::size_t counter = 0;
int connectivities_offset = std::numeric_limits<int>::max(); //in paraview the connectivities start from 0, hence we have to check beforehand what is the connectivities offset
for (std::size_t i=0; i<num_elems; ++i) {
const std::size_t num_nodes_cell = GetNumNodesForVtkCellType(rElementTypes[i]);
cell_list_size += num_nodes_cell + 1; // +1 for size of connectivity
for (std::size_t j=0; j<num_nodes_cell; ++j) {
connectivities_offset = std::min(connectivities_offset, rElementConnectivities[counter++]);
}
}

CO_SIM_IO_ERROR_IF(num_elems > 0 && connectivities_offset != 0) << "Connectivities have an offset of " << connectivities_offset << " which is not allowed!" << std::endl;

// write cells connectivity
counter = 0;
output_file << "CELLS " << num_elems << " " << cell_list_size << "\n";
for (std::size_t i=0; i<num_elems; ++i) {
const std::size_t num_nodes_cell = GetNumNodesForVtkCellType(rElementTypes[i]);
output_file << num_nodes_cell << " ";
for (std::size_t j=0; j<num_nodes_cell; ++j) {
output_file << (rElementConnectivities[counter++]-connectivities_offset);
if (j<num_nodes_cell-1) output_file << " "; // not adding a whitespace after last number
}
output_file << "\n";
}

output_file << "\n";

// write cell types
output_file << "CELL_TYPES " << num_elems << "\n";
for (std::size_t i=0; i<num_elems; ++i) {
output_file << rElementTypes[i] << "\n";
}

output_file.close();
MakeFileVisible(file_name);

CO_SIM_IO_INFO_IF("CoSimIO", GetEchoLevel()>1) << "Finished sending mesh" << std::endl;

CO_SIM_IO_INFO_IF("CoSimIO", GetPrintTiming()) << "Sending Mesh \"" << rIdentifier << "\" took: " << ElapsedSeconds(start_time) << " [sec]" << std::endl;

return Info();
}

std::string GetTempFileName(const std::string& rFileName) const
{
if (mCommInFolder) {
Expand Down
Loading