OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
freeminterface.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 "freeminterface.h"
36 #include "errorestimator.h"
37 #include "domain.h"
38 #include "node.h"
39 #include "element.h"
40 #include "connectivitytable.h"
41 #include "mathfem.h"
42 #include "remeshingcrit.h"
43 #include "classfactory.h"
44 
45 #include <list>
46 
47 namespace oofem {
48 REGISTER_Mesher(FreemInterface, MPT_FREEM);
49 
51 FreemInterface :: createMesh(TimeStep *tStep, int domainNumber, int domainSerNum, Domain **dNew)
52 {
53  * dNew = NULL;
54  if ( this->createInput(this->domain, tStep) ) {
56  } else {
57  return MI_FAILED;
58  }
59 }
60 
61 int
63 {
64  int nnodes = d->giveNumberOfDofManagers(), nelem = d->giveNumberOfElements();
65  double density;
66  FILE *outputStrem;
67  Node *inode;
68  Element *ielem;
69 
70  outputStrem = fopen("freem.bmf", "w");
71  // print header for 2D
72  fprintf(outputStrem, "nbnodes %d nbelem %d \n", nnodes, nelem);
73 
74  /* mesh densities smoothing */
75  // query nodal absolute densities
76  FloatArray nodalDensities(nnodes);
77  for ( int i = 1; i <= nnodes; i++ ) {
78  nodalDensities.at(i) = d->giveErrorEstimator()->giveRemeshingCrit()->giveRequiredDofManDensity(i, tStep);
79  }
80 
81  this->smoothNodalDensities(d, nodalDensities, tStep);
82  /* end of smoothing */
83 
84  // loop over nodes
85  for ( int i = 1; i <= nnodes; i++ ) {
86  //density = d->giveErrorEstimator ()->giveRemeshingCrit()->giveRequiredDofManDensity (i, tStep, 1);
87  //density = d->giveErrorEstimator ()->giveRemeshingCrit()->giveDofManDensity (i) / nodalDensities.at(i);
88  density = nodalDensities.at(i);
89  inode = d->giveNode(i);
90  fprintf(outputStrem, "backgroungMeshNode %d x %e y %e density %e\n", i, inode->giveCoordinate(1), inode->giveCoordinate(2), density);
91  }
92 
93  for ( int i = 1; i <= nelem; i++ ) {
94  ielem = d->giveElement(i);
95  if ( ielem->giveGeometryType() != EGT_quad_1 ) {
96  OOFEM_ERROR("unsupported element type (not a bilinear quad)");
97  }
98 
99  fprintf( outputStrem, "backgroundMeshElem %d nodes 4 %d %d %d %d\n", i,
100  ielem->giveNode(1)->giveNumber(), ielem->giveNode(2)->giveNumber(),
101  ielem->giveNode(3)->giveNumber(), ielem->giveNode(4)->giveNumber() );
102  }
103 
104  fclose(outputStrem);
105 
106  OOFEM_LOG_INFO("freem.bmf file created\n");
107  return 1;
108 }
109 
110 void
112 {
113  int neighbour, candidate, found, jelemNodes;
114  int nnodes = d->giveNumberOfDofManagers();
115  double dist;
116  const IntArray *candidateConnectivity;
117  FloatArray *neighbourCoords;
118  Element *jelem;
119  Node *candNode;
120  std :: list< int >queue;
121 
122 
123  // loop over nodes
124  for ( int i = 1; i <= nnodes; i++ ) {
125  if ( !dynamic_cast< Node * >( d->giveDofManager(i) ) ) {
126  continue;
127  }
128 
129  queue.clear();
130  queue.push_front(i);
131 
132  while ( !queue.empty() ) {
133  // extract candidate
134  candidate = * ( queue.begin() );
135  queue.erase( queue.begin() );
136 
137  candNode = static_cast< Node * >( d->giveDofManager(candidate) );
138  // find candidate neighbours
139  candidateConnectivity = d->giveConnectivityTable()->giveDofManConnectivityArray(candidate);
140  for ( int j = 1; j <= candidateConnectivity->giveSize(); j++ ) {
141  jelem = d->giveElement( candidateConnectivity->at(j) );
142  jelemNodes = jelem->giveNumberOfNodes();
143  for ( int k = 1; k <= jelemNodes; k++ ) {
144  neighbour = jelem->giveNode(k)->giveNumber();
145  if ( neighbour == candidate ) {
146  continue;
147  }
148 
149  // neighbour found, check if smoothing necessary
150  neighbourCoords = jelem->giveNode(k)->giveCoordinates();
151  dist = candNode->giveCoordinates()->distance(neighbourCoords);
152  // overshoot criteria
153  if ( ( ( nodalDensities.at(neighbour) / nodalDensities.at(candidate) ) > 1.3 ) &&
154  ( nodalDensities.at(neighbour) > 1.0 * dist ) ) {
155  // increase candidate nodal density
156  nodalDensities.at(neighbour) = max( 1.0 * dist, nodalDensities.at(candidate) );
157  // printf ("o");
158  // put candidate into queue if not yet added present
159  found = 0;
160  for ( int q: queue ) {
161  if ( q == neighbour ) {
162  found = 1;
163  break;
164  }
165  }
166 
167  if ( !found ) {
168  queue.push_front(neighbour);
169  }
170 
171  // end overshoot criteria
172  } else if ( ( nodalDensities.at(neighbour) - nodalDensities.at(candidate) ) / dist > 2.5 ) {
173  // max gradient criteria
174  nodalDensities.at(neighbour) = nodalDensities.at(candidate) + 2.2 * dist;
175  //printf ("g");
176  // put candidate into queue if not yet added present
177  found = 0;
178  for ( int q: queue ) {
179  if ( q == neighbour ) {
180  found = 1;
181  break;
182  }
183  }
184 
185  if ( !found ) {
186  queue.push_front(neighbour);
187  }
188  }
189  }
190  }
191  } // end loop over queue
192  }
193 }
194 } // end namespace oofem
Class and object Domain.
Definition: domain.h:115
int createInput(Domain *d, TimeStep *tStep)
Creates the mesher input, containing the required mesh density information.
int giveNumberOfDofManagers() const
Returns number of dof managers in domain.
Definition: domain.h:432
REGISTER_Mesher(FreemInterface, MPT_FREEM)
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
void smoothNodalDensities(Domain *d, FloatArray &nodalDensities, TimeStep *tStep)
Service for smoothing the densities for freem.
int max(int i, int j)
Returns bigger value form two given decimals.
Definition: mathfem.h:71
ConnectivityTable * giveConnectivityTable()
Returns receiver&#39;s associated connectivity table.
Definition: domain.C:1170
Abstract base class for all finite elements.
Definition: element.h:145
int giveNumberOfElements() const
Returns number of elements in domain.
Definition: domain.h:434
virtual double giveCoordinate(int i)
Definition: node.C:82
Class implementing an array of integers.
Definition: intarray.h:61
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
virtual double giveRequiredDofManDensity(int num, TimeStep *tStep, int relative=0)=0
Returns the required mesh size n given dof manager.
virtual int giveNumberOfNodes() const
Returns number of nodes of receiver.
Definition: element.h:662
ErrorEstimator * giveErrorEstimator()
Returns Error Estimator associated to receiver.
Definition: domain.C:1429
double distance(const FloatArray &x) const
Computes the distance between position represented by receiver and position given as parameter...
Definition: floatarray.C:489
#define OOFEM_LOG_INFO(...)
Definition: logger.h:127
Element * giveElement(int n)
Service for accessing particular domain fe element.
Definition: domain.C:160
#define OOFEM_ERROR(...)
Definition: error.h:61
virtual RemeshingCriteria * giveRemeshingCrit()=0
Returns reference to associated remeshing criteria.
Class representing vector of real numbers.
Definition: floatarray.h:82
const IntArray * giveDofManConnectivityArray(int dofman)
virtual returnCode createMesh(TimeStep *tStep, int domainNumber, int domainSerNum, Domain **dNew)
Runs the mesh generation, mesh will be written to corresponding domain din file.
virtual FloatArray * giveCoordinates()
Definition: node.h:114
int giveSize() const
Definition: intarray.h:203
virtual Element_Geometry_Type giveGeometryType() const
Returns the element geometry type.
Definition: element.C:1529
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.
Class implementing node in finite element mesh.
Definition: node.h:87
int giveNumber() const
Definition: femcmpnn.h:107
DofManager * giveDofManager(int n)
Service for accessing particular domain dof manager.
Definition: domain.C:314
Node * giveNode(int i) const
Returns reference to the i-th node of element.
Definition: element.h:610
Class representing solution step.
Definition: timestep.h:80

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