Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Mesh Namespace Reference

Everything mesh. More...

Functions

int GenerateCartesianGrid (Mesh::NodalCoordinates &nc, Mesh::BSExtent< Mesh::IndexType > &gridextent, std::vector< Mesh::IndexType > &gridsizes, GeoPrim::CBox &box)
 
template<typename OuterCont , typename OutCont , typename InnerCont , typename MapType >
void MapElements (OuterCont &src, OutCont &trg, MapType &m)
 
template<typename ListContainerType , typename ListType >
IndexType MaxNodeId (const ListContainerType &fc)
 Return the maximum of all elements of a multicontainer. More...
 
template<typename OuterCont , typename InnerCont , typename OutCont >
void Flatten (OuterCont &con, OutCont &ocon)
 Populate OutCont with a flat list of entries from a multicontainer. More...
 
template<typename OuterContType >
IndexType GetTotalSize (OuterContType &con)
 Return the total number of entries in a multicontainer. More...
 
template<typename OuterContType , typename InnerContType , typename RetCont , typename idxtype >
void Container2CSR (RetCont &xadj, RetCont &adj, OuterContType &source)
 
template<typename ListContainerType , typename ListType >
void CreateAdjacentNodeList (std::vector< std::list< IndexType > > &anodelist, ListContainerType &fc, IndexType nnodes=0)
 Given an array of adjacent node lists (like an array of face connectivities), this function will loop thru and create a list of unique adjacent nodes for each node with the nodes that are actually adjacent in the lists More...
 
template<typename ListContainerType , typename ListType >
void AdjEList (std::vector< std::list< IndexType > > &aelist, ListContainerType &dual_con, unsigned long nel=0)
 Given an array of adjacent node lists (like an array of face connectivities), this function will loop thru and create a list of unique adjacent nodes for each node Note that this is a little different from the AdjNodeList because in this version every node in each list is considered adjacent. More...
 
template<typename ConType , typename IConType >
IndexType NumberOfEdges (ConType &con)
 
template<typename ContainerType , typename Icont >
void FormGraph (const ContainerType &adjlist)
 
int ReadMesh (const std::string &path, Mesh::UnstructuredMesh &mesh)
 
int GetMeshCentroids (Mesh::NodalCoordinates &nc, Mesh::Connectivity &conn, std::vector< double > &centroids)
 
int CollideCellsWithBox (Mesh::NodalCoordinates &nc, Mesh::Connectivity &conn, GeoPrim::CBox &box, std::vector< Mesh::IndexType > &candidates, std::vector< Mesh::IndexType > &cells)
 
int CollideMeshWithBox (Mesh::NodalCoordinates &nc, Mesh::Connectivity &conn, GeoPrim::CBox &box, std::vector< Mesh::IndexType > &cells)
 
bool NewtonRaphson (GeoPrim::CVector &natc, IndexType elnum, const GenericElement &el, const Connectivity &ec, const NodalCoordinates &nc, const GeoPrim::CPoint &point)
 Newton-Raphson method, customized for using the GeoPrimitives and computational mesh constructs. More...
 
bool NewtonRaphson_2 (GeoPrim::CVector &natc, IndexType elnum, const GenericCell_2 &el, const Connectivity &ec, const NodalCoordinates &nc, const GeoPrim::CPoint &point)
 Newton-Raphson method, customized for using the GeoPrimitives and computational mesh constructs. More...
 
bool LUDcmp (GeoPrim::CVector a[], int indx[])
 
void LUBksb (GeoPrim::CVector a[], int indx[], GeoPrim::CVector &b)
 
void GetCoordinateBounds (NodalCoordinates &nc, std::vector< double > &)
 
void GetMeshBoxes (const NodalCoordinates &nc, const Connectivity &ec, GeoPrim::CBox &mesh_box, GeoPrim::CBox &small_box, GeoPrim::CBox &large_box)
 Bounding boxes for a mesh. More...
 
void FindElementsInBox (const GeoPrim::CBox &box, const NodalCoordinates &nc, const Connectivity &dc,std::list< IndexType > &elements)
 Get elements in box. More...
 
Mesh::IndexType FindPointInCells (const GeoPrim::CPoint &p,const NodalCoordinates &nc,const Connectivity &ec,const std::vector< Mesh::IndexType > &elements,GeoPrim::CVector &natc)
 Locate element containing given physical point. More...
 
Mesh::IndexType GlobalFindPointInMesh (const GeoPrim::CPoint &p, const NodalCoordinates &nc, const Connectivity &ec, const Connectivity &dc, const GeoPrim::CBox &box, GeoPrim::CVector &natc)
 
