File: writetochnog.cpp

package info (click to toggle)
netgen 6.2.2601%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,076 kB
  • sloc: cpp: 166,627; tcl: 6,310; python: 2,868; sh: 528; makefile: 90
file content (109 lines) | stat: -rw-r--r-- 2,283 bytes parent folder | download | duplicates (2)
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
//
//  Write Tochnog file
//
//  by
//
//  Andreas Seltmann
//  email:  A.Seltmann@lsw.uni-heidelberg.de
//
#include <mystdlib.h>

#include <myadt.hpp>
#include <linalg.hpp>
#include <csg.hpp>
#include <meshing.hpp>

#include "writeuser.hpp"

namespace netgen
{


void WriteTochnogFormat (const Mesh & mesh,
			 const filesystem::path & filename)
{
  cout << "\nWrite Tochnog Volume Mesh" << endl;

  ofstream outfile (filename);

  outfile << "(Nodes and Elements generated with NETGEN" << endl;
  outfile << " " << filename << ")" << endl;

  outfile.precision(8);

  outfile << "(Nodes)" << endl;

  int np = mesh.GetNP();
  int ne = mesh.GetNE();
  int i, j;

  for (i = 1; i <= np; i++)
    {
      outfile << "node " << " " << i << " ";
      outfile << mesh.Point(i)(0) << " ";
      outfile << mesh.Point(i)(1) << " ";
      outfile << mesh.Point(i)(2) << "\n";
    }

  int elemcnt = 0; //element counter
  int finished = 0;
  int indcnt = 1; //index counter

  while (!finished)
    {
      int actcnt = 0;
      const Element & el1 = mesh.VolumeElement(1);
      int non = el1.GetNP();
      if (non == 4)
	{
	  outfile << "(Elements, type=-tet4)" << endl;
	} 
      else
	{
	  cout << "unsupported Element type!!!" << endl;	  
	}

      for (i = 1; i <= ne; i++)
	{
	  const Element & el = mesh.VolumeElement(i);
	      
	  if (el.GetIndex() == indcnt)
	    {
	      actcnt++;
	      if (el.GetNP() != non) 
		{
		  cout << "different element-types in a subdomain are not possible!!!" << endl;
		  continue;
		}
		  
	      elemcnt++;
	      outfile << "element " << elemcnt << " -tet4 ";
	      if (non == 4)
		{
		  outfile << el.PNum(1) << " ";
		  outfile << el.PNum(2) << " ";
		  outfile << el.PNum(4) << " ";
		  outfile << el.PNum(3) << "\n";
		}
	      else
		{
		  cout << "unsupported Element type!!!" << endl;
		  for (j = 1; j <= el.GetNP(); j++)
		    {
		      outfile << el.PNum(j);
		      if (j != el.GetNP()) outfile << ", ";
		    }
		  outfile << "\n";
		}
	    }
	}	  
      indcnt++;
      if (elemcnt == ne) {finished = 1; cout << "all elements found by Index!" << endl;}
      if (actcnt == 0) {finished = 1;}
    }

  cout << "done" << endl;
}

static RegisterUserFormat reg_tochnog ("Tochnog Format", {".mesh"}, nullopt, WriteTochnogFormat);
}