OOFEM 3.0
Loading...
Searching...
No Matches
polylinenonlocalbarrier.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
36#include "domain.h"
37#include "node.h"
38#include "intarray.h"
39#include "floatarray.h"
40#include "mathfem.h"
41#include "classfactory.h"
42
43namespace oofem {
45
46PolylineNonlocalBarrier :: PolylineNonlocalBarrier(int n, Domain *aDomain) :
47 NonlocalBarrier(n, aDomain), vertexNodes()
48 // Constructor. Creates an element with number n, belonging to aDomain.
49{
50 localXCoordIndx = 1;
51 localYCoordIndx = 2;
52}
53
54
55PolylineNonlocalBarrier :: ~PolylineNonlocalBarrier()
56// Destructor.
57{ }
58
59
60void
61PolylineNonlocalBarrier :: applyConstraint(const double cl, const FloatArray &c1, const FloatArray &c2, double &weight,
62 bool &shieldFlag, const NonlocalMaterialExtensionInterface &nei)
63{
64 if ( this->isActivated(c1, c2) ) {
65 weight = 0.0;
66 shieldFlag = true;
67 } else {
68 shieldFlag = false;
69 }
70}
71
72
73bool
74PolylineNonlocalBarrier :: isActivated(const FloatArray &c1, const FloatArray &c2)
75{
76 int size = vertexNodes.giveSize();
77 int indx;
78 double xc1, xc2, xa, xb, yc1, yc2, ya, yb;
79 double a11, a12, a21, a22, b1, b2, det, t, s;
80 Node *A, *B;
81
82 xc1 = c1.at(localXCoordIndx);
83 yc1 = c1.at(localYCoordIndx);
84 xc2 = c2.at(localXCoordIndx);
85 yc2 = c2.at(localYCoordIndx);
86
87 for ( indx = 1; indx < size; indx++ ) {
88 A = domain->giveNode( vertexNodes.at(indx) );
89 B = domain->giveNode( vertexNodes.at(indx + 1) );
90
95
96 a11 = xc2 - xc1;
97 a12 = xa - xb;
98 a21 = yc2 - yc1;
99 a22 = ya - yb;
100 b1 = xa - xc1;
101 b2 = ya - yc1;
102 det = a11 * a22 - a21 * a12;
103 if ( det == 0 ) {
104 continue;
105 }
106
107 t = ( b1 * a22 - b2 * a12 ) / det;
108 if ( t < 0. || t > 1. ) {
109 continue;
110 }
111
112 s = ( -b1 * a21 + b2 * a11 ) / det;
113 if ( s >= 0. && s <= 1. ) {
114 return true;
115 }
116 }
117
118 return false;
119}
120
121double
122PolylineNonlocalBarrier :: calculateMinimumDistanceFromBoundary(const FloatArray &coords)
123{
124 double min = 1.e10;
125 double tempDistance;
126 //Loop over all linear sections forming the nonlocal boundary to find the minimum distance
127 for ( int i = 1; i < vertexNodes.giveSize(); i++ ) {
128 //Get the coordinates of the vertices
129 FloatArray coordsA(coords);
130 FloatArray coordsB(coords);
131 for ( int j = 1; j <= coords.giveSize(); j++ ) {
132 coordsA.at(j) = domain->giveNode( vertexNodes.at(i) )->giveCoordinate(j);
133 coordsB.at(j) = domain->giveNode( vertexNodes.at(i + 1) )->giveCoordinate(j);
134 }
135
136 //Get the distance from the line segment described by the vertices
137 tempDistance = giveDistancePointLine(coordsA, coordsB, coords);
138 if ( min > tempDistance ) { //Check if it is smaller than the minimum value
139 min = tempDistance;
140 }
141 }
142
143 return min;
144}
145
146double
147PolylineNonlocalBarrier :: giveDistancePointLine(const FloatArray &coordsA, const FloatArray &coordsB, const FloatArray &coordsGP)
148{
149 FloatArray lineAGP(coordsGP); //Line start A, Line End Gauss Point
150 lineAGP.subtract(coordsA);
151 FloatArray lineAB(coordsB); //Line Start A, Line End B
152 lineAB.subtract(coordsA);
153
154 if ( lineAB.computeNorm() == 0. ) { //Check if A,B coincide
155 return lineAGP.computeNorm();
156 }
157
158 //Since vectors AB and AP are collinear and have the same direction: AP=scaleFactor*AB
159 double scaleFactor;
160 scaleFactor = ( lineAGP.dotProduct(lineAB) ) / lineAB.computeSquaredNorm();
161 if ( scaleFactor < 0. || scaleFactor > 1. ) { //Check if P is outside line segment AB
162 FloatArray lineBGP(coordsGP); //Line start B, Line End Gauss Point
163 lineBGP.subtract(coordsB);
164 //Return minimum of A-Gauss Point and B-Gauss Point
165 if ( lineAGP.computeNorm() < lineBGP.computeNorm() ) {
166 return lineAGP.computeNorm();
167 } else {
168 return lineBGP.computeNorm();
169 }
170 } else {
171 // Find coordinates of Point P = A + AB*scaleFactor
172 lineAB.times(scaleFactor);
173 FloatArray coordsP(coordsA);
174 coordsP.add(lineAB);
175 //Calculate distance from Point P to Gauss Point
176 FloatArray linePGP(coordsP); //Line start P, Line End Gauss Point
177 linePGP.subtract(coordsGP);
178 return linePGP.computeNorm();
179 }
180}
181
182
183void
195} // end namespace oofem
#define REGISTER_NonlocalBarrier(class)
double giveCoordinate(int i) const
Definition dofmanager.h:383
Domain * domain
Link to domain object, useful for communicating with other FEM components.
Definition femcmpnn.h:79
double computeNorm() const
Definition floatarray.C:861
double & at(Index i)
Definition floatarray.h:202
double computeSquaredNorm() const
Definition floatarray.C:867
double dotProduct(const FloatArray &x) const
Definition floatarray.C:524
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
void add(const FloatArray &src)
Definition floatarray.C:218
void subtract(const FloatArray &src)
Definition floatarray.C:320
void times(double s)
Definition floatarray.C:834
virtual bool isActivated(const FloatArray &c1, const FloatArray &c2)
double giveDistancePointLine(const FloatArray &coordsA, const FloatArray &coordsB, const FloatArray &coordsGP)
int localXCoordIndx
Local x-coordinate index.
int localYCoordIndx
Local y-coordinate index.
IntArray vertexNodes
List of polyline vertices.
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Definition inputrecord.h:75
#define IR_GIVE_FIELD(__ir, __value, __id)
Definition inputrecord.h:67
FloatArrayF< N > min(const FloatArrayF< N > &a, const FloatArrayF< N > &b)
double det(const FloatMatrixF< 2, 2 > &mat)
Computes the determinant.
#define _IFT_PolylineNonlocalBarrier_vertexnodes
#define _IFT_PolylineNonlocalBarrier_ycoordindx
#define _IFT_PolylineNonlocalBarrier_xcoordindx

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