OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
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 - 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 #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 
46 #include <sstream>
47 
48 namespace oofem {
50 {
51  DynamicInputRecord *result = new DynamicInputRecord(nodeType, i);
52  result->setField(std :: move(coord), _IFT_Node_coords);
53  return result;
54 }
55 
56 DynamicInputRecord *CreateElementIR(int i, InputFieldType elementType, IntArray nodes, int cs)
57 {
58  DynamicInputRecord *result = new DynamicInputRecord(elementType, i);
59  result->setField(std :: move(nodes), _IFT_Element_nodes);
60  if ( cs != 0 ) {
61  result->setField(cs, _IFT_Element_crosssect);
62  }
63  return result;
64 }
65 
66 
67 DynamicInputRecord :: DynamicInputRecord(std :: string keyword, int value) : InputRecord(),
68  recordKeyword(keyword),
69  recordNumber(value),
70  emptyRecord(),
71  intRecord(),
72  doubleRecord(),
73  boolRecord(),
74  stringRecord(),
75  floatArrayRecord(),
76  intArrayRecord(),
77  matrixRecord(),
78  stringListRecord(),
79  dictionaryRecord(),
80  rangeRecord()
81 { }
82 
84  recordKeyword(),
85  recordNumber(0),
86  emptyRecord(),
87  intRecord(),
88  doubleRecord(),
89  boolRecord(),
90  stringRecord(),
93  matrixRecord(),
96  rangeRecord()
97 {
98  femc.giveInputRecord(* this);
99 }
100 
105  intRecord(src.intRecord),
107  boolRecord(src.boolRecord),
115 { }
116 
118 { }
119 
121 {
122  this->recordKeyword = src.recordKeyword;
123  this->recordNumber = src.recordNumber;
124  this->emptyRecord = src.emptyRecord;
125  this->intRecord = src.intRecord;
126  this->doubleRecord = src.doubleRecord;
127  this->boolRecord = src.boolRecord;
128  this->stringRecord = src.stringRecord;
130  this->intArrayRecord = src.intArrayRecord;
131  this->matrixRecord = src.matrixRecord;
134  this->rangeRecord = src.rangeRecord;
135 
136  return * this;
137 }
138 
140 {
142 }
143 
145 {
146  answer = this->recordKeyword;
147  value = this->recordNumber;
148  return IRRT_OK;
149 }
150 
152 {
153  answer = this->recordKeyword;
154  return IRRT_OK;
155 }
156 
158 {
159  std :: map< std :: string, int > :: iterator it = this->intRecord.find(id);
160  if ( it == this->intRecord.end() ) {
161  return IRRT_NOTFOUND;
162  }
163  answer = it->second;
164  return IRRT_OK;
165 }
166 
168 {
169  std :: map< std :: string, double > :: iterator it = this->doubleRecord.find(id);
170  if ( it == this->doubleRecord.end() ) {
171  return IRRT_NOTFOUND;
172  }
173  answer = it->second;
174  return IRRT_OK;
175 }
176 
178 {
179  std :: map< std :: string, bool > :: iterator it = this->boolRecord.find(id);
180  if ( it == this->boolRecord.end() ) {
181  return IRRT_NOTFOUND;
182  }
183  answer = it->second;
184  return IRRT_OK;
185 }
186 
188 {
189  std :: map< std :: string, std :: string > :: iterator it = this->stringRecord.find(id);
190  if ( it == this->stringRecord.end() ) {
191  return IRRT_NOTFOUND;
192  }
193  answer = it->second;
194  return IRRT_OK;
195 }
196 
198 {
199  std :: map< std :: string, FloatArray > :: iterator it = this->floatArrayRecord.find(id);
200  if ( it == this->floatArrayRecord.end() ) {
201  return IRRT_NOTFOUND;
202  }
203  answer = it->second;
204  return IRRT_OK;
205 }
206 
208 {
209  std :: map< std :: string, IntArray > :: iterator it = this->intArrayRecord.find(id);
210  if ( it == this->intArrayRecord.end() ) {
211  return IRRT_NOTFOUND;
212  }
213  answer = it->second;
214  return IRRT_OK;
215 }
216 
218 {
219  std :: map< std :: string, FloatMatrix > :: iterator it = this->matrixRecord.find(id);
220  if ( it == this->matrixRecord.end() ) {
221  return IRRT_NOTFOUND;
222  }
223  answer = it->second;
224  return IRRT_OK;
225 }
226 
227 IRResultType DynamicInputRecord :: giveField(std :: vector< std :: string > &answer, InputFieldType id)
228 {
229  std :: map< std :: string, std :: vector< std :: string > > :: iterator it = this->stringListRecord.find(id);
230  if ( it == this->stringListRecord.end() ) {
231  return IRRT_NOTFOUND;
232  }
233  answer = it->second;
234  return IRRT_OK;
235 }
236 
238 {
239  std :: map< std :: string, Dictionary > :: iterator it = this->dictionaryRecord.find(id);
240  if ( it == this->dictionaryRecord.end() ) {
241  return IRRT_NOTFOUND;
242  }
243  answer = it->second;
244  return IRRT_OK;
245 }
246 
248 {
249  std :: map< std :: string, std :: list< Range > > :: iterator it = this->rangeRecord.find(id);
250  if ( it == this->rangeRecord.end() ) {
251  return IRRT_NOTFOUND;
252  }
253  answer = it->second;
254  return IRRT_OK;
255 }
256 
258 {
259  std :: map< std :: string, ScalarFunction > :: iterator it = this->scalarFunctionRecord.find(id);
260  if ( it == this->scalarFunctionRecord.end() ) {
261  return IRRT_NOTFOUND;
262  }
263  answer = it->second;
264  return IRRT_OK;
265 }
266 
268 {
269  return this->emptyRecord.find(id) != this->emptyRecord.end() ||
270  this->intRecord.find(id) != this->intRecord.end() ||
271  this->doubleRecord.find(id) != this->doubleRecord.end() ||
272  this->boolRecord.find(id) != this->boolRecord.end() ||
273  this->floatArrayRecord.find(id) != this->floatArrayRecord.end() ||
274  this->intArrayRecord.find(id) != this->intArrayRecord.end() ||
275  this->matrixRecord.find(id) != this->matrixRecord.end() ||
276  this->stringListRecord.find(id) != this->stringListRecord.end() ||
277  this->dictionaryRecord.find(id) != this->dictionaryRecord.end() ||
278  this->rangeRecord.find(id) != this->rangeRecord.end();
279 }
280 
281 void
283 {
284  //printf( "%s", this->record );
285 }
286 
287 // Setters
288 void DynamicInputRecord :: setRecordKeywordField(std :: string keyword, int value)
289 {
290  this->recordKeyword = std :: move(keyword);
291  this->recordNumber = value;
292 }
293 
295 {
296  this->recordNumber = value;
297 }
298 
300 {
301  this->intRecord [ id ] = item;
302 }
303 
305 {
306  this->doubleRecord [ id ] = item;
307 }
308 
310 {
311  this->boolRecord [ id ] = item;
312 }
313 
314 void DynamicInputRecord :: setField(std :: string item, InputFieldType id)
315 {
316  this->stringRecord [ id ] = item;
317 }
318 
320 {
321  this->floatArrayRecord [id] = std :: move(item);
322 }
323 
325 {
326  this->intArrayRecord [id] = std :: move(item);
327 }
328 
330 {
331  this->matrixRecord [id] = std :: move(item);
332 }
333 
334 void DynamicInputRecord :: setField(std :: vector< std :: string > item, InputFieldType id)
335 {
336  this->stringListRecord [id] = std :: move(item);
337 }
338 
340 {
341  this->dictionaryRecord [ id ] = item;
342 }
343 
344 void DynamicInputRecord :: setField(const std :: list< Range > &item, InputFieldType id)
345 {
346  this->rangeRecord [ id ] = item;
347 }
348 
350 {
351  this->scalarFunctionRecord [ id ] = item;
352 }
353 
355 {
356  this->emptyRecord.insert(id);
357 }
358 
360 {
361  this->emptyRecord.erase(id);
362  this->intRecord.erase(id);
363  this->doubleRecord.erase(id);
364  this->boolRecord.erase(id);
365  this->stringRecord.erase(id);
366  this->floatArrayRecord.erase(id);
367  this->intArrayRecord.erase(id);
368  this->matrixRecord.erase(id);
369  this->stringListRecord.erase(id);
370  this->dictionaryRecord.erase(id);
371  this->rangeRecord.erase(id);
372  this->scalarFunctionRecord.erase(id);
373 }
374 
375 void
376 DynamicInputRecord :: report_error(const char *_class, const char *proc, InputFieldType id,
377  IRResultType result, const char *file, int line)
378 {
380  "Input error: \"%s\", field keyword \"%s\"\n%s::%s",
381  strerror(result), id, _class, proc);
382  OOFEM_EXIT(1);
383 }
384 
385 // Helpful macro since we have so many separate records
386 #define forRecord(name) \
387  for ( const auto &x: name ) { \
388  rec << " " << x.first << " " << x.second; \
389  }
390 
392 {
393  std :: ostringstream rec;
394  rec << this->recordKeyword;
395  // Some records aren't numbered, here we assume that if no number is set (default 0) then it's not printed.
396  // Though, technically, some things *could* be numbered arbitrarily (even negative), this is never actually done in practice.
397  if ( this->recordNumber > 0 ) {
398  rec << " " << this->recordNumber;
399  }
400 
401  // Empty fields
402  for ( const auto &x: emptyRecord ) {
403  rec << " " << x;
404  }
405 
406  // Standard fields;
416 
417  // Have to write special code for std::vector and std::list
418  for ( const auto &x: stringListRecord ) {
419  rec << " " << x.first;
420  const std :: vector< std :: string > &list = x.second;
421  rec << " " << list.size();
422  for ( const auto &y: list ) {
423  rec << " " << y;
424  }
425  }
426 
427  for ( const auto &x: rangeRecord ) {
428  rec << " " << x.first;
429  const std :: list< Range > &list = x.second;
430  rec << " " << list.size();
431  for ( const auto &y: list ) {
432  rec << " " << y;
433  }
434  }
435 
436  return rec.str();
437 }
438 };
void setField(int item, InputFieldType id)
std::map< std::string, bool > boolRecord
virtual ~DynamicInputRecord()
Destructor.
std::map< std::string, FloatMatrix > matrixRecord
virtual void finish(bool wrn=true)
Terminates the current record session and if the flag is true, warning is printed for unscanned token...
DynamicInputRecord & operator=(const DynamicInputRecord &)
Assignment operator.
const char * strerror(IRResultType)
Returns error string corresponding to given value of IRResultType type.
Definition: inputrecord.C:49
DynamicInputRecord * CreateElementIR(int i, InputFieldType elementType, IntArray nodes, int cs)
Helper function for creating elements (with optional cross-section number).
void unsetField(InputFieldType id)
Removes given field from record.
virtual std::string giveRecordAsString() const
Returns string representation of record in OOFEMs text format.
std::set< std::string > emptyRecord
Fields without values.
std::map< std::string, double > doubleRecord
virtual void printYourself()
Print input record.
const char * InputFieldType
Identifier of fields in input records.
Definition: inputrecord.h:52
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
Definition: femcmpnn.C:77
Class implementing an array of integers.
Definition: intarray.h:61
std::map< std::string, FloatArray > floatArrayRecord
void writeELogMsg(logLevelType level, const char *_func, const char *_file, int _line, const char *format,...)
Writes extended log message with file and line info.
Definition: logger.C:265
void setRecordKeywordNumber(int number)
virtual IRResultType giveField(int &answer, InputFieldType id)
Reads the integer field value.
virtual bool hasField(InputFieldType id)
Returns true if record contains field identified by idString keyword.
std::map< std::string, ScalarFunction > scalarFunctionRecord
std::map< std::string, std::list< Range > > rangeRecord
DynamicInputRecord(std::string answer="", int value=0)
Creates an empty input record.
#define _IFT_Element_nodes
Definition: element.h:65
DynamicInputRecord * CreateNodeIR(int i, InputFieldType nodeType, FloatArray coord)
Helper function for creating a dynamic input record for a node.
std::map< std::string, IntArray > intArrayRecord
Logger oofem_logger(Logger::LOG_LEVEL_INFO)
Definition: logger.h:115
std::map< std::string, std::vector< std::string > > stringListRecord
This class implements a linked list whose entries are Pairs (see below).
Definition: dictionary.h:58
Class representing vector of real numbers.
Definition: floatarray.h:82
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
Implementation of Scalar function.
#define _IFT_Element_crosssect
Definition: element.h:64
std::map< std::string, std::string > stringRecord
#define OOFEM_EXIT(code)
Cause oofem program termination by calling exit.
Definition: error.h:50
#define forRecord(name)
Class representing the general Input Record.
Definition: inputrecord.h:101
std::map< std::string, Dictionary > dictionaryRecord
Class representing the a dynamic Input Record.
#define _IFT_Node_coords
Definition: node.h:50
void setRecordKeywordField(std::string keyword, int number)
virtual void report_error(const char *_class, const char *proc, InputFieldType id, IRResultType result, const char *file, int line)
Prints the error message.
the oofem namespace is to define a context or scope in which all oofem names are defined.
virtual IRResultType giveRecordKeywordField(std::string &answer, int &value)
Reads the record id field (type of record) and its corresponding number.
std::map< std::string, int > intRecord
The top abstract class of all classes constituting the finite element mesh.
Definition: femcmpnn.h:76

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:28 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011