OOFEM 3.0
Loading...
Searching...
No Matches
dynamicinputrecord.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 "dynamicinputrecord.h"
36#include "femcmpnn.h"
37#include "intarray.h"
38#include "floatarray.h"
39#include "floatmatrix.h"
40#include "dictionary.h"
41#include "range.h"
42#include "node.h"
43#include "element.h"
44#include "scalarfunction.h"
45#include "paramkey.h"
46
47#include <sstream>
48
49namespace oofem {
50std::unique_ptr<DynamicInputRecord> CreateNodeIR(int i, InputFieldType nodeType, FloatArray coord)
51{
52 auto result = std::make_unique<DynamicInputRecord>(nodeType, i);
53 result->setField(std :: move(coord), _IFT_Node_coords);
54 return result;
55}
56
57std::unique_ptr<DynamicInputRecord> CreateElementIR(int i, InputFieldType elementType, IntArray nodes, int cs)
58{
59 auto result = std::make_unique<DynamicInputRecord>(elementType, i);
60 result->setField(std :: move(nodes), Element::IPK_Element_nodes.getName().c_str());
61 if ( cs != 0 ) {
62 result->setField(cs, Element::IPK_Element_crosssect.getName().c_str());
63 }
64 return result;
65}
66
67
68DynamicInputRecord :: DynamicInputRecord(std :: string keyword, int value) :
69 recordKeyword(std::move(keyword)),
70 recordNumber(value),
72 intRecord(),
74 boolRecord(),
82{ }
83
84DynamicInputRecord :: DynamicInputRecord(FEMComponent &femc) :
86 recordNumber(0),
88 intRecord(),
90 boolRecord(),
98{
99 femc.giveInputRecord(* this);
100}
101
117
118DynamicInputRecord :: ~DynamicInputRecord()
119{ }
120
121DynamicInputRecord &DynamicInputRecord :: operator = ( const DynamicInputRecord & src )
122{
123 this->recordKeyword = src.recordKeyword;
124 this->recordNumber = src.recordNumber;
125 this->emptyRecord = src.emptyRecord;
126 this->intRecord = src.intRecord;
127 this->doubleRecord = src.doubleRecord;
128 this->boolRecord = src.boolRecord;
129 this->stringRecord = src.stringRecord;
131 this->intArrayRecord = src.intArrayRecord;
132 this->matrixRecord = src.matrixRecord;
135 this->rangeRecord = src.rangeRecord;
136
137 return * this;
138}
139
140
141int DynamicInputRecord::giveGroupCount(InputFieldType id, const std::string& name, bool optional){
142 OOFEM_ERROR("DynamicInputRecord::giveNestedCount: not implemented.");
143}
144
145bool DynamicInputRecord::hasChild(InputFieldType id, const std::string& name, bool optional){
146 OOFEM_ERROR("DynamicInputRecord::hasChild: not implemented.");
147}
148
149
150void DynamicInputRecord :: finish(bool wrn)
151{
153}
154
155void DynamicInputRecord :: giveRecordKeywordField(std :: string &answer, int &value)
156{
157 answer = this->recordKeyword;
158 value = this->recordNumber;
159}
160
161void DynamicInputRecord :: giveRecordKeywordField(std :: string &answer)
162{
163 answer = this->recordKeyword;
164}
165
166void DynamicInputRecord :: giveField(int &answer, InputFieldType id)
167{
168 std :: map< std :: string, int > :: iterator it = this->intRecord.find(id);
169 if ( it == this->intRecord.end() ) {
171 }
172 answer = it->second;
173}
174
175void DynamicInputRecord :: giveField(double &answer, InputFieldType id)
176{
177 std :: map< std :: string, double > :: iterator it = this->doubleRecord.find(id);
178 if ( it == this->doubleRecord.end() ) {
179 // try to look in intRecord
180 std :: map< std :: string, int > :: iterator it2 = this->intRecord.find(id);
181 if ( it2 == this->intRecord.end() ) {
183 }
184 answer = it2->second;
185 }
186 answer = it->second;
187}
188
189void DynamicInputRecord :: giveField(bool &answer, InputFieldType id)
190{
191 std :: map< std :: string, bool > :: iterator it = this->boolRecord.find(id);
192 if ( it == this->boolRecord.end() ) {
194 }
195 answer = it->second;
196}
197
198void DynamicInputRecord :: giveField(std :: string &answer, InputFieldType id)
199{
200 std :: map< std :: string, std :: string > :: iterator it = this->stringRecord.find(id);
201 if ( it == this->stringRecord.end() ) {
203 }
204 answer = it->second;
205}
206
207void DynamicInputRecord :: giveField(FloatArray &answer, InputFieldType id)
208{
209 std :: map< std :: string, FloatArray > :: iterator it = this->floatArrayRecord.find(id);
210 if ( it == this->floatArrayRecord.end() ) {
212 }
213 answer = it->second;
214}
215
216void DynamicInputRecord :: giveField(IntArray &answer, InputFieldType id)
217{
218 std :: map< std :: string, IntArray > :: iterator it = this->intArrayRecord.find(id);
219 if ( it == this->intArrayRecord.end() ) {
221 }
222 answer = it->second;
223}
224
225void DynamicInputRecord :: giveField(FloatMatrix &answer, InputFieldType id)
226{
227 std :: map< std :: string, FloatMatrix > :: iterator it = this->matrixRecord.find(id);
228 if ( it == this->matrixRecord.end() ) {
230 }
231 answer = it->second;
232}
233
234void DynamicInputRecord :: giveField(std :: vector< std :: string > &answer, InputFieldType id)
235{
236 std :: map< std :: string, std :: vector< std :: string > > :: iterator it = this->stringListRecord.find(id);
237 if ( it == this->stringListRecord.end() ) {
239 }
240 answer = it->second;
241}
242
243void DynamicInputRecord :: giveField(Dictionary &answer, InputFieldType id)
244{
245 std :: map< std :: string, Dictionary > :: iterator it = this->dictionaryRecord.find(id);
246 if ( it == this->dictionaryRecord.end() ) {
248 }
249 answer = it->second;
250}
251
252void DynamicInputRecord :: giveField(std :: list< Range > &answer, InputFieldType id)
253{
254 std :: map< std :: string, std :: list< Range > > :: iterator it = this->rangeRecord.find(id);
255 if ( it == this->rangeRecord.end() ) {
257 }
258 answer = it->second;
259}
260
261void DynamicInputRecord :: giveField(ScalarFunction &answer, InputFieldType id)
262{
263 std :: map< std :: string, ScalarFunction > :: iterator it = this->scalarFunctionRecord.find(id);
264 if ( it == this->scalarFunctionRecord.end() ) {
266 }
267 answer = it->second;
268}
269
270bool DynamicInputRecord :: hasField(InputFieldType id)
271{
272 return this->emptyRecord.find(id) != this->emptyRecord.end() ||
273 this->intRecord.find(id) != this->intRecord.end() ||
274 this->doubleRecord.find(id) != this->doubleRecord.end() ||
275 this->boolRecord.find(id) != this->boolRecord.end() ||
276 this->floatArrayRecord.find(id) != this->floatArrayRecord.end() ||
277 this->intArrayRecord.find(id) != this->intArrayRecord.end() ||
278 this->matrixRecord.find(id) != this->matrixRecord.end() ||
279 this->stringListRecord.find(id) != this->stringListRecord.end() ||
280 this->dictionaryRecord.find(id) != this->dictionaryRecord.end() ||
281 this->rangeRecord.find(id) != this->rangeRecord.end();
282}
283
284void
285DynamicInputRecord :: printYourself()
286{
287 //printf( "%s", this->record );
288}
289
290// Setters
291void DynamicInputRecord :: setRecordKeywordField(std :: string keyword, int value)
292{
293 this->recordKeyword = std :: move(keyword);
294 this->recordNumber = value;
295}
296
297void DynamicInputRecord :: setRecordKeywordNumber(int value)
298{
299 this->recordNumber = value;
300}
301
302void DynamicInputRecord :: setField(int item, InputFieldType id)
303{
304 this->intRecord [ id ] = item;
305}
306
307void DynamicInputRecord :: setField(double item, InputFieldType id)
308{
309 this->doubleRecord [ id ] = item;
310}
311
312void DynamicInputRecord :: setField(bool item, InputFieldType id)
313{
314 this->boolRecord [ id ] = item;
315}
316
317void DynamicInputRecord :: setField(std :: string item, InputFieldType id)
318{
319 this->stringRecord [ id ] = item;
320}
321
322void DynamicInputRecord :: setField(FloatArray item, InputFieldType id)
323{
324 this->floatArrayRecord [id] = std :: move(item);
325}
326
327void DynamicInputRecord :: setField(IntArray item, InputFieldType id)
328{
329 this->intArrayRecord [id] = std :: move(item);
330}
331
332void DynamicInputRecord :: setField(FloatMatrix item, InputFieldType id)
333{
334 this->matrixRecord [id] = std :: move(item);
335}
336
337void DynamicInputRecord :: setField(std :: vector< std :: string > item, InputFieldType id)
338{
339 this->stringListRecord [id] = std :: move(item);
340}
341
342void DynamicInputRecord :: setField(const Dictionary &item, InputFieldType id)
343{
344 this->dictionaryRecord [ id ] = item;
345}
346
347void DynamicInputRecord :: setField(const std :: list< Range > &item, InputFieldType id)
348{
349 this->rangeRecord [ id ] = item;
350}
351
352void DynamicInputRecord :: setField(const ScalarFunction &item, InputFieldType id)
353{
354 this->scalarFunctionRecord [ id ] = item;
355}
356
357void DynamicInputRecord :: setField(InputFieldType id)
358{
359 this->emptyRecord.insert(id);
360}
361
362void DynamicInputRecord :: unsetField(InputFieldType id)
363{
364 this->emptyRecord.erase(id);
365 this->intRecord.erase(id);
366 this->doubleRecord.erase(id);
367 this->boolRecord.erase(id);
368 this->stringRecord.erase(id);
369 this->floatArrayRecord.erase(id);
370 this->intArrayRecord.erase(id);
371 this->matrixRecord.erase(id);
372 this->stringListRecord.erase(id);
373 this->dictionaryRecord.erase(id);
374 this->rangeRecord.erase(id);
375 this->scalarFunctionRecord.erase(id);
376}
377
378
379// Helpful macro since we have so many separate records
380#define forRecord(name) \
381 for ( const auto &x: name ) { \
382 rec << " " << x.first << " " << x.second; \
383 }
384
385
386std :: string DynamicInputRecord :: giveLocation() const { return "<DynamicInputRecord>"; }
387std :: string DynamicInputRecord :: giveRecordInTXTFormat() const
388{
389 std :: ostringstream rec;
390 rec << this->recordKeyword;
391 // Some records aren't numbered, here we assume that if no number is set (default 0) then it's not printed.
392 // Though, technically, some things *could* be numbered arbitrarily (even negative), this is never actually done in practice.
393 if ( this->recordNumber > 0 ) {
394 rec << " " << this->recordNumber;
395 }
396
397 // Empty fields
398 for ( const auto &x: emptyRecord ) {
399 rec << " " << x;
400 }
401
402 // Standard fields;
412
413 // Have to write special code for std::vector and std::list
414 for ( const auto &x: stringListRecord ) {
415 rec << " " << x.first;
416 const std :: vector< std :: string > &list = x.second;
417 rec << " " << list.size();
418 for ( const auto &y: list ) {
419 rec << " " << y;
420 }
421 }
422
423 for ( const auto &x: rangeRecord ) {
424 rec << " " << x.first;
425 const std :: list< Range > &list = x.second;
426 rec << " " << list.size();
427 for ( const auto &y: list ) {
428 rec << " " << y;
429 }
430 }
431
432 return rec.str();
433}
434};
std ::map< std ::string, std ::list< Range > > rangeRecord
std ::map< std ::string, std ::string > stringRecord
std ::map< std ::string, FloatArray > floatArrayRecord
int giveGroupCount(InputFieldType id, const std::string &name, bool optional) override
DynamicInputRecord(std ::string answer="", int value=0)
Creates an empty input record.
std ::map< std ::string, double > doubleRecord
std ::map< std ::string, ScalarFunction > scalarFunctionRecord
std ::set< std ::string > emptyRecord
Fields without values.
std ::map< std ::string, std ::vector< std ::string > > stringListRecord
std ::map< std ::string, bool > boolRecord
std ::map< std ::string, IntArray > intArrayRecord
std ::map< std ::string, FloatMatrix > matrixRecord
std ::map< std ::string, int > intRecord
std ::map< std ::string, Dictionary > dictionaryRecord
bool hasChild(InputFieldType id, const std::string &name, bool optional) override
static ParamKey IPK_Element_crosssect
Definition element.h:199
static ParamKey IPK_Element_nodes
Definition element.h:200
virtual void giveInputRecord(DynamicInputRecord &input)
Definition femcmpnn.C:73
#define forRecord(name)
#define OOFEM_ERROR(...)
Definition error.h:79
std::unique_ptr< DynamicInputRecord > CreateElementIR(int i, InputFieldType elementType, IntArray nodes, int cs)
Helper function for creating elements (with optional cross-section number).
std::unique_ptr< DynamicInputRecord > CreateNodeIR(int i, InputFieldType nodeType, FloatArray coord)
Helper function for creating a dynamic input record for a node.
const char * InputFieldType
Identifier of fields in input records.
Definition inputrecord.h:59
#define _IFT_Node_coords
Definition node.h:53

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