Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "topology/Topology.h"
00008 #include <iostream>
00009 #include <fstream>
00010 #include <stdio.h>
00011 #include <string>
00012 #include <sstream>
00013
00014 typedef stk::mesh::Entity Entity;
00015
00016 #include <boost/numeric/ublas/matrix.hpp>
00017 #include <boost/numeric/ublas/io.hpp>
00018 #include <boost/numeric/ublas/matrix_proxy.hpp>
00019 #include <boost/numeric/ublas/vector.hpp>
00020 #include <boost/numeric/ublas/matrix_sparse.hpp>
00021
00022
00023
00024 std::string itoa(int num);
00025
00026
00027 int main (int ac, char* av[]){
00028
00029
00030 std::string input_file;
00031 std::string normals_file;
00032 typedef stk::mesh::Entity Entity;
00033 std::string output_file;
00034
00035 using namespace std;
00036
00037 if (ac == 3){
00038
00039 std::cout << "Generating .msh boundary files with mesh " << av[1] << " and normals from file: " << av[2] << std::endl;
00040 stringstream ss1;
00041 stringstream ss2;
00042 ss1 << av[1];
00043 ss1 >> input_file;
00044 ss2 << av[2];
00045 ss2 >> normals_file;
00046
00047
00048 string s2 = ".txt";
00049 if (normals_file.find(s2) == std::string::npos) {
00050 std::cout << "Missing extension .txt for the third input" << '\n';
00051 throw(0);
00052 }
00053 }
00054 else {
00055 std::cout << "Usage:BoundarySurfaceOutput Mesh.exo Normals.txt" << std::endl;
00056 return 1;
00057 }
00058
00059
00060
00061
00062
00063 Teuchos::GlobalMPISession mpiSession(&ac, &av);
00064 LCM::Topology topology(input_file, output_file);
00065
00066
00067
00068
00069
00070 stringstream ss;
00071 std::string file_name_;
00072 ss << av[1];
00073 ss >> file_name_;
00074 string exoFile = ".exo";
00075 std::size_t Position = file_name_.find(exoFile);
00076 std::string file_name2 = file_name_.substr(0, Position);
00077
00078
00079
00080
00081
00082
00083 ifstream normals_(normals_file.c_str());
00084
00085
00086
00087 int numberNormals_;
00088 if (normals_.is_open())
00089 {
00090 normals_ >> numberNormals_;
00091 }
00092
00093
00094 std::vector<std::vector<double> > mNormals(numberNormals_,std::vector<double>(3,0));
00095
00096 if (normals_.is_open())
00097 {
00098 for (int i = 0; i < numberNormals_ ; i++)
00099 {
00100 normals_ >> mNormals[i][0] >> mNormals[i][1]>> mNormals[i][2];
00101 }
00102 }
00103
00104
00105 std::vector<std::vector<int> >BoundaryVector;
00106 for(int i = 0; i < numberNormals_; i++)
00107 {
00108 std::string file_name = "Boundary_"+file_name2+"_"+itoa(i+1) + ".msh";
00109
00110 ofstream mshFile(file_name.c_str(),std::ofstream::out);
00111 if ( mshFile.is_open())
00112 {
00113
00114 std::vector<std::vector<int> >BoundaryVector;
00115
00116 std::vector<double> normalToPlane;
00117 normalToPlane.push_back(mNormals.at(i).at(0));
00118 normalToPlane.push_back(mNormals.at(i).at(1));
00119 normalToPlane.push_back(mNormals.at(i).at(2));
00120
00121
00122 std::vector<std::vector<double> > pointsOnPlane = topology.getCoordinatesOfTriangle(normalToPlane);
00123
00124
00125
00126 std::vector<Entity*> closestNodes = topology.getClosestNodesOnSurface(pointsOnPlane);
00127
00128
00129
00130 std::vector<std::vector<int> > ShortestPathFinal = topology.shortestpath(closestNodes);
00131
00132
00133
00134 std::vector<int> nodesIdentifiers;
00135 for (unsigned int i = 0; i < ShortestPathFinal.size(); ++i){
00136 for (unsigned int j = 0; j < ShortestPathFinal[i].size()-1; ++j){
00137 nodesIdentifiers.push_back((ShortestPathFinal[i][j]));
00138 nodesIdentifiers.push_back((ShortestPathFinal[i][j+1]));
00139 }
00140 }
00141
00142
00143 std::vector<int> setOfNodes;
00144 std::vector<int>::const_iterator iteratorInt;
00145 for(unsigned int i =0; i<nodesIdentifiers.size(); i = i+2)
00146 {
00147 setOfNodes.push_back(nodesIdentifiers[i]);
00148 }
00149
00150 int dimension = 3;
00151 int NumNodesPerElement = 2;
00152
00153 mshFile << dimension <<" "<< NumNodesPerElement << endl;
00154 mshFile << setOfNodes.size() <<" "<< ShortestPathFinal.size() <<endl;
00155
00156
00157 std::map <int,int> node_map; int counter = 0;
00158 std::vector<int>::const_iterator I_setOfNodes;
00159
00160 for(I_setOfNodes = setOfNodes.begin();I_setOfNodes != setOfNodes.end();++I_setOfNodes)
00161 {
00162 std::vector<double> nodeCoordinates = topology.findCoordinates(*I_setOfNodes);
00163 mshFile << nodeCoordinates[0]<<" "<< nodeCoordinates[1]<<" "<<nodeCoordinates[2] << endl;
00164 node_map[*I_setOfNodes] = counter;
00165
00166 counter++;
00167 }
00168
00169
00170 for (unsigned int i = 0; i < ShortestPathFinal.size(); ++i){
00171 for (unsigned int j = 0; j < ShortestPathFinal[i].size(); ++j){
00172 mshFile << (node_map.find(ShortestPathFinal[i][j])->second)+1 << " ";
00173 }
00174 mshFile << endl;
00175 }
00176
00177 }
00178 }
00179
00180 return 0;
00181 }
00182
00183
00184 std::string itoa(int num) {
00185 std::stringstream converter;
00186 converter << num;
00187 return converter.str();
00188 }
00189