Mesh::IndexType FindPointInMesh_2 (const GeoPrim::CPoint &p,const NodalCoordinates &nc,const Connectivity &ec,const Connectivity &dc,const GeoPrim::CBox &box,GeoPrim::CVector &natc)
 Locate element containing given physical point. More...
 
Mesh::IndexType FindPointInMesh (const GeoPrim::CPoint &p,const NodalCoordinates &nc,const Connectivity &ec,const Connectivity &dc,const GeoPrim::CBox &box,GeoPrim::CVector &natc)
 Locate element containing given physical point. More...
 
void writeVtkData ()
 Writes the merged grid and its data in VTK UNSTRUCTURED_GRID file format. More...
 
void writeVtkFiles (std::vector< Mesh::UnstructuredMesh > &m)
 Writes the set of meshes into separate VTK files that can be visualized with Paraview. More...
 
void printVtk (std::vector< double > &vlist, std::vector< std::vector< int > > &elist)
 This method prints the global grid in VTK file format. More...
 
std::istream & operator>> (std::istream &iSt, Mesh::GeometricEntity &ge)
 
std::istream & operator>> (std::istream &iSt, Mesh::Connectivity &ec)
 
std::istream & operator>> (std::istream &iSt, Mesh::NodalCoordinates &nc)
 
std::ostream & operator<< (std::ostream &oSt, const Mesh::NodalCoordinates &nc)
 
std::ostream & operator<< (std::ostream &oSt, const Mesh::Connectivity &ec)
 
std::ostream & operator<< (std::ostream &oSt, const Mesh::GeometricEntity &ge)
 
void writeVtkData (NodalCoordinates &nc, Connectivity &con, const std::string &filename, std::vector< double > &soln)
 Writes the merged grid and its data in VTK UNSTRUCTURED_GRID file format. More...
 

Detailed Description

Everything mesh.

VTK utilities for the Mesh data structures Author: George Zagaris (gzaga.nosp@m.ris@.nosp@m.illin.nosp@m.ois..nosp@m.edu)

The Mesh namespace encapsulates all the mesh-related data structures and algorithms that operate on them.

Function Documentation

void Mesh::AdjEList ( std::vector< std::list< IndexType > > &  aelist,
ListContainerType &  dual_con,
unsigned long  nel = 0 
)

Given an array of adjacent node lists (like an array of face connectivities), this function will loop thru and create a list of unique adjacent nodes for each node Note that this is a little different from the AdjNodeList because in this version every node in each list is considered adjacent.

Definition at line 189 of file Mesh.H.

191  {
192  if(nel == 0)
193  nel = MaxNodeId<ListContainerType,ListType>(dual_con);
194  aelist.resize(nel);
195  typename ListContainerType::iterator lci = dual_con.begin();
196  while(lci != dual_con.end())
197  {
198  typename ListType::iterator li = lci->begin();
199  while(li != lci->end()){
200  IndexType this_node = *li++ - 1;
201  typename ListType::iterator li2 = li;
202  while(li2 != lci->end()){
203  IndexType nexnode = *li2++ - 1;
204  aelist[this_node].push_back(nexnode+1);
205  aelist[nexnode].push_back(this_node+1);
206  }
207  }
208  lci++;
209  }
210  for(IndexType node = 0;node < nel;node++)
211  {
212  aelist[node].sort();
213  aelist[node].unique();
214  }
215  }
Definition: adj.h:150
int Mesh::CollideCellsWithBox ( Mesh::NodalCoordinates nc,
Mesh::Connectivity conn,
GeoPrim::CBox box,
std::vector< Mesh::IndexType > &  candidates,
std::vector< Mesh::IndexType > &  cells 
)

Referenced by main().

Here is the caller graph for this function:

int Mesh::CollideMeshWithBox ( Mesh::NodalCoordinates nc,
Mesh::Connectivity conn,
GeoPrim::CBox box,
std::vector< Mesh::IndexType > &  cells 
)

Referenced by main().

Here is the caller graph for this function:

void Mesh::Container2CSR ( RetCont &  xadj,
RetCont &  adj,
OuterContType &  source 
)

Definition at line 127 of file Mesh.H.

