mesh_file.cpp 4.48 KB
Newer Older
Kirill Terekhov's avatar
Kirill Terekhov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
#ifdef _MSC_VER //kill some warnings
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "inmost.h"

#if defined(USE_MESH)
#include <deque>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include "io.hpp"











#if defined(USE_PARALLEL_WRITE_TIME)
#define REPORT_MPI(x) {WriteTab(out_time) << "<MPI><![CDATA[" << #x << "]]></MPI>\n"; x;}
#define REPORT_STR(x) {WriteTab(out_time) << "<TEXT><![CDATA[" << x << "]]></TEXT>\n";}
#define REPORT_VAL(str,x) {WriteTab(out_time) << "<VALUE name=\"" << str << "\"> <CONTENT><![CDATA[" << x << "]]> </CONTENT><CODE><![CDATA[" << #x << "]]></CODE></VALUE>\n";}
#define ENTER_FUNC() long double all_time = Timer(); WriteTab(out_time) << "<FUNCTION name=\"" << __FUNCTION__ << "\" id=\"func" << func_id++ << "\">\n"; Enter();
#define EXIT_FUNC() WriteTab(out_time) << "<TIME>" << Timer() - all_time << "</TIME>\n"; Exit(); WriteTab(out_time) << "</FUNCTION>\n";
#else
#define REPORT_MPI(x) x
#define REPORT_STR(x) 
#define REPORT_VAL(str,x)
#define ENTER_FUNC()
#define EXIT_FUNC() 
#endif


#define GMV_HEADER 0
#define GMV_NODES 1
#define GMV

namespace INMOST
{

	

	void Mesh::SetFileOption(std::string key, std::string val)
	{
		for(INMOST_DATA_ENUM_TYPE k = 0; k < file_options.size(); k++)
		{
			if(file_options[k].first == key)
			{
				file_options[k].second = val;
			}
		}
		file_options.push_back(std::make_pair(key,val));
	}

	std::string Mesh::GetFileOption(std::string key)
	{
		for(INMOST_DATA_ENUM_TYPE k = 0; k < file_options.size(); k++)
		{
			if(file_options[k].first == key)
			{
				return file_options[k].second;
			}
		}
		return "";
	}
	
	
	void Mesh::Load(std::string File)
	{
		ENTER_FUNC();
		REPORT_VAL("File",File);
		std::string LFile;
		LFile.resize(File.size());
		std::transform(File.begin(),File.end(),LFile.begin(),::tolower);
//		long double load_timer = Timer();
		/*
		if(File.find("gmv") != std::string::npos) //this is gmv
		{
			char readline[2048];
			std::vector<File *> fs;
			fs.push_back(fopen(File.c_str(),"r"));
			if( fs[0] == NULL ) throw BadFileName;
			while( !fs.empty() )
			{
				while( fgets(readline,2048,fs[fs.size()-1]) != NULL )
				{
					switch(state)
					{
						case 
					}
				}
				fclose(fs[fs.size()-1]);
				fs.pop();
			}
		}
		else 
		*/
		if(LFile.find(".grdecl") != std::string::npos) // this is eclipse grid
		  LoadECL(File);
		else if(LFile.find(".pvtk") != std::string::npos) //this is legacy parallel vtk
		  LoadPVTK(File);
		else if(LFile.find(".vtk") != std::string::npos) //this is legacy vtk
		  LoadVTK(File);
		else if(LFile.find(".grid") != std::string::npos ) // mesh format by Mohammad Karimi-Fard
		  LoadMKF(File);
		else if(LFile.find(".msh") != std::string::npos ) // GMSH file format
		  LoadMSH(File);
Kirill Terekhov's avatar
Kirill Terekhov committed
113 114 115 116
		else if (LFile.find(".xml") != std::string::npos) //new mesh format 
			LoadXML(File);
		else if (LFile.find(".vtu") != std::string::npos)
			LoadVTU(File);
Kirill Terekhov's avatar
Kirill Terekhov committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
		else if(LFile.find(".pmf") != std::string::npos) //this is inner parallel/platform mesh format
		  LoadPMF(File);
		else throw NotImplemented;
		EXIT_FUNC();
	}
	
	void Mesh::Save(std::string File)
	{
		ENTER_FUNC();
		REPORT_VAL("File",File);
		std::string LFile;
		LFile.resize(File.size());
		std::transform(File.begin(),File.end(),LFile.begin(),::tolower);
		if(LFile.find(".pvtk") != std::string::npos) //this is legacy parallel vtk
		  SavePVTK(File);
    else if(LFile.find(".xml") != std::string::npos)
      SaveXML(File);
		else if(LFile.find(".vtk") != std::string::npos) //this is legacy vtk
		  SaveVTK(File);
		else if( LFile.find(".gmv") != std::string::npos) //this is gmv file
		  SaveGMV(File);
		else if(LFile.find(".pmf") != std::string::npos) //this is inner parallel/platform mesh format
		  SavePMF(File);
		else throw NotImplemented;	
		EXIT_FUNC();
	}
	
	bool Mesh::isParallelFileFormat(std::string File)
	{
		std::string LFile;
		LFile.resize(File.size());
		std::transform(File.begin(),File.end(),LFile.begin(),::tolower);
Kirill Terekhov's avatar
Kirill Terekhov committed
149
		if(LFile.find(".grdecl") != std::string::npos) return true;
Kirill Terekhov's avatar
Kirill Terekhov committed
150 151 152 153 154 155
		if(LFile.find(".msh") != std::string::npos) return false;
		if(LFile.find(".grid") != std::string::npos) return false;
		else if(LFile.find(".vtk") != std::string::npos) return false;
		else if(LFile.find(".gmv") != std::string::npos) return false;
		else if(LFile.find(".pvtk") != std::string::npos) return true;
		else if(LFile.find(".pmf") != std::string::npos) return true;
Kirill Terekhov's avatar
Kirill Terekhov committed
156 157
		else if(LFile.find(".xml") != std::string::npos) return true;
		else if (LFile.find(".vtu") != std::string::npos) return false;
Kirill Terekhov's avatar
Kirill Terekhov committed
158 159 160 161
		throw NotImplemented;
	}
}
#endif