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 std::string input_file;
00030 std::string normals_file;
00031 typedef stk::mesh::Entity Entity;
00032 std::string output_file;
00033
00034 using namespace std;
00035
00036
00037 if(ac == 2) {
00038 std::cout << "Generating MPS header file with mesh " << av[1] << std::endl;
00039 stringstream ss;
00040 ss << av[1];
00041 ss >> input_file;
00042
00043 } else if (ac == 3){
00044 std::cout << "Generating MPS rhs files with mesh " << av[1] << " and normals from file: " << av[2] << std::endl;
00045 stringstream ss1;
00046 stringstream ss2;
00047 ss1 << av[1];
00048 ss1 >> input_file;
00049 ss2 << av[2];
00050 ss2 >> normals_file;
00051
00052
00053 string s2 = ".txt";
00054 if (normals_file.find(s2) == std::string::npos) {
00055 std::cout << "Missing extension .txt for the third input" << '\n';
00056 throw(0);
00057 }
00058 } else {
00059 std::cout << "Usage: MinsurfaceMPS Mesh.exo or MinsurfaceMPS Mesh.exo Normals.txt" << std::endl;
00060 return 1;
00061 }
00062
00063
00064
00065
00066
00067 Teuchos::GlobalMPISession mpiSession(&ac, &av);
00068 LCM::Topology topology(input_file, output_file);
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 stringstream ss;
00083 std::string file_name_;
00084 ss << av[1];
00085 ss >> file_name_;
00086 string exoFile = ".exo";
00087 std::size_t Position = file_name_.find(exoFile);
00088
00089
00090
00091 std::string file_name1 = "MPS_"+file_name_.substr(0, Position)+"_header.txt";
00092 std::string file_name2 = file_name_.substr(0, Position);
00093
00094
00095 if (ac == 2)
00096 {
00097 ofstream mpsFile(file_name1.c_str(),std::ofstream::out);
00098 if (mpsFile.is_open())
00099 {
00100
00101 mpsFile << "NAME" <<" "<< "MPS_"<<file_name2<<"_" <<endl;
00102 mpsFile << "ROWS" <<endl;
00103 mpsFile <<" "<<"N"<<" "<<"Z"<<endl;
00104
00105
00106 std::vector<std::vector<int> > edgesDirec = topology.edgesDirections();
00107 for (unsigned int i = 0; i< edgesDirec.size();i++)
00108 {
00109 mpsFile<<" "<<"E"<<" "<<"R"<<i+1<<endl;
00110 }
00111
00112 mpsFile << "COLUMNS" <<endl;
00113
00114 std::vector<std::vector<double> > outputForMpsFile = topology.outputForMpsFile();
00115 for (unsigned int i = 0; i < outputForMpsFile.size(); i+=4)
00116 {
00117
00118 mpsFile <<" "<<"X"<<outputForMpsFile[i+1][0]<<" "<<"Z"<<" "<<setprecision(numeric_limits<long double>::digits10)<<outputForMpsFile[i][0]<<endl;
00119 mpsFile <<" "<<"X"<<outputForMpsFile[i+1][0]<<" "<<"R"<<outputForMpsFile[i+1][1]<<" "<<outputForMpsFile[i+1][2]<<endl;
00120 mpsFile <<" "<<"X"<<outputForMpsFile[i+2][0]<<" "<<"R"<<outputForMpsFile[i+2][1]<<" "<<outputForMpsFile[i+2][2]<<endl;
00121 mpsFile <<" "<<"X"<<outputForMpsFile[i+3][0]<<" "<<"R"<<outputForMpsFile[i+3][1]<<" "<<outputForMpsFile[i+3][2]<<endl;
00122 mpsFile <<" "<<"X"<<outputForMpsFile[i+1][3]<<" "<<"Z"<<" "<<setprecision(numeric_limits<long double>::digits10)<<outputForMpsFile[i][0]<<endl;
00123 mpsFile <<" "<<"X"<<outputForMpsFile[i+1][3]<<" "<<"R"<<outputForMpsFile[i+1][4]<<" "<<outputForMpsFile[i+1][5]<<endl;
00124 mpsFile <<" "<<"X"<<outputForMpsFile[i+2][3]<<" "<<"R"<<outputForMpsFile[i+2][4]<<" "<<outputForMpsFile[i+2][5]<<endl;
00125 mpsFile <<" "<<"X"<<outputForMpsFile[i+3][3]<<" "<<"R"<<outputForMpsFile[i+3][4]<<" "<<outputForMpsFile[i+3][5]<<endl;
00126 }
00127 }
00128 }
00129
00130
00131
00132 else
00133 {
00134 ifstream normals_(normals_file.c_str());
00135 int numberNormals_;
00136 if (normals_.is_open())
00137 {
00138 normals_ >> numberNormals_;
00139 }
00140
00141
00142 std::vector<std::vector<double> > mNormals(numberNormals_,std::vector<double>(3,0));
00143
00144 if (normals_.is_open())
00145 {
00146 for (int i = 0; i < numberNormals_ ; i++)
00147 {
00148 normals_ >> mNormals[i][0] >> mNormals[i][1]>> mNormals[i][2];
00149 }
00150 }
00151
00152
00153 std::vector<std::vector<int> >BoundaryVector;
00154 for(int i = 0; i < numberNormals_; i++)
00155 {
00156 std::string file_name = "MPS_"+file_name2+"_rhs_" + itoa(i+1) + ".txt";
00157
00158 ofstream mpsFile(file_name.c_str(),std::ofstream::out);
00159 if (mpsFile.is_open())
00160 {
00161 mpsFile <<"RHS"<<endl;
00162
00163
00164 std::vector<std::vector<int> >BoundaryVector;
00165
00166 std::vector<double> normalToPlane;
00167 normalToPlane.push_back(mNormals.at(i).at(0));
00168 normalToPlane.push_back(mNormals.at(i).at(1));
00169 normalToPlane.push_back(mNormals.at(i).at(2));
00170
00171
00172 std::vector<std::vector<double> > pointsOnPlane = topology.getCoordinatesOfTriangle(normalToPlane);
00173
00174
00175
00176 std::vector<Entity*> closestNodes = topology.getClosestNodesOnSurface(pointsOnPlane);
00177
00178
00179
00180 std::vector<std::vector<int> > ShortestPathFinal = topology.shortestpath(closestNodes);
00181 BoundaryVector = topology.boundaryVector(ShortestPathFinal);
00182 for (unsigned int i =0; i < BoundaryVector.size();i++)
00183 {
00184 mpsFile <<" "<<"RHS1"<<" "<<"R"<<BoundaryVector[i][0]<<" "<<BoundaryVector[i][1]<<endl;
00185 }
00186
00187
00188 mpsFile << "BOUNDS"<<endl;
00189 mpsFile << "ENDATA"<<endl;
00190 }
00191 }
00192 }
00193 return 0;
00194 }
00195
00196
00197 std::string itoa(int num) {
00198 std::stringstream converter;
00199 converter << num;
00200 return converter.str();
00201 }
00202