Nektar++
DriverStandard.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: DriverStandard.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: Driver class for the standard solver
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <iomanip>
36 
39 
40 using namespace std;
41 
42 namespace Nektar
43 {
44 namespace SolverUtils
45 {
46 string DriverStandard::className = GetDriverFactory().RegisterCreatorFunction(
47  "Standard", DriverStandard::create);
48 string DriverStandard::driverLookupId =
49  LibUtilities::SessionReader::RegisterEnumValue("Driver", "Standard", 0);
50 
51 /**
52  *
53  */
54 DriverStandard::DriverStandard(
57  : Driver(pSession, pGraph)
58 {
59 }
60 
61 /**
62  *
63  */
65 {
66 }
67 
68 /**
69  *
70  */
71 void DriverStandard::v_InitObject(ostream &out)
72 {
74 }
75 
76 void DriverStandard::v_Execute(ostream &out)
77 
78 {
80  NekDouble CPUtime;
81 
82  m_equ[0]->PrintSummary(out);
83 
84  timer.Start();
85 
86  m_equ[0]->DoInitialise();
87  m_equ[0]->DoSolve();
88 
89  timer.Stop();
90 
91  m_equ[0]->Output();
92 
93  if (m_comm->GetRank() == 0)
94  {
95  CPUtime = timer.Elapsed().count();
96  cout << "-------------------------------------------" << endl;
97  cout << "Total Computation Time = " << CPUtime << "s" << endl;
98  cout << "-------------------------------------------" << endl;
99  }
100 
101  // Evaluate and output computation time and solution accuracy.
102  // The specific format of the error output is essential for the
103  // regression tests to work.
104  // Evaluate L2 Error
105  for (int i = 0; i < m_equ[0]->GetNvariables(); ++i)
106  {
107  Array<OneD, NekDouble> exactsoln(m_equ[0]->GetTotPoints(), 0.0);
108 
109  // Evaluate "ExactSolution" function, or zero array
110  m_equ[0]->EvaluateExactSolution(i, exactsoln, m_equ[0]->GetFinalTime());
111 
112  NekDouble vL2Error = m_equ[0]->L2Error(i, exactsoln);
113  NekDouble vLinfError = m_equ[0]->LinfError(i, exactsoln);
114 
115  if (m_comm->GetRank() == 0)
116  {
117  out << "L 2 error (variable " << m_equ[0]->GetVariable(i)
118  << ") : " << vL2Error << endl;
119  out << "L inf error (variable " << m_equ[0]->GetVariable(i)
120  << ") : " << vLinfError << endl;
121  }
122  }
123 }
124 } // namespace SolverUtils
125 } // namespace Nektar
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
Base class for the development of solvers.
Definition: Driver.h:67
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout)
Definition: Driver.cpp:87
LibUtilities::CommSharedPtr m_comm
Communication object.
Definition: Driver.h:85
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
Definition: Driver.h:97
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout) override
Second-stage initialisation.
virtual SOLVER_UTILS_EXPORT void v_Execute(std::ostream &out=std::cout) override
Virtual function for solve implementation.
virtual SOLVER_UTILS_EXPORT ~DriverStandard()
Destructor.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:64
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:172
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble