OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
sparsenonlinsystemnm.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 - 2014 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 "sparsenonlinsystemnm.h"
36 #include "error.h"
37 #include "domain.h"
38 #include "node.h"
39 #include "unknownnumberingscheme.h"
40 
41 namespace oofem {
42 
45 {
46  IRResultType result; // Required by IR_GIVE_FIELD macro
47 
48  randPertAmplitude = 0.;
50  if ( randPertAmplitude < 0. ) {
51  OOFEM_WARNING("Random pertubation amplitude can not be negative");
52  return IRRT_BAD_FORMAT;
53  }
54  randSeed = 0;
56 
57  // optional parameters related to perturbations of the initial guess (first iteration)
63  if ( ( igp_PertDmanDofSrcArray.giveSize() % 2 ) != 0 ) {
64  OOFEM_WARNING("Pert map size must be an even number, it contains pairs <node, nodeDof>");
65  return IRRT_BAD_FORMAT;
66  }
67  int nsize = igp_PertDmanDofSrcArray.giveSize() / 2;
68  if ( igp_PertWeightArray.giveSize() != nsize ) {
69  OOFEM_WARNING("Pert map size and weight array size mismatch");
70  return IRRT_BAD_FORMAT;
71  }
72  pert_init_needed = true;
73  } else {
74  pert_init_needed = false;
75  }
76  return IRRT_OK;
77 }
78 
79 void
81 {
83  int count = 0, ndofman = this -> domain -> giveNumberOfDofManagers();
84  int size = igp_PertDmanDofSrcArray.giveSize() / 2;
85  igp_Map.resize(size);
86  igp_Weight.resize(size);
87 
88  for ( int j = 1; j <= ndofman; j++ ) {
89  int jglobnum = this->domain->giveNode(j)->giveLabel();
90  for ( int i = 1; i <= size; i++ ) {
91  int inode = igp_PertDmanDofSrcArray.at(2 * i - 1);
92  int idof = igp_PertDmanDofSrcArray.at(2 * i);
93  if ( inode == jglobnum ) {
94  igp_Map.at(++count) = this -> domain ->giveNode(j)->giveDofWithID(idof)->giveEquationNumber(dn);
95  igp_Weight.at(count) = igp_PertWeightArray.at(i);
96  continue;
97  }
98  }
99  }
100 }
101 
102 void
104 {
105  int nsize;
106 
107  // First type of perturbation - random perturbation with uniform probability density
108  // over the interval (-randPertAmplitude,randPertAmplitude) applied on each unknown.
109  if (randPertAmplitude > 0.) {
110  nsize = displacement -> giveSize();
111  srand(randSeed);
112  for ( int i = 1; i <= nsize; i++ ) {
113  double pert = randPertAmplitude * (2. * rand() / RAND_MAX - 1.);
114  displacement->at(i) += pert;
115  }
116  }
117 
118  // Second type of perturbation - only selected unknowns perturbed by the amount specified by the user.
119  if ( pert_init_needed ) {
120  convertPertMap();
121  pert_init_needed = false;
122  }
123 
124  nsize = igp_Weight.giveSize();
125  for ( int i = 1; i <= nsize; i++ ) {
126  int iDof = igp_Map.at(i);
127  double w = igp_Weight.at(i);
128  displacement->at(iDof) += w;
129  }
130 }
131 
132 } // end namespace oofem
The representation of EngngModel default unknown numbering.
#define _IFT_NonLinearStatic_pertw
#define _IFT_NonLinearStatic_randPertAmplitude
virtual void applyPerturbation(FloatArray *displacement)
#define _IFT_NonLinearStatic_pert
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
void clear()
Clears receiver (zero size).
Definition: floatarray.h:206
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
#define _IFT_NonLinearStatic_randSeed
Domain * domain
Pointer to domain.
Definition: nummet.h:84
void clear()
Clears the array (zero size).
Definition: intarray.h:177
int giveLabel() const
Definition: dofmanager.h:502
void resize(int n)
Checks size of receiver towards requested bounds.
Definition: intarray.C:124
Class representing vector of real numbers.
Definition: floatarray.h:82
IRResultType initializeFrom(InputRecord *ir)
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
Class representing the general Input Record.
Definition: inputrecord.h:101
Dof * giveDofWithID(int dofID) const
Returns DOF with given dofID; issues error if not present.
Definition: dofmanager.C:119
double randPertAmplitude
Amplitude of a random perturbation applied on the solution before the iteration process.
int giveEquationNumber(const UnknownNumberingScheme &s)
Returns equation number of receiver for given equation numbering scheme.
Definition: dof.C:56
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:78
int giveSize() const
Definition: intarray.h:203
int giveSize() const
Returns the size of receiver.
Definition: floatarray.h:218
Node * giveNode(int n)
Service for accessing particular domain node.
Definition: domain.h:371
the oofem namespace is to define a context or scope in which all oofem names are defined.
#define OOFEM_WARNING(...)
Definition: error.h:62
void resize(int s)
Resizes receiver towards requested size.
Definition: floatarray.C:631

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