Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
28  string vDriverModule;
29  DriverSharedPtr drv;
30 
31 
32  try
33  {
34 
35  // Define new input with extra argument to intialisae -OneD=false
36  int newargc = argc+1;
37  char **newargv = new char*[newargc];
38 
39  newargv[0] = argv[0];
40  newargv[1] = new char[31];
41  strcpy(newargv[1], "--SetToOneSpaceDimension=false");
42 
43  for(int i = 1; i < argc; ++i)
44  {
45  newargv[i+1] = argv[i];
46  }
47 
48  // Create session reader.
49  session = LibUtilities::SessionReader::CreateInstance(newargc, newargv);
50  delete[] newargv;
51 
52  bool CalcCharacteristicVariables = false;
53 
54  if(session->DefinesCmdLineArgument(cvar))
55  {
56  CalcCharacteristicVariables = true;
57  }
58 
59 
60  // Create driver
61  session->LoadSolverInfo("Driver", vDriverModule, "Standard");
62  drv = GetDriverFactory().CreateInstance(vDriverModule, session);
63 
64  EquationSystemSharedPtr EqSys = drv->GetEqu()[0];
65 
66  PulseWaveSystemSharedPtr PulseWave;
67  if(!(PulseWave = boost::dynamic_pointer_cast
68  <PulseWaveSystem>(EqSys)))
69  {
70  ASSERTL0(false,"Failed to dynamically cast to PulseWaveSystemOutput");
71  }
72 
73  std::string fname(argv[argc-1]);
75 
76  int ndomains = PulseWave->GetNdomains();
77 
78  PulseWave->ImportFldToMultiDomains(fname,Vessels = PulseWave->UpdateVessels(),
79  ndomains);
80  int fdot = fname.find_last_of('.');
81 
82  if (fdot != std::string::npos)
83  {
84  string ending = fname.substr(fdot);
85 
86  // If .chk or .fld we exchange the extension in the output file.
87  // For all other files (e.g. .bse) we append the extension to avoid
88  // conflicts.
89  if (ending == ".chk" || ending == ".fld")
90  {
91  fname = fname.substr(0,fdot);
92  }
93  }
94 
95  fname = fname + ".dat";
96 
97  ofstream outfile(fname.c_str());
98  int nvariables = session->GetVariables().size();
99  std::string var = "";
100  int j;
101  for(j = 0; j < nvariables-1; ++j)
102  {
103  var += session->GetVariable(j) + ", ";
104  }
105  var += session->GetVariable(j);
106 
107  if(CalcCharacteristicVariables)
108  {
109  var += ", Char1, Char2";
110  }
111 
112  Vessels[0]->WriteTecplotHeader(outfile,var);
113 
114  for(int n = 0; n < ndomains; ++n)
115  {
116  Vessels[n*nvariables]->WriteTecplotZone(outfile);
117  for(int j = 0; j < nvariables; ++j)
118  {
119  Vessels[n*nvariables+j]->WriteTecplotField(outfile);
120  }
121 
122  if(CalcCharacteristicVariables)
123  {
124  PulseWave->CalcCharacteristicVariables(n*nvariables);
125 
126  for(int j = 0; j < nvariables; ++j)
127  {
128  Vessels[n*nvariables+j]->WriteTecplotField(outfile);
129  }
130  }
131  Vessels[n*nvariables]->WriteTecplotConnectivity(outfile);
132  }
133  }
134 
135  catch (const std::runtime_error&)
136  {
137  return 1;
138  }
139  catch (const std::string& eStr)
140  {
141  cout << "Error: " << eStr << endl;
142  }
143 
144  return 0;
145 }
boost::shared_ptr< PulseWaveSystem > PulseWaveSystemSharedPtr
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
boost::shared_ptr< Driver > DriverSharedPtr
A shared pointer to a Driver object.
Definition: Driver.h:52
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:162
STL namespace.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
boost::shared_ptr< EquationSystem > EquationSystemSharedPtr
A shared pointer to an EquationSystem object.
Base class for unsteady solvers.
static std::string SetToOneD
Definition: Fld2Tecplot.cpp:16
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:66
static std::string cvar
Definition: Fld2Tecplot.cpp:13
int main(int argc, char *argv[])
Definition: Fld2Tecplot.cpp:18