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>
41
43
44using namespace std;
45using namespace Nektar;
46using namespace Nektar::SolverUtils;
47
48static std::string SetToOneD =
49 LibUtilities::SessionReader::RegisterCmdLineArgument(
50 "SetToOneSpaceDimension", "1", "Redefine mesh to be aligned to x-axis");
51
52int main(int argc, char *argv[])
53{
54 if ((argc < 3) || (argc > 4))
55 {
56 fprintf(stderr, "Usage: ./Fld2Tecplot [-c] file.xml file.fld\n");
57 exit(1);
58 }
59
62 string vDriverModule;
64
65 try
66 {
67
68 // Define new input with extra argument to intialisae -OneD=false
69 int newargc = argc + 1;
70 char **newargv = new char *[newargc];
71
72 newargv[0] = argv[0];
73 newargv[1] = new char[31];
74 strcpy(newargv[1], "--SetToOneSpaceDimension=false");
75
76 for (int i = 1; i < argc; ++i)
77 {
78 newargv[i + 1] = argv[i];
79 }
80
81 // Create session reader and MeshGraph.
82 session = LibUtilities::SessionReader::CreateInstance(newargc, newargv);
83 graph = SpatialDomains::MeshGraphIO::Read(session);
84 delete[] newargv;
85
86 // Create driver
87 session->LoadSolverInfo("Driver", vDriverModule, "Standard");
88 drv = GetDriverFactory().CreateInstance(vDriverModule, session, graph);
89
90 EquationSystemSharedPtr EqSys = drv->GetEqu()[0];
91
93 if (!(PulseWave = std::dynamic_pointer_cast<PulseWaveSystem>(EqSys)))
94 {
95 ASSERTL0(false,
96 "Failed to dynamically cast to PulseWaveSystemOutput");
97 }
98
99 std::string fname(argv[argc - 1]);
101
102 int ndomains = PulseWave->GetNdomains();
103
104 PulseWave->ImportFldToMultiDomains(
105 fname, Vessels = PulseWave->UpdateVessels(), ndomains);
106 int fdot = fname.find_last_of('.');
107
108 if (fdot != std::string::npos)
109 {
110 string ending = fname.substr(fdot);
111
112 // If .chk or .fld we exchange the extension in the output file.
113 // For all other files (e.g. .bse) we append the extension to avoid
114 // conflicts.
115 if (ending == ".chk" || ending == ".fld")
116 {
117 fname = fname.substr(0, fdot);
118 }
119 }
120
121 fname += ".dat";
122
123 ofstream outfile(fname.c_str());
124 int nvariables = session->GetVariables().size();
125 std::string var = "";
126 int j;
127 for (j = 0; j < nvariables - 1; ++j)
128 {
129 var += session->GetVariable(j) + ", ";
130 }
131 var += session->GetVariable(j);
132
133 Vessels[0]->WriteTecplotHeader(outfile, var);
134
135 for (int n = 0; n < ndomains; ++n)
136 {
137 Vessels[n * nvariables]->WriteTecplotZone(outfile);
138 for (int j = 0; j < nvariables; ++j)
139 {
140 Vessels[n * nvariables + j]->WriteTecplotField(outfile);
141 }
142
143 Vessels[n * nvariables]->WriteTecplotConnectivity(outfile);
144 }
145 }
146
147 catch (const std::runtime_error &)
148 {
149 return 1;
150 }
151 catch (const std::string &eStr)
152 {
153 cout << "Error: " << eStr << endl;
154 }
155
156 return 0;
157}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
int main(int argc, char *argv[])
Definition: Fld2Tecplot.cpp:52
static std::string SetToOneD
Definition: Fld2Tecplot.cpp:48
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Driver > DriverSharedPtr
A shared pointer to a Driver object.
Definition: Driver.h:52
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:66
std::shared_ptr< EquationSystem > EquationSystemSharedPtr
A shared pointer to an EquationSystem object.
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
std::shared_ptr< PulseWaveSystem > PulseWaveSystemSharedPtr
STL namespace.