129  {
130  IndexType number_of_elements = source.size();
131  xadj.resize(number_of_elements+1);
132  IndexType number_entries = GetTotalSize<OuterContType>(source);
133  adj.reserve(number_entries);
134  typename OuterContType::iterator si = source.begin();
135  IndexType elm = 0;
136  xadj[elm++] = 0;
137  while(si != source.end()){
138  typename InnerContType::iterator ei = si->begin();
139  xadj[elm] = static_cast<idxtype>(si->size() + xadj[elm-1]);
140  elm++;
141  while(ei != si->end())
142  adj.push_back(static_cast<idxtype>(*ei++-1));
143  si++;
144  }
145  };
void Mesh::CreateAdjacentNodeList ( std::vector< std::list< IndexType > > &  anodelist,
ListContainerType &  fc,
IndexType  nnodes = 0 
)

Given an array of adjacent node lists (like an array of face connectivities), this function will loop thru and create a list of unique adjacent nodes for each node with the nodes that are actually adjacent in the lists

Definition at line 153 of file Mesh.H.

155  {
156  if(nnodes == 0)
157  nnodes = MaxNodeId<ListContainerType,ListType>(fc);
158  anodelist.resize(nnodes);
159  typename ListContainerType::iterator lci = fc.begin();
160  while(lci != fc.end())
161  {
162  typename ListType::iterator li = lci->begin();
163  while(li != lci->end()){
164  IndexType this_node = *li++ - 1;
165  IndexType next_node = 0;
166  if(li == lci->end())
167  next_node = *(lci->begin());
168  else
169  next_node = *li++;
170  anodelist[this_node].push_back(next_node);
171  anodelist[next_node-1].push_back(this_node+1);
172  }
173  lci++;
174  }
175  for(IndexType node = 0;node < nnodes;node++)
176  {
177  anodelist[node].sort();
178  anodelist[node].unique();
179  }
180  }
Definition: adj.h:150
void Mesh::FindElementsInBox ( const GeoPrim::CBox box,
const NodalCoordinates &  nc,
const Connectivity dc,
std::list< IndexType > &  elements 
)

Get elements in box.

Given a box in a cartesian space, this function will populate a list<IndexType> with all the elements that lie within.
Inputs: CBox object (see GeoPrimitives.H) NodalCoordinates object ElementConnectivity object DualConnectivity object list<IndexType> stores results

Mesh::IndexType Mesh::FindPointInCells ( const GeoPrim::CPoint p,
const NodalCoordinates &  nc,
const Connectivity ec,
const std::vector< Mesh::IndexType > &  elements,
GeoPrim::CVector natc 
)

Locate element containing given physical point.

This function will locate which element in a mesh contains a specified point by constructing a box around the point and solving (by Newton-Raphson) the system for each element that touches the box until the element is found.
Inputs: A point in cartesian, ie (X,Y,Z), coordinates A Nodal Coordinates object for the mesh An Element Connectivity object for the mesh Dual Connectivity object for the mesh CBox specifying the parameters of the box use

Returns: An integer indicating which element in the connectivity object contains the point. A 0 will indicate that the point could not be located.

The natural coordinates of the point in the containing element is returned in natc

Referenced by main(), and test().

Here is the caller graph for this function:

Mesh::IndexType Mesh::FindPointInMesh ( const GeoPrim::CPoint p,
const NodalCoordinates &  nc,
const Connectivity ec,
const Connectivity dc,
const GeoPrim::CBox box,
GeoPrim::CVector natc 
)

Locate element containing given physical point.

This function will locate which element in a mesh contains a specified point by constructing a box around the point and solving (by Newton-Raphson) the system for each element that touches the box until the element is found.
Inputs: A point in cartesian, ie (X,Y,Z), coordinates A Nodal Coordinates object for the mesh An Element Connectivity object for the mesh Dual Connectivity object for the mesh CBox specifying the parameters of the box use

Returns: An integer indicating which element in the connectivity object contains the point. A 0 will indicate that the point could not be located.

The natural coordinates of the point in the containing element is returned in natc

Mesh::IndexType Mesh::FindPointInMesh_2 ( const GeoPrim::CPoint p,
const NodalCoordinates &  nc,
const Connectivity ec,
const Connectivity dc,
const GeoPrim::CBox box,
GeoPrim::CVector natc 
)

Locate element containing given physical point.

This function will locate which element in a mesh contains a specified point by constructing a box around the point and solving (by Newton-Raphson) the system for each element that touches the box until the element is found.
Inputs: A point in cartesian, ie (X,Y,Z), coordinates A Nodal Coordinates object for the mesh An Element Connectivity object for the mesh Dual Connectivity object for the mesh CBox specifying the parameters of the box use

Returns: An integer indicating which element in the connectivity object contains the point. A 0 will indicate that the point could not be located.

The natural coordinates of the point in the containing element is returned in natc

Referenced by main().

Here is the caller graph for this function:

void Mesh::Flatten ( OuterCont &  con,
OutCont &  ocon 
)

