File: DiscretizedOperators.hpp

package info (click to toggle)
freefem3d 1.0pre10-3.4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 25,016 kB
  • ctags: 8,675
  • sloc: cpp: 57,204; sh: 8,788; yacc: 2,975; makefile: 1,149; ansic: 508; perl: 110
file content (367 lines) | stat: -rw-r--r-- 9,666 bytes parent folder | download | duplicates (5)
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
//  This file is part of ff3d - http://www.freefem.org/ff3d
//  Copyright (C) 2001, 2002, 2003 Stphane Del Pino

//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2, or (at your option)
//  any later version.

//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.

//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software Foundation,
//  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  

//  $Id: DiscretizedOperators.hpp,v 1.6 2006/07/20 19:08:54 delpinux Exp $

#ifndef DISCRETIZED_OPERATORS_HPP
#define DISCRETIZED_OPERATORS_HPP

#include <TinyMatrix.hpp>

#include <ReferenceCounting.hpp>

#include <Problem.hpp>
#include <ScalarFunctionBase.hpp>

#include <ElementaryMatrixSet.hpp>

#include <PDESystem.hpp>

#include <MassOperator.hpp>
#include <FirstOrderOperator.hpp>
#include <DivMuGrad.hpp>
#include <SecondOrderOperator.hpp>


#include <VariationalProblem.hpp>
#include <VariationalOperatorMuGradUGradV.hpp>
#include <VariationalOperatorAlphaDxUDxV.hpp>
#include <VariationalOperatorNuUdxV.hpp>
#include <VariationalOperatorNuDxUV.hpp>
#include <VariationalOperatorAlphaUV.hpp>

#include <ErrorHandler.hpp>

#include <map>

/**
 * @file   DiscretizedOperators.hpp
 * @author Stephane Del Pino
 * @date   Wed Jul 19 15:57:01 2006
 * 
 * @brief Builds lists of discretized operators according to a problem
 * definition
 * 
 */
template <typename ElementaryMatrixType>
class DiscretizedOperators
{
public:
  /*! This sub-class is used to describe the position of the parameter
    function associated to a PDE Operator in the System.
   */
  class FunctionAndPosition
  {
  private:
    const size_t __i;		/**< line of the function in the linear system */
    const size_t __j;		/**< column of the function in the linear system */
    ConstReferenceCounting<ScalarFunctionBase>
    __function;			/**< coefficient function */
  public:
    /** 
     * Read-only access to the line of the function
     * 
     * @return __i
     */
    inline const size_t& i() const
    {
      return __i;
    }

    /** 
     * Read-only access to the column of the function
     * 
     * @return __j
     */
    inline const size_t& j() const
    {
      return __j;
    }

    /** 
     * Evaluates the function at the point @f$ x @f$
     * 
     * @return @f$ f(x) @f$
     */
    inline real_t operator()(const TinyVector<3, real_t>& x) const
    {
      return (*__function)(x);
    }

    /** 
     * Copy constructor
     * 
     * @param fap given FunctionAndPosition
     */
    FunctionAndPosition(const FunctionAndPosition& fap)
      : __i(fap.__i),
	__j(fap.__j),
	__function(fap.__function)
    {
      ;
    }

    /** 
     * Constructor
     * 
     * @param line line in the linear system
     * @param column column in the linear system
     * @param function given function
     */
    FunctionAndPosition(const size_t& line,
			const size_t& column,
			ConstReferenceCounting<ScalarFunctionBase> function)
      : __i(line),
	__j(column),
	__function(function)
    {
      ;
    }

    /** 
     * Destructor
     * 
     */
    ~FunctionAndPosition()
    {
      ;
    }
  };

  // ================================
  // Now we describe the class itself 
  // ================================

  typedef std::pair<const ElementaryMatrixType*,
		    FunctionAndPosition > ListPair;
  typedef std::multimap<const ElementaryMatrixType*,
			FunctionAndPosition > List;
  typedef typename List::iterator iterator;
  typedef typename List::const_iterator const_iterator;

  /**Begining of the list 
   * 
   * @return begin iterator
   */
  typename DiscretizedOperators::iterator
  begin()
  {
    return __list.begin();
  }

  /** 
   * Begining of the list
   * 
   * @return begin const_iterator
   */
  const typename DiscretizedOperators::const_iterator
  begin() const
  {
    return __list.begin();
  }

  /** 
   * End of the list
   * 
   * @return end iterator
   */
  typename DiscretizedOperators::iterator
  end()
  {
    return __list.end();
  }

  /** 
   * End of the list
   * 
   * @return end const_iterator
   */
  const typename DiscretizedOperators::const_iterator
  end() const
  {
    return __list.end();
  }

private:
  const ElementaryMatrixSet<ElementaryMatrixType>&
  __elementaryMatrixSet;	/**< Reference to the elementary
				   matrices set */

  List __list;			/**< list of discretized operators */

