OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
set.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 "set.h"
36 #include "error.h"
37 #include "intarray.h"
38 #include "inputrecord.h"
39 #include "domain.h"
40 #include "element.h"
41 #include "node.h"
42 #include "range.h"
43 #include "feinterpol.h"
44 #include "feinterpol2d.h"
45 #include "feinterpol3d.h"
46 #include "contextioerr.h"
47 #include "dynamicinputrecord.h"
48 #include <list>
49 
50 namespace oofem {
52 {
53  IRResultType result;
54 
55  IntArray inputNodes;
56  std :: list< Range >inputNodeRanges;
57  if ( ir->hasField(_IFT_Set_allNodes) ) { // generate a list with all the node numbers
58  this->nodes.enumerate(this->giveDomain()->giveNumberOfDofManagers());
59  } else {
60  IR_GIVE_OPTIONAL_FIELD(ir, inputNodes, _IFT_Set_nodes);
61  IR_GIVE_OPTIONAL_FIELD(ir, inputNodeRanges, _IFT_Set_nodeRanges);
62  this->computeIntArray(this->nodes, inputNodes, inputNodeRanges);
63  }
64 
65  if ( ir->hasField(_IFT_Set_allElements) ) { // generate a list with all the element numbers
66  this->elements.enumerate(this->giveDomain()->giveNumberOfElements());
67  mElementListIsSorted = false;
68  } else {
69  IntArray inputElements;
70  std :: list< Range >inputElementRanges;
71  IR_GIVE_OPTIONAL_FIELD(ir, inputElements, _IFT_Set_elements);
72  IR_GIVE_OPTIONAL_FIELD(ir, inputElementRanges, _IFT_Set_elementRanges);
73  this->computeIntArray(this->elements, inputElements, inputElementRanges);
74  mElementListIsSorted = false;
75  }
76 
77 
78  this->elementBoundaries.clear();
80 
81  this->elementEdges.clear();
83 
84  this->elementSurfaces.clear();
86 
88 }
89 
90 
92 {
94 
95  if ( this->giveNodeList().giveSize() ) {
96  input.setField(this->nodes, _IFT_Set_nodes);
97  }
98  if ( this->giveElementList().giveSize() ) {
99  input.setField(this->elements, _IFT_Set_elements);
100  }
101  if ( this->giveBoundaryList().giveSize() ) {
103  }
104  if ( this->giveEdgeList().giveSize() ) {
106  }
107  if ( this->giveSurfaceList().giveSize() ) {
109  }
110 }
111 
112 
113 void Set :: computeIntArray(IntArray &answer, const IntArray &specified, std :: list< Range >ranges)
114 {
115  // Find the max value;
116  int maxIndex = specified.giveSize() == 0 ? 0 : specified.maximum();
117  for ( auto &range: ranges ) {
118  if ( range.giveEnd() > maxIndex ) {
119  maxIndex = range.giveEnd();
120  }
121  }
122  IntArray afflictedNodes(maxIndex);
123  afflictedNodes.zero();
124 
125  for ( int i = 1; i <= specified.giveSize(); ++i ) {
126  afflictedNodes.at( specified.at(i) ) = 1;
127  }
128 
129  for ( auto &range: ranges ) {
130  for ( int i = range.giveStart(); i <= range.giveEnd(); ++i ) {
131  afflictedNodes.at(i) = 1;
132  }
133  }
134  answer.findNonzeros(afflictedNodes);
135 }
136 
137 
139 
141 
143 
145 
147 {
148  // Lazy evaluation, we compute the unique set of nodes if needed (and store it).
149  if ( this->totalNodes.giveSize() == 0 ) {
150  IntArray afflictedNodes( this->domain->giveNumberOfDofManagers() );
151  afflictedNodes.zero();
152  for ( int ielem = 1; ielem <= this->elements.giveSize(); ++ielem ) {
153  Element *e = this->domain->giveElement( this->elements.at(ielem) );
154  for ( int inode = 1; inode <= e->giveNumberOfNodes(); ++inode ) {
155  afflictedNodes.at( e->giveNode(inode)->giveNumber() ) = 1;
156  }
157  }
158 
159  /* boundary entities are obsolete, use edges and/or surfaces instead */
160  IntArray bNodes;
161  for ( int ibnd = 1; ibnd <= this->elementBoundaries.giveSize() / 2; ++ibnd ) {
162  Element *e = this->domain->giveElement( this->elementBoundaries.at(ibnd * 2 - 1) );
163  int boundary = this->elementBoundaries.at(ibnd * 2);
165  fei->boundaryGiveNodes(bNodes, boundary);
166  for ( int inode = 1; inode <= bNodes.giveSize(); ++inode ) {
167  afflictedNodes.at( e->giveNode( bNodes.at(inode) )->giveNumber() ) = 1;
168  }
169  }
170 
171  IntArray eNodes;
172  for ( int iedge = 1; iedge <= this->elementEdges.giveSize() / 2; ++iedge ) {
173  Element *e = this->domain->giveElement( this->elementEdges.at(iedge * 2 - 1) );
174  int edge = this->elementEdges.at(iedge * 2);
176  fei->boundaryEdgeGiveNodes(eNodes, edge);
177  for ( int inode = 1; inode <= eNodes.giveSize(); ++inode ) {
178  afflictedNodes.at( e->giveNode( eNodes.at(inode) )->giveNumber() ) = 1;
179  }
180  }
181 
182  for ( int isurf = 1; isurf <= this->elementSurfaces.giveSize() / 2; ++isurf ) {
183  Element *e = this->domain->giveElement( this->elementSurfaces.at(isurf * 2 - 1) );
184  int surf = this->elementSurfaces.at(isurf * 2);
186  fei->boundarySurfaceGiveNodes(eNodes, surf);
187  for ( int inode = 1; inode <= eNodes.giveSize(); ++inode ) {
188  afflictedNodes.at( e->giveNode( eNodes.at(inode) )->giveNumber() ) = 1;
189  }
190  }
191 
192 
193 
194  for ( int inode = 1; inode <= this->nodes.giveSize(); ++inode ) {
195  afflictedNodes.at( this->nodes.at(inode) ) = 1;
196  }
197  totalNodes.findNonzeros(afflictedNodes);
198  }
199  return this->totalNodes;
200 }
201 
202 const IntArray &Set :: giveSpecifiedNodeList() { return this->nodes; }
203 
204 void Set :: setElementList(IntArray newElements) { this->elements = std :: move(newElements); mElementListIsSorted = false; }
205 
206 void Set :: setBoundaryList(IntArray newBoundaries) { this->elementBoundaries = std :: move(newBoundaries); }
207 
208 void Set :: setEdgeList(IntArray newEdges) { this->elementEdges = std :: move(newEdges); }
209 
210 void Set :: setNodeList(IntArray newNodes) { this->nodes = std :: move(newNodes); }
211 
213 {
214  this->elements.enumerate(this->giveDomain()->giveNumberOfElements());
215  mElementListIsSorted = false;
216 }
217 
218 bool Set :: hasElement(int number) const
219 {
220  if(!mElementListIsSorted) {
223  mElementListIsSorted = true;
224  }
225  return std :: binary_search(mElementsSorted.begin(), mElementsSorted.end(), number);
226 }
227 
229 {
230  this->elementEdges.clear();
231  this->elementBoundaries.clear();
232  this->elements.clear();
233  this->nodes.clear();
234  this->totalNodes.clear();
235 }
236 
238 {
239  this->updateLocalNodeNumbering(f);
241 }
242 
244 {
245  for ( int i = 1; i <= nodes.giveSize(); i++ ) {
246  nodes.at(i) = f(nodes.at(i), ERS_DofManager);
247  }
248 }
249 
251 {
252  for ( int i = 1; i <= elements.giveSize(); i++ ) {
253  elements.at(i) = f(elements.at(i), ERS_Element);
254  }
256  for ( int i = 1; i <= elementBoundaries.giveSize(); i += 2 ) {
258  }
259  for ( int i = 1; i <= elementEdges.giveSize(); i += 2 ) {
261  }
262 
263  mElementListIsSorted = false;
264 }
265 
266 
268 {
269  contextIOResultType iores;
270 
271  if ( ( iores = FEMComponent :: saveContext(stream, mode, obj) ) != CIO_OK ) {
272  THROW_CIOERR(iores);
273  }
274 
275  if ( ( mode & CM_Definition ) ) {
276  if ( ( iores = elements.storeYourself(stream) ) != CIO_OK ) {
277  THROW_CIOERR(iores);
278  }
279  if ( ( iores = elementBoundaries.storeYourself(stream) ) != CIO_OK ) {
280  THROW_CIOERR(iores);
281  }
282  if ( ( iores = elementEdges.storeYourself(stream) ) != CIO_OK ) {
283  THROW_CIOERR(iores);
284  }
285  if ( ( iores = nodes.storeYourself(stream) ) != CIO_OK ) {
286  THROW_CIOERR(iores);
287  }
288  }
289 
290  return CIO_OK;
291 }
292 
294 {
295  contextIOResultType iores;
296 
297  if ( ( iores = FEMComponent :: restoreContext(stream, mode, obj) ) != CIO_OK ) {
298  THROW_CIOERR(iores);
299  }
300 
301  if ( mode & CM_Definition ) {
302  if ( ( iores = elements.restoreYourself(stream) ) != CIO_OK ) {
303  THROW_CIOERR(iores);
304  }
305  if ( ( iores = elementBoundaries.restoreYourself(stream) ) != CIO_OK ) {
306  THROW_CIOERR(iores);
307  }
308  if ( ( iores = elementEdges.restoreYourself(stream) ) != CIO_OK ) {
309  THROW_CIOERR(iores);
310  }
311  if ( ( iores = nodes.restoreYourself(stream) ) != CIO_OK ) {
312  THROW_CIOERR(iores);
313  }
314  }
315 
316  this->totalNodes.clear();
317 
318  return CIO_OK;
319 }
320 }
void setField(int item, InputFieldType id)
contextIOResultType storeYourself(DataStream &stream) const
Stores array to output stream.
Definition: intarray.C:289
void enumerate(int maxVal)
Resizes receiver and enumerates from 1 to the maximum value given.
Definition: intarray.C:136
int number
Component number.
Definition: femcmpnn.h:80
IntArray elementEdges
Element numbers + boundary numbers (interleaved).
Definition: set.h:73
const IntArray & giveSurfaceList()
Returns list of element surfaces within set.
Definition: set.C:144
Domain * domain
Link to domain object, useful for communicating with other FEM components.
Definition: femcmpnn.h:82
int giveNumberOfDofManagers() const
Returns number of dof managers in domain.
Definition: domain.h:432
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
Definition: set.C:91
const IntArray & giveBoundaryList()
Returns list of element boundaries within set.
Definition: set.C:140
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
Definition: datastream.h:54
void zero()
Sets all component to zero.
Definition: intarray.C:52
void setBoundaryList(IntArray newBoundaries)
Sets list of element boundaries within set.
Definition: set.C:206
#define _IFT_Set_Name
Definition: set.h:46
virtual void boundarySurfaceGiveNodes(IntArray &answer, int boundary)=0
Gives the boundary nodes for requested boundary number.
bool mElementListIsSorted
Definition: set.h:70
virtual bool hasField(InputFieldType id)=0
Returns true if record contains field identified by idString keyword.
Abstract base class for all finite elements.
Definition: element.h:145
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Stores receiver state to output stream.
Definition: femcmpnn.C:51
std::vector< int >::iterator end()
Definition: intarray.h:71
#define _IFT_Set_elementBoundaries
Interleaved array of element index + boundary number.
Definition: set.h:53
IntArray elementBoundaries
Definition: set.h:72
#define _IFT_Set_allElements
Will generate a list of att the elements in the domain)
Definition: set.h:51
void findNonzeros(const IntArray &logical)
Finds all indices where the input array is nonzero.
Definition: intarray.C:206
Class implementing an array of integers.
Definition: intarray.h:61
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
void setElementList(IntArray newElements)
Sets list of elements within set.
Definition: set.C:204
#define THROW_CIOERR(e)
Definition: contextioerr.h:61
virtual FEInterpolation * giveInterpolation() const
Definition: element.h:629
void sort()
Sorts array.
Definition: intarray.C:420
IntArray elements
Element numbers.
Definition: set.h:69
virtual int giveNumberOfNodes() const
Returns number of nodes of receiver.
Definition: element.h:662
Class representing a general abstraction for finite element interpolation class.
Definition: feinterpol.h:132
IntArray nodes
Element numbers + surface numbers (interleaved).
Definition: set.h:75
#define _IFT_Set_elements
List of specific element indices.
Definition: set.h:50
Element * giveElement(int n)
Service for accessing particular domain fe element.
Definition: domain.C:160
virtual void boundaryEdgeGiveNodes(IntArray &answer, int boundary)=0
Gives the boundary nodes for requested boundary number.
IntArray elementSurfaces
Element numbers + edge numbers (interleaved).
Definition: set.h:74
void clear()
Clears the array (zero size).
Definition: intarray.h:177
void setEdgeList(IntArray newEdges)
Sets list of element edges within set (must be edges of 3D elements).
Definition: set.C:208
const IntArray & giveNodeList()
Returns list of all nodes within set.
Definition: set.C:146
int maximum() const
Finds the maximum component in the array.
Definition: intarray.C:195
const IntArray & giveEdgeList()
Returns list of element edges within set (must be edges of 3D elements).
Definition: set.C:142
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Definition: femcmpnn.C:89
void computeIntArray(IntArray &answer, const IntArray &specified, std::list< Range >ranges)
Converts list ranges to list of individual values + individually specified values.
Definition: set.C:113
#define _IFT_Set_nodes
List of specific node indices.
Definition: set.h:47
void updateLocalNodeNumbering(EntityRenumberingFunctor &f)
Renumbering of nodes (could change due to load balancing).
Definition: set.C:243
virtual void updateLocalNumbering(EntityRenumberingFunctor &f)
Local renumbering support.
Definition: set.C:237
#define _IFT_Set_elementEdges
Interleaved array of element index + edge number.
Definition: set.h:54
IntArray mElementsSorted
Definition: set.h:71
contextIOResultType restoreYourself(DataStream &stream)
Restores array from image on stream.
Definition: intarray.C:305
virtual void boundaryGiveNodes(IntArray &answer, int boundary)=0
Gives the boundary nodes for requested boundary number.
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
Class representing the general Input Record.
Definition: inputrecord.h:101
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Restores the receiver state previously written in stream.
Definition: set.C:293
const IntArray & giveSpecifiedNodeList()
Returns list of all directly specified nodes (excluding those generated from elements).
Definition: set.C:202
#define _IFT_Set_elementRanges
List of element index ranges.
Definition: set.h:52
void addAllElements()
Initialize the element set to contain all elements in the receiver domain.
Definition: set.C:212
Class representing the a dynamic Input Record.
IntArray totalNodes
Unique set of nodes (computed).
Definition: set.h:76
long ContextMode
Context mode (mask), defining the type of information written/read to/from context.
Definition: contextmode.h:43
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Definition: set.C:51
#define CM_Definition
Definition: contextmode.h:47
void setRecordKeywordField(std::string keyword, int number)
Domain * giveDomain() const
Definition: femcmpnn.h:100
std::vector< int >::iterator begin()
Definition: intarray.h:70
void setNodeList(IntArray newNodes)
Sets list of nodes within set.
Definition: set.C:210
#define _IFT_Set_elementSurfaces
Interleaved array of element index + surface number.
Definition: set.h:55
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Restores the receiver state previously written in stream.
Definition: femcmpnn.C:64
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:78
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Stores receiver state to output stream.
Definition: set.C:267
void clear()
Clears the entire set.
Definition: set.C:228
int giveSize() const
Definition: intarray.h:203
#define _IFT_Set_allNodes
List of specific node indices.
Definition: set.h:48
the oofem namespace is to define a context or scope in which all oofem names are defined.
void updateLocalElementNumbering(EntityRenumberingFunctor &f)
Renumbering of nodes (could change due to load balancing).
Definition: set.C:250
int giveNumber() const
Definition: femcmpnn.h:107
Node * giveNode(int i) const
Returns reference to the i-th node of element.
Definition: element.h:610
bool hasElement(int elem) const
Return True if given element is contained.
Definition: set.C:218
#define _IFT_Set_nodeRanges
List of node index ranges.
Definition: set.h:49
const IntArray & giveElementList()
Returns list of elements within set.
Definition: set.C:138

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