Populate OutCont with a flat list of entries from a multicontainer.

Definition at line 101 of file Mesh.H.

101  {
102  typename OuterCont::iterator cci = con.begin();
103  ocon.resize(0);
104  while(cci != con.end()){
105  typename InnerCont::iterator ccni = cci->begin();
106  while(ccni != cci->end())
107  ocon.push_back(*ccni++);
108  cci++;
109  }
110  };
void Mesh::FormGraph ( const ContainerType &  adjlist)

Definition at line 239 of file Mesh.H.

240  {
241  // empty for now
242  };
int Mesh::GenerateCartesianGrid ( Mesh::NodalCoordinates nc,
Mesh::BSExtent< Mesh::IndexType > &  gridextent,
std::vector< Mesh::IndexType > &  gridsizes,
GeoPrim::CBox box 
)
void Mesh::GetCoordinateBounds ( NodalCoordinates &  nc,
std::vector< double > &  bnds 
)

Referenced by main().

Here is the caller graph for this function:

void Mesh::GetMeshBoxes ( const NodalCoordinates &  nc,
const Connectivity ec,
GeoPrim::CBox mesh_box,
GeoPrim::CBox small_box,
GeoPrim::CBox large_box 
)

Bounding boxes for a mesh.

This function will determine some bounding boxes for the mesh. Namely, it gets a box for the entire mesh, one for the smallest element and one for the largest.

Referenced by main().

Here is the caller graph for this function:

int Mesh::GetMeshCentroids ( Mesh::NodalCoordinates nc,
Mesh::Connectivity conn,
std::vector< double > &  centroids 
)

Referenced by main().

Here is the caller graph for this function:

IndexType Mesh::GetTotalSize ( OuterContType &  con)

Return the total number of entries in a multicontainer.

Definition at line 114 of file Mesh.H.

Referenced by main().

115  {
116  IndexType total_size = 0;
117  typename OuterContType::iterator ci = con.begin();
118  while(ci != con.end()){
119  total_size += ci->size();
120  ci++;
121  }
122  return(total_size);
123  };

Here is the caller graph for this function:

Mesh::IndexType Mesh::GlobalFindPointInMesh ( const GeoPrim::CPoint p,
const NodalCoordinates &  nc,
const Connectivity ec,
const Connectivity dc,
const GeoPrim::CBox box,
GeoPrim::CVector natc 
)
void Mesh::LUBksb ( GeoPrim::CVector  a[],
int  indx[],
GeoPrim::CVector b 
)
bool Mesh::LUDcmp ( GeoPrim::CVector  a[],
int  indx[] 
)
void Mesh::MapElements ( OuterCont &  src,
OutCont &  trg,
MapType &  m 
)

Definition at line 68 of file Mesh.H.

Referenced by main().

69  {
70  trg.resize(src.size());
71  typename OuterCont::iterator sci = src.begin();
72  typename OutCont::iterator oci = trg.begin();
73  while(sci != src.end()){
74  typename InnerCont::iterator ici = sci->begin();
75  while(ici != sci->end())
76  oci->push_back(m[*ici++]);
77  sci++;
78  oci++;
79  }
80  };

Here is the caller graph for this function:

IndexType Mesh::MaxNodeId ( const ListContainerType &  fc)

Return the maximum of all elements of a multicontainer.

Definition at line 84 of file Mesh.H.

85  {
86  IndexType maxid = 0;
87  typename ListContainerType::const_iterator lci = fc.begin();
88  while(lci != fc.end()){
89  typename ListType::const_iterator li = lci->begin();
90  while(li != lci->end()){
91  if(maxid < *li)
92  maxid = *li;
93  li++;
94  }
95  }
96  return(maxid);
97  };
bool Mesh::NewtonRaphson ( GeoPrim::CVector natc,
IndexType  elnum,
const GenericElement &  el,
const Connectivity ec,
const NodalCoordinates &  nc,
const GeoPrim::CPoint point 
)

Newton-Raphson method, customized for using the GeoPrimitives and computational mesh constructs.

Parameters: double natc[] = initial guess at the natural coordinates IndexType elnum = index of the mesh element to use const ElementConnectivity &ec = The element connectivity for the mesh const NodalCoordinates &nc = The nodal coordinates for the mesh const CPoint &point = the point at which we wish a solution

bool Mesh::NewtonRaphson_2 ( GeoPrim::CVector natc,
IndexType  elnum,
const GenericCell_2 &  el,
const Connectivity ec,
const NodalCoordinates &  nc,
const GeoPrim::CPoint point 
)

Newton-Raphson method, customized for using the GeoPrimitives and computational mesh constructs.

