OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
dummylocalizer.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 "dummylocalizer.h"
36 #include "element.h"
37 #include "domain.h"
38 #include "integrationrule.h"
39 #include "gausspoint.h"
40 #include "node.h"
41 
42 namespace oofem {
43 int
45 {
46  if ( !force && this->initialized ) {
47  return true;
48  }
49 
50  // Count the elements in each cross section.
51  int r;
52  int nregion = this->domain->giveNumberOfRegions();
53  int nelem = this->domain->giveNumberOfElements();
54 
55  IntArray region_nelem(nregion);
56  region_nelem.zero();
57  for ( auto &elem : domain->giveElements() ) {
58  r = elem->giveRegionNumber();
59  region_nelem.at(r)++;
60  }
61 
62  this->region_elements.resize(nregion);
63  // Creates a new int array of correct size for each region
64  for ( int i = 1; i <= nregion; i++ ) {
65  this->region_elements [ i - 1 ].resize( region_nelem.at(i) );
66  }
67  // Add the numbers into the list.
68  IntArray c(nregion);
69  c.zero();
70  for ( int i = 1; i <= nelem; i++ ) {
71  Element *e = this->domain->giveElement(i);
72  r = e->giveRegionNumber();
73  c.at(r)++;
74  this->region_elements [ r - 1 ].at( c.at(r) ) = i;
75  }
76  return this->initialized = true;
77 }
78 
79 Element *
81 {
82  for ( auto &elem : domain->giveElements() ) {
83  SpatialLocalizerInterface *interface = static_cast< SpatialLocalizerInterface * >( elem->giveInterface(SpatialLocalizerInterfaceType) );
84  if ( interface ) {
85  if ( regionList && ( regionList->findFirstIndexOf( elem->giveRegionNumber() ) == 0 ) ) {
86  continue;
87  }
88 
89  if ( interface->SpatialLocalizerI_BBoxContainsPoint(coords) == 0 ) {
90  continue;
91  }
92 
93  if ( interface->SpatialLocalizerI_containsPoint(coords) ) {
94  return elem.get();
95  }
96  }
97  }
98 
99  return NULL;
100 }
101 
102 
103 Element *
105 {
106  int nelems;
107  Element *answer = NULL;
108  double dist = 0.0;
109  FloatArray el_coords, el_lcoords;
110  lcoords.clear();
111  closest.clear();
112 
113  if ( region > 0 ) {
114  IntArray &elems = this->region_elements [ region - 1 ];
115  for ( int ielem = 1; ielem <= elems.giveSize(); ielem++ ) {
116  Element *ielemptr = this->domain->giveElement( elems.at(ielem) );
117  SpatialLocalizerInterface *interface = static_cast< SpatialLocalizerInterface * >( ielemptr->giveInterface(SpatialLocalizerInterfaceType) );
118  if ( interface ) {
119  double currDist = interface->SpatialLocalizerI_giveClosestPoint(el_lcoords, el_coords, coords);
120  if ( answer == NULL || ( currDist < dist && currDist >= 0.0 ) ) {
121  answer = ielemptr;
122  lcoords = el_lcoords;
123  closest = el_coords;
124  dist = currDist;
125  if ( dist == 0.0 ) {
126  break;
127  }
128  }
129  }
130  }
131  } else { // Check them all;
132  nelems = this->giveDomain()->giveNumberOfElements();
133  for ( int ielem = 1; ielem <= nelems; ielem++ ) {
134  Element *ielemptr = this->giveDomain()->giveElement(ielem);
135  SpatialLocalizerInterface *interface = static_cast< SpatialLocalizerInterface * >( ielemptr->giveInterface(SpatialLocalizerInterfaceType) );
136  if ( interface ) {
137  if ( region > 0 && region == ielemptr->giveRegionNumber() ) {
138  continue;
139  }
140 
141  double currDist = interface->SpatialLocalizerI_giveClosestPoint(el_lcoords, el_coords, coords);
142  if ( answer == NULL || ( currDist < dist && currDist >= 0.0 ) ) {
143  answer = ielemptr;
144  lcoords = el_lcoords;
145  closest = el_coords;
146  dist = currDist;
147  if ( dist == 0.0 ) {
148  break;
149  }
150  }
151  }
152  }
153  }
154 
155  return answer;
156 }
157 
158 
159 GaussPoint *
160 DummySpatialLocalizer :: giveClosestIP(const FloatArray &coords, int region, bool iCohesiveZoneGP)
161 {
162  double minDist = 0.0;
163  GaussPoint *answer = NULL;
164  FloatArray jGpCoords;
165 
166  for ( auto &elem : this->giveDomain()->giveElements() ) {
167  if ( ( region < 0 ) || ( region == elem->giveRegionNumber() ) ) {
168  for ( GaussPoint *jGp: *elem->giveDefaultIntegrationRulePtr() ) {
169  if ( elem->computeGlobalCoordinates( jGpCoords, jGp->giveNaturalCoordinates() ) ) {
170  double distance = coords.distance(jGpCoords);
171  if ( answer == NULL || distance < minDist ) {
172  minDist = distance;
173  answer = jGp;
174  }
175  }
176  }
177  }
178  } // loop over elements
179 
180  return answer;
181 }
182 
183 
184 void
186 {
187  int nelem;
188  FloatArray jGpCoords;
189 
190  nelem = this->giveDomain()->giveNumberOfElements();
191  for ( int i = 1; i <= nelem; i++ ) {
192  Element *ielem = this->giveDomain()->giveElement(i);
193  for ( GaussPoint *jGp: *ielem->giveDefaultIntegrationRulePtr() ) {
194  if ( ielem->computeGlobalCoordinates( jGpCoords, jGp->giveNaturalCoordinates() ) ) {
195  double currDist = coords.distance(jGpCoords);
196  if ( currDist <= radius ) {
197  elemSet.insertSortedOnce(i);
198  }
199  }
200  }
201  } // end element loop
202 }
203 
204 
205 void
207 {
208  int nnode = this->giveDomain()->giveNumberOfDofManagers();
209  for ( int i = 1; i <= nnode; i++ ) {
210  DofManager *idofman = this->giveDomain()->giveDofManager(i);
211  Node *inode = dynamic_cast< Node * >(idofman);
212  if ( inode != NULL ) {
213  if ( coords.distance( inode->giveCoordinates() ) <= radius ) {
214  nodeSet.push_back(i);
215  }
216  }
217  }
218 }
219 
220 
221 Node *
223 {
224  Node *closest = NULL;
225  double maxdist = 0.;
226  for ( auto &dman : this->giveDomain()->giveDofManagers() ) {
227  Node *node = dynamic_cast< Node* >( dman.get() );
228  if ( node ) {
229  double dist = coords.distance( node->giveCoordinates() );
230  if ( closest == NULL || dist < maxdist ) {
231  closest = node;
232  maxdist = dist;
233  }
234  }
235  }
236  return maxdist > maxDist ? closest : NULL;
237 }
238 
239 } // end namespace oofem
int giveRegionNumber()
Definition: element.C:507
virtual IntegrationRule * giveDefaultIntegrationRulePtr()
Access method for default integration rule.
Definition: element.h:822
int giveNumberOfDofManagers() const
Returns number of dof managers in domain.
Definition: domain.h:432
void zero()
Sets all component to zero.
Definition: intarray.C:52
void clear()
Clears receiver (zero size).
Definition: floatarray.h:206
bool insertSortedOnce(int value, int allocChunk=0)
Inserts given value into a receiver, which is assumed to be sorted.
Definition: intarray.C:360
Abstract base class for all finite elements.
Definition: element.h:145
Base class for dof managers.
Definition: dofmanager.h:113
virtual void giveAllNodesWithinBox(nodeContainerType &nodeList, const FloatArray &coords, const double radius)
Returns container (list) of all domain nodes within given box.
int giveNumberOfElements() const
Returns number of elements in domain.
Definition: domain.h:434
Class implementing an array of integers.
Definition: intarray.h:61
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
virtual int init(bool force=false)
Initialize receiver data structure if not done previously If force is set to true, the initialization is enforced (useful if domain geometry has changed)
Domain * domain
Link to domain object.
virtual Element * giveElementClosestToPoint(FloatArray &lcoords, FloatArray &closest, const FloatArray &coords, int region=0)
Returns the element closest to a given point.
std::list< int > nodeContainerType
Typedefs to introduce the container type for nodal numbers, returned by some services.
double distance(const FloatArray &x) const
Computes the distance between position represented by receiver and position given as parameter...
Definition: floatarray.C:489
virtual double SpatialLocalizerI_giveClosestPoint(FloatArray &lcoords, FloatArray &closest, const FloatArray &gcoords)
Gives the closest point on the element.
std::vector< IntArray > region_elements
Element * giveElement(int n)
Service for accessing particular domain fe element.
Definition: domain.C:160
virtual GaussPoint * giveClosestIP(const FloatArray &coords, int region, bool iCohesiveZoneGP=false)
Returns the integration point in associated domain, which is closest to given point.
virtual Element * giveElementContainingPoint(const FloatArray &coords, const IntArray *regionList=NULL)
Returns the element, containing given point and belonging to one of the region in region list...
virtual Node * giveNodeClosestToPoint(const FloatArray &coords, double maxDist)
Returns the node closest to the given coordinate.
Class representing vector of real numbers.
Definition: floatarray.h:82
virtual void giveAllElementsWithIpWithinBox(elementContainerType &elemSet, const FloatArray &coords, const double radius)
Returns container (set) of all domain elements having integration point within given box...
virtual Interface * giveInterface(InterfaceType t)
Interface requesting service.
Definition: femcmpnn.h:179
int giveNumberOfRegions() const
Returns number of regions. Currently regions corresponds to cross section models. ...
Definition: domain.h:446
The spatial localizer element interface associated to spatial localizer.
virtual FloatArray * giveCoordinates()
Definition: node.h:114
std::vector< std::unique_ptr< Element > > & giveElements()
Definition: domain.h:279
int giveSize() const
Definition: intarray.h:203
the oofem namespace is to define a context or scope in which all oofem names are defined.
Class implementing node in finite element mesh.
Definition: node.h:87
Domain * giveDomain()
Returns the domain that localizer acts on.
DofManager * giveDofManager(int n)
Service for accessing particular domain dof manager.
Definition: domain.C:314
Class representing integration point in finite element program.
Definition: gausspoint.h:93
virtual int computeGlobalCoordinates(FloatArray &answer, const FloatArray &lcoords)
Computes the global coordinates from given element&#39;s local coordinates.
Definition: element.C:1207
int findFirstIndexOf(int value) const
Finds index of first occurrence of given value in array.
Definition: intarray.C:331

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