Nektar++
Fld2Tecplot.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstdlib>
3 
4 #include <SolverUtils/Driver.h>
6 
8 
9 using namespace std;
10 using namespace Nektar;
11 using namespace Nektar::SolverUtils;
12 
13 static std::string cvar = LibUtilities::SessionReader::RegisterCmdLineFlag(
14  "CharateristicVariables","c","Output characteristic variables");
15 
16 static std::string SetToOneD = LibUtilities::SessionReader::RegisterCmdLineArgument("SetToOneSpaceDimension","1","Redefine mesh to be aligned to x-axis");
17 
18 int main(int argc, char *argv[])
19 {
20  if((argc < 3)||(argc > 4))
21  {
22  fprintf(stderr,"Usage: ./Fld2Tecplot [-c] file.xml file.fld\n");
23  exit(1);
24  }
25 
26 
29  string vDriverModule;
30  DriverSharedPtr drv;
31 
32 
33  try
34  {
35 
36  // Define new input with extra argument to intialisae -OneD=false
37  int newargc = argc+1;
38  char **newargv = new char*[newargc];
39 
40  newargv[0] = argv[0];
41  newargv[1] = new char[31];
42  strcpy(newargv[1], "--SetToOneSpaceDimension=false");
43 
44  for(int i = 1; i < argc; ++i)
45  {
46  newargv[i+1] = argv[i];
47  }
48 
49  // Create session reader and MeshGraph.
50  session = LibUtilities::SessionReader::CreateInstance(newargc, newargv);
51  graph = SpatialDomains::MeshGraph::Read(session);
52  delete[] newargv;
53 
54  bool CalcCharacteristicVariables = false;
55 
56  if(session->DefinesCmdLineArgument(cvar))
57  {
58  CalcCharacteristicVariables = true;
59  }
60 
61 
62  // Create driver
63  session->LoadSolverInfo("Driver", vDriverModule, "Standard");
64  drv = GetDriverFactory().CreateInstance(vDriverModule, session, graph);
65 
66  EquationSystemSharedPtr EqSys = drv->GetEqu()[0];
67 
68  PulseWaveSystemSharedPtr PulseWave;
69  if(!(PulseWave = std::dynamic_pointer_cast
70  <PulseWaveSystem>(EqSys)))
71  {
72  ASSERTL0(false,"Failed to dynamically cast to PulseWaveSystemOutput");
73  }
74 
75  std::string fname(argv[argc-1]);
77 
78  int ndomains = PulseWave->GetNdomains();
79 
80  PulseWave->ImportFldToMultiDomains(fname,Vessels = PulseWave->UpdateVessels(),
81  ndomains);
82  int fdot = fname.find_last_of('.');
83 
84  if (fdot != std::string::npos)
85  {
86  string ending = fname.substr(fdot);
87 
88  // If .chk or .fld we exchange the extension in the output file.
89  // For all other files (e.g. .bse) we append the extension to avoid
90  // conflicts.
91  if (ending == ".chk" || ending == ".fld")
92  {
93  fname = fname.substr(0,fdot);
94  }
95  }
96 
97  fname = fname + ".dat";
98 
99  ofstream outfile(fname.c_str());
100  int nvariables = session->GetVariables().size();
101  std::string var = "";
102  int j;
103  for(j = 0; j < nvariables-1; ++j)
104  {
105  var += session->GetVariable(j) + ", ";
106  }
107  var += session->GetVariable(j);
108 
109  if(CalcCharacteristicVariables)
110  {
111  var += ", Char1, Char2";
112  }
113 
114  Vessels[0]->WriteTecplotHeader(outfile,var);
115 
116  for(int n = 0; n < ndomains; ++n)
117  {
118  Vessels[n*nvariables]->WriteTecplotZone(outfile);
119  for(int j = 0; j < nvariables; ++j)
120  {
121  Vessels[n*nvariables+j]->WriteTecplotField(outfile);
122  }
123 
124  if(CalcCharacteristicVariables)
125  {
126  PulseWave->CalcCharacteristicVariables(n*nvariables);
127 
128  for(int j = 0; j < nvariables; ++j)
129  {
130  Vessels[n*nvariables+j]->WriteTecplotField(outfile);
131  }
132  }
133  Vessels[n*nvariables]->WriteTecplotConnectivity(outfile);
134  }
135  }
136 
137  catch (const std::runtime_error&)
138  {
139  return 1;
140  }
141  catch (const std::string& eStr)
142  {
143  cout << "Error: " << eStr << endl;
144  }
145 
146  return 0;
147 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:163
std::shared_ptr< Driver > DriverSharedPtr
A shared pointer to a Driver object.
Definition: Driver.h:51
STL namespace.
Base class for unsteady solvers.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
static std::string SetToOneD
Definition: Fld2Tecplot.cpp:16
std::shared_ptr< PulseWaveSystem > PulseWaveSystemSharedPtr
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:65
static std::string cvar
Definition: Fld2Tecplot.cpp:13
int main(int argc, char *argv[])
Definition: Fld2Tecplot.cpp:18
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< EquationSystem > EquationSystemSharedPtr
A shared pointer to an EquationSystem object.