Parameters: double natc[] = initial guess at the natural coordinates IndexType elnum = index of the mesh element to use const ElementConnectivity &ec = The element connectivity for the mesh const NodalCoordinates &nc = The nodal coordinates for the mesh const CPoint &point = the point at which we wish a solution

IndexType Mesh::NumberOfEdges ( ConType &  con)

Definition at line 218 of file Mesh.H.

219  {
220  typename ConType::iterator ci = con.begin();
221  IndexType node = 0;
222  IndexType nedges = 0;
223  while(ci != con.end())
224  {
225  IndexType tnode = ++node;
226  typename IConType::iterator eni = ci->begin();
227  while(eni != ci->end())
228  {
229  IndexType anode = *eni++;
230  if((tnode) < anode)
231  nedges++;
232  }
233  ci++;
234  }
235  return(nedges);
236  }
Definition: adj.h:150
std::ostream& Mesh::operator<< ( std::ostream &  oSt,
const Mesh::NodalCoordinates nc 
)

Definition at line 2128 of file Mesh.C.

References n, and Mesh::NodalCoordinates::size().

2129  {
2130  // if(nc.size() == 0) return(oSt);
2131  oSt.setf(std::ios::scientific);
2132  oSt.setf(std::ios::showpoint);
2133  oSt << std::setprecision(10) << std::setiosflags(std::ios::left);
2134  oSt << nc.size();
2135  if(nc.size() > 0) oSt << "\n";
2136  for(IndexType n = 1;n <= nc.size() ;n++){
2137  oSt << std::setw(16) << nc[n][0] << "\t"
2138  << std::setw(16) << nc[n][1] << "\t"
2139  << std::setw(16) << nc[n][2];
2140  if(n != nc.size())
2141  oSt << std::endl;
2142  }
2143  return (oSt);
2144  }
const NT & n
IndexType size() const
Definition: Mesh.C:48

Here is the call graph for this function:

std::ostream& Mesh::operator<< ( std::ostream &  oSt,
const Mesh::Connectivity ec 
)

Definition at line 2146 of file Mesh.C.

2147  {
2148  oSt << std::setiosflags(std::ios::left) << ec.size();
2149  if(ec.size() == 0) return(oSt);
2150  oSt << "\n";
2151  Mesh::Connectivity::const_iterator ci = ec.begin();
2152  while(ci != ec.end()){
2153  std::vector<IndexType>::const_iterator ni = ci->begin();
2154  while(ni != ci->end()){
2155  oSt << *ni++;
2156  if(ni != ci->end())
2157  oSt << "\t";
2158  }
2159  ci++;
2160  if(ci != ec.end())
2161  oSt << "\n";
2162  }
2163  return(oSt);
2164  }
void int int REAL REAL REAL *z blockDim dim * ni
Definition: read.cpp:77
std::ostream& Mesh::operator<< ( std::ostream &  oSt,
const Mesh::GeometricEntity ge 
)

Definition at line 2166 of file Mesh.C.

References Mesh::GeometricEntity::_collections.

2167  {
2168  if(ge.first.empty()) return(oSt);
2169  oSt << std::setiosflags(std::ios::left) << ge.first << "\n";
2170  oSt << ge._collections;
2171  return(oSt);
2172  }
Mesh::Connectivity _collections
Definition: Mesh.H:441
std::istream& Mesh::operator>> ( std::istream &  iSt,
Mesh::GeometricEntity ge 
)

Definition at line 2074 of file Mesh.C.

References Mesh::GeometricEntity::_collections.

2075  {
2076  std::string line;
2077  std::getline(iSt,line);
2078  std::istringstream Istr(line);
2079  Istr >> ge.first;
2080  iSt >> ge._collections;
2081  ge.second = ge._collections.size();
2082  return(iSt);
2083  }
Mesh::Connectivity _collections
Definition: Mesh.H:441
std::istream& Mesh::operator>> ( std::istream &  iSt,
Mesh::Connectivity ec 
)

Definition at line 2085 of file Mesh.C.

References Mesh::Connectivity::_nelem, i, Mesh::Connectivity::Resize(), and swap().