  /** 
   * Copy constructor
   * @note this constructor is forbidden
   * 
   * @param c given disretized operator
   */
  DiscretizedOperators(const DiscretizedOperators& c);

public:
  /** 
   * Constructor
   * 
   * @param e elementary matrices set
   * @param problem problem to discretize
   */
  DiscretizedOperators(const ElementaryMatrixSet<ElementaryMatrixType>& e,
		       const Problem& problem)
    : __elementaryMatrixSet(e)
  {
    switch (problem.type()) {
    case Problem::pdeProblem: {
      const PDESystem& pdeSystem
	= dynamic_cast<const PDESystem&>(problem);

      for (size_t i=0; i<problem.numberOfUnknown(); ++i) {
	const PDE& pde = pdeSystem[i].pde();
	for (size_t j=0; j<pdeSystem.numberOfEquations(); ++j) {
	  const PDEOperatorSum& pdeOpSum = *pde[j];
	  for (size_t k=0; k<pdeOpSum.numberOfOperators(); ++k) {
	    const PDEOperator& pdeOperator = *pdeOpSum[k];
	    switch (pdeOperator.type()) {
	    case PDEOperator::firstorderop: {
	      const FirstOrderOperator& firstOrderOperator
		= dynamic_cast<const FirstOrderOperator&>(pdeOperator);
	      for (size_t m=0; m<3; ++m) {
		if (firstOrderOperator.isSet(m)) {
		  __list.insert(ListPair(&__elementaryMatrixSet.firstOrderOperatorDxUV(m),
					 FunctionAndPosition(i,j,firstOrderOperator.nu(m))));
		}
	      }
	      break;
	    }
	    case PDEOperator::divmugrad: {
	      const DivMuGrad& divMuGrad
		= dynamic_cast<const DivMuGrad&>(pdeOperator);
	      __list.insert(ListPair(&__elementaryMatrixSet.divMuGrad(),
				     FunctionAndPosition(i,j,divMuGrad.mu())));
	      break;
	    }
	    case PDEOperator::secondorderop: {
	      const SecondOrderOperator& secondOrderOperator
		= dynamic_cast<const SecondOrderOperator&>(pdeOperator);
	      for (size_t m=0; m<3; ++m)
		for (size_t n=0; n<3; ++n) {
		  if (secondOrderOperator.isSet(m,n)) {
		    __list.insert(ListPair(&__elementaryMatrixSet.secondOrderOperator(m,n),
					   FunctionAndPosition(i,j,secondOrderOperator.A(m,n))));
		  }
		}
	      break;
	    }
	    case PDEOperator::massop: {
	      const MassOperator& massOperator
		= dynamic_cast<const MassOperator&>(pdeOperator);
	      __list.insert(ListPair(&__elementaryMatrixSet.massOperator(),
				     FunctionAndPosition(i,j,massOperator.alpha())));
	      break;
	    }
	    default: {
	      throw ErrorHandler(__FILE__,__LINE__,
				 "unknown operator",
				 ErrorHandler::unexpected);
	    }
	    }
	  }
	}
      }
      break;
    }
    case Problem::variationalProblem: {
      const VariationalProblem& P
	= dynamic_cast<const VariationalProblem&>(problem);
      for (VariationalProblem::bilinearOperatorConst_iterator
	     i = P.beginBilinearOperator();
	   i != P.endBilinearOperator(); ++i) {
	switch ((*(*i)).type()) {
	case VariationalBilinearOperator::muGradUGradV: {
	  const VariationalMuGradUGradVOperator& O
	    = dynamic_cast<const VariationalMuGradUGradVOperator&>(*(*i));

	  __list.insert(ListPair(&__elementaryMatrixSet.divMuGrad(),
				 FunctionAndPosition(O.unknownNumber(),
						     O.testFunctionNumber(),
						     O.mu())));

	  break;
	}
	case VariationalBilinearOperator::alphaDxUDxV: {
	  const VariationalAlphaDxUDxVOperator& O
	    = dynamic_cast<const VariationalAlphaDxUDxVOperator&>(*(*i));

	  const size_t i = O.i();
	  const size_t j = O.j();
	
	  __list.insert(ListPair(&__elementaryMatrixSet.secondOrderOperator(i,j),
				 FunctionAndPosition(O.unknownNumber(),
						     O.testFunctionNumber(),
						     O.alpha())));
	  break;
	}
	case VariationalBilinearOperator::nuUdxV: {
	  const VariationalNuUdxVOperator& O
	    = dynamic_cast<const VariationalNuUdxVOperator&>(*(*i));

	  const size_t n = O.i();
	  __list.insert(ListPair(&__elementaryMatrixSet.firstOrderOperatorUdxV(n),
				 FunctionAndPosition(O.unknownNumber(),
						     O.testFunctionNumber(),
						     O.nu())));
	  break;
	}
	case VariationalBilinearOperator::nuDxUV: {
	  const VariationalNuDxUVOperator& O
	    = dynamic_cast<const VariationalNuDxUVOperator&>(*(*i));

	  const size_t n = O.i();
	  __list.insert(ListPair(&__elementaryMatrixSet.firstOrderOperatorDxUV(n),
				 FunctionAndPosition(O.unknownNumber(),
						     O.testFunctionNumber(),
						     O.nu())));
	  break;
	}
	case VariationalBilinearOperator::alphaUV: {
	  const VariationalAlphaUVOperator& O
	    = dynamic_cast<const VariationalAlphaUVOperator&>(*(*i));

	  __list.insert(ListPair(&__elementaryMatrixSet.massOperator(),
				 FunctionAndPosition(O.unknownNumber(),
						     O.testFunctionNumber(),
						     O.alpha())));

	  break;
	}
	default: {
	  throw ErrorHandler(__FILE__,__LINE__,
			     "unknown variational form",
			     ErrorHandler::unexpected);
	}
	}
      }
      break;
    }
    default: {
      throw ErrorHandler(__FILE__,__LINE__,
			 "Unknown problem type",
			 ErrorHandler::unexpected);
    }
    }
  }
};

#endif // DISCRETIZED_OPERATORS_HPP