Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XmlToVtk.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // File: XmlToVtk.cpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Output VTK file of XML mesh, optionally with Jacobian.
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #include <cstdlib>
37 
38 #include <MultiRegions/ExpList.h>
39 #include <MultiRegions/ExpList1D.h>
40 #include <MultiRegions/ExpList2D.h>
41 #include <MultiRegions/ExpList3D.h>
43 
44 using namespace Nektar;
45 
46 int main(int argc, char *argv[])
47 {
48  if(argc < 2)
49  {
50  cerr << "Usage: XmlToVtk meshfile" << endl;
51  exit(1);
52  }
53 
55  "jacobian", "j", "Output Jacobian as scalar field");
56 
59 
60  bool jac = vSession->DefinesCmdLineArgument("jacobian");
61 
62  // Read in mesh from input file
63  string meshfile(argv[argc-1]);
65  SpatialDomains::MeshGraph::Read(vSession); //meshfile);
66 
67  // Set up Expansion information
68  SpatialDomains::ExpansionMap emap = graphShPt->GetExpansions();
70 
71  for (it = emap.begin(); it != emap.end(); ++it)
72  {
73  for (int i = 0; i < it->second->m_basisKeyVector.size(); ++i)
74  {
75  LibUtilities::BasisKey tmp1 = it->second->m_basisKeyVector[i];
77  it->second->m_basisKeyVector[i] = LibUtilities::BasisKey(
78  tmp1.GetBasisType(), tmp1.GetNumModes(),
81  }
82  }
83 
84  // Define Expansion
85  int expdim = graphShPt->GetMeshDimension();
86  Array<OneD, MultiRegions::ExpListSharedPtr> Exp(1);
87 
88  switch(expdim)
89  {
90  case 1:
91  {
94  ::AllocateSharedPtr(vSession,graphShPt);
95  Exp[0] = Exp1D;
96  break;
97  }
98  case 2:
99  {
100  if(vSession->DefinesSolverInfo("HOMOGENEOUS"))
101  {
102  std::string HomoStr = vSession->GetSolverInfo("HOMOGENEOUS");
104 
105  ASSERTL0(
106  HomoStr == "HOMOGENEOUS1D" || HomoStr == "Homogeneous1D" ||
107  HomoStr == "1D" || HomoStr == "Homo1D",
108  "Only 3DH1D supported for XML output currently.");
109 
110  int nplanes;
111  vSession->LoadParameter("HomModesZ", nplanes);
112 
113  // choose points to be at evenly spaced points at nplanes + 1
114  // points
115  const LibUtilities::PointsKey Pkey(
116  nplanes + 1, LibUtilities::ePolyEvenlySpaced);
117  const LibUtilities::BasisKey Bkey(
118  LibUtilities::eFourier, nplanes, Pkey);
119  NekDouble lz = vSession->GetParameter("LZ");
120 
123  vSession, Bkey, lz, false, false, graphShPt);
124  Exp[0] = Exp3DH1;
125  }
126  else
127  {
130  ::AllocateSharedPtr(vSession,graphShPt);
131  Exp[0] = Exp2D;
132  }
133  break;
134  }
135  case 3:
136  {
139  ::AllocateSharedPtr(vSession,graphShPt);
140  Exp[0] = Exp3D;
141  break;
142  }
143  default:
144  {
145  ASSERTL0(false,"Expansion dimension not recognised");
146  break;
147  }
148  }
149 
150  // Write out VTK file.
151  string outname(strtok(argv[argc-1],"."));
152  outname += ".vtu";
153  ofstream outfile(outname.c_str());
154 
155  Exp[0]->WriteVtkHeader(outfile);
156 
157  if (jac)
158  {
159  // Find minimum Jacobian.
160  Array<OneD, NekDouble> tmp;
161  Array<OneD, NekDouble> x0 (Exp[0]->GetNpoints());
162  Array<OneD, NekDouble> x1 (Exp[0]->GetNpoints());
163  Array<OneD, NekDouble> x2 (Exp[0]->GetNpoints());
164  Exp[0]->GetCoords(x0, x1, x2);
165 
166  // Write out field containing Jacobian.
167  for(int i = 0; i < Exp[0]->GetExpSize(); ++i)
168  {
169  LocalRegions::ExpansionSharedPtr e = Exp[0]->GetExp(i);
170  SpatialDomains::GeomFactorsSharedPtr g = e->GetMetricInfo();
171  LibUtilities::PointsKeyVector ptsKeys = e->GetPointsKeys();
172  unsigned int npts = e->GetTotPoints();
173 
174  if (g->GetGtype() == SpatialDomains::eDeformed)
175  {
176  Vmath::Vcopy(npts, g->GetJac(ptsKeys), 1,
177  tmp = Exp[0]->UpdatePhys()
178  + Exp[0]->GetPhys_Offset(i), 1);
179  }
180  else
181  {
182  Vmath::Fill (npts, g->GetJac(ptsKeys)[0],
183  tmp = Exp[0]->UpdatePhys()
184  + Exp[0]->GetPhys_Offset(i), 1);
185  }
186 
187  Exp[0]->WriteVtkPieceHeader(outfile, i);
188  Exp[0]->WriteVtkPieceData (outfile, i, "Jac");
189  Exp[0]->WriteVtkPieceFooter(outfile, i);
190  }
191 
192  unsigned int n
193  = Vmath::Imin(Exp[0]->GetNpoints(), Exp[0]->GetPhys(), 1);
194  cout << "- Minimum Jacobian: "
195  << Vmath::Vmin(Exp[0]->GetNpoints(), Exp[0]->GetPhys(), 1)
196  << " at coords (" << x0[n] << ", " << x1[n] << ", " << x2[n] << ")"
197  << endl;
198 
199  }
200  else
201  {
202  // For each field write header and footer, since there is no field data.
203  for(int i = 0; i < Exp[0]->GetExpSize(); ++i)
204  {
205  Exp[0]->WriteVtkPieceHeader(outfile, i);
206  Exp[0]->WriteVtkPieceFooter(outfile, i);
207  }
208  }
209 
210  Exp[0]->WriteVtkFooter(outfile);
211 
212  return 0;
213 }
214