2086  {
2087  std::string line;
2088  std::getline(iSt,line);
2089  std::istringstream Istr(line);
2090  IndexType nelem = 0;
2091  Istr >> nelem;
2092  if(nelem > 0){
2093  ec.Resize(nelem);
2094  ec._nelem = nelem;
2095  for(IndexType i = 0;i < nelem;i++){
2096  std::getline(iSt,line);
2097  std::istringstream Istr2(line);
2098  IndexType node;
2099  ec[i].reserve(8);
2100  while(Istr2 >> node)
2101  ec[i].push_back(node);
2102  std::vector<Mesh::IndexType>(ec[i]).swap(ec[i]);
2103  }
2104  }
2105  return(iSt);
2106  }
void swap(int &a, int &b)
Definition: buildface.cpp:88
Definition: adj.h:150
void Resize(unsigned int N=0)
Definition: Mesh.C:233
blockLoc i
Definition: read.cpp:79
IndexType _nelem
Definition: Mesh.H:339

Here is the call graph for this function:

std::istream& Mesh::operator>> ( std::istream &  iSt,
Mesh::NodalCoordinates nc 
)

Definition at line 2108 of file Mesh.C.

References Mesh::NodalCoordinates::init(), n, and Mesh::NodalCoordinates::size().

2109  {
2110  // if(nc.size() == 0) return (iSt);
2111  std::string line;
2112  IndexType nnodes;
2113  std::getline(iSt,line);
2114  std::istringstream Istr(line);
2115  Istr >> nnodes;
2116  if(nnodes > 0){
2117  nc.init(nnodes);
2118  for(IndexType n = 1;n <= nc.size();n++){
2119  double *inPtr = nc[n];
2120  std::getline(iSt,line);
2121  std::istringstream Istr2(line);
2122  Istr2 >> inPtr[0] >> inPtr[1] >> inPtr[2];
2123  }
2124  }
2125  return(iSt);
2126  }
const NT & n
IndexType size() const
Definition: Mesh.C:48

Here is the call graph for this function:

void Mesh::printVtk ( std::vector< double > &  vlist,
std::vector< std::vector< int > > &  elist 
)

This method prints the global grid in VTK file format.

Note
Mostly used for debugging.
Parameters
vlistthe global vertex list.
elistthe element list.
int Mesh::ReadMesh ( const std::string &  path,
Mesh::UnstructuredMesh mesh 
)
void Mesh::writeVtkData ( )

Writes the merged grid and its data in VTK UNSTRUCTURED_GRID file format.

Precondition
Program.globalNodeList.size( ) > 0.
Program.globalElementList.size( ) > 0.
Program.smdv.size( ) > 0.
Program.globalSolution.size( ) == Program.smdv.size( ).
Program.solutionignore.size( ) == Program.smdv.size( ).
Program.outputfile != ""
Postcondition
A VTK formatted file is written in Program.outputfile.vtk
Note
The extension in the outputfile will be appended.

Definition at line 645 of file hdf2pltV2.C.

References CELLDATA, i, j, NODEDATA, globarg::outputfile, and Program.

Referenced by printWindow().

646 {
647 
648  std::cout << "Writing VTK data...";
649  std::cout.flush( );
650 
651  #ifdef ASSERT_ON
652  assert( Program.globalNodeList.size( ) > 0 );
653  assert( Program.globalElementList.size( ) > 0 );
654  assert( Program.smdv.size( ) > 0 );
655  assert( Program.globalSolution.size( ) == Program.smdv.size( ) );
656  assert( Program.solutionignore.size( ) == Program.smdv.size( ) );
657  assert( Program.outputfile != "" );
658  #endif
659 
660  std::ofstream ofs;
661  ofs.open( std::string(Program.outputfile + ".vtk").c_str( ) );
662 
663  if( !ofs.is_open( ) )
664  {
665  std::cerr << "Cannot write VTK file: " << Program.outputfile+".vtk" << std::endl;
666  std::cerr << "File: " << __FILE__ << std::endl;
667  std::cerr << "Line: " << __LINE__ << std::endl;
668  assert( false );
669  }
670 
671  /* STEP 1: Write the header */
672  ofs << "# vtk DataFile Version 3.0\n";
673  ofs << "Global Mesh Output" << std::endl;
674  ofs << "ASCII\n";
675  ofs << "DATASET UNSTRUCTURED_GRID\n";
676  ofs << "POINTS " << Program.globalNodeList.size( )/3 << " double\n";
677 
678  /* STEP 2: Write the nodes */
679  for( int i=0; i < Program.globalNodeList.size( )/3; ++i )
680  {
681  ofs << Program.globalNodeList[ i*3 ] << " ";
682  ofs << Program.globalNodeList[ i*3+1 ] << " ";
683  ofs << Program.globalNodeList[ i*3+2 ] << std::endl;
684  }
685 
686  /* STEP 3: Write the max element size */
687  int maxnodes = 0; /* the maximum number of nodes per element */
688  for( int i=0; i < Program.globalElementList.size( ); ++i )
689  {
690  if( maxnodes < Program.globalElementList[ i ].size( ) )
691  maxnodes = Program.globalElementList[ i ].size( );
692  }
693 
694  /* STEP 4: Write the element connectivity */
695  ofs << "CELLS " << Program.globalElementList.size( ) << " " << Program.globalElementList.size( )*( maxnodes+1) << "\n";
696  for( int i=0; i < Program.globalElementList.size( ); ++i )
697  {
698  ofs << Program.globalElementList[ i ].size( ) << " ";
699  for( int j=0; j < Program.globalElementList[ i ].size( ); ++j )
700  ofs << Program.globalElementList[ i ][ j ]<< " ";
701  ofs << std::endl;
702  }
703 
704  /* STEP 5: Write the cell types */
705  ofs << "CELL_TYPES " << Program.globalElementList.size( ) << std::endl;
706  for( int i=0; i < Program.globalElementList.size( ); ++i )
707  {
708 
709  if( Program.globalElementList[ i ].size( ) == 8 )
710  ofs << "12\n";
711  else if( Program.globalElementList[ i ].size( ) == 4 )
712  ofs << "10\n";
713  else {
714  std::cerr << "Undefined element type!\n";
715  std::cerr << "File: " << __FILE__ << std::endl;
716  std::cerr << "Line: " << __LINE__ << std::endl;
717  }
718 
719  }
720 
721  /* STEP 6: Write the solution data attached to the points */
722  bool wroteHeader = false;
723  for( int i=0; i < Program.globalSolution.size( ); ++i )
724  {
725 
726  if( ! Program.solutionignore[ i ] && Program.getDataItemType( i ) == NODEDATA )
727  {
728 
729  int N = Program.globalNodeList.size( )/3;
730  int NC = Program.smdv[ i ].ncomp;
731 
732  if(!wroteHeader)
733  {
734  ofs << "POINT_DATA " << N << std::endl;
735  wroteHeader = true;
736  }
737 
738  if( NC == 1 )
739  {
740  ofs << "SCALARS " << Program.smdv[ i ].name << " double" << std::endl;
741  ofs << "LOOKUP_TABLE default\n";
742  }
743  else if( NC == 3 )
744  {
745  ofs << "VECTORS " << Program.smdv[ i ].name << " double" << std::endl;
746  }
747  else
748  {
749  ofs << "TENSORS " << Program.smdv[ i ].name << " double" << std::endl;
750  }
751 
752  for( int j=0; j < N; ++j )
753  {
754  for( int component=0; component < NC; ++component )
755  {
756  ofs << Program.globalSolution[ i ][ j*NC+component ] << " ";
757  }
758  ofs << std::endl;
759  }
760 
761  } /* End if the solution is not ignored */
762 
763  } /* End for all solution data */
764 
765 
766  /* STEP 6: Write the solution data attached to the cells */
767  wroteHeader = false;
768  for( int i=0; i < Program.globalSolution.size( ); ++i )
769  {
770 
771  if( ! Program.solutionignore[ i ] && Program.getDataItemType( i ) == CELLDATA )
772  {
773 
774  int N = Program.globalElementList.size();
775  int NC = Program.smdv[ i ].ncomp;
776 
777  if( !wroteHeader )
778  {
779  ofs << "CELL_DATA " << N << std::endl;
780  wroteHeader = true;
781  }
782 
783  if( NC == 1 )
784  {
785  ofs << "SCALARS " << Program.smdv[ i ].name << " double" << std::endl;
786  ofs << "LOOKUP_TABLE default\n";
787  }
788  else if( NC == 3 )
789  {
790  ofs << "VECTORS " << Program.smdv[ i ].name << " double" << std::endl;
791  }
792  else
793  {
794  ofs << "TENSORS " << Program.smdv[ i ].name << " double" << std::endl;
795  }
796 
797  for( int j=0; j < N; ++j )
798  {
799  for( int component=0; component < NC; ++component )
800  {
801  ofs << Program.globalSolution[ i ][ j*NC+component ] << " ";
802  }
803  ofs << std::endl;
804  }
805 
806  } /* End if the solution is not ignored */
807 
808  } /* End for all solution data */
809 
810  ofs.close( );
811 
812  std::cout << "[DONE]\n";
813 
814 }
std::string outputfile
The filename of the output file.
Definition: hdf2plt.C:743
blockLoc i
Definition: read.cpp:79
struct globarg Program
j indices j
Definition: Indexing.h:6

Here is the caller graph for this function:

void Mesh::writeVtkData ( NodalCoordinates &  nc,
Connectivity con,
const std::string &  filename,
std::vector< double > &  soln 
)

Writes the merged grid and its data in VTK UNSTRUCTURED_GRID file format.

Precondition
Program.globalNodeList.size( ) > 0.
Program.globalElementList.size( ) > 0.
Program.smdv.size( ) > 0.
Program.globalSolution.size( ) == Program.smdv.size( ).
Program.solutionignore.size( ) == Program.smdv.size( ).
Program.outputfile != ""
Postcondition
A VTK formatted file is written in Program.outputfile.vtk
Note
The extension in the outputfile will be appended.

Definition at line 143 of file MeshVTK.C.

References Mesh::Connectivity::Esize(), i, j, Mesh::NodalCoordinates::NNodes(), and Mesh::Connectivity::SyncSizes().

144  {
145 
146  std::cout << "Writing VTK data...";
147  std::cout.flush( );
148 
149  std::ofstream ofs;
150  ofs.open( filename.c_str());
151 
152  if( !ofs.is_open( ) )
153  {
154  std::cerr << "Cannot write VTK file: " << filename << std::endl;
155  std::cerr << "File: " << __FILE__ << std::endl;
156  std::cerr << "Line: " << __LINE__ << std::endl;
157  assert( false );
158  }
159 
160  unsigned int nnodes = nc.NNodes();
161  /* STEP 1: Write the header */
162  ofs << "# vtk DataFile Version 3.0\n";
163  ofs << "Global Mesh Output" << std::endl;
164  ofs << "ASCII\n";
165  ofs << "DATASET UNSTRUCTURED_GRID\n";
166  ofs << "POINTS " << nnodes << " double\n";
167 
168  /* STEP 2: Write the nodes */
169  for( int i=1; i < nnodes; ++i )
170  {
171  ofs << GeoPrim::C3Point(&(nc[i])) << std:endl;
172  }
173 
174  /* STEP 3: Write the max element size */
175  int maxnodes = 0; /* the maximum number of nodes per element */
176  unsigned int nelem = con.size();
177  con.SyncSizes();
178  for( int i=0; i < nelem; ++i )
179  {
180  unsigned int esize = con[i].size();
181  if(maxnodes < esize)
182  maxnodes = esize;
183  }
184 
185  /* STEP 4: Write the element connectivity */
186  ofs << "CELLS " << nelem << " " << nelem*( maxnodes+1) << "\n";
187  for( int i=0; i < nelem; ++i )
188  {
189  ofs << con.Esize(i) << " ";
190  for( int j=0; j < con.Esize(i); ++j )
191  ofs << con[ i ][ j ]-1 << " ";
192  ofs << std::endl;
193  }
194 
195  /* STEP 5: Write the cell types */
196  ofs << "CELL_TYPES " << nelem << std::endl;
197  for( int i=0; i < nelem; ++i )
198  {
199 
200  if( con.Esize(i) == 8 )
201  ofs << "12\n";
202  else if( con.Esize(i) == 4 )
203  ofs << "10\n";
204  else {
205  std::cerr << "Undefined element type!\n";
206  std::cerr << "File: " << __FILE__ << std::endl;
207  std::cerr << "Line: " << __LINE__ << std::endl;
208  }
209 
210  }
211 
212  /* STEP 6: Write the solution data attached to the points */
213  bool wroteHeader = false;
214  std::vector<std::string> Name(5);
215  Name[0] = "rho";
216  Name[1] = "rho-u";
217  Name[2] = "rho-v";
218  Name[3] = "rho-w";
219  Name[4] = "rho-E";
220  if(!soln.empty()){
221  for( int i=0; i < 5; ++i )
222  {
223  if( !wroteHeader )
224  {
225  ofs << "CELL_DATA " << nelem << std::endl;
226  wroteHeader = true;
227  }
228  ofs << "SCALARS " << Name[i] << " double" << std::endl;
229  ofs << "LOOKUP_TABLE default\n";
230  for( int j=0; j < nelem; ++j )
231  {
232  ofs << soln[ i*nelem + j ] << " ";
233  }
234  ofs << std::endl;
235  }
236  }
237  ofs.close( );
238  std::cout << "[DONE]\n";
239  }
blockLoc i
Definition: read.cpp:79
j indices j
Definition: Indexing.h:6
C3Vector C3Point

Here is the call graph for this function:

void Mesh::writeVtkFiles ( std::vector< Mesh::UnstructuredMesh > &  m)

Writes the set of meshes into separate VTK files that can be visualized with Paraview.

The format of the files is {outputFile}.paneId.vtk.

Note
This method is mainly used for debugging.
Parameters
mthe set of meshes.