models.hh

Go to the documentation of this file.
1 
7 #ifndef models_hh
8 #define models_hh
9 
10 #include <sys/utsname.h>
11 #include "basics/exceptions.hh"
12 #include "basics/outputOperator.hh"
13 #include "toolbox/inputOutput.hh"
14 #include "formula/formula.hh"
15 #include "geometry/mesh.hh"
16 #include "graphics/matlab.hh"
17 #include "space/space.hh"
18 #include "function/vector.hh"
19 
20 
21 #define ModelControl_formulaOut_D 0
22 
23 namespace concepts {
24 
25  // forward declaration
26  template<class F>
28 
29  template<class F>
30  class ModelControl;
31 
32  // ********************************************************* ModelNotSolved **
33 
38  class ModelNotSolved : public ExceptionBase {};
39 
40  // ********************************************************* MatrixNotBuilt **
41 
46  class MatrixNotBuilt : public ExceptionBase {};
47 
48  // ***************************************************************** Model **
49 
54  template<class F>
55  class Model : public OutputOperator {
56  friend class ModelControlBase<Model<F> >;
57  friend class ModelControl<Model<F> >;
58  public:
59  typedef F type;
60 
62  Model(const std::string problemName);
63  virtual ~Model() {}
65  virtual Space<Real>& space() const = 0;
67  const Vector<F>* solution() {
68  solve_();
69  return sol_.get();
70  }
71  protected:
72  virtual std::ostream& info(std::ostream& os) const;
74  virtual Mesh& mesh_() = 0;
76  virtual const std::string mshAbbr_() = 0;
78  std::unique_ptr<Vector<F> > sol_;
80  virtual void solve_() = 0;
82  const std::string problemName_;
83  };
84 
85  // ****************************************************** ModelControlBase **
86 
93  template<class F>
94  class ModelControlBase : public OutputOperator {
95  public:
98  parameters_.addString("vectorFile", "");
99  }
100  virtual ~ModelControlBase() {}
102  virtual F& model() { return model_; }
103  virtual const F& model() const { return model_; }
105  void loadSolution(const std::string vectorFile);
109  void writeSolution(const std::string vectorFile, bool verbose = true);
113  void basisFunctions(const std::string path = "");
118  const bool store = false,
119  const std::string path = "");
122  return parameters_;
123  }
124  protected:
125  virtual std::ostream& info(std::ostream& os) const;
127  F& model_;
138  virtual std::string filename_(const std::string varname,
139  const std::string path,
140  const bool flag = false);
149  void newfile_(std::string& name, const std::string varname,
150  const std::string ending);
152  template<class G>
154  const std::string frmstr, const std::string name);
155 
156  };
157 
158  template<class F>
159  template<class G>
162  const std::string frmstr, const std::string name)
163  {
165  "Writing formula " << frmstr << " into " << name << ".m");
166  graphics::MatlabGraphics(model_.space(), name.c_str(), frm);
167  parameters_.addString((std::string("grafik_") + frmstr).c_str(),
168  (name + ".m").c_str());
169  }
170 
171  // ********************************************************** ModelControl **
172 
173  template<class F>
174  class ModelControl : public ModelControlBase<F> {
175  public:
177  ModelControl(F& model) : ModelControlBase<F>(model) {}
178  };
179 
180 } // namespace concepts
181 
182 #endif // models_hh
Draws a picture of data in Matlab format and stores the result in a single file.
Definition: matlab.hh:114
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Base class for a model.
Definition: models.hh:55
Base class for controlling a model.
Definition: models.hh:27
Piecewise defined function on a number of cells.
virtual std::string filename_(const std::string varname, const std::string path, const bool flag=false)
Gives a file name for different outputs.
void basisFunctions(const std::string path="")
Writes matlab graphics files for each basis function of the space of the model.
void writeSolution(const std::string vectorFile, bool verbose=true)
Writes solution vector to vectorFile.
virtual Mesh & mesh_()=0
Mesh.
const Vector< F > * solution()
Returns solution vector.
Definition: models.hh:67
Base class for exceptions.
Definition: exceptions.hh:86
Holds parameters in hashes.
Definition: inputOutput.hh:75
virtual ~ModelControlBase()
Definition: models.hh:100
ModelControlBase(F &model)
Constructor.
Definition: models.hh:97
Indicates that a model wasn't solved yet.
Definition: models.hh:38
const std::string problemName_
Name of the problem.
Definition: models.hh:82
ModelControl(F &model)
Constructor.
Definition: models.hh:177
F & model_
The model.
Definition: models.hh:127
#define DEBUGL(doit, msg)
const concepts::InOutParameters & parameters() const
Return parameters of the calculation.
Definition: models.hh:121
void newfile_(std::string &name, const std::string varname, const std::string ending)
Tries, if given file can be opened for writing or if its a path.
#define ModelControl_formulaOut_D
Definition: models.hh:21
virtual const F & model() const
Definition: models.hh:103
virtual ~Model()
Definition: models.hh:63
void addString(const char *name, const char *value)
Adds a string to the hash of strings.
std::unique_ptr< Vector< F > > sol_
Solution vector.
Definition: models.hh:78
Indicates that a needed matrix wasn't build yet.
Definition: models.hh:46
void loadSolution(const std::string vectorFile)
Loads solution vector from vectorFile.
virtual std::ostream & info(std::ostream &os) const
virtual F & model()
Returns the model.
Definition: models.hh:102
virtual void dataOut(concepts::InOutParameters &parameters, const bool store=false, const std::string path="")
Append the parameters of the calculation to parameters and writes it in matlab format if path is give...
virtual Space< Real > & space() const =0
Returns the space.
An abstract class for meshes.
Definition: mesh.hh:76
concepts::InOutParameters parameters_
Parameters of the calculation.
Definition: models.hh:129
virtual const std::string mshAbbr_()=0
Mesh abbreviation string.
void formulaOut_(const concepts::PiecewiseFormulaBase< G > &frm, const std::string frmstr, const std::string name)
graphical output of formulas
Definition: models.hh:161
Model(const std::string problemName)
Constructor.
Class providing an output operator.
virtual void solve_()=0
Method for solving.
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich