26 template<
typename Scalar>
27 Filter<Scalar>::Filter()
31 template<
typename Scalar>
32 Filter<Scalar>::Filter(MeshFunction<Scalar>** solutions,
int num) : MeshFunction<Scalar>()
36 throw Hermes::Exceptions::Exception(
"Attempt to create an instance of Filter with more than 10 MeshFunctions.");
37 for(
int i = 0; i < this->num; i++)
38 this->sln[i] = solutions[i];
42 template<
typename Scalar>
43 Filter<Scalar>::Filter(
const Hermes::vector<MeshFunction<Scalar>*>& solutions) : MeshFunction<Scalar>()
45 this->num = solutions.size();
47 throw Hermes::Exceptions::Exception(
"Attempt to create an instance of Filter with more than 10 MeshFunctions.");
48 for(
int i = 0; i < this->num; i++)
49 this->sln[i] = solutions.at(i);
53 template<
typename Scalar>
54 Filter<Scalar>::Filter(
const Hermes::vector<Solution<Scalar>*>& solutions) : MeshFunction<Scalar>()
56 this->num = solutions.size();
58 throw Hermes::Exceptions::Exception(
"Attempt to create an instance of Filter with more than 10 MeshFunctions.");
59 for(
int i = 0; i < this->num; i++)
60 this->sln[i] = solutions.at(i);
64 template<
typename Scalar>
65 void Filter<Scalar>::init(
const Hermes::vector<MeshFunction<Scalar>*>& solutions)
67 this->num = solutions.size();
69 throw Hermes::Exceptions::Exception(
"Attempt to create an instance of Filter with more than 10 MeshFunctions.");
70 for(
int i = 0; i < this->num; i++)
71 this->sln[i] = solutions.at(i);
75 template<
typename Scalar>
76 void Filter<Scalar>::setDeleteSolutions()
78 this->deleteSolutions =
true;
81 template<
typename Scalar>
82 void Filter<Scalar>::init()
85 const Mesh* meshes[H2D_MAX_COMPONENTS];
86 for(
int i = 0; i < this->num; i++)
87 meshes[i] = this->sln[i]->get_mesh();
88 this->mesh = meshes[0];
91 for (
int i = 1; i < num; i++)
96 this->warn(
"You may be initializing a Filter with Solution that is missing a Mesh.");
97 throw Hermes::Exceptions::Exception(
"this->meshes[%d] is NULL in Filter<Scalar>::init().", i);
99 if(meshes[i]->get_seq() != this->mesh->get_seq())
109 trav.begin(num, meshes);
110 this->mesh =
new Mesh;
111 unidata = trav.construct_union_mesh(const_cast<Hermes2D::Mesh*>(this->mesh));
116 this->num_components = 1;
119 memset(sln_sub, 0,
sizeof(sln_sub));
120 set_quad_2d(&g_quad_2d_std);
122 this->deleteSolutions =
false;
125 template<
typename Scalar>
126 Filter<Scalar>::~Filter()
129 if(this->deleteSolutions)
131 for(
int i = 0; i < this->num; i++)
136 template<
typename Scalar>
140 for (
int i = 0; i < num; i++)
141 this->sln[i]->set_quad_2d(quad_2d);
144 template<
typename Scalar>
150 for (
int i = 0; i < num; i++)
151 this->sln[i]->set_active_element(e);
152 memset(sln_sub, 0,
sizeof(sln_sub));
156 for (
int i = 0; i < num; i++)
158 this->sln[i]->set_active_element(unidata[i][e->
id].e);
159 this->sln[i]->set_transform(unidata[i][e->
id].idx);
160 sln_sub[i] = this->sln[i]->get_transform();
164 for(
typename std::map<uint64_t, LightArray<
struct Filter<Scalar>::Node*>*>::iterator it = tables[this->cur_quad].begin(); it != tables[this->cur_quad].end(); it++)
166 for(
unsigned int l = 0; l < it->second->get_size(); l++)
167 if(it->second->present(l))
168 ::free(it->second->get(l));
171 tables[this->cur_quad].clear();
173 this->sub_tables = &tables[this->cur_quad];
174 this->update_nodes_ptr();
179 template<
typename Scalar>
182 for (
int i = 0; i < 4; i++)
184 for(
typename std::map<uint64_t, LightArray<
struct Filter<Scalar>::Node*>*>::iterator it = tables[i].begin(); it != tables[i].end(); it++)
186 for(
unsigned int l = 0; l < it->second->get_size(); l++)
187 if(it->second->present(l))
188 ::free(it->second->get(l));
197 for (
int i = 0; i < num; i++)
203 template<
typename Scalar>
210 template<
typename Scalar>
214 for (
int i = 0; i < num; i++)
225 if(this->sln[i]->get_transform() == sln_sub[i])
226 this->sln[i]->push_transform(son);
227 sln_sub[i] = this->sln[i]->get_transform();
231 template<
typename Scalar>
235 for (
int i = 0; i < num; i++)
237 if(this->sln[i]->get_transform() == sln_sub[i] && sln_sub[i] != 0)
238 this->sln[i]->pop_transform();
239 sln_sub[i] = this->sln[i]->get_transform();
243 template<
typename Scalar>
248 template<
typename Scalar>
249 SimpleFilter<Scalar>::SimpleFilter(
const Hermes::vector<MeshFunction<Scalar>*>& solutions,
const Hermes::vector<int>& items)
251 this->num = solutions.size();
253 throw Hermes::Exceptions::Exception(
"Attempt to create an instance of Filter with more than 10 MeshFunctions.");
254 if(items.size() != (unsigned) this->num)
256 throw Hermes::Exceptions::Exception(
"Attempt to create an instance of SimpleFilter with different supplied number of MeshFunctions than the number of types of data used from them.");
258 for(
int i = 0; i < this->num; i++)
261 this->sln[i] = solutions.at(i);
263 this->item[i] = items.at(i);
269 this->deleteSolutions =
false;
272 template<
typename Scalar>
273 SimpleFilter<Scalar>::SimpleFilter(
const Hermes::vector<Solution<Scalar>*>& solutions,
const Hermes::vector<int>& items)
275 this->num = solutions.size();
277 throw Hermes::Exceptions::Exception(
"Attempt to create an instance of Filter with more than 10 MeshFunctions.");
278 if(items.size() != (unsigned) this->num)
280 throw Hermes::Exceptions::Exception(
"Attempt to create an instance of SimpleFilter with different supplied number of MeshFunctions than the number of types of data used from them.");
282 for(
int i = 0; i < this->num; i++)
284 this->sln[i] = solutions.at(i);
286 this->item[i] = items.at(i);
292 this->deleteSolutions =
false;
295 template<
typename Scalar>
296 SimpleFilter<Scalar>::~SimpleFilter()
300 template<
typename Scalar>
301 void SimpleFilter<Scalar>::init_components()
303 bool vec1 =
false, vec2 =
false;
304 for (
int i = 0; i < this->num; i++)
306 if(this->sln[i]->get_num_components() > 1) vec1 =
true;
307 if((item[i] & H2D_FN_COMPONENT_0) && (item[i] & H2D_FN_COMPONENT_1)) vec2 =
true;
308 if(this->sln[i]->get_num_components() == 1) item[i] &= H2D_FN_COMPONENT_0;
310 this->num_components = (vec1 && vec2) ? 2 : 1;
313 template<
typename Scalar>
316 if(mask & (H2D_FN_DX | H2D_FN_DY | H2D_FN_DXX | H2D_FN_DYY | H2D_FN_DXY))
317 throw Hermes::Exceptions::Exception(
"Filter not defined for derivatives.");
319 Quad2D* quad = this->quads[this->cur_quad];
320 int np = quad->get_num_points(order, this->element->get_mode());
321 struct Function<Scalar>::
Node* node = this->new_node(H2D_FN_VAL, np);
324 for (int i = 0; i < this->num; i++)
325 this->sln[i]->set_quad_order(order, item[i]);
327 for (int j = 0; j < this->num_components; j++)
330 Scalar* tab[H2D_MAX_COMPONENTS];
331 for (
int i = 0; i < this->num; i++)
333 int a = 0, b = 0, mask = item[i];
334 if(mask >= 0x40) { a = 1; mask >>= 6; }
335 while (!(mask & 1)) { mask >>= 1; b++; }
336 tab[i] = this->sln[i]->get_values(this->
num_components == 1 ? a : j, b);
337 if(tab[i] == NULL)
throw Hermes::Exceptions::Exception(
"Value of 'item%d' is incorrect in filter definition.", i + 1);
340 Hermes::vector<Scalar*> values;
341 for(
int i = 0; i < this->num; i++)
342 values.push_back(tab[i]);
345 filter_fn(np, values, node->values[j][0]);
348 if(this->nodes->present(order))
350 assert(this->nodes->get(order) == this->cur_node);
351 ::free(this->nodes->get(order));
353 this->nodes->add(node, order);
354 this->cur_node = node;
357 template<
typename Scalar>
360 Scalar val[H2D_MAX_COMPONENTS];
361 for (
int i = 0; i < this->num; i++)
362 val[i] = this->sln[i]->get_pt_value(x, y)->val[0];
367 Hermes::vector<Scalar*> values;
368 for(
int i = 0; i < this->num; i++)
369 values.push_back(&val[i]);
372 filter_fn(1, values, &result);
374 toReturn->
val[0] = result;
378 template<
typename Scalar>
383 template<
typename Scalar>
384 DXFilter<Scalar>::~DXFilter()
388 template<
typename Scalar>
389 void DXFilter<Scalar>::filter_fn(
int n, Hermes::vector<Scalar *> values, Hermes::vector<Scalar *> dx, Hermes::vector<Scalar *> dy, Scalar* rslt, Scalar* rslt_dx, Scalar* rslt_dy)
391 for (
int i = 0; i < n; i++)
395 for(
unsigned int j = 0; j < values.size(); j++)
397 rslt_dx[i] += dx.at(j)[i];
398 rslt_dy[i] += dy.at(j)[i];
403 template<
typename Scalar>
404 MeshFunction<Scalar>* DXFilter<Scalar>::clone()
const
406 Hermes::vector<MeshFunction<Scalar>*> slns;
407 Hermes::vector<int> items;
408 for(
int i = 0; i < this->num; i++)
410 slns.push_back(this->sln[i]->clone());
412 DXFilter<Scalar>* filter =
new DXFilter<Scalar>(slns);
413 filter->setDeleteSolutions();
417 ComplexFilter::ComplexFilter(MeshFunction<std::complex<double> >* solution,
int item) : Filter<double>()
420 this->unimesh =
false;
421 this->sln_complex = solution;
423 this->mesh = solution->get_mesh();
427 this->deleteSolutions =
false;
430 ComplexFilter::~ComplexFilter()
437 for (
int i = 0; i < 4; i++)
439 #ifdef _MSC_VER // For Visual Studio compiler the latter does not compile.
440 for(std::map<uint64_t, LightArray<Node*>*>::iterator it =
tables[i].begin(); it !=
tables[i].end(); it++)
445 for(
unsigned int l = 0; l < it->second->get_size(); l++)
446 if(it->second->present(l))
447 ::
free(it->second->get(l));
453 if(this->deleteSolutions)
454 delete this->sln_complex;
469 memset(sln_sub, 0,
sizeof(sln_sub));
473 for(
unsigned int l = 0; l < it->second->get_size(); l++)
474 if(it->second->present(l))
475 ::
free(it->second->get(l));
501 if(mask & (H2D_FN_DX | H2D_FN_DY | H2D_FN_DXX | H2D_FN_DYY | H2D_FN_DXY))
502 throw Hermes::Exceptions::Exception(
"Filter not defined for derivatives.");
505 int np = quad->get_num_points(order, this->
element->get_mode());
511 filter_fn(np, this->sln_complex->get_values(0, 0), node->values[0][0]);
512 if(num_components > 1)
513 filter_fn(np, this->sln_complex->get_values(1, 0), node->values[1][0]);
515 if(this->
nodes->present(order))
533 filter_fn(1, val->
val, &result);
537 toReturn->
val[0] = result;
538 toReturn->dx[0] = 0.0;
539 toReturn->
dy[0] = 0.0;
543 this->warn(
"ComplexFilter only implemented for scalar functions.");
548 template<
typename Scalar>
553 template<
typename Scalar>
554 DXDYFilter<Scalar>::DXDYFilter(
const Hermes::vector<MeshFunction<Scalar>*>& solutions) : Filter<Scalar>(solutions)
559 template<
typename Scalar>
560 DXDYFilter<Scalar>::DXDYFilter(
const Hermes::vector<Solution<Scalar>*>& solutions) : Filter<Scalar>(solutions)
565 template<
typename Scalar>
566 DXDYFilter<Scalar>::~DXDYFilter()
570 template<
typename Scalar>
571 void DXDYFilter<Scalar>::init_components()
573 this->num_components = this->sln[0]->get_num_components();
574 for (
int i = 1; i < this->num; i++)
575 if(this->sln[i]->get_num_components() != this->num_components)
576 throw Hermes::Exceptions::Exception(
"Filter: Solutions do not have the same number of components!");
579 template<
typename Scalar>
580 void DXDYFilter<Scalar>::init(
const Hermes::vector<MeshFunction<Scalar>*>& solutions)
582 Filter<Scalar>::init(solutions);
586 template<
typename Scalar>
589 Quad2D* quad = this->quads[this->cur_quad];
590 int np = quad->get_num_points(order, this->element->get_mode());
591 struct Function<Scalar>::
Node* node = this->new_node(H2D_FN_DEFAULT, np);
594 for (int i = 0; i < this->num; i++)
595 this->sln[i]->set_quad_order(order, H2D_FN_DEFAULT);
597 for (int j = 0; j < this->num_components; j++)
600 Scalar *val[H2D_MAX_COMPONENTS], *dx[H2D_MAX_COMPONENTS], *dy[H2D_MAX_COMPONENTS];
601 for (
int i = 0; i < this->num; i++)
604 dx[i] = this->sln[i]->get_dx_values(j);
605 dy[i] = this->sln[i]->get_dy_values(j);
608 Hermes::vector<Scalar *> values_vector;
609 Hermes::vector<Scalar *> dx_vector;
610 Hermes::vector<Scalar *> dy_vector;
612 for(
int i = 0; i < this->num; i++)
614 values_vector.push_back(val[i]);
615 dx_vector.push_back(dx[i]);
616 dy_vector.push_back(dy[i]);
620 filter_fn(np, values_vector, dx_vector, dy_vector, node->values[j][0], node->values[j][1], node->values[j][2]);
623 if(this->nodes->present(order))
625 assert(this->nodes->get(order) == this->cur_node);
626 ::free(this->nodes->get(order));
628 this->nodes->add(node, order);
629 this->cur_node = node;
632 template<
typename Scalar>
638 template<
typename Scalar>
641 for (
int i = 0; i < n; i++)
645 for(
unsigned int j = 0; j < values.size(); j++)
646 result[i] += sqr(values.at(j)[i]);
647 result[i] = sqrt(result[i]);
651 template<
typename Scalar>
652 MagFilter<Scalar>::MagFilter(Hermes::vector<MeshFunction<Scalar>*> solutions, Hermes::vector<int> items) : SimpleFilter<Scalar>(solutions, items)
656 template<
typename Scalar>
659 Hermes::vector<int>(item1 & H2D_FN_COMPONENT_0, item1 & H2D_FN_COMPONENT_1))
662 throw Hermes::Exceptions::Exception(
"The single-argument constructor is intended for vector-valued solutions.");
665 template<
typename Scalar>
670 template<
typename Scalar>
671 MeshFunction<Scalar>* MagFilter<Scalar>::clone()
const
673 Hermes::vector<MeshFunction<Scalar>*> slns;
674 Hermes::vector<int> items;
675 for(
int i = 0; i < this->num; i++)
677 slns.push_back(this->sln[i]->clone());
678 items.push_back(this->item[i]);
680 MagFilter<Scalar>* filter =
new MagFilter<Scalar>(slns, items);
681 filter->setDeleteSolutions();
685 void TopValFilter::filter_fn(
int n, Hermes::vector<double*> values,
double* result)
687 for (
int i = 0; i < n; i++)
690 for(
unsigned int j = 0; j < values.size(); j++)
691 if(values.at(j)[i] > limits[j])
692 result[i] = limits[j];
694 result[i] = values.at(j)[i];
698 TopValFilter::TopValFilter(Hermes::vector<MeshFunction<double>*> solutions, Hermes::vector<double> limits, Hermes::vector<int> items) : SimpleFilter<double>(solutions, items), limits(limits)
705 this->limits.push_back(limit);
707 this->item[0] = item;
712 TopValFilter::~TopValFilter()
716 MeshFunction<double>* TopValFilter::clone()
const
718 Hermes::vector<MeshFunction<double>*> slns;
719 Hermes::vector<int> items;
720 for(
int i = 0; i < this->num; i++)
722 slns.push_back(this->sln[i]->clone());
723 items.push_back(this->item[i]);
725 TopValFilter* filter =
new TopValFilter(slns, limits, items);
726 filter->setDeleteSolutions();
730 void BottomValFilter::filter_fn(
int n, Hermes::vector<double*> values,
double* result)
732 for (
int i = 0; i < n; i++)
735 for(
unsigned int j = 0; j < values.size(); j++)
736 if(values.at(j)[i] < limits[j])
737 result[i] = limits[j];
739 result[i] = values.at(j)[i];
743 BottomValFilter::BottomValFilter(Hermes::vector<MeshFunction<double>*> solutions, Hermes::vector<double> limits, Hermes::vector<int> items) : SimpleFilter<double>(solutions, items), limits(limits)
750 this->limits.push_back(limit);
752 this->item[0] = item;
757 BottomValFilter::~BottomValFilter()
761 MeshFunction<double>* BottomValFilter::clone()
const
763 Hermes::vector<MeshFunction<double>*> slns;
764 Hermes::vector<int> items;
765 for(
int i = 0; i < this->num; i++)
767 slns.push_back(this->sln[i]->clone());
768 items.push_back(this->item[i]);
770 BottomValFilter* filter =
new BottomValFilter(slns, limits, items);
771 filter->setDeleteSolutions();
775 void ValFilter::filter_fn(
int n, Hermes::vector<double*> values,
double* result)
777 for (
int i = 0; i < n; i++)
780 for(
unsigned int j = 0; j < values.size(); j++)
781 if(values.at(j)[i] < low_limits[j])
782 result[i] = low_limits[j];
784 if(values.at(j)[i] > high_limits[j])
785 result[i] = high_limits[j];
787 result[i] = values.at(j)[i];
791 ValFilter::ValFilter(Hermes::vector<MeshFunction<double>*> solutions, Hermes::vector<double> low_limits, Hermes::vector<double> high_limits, Hermes::vector<int> items) : SimpleFilter<double>(solutions, items), low_limits(low_limits), high_limits(high_limits)
798 this->low_limits.push_back(low_limit);
799 this->high_limits.push_back(high_limit);
801 this->item[0] = item;
806 ValFilter::~ValFilter()
810 MeshFunction<double>* ValFilter::clone()
const
812 Hermes::vector<MeshFunction<double>*> slns;
813 Hermes::vector<int> items;
814 for(
int i = 0; i < this->num; i++)
816 slns.push_back(this->sln[i]->clone());
817 items.push_back(this->item[i]);
819 ValFilter* filter =
new ValFilter(slns, low_limits, high_limits, items);
820 filter->setDeleteSolutions();
824 template<
typename Scalar>
825 void DiffFilter<Scalar>::filter_fn(
int n, Hermes::vector<Scalar*> values, Scalar* result)
827 for (
int i = 0; i < n; i++) result[i] = values.at(0)[i] - values.at(1)[i];
830 template<
typename Scalar>
831 DiffFilter<Scalar>::DiffFilter(Hermes::vector<MeshFunction<Scalar>*> solutions, Hermes::vector<int> items) : SimpleFilter<Scalar>(solutions, items) {}
833 template<
typename Scalar>
834 DiffFilter<Scalar>::~DiffFilter()
838 template<
typename Scalar>
839 MeshFunction<Scalar>* DiffFilter<Scalar>::clone()
const
841 Hermes::vector<MeshFunction<Scalar>*> slns;
842 Hermes::vector<int> items;
843 for(
int i = 0; i < this->num; i++)
845 slns.push_back(this->sln[i]->clone());
846 items.push_back(this->item[i]);
848 DiffFilter* filter =
new DiffFilter<Scalar>(slns, items);
849 filter->setDeleteSolutions();
853 template<
typename Scalar>
854 void SumFilter<Scalar>::filter_fn(
int n, Hermes::vector<Scalar*> values, Scalar* result)
856 for (
int i = 0; i < n; i++)
859 for (
unsigned int j = 0; j < values.size(); j++)
860 result[i] += values.at(j)[i];
864 template<
typename Scalar>
865 SumFilter<Scalar>::SumFilter(Hermes::vector<MeshFunction<Scalar>*> solutions, Hermes::vector<int> items) : SimpleFilter<Scalar>(solutions, items) {}
867 template<
typename Scalar>
868 SumFilter<Scalar>::~SumFilter()
872 template<
typename Scalar>
873 MeshFunction<Scalar>* SumFilter<Scalar>::clone()
const
875 Hermes::vector<MeshFunction<Scalar>*> slns;
876 Hermes::vector<int> items;
877 for(
int i = 0; i < this->num; i++)
879 slns.push_back(this->sln[i]->clone());
880 items.push_back(this->item[i]);
882 SumFilter<Scalar>* filter =
new SumFilter<Scalar>(slns, items);
883 filter->setDeleteSolutions();
888 void SquareFilter<double>::filter_fn(
int n, Hermes::vector<double *> v1,
double* result)
890 for (
int i = 0; i < n; i++)
891 result[i] = sqr(v1.at(0)[i]);
895 void SquareFilter<std::complex<double> >::filter_fn(
int n, Hermes::vector<std::complex<double> *> v1, std::complex<double> * result)
897 for (
int i = 0; i < n; i++)
898 result[i] = std::norm(v1.at(0)[i]);
901 template<
typename Scalar>
902 SquareFilter<Scalar>::SquareFilter(Hermes::vector<MeshFunction<Scalar>*> solutions, Hermes::vector<int> items)
903 : SimpleFilter<Scalar>(solutions, items)
905 if(solutions.size() > 1)
906 throw Hermes::Exceptions::Exception(
"SquareFilter only supports one MeshFunction.");
909 template<
typename Scalar>
910 SquareFilter<Scalar>::~SquareFilter()
914 template<
typename Scalar>
915 MeshFunction<Scalar>* SquareFilter<Scalar>::clone()
const
917 Hermes::vector<MeshFunction<Scalar>*> slns;
918 Hermes::vector<int> items;
919 for(
int i = 0; i < this->num; i++)
921 slns.push_back(this->sln[i]->clone());
922 items.push_back(this->item[i]);
924 SquareFilter<Scalar>* filter =
new SquareFilter<Scalar>(slns, items);
925 filter->setDeleteSolutions();
929 void AbsFilter::filter_fn(
int n, Hermes::vector<double*> v1,
double * result)
931 for (
int i = 0; i < n; i++)
932 result[i] = std::abs(v1.at(0)[i]);
935 AbsFilter::AbsFilter(Hermes::vector<MeshFunction<double>*> solutions, Hermes::vector<int> items)
936 : SimpleFilter<double>(solutions, items)
938 if(solutions.size() > 1)
939 throw Hermes::Exceptions::Exception(
"AbsFilter only supports one MeshFunction.");
942 AbsFilter::AbsFilter(MeshFunction<double>* solution)
943 : SimpleFilter<double>()
946 this->sln[0] = solution;
954 AbsFilter::~AbsFilter()
958 MeshFunction<double>* AbsFilter::clone()
const
960 Hermes::vector<MeshFunction<double>*> slns;
961 Hermes::vector<int> items;
962 for(
int i = 0; i < this->num; i++)
964 slns.push_back(this->sln[i]->clone());
965 items.push_back(this->item[i]);
967 AbsFilter* filter =
new AbsFilter(slns, items);
968 filter->setDeleteSolutions();
972 void RealFilter::filter_fn(
int n, std::complex<double>* values,
double* result)
974 for (
int i = 0; i < n; i++)
975 result[i] = values[i].real();
978 MeshFunction<double>* RealFilter::clone()
const
980 RealFilter* filter =
new RealFilter(this->sln_complex->clone(), this->item);
981 filter->setDeleteSolutions();
985 RealFilter::RealFilter(MeshFunction<std::complex<double> >* solution,
int item)
986 : ComplexFilter(solution, item)
990 RealFilter::~RealFilter()
994 void ImagFilter::filter_fn(
int n, std::complex<double>* values,
double* result)
996 for (
int i = 0; i < n; i++)
997 result[i] = values[i].imag();
1000 ImagFilter::ImagFilter(MeshFunction<std::complex<double> >* solution,
int item)
1001 : ComplexFilter(solution, item)
1005 ImagFilter::~ImagFilter()
1009 MeshFunction<double>* ImagFilter::clone()
const
1011 ImagFilter* filter =
new ImagFilter(this->sln_complex->clone(), this->item);
1012 filter->setDeleteSolutions();
1016 void ComplexAbsFilter::filter_fn(
int n, std::complex<double>* values,
double* result)
1018 for (
int i = 0; i < n; i++)
1019 result[i] = sqrt(sqr(values[i].real()) + sqr(values[i].imag()));
1022 MeshFunction<double>* ComplexAbsFilter::clone()
const
1024 ComplexAbsFilter* filter =
new ComplexAbsFilter(this->sln_complex->clone(), this->item);
1025 filter->setDeleteSolutions();
1029 ComplexAbsFilter::ComplexAbsFilter(MeshFunction<std::complex<double> >* solution,
int item)
1030 : ComplexFilter(solution, item)
1034 ComplexAbsFilter::~ComplexAbsFilter()
1038 void AngleFilter::filter_fn(
int n, Hermes::vector<std::complex<double>*> v1,
double* result)
1040 for (
int i = 0; i < n; i++)
1041 result[i] = atan2( v1.at(0)[i].imag(), v1.at(0)[i].real() );
1044 AngleFilter::AngleFilter(Hermes::vector<MeshFunction<std::complex<double> >*> solutions, Hermes::vector<int> items)
1045 : SimpleFilter<std::complex<double> >(solutions, items)
1047 if(solutions.size() > 1)
1048 throw Hermes::Exceptions::Exception(
"RealFilter only supports one MeshFunction.");
1051 AngleFilter::~AngleFilter()
1057 if(mask & (H2D_FN_DX | H2D_FN_DY | H2D_FN_DXX | H2D_FN_DYY | H2D_FN_DXY))
1058 throw Hermes::Exceptions::Exception(
"VonMisesFilter not defined for derivatives.");
1061 int np = quad->get_num_points(order, this->
element->get_mode());
1067 double *dudx, *dudy, *dvdx, *dvdy;
1074 for (
int i = 0; i < np; i++)
1077 double tz = lambda*(dudx[i] + dvdy[i]);
1078 double tx = tz + 2*mu*dudx[i];
1079 double ty = tz + 2*mu*dvdy[i];
1080 if(cyl) tz += 2*mu*uval[i] / x[i];
1081 double txy = mu*(dudy[i] + dvdx[i]);
1084 node->values[0][0][i] = 1.0/sqrt(2.0) * sqrt(sqr(tx - ty) + sqr(ty - tz) + sqr(tz - tx) + 6*sqr(txy));
1087 if(this->
nodes->present(order))
1092 this->
nodes->add(node, order);
1102 int cyl,
int item1,
int item2)
1103 :
Filter<double>(solutions)
1106 this->lambda = lambda;
1108 this->item1 = item1;
1109 this->item2 = item2;
1113 int cyl,
int item1,
int item2):
Filter<double>(solutions, num)
1116 this->lambda = lambda;
1118 this->item1 = item1;
1119 this->item2 = item2;
1122 VonMisesFilter::~VonMisesFilter()
1126 MeshFunction<double>* VonMisesFilter::clone()
const
1128 MeshFunction<double>** slns =
new MeshFunction<double>*[num];
1129 for(
int i = 0; i < num; i++)
1130 slns[i] = sln[i]->clone();
1132 filter->setDeleteSolutions();
1136 template<
typename Scalar>
1139 Quad2D* quad = this->quads[this->cur_quad];
1140 int np = quad->get_num_points(order, this->element->get_mode());
1141 struct Filter<Scalar>::
Node* node = this->new_node(H2D_FN_DEFAULT, np);
1144 for (int i = 0; i < this->num; i++)
1145 this->sln[i]->set_quad_order(order);
1147 for (int j = 0; j < this->num_components; j++)
1150 Scalar *val[H2D_MAX_COMPONENTS], *dx[H2D_MAX_COMPONENTS], *dy[H2D_MAX_COMPONENTS];
1151 for (
int i = 0; i < this->num; i++)
1153 val[i] = this->sln[i]->get_fn_values(j);
1154 dx[i] = this->sln[i]->get_dx_values(j);
1155 dy[i] = this->sln[i]->get_dy_values(j);
1158 for (
int i = 0; i < np; i++)
1160 node->values[j][0][i] = tau_frac * (val[1][i] - val[0][i]) + val[1][i];
1161 node->values[j][1][i] = tau_frac * (dx[1][i] - dx[0][i]) + dx[1][i];
1162 node->values[j][2][i] = tau_frac * (dy[1][i] - dy[0][i]) + dy[1][i];
1165 for (
int i = 0; i < np; i++)
1167 node->values[j][0][i] = val[0][i];
1168 node->values[j][1][i] = dx[0][i];
1169 node->values[j][2][i] = dy[0][i];
1173 if(this->nodes->present(order))
1175 assert(this->nodes->get(order) == this->cur_node);
1176 ::free(this->nodes->get(order));
1178 this->nodes->add(node, order);
1179 this->cur_node = node;
1182 template<
typename Scalar>
1188 template<
typename Scalar>
1194 template<
typename Scalar>
1195 LinearFilter<Scalar>::LinearFilter(MeshFunction<Scalar>* older, MeshFunction<Scalar>* old,
double tau_frac)
1196 : Filter<Scalar>(Hermes::vector<MeshFunction<Scalar>*>(older, old))
1198 this->tau_frac = tau_frac;
1202 template<
typename Scalar>
1203 LinearFilter<Scalar>::~LinearFilter()
1207 template<
typename Scalar>
1208 void LinearFilter<Scalar>::init_components()
1210 this->num_components = this->sln[0]->get_num_components();
1211 for (
int i = 1; i < this->num; i++)
1212 if(this->sln[i]->get_num_components() != this->num_components)
1213 throw Hermes::Exceptions::Exception(
"Filter: Solutions do not have the same number of components!");
1216 template<
typename Scalar>
1222 for (
int i = 0; i < this->num; i++)
1224 int o = this->sln[i]->get_fn_order();
1225 if(o > this->order) this->order = o;