21 #include "shapeset_l2_all.h"
22 #include "shapeset_hc_all.h"
23 #include "shapeset_hd_all.h"
24 #include "shapeset_h1_all.h"
25 using namespace Hermes::Algebra::DenseMatrixOperations;
34 static const std::string H2D_DG_INNER_EDGE =
"-1234567";
36 template<
typename Scalar>
40 this->is_matfree = mat_free;
43 template<
typename Scalar>
46 for(
unsigned int i = 0; i < this->ext.size(); i++)
48 for(
unsigned int i = 0; i < this->forms.size(); i++)
49 for(
unsigned int j = 0; j < get_forms()[i]->ext.size(); j++)
50 delete get_forms()[i]->
ext[j];
53 template<
typename Scalar>
56 for(
unsigned int i = 0; i < this->forms.size(); i++)
57 delete get_forms()[i];
61 template<
typename Scalar>
64 if(!this->warned_nonOverride)
65 #pragma omp critical (warning_weakform_nonOverride)
67 if(!this->warned_nonOverride)
68 this->warn(
"Using default WeakForm<Scalar>::clone, if you have any dynamically created data in your WeakForm constructor, you need to overload this method!");
71 return new WeakForm(*
this);
74 template<
typename Scalar>
75 void WeakForm<Scalar>::cloneMembers(
const WeakForm<Scalar>* otherWf)
86 for(
unsigned int i = 0; i < otherWf->forms.size(); i++)
88 if(
dynamic_cast<MatrixFormVol<Scalar>*
>(otherWf->forms[i]) != NULL)
89 this->forms.push_back((dynamic_cast<MatrixFormVol<Scalar>*>(otherWf->forms[i]))->clone());
90 if(
dynamic_cast<MatrixFormSurf<Scalar>*
>(otherWf->forms[i]) != NULL)
91 this->forms.push_back((dynamic_cast<MatrixFormSurf<Scalar>*>(otherWf->forms[i]))->clone());
92 if(
dynamic_cast<MatrixFormDG<Scalar>*
>(otherWf->forms[i]) != NULL)
93 this->forms.push_back((dynamic_cast<MatrixFormDG<Scalar>*>(otherWf->forms[i]))->clone());
95 if(
dynamic_cast<VectorFormVol<Scalar>*
>(otherWf->forms[i]) != NULL)
96 this->forms.push_back((dynamic_cast<VectorFormVol<Scalar>*>(otherWf->forms[i]))->clone());
97 if(
dynamic_cast<VectorFormSurf<Scalar>*
>(otherWf->forms[i]) != NULL)
98 this->forms.push_back((dynamic_cast<VectorFormSurf<Scalar>*>(otherWf->forms[i]))->clone());
99 if(
dynamic_cast<VectorFormDG<Scalar>*
>(otherWf->forms[i]) != NULL)
100 this->forms.push_back((dynamic_cast<VectorFormDG<Scalar>*>(otherWf->forms[i]))->clone());
102 Hermes::vector<MeshFunction<Scalar>*> newExt;
103 for(
unsigned int ext_i = 0; ext_i < otherWf->forms[i]->ext.size(); ext_i++)
104 newExt.push_back(otherWf->forms[i]->ext[ext_i]->clone());
105 this->forms.back()->set_ext(newExt);
106 this->forms.back()->wf =
this;
108 if(
dynamic_cast<MatrixFormVol<Scalar>*
>(otherWf->forms[i]) != NULL)
109 this->mfvol.push_back(
dynamic_cast<MatrixFormVol<Scalar>*
>(this->forms.back()));
110 if(
dynamic_cast<MatrixFormSurf<Scalar>*
>(otherWf->forms[i]) != NULL)
111 this->mfsurf.push_back(dynamic_cast<MatrixFormSurf<Scalar>*>(this->forms.back()));
112 if(
dynamic_cast<MatrixFormDG<Scalar>*
>(otherWf->forms[i]) != NULL)
113 this->mfDG.push_back(dynamic_cast<MatrixFormDG<Scalar>*>(this->forms.back()));
115 if(
dynamic_cast<VectorFormVol<Scalar>*
>(otherWf->forms[i]) != NULL)
116 this->vfvol.push_back(dynamic_cast<VectorFormVol<Scalar>*>(this->forms.back()));
117 if(
dynamic_cast<VectorFormSurf<Scalar>*
>(otherWf->forms[i]) != NULL)
118 this->vfsurf.push_back(dynamic_cast<VectorFormSurf<Scalar>*>(this->forms.back()));
119 if(
dynamic_cast<VectorFormDG<Scalar>*
>(otherWf->forms[i]) != NULL)
120 this->vfDG.push_back(dynamic_cast<VectorFormDG<Scalar>*>(this->forms.back()));
122 for(
unsigned int i = 0; i < otherWf->ext.size(); i++)
123 this->ext.push_back(otherWf->ext[i]->clone());
126 template<
typename Scalar>
138 template<
typename Scalar>
142 this->ext.push_back(ext);
145 template<
typename Scalar>
151 template<
typename Scalar>
152 Hermes::vector<MeshFunction<Scalar>*> WeakForm<Scalar>::get_ext()
const
157 template<
typename Scalar>
160 areas.push_back(HERMES_ANY);
164 template<
typename Scalar>
169 template<
typename Scalar>
175 template<
typename Scalar>
181 template<
typename Scalar>
185 areas.push_back(area);
187 template<
typename Scalar>
193 template<
typename Scalar>
194 Hermes::vector<std::string> Form<Scalar>::getAreas()
const
199 template<
typename Scalar>
200 void Form<Scalar>::setScalingFactor(
double scalingFactor)
202 this->scaling_factor = scalingFactor;
205 template<
typename Scalar>
206 void Form<Scalar>::set_uExtOffset(
int u_ext_offset)
208 this->u_ext_offset = u_ext_offset;
211 template<
typename Scalar>
215 this->ext.push_back(ext);
218 template<
typename Scalar>
224 template<
typename Scalar>
225 Hermes::vector<MeshFunction<Scalar>*> Form<Scalar>::get_ext()
const
230 template<
typename Scalar>
232 Form<Scalar>(), sym(HERMES_NONSYM), i(i), j(j), previous_iteration_space_index(-1)
236 template<
typename Scalar>
241 template<
typename Scalar>
242 Scalar MatrixForm<Scalar>::value(
int n,
double *wt, Func<Scalar> *u_ext[], Func<double> *u, Func<double> *v,
243 Geom<double> *e, Func<Scalar> **ext)
const
245 throw Hermes::Exceptions::MethodNotOverridenException(
"MatrixForm<Scalar>::value");
249 template<
typename Scalar>
250 Hermes::Ord MatrixForm<Scalar>::ord(
int n,
double *wt, Func<Hermes::Ord> *u_ext[], Func<Hermes::Ord> *u, Func<Hermes::Ord> *v,
251 Geom<Hermes::Ord> *e, Func<Ord> **ext)
const
253 throw Hermes::Exceptions::MethodNotOverridenException(
"MatrixForm<Scalar>::ord");
254 return Hermes::Ord();
257 template<
typename Scalar>
263 template<
typename Scalar>
268 template<
typename Scalar>
269 void MatrixFormVol<Scalar>::setSymFlag(
SymFlag sym)
274 template<
typename Scalar>
275 SymFlag MatrixFormVol<Scalar>::getSymFlag()
const
280 template<
typename Scalar>
281 MatrixFormVol<Scalar>* MatrixFormVol<Scalar>::clone()
const
283 throw Hermes::Exceptions::MethodNotOverridenException(
"MatrixFormVol<Scalar>::clone()");
287 template<
typename Scalar>
293 template<
typename Scalar>
296 throw Hermes::Exceptions::MethodNotOverridenException(
"MatrixFormSurf<Scalar>::clone()");
300 template<
typename Scalar>
301 MatrixFormSurf<Scalar>::~MatrixFormSurf()
305 template<
typename Scalar>
312 template<
typename Scalar>
317 template<
typename Scalar>
318 MatrixFormDG<Scalar>* MatrixFormDG<Scalar>::clone()
const
320 throw Hermes::Exceptions::MethodNotOverridenException(
"MatrixFormDG<Scalar>::clone()");
324 template<
typename Scalar>
330 template<
typename Scalar>
335 template<
typename Scalar>
341 template<
typename Scalar>
346 template<
typename Scalar>
347 Scalar VectorForm<Scalar>::value(
int n,
double *wt, Func<Scalar> *u_ext[], Func<double> *v,
348 Geom<double> *e, Func<Scalar> **ext)
const
350 throw Hermes::Exceptions::MethodNotOverridenException(
"VectorForm<Scalar>::value");
354 template<
typename Scalar>
355 Hermes::Ord VectorForm<Scalar>::ord(
int n,
double *wt, Func<Hermes::Ord> *u_ext[], Func<Hermes::Ord> *v,
356 Geom<Hermes::Ord> *e, Func<Ord> **ext)
const
358 throw Hermes::Exceptions::MethodNotOverridenException(
"VectorForm<Scalar>::ord");
359 return Hermes::Ord();
362 template<
typename Scalar>
363 VectorFormVol<Scalar>* VectorFormVol<Scalar>::clone()
const
365 throw Hermes::Exceptions::MethodNotOverridenException(
"VectorFormVol<Scalar>::clone()");
369 template<
typename Scalar>
375 template<
typename Scalar>
380 template<
typename Scalar>
381 VectorFormSurf<Scalar>* VectorFormSurf<Scalar>::clone()
const
383 throw Hermes::Exceptions::MethodNotOverridenException(
"VectorFormSurf<Scalar>::clone()");
387 template<
typename Scalar>
394 template<
typename Scalar>
399 template<
typename Scalar>
400 VectorFormDG<Scalar>* VectorFormDG<Scalar>::clone()
const
402 throw Hermes::Exceptions::MethodNotOverridenException(
"VectorFormDG<Scalar>::clone()");
406 template<
typename Scalar>
409 if(form->i >= neq || form->j >= neq)
410 throw Hermes::Exceptions::Exception(
"Invalid equation number.");
411 if(form->sym < -1 || form->sym > 1)
412 throw Hermes::Exceptions::Exception(
"\"sym\" must be -1, 0 or 1.");
413 if(form->sym < 0 && form->i == form->j)
414 throw Hermes::Exceptions::Exception(
"Only off-diagonal forms can be antisymmetric.");
415 if(mfvol.size() > 100)
417 this->warn(
"Large number of forms (> 100). Is this the intent?");
421 mfvol.push_back(form);
422 forms.push_back(form);
425 template<
typename Scalar>
428 if(form->i >= neq || form->j >= neq)
429 throw Hermes::Exceptions::Exception(
"Invalid equation number.");
432 mfsurf.push_back(form);
433 forms.push_back(form);
436 template<
typename Scalar>
439 if(form->i >= neq || form->j >= neq)
440 throw Hermes::Exceptions::Exception(
"Invalid equation number.");
443 mfDG.push_back(form);
444 forms.push_back(form);
447 template<
typename Scalar>
451 throw Hermes::Exceptions::Exception(
"Invalid equation number.");
453 vfvol.push_back(form);
454 forms.push_back(form);
457 template<
typename Scalar>
461 throw Hermes::Exceptions::Exception(
"Invalid equation number.");
464 vfsurf.push_back(form);
465 forms.push_back(form);
468 template<
typename Scalar>
472 throw Hermes::Exceptions::Exception(
"Invalid equation number.");
475 vfDG.push_back(form);
476 forms.push_back(form);
479 template<
typename Scalar>
485 template<
typename Scalar>
486 Hermes::vector<MatrixFormVol<Scalar> *> WeakForm<Scalar>::get_mfvol()
const
490 template<
typename Scalar>
491 Hermes::vector<MatrixFormSurf<Scalar> *> WeakForm<Scalar>::get_mfsurf()
const
495 template<
typename Scalar>
496 Hermes::vector<MatrixFormDG<Scalar> *> WeakForm<Scalar>::get_mfDG()
const
500 template<
typename Scalar>
501 Hermes::vector<VectorFormVol<Scalar> *> WeakForm<Scalar>::get_vfvol()
const
505 template<
typename Scalar>
506 Hermes::vector<VectorFormSurf<Scalar> *> WeakForm<Scalar>::get_vfsurf()
const
510 template<
typename Scalar>
511 Hermes::vector<VectorFormDG<Scalar> *> WeakForm<Scalar>::get_vfDG()
const
516 template<
typename Scalar>
517 bool** WeakForm<Scalar>::get_blocks(
bool force_diagonal_blocks)
const
519 bool** blocks = new_matrix<bool>(neq, neq);
520 for (
unsigned int i = 0; i < neq; i++)
522 for (
unsigned int j = 0; j < neq; j++)
523 blocks[i][j] =
false;
524 if(force_diagonal_blocks)
527 for (
unsigned i = 0; i < mfvol.size(); i++)
529 if(fabs(mfvol[i]->scaling_factor) > 1e-12)
530 blocks[mfvol[i]->i][mfvol[i]->j] =
true;
532 if(fabs(mfvol[i]->scaling_factor) > 1e-12)
533 blocks[mfvol[i]->j][mfvol[i]->i] =
true;
535 for (
unsigned i = 0; i < mfsurf.size(); i++)
537 if(fabs(mfsurf[i]->scaling_factor) > 1e-12)
538 blocks[mfsurf[i]->i][mfsurf[i]->j] =
true;
544 template<
typename Scalar>
550 template<
typename Scalar>
556 template<
typename Scalar>
557 void WeakForm<Scalar>::set_current_time_step(
double time_step)
559 current_time_step = time_step;
562 template<
typename Scalar>
563 double WeakForm<Scalar>::get_current_time_step()
const
565 return current_time_step;
568 template class HERMES_API WeakForm<double>;
569 template class HERMES_API WeakForm<std::complex<double> >;
570 template class HERMES_API Form<double>;
571 template class HERMES_API Form<std::complex<double> >;
572 template class HERMES_API MatrixForm<double>;
573 template class HERMES_API MatrixForm<std::complex<double> >;
574 template class HERMES_API MatrixFormVol<double>;
575 template class HERMES_API MatrixFormVol<std::complex<double> >;
576 template class HERMES_API MatrixFormSurf<double>;
577 template class HERMES_API MatrixFormSurf<std::complex<double> >;
578 template class HERMES_API MatrixFormDG<double>;
579 template class HERMES_API MatrixFormDG<std::complex<double> >;
580 template class HERMES_API VectorForm<double>;
581 template class HERMES_API VectorForm<std::complex<double> >;
582 template class HERMES_API VectorFormVol<double>;
583 template class HERMES_API VectorFormVol<std::complex<double> >;
584 template class HERMES_API VectorFormSurf<double>;
585 template class HERMES_API VectorFormSurf<std::complex<double> >;
586 template class HERMES_API VectorFormDG<double>;
587 template class HERMES_API VectorFormDG<std::complex<double> >;