|
12 | 12 | //+++ Function: finite element cell management class |
13 | 13 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | 14 |
|
| 15 | +#include <fstream> |
15 | 16 | #include "FECell/FECell.h" |
16 | 17 |
|
17 | 18 | FECell::FECell(){} |
@@ -51,6 +52,80 @@ void FECell::setMeshInfo(const int &nx,const int &ny,const int &nz, |
51 | 52 | m_CellData.Zmax=zmax; |
52 | 53 | m_CellData.BulkElmtMeshType=meshtype; |
53 | 54 | } |
| 55 | +//**************************************************** |
| 56 | +void FECell::saveFECell2VTUFile()const{ |
| 57 | + int rank; |
| 58 | + MPI_Comm_rank(MPI_COMM_WORLD,&rank); |
| 59 | + if(rank==0){ |
| 60 | + std::ofstream out; |
| 61 | + out.open("mesh.vtu",std::ios::out); |
| 62 | + if(!out.is_open()){ |
| 63 | + MessagePrinter::printErrorTxt("can\'t create/open mesh.vtu, please make sure you have the write permission"); |
| 64 | + MessagePrinter::exitAsFem(); |
| 65 | + } |
| 66 | + out << "<?xml version=\"1.0\"?>\n"; |
| 67 | + out << "<VTKFile type=\"UnstructuredGrid\" version=\"1.0\">\n"; |
| 68 | + out << "<UnstructuredGrid>\n"; |
| 69 | + out << "<Piece NumberOfPoints=\"" << m_CellData.NodesNum << "\" NumberOfCells=\"" << m_CellData.BulkElmtsNum << "\">\n"; |
| 70 | + out << "<Points>\n"; |
| 71 | + out << "<DataArray type=\"Float64\" Name=\"nodes\" NumberOfComponents=\"3\" format=\"ascii\">\n"; |
| 72 | + |
| 73 | + int i; |
| 74 | + //***************************** |
| 75 | + // print out node coordinates |
| 76 | + out <<std::scientific << std::setprecision(6); |
| 77 | + for (i = 1; i <= m_CellData.NodesNum; i++){ |
| 78 | + out << m_CellData.NodeCoords_Global[(i-1)*3+1-1] << " "; |
| 79 | + out << m_CellData.NodeCoords_Global[(i-1)*3+2-1] << " "; |
| 80 | + out << m_CellData.NodeCoords_Global[(i-1)*3+3-1] << "\n"; |
| 81 | + } |
| 82 | + out << "</DataArray>\n"; |
| 83 | + out << "</Points>\n"; |
| 84 | + |
| 85 | + //*************************************** |
| 86 | + //*** For cell information |
| 87 | + //*************************************** |
| 88 | + out << "<Cells>\n"; |
| 89 | + out << "<DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">\n"; |
| 90 | + for(const auto &cell:m_CellData.MeshCell_Total){ |
| 91 | + for(const auto &id:cell.ElmtConn){ |
| 92 | + out<<id-1<<" "; |
| 93 | + } |
| 94 | + out<<"\n"; |
| 95 | + } |
| 96 | + out << "</DataArray>\n"; |
| 97 | + |
| 98 | + //*************************************** |
| 99 | + //*** For offset |
| 100 | + //*************************************** |
| 101 | + out << "<DataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n"; |
| 102 | + int offset = 0; |
| 103 | + for(const auto &cell:m_CellData.MeshCell_Total){ |
| 104 | + offset+=cell.NodesNumPerElmt; |
| 105 | + out << offset << "\n"; |
| 106 | + } |
| 107 | + out << "</DataArray>\n"; |
| 108 | + |
| 109 | + //*************************************** |
| 110 | + //*** For vtk cell type |
| 111 | + //*************************************** |
| 112 | + out << "<DataArray type=\"Int32\" Name=\"types\" NumberOfComponents=\"1\" format=\"ascii\">\n"; |
| 113 | + for(const auto &cell:m_CellData.MeshCell_Total){ |
| 114 | + out<<cell.VTKCellType<<"\n"; |
| 115 | + } |
| 116 | + out << "</DataArray>\n"; |
| 117 | + out << "</Cells>\n"; |
| 118 | + |
| 119 | + //*************************************** |
| 120 | + //*** End of output |
| 121 | + //*************************************** |
| 122 | + out << "</Piece>\n"; |
| 123 | + out << "</UnstructuredGrid>\n"; |
| 124 | + out << "</VTKFile>" << endl; |
| 125 | + |
| 126 | + out.close(); |
| 127 | + } |
| 128 | +} |
54 | 129 | void FECell::printSummaryInfo()const{ |
55 | 130 | MessagePrinter::printStars(); |
56 | 131 | MessagePrinter::printNormalTxt("Summary information of FECell system"); |
|
0 commit comments