File: SizeFieldManager.cc

package info (click to toggle)
madlib 1.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,196 kB
  • sloc: cpp: 39,851; sh: 10,041; makefile: 473
file content (199 lines) | stat: -rw-r--r-- 5,815 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// -------------------------------------------------------------------
// MAdLib - Copyright (C) 2008-2009 Universite catholique de Louvain
//
// See the Copyright.txt and License.txt files for license information. 
// You should have received a copy of these files along with MAdLib. 
// If not, see <http://www.madlib.be/license/>
//
// Please report all bugs and problems to <contrib@madlib.be>
//
// Authors: Gaetan Compere, Jean-Francois Remacle
// -------------------------------------------------------------------

#include "SizeFieldManager.h"
#include "NullSField.h"
#include "MAdTimeManager.h"
#include "MeshQualityManager.h"
#include "MAdMessage.h"
#include "MeshSizeBase.h"

#include <iostream>
using std::cerr;
using std::cout;
using std::endl;
using std::set;

namespace MAd {

  // -------------------------------------------------------------------
  SizeFieldManager::SizeFieldManager(pMesh m, pSField psf): 
    localTime(-1.),smooth(false),maxGradient(1.)
  {
    if (!m) return;
    mesh = m;

    mainSF = new PWLSField(mesh,"Main size field");

    localTime = MAdTimeManagerSgl::instance().getTime();

    if (!psf) MAdMsgSgl::instance().warning(__LINE__,__FILE__,"No size field registered");

    else {
    
      mainSF->intersect(psf);
  
      sFieldType type = psf->getType();
      switch (type) {
      case NULLSFIELD: {
        break;
      }
      case DISCRETESFIELD: {
        assert ( ((DiscreteSF*)psf)->discretization() == VERTEX_P1_DSFTYPE );
        PWLSField* linsf = static_cast<PWLSField*>(psf);
        addPWLinearSF( linsf );
        break;
      }
      case ANALYTICALSFIELD: {
        AnalyticalSField* asf = static_cast<AnalyticalSField*>(psf);
        addAnalyticalSF( asf );
        break;
      }
      case LOCALSFIELD: {
        LocalSizeField* locsf = static_cast<LocalSizeField*>(psf);
        addLocalSF( locsf );
        break;
      }
      case BACKGROUNDSFIELD: {
        BackgroundSF* bg = static_cast<BackgroundSF*>(psf);
        addBGSF( bg );
        break;
      }
      default: {
        MAdMsgSgl::instance().error(__LINE__,__FILE__,
                                    "unknown size field type %d", type);
      }
      }
    }  
  }

  // -------------------------------------------------------------------
  SizeFieldManager::~SizeFieldManager() {

    if (mainSF) delete mainSF;
    linears.clear();
    analyticals.clear();
    locals.clear();
    bgs.clear();
  }

  // -------------------------------------------------------------------
  void SizeFieldManager::setMesh(pMesh m)
  {
    mesh = m;
    mainSF = new PWLSField(mesh);
    MAdMsgSgl::instance().warning(__LINE__,__FILE__,"No size field registered");
  }

  // -------------------------------------------------------------------
  void SizeFieldManager::intersect(const pSField sf) {
    mainSF->intersect(sf);
  }

  // -------------------------------------------------------------------
  void SizeFieldManager::addSizeField(pSField sf) {

    mainSF->intersect(sf);
  
    sFieldType type = sf->getType();
    switch (type) {
    case NULLSFIELD: {
      break;
    }
    case DISCRETESFIELD: {
      assert ( ((DiscreteSF*)sf)->discretization() == VERTEX_P1_DSFTYPE );
      PWLSField* linsf = static_cast<PWLSField*>(sf);
      addPWLinearSF( linsf );
      break;
    }
    case ANALYTICALSFIELD: {
      AnalyticalSField* asf = static_cast<AnalyticalSField*>(sf);
      addAnalyticalSF( asf );
      break;
    }
    case LOCALSFIELD: {
      LocalSizeField* locsf = static_cast<LocalSizeField*>(sf);
      addLocalSF( locsf );
      break;
    }
    case BACKGROUNDSFIELD: {
      BackgroundSF* bg = static_cast<BackgroundSF*>(sf);
      addBGSF( bg );
      break;
    }
    default: {
      MAdMsgSgl::instance().error(__LINE__,__FILE__,
                                  "Unknown size field type %d",type);
    }
    }
  }

  // -------------------------------------------------------------------
  void SizeFieldManager::addPWLinearSF(PWLSField* sf) {
    linears.insert(sf);
  }

  // -------------------------------------------------------------------
  void SizeFieldManager::addAnalyticalSF(AnalyticalSField* sf) {
    analyticals.insert(sf);
  }

  // -------------------------------------------------------------------
  void SizeFieldManager::addLocalSF(LocalSizeField* sf) {
    locals.insert(sf);
  }

  // -------------------------------------------------------------------
  void SizeFieldManager::addBGSF(BackgroundSF* sf) {
    bgs.insert(sf);
  }

  // -------------------------------------------------------------------
  void SizeFieldManager::update()
  {
    MeshQualityManagerSgl::instance().clearAllShapes(); // not useful in isotropic case (be careful about the hypothesis)

    mainSF->cleanUp();

    set<PWLSField*>::const_iterator linIter = linears.begin();
    set<PWLSField*>::const_iterator linLast = linears.end();
    for (; linIter != linLast; linIter++) {
      mainSF->intersect(*linIter);
    }

    set<AnalyticalSField*>::const_iterator aIter = analyticals.begin();
    set<AnalyticalSField*>::const_iterator aLast = analyticals.end();
    for (; aIter != aLast; aIter++) {
      mainSF->intersect(*aIter);
    }

    set<LocalSizeField*>::iterator locIter = locals.begin();
    set<LocalSizeField*>::iterator locLast = locals.end();
    for (; locIter != locLast; locIter++) {
      (*locIter)->updateTree();
      mainSF->intersect(*locIter);
    }

    set<BackgroundSF*>::iterator bgIter = bgs.begin();
    set<BackgroundSF*>::iterator bgLast = bgs.end();
    for (; bgIter != bgLast; bgIter++) {
      mainSF->intersect(*bgIter);
    }

    if ( smooth ) mainSF->smooth(maxGradient);

    localTime = MAdTimeManagerSgl::instance().getTime();
  }

  // -------------------------------------------------------------------

}