OOFEM 3.0
Loading...
Searching...
No Matches
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 - 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 "dummylocalizer.h"
36#include "element.h"
37#include "domain.h"
38#include "integrationrule.h"
39#include "gausspoint.h"
40#include "node.h"
41
42namespace oofem {
43int
44DummySpatialLocalizer :: init(bool force)
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
79Element *
80DummySpatialLocalizer :: giveElementContainingPoint(const FloatArray &coords, const IntArray *regionList)
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
103Element *
104DummySpatialLocalizer :: giveElementClosestToPoint(FloatArray &lcoords, FloatArray &closest, const FloatArray &coords, int region)
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) );
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);
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
160DummySpatialLocalizer :: giveClosestIP(const FloatArray &coords, int region, bool iCohesiveZoneGP)
161{
162 double minDist = 0.0;
163 GaussPoint *answer = nullptr;
164 FloatArray jGpCoords;
165
166 for ( auto &elem : this->giveDomain()->giveElements() ) {
167 if ( ( region < 0 ) || ( region == elem->giveRegionNumber() ) ) {
168 for ( auto &jGp: *elem->giveDefaultIntegrationRulePtr() ) {
169 if ( elem->computeGlobalCoordinates( jGpCoords, jGp->giveNaturalCoordinates() ) ) {
170 double dist = distance(coords, jGpCoords);
171 if ( answer == nullptr || dist < minDist ) {
172 minDist = dist;
173 answer = jGp;
174 }
175 }
176 }
177 }
178 } // loop over elements
179
180 return answer;
181}
182
183
184void
185DummySpatialLocalizer :: giveAllElementsWithIpWithinBox(elementContainerType &elemSet, const FloatArray &coords, const double radius)
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 ( auto &jGp: *ielem->giveDefaultIntegrationRulePtr() ) {
194 if ( ielem->computeGlobalCoordinates( jGpCoords, jGp->giveNaturalCoordinates() ) ) {
195 double currDist = distance(coords, jGpCoords);
196 if ( currDist <= radius ) {
197 elemSet.insertSortedOnce(i);
198 }
199 }
200 }
201 } // end element loop
202}
203
204
205void
206DummySpatialLocalizer :: giveAllNodesWithinBox(nodeContainerType &nodeSet, const FloatArray &coords, const double radius)
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 ) {
213 if ( distance(coords, inode->giveCoordinates()) <= radius ) {
214 nodeSet.push_back(i);
215 }
216 }
217 }
218}
219
220
221Node *
222DummySpatialLocalizer :: giveNodeClosestToPoint(const FloatArray &coords, double maxDist)
223{
224 Node *closest = nullptr;
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 = distance(coords, node->giveCoordinates());
230 if ( closest == nullptr || dist < maxdist ) {
231 closest = node;
232 maxdist = dist;
233 }
234 }
235 }
236 return maxdist > maxDist ? closest : nullptr;
237}
238
239} // end namespace oofem
const FloatArray & giveCoordinates() const
Definition dofmanager.h:390
std ::vector< IntArray > region_elements
virtual int computeGlobalCoordinates(FloatArray &answer, const FloatArray &lcoords)
Definition element.C:1225
virtual IntegrationRule * giveDefaultIntegrationRulePtr()
Definition element.h:886
int giveRegionNumber()
Definition element.C:546
virtual Interface * giveInterface(InterfaceType t)
Definition femcmpnn.h:181
bool insertSortedOnce(int value, int allocChunk=0)
Definition intarray.C:309
void zero()
Sets all component to zero.
Definition intarray.C:52
int findFirstIndexOf(int value) const
Definition intarray.C:280
int & at(std::size_t i)
Definition intarray.h:104
int giveSize() const
Definition intarray.h:211
Domain * domain
Link to domain object.
Domain * giveDomain()
Returns the domain that localizer acts on.
std ::list< int > nodeContainerType
Typedefs to introduce the container type for nodal numbers, returned by some services.
IntArray elementContainerType
Typedefs to introduce the container type for element numbers, returned by some services.
@ SpatialLocalizerInterfaceType
double distance(const FloatArray &x, const FloatArray &y)

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