DUNE-FEM (unstable)

localoperator.hh
1#ifndef DUNE_FEM_LOCALOPERATORS_HH
2#define DUNE_FEM_LOCALOPERATORS_HH
3
4#include <iostream>
5
6#include "objpointer.hh"
7
8namespace Dune
9{
10
11 namespace Fem
12 {
13
14 //***********************************************************************
15 //
28 //***********************************************************************
29 template <class FstPType, class SecPType, class SType ,
30 class LocalOperatorImp>
31 class LocalOperatorInterface
32 {
33 public:
35 typedef FstPType FirstParamType;
36 typedef SecPType SecondParamType;
37 typedef SType ScalarType;
38
39 //**************************************************************
43
44 void prepareGlobal(const FirstParamType &pa, SecondParamType &pb)
45 {
46 asImp().prepareGlobal(pa,pb);
47 }
48
50 void prepareGlobal ()
51 {
52 asImp().prepareGlobal();
53 }
54
56 void finalizeGlobal()
57 {
58 asImp().finalizeGlobal();
59 }
60
62 template<class EntityType>
63 void prepareLocal (EntityType & en)
64 {
65 asImp().prepareLocal(en);
66 }
67
69 template<class EntityType>
70 void finalizeLocal(EntityType & en)
71 {
72 asImp().finalizeLocal(en);
73 }
74
76 template<class EntityType>
77 void prepareLocal (EntityType & en1, EntityType &en2)
78 {
79 asImp().prepareLocal(en1,en2);
80 }
81
83 template<class EntityType>
84 void finalizeLocal(EntityType & en1, EntityType &en2)
85 {
86 asImp().finalizeLocal(en1,en2);
87 }
88
90 template<class EntityType>
91 void applyLocal(EntityType & en)
92 {
93 asImp().applyLocal(en);
94 }
95
97 template<class EntityType>
98 void applyLocal(EntityType & en1, EntityType &en2)
99 {
100 asImp().applyLocal(en1,en2);
101 }
102 private:
104 LocalOperatorImp & asImp()
105 {
106 return static_cast<LocalOperatorImp &> (*this);
107 }
108 };
109
110 //**************************************************************************
111 // Default implemenations for LocalOperators
112 //**************************************************************************
118 template <class FstPType, class SecPType, class SType ,
119 class LocalOperatorImp>
121 : public LocalOperatorInterface <FstPType,SecPType,
122 SType,LocalOperatorImp>
123 {
124 public:
126 typedef FstPType FirstParamType;
127 typedef SecPType SecondParamType;
128 typedef SType ScalarType;
129
131 LocalOperatorDefault () : scalar_ (1.0) {}
132
134 void scaleIt ( const ScalarType scalar )
135 {
136 scalar_ = scalar;
137 }
138
139 //**************************************************************
143 // prepare for grid walktrough
144 void prepareGlobal () {}
145
146 // finalize the walktrough
147 void finalizeGlobal() {}
148
149 // one entity
150 template<class EntityType>
151 void prepareLocal (EntityType & en) {}
152
154 template<class EntityType>
155 void finalizeLocal(EntityType & en) {}
156
157 // two entities
158 template<class EntityType>
159 void prepareLocal (EntityType & en1, EntityType &en2){}
160
162 template<class EntityType>
163 void finalizeLocal(EntityType & en1, EntityType &en2){}
164 //**************************************************************
165
166 protected:
167 // scalar for operator
168 ScalarType scalar_;
169 };
170
171 //*******************************************************************
172 //
183 //*******************************************************************
186 template <class A, class B >
188 : public ObjPointerStorage
189 {
190 public:
193 typedef B SecondOperatorType;
194
196 CombinedLocalOperator ( A & a, B & b , bool printMsg = false )
197 : _a ( a ) , _b ( b ) , printMSG_ ( printMsg )
198 {
199 if(printMSG_)
200 std::cout << "Create CombinedLocalOperator " << this << std::endl;
201 }
202
205 {
206 if(printMSG_)
207 std::cout << "Delete CombinedLocalOperator " << this << std::endl;
208 }
209
211 template <class ScalarType>
212 void scaleIt( const ScalarType scalar);
213
214 //*******************************************************
218
219 template <class FirstParamType, class SecondParamType>
220 void prepareGlobal(const FirstParamType &pa, SecondParamType &pb);
221
223 void finalizeGlobal();
224
225 //*******************************************************
232 // one entity
233 template<class EntityType>
234 void prepareLocal (EntityType & en);
235
237 template<class EntityType>
238 void finalizeLocal(EntityType & en);
239
240 // two entities
241 template<class EntityType>
242 void prepareLocal (EntityType & en1, EntityType &en2);
243
245 template<class EntityType>
246 void finalizeLocal(EntityType & en1, EntityType &en2);
247
248 //**********************************************************
256 // things to do on one entity
257 template<class EntityType>
258 void applyLocal(EntityType & en);
259
260 // things to do on two entity
261 template<class EntityType>
262 void applyLocal(EntityType & en1, EntityType &en2);
263
264 //****************************************************************
268 private:
270 A & _a;
271 B & _b;
272
273 // if true some messages in Constructor and Destructor are printed
274 bool printMSG_;
275 };
276
277
278 //********************************************************************
279 //
280 // Implementation
281 //
282 //********************************************************************
283 template <class A, class B >
284 template <class ScalarType>
286 scaleIt(const ScalarType scalar)
287 {
288 _a.scaleIt(scalar);
289 _b.scaleIt(scalar);
290 }
291 template <class A, class B >
292 template <class FirstParamType, class SecondParamType>
294 prepareGlobal(const FirstParamType &pa, SecondParamType &pb)
295 {
296 _a.scaleIt(1.0);
297 _b.scaleIt(1.0);
298 _b.prepareGlobal(pa,pb);
299 _a.prepareGlobal(pa,pb);
300 }
301
302 template <class A, class B >
304 {
305 _b.finalizeGlobal();
306 _a.finalizeGlobal();
307 }
308
309
310 template <class A, class B >
311 template <class EntityType>
313 {
314 _b.prepareLocal(en);
315 _a.prepareLocal(en);
316 }
317
318 template <class A, class B >
319 template <class EntityType>
321 {
322 _b.finalizeLocal(en);
323 _a.finalizeLocal(en);
324 }
325
326 template <class A, class B >
327 template <class EntityType>
328 inline void CombinedLocalOperator<A,B>::applyLocal(EntityType &en)
329 {
330 _b.applyLocal(en);
331 _a.applyLocal(en);
332 }
333
334
335 template <class A, class B >
336 template <class EntityType>
337 inline void CombinedLocalOperator<A,B>::prepareLocal(EntityType &en1, EntityType & en2)
338 {
339 _b.prepareLocal(en1,en2);
340 _a.prepareLocal(en1,en2);
341 }
342
343 template <class A, class B >
344 template <class EntityType>
345 inline void CombinedLocalOperator<A,B>::applyLocal(EntityType &en1, EntityType &en2 )
346 {
347 _b.applyLocal(en1,en2);
348 _a.applyLocal(en1,en2);
349 }
350
351 template <class A, class B >
352 template <class EntityType>
353 inline void CombinedLocalOperator<A,B>::finalizeLocal(EntityType &en1, EntityType & en2)
354 {
355 _b.finalizeLocal(en1,en2);
356 _a.finalizeLocal(en1,en2);
357 }
358
359
360 //********************************************************************
361 //********************************************************************
362 //********************************************************************
363 //********************************************************************
364 //
367 //
368 //********************************************************************
369 template <class A,class ScalarType>
371 : public ObjPointerStorage
372 {
373 public:
375 ScaledLocalOperator ( A & a , const ScalarType scalar,
376 bool printMsg = false)
377 : _a ( a ) , scalar_ (scalar), tmpScalar_ (scalar) ,
378 printMSG_ ( printMsg )
379 {
380 if(printMSG_)
381 std::cout << "Create ScaledLocalOperator " << this << std::endl;
382 }
383
385 {
386 if(printMSG_)
387 std::cout << "Delete ScaledLocalOperator " << this << std::endl;
388 }
389 // scale this operator from outside
390 void scaleIt ( const ScalarType & scalar);
391
392 //*******************************************************
396
397 template <class FirstParamType, class SecondParamType>
398 void prepareGlobal(const FirstParamType &pa, SecondParamType &pb);
399
401 void finalizeGlobal();
402
403 //*******************************************************
409 // one entity
410 template<class EntityType>
411 void prepareLocal (EntityType & en);
412
414 template<class EntityType>
415 void finalizeLocal(EntityType & en);
416
417 // two entities
418 template<class EntityType>
419 void prepareLocal (EntityType & en1, EntityType &en2);
420
422 template<class EntityType>
423 void finalizeLocal(EntityType & en1, EntityType &en2);
424
425 //**********************************************************
432 // things to do on one entity
433 template<class EntityType>
434 void applyLocal(EntityType & en);
435
436 // things to do on two entity
437 template<class EntityType>
438 void applyLocal(EntityType & en1, EntityType &en2);
439 protected:
441 A & _a;
442
444 const ScalarType scalar_;
445 ScalarType tmpScalar_;
446
447 // if true some messages in Contructor and Destructor are printed
448 bool printMSG_;
449 }; // end class ScaledLocalOperator
450
451 //****************************************************
452 // Implementation
453 //****************************************************
454 template <class A, class ScalarType>
456 scaleIt ( const ScalarType & scalar )
457 {
458 tmpScalar_ = scalar_ * scalar;
459 }
460
461 template <class A, class ScalarType>
462 template <class FirstParamType, class SecondParamType>
464 prepareGlobal(const FirstParamType &pa, SecondParamType &pb)
465 {
466 _a.scaleIt(tmpScalar_);
467 _a.prepareGlobal(pa,pb);
468 }
469
470 template <class A, class ScalarType>
472 {
473 _a.finalizeGlobal();
474 }
475
476 template <class A, class ScalarType>
477 template <class EntityType>
479 {
480 _a.prepareLocal(en);
481 }
482
483 template <class A, class ScalarType>
484 template <class EntityType>
485 inline void ScaledLocalOperator<A,ScalarType>::prepareLocal(EntityType &en1, EntityType & en2)
486 {
487 _a.prepareLocal(en1,en2);
488 }
489
490 template <class A, class ScalarType>
491 template <class EntityType>
493 {
494 _a.finalizeLocal(en);
495 }
496
497 template <class A, class ScalarType>
498 template <class EntityType>
499 inline void ScaledLocalOperator<A,ScalarType>::finalizeLocal(EntityType &en1, EntityType & en2)
500 {
501 _a.finalizeLocal(en1,en2);
502 }
503
504 template <class A, class ScalarType>
505 template <class EntityType>
507 {
508 _a.applyLocal(en);
509 }
510
511 template <class A, class ScalarType>
512 template <class EntityType>
513 inline void ScaledLocalOperator<A,ScalarType>::applyLocal(EntityType &en1, EntityType &en2 )
514 {
515 _a.applyLocal(en1,en2);
516 }
517
518 } // namespace Fem
519
520} // namespace Dune
521
522#endif // #ifndef DUNE_FEM_LOCALOPERATORS_HH
Definition: localoperator.hh:189
~CombinedLocalOperator()
Destructor.
Definition: localoperator.hh:204
A FirstOperatorType
The type of the operators exported.
Definition: localoperator.hh:192
void scaleIt(const ScalarType scalar)
method to scale the belonging operators
Definition: localoperator.hh:286
void finalizeGlobal()
finalizeGlobal is called after the grid walktrough
Definition: localoperator.hh:303
void prepareGlobal(const FirstParamType &pa, SecondParamType &pb)
prepareGlobal is called before the grid walktrough
Definition: localoperator.hh:294
void applyLocal(EntityType &en)
Definition: localoperator.hh:328
void finalizeLocal(EntityType &en)
Definition: localoperator.hh:320
void prepareLocal(EntityType &en)
Definition: localoperator.hh:312
CombinedLocalOperator(A &a, B &b, bool printMsg=false)
Constructor for combinations storing the two operators.
Definition: localoperator.hh:196
Default implementation of a local operator A local operator works on entities only and is used by a D...
Definition: localoperator.hh:123
void prepareGlobal()
Definition: localoperator.hh:144
void scaleIt(const ScalarType scalar)
scale operator , for inheritance
Definition: localoperator.hh:134
LocalOperatorDefault()
no default implementation at the moement
Definition: localoperator.hh:131
void finalizeLocal(EntityType &en1, EntityType &en2)
Definition: localoperator.hh:163
FstPType FirstParamType
remember the parameter types
Definition: localoperator.hh:126
void finalizeLocal(EntityType &en)
Definition: localoperator.hh:155
Definition: objpointer.hh:42
Definition: localoperator.hh:372
void applyLocal(EntityType &en)
Definition: localoperator.hh:506
const ScalarType scalar_
scale factor for operator _a
Definition: localoperator.hh:444
void finalizeLocal(EntityType &en)
Definition: localoperator.hh:492
void prepareLocal(EntityType &en)
Definition: localoperator.hh:478
void prepareGlobal(const FirstParamType &pa, SecondParamType &pb)
prepareGlobal is called before the grid walktrough
Definition: localoperator.hh:464
A & _a
reference to local operator A
Definition: localoperator.hh:441
ScaledLocalOperator(A &a, const ScalarType scalar, bool printMsg=false)
Constructor for combinations with factors.
Definition: localoperator.hh:375
void finalizeGlobal()
finalizeGlobal is called after the grid walktrough
Definition: localoperator.hh:471
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)