OOFEM 3.0
Loading...
Searching...
No Matches
fieldmanager.C
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#include "fieldmanager.h"
36#include "datareader.h"
37#include "inputrecord.h"
38#include "classfactory.h"
39
40namespace oofem {
41FieldManager :: ~FieldManager()
42{ }
43
44void
45FieldManager :: registerField(std :: shared_ptr< Field >eField, FieldType key)
46{
47 if (this->externalFields.find(key) == this->externalFields.end()) {
48 this->externalFields.insert({key, eField});
49 } else {
50 this->externalFields.at(key)=eField;
51 }
54}
55
56
57
58
59bool
60FieldManager :: isFieldRegistered(FieldType key)
61{
62 return ( this->externalFields.find(key) != this->externalFields.end() );
63}
64
65std :: shared_ptr< Field >
66FieldManager :: giveField(FieldType key)
67{
68 auto i = this->externalFields.find(key);
69 if ( i == this->externalFields.end() ) {
70 std :: shared_ptr< Field >p; // std::shared_ptr<Field> p(nullptr);
71 return p;
72 }
73
74 return i->second;
75}
76
77void
78FieldManager :: unregisterField(FieldType key)
79{
80 auto i = this->externalFields.find(key);
81 if ( i == this->externalFields.end() ) {
82 return;
83 }
84
85 this->externalFields.erase(i);
86}
87
88std::vector<FieldType>
89FieldManager :: giveRegisteredKeys()
90{
91 std::vector<FieldType> ret;
92 for(const auto& keyField: this->externalFields) ret.push_back(keyField.first);
93 return ret;
94}
95
96
97
99{
100 for(auto& fieldRecord: dr.giveGroupRecords(ir.ptr(),"nfields","Fields",DataReader::IR_fieldRec,/*optional*/true)){
101 std :: string fname;
102 fieldRecord.giveRecordKeywordField(fname);
103 std :: shared_ptr< Field > fieldPtr = classFactory.createField(fname.c_str());
104 if ( !fieldPtr ) {
105 OOFEM_ERROR("unknown field name (%s)", fname.c_str());
106 }
107 fieldPtr->initializeFrom(fieldRecord);
108 registerField(fieldPtr, fieldPtr->giveType());
109 }
110 return 1;
111}
112
113} // end namespace oofem
GroupRecords giveGroupRecords(const std::shared_ptr< InputRecord > &ir, InputFieldType ift, const std::string &name, InputRecordType irType, bool optional)
Definition datareader.C:46
int instanciateYourself(DataReader &dr, InputRecord &ir)
std ::map< FieldType, std ::shared_ptr< Field > > externalFields
void registerField(FieldPtr eField, FieldType key)
std::shared_ptr< InputRecord > ptr()
#define OOFEM_ERROR(...)
Definition error.h:79
FieldType
Physical type of field.
Definition field.h:64
ClassFactory & classFactory

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