Nektar++
Fld2Tecplot.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Fld2Tecplot.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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description:
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <cstdio>
36 #include <cstdlib>
37 
39 #include <SolverUtils/Driver.h>
40 
42 
43 using namespace std;
44 using namespace Nektar;
45 using namespace Nektar::SolverUtils;
46 
47 static std::string SetToOneD =
48  LibUtilities::SessionReader::RegisterCmdLineArgument(
49  "SetToOneSpaceDimension", "1", "Redefine mesh to be aligned to x-axis");
50 
51 int main(int argc, char *argv[])
52 {
53  if ((argc < 3) || (argc > 4))
54  {
55  fprintf(stderr, "Usage: ./Fld2Tecplot [-c] file.xml file.fld\n");
56  exit(1);
57  }
58 
61  string vDriverModule;
62  DriverSharedPtr drv;
63 
64  try
65  {
66 
67  // Define new input with extra argument to intialisae -OneD=false
68  int newargc = argc + 1;
69  char **newargv = new char *[newargc];
70 
71  newargv[0] = argv[0];
72  newargv[1] = new char[31];
73  strcpy(newargv[1], "--SetToOneSpaceDimension=false");
74 
75  for (int i = 1; i < argc; ++i)
76  {
77  newargv[i + 1] = argv[i];
78  }
79 
80  // Create session reader and MeshGraph.
81  session = LibUtilities::SessionReader::CreateInstance(newargc, newargv);
82  graph = SpatialDomains::MeshGraph::Read(session);
83  delete[] newargv;
84 
85  // Create driver
86  session->LoadSolverInfo("Driver", vDriverModule, "Standard");
87  drv = GetDriverFactory().CreateInstance(vDriverModule, session, graph);
88 
89  EquationSystemSharedPtr EqSys = drv->GetEqu()[0];
90 
91  PulseWaveSystemSharedPtr PulseWave;
92  if (!(PulseWave = std::dynamic_pointer_cast<PulseWaveSystem>(EqSys)))
93  {
94  ASSERTL0(false,
95  "Failed to dynamically cast to PulseWaveSystemOutput");
96  }
97 
98  std::string fname(argv[argc - 1]);
100 
101  int ndomains = PulseWave->GetNdomains();
102 
103  PulseWave->ImportFldToMultiDomains(
104  fname, Vessels = PulseWave->UpdateVessels(), ndomains);
105  int fdot = fname.find_last_of('.');
106 
107  if (fdot != std::string::npos)
108  {
109  string ending = fname.substr(fdot);
110 
111  // If .chk or .fld we exchange the extension in the output file.
112  // For all other files (e.g. .bse) we append the extension to avoid
113  // conflicts.
114  if (ending == ".chk" || ending == ".fld")
115  {
116  fname = fname.substr(0, fdot);
117  }
118  }
119 
120  fname += ".dat";
121 
122  ofstream outfile(fname.c_str());
123  int nvariables = session->GetVariables().size();
124  std::string var = "";
125  int j;
126  for (j = 0; j < nvariables - 1; ++j)
127  {
128  var += session->GetVariable(j) + ", ";
129  }
130  var += session->GetVariable(j);
131 
132  Vessels[0]->WriteTecplotHeader(outfile, var);
133 
134  for (int n = 0; n < ndomains; ++n)
135  {
136  Vessels[n * nvariables]->WriteTecplotZone(outfile);
137  for (int j = 0; j < nvariables; ++j)
138  {
139  Vessels[n * nvariables + j]->WriteTecplotField(outfile);
140  }
141 
142  Vessels[n * nvariables]->WriteTecplotConnectivity(outfile);
143  }
144  }
145 
146  catch (const std::runtime_error &)
147  {
148  return 1;
149  }
150  catch (const std::string &eStr)
151  {
152  cout << "Error: " << eStr << endl;
153  }
154 
155  return 0;
156 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
int main(int argc, char *argv[])
Definition: Fld2Tecplot.cpp:51
static std::string SetToOneD
Definition: Fld2Tecplot.cpp:47
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Driver > DriverSharedPtr
A shared pointer to a Driver object.
Definition: Driver.h:51
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:64
std::shared_ptr< EquationSystem > EquationSystemSharedPtr
A shared pointer to an EquationSystem object.
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:172
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
std::shared_ptr< PulseWaveSystem > PulseWaveSystemSharedPtr