OOFEM 3.0
Loading...
Searching...
No Matches
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 - 2025 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#include "exportmodule.h"
41
42
43#include <memory>
44#include <vector>
45
47
48#define _IFT_ModuleManager_nmodules "nmodules"
50
51namespace oofem {
52class EngngModel;
53
58template< class M >
60{
61protected:
63 std::vector< std::unique_ptr< M > > moduleList;
67 EngngModel *emodel = nullptr;
68
69public:
71 this->emodel = emodel;
73 }
74 virtual ~ModuleManager() {
75 }
76 ModuleManager(const ModuleManager &) = delete;
84 virtual std::unique_ptr<M> CreateModule(const char *name, int n, EngngModel *emodel) = 0;
96 virtual int instanciateYourself(DataReader &dr, const std::shared_ptr<InputRecord>& irPtr, InputFieldType ift, const std::string& name, DataReader::InputRecordType irType)
97 {
98 // read modules
99 DataReader::GroupRecords modRecs=dr.giveGroupRecords(irPtr,ift,name,irType,/*optional*/true);
100 moduleList.reserve(modRecs.size());
101 int modIndex0=0;
102 for (auto& mir: modRecs){
103 std::string modName;
104 mir.giveRecordKeywordField(modName);
105
106 // read type of module
107 std :: unique_ptr< M > module = this->CreateModule(modName.c_str(), modIndex0, emodel);
108 if ( !module ) {
109 OOFEM_ERROR("unknown module (%s)", modName.c_str());
110 }
111
112 module->initializeFrom(mir);
113 registerModule(module);
114 modIndex0++;
115 }
116
117 # ifdef VERBOSE
118 VERBOSE_PRINT0("Instanciated %d modules", numberOfModules);
119 # endif
120 return 1;
121 }
122
127
128 virtual void registerModule (std::unique_ptr< M > &module){
129 moduleList.push_back(std::move(module));
130 }
131
132
134 virtual const char *giveClassName() const = 0;
135
140 M *giveModule(int num) {
141 M *elem = NULL;
142
143 if ( num >= 1 && num <= (int)moduleList.size() ) {
144 elem = moduleList[num-1].get();
145 } else {
146 OOFEM_ERROR("No module no. %d defined", num);
147 }
148
149 return elem;
150 }
151
152 int giveNumberOfModules() const { return (int)moduleList.size(); }
153};
154
156
157} // end namespace oofem
158#endif // modulemanager_h
Internal range-like class, return type for giveGroupRecords methods.
Definition datareader.h:137
InputRecordType
Determines the type of input record.
Definition datareader.h:64
GroupRecords giveGroupRecords(const std::shared_ptr< InputRecord > &ir, InputFieldType ift, const std::string &name, InputRecordType irType, bool optional)
Definition datareader.C:46
ModuleManager(EngngModel *emodel)
virtual std::unique_ptr< M > CreateModule(const char *name, int n, EngngModel *emodel)=0
virtual void registerModule(std::unique_ptr< M > &module)
int giveNumberOfModules() const
ModuleManager & operator=(const ModuleManager &)=delete
EngngModel * emodel
Associated Engineering model.
int numberOfModules
Number of modules.
virtual int instanciateYourself(DataReader &dr, const std::shared_ptr< InputRecord > &irPtr, InputFieldType ift, const std::string &name, DataReader::InputRecordType irType)
virtual const char * giveClassName() const =0
Returns class name of the receiver.
ModuleManager(const ModuleManager &)=delete
M * giveModule(int num)
std::vector< std::unique_ptr< M > > moduleList
Module list.
#define OOFEM_ERROR(...)
Definition error.h:79
const char * InputFieldType
Identifier of fields in input records.
Definition inputrecord.h:59
#define OOFEM_EXPORT
Definition oofemcfg.h:7
#define VERBOSE_PRINT0(str, number)
Definition verbose.h:56

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011