OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
directerrorindicatorrc.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 "../sm/ErrorEstimators/directerrorindicatorrc.h"
36 #include "errorestimator.h"
37 #include "domain.h"
38 #include "element.h"
39 #include "dofmanager.h"
40 #include "engngm.h"
41 #include "connectivitytable.h"
42 #include "mathfem.h"
43 #include "timestep.h"
44 
45 #ifdef __PARALLEL_MODE
46  #include "problemcomm.h"
47 #endif
48 
49 namespace oofem {
51 {
52  stateCounter = -1;
53 #ifdef __PARALLEL_MODE
55 #endif
56 }
57 
59 {
60 }
61 
62 void
63 DirectErrorIndicatorRC :: giveNodeChar(int inode, TimeStep *tStep, double &indicatorVal, double &currDensity)
64 {
65  currDensity = this->giveDofManDensity(inode);
66  indicatorVal = this->giveDofManIndicator(inode, tStep);
67 }
68 
69 
70 double
72 {
73 #ifdef __PARALLEL_MODE
74  Domain *d = this->giveDomain();
75  if ( d->giveDofManager(num)->isShared() ) {
76  return this->sharedDofManDensities [ num ];
77  } else {
78  return this->giveLocalDofManDensity(num);
79  }
80 
81 #else
82  return this->giveLocalDofManDensity(num);
83 
84 #endif
85 }
86 
87 double
89 {
90  int isize;
91  double currDensity = 0.0;
92  const IntArray *con;
93  Domain *d = this->giveDomain();
95 
96  con = ct->giveDofManConnectivityArray(num);
97  isize = con->giveSize();
98 
99  for ( int i = 1; i <= isize; i++ ) {
100  // ask for indicator variable value and determine current mesh density
101  Element *element = d->giveElement( con->at(i) );
102 
103  if ( i == 1 ) {
104  currDensity = element->computeMeanSize();
105  } else {
106  currDensity = max( currDensity, element->computeMeanSize() );
107  }
108  }
109 
110  return currDensity;
111 }
112 
113 
114 double
116 {
117 #ifdef __PARALLEL_MODE
118  Domain *d = this->giveDomain();
119  if ( d->giveDofManager(num)->isShared() ) {
120  return this->sharedDofManIndicatorVals [ num ];
121  } else {
122  return this->giveLocalDofManIndicator(num, tStep);
123  }
124 
125 #else
126  return this->giveLocalDofManIndicator(num, tStep);
127 
128 #endif
129 }
130 
131 double
133 {
134  int isize;
135  const IntArray *con;
136  Domain *d = this->giveDomain();
138  double indicatorVal = 0.0;
139 
140  con = ct->giveDofManConnectivityArray(inode);
141  isize = con->giveSize();
142 
143  for ( int i = 1; i <= isize; i++ ) {
144  // ask for indicator variable value and determine current mesh density
145  Element *element = d->giveElement( con->at(i) );
146 
147  if ( i == 1 ) {
148  indicatorVal = ee->giveElementError(indicatorET, element, tStep);
149  } else {
150  indicatorVal = max( indicatorVal, ee->giveElementError(indicatorET, element, tStep) );
151  }
152  }
153 
154  return indicatorVal;
155 }
156 
157 
158 
159 int
161 {
162  Domain *d = this->giveDomain();
163  int inode, nnodes = d->giveNumberOfDofManagers();
164  double indicatorVal, currDensity, proposedDensity;
165 
166  if ( stateCounter == tStep->giveSolutionStateCounter() ) {
167  return 1;
168  }
169 
170 #ifdef __PARALLEL_MODE
171  if ( initCommMap ) {
173  OOFEM_LOG_INFO("DirectErrorIndicatorRC :: estimateMeshDensities: initialized comm maps\n");
174  initCommMap = false;
175  }
176 
177 
178  this->exchangeDofManDensities();
179  this->exchangeDofManIndicatorVals(tStep);
180 #endif
181 
183  this->nodalDensities.resize(nnodes);
184 
185  for ( inode = 1; inode <= nnodes; inode++ ) {
186  this->giveNodeChar(inode, tStep, indicatorVal, currDensity);
187 
188  if ( indicatorVal < minIndicatorLimit ) {
189  this->nodalDensities.at(inode) = zeroIndicatorDensity; //currDensity;
190  } else if ( indicatorVal >= maxIndicatorLimit ) {
191  this->nodalDensities.at(inode) = proposedDensity = maxIndicatorDensity;
192 
193  if ( proposedDensity < ( currDensity * this->remeshingDensityRatioToggle ) ) {
195  OOFEM_LOG_DEBUG("DirectEI: remeshing required for node %d, den %e, required_dens %e\n", inode, currDensity, proposedDensity);
196  }
197  } else {
198  // evaluate the required size
199  proposedDensity = minIndicatorDensity +
201  //proposedDensity = min (currDensity, proposedDensity);
202  this->nodalDensities.at(inode) = proposedDensity;
203 
204  if ( proposedDensity < ( currDensity * this->remeshingDensityRatioToggle ) ) {
205  OOFEM_LOG_DEBUG("DirectEI: remeshing required for node %d, den %e, required_dens %e\n", inode, currDensity, proposedDensity);
207  }
208  }
209  }
210 
211 #ifdef __PARALLEL_MODE
212  // exchange strategies between nodes to ensure consistency
213  int myStrategy = this->currStrategy, globalStrategy;
214  MPI_Allreduce(& myStrategy, & globalStrategy, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
215  this->currStrategy = ( RemeshingStrategy ) globalStrategy;
216 #endif
217 
218  // remember time stamp
220  return 1;
221 }
222 
223 
224 double
226 {
227  this->estimateMeshDensities(tStep);
228  if ( relative ) {
229  double currDens;
230  currDens = this->giveDofManDensity(num);
231  return this->nodalDensities.at(num) / currDens;
232  } else {
233  return this->nodalDensities.at(num);
234  }
235 }
236 
237 
240 {
241  IRResultType result; // Required by IR_GIVE_FIELD macro
242 
248 
251 
252 #ifdef __PARALLEL_MODE
253  EngngModel *emodel = domain->giveEngngModel();
255  communicator = new NodeCommunicator(emodel, commBuff, emodel->giveRank(),
256  emodel->giveNumberOfProcesses());
257 #endif
258  return IRRT_OK;
259 }
260 
263 {
264  this->estimateMeshDensities(tStep);
265  return this->currStrategy;
266 }
267 
268 void
270 {
271  stateCounter = -1;
272 #ifdef __PARALLEL_MODE
274  initCommMap = true;
275 #endif
276 }
277 
278 
279 void
281 {
283 #ifdef __PARALLEL_MODE
285  initCommMap = true;
286 #endif
287 }
288 
289 
290 #ifdef __PARALLEL_MODE
291 void
293 {
294  Domain *domain = this->giveDomain();
295 
296  if ( this->dofManDensityExchangeFlag ) {
298  sharedDofManDensities.clear();
299  int size = domain->giveNumberOfDofManagers();
300  for ( int i = 1; i <= size; i++ ) {
301  if ( domain->giveDofManager(i)->giveParallelMode() == DofManager_shared ) {
303  }
304  }
305 
306  // exchange them
311 
312  this->dofManDensityExchangeFlag = false;
313  } // if (this->dofManDensityExchangeFlag)
314 }
315 
316 int
318 {
319  int result = 1, i, size;
321  IntArray const *toSendMap = processComm.giveToSendMap();
322 
323  size = toSendMap->giveSize();
324  for ( i = 1; i <= size; i++ ) {
325  result &= pcbuff->write(this->sharedDofManDensities [ toSendMap->at(i) ]);
326  }
327 
328  return result;
329 }
330 
331 int
333 {
334  int result = 1;
335  int i, size;
336  IntArray const *toRecvMap = processComm.giveToRecvMap();
338  double value;
339 
340  size = toRecvMap->giveSize();
341  for ( i = 1; i <= size; i++ ) {
342  result &= pcbuff->read(value);
343  this->sharedDofManDensities [ toRecvMap->at(i) ] = max(value, this->sharedDofManDensities [ toRecvMap->at(i) ]);
344  #ifdef __VERBOSE_PARALLEL
345  OOFEM_LOG_INFO("unpackSharedDofManLocalDensities: node %d[%d], value %f\n", toRecvMap->at(i), domain->giveDofManager( toRecvMap->at(i) )->giveGlobalNumber(), this->sharedDofManDensities [ toRecvMap->at(i) ]);
346  #endif
347  }
348 
349  return result;
350 }
351 
352 
353 
354 
355 void
357 {
358  Domain *domain = this->giveDomain();
359 
362  int size = domain->giveNumberOfDofManagers();
363  for ( int i = 1; i <= size; i++ ) {
364  if ( domain->giveDofManager(i)->giveParallelMode() == DofManager_shared ) {
365  sharedDofManIndicatorVals [ i ] = this->giveLocalDofManIndicator(i, tStep);
366  }
367  }
368 
369  // exchange them
374 }
375 
376 int
378 {
379  int result = 1, i, size;
380  //Domain *d = this->giveDomain();
382  IntArray const *toSendMap = processComm.giveToSendMap();
383 
384  size = toSendMap->giveSize();
385  for ( i = 1; i <= size; i++ ) {
386  result &= pcbuff->write(this->sharedDofManIndicatorVals [ toSendMap->at(i) ]);
387  }
388 
389  return result;
390 }
391 
392 int
394 {
395  int result = 1;
396  int i, size;
397  IntArray const *toRecvMap = processComm.giveToRecvMap();
399  double value;
400 
401  size = toRecvMap->giveSize();
402  for ( i = 1; i <= size; i++ ) {
403  result &= pcbuff->read(value);
404  this->sharedDofManIndicatorVals [ toRecvMap->at(i) ] = max(value, this->sharedDofManIndicatorVals [ toRecvMap->at(i) ]);
405  #ifdef __VERBOSE_PARALLEL
406  OOFEM_LOG_INFO("unpackSharedDofManLocalIndicatorVals: node %d[%d], value %f\n", toRecvMap->at(i), domain->giveDofManager( toRecvMap->at(i) )->giveGlobalNumber(), this->sharedDofManIndicatorVals [ toRecvMap->at(i) ]);
407  #endif
408  }
409 
410  return result;
411 }
412 
413 
414 #endif
415 } // end namespace oofem
double giveDofManIndicator(int num, TimeStep *tStep)
Returns dof man indicator values.
double giveLocalDofManIndicator(int num, TimeStep *tStep)
#define _IFT_DirectErrorIndicatorRC_minlim
The base class for all remeshing criteria.
Definition: remeshingcrit.h:61
int initExchange(int tag)
Initializes data exchange with all problems.
Definition: communicator.C:104
double remeshingDensityRatioToggle
Ratio between proposedDensity and currDensity.
DirectErrorIndicatorRC(int n, ErrorEstimator *e)
Constructor.
Class and object Domain.
Definition: domain.h:115
Domain * domain
Link to domain object, useful for communicating with other FEM components.
Definition: femcmpnn.h:82
double computeMeanSize()
Computes the size of the element defined as its length.
Definition: element.C:1078
int giveNumberOfDofManagers() const
Returns number of dof managers in domain.
Definition: domain.h:432
int packAllData(T *ptr, int(T::*packFunc)(ProcessCommunicator &))
Pack all problemCommunicators data to their send buffers.
Definition: communicator.h:223
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
int max(int i, int j)
Returns bigger value form two given decimals.
Definition: mathfem.h:71
int unpackSharedDofManLocalDensities(ProcessCommunicator &processComm)
ProblemCommunicator * communicator
Communicator.
Definition: remeshingcrit.h:70
virtual int estimateMeshDensities(TimeStep *tStep)
Estimates the nodal densities.
int unpackSharedDofManLocalIndicatorVals(ProcessCommunicator &processComm)
ConnectivityTable * giveConnectivityTable()
Returns receiver&#39;s associated connectivity table.
Definition: domain.C:1170
CommunicatorBuff * commBuff
Common Communicator buffer.
Definition: remeshingcrit.h:68
EngngModel * giveEngngModel()
Returns engineering model to which receiver is associated.
Definition: domain.C:433
Abstract base class for all finite elements.
Definition: element.h:145
int giveNumberOfProcesses() const
Returns the number of collaborating processes.
Definition: engngm.h:1060
The ProcessCommunicator and corresponding buffers (represented by this class) are separated in order ...
Definition: processcomm.h:64
bool initCommMap
Communication init flag.
Definition: remeshingcrit.h:72
#define OOFEM_LOG_DEBUG(...)
Definition: logger.h:128
Class implementing an array of integers.
Definition: intarray.h:61
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
#define _IFT_DirectErrorIndicatorRC_maxlim
virtual void setUpCommunicationMaps(EngngModel *emodel, bool excludeSelfCommFlag, bool forceReinit=false)=0
Service for setting up the communication patterns with other remote process.
double zeroIndicatorDensity
Default mesh density for Indicator value < minIndicatorLimit.
int finishExchange()
Finishes the exchange.
Definition: communicator.C:115
const IntArray * giveToSendMap()
Returns receiver to send map.
Definition: processcomm.h:223
ErrorEstimator * ee
Definition: remeshingcrit.h:64
virtual RemeshingStrategy giveRemeshingStrategy(TimeStep *tStep)
Determines, if the remeshing is needed, and if needed, the type of strategy used. ...
int packSharedDofManLocalDensities(ProcessCommunicator &processComm)
#define OOFEM_LOG_INFO(...)
Definition: logger.h:127
Element * giveElement(int n)
Service for accessing particular domain fe element.
Definition: domain.C:160
virtual int write(const int *data, int count)
Writes count integer values from array pointed by data.
Definition: processcomm.h:83
StateCounterType giveSolutionStateCounter()
Returns current solution state counter.
Definition: timestep.h:188
std::map< int, double > sharedDofManIndicatorVals
virtual double giveRequiredDofManDensity(int num, TimeStep *tStep, int relative=0)
Returns the required mesh size n given dof manager.
virtual void setDomain(Domain *d)
Sets associated Domain.
ProcessCommunicatorBuff * giveProcessCommunicatorBuff()
Returns communication buffer.
Definition: processcomm.h:210
const IntArray * giveToRecvMap()
Returns receiver to receive map.
Definition: processcomm.h:227
Class representing connectivity table.
Class representing process communicator for engineering model.
Definition: processcomm.h:176
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
The base class for all error estimation or error indicator algorithms.
#define _IFT_DirectErrorIndicatorRC_defdens
int unpackAllData(T *ptr, int(T::*unpackFunc)(ProcessCommunicator &))
Unpack all problemCommuncators data from recv buffers.
Definition: communicator.h:262
RemeshingStrategy
Type representing the remeshing strategy.
Definition: remeshingcrit.h:50
const IntArray * giveDofManConnectivityArray(int dofman)
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
#define _IFT_DirectErrorIndicatorRC_remeshingdensityratio
Class representing the general Input Record.
Definition: inputrecord.h:101
int giveRank() const
Returns domain rank in a group of collaborating processes (0..groupSize-1)
Definition: engngm.h:1058
#define _IFT_DirectErrorIndicatorRC_mindens
void giveNodeChar(int inode, TimeStep *tStep, double &indicatorVal, double &currDensity)
#define _IFT_DirectErrorIndicatorRC_maxdens
Domain * giveDomain() const
Definition: femcmpnn.h:100
std::map< int, double > sharedDofManDensities
virtual int read(int *data, int count)
Reads count integer values into array pointed by data.
Definition: processcomm.h:91
The Communicator and corresponding buffers (represented by this class) are separated in order to allo...
Definition: communicator.h:60
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
#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
the oofem namespace is to define a context or scope in which all oofem names are defined.
virtual double giveElementError(EE_ErrorType type, Element *elem, TimeStep *tStep)=0
Returns the element error.
void exchangeDofManIndicatorVals(TimeStep *tStep)
#define IR_GIVE_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:69
DofManager * giveDofManager(int n)
Service for accessing particular domain dof manager.
Definition: domain.C:314
bool isShared()
Returns true if receiver is shared.
Definition: dofmanager.h:538
virtual void setDomain(Domain *d)
Sets associated Domain.
Definition: femcmpnn.h:105
int packSharedDofManLocalIndicatorVals(ProcessCommunicator &processComm)
Class representing solution step.
Definition: timestep.h:80
DofManager is shared by neighboring partitions, it is necessary to sum contributions from all contrib...
Definition: dofmanager.h:82
dofManagerParallelMode giveParallelMode() const
Return dofManagerParallelMode of receiver.
Definition: dofmanager.h:512
virtual double giveDofManDensity(int num)
Returns existing mesh size for given dof manager.
void resize(int s)
Resizes receiver towards requested size.
Definition: floatarray.C:631
StateCounterType stateCounter
Actual values (densities) state counter.

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