OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
modulemanager.h
Go to the documentation of this file.
1 /*
2  *
3  * ##### ##### ###### ###### ### ###
4  * ## ## ## ## ## ## ## ### ##
5  * ## ## ## ## #### #### ## # ##
6  * ## ## ## ## ## ## ## ##
7  * ## ## ## ## ## ## ## ##
8  * ##### ##### ## ###### ## ##
9  *
10  *
11  * OOFEM : Object Oriented Finite Element Code
12  *
13  * Copyright (C) 1993 - 2013 Borek Patzak
14  *
15  *
16  *
17  * Czech Technical University, Faculty of Civil Engineering,
18  * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19  *
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  *
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33  */
34 
35 #ifndef modulemanager_h
36 #define modulemanager_h
37 
38 #include "datareader.h"
39 #include "error.h"
40 
41 #include <memory>
42 #include <vector>
43 
45 
46 #define _IFT_ModuleManager_nmodules "nmodules"
47 
48 
49 namespace oofem {
50 class EngngModel;
51 
56 template< class M >
57 class OOFEM_EXPORT ModuleManager
58 {
59 protected:
61  std :: vector< std :: unique_ptr< M > > moduleList;
66 
67 public:
69  this->emodel = emodel;
70  numberOfModules = 0;
71  }
72  virtual ~ModuleManager() {
73  }
74  ModuleManager(const ModuleManager &) = delete;
75  ModuleManager & operator=(const ModuleManager &) = delete;
82  virtual M *CreateModule(const char *name, int n, EngngModel *emodel) = 0;
95  {
96  IRResultType result; // Required by IR_GIVE_FIELD macro
97 
98  std :: string name;
99 
100  // read modules
101  moduleList.reserve(numberOfModules);
102  for ( int i = 0; i < numberOfModules; i++ ) {
104  result = mir->giveRecordKeywordField(name);
105  if ( result != IRRT_OK ) {
106  IR_IOERR("", mir, result);
107  }
108 
109  // read type of module
110  std :: unique_ptr< M > module( this->CreateModule(name.c_str(), i, emodel) );
111  if ( !module ) {
112  OOFEM_ERROR("unknown module (%s)", name.c_str());
113  }
114 
115  module->initializeFrom(mir);
116  moduleList.push_back(std :: move(module));
117  }
118 
119 # ifdef VERBOSE
120  VERBOSE_PRINT0("Instanciated output modules ", numberOfModules)
121 # endif
122  return 1;
123  }
124 
129  virtual IRResultType initializeFrom(InputRecord *ir) = 0;
131  virtual const char *giveClassName() const = 0;
132 
137  M *giveModule(int num) {
138  M *elem = NULL;
139 
140  if ( num >= 1 && num <= (int)moduleList.size() ) {
141  elem = moduleList[num-1].get();
142  } else {
143  OOFEM_ERROR("No module no. %d defined", num);
144  }
145 
146  return elem;
147  }
148 
149  int giveNumberOfModules() const { return (int)moduleList.size(); }
150 };
151 } // end namespace oofem
152 #endif // modulemanager_h
Class representing and implementing ModuleManager.
Definition: modulemanager.h:57
virtual ~ModuleManager()
Definition: modulemanager.h:72
virtual int instanciateYourself(DataReader &dr, InputRecord *ir)
Reads receiver description from input stream and creates corresponding modules components accordingly...
Definition: modulemanager.h:94
Class representing the abstraction for input data source.
Definition: datareader.h:50
int numberOfModules
Number of modules.
Definition: modulemanager.h:63
#define VERBOSE_PRINT0(str, number)
Definition: verbose.h:56
M * giveModule(int num)
Returns the required module.
virtual IRResultType giveRecordKeywordField(std::string &answer, int &value)=0
Reads the record id field (type of record) and its corresponding number.
#define OOFEM_ERROR(...)
Definition: error.h:61
virtual InputRecord * giveInputRecord(InputRecordType irType, int recordId)=0
Returns input record corresponding to given InputRecordType value and its record_id.
EngngModel * emodel
Associated Engineering model.
Definition: modulemanager.h:65
#define IR_IOERR(__keyword, __ir, __result)
Macro simplifying the error reporting.
Definition: inputrecord.h:60
int giveNumberOfModules() const
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
Class representing the general Input Record.
Definition: inputrecord.h:101
std::vector< std::unique_ptr< M > > moduleList
Module list.
Definition: modulemanager.h:61
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
the oofem namespace is to define a context or scope in which all oofem names are defined.
ModuleManager(EngngModel *emodel)
Definition: modulemanager.h:68

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:30 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011