JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGSimplexTrim.h
1 /*
2  * FGSimplexTrim.h
3  * Copyright (C) James Goppert 2010 <james.goppert@gmail.com>
4  *
5  * FGSimplexTrim.h is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * FGSimplexTrim.h is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef FGSimplexTrim_H_
20 #define FGSimplexTrim_H_
21 
22 #include "initialization/FGTrimmer.h"
23 #include "math/FGStateSpace.h"
24 #include <iomanip>
25 #include <fstream>
26 #include "models/FGAircraft.h"
27 #include "models/propulsion/FGEngine.h"
28 #include "models/propulsion/FGTurbine.h"
29 #include "models/propulsion/FGTurboProp.h"
30 #include "math/FGNelderMead.h"
31 #include <stdexcept>
32 #include <fstream>
33 #include <cstdlib>
34 
35 namespace JSBSim {
36 
38 {
39 public:
40  FGSimplexTrim(FGFDMExec * fdmPtr, TrimMode mode);
41 private:
42  template <class varType>
43  void prompt(const std::string & str, varType & var)
44  {
45  std::cout << str + " [" << std::setw(10) << var << "]\t: ";
46  if (std::cin.peek() != '\n')
47  {
48  std::cin >> var;
49  std::cin.ignore(1000, '\n');
50  }
51  else std::cin.get();
52  }
53 
54  class Callback : public JSBSim::FGNelderMead::Callback
55  {
56  private:
57  std::ofstream _outputFile;
58  JSBSim::FGTrimmer * _trimmer;
59  public:
60  Callback(std::string fileName, JSBSim::FGTrimmer * trimmer) :
61  _outputFile((fileName + std::string("_simplexTrim.log")).c_str()),
62  _trimmer(trimmer) {
63  }
64  virtual ~Callback() {
65  _outputFile.close();
66  }
67  void eval(const std::vector<double> &v)
68  {
69  _outputFile << _trimmer->eval(v) << std::endl;;
70  //std::cout << "v: ";
71  //for (int i=0;i<v.size();i++) std::cout << v[i] << " ";
72  //std::cout << std::endl;
73  }
74  };
75 };
76 
77 } // JSBSim
78 
79 #endif //FGSimplexTrim_H_
80 
81 // vim:ts=4:sw=4
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:189