ug4
Loading...
Searching...
No Matches
grid_function_util.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3 * Author: Andreas Vogel
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef __H__UG__LIB_DISC__FUNCTION_SPACE__GRID_FUNCTION_UTIL__
34#define __H__UG__LIB_DISC__FUNCTION_SPACE__GRID_FUNCTION_UTIL__
35
36#include <vector>
37#include <string>
38#include <cmath> // for isinf, isnan
39
40
42
57#include "lib_grid/algorithms/debug_util.h" // for ElementDebugInfo
59
60#include "grid_function.h"
61#include "dof_position_util.h"
62
63#ifdef UG_PARALLEL
64#include "pcl/pcl.h"
65#endif
66
67namespace ug {
68
69#ifndef isnan
70using boost::math::isnan;
71#endif
72
73#ifndef isinf
74using boost::math::isinf;
75#endif
76
77
78template <typename TBaseElem, typename TGridFunction>
79static void ScaleGFOnElems
80(
84 const std::vector<number>& vScale
85)
86{
88 std::vector<DoFIndex> vInd;
89
90 try
91 {
92 // iterate all elements (including SHADOW_RIM_COPY!)
93 iter = dd->template begin<TBaseElem>(SurfaceView::ALL);
94 iterEnd = dd->template end<TBaseElem>(SurfaceView::ALL);
95 for (; iter != iterEnd; ++iter)
96 {
97 for (size_t fi = 0; fi < dd->num_fct(); ++fi)
98 {
99 size_t nInd = dd->inner_dof_indices(*iter, fi, vInd);
100
101 // remember multi indices
102 for (size_t dof = 0; dof < nInd; ++dof)
103 DoFRef(*vecOut, vInd[dof]) = vScale[fi] * DoFRef(*vecIn, vInd[dof]);
104 }
105 }
106 }
107 UG_CATCH_THROW("Error while scaling vector.")
108}
109
110
120template <typename TGridFunction>
122(
123 SmartPtr<TGridFunction> scaledVecOut,
125 const std::vector<number>& scalingFactors
126)
127{
128 // check that the correct numbers of scaling factors are given
129 size_t n = scalingFactors.size();
130 UG_COND_THROW(n != vecIn->num_fct(), "Number of scaling factors (" << n << ") "
131 "does not match number of functions given in dimless vector (" << vecIn->num_fct() << ").");
132
133 // check that input and output vectors have the same number of components and dofs
134 UG_COND_THROW(n != scaledVecOut->num_fct(), "Input and output vectors do not have "
135 "the same number of functions (" << n << " vs. " << scaledVecOut->num_fct() << ").");
136 for (size_t fct = 0; fct < n; ++fct)
137 {
138 UG_COND_THROW(vecIn->num_dofs(fct) != scaledVecOut->num_dofs(fct),
139 "Input and output vectors do not have the same number of DoFs for function " << fct
140 << " (" << vecIn->num_dofs(fct) << " vs. " << scaledVecOut->num_dofs(fct) << ").");
141 }
142
143 ConstSmartPtr<DoFDistribution> dd = vecIn->dof_distribution();
144
145 if (dd->max_dofs(VERTEX))
146 ScaleGFOnElems<Vertex, TGridFunction>(dd, scaledVecOut, vecIn, scalingFactors);
147 if (dd->max_dofs(EDGE))
148 ScaleGFOnElems<Edge, TGridFunction>(dd, scaledVecOut, vecIn, scalingFactors);
149 if (dd->max_dofs(FACE))
150 ScaleGFOnElems<Face, TGridFunction>(dd, scaledVecOut, vecIn, scalingFactors);
151 if (dd->max_dofs(VOLUME))
152 ScaleGFOnElems<Volume, TGridFunction>(dd, scaledVecOut, vecIn, scalingFactors);
153}
154
155
156
157
159// AverageComponent
161
169template<typename TGridFunction, typename TBaseElem>
171{
172 typedef TGridFunction GF;
173 typedef typename GF::template traits<TBaseElem>::const_iterator iter_type;
174
175 iter_type iter = spGF->template begin<TBaseElem>();
176 iter_type iterEnd = spGF->template end<TBaseElem>();
177
178 PeriodicBoundaryManager* pbm = spGF->domain()->grid()->periodic_boundary_manager();
179
180// loop elems
181 std::vector<DoFIndex> vMultInd;
182 for(; iter != iterEnd; ++iter)
183 {
184 // get element
185 TBaseElem* elem = *iter;
186
187 // skip periodic ghosts
188 if (pbm && pbm->is_slave(elem)) continue;
189
190 // get global indices
191 spGF->inner_dof_indices(elem, fct, vMultInd);
192
193 // sum up value
194 for(size_t i = 0; i < vMultInd.size(); ++i)
195 {
196 DoFRef(*spGF, vMultInd[i]) -= sub;
197 }
198 }
199}
200
211template<typename TGridFunction>
213(
215 const std::vector<std::string>& vCmp,
216 number mean
217)
218{
219 typedef TGridFunction GF;
220 PROFILE_FUNC_GROUP("gmg");
221
222 if(vCmp.empty())
223 return;
224
225 if(spGF.invalid())
226 UG_THROW("AverageComponent: expects a valid GridFunction.");
227
229 spGF->approx_space()->dof_distribution_info();
230
231// compute integral of components
232 const number area = Integral(1.0, spGF);
233 std::vector<number> vIntegral(vCmp.size(), 0.0);
234 for(size_t f = 0; f < vCmp.size(); f++){
235 const size_t fct = spGF->fct_id_by_name(vCmp[f].c_str());
236 vIntegral[f] = Integral(spGF, vCmp[f].c_str(), NULL, ddinfo->lfeid(fct).order());
237 }
238
239// subtract value
240 for(size_t f = 0; f < vCmp.size(); f++)
241 {
242 const number sub = (vIntegral[f] - mean) / area;
243 const size_t fct = spGF->fct_id_by_name(vCmp[f].c_str());
244
245 if(ddinfo->max_fct_dofs(fct, VERTEX)) SubtractValueFromComponent<GF, Vertex>(spGF, fct, sub);
246 if(ddinfo->max_fct_dofs(fct, EDGE)) SubtractValueFromComponent<GF, Edge>(spGF, fct, sub);
247 if(ddinfo->max_fct_dofs(fct, FACE)) SubtractValueFromComponent<GF, Face>(spGF, fct, sub);
248 if(ddinfo->max_fct_dofs(fct, VOLUME)) SubtractValueFromComponent<GF, Volume>(spGF, fct, sub);
249 }
250}
251
259template<typename TGridFunction>
260void AdjustMeanValue(SmartPtr<TGridFunction> spGF, const std::vector<std::string>& vCmp)
261{
262 AdjustMeanValue(spGF, vCmp, 0.0);
263}
264
272template<typename TGridFunction>
273void AdjustMeanValue(SmartPtr<TGridFunction> spGF, const std::string& fcts)
274{
275 AdjustMeanValue(spGF, TokenizeTrimString(fcts), 0.0);
276}
277
288template<typename TGridFunction>
289void AdjustMeanValue(SmartPtr<TGridFunction> spGF, const std::string& fcts, number mean)
290{
291 AdjustMeanValue(spGF, TokenizeTrimString(fcts), mean);
292}
293
295// Summing up components
297
304template <typename TGridFunction, typename TBaseElem>
306(
307 TGridFunction * u,
308 size_t fct
309)
310{
311 typedef typename TGridFunction::template traits<TBaseElem>::const_iterator t_elem_iter;
312
313 std::vector<DoFIndex> ind;
314 number sum (1);
315
316 sum = 0;
317// Loop the elements in the subset
318 for (t_elem_iter vi = u->template begin<TBaseElem> ();
319 vi != u->template end<TBaseElem> (); ++vi)
320 {
321 TBaseElem * vert = *vi;
322
323 // indices at this element
324 u->inner_dof_indices (vert, fct, ind);
325
326 if (ind.size () != 1)
327 UG_THROW ("SumGFValuesAt: The function must be scalar!");
328
329 // add the contribution
330 sum += DoFRef (*u, ind [0]);
331 }
332
333#ifdef UG_PARALLEL
335 sum = procComm.allreduce (sum, PCL_RO_SUM);
336#endif
337
338 return sum;
339}
340
349template <typename TGridFunction, typename TBaseElem>
351(
352 TGridFunction * u,
353 const char * fct_names
354)
355{
356// Get the function index
357 std::vector<std::string> vfctNames;
358 TokenizeString (fct_names, vfctNames);
359 if (vfctNames.size () != 1)
360 UG_THROW ("SumGFValuesAt: Exactly one function name must be specified.");
361 FunctionGroup fctGroup (u->function_pattern ());
362 fctGroup.add (vfctNames [0]);
363
364// Compute the sum
365 return SumGFValuesAt<TGridFunction, TBaseElem> (u, fctGroup[0]);
366}
367
374template <typename TGridFunction, typename TBaseElem>
376(
377 TGridFunction * u,
378 size_t fct,
379 SubsetGroup & ssGroup
380)
381{
382 typedef typename TGridFunction::template traits<TBaseElem>::const_iterator t_elem_iter;
383
384 std::vector<DoFIndex> ind;
385 number sum (1);
386
387// Loop the selected subsets
388 sum = 0;
389 for (size_t i = 0; i < ssGroup.size (); i++)
390 {
391 int ssi = ssGroup [i];
392
393 // Loop the elements in the subset
394 for (t_elem_iter vi = u->template begin<TBaseElem> (ssi);
395 vi != u->template end<TBaseElem> (ssi); ++vi)
396 {
397 TBaseElem * vert = *vi;
398
399 // indices at this element
400 u->inner_dof_indices (vert, fct, ind);
401
402 if (ind.size () != 1)
403 UG_THROW ("SumGFValuesAt: The function must be scalar!");
404
405 // add the contribution
406 sum += DoFRef (*u, ind [0]);
407 }
408 }
409
410#ifdef UG_PARALLEL
412 sum = procComm.allreduce (sum, PCL_RO_SUM);
413#endif
414
415 return sum;
416}
417
426template <typename TGridFunction, typename TBaseElem>
428(
429 TGridFunction * u,
430 const char * fct_names,
431 const char * subset_names
432)
433{
434// Get the function index
435 std::vector<std::string> vfctNames;
436 TokenizeString (fct_names, vfctNames);
437 if (vfctNames.size () != 1)
438 UG_THROW ("SumGFValuesAt: Exactly one function name must be specified.");
439 FunctionGroup fctGroup (u->function_pattern ());
440 fctGroup.add (vfctNames [0]);
441
442// Get the subset indices
443 std::vector<std::string> vssNames;
444 TokenizeString (subset_names, vssNames);
445 SubsetGroup ssGroup (u->domain()->subset_handler ());
446 ssGroup.add (vssNames);
447
448// Compute the sum
449 return SumGFValuesAt<TGridFunction, TBaseElem> (u, fctGroup[0], ssGroup);
450}
451
453// Checking components for nan and inf
455
462template <typename TGridFunction, typename TBaseElem>
464(
465 const TGridFunction * u,
466 size_t fct
467)
468{
469 typedef typename TGridFunction::template traits<TBaseElem>::const_iterator t_elem_iter;
470
471 std::vector<DoFIndex> ind;
472
473// Loop the elements in the subset
474 for (t_elem_iter vi = u->template begin<TBaseElem> ();
475 vi != u->template end<TBaseElem> (); ++vi)
476 {
477 TBaseElem * vert = *vi;
478
479 // indices at this element
480 u->inner_dof_indices (vert, fct, ind);
481
482 if (ind.size () != 1)
483 UG_THROW ("CheckGFforNaN: The function must be scalar!");
484
485 // check the value
486 number value = DoFRef (*u, ind [0]);
487 if (isnan (value))
488 {
489 int si = u->domain()->subset_handler()->get_subset_index (vert);
490 UG_LOG ("nan at index " << ind [0] << ", grid data idx " << vert->grid_data_index ());
491 if (si >= 0)
492 UG_LOG (", subset " << u->domain()->subset_handler()->get_subset_name (si))
493 UG_LOG ('\n');
494 return true;
495 }
496 if (isinf (value))
497 {
498 int si = u->domain()->subset_handler()->get_subset_index (vert);
499 UG_LOG ("inf at index " << ind [0] << ", grid data idx " << vert->grid_data_index ());
500 if (si >= 0)
501 UG_LOG (", subset " << u->domain()->subset_handler()->get_subset_name (si))
502 UG_LOG ('\n');
503 return true;
504 }
505 }
506
507 return false;
508}
509
518template <typename TGridFunction, typename TBaseElem>
520(
521 const TGridFunction * u,
522 const char * fct_names
523)
524{
525// Get the function index
526 std::vector<std::string> vfctNames;
527 TokenizeString (fct_names, vfctNames);
528 FunctionGroup fctGroup (u->function_pattern ());
529 for (size_t i = 0; i < vfctNames.size (); i++)
530 fctGroup.add (vfctNames [i]);
531
532// Check the functions
533 bool result = false;
534 for (size_t i = 0; i < vfctNames.size (); i++)
535 {
536 UG_LOG ("Checking " << vfctNames[i] << " ... ");
537 if (CheckGFforNaN<TGridFunction, TBaseElem> (u, fctGroup[i]))
538 result = true;
539 else
540 UG_LOG ("OK\n");
541 }
542 return result;
543}
544
553template <typename TGridFunction, typename TBaseElem>
555(
556 const TGridFunction * u,
557 const FunctionGroup & fctGroup
558)
559{
560// Check the functions
561 bool result = false;
562 for (size_t i = 0; i < fctGroup.size (); i++)
563 {
564 UG_LOG ("Checking fct #" << i << " ... ");
565 if (CheckGFforNaN<TGridFunction, TBaseElem> (u, fctGroup[i]))
566 result = true;
567 else
568 UG_LOG ("OK\n");
569 }
570 return result;
571}
572
573// //////////////////////////////////////////////////////////////////////////////
574// Check values are within bounds
575// //////////////////////////////////////////////////////////////////////////////
576template <typename TGridFunction, typename TBaseElem>
578(
580 size_t cmp,
581 number lowerBnd,
582 number upperBnd
583)
584{
585 typedef typename TGridFunction::template traits<TBaseElem>::const_iterator elem_it;
586
587 bool ret = true;
588
589 // loop the elements in the subset
590 std::vector<DoFIndex> vDI;
591 elem_it it = u->template begin<TBaseElem>();
592 elem_it itEnd = u->template end<TBaseElem>();
593 for (; it != itEnd; ++it)
594 {
595 TBaseElem* elem = *it;
596
597 // loop indices at this element
598 const size_t nInd = u->inner_dof_indices(elem, cmp, vDI, true);
599 for (size_t i = 0; i < nInd; ++i)
600 {
601 const number& val = DoFRef(*u, vDI[i]);
602 if (val < lowerBnd || val > upperBnd)
603 {
604 UG_LOG_ALL_PROCS("Function value for component " << cmp << " (" << val << ") "
605 "is outside the specified range [" << lowerBnd << ", " << upperBnd << "] "
606 "at " << ElementDebugInfo(*u->domain()->grid(), elem) << std::endl);
607 ret = false;
608 }
609 }
610 }
611
612#ifdef UG_PARALLEL
613 if (pcl::NumProcs() > 1)
614 {
616 int retInt = ret;
617 ret = pc.allreduce(retInt, PCL_RO_BAND);
618 }
619#endif
620
621 return ret;
622}
623
624template <typename TGridFunction>
626(
628 size_t cmp,
629 number lowerBnd,
630 number upperBnd
631)
632{
633 bool ret = true;
634 if (u->max_fct_dofs(cmp, 0))
635 ret = ret && CheckGFValuesWithinBounds<TGridFunction, Vertex>(u, cmp, lowerBnd, upperBnd);
636 if (u->max_fct_dofs(cmp, 1))
637 ret = ret && CheckGFValuesWithinBounds<TGridFunction, Edge>(u, cmp, lowerBnd, upperBnd);
638 if (u->max_fct_dofs(cmp, 2))
639 ret = ret && CheckGFValuesWithinBounds<TGridFunction, Face>(u, cmp, lowerBnd, upperBnd);
640 if (u->max_fct_dofs(cmp, 3))
641 ret = ret && CheckGFValuesWithinBounds<TGridFunction, Volume>(u, cmp, lowerBnd, upperBnd);
642
643 return ret;
644}
645
646template <typename TGridFunction>
648(
650 const char* fctNames,
651 number lowerBnd,
652 number upperBnd
653)
654{
655 std::vector<std::string> vFctNames;
656 TokenizeTrimString (fctNames, vFctNames);
657 FunctionGroup fctGroup (u->function_pattern());
658 const size_t nFct = vFctNames.size();
659 for (size_t f = 0; f < nFct; ++f)
660 {
661 try {fctGroup.add(vFctNames[f]);}
662 UG_CATCH_THROW("Could not add function " << vFctNames[f] << " to function group.");
663 }
664
665 bool ret = true;
666 const size_t fctGrpSz = fctGroup.size();
667 for (size_t f = 0; f < fctGrpSz; ++f)
668 ret = ret && CheckGFValuesWithinBounds(u, fctGroup[f], lowerBnd, upperBnd);
669
670 return ret;
671}
672
673
674
675
677// Writing algebra
679
680template<typename TDomain>
682{
683 PROFILE_FUNC_GROUP("debug");
684
685#ifdef UG_PARALLEL
686 name = ConnectionViewer::GetParallelName(name, dd->layouts()->proc_comm());
687#endif
688
689 std::vector<size_t> fctIndex;
690 std::vector<std::string> fctNames;
691
692 ExtractAlgebraIndices<TDomain>(domain, dd, fctIndex);
693
694 size_t numFct = dd->num_fct();
695 if(numFct <= 1) return;
696
697 fctNames.resize(numFct);
698 for(size_t i=0; i<numFct; i++)
699 fctNames[i] = dd->name(i);
700
701 name.append(".indices");
702 std::fstream file(name.c_str(), std::ios::out);
703
704 //std::cout << "name is " << name << "\n";
705 file << "NUMDOF " << fctNames.size() << "\n";
706 for(size_t i=0; i<numFct; i++)
707 file << fctNames[i] << "\n";
708
709 for(size_t i=0; i<fctIndex.size(); i++)
710 file << fctIndex[i] << "\n";
711}
712
713template<class TFunction>
714void WriteMatrixToConnectionViewer(const char *filename,
715 const typename TFunction::algebra_type::matrix_type &A,
716 const TFunction &u) {
717
718 PROFILE_FUNC_GROUP("debug");
719// check name
720 if ( !FileTypeIs( filename, ".mat") ) {
721 UG_THROW( "Only '.mat' format supported for matrices, but"
722 " filename is '" << filename << "'." );
723 }
724
725// position array
726 const static int dim = TFunction::domain_type::dim;
727 std::vector<MathVector<dim> > vPos;
728 ExtractPositions(u, vPos);
729
730// write matrix
731 if(vPos.empty())
732 ConnectionViewer::WriteMatrixPar( filename, A, (MathVector<dim>*)NULL, dim );
733 else
734 ConnectionViewer::WriteMatrixPar( filename, A, &vPos[0], dim );
735
736 WriteAlgebraIndices(filename, u.domain(),u.dof_distribution());
737
738}
739
740template<typename TGridFunction>
742 TGridFunction& u,
743 MatrixOperator<typename TGridFunction::algebra_type::matrix_type,
744 typename TGridFunction::vector_type>& A,
745 const char* filename) {
746 PROFILE_FUNC_GROUP("debug");
747// forward
748 WriteMatrixToConnectionViewer(filename, A.get_matrix(), u);
749}
750
760// TODO extend MatrixIO to support other than CPUAlgebra
761inline void SaveMatrixToMTX( const char *filename,
763 std::string comment="%Generated with ug4." ) {
764 PROFILE_FUNC_GROUP("debug");
765
766 // check name
767 if ( !FileTypeIs( filename, ".mtx" ) ) {
768 UG_THROW( "Please use '.mtx' as file extension for MatrixMarket exchange files."
769 " (Filename is '" << filename << "')" );
770 }
771
772 // automatically detect the file mode to use
774
775 // create MatrixIO object for handling the export
776 MatrixIOMtx mtx( filename, openMode );
777 mtx.write_from( A.get_matrix(), comment );
778}
779
780template<class TFunction>
781void WriteVectorToConnectionViewer(const char *filename,
782 const typename TFunction::algebra_type::vector_type &b,
783 const TFunction &u,
784 const typename TFunction::algebra_type::vector_type *pCompareVec = NULL) {
785 PROFILE_FUNC_GROUP("debug");
786// check name
787 if ( !FileTypeIs( filename, ".vec") ) {
788 UG_THROW( "Only '.vec' format supported for vectors, but"
789 " filename is '" << filename << "'." );
790 }
791
792// get positions of vertices
793 const static int dim = TFunction::domain_type::dim;
794 std::vector<MathVector<dim> > vPos;
795 ExtractPositions(u, vPos);
796
797// write vector
798 ConnectionViewer::WriteVectorPar( filename, b, &vPos[0], dim, pCompareVec);
799 WriteAlgebraIndices(filename, u.domain(),u.dof_distribution());
800}
801
802template<class TFunction>
804 const char *filename,
805 const typename TFunction::algebra_type::matrix_type &A,
806 const typename TFunction::algebra_type::vector_type &b,
807 const TFunction &u,
808 const typename TFunction::algebra_type::vector_type *pCompareVec = NULL) {
809 PROFILE_FUNC_GROUP("debug");
810// get dimension
811 const static int dim = TFunction::domain_type::dim;
812
813// check name
814 if ( !FileTypeIs( filename, ".vec") ) {
815 UG_THROW( "Only '.vec' format supported for vectors." );
816 }
817
818// get positions of vertices
819 std::vector<MathVector<dim> > positions;
820 ExtractPositions(u, positions);
821
822// write vector
823 ConnectionViewer::WriteVectorPar( filename, A, b, &positions[0], dim, pCompareVec );
824}
825
826template<typename TGridFunction>
827void SaveVectorForConnectionViewer(TGridFunction& b, const char* filename) {
828 WriteVectorToConnectionViewer(filename, b, b);
829}
830
831template<typename TGridFunction>
832void SaveVectorDiffForConnectionViewer(TGridFunction& b, TGridFunction& bCompare, const char* filename) {
833 WriteVectorToConnectionViewer(filename, b, b, &bCompare);
834}
835
836template<typename TGridFunction>
838 TGridFunction& u,
839 MatrixOperator<typename TGridFunction::algebra_type::matrix_type,
840 typename TGridFunction::vector_type>& A,
841 const char* filename) {
842 WriteVectorToConnectionViewer(filename, A.get_matrix(), u, u);
843}
844
845template<typename TGridFunction>
847 TGridFunction& u,
848 TGridFunction& compareVec,
849 MatrixOperator<typename TGridFunction::algebra_type::matrix_type,
850 typename TGridFunction::vector_type>& A,
851 const char* filename) {
852// forward
853 WriteVectorToConnectionViewer(filename, A.get_matrix(), u, u, &compareVec);
854}
855
856// from connection_viewer_input.h
857// with additional checks
858template<typename vector_type>
859bool ReadVector(std::string filename, vector_type &vec,int dim)
860{
861 Progress p;
862 std::cout << " Reading std::vector from " << filename << "... ";
863 std::fstream matfile(filename.c_str(), std::ios::in);
864 if(matfile.is_open() == false) { std::cout << "failed.\n"; return false; }
865
866 int version=-1, dimension=-1, gridsize;
867
868 matfile >> version;
869 matfile >> dimension;
870 matfile >> gridsize;
871
872 assert(version == 1);
873 assert(dimension == dim);
874 // todo check positions and not just size
875 assert(gridsize == (int)vec.size());
876
877
878 PROGRESS_START(prog, gridsize*2, "ReadVector " << dimension << "d from " << filename << " , " << gridsize << " x " << gridsize);
879 for(int i=0; i<gridsize; i++)
880 {
881 if(i%100) { PROGRESS_UPDATE(prog, i); }
882 if(matfile.eof())
883 {
884 std::cout << " failed.\n";
885 assert(0);
886 return false;
887 }
888 double x, y, z;
889 matfile >> x >> y;
890 if(dimension==3) matfile >> z;
891 }
892
893 int printStringsInWindow;
894 matfile >> printStringsInWindow;
895
896 // vec.resize(gridsize);
897 bool bEOF = matfile.eof();
898 while(!bEOF)
899 {
900 int from, to; double value;
901 char c = matfile.peek();
902 if(c == -1 || c == 'c' || c == 'v' || matfile.eof())
903 break;
904
905 matfile >> from >> to >> value;
906 assert(from == to);
907 vec[from] = value;
908 if(from%100) { PROGRESS_UPDATE(prog, from); }
909 bEOF = matfile.eof();
910 }
911 return true;
912}
913
914// load vector that has been saved in connection viewer format and write it
915// into grid function
916template<typename TGridFunction>
917void LoadVector(TGridFunction& u,const char* filename){
918 PROFILE_FUNC();
919 typename TGridFunction::algebra_type::vector_type b;
920 b.resize(u.num_indices());
921 ReadVector(filename,b,TGridFunction::dim);
922 u.assign(b);
923}
924
925// Same as before, but for comma separated value (CSV)
926template<class TFunction>
927void WriteVectorCSV(const char *filename,
928 const typename TFunction::algebra_type::vector_type &b,
929 const TFunction &u) {
930 PROFILE_FUNC_GROUP("debug");
931// get dimension
932 const static int dim = TFunction::domain_type::dim;
933
934// check name
935 if ( !FileTypeIs( filename, ".csv") ) {
936 UG_THROW( "Only '.csv' format supported for vectors, but"
937 " filename is '" << filename << "'." );
938 }
939
940// extended filename
941// add p000X extension in parallel
942#ifdef UG_PARALLEL
943 std::string name(filename);
944 size_t iExtPos = name.find_last_of(".");
945 name.resize(iExtPos);
946 int rank = pcl::ProcRank();
947 char ext[20]; snprintf(ext, 20, "_p%05d.csv", rank);
948 name.append(ext);
949#endif
950
951// get positions of vertices
952 std::vector<MathVector<dim> > positions;
953 ExtractPositions(u, positions);
954
955// write vector
956 WriteVectorCSV( filename, b, &positions[0], dim );
957}
958
959template<typename TGridFunction>
960void SaveVectorCSV(TGridFunction& b, const char* filename) {
961 PROFILE_FUNC();
962 WriteVectorCSV(filename, b, b);
963}
964
978template<typename TDomain, typename TAlgebra>
981 std::string subset, std::string fct1, std::string fct2 )
982{
983 PROFILE_FUNC();
984 // get subset index
985 size_t subSetID = spGridFct->subset_id_by_name( subset.c_str() );
986
987 // get function indices
988 size_t fct1ID = spGridFct->fct_id_by_name( fct1.c_str() );
989 size_t fct2ID = spGridFct->fct_id_by_name( fct2.c_str() );
990
991 // create space for sum of difference
992 number sum = 0.0;
993 size_t numElements = 0;
994
995 // loop over all vertices in given subset and compare values of fct1 and fct2
996 typedef typename GridFunction<TDomain, TAlgebra>::template traits<Vertex>::const_iterator gridFctIterator;
997 for( gridFctIterator iter = spGridFct->template begin<Vertex>((int)subSetID);
998 iter != spGridFct->template end<Vertex>((int)subSetID); ++iter ) {
999 // get dof_indices for the two functions on given subset
1000 std::vector< DoFIndex > indFct1, indFct2;
1001 spGridFct->template dof_indices<Vertex>( *iter, fct1ID, indFct1 );
1002 spGridFct->template dof_indices<Vertex>( *iter, fct2ID, indFct2 );
1003
1004 // calculate the difference between the two functions at this grid point
1005 sum += DoFRef( *spGridFct, indFct1[0] ) - DoFRef( *spGridFct, indFct2[0] );
1006 numElements++;
1007 }
1008
1009 // return overal arithmetic average of differences
1010 return sum / numElements;
1011}
1012
1013
1015// Grid Function Debug Writer
1017
1018template<typename TDomain, typename TAlgebra>
1020{
1022 static const int dim = TDomain::dim;
1023
1024public:
1026 typedef TAlgebra algebra_type;
1027
1029 typedef typename algebra_type::vector_type vector_type;
1030
1032 typedef typename algebra_type::matrix_type matrix_type;
1033
1036
1038 using super::get_base_dir;
1039
1040public:
1050
1052
1054 void set_grid_level(const GridLevel& gridLevel) {
1055 m_glFrom = gridLevel; m_glTo = gridLevel;
1056 }
1057
1059 void set_grid_levels(const GridLevel& glFrom, const GridLevel& glTo) {
1060 m_glFrom = glFrom; m_glTo = glTo;
1061 }
1062
1065
1070
1071
1073 void set_vtk_output(bool b) {bVTKOut = b;}
1074
1077
1080
1083
1085 virtual void write_vector(const vector_type& vec, const char* filename) {
1086 // write to conn viewer
1087 if (bConnViewerOut)
1088 write_vector_to_conn_viewer(vec, filename);
1089
1090 // write to vtk
1091 if (bVTKOut)
1092 write_vector_to_vtk(vec, filename);
1093 }
1094
1095 virtual void update_positions()
1096 {
1098 }
1099
1101 virtual void write_matrix(const matrix_type& mat, const char* filename) {
1102 PROFILE_FUNC_GROUP("debug");
1103 // something to do ?
1104 if (!bConnViewerOut)
1105 return;
1106
1108
1109 std::string name;
1110 this->compose_file_path (name);
1111 name += filename;
1112
1113 if ( !FileTypeIs( filename, ".mat" ) ) {
1114 UG_THROW( "Only '.mat' format supported for matrices, but"
1115 " filename is '" << filename << "'." );
1116 }
1117
1118 // write to file
1120 if(m_glFrom == m_glTo){
1121 if(mat.num_rows() != mat.num_cols())
1122 UG_THROW("DebugWriter: grid level the same, but non-square matrix.");
1123
1124 const std::vector<MathVector<dim> >& vPos = this->template get_positions<dim>();
1125 if(vPos.empty())
1127 else
1128 ConnectionViewer::WriteMatrixPar(name.c_str(), mat, &vPos[0], dim);
1129 }
1130 else{
1131 const std::vector<MathVector<dim> >& vFromPos = this->template get_positions<dim>();
1132
1133 std::vector<MathVector<dim> > vToPos;
1134 ExtractPositions<TDomain>(m_spApproxSpace->domain(),
1135 m_spApproxSpace->dof_distribution(m_glTo),
1136 vToPos);
1137
1138 if(mat.num_cols() == vFromPos.size() && mat.num_rows() == vToPos.size())
1139 {
1140 ConnectionViewer::WriteMatrixPar(name, mat, vFromPos, vToPos, dim);
1141 }
1142 else{
1143 UG_THROW("GridFunctionDebugWriter: Wrong size of matrix for writing"
1144 "matrix ("<<m_glTo<<" x "<<m_glFrom<<"), that would be a ("
1145 <<vToPos.size()<<" x "<<vFromPos.size()<<") matrix. But "
1146 "passed matrix of size ("<<mat.num_rows()<<" x "
1147 <<mat.num_cols()<<").");
1148 }
1149 }
1150 }
1151
1152protected:
1153
1155 {
1157 WriteAlgebraIndices<TDomain>(name, m_spApproxSpace->domain(), m_spApproxSpace->dof_distribution(m_glFrom));
1158 }
1159
1161 void extract_positions(const GridLevel& gridLevel) {
1162 // extract positions for this grid function
1163 std::vector<MathVector<dim> >& vPos =
1164 this->template positions<dim>();
1165
1166 vPos.clear();
1167 ExtractPositions<TDomain>(
1168 m_spApproxSpace->domain(),
1169 m_spApproxSpace->dof_distribution(gridLevel),
1170 vPos);
1171 }
1172
1175 const char* filename)
1176 {
1177 PROFILE_FUNC_GROUP("debug");
1179
1180 std::string name;
1181 this->compose_file_path (name);
1182 name += filename;
1183
1184 if ( !FileTypeIs( filename, ".vec" ) ) {
1185 UG_THROW( "Only '.vec' format supported for vectors, but"
1186 " filename is '" << name << "'.");
1187 }
1188
1189 // write
1190 write_algebra_indices_CV(filename);
1191 const std::vector<MathVector<dim> >& vPos =
1192 this->template get_positions<dim>();
1193 if(vPos.empty())
1195 else
1196 ConnectionViewer::WriteVectorPar(name.c_str(), vec, &vPos[0], dim);
1197 }
1198
1199 void write_vector_to_vtk(const vector_type& vec, const char* filename) {
1200 PROFILE_FUNC_GROUP("debug");
1201 // check name
1202
1203 std::string name;
1204 this->compose_file_path (name);
1205 name += filename;
1206
1207 typedef GridFunction<TDomain, TAlgebra> TGridFunction;
1208 TGridFunction vtkFunc(
1210 m_spApproxSpace->dof_distribution(m_glFrom));
1211 vtkFunc.resize_values(vec.size());
1212 vtkFunc.assign(vec);
1213 VTKOutput<dim> out;
1214 out.print(name.c_str(), vtkFunc, m_printConsistent);
1215 }
1216
1217protected:
1218 // underlying approximation space
1220
1221 // flag if write to conn viewer
1224
1225 // flag if write to vtk
1227
1228 // flag if data shall be made consistent before printing
1230
1231 // current grid level
1233};
1234
1236// Grid Function Position Provider
1238
1239template<typename TGridFunction>
1241 TGridFunction::domain_type::dim> {
1242public:
1245 m_pGridFunc(NULL) {
1246 }
1247 GridFunctionPositionProvider(const TGridFunction& u) :
1248 m_pGridFunc(&u) {
1249 }
1250 void set_reference_grid_function(const TGridFunction& u) {
1251 m_pGridFunc = &u;
1252 }
1253
1254 virtual bool get_positions(
1256 UG_ASSERT(m_pGridFunc != NULL,
1257 "provide a grid function with set_reference_grid_function");
1258 ExtractPositions(*m_pGridFunc, vec);
1259 return true;
1260 }
1261
1262protected:
1263 const TGridFunction *m_pGridFunc;
1264};
1265
1267// Grid Function Vector Writer
1269
1270template<typename TGridFunction, typename TVector>
1272public:
1273 typedef typename TVector::value_type value_type;
1274 typedef typename TGridFunction::domain_type domain_type;
1275 typedef TVector vector_type;
1276
1277public:
1280 m_pGridFunc(NULL) {
1281 }
1282
1284 m_userData = userData;
1285 }
1286
1287 void set_reference_grid_function(const TGridFunction& u) {
1288 m_pGridFunc = &u;
1289 }
1290
1291 /*virtual double calculate(MathVector<3> &v, double time)
1292 {
1293 }*/
1294
1295 virtual bool update(vector_type &vec) {
1296 PROFILE_FUNC_GROUP("debug");
1297 UG_ASSERT(m_pGridFunc != NULL,
1298 "provide a grid function with set_reference_grid_function");
1299 UG_ASSERT(m_userData.valid(), "provide user data with set_user_data");
1300
1301 const TGridFunction &u = *m_pGridFunc;
1302
1303 // get position accessor
1304
1305 const typename domain_type::position_accessor_type& aaPos =
1306 u.domain()->position_accessor();
1307
1308 // number of total dofs
1309 int nr = u.num_indices();
1310
1311 // resize positions
1312 vec.resize(nr);
1313
1314 typedef typename TGridFunction::template traits<Vertex>::const_iterator const_iterator;
1315
1316 // loop all subsets
1317 for (int si = 0; si < u.num_subsets(); ++si) {
1318 // loop all vertices
1319 const_iterator iter = u.template begin<Vertex>(si);
1320 const_iterator iterEnd = u.template end<Vertex>(si);
1321
1322 for (; iter != iterEnd; ++iter) {
1323 // get vertex
1324 Vertex* v = *iter;
1325
1326 // algebra indices vector
1327 std::vector<size_t> ind;
1328
1329 // load indices associated with vertex
1330 u.inner_algebra_indices(v, ind);
1331
1332 number t = 0.0;
1333
1334 number d;
1335 (*m_userData)(d, aaPos[v], t, si);
1336
1337 // write
1338 for (size_t i = 0; i < ind.size(); ++i) {
1339 const size_t index = ind[i];
1340 for (size_t alpha = 0; alpha < GetSize(vec[index]); ++alpha)
1341 BlockRef(vec[index], alpha) = d;
1342 }
1343 }
1344 }
1345 return true;
1346 }
1347
1348protected:
1349 const TGridFunction *m_pGridFunc;
1351};
1352
1354// Grid Function Vector Writer Dirichlet 0
1356
1357template<typename TGridFunction>
1359 typename TGridFunction::algebra_type::vector_type> {
1360public:
1361 typedef typename TGridFunction::domain_type domain_type;
1362
1363 typedef typename TGridFunction::approximation_space_type approximation_space_type;
1364
1365 typedef typename TGridFunction::algebra_type algebra_type;
1366 typedef typename algebra_type::vector_type vector_type;
1367 typedef typename vector_type::value_type value_type;
1368
1369public:
1374
1375 void set_level(size_t level) {
1376 m_level = level;
1377 }
1378
1380 approximation_space_type& approxSpace) {
1381 m_spPostProcess = pp;
1382 m_pApproxSpace = &approxSpace;
1383 }
1384
1385 /*virtual double calculate(MathVector<3> &v, double time)
1386 {
1387 }*/
1388
1389 virtual bool update(vector_type &vec) {
1390 PROFILE_FUNC_GROUP("debug");
1391 UG_ASSERT(m_spPostProcess.valid(), "provide a post process with init");
1392 UG_ASSERT(m_pApproxSpace != NULL, "provide approximation space init");
1393
1394 size_t numDoFs = 0;
1395 GridLevel gl;
1396 if (m_level == (size_t) -1) {
1397 numDoFs = m_pApproxSpace->dof_distribution(GridLevel(GridLevel::TOP, GridLevel::SURFACE))->num_indices();
1398 gl = GridLevel();
1399 } else {
1400 numDoFs =
1401 m_pApproxSpace->dof_distribution(GridLevel(m_level, GridLevel::LEVEL, true))->num_indices();
1403 }
1404 vec.resize(numDoFs);
1405 vec.set(1.0);
1406
1407 m_spPostProcess->adjust_defect(vec, vec, m_pApproxSpace->dof_distribution(gl), CT_DIRICHLET);
1408
1409 return true;
1410 }
1411
1412protected:
1415 size_t m_level;
1416};
1417
1418} // end namespace ug
1419
1420#endif /* __H__UG__LIB_DISC__FUNCTION_SPACE__GRID_FUNCTION_UTIL__ */
parameterString p
location name
Definition checkpoint_util.lua:128
Definition smart_pointer.h:296
Definition smart_pointer.h:107
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition smart_pointer.h:212
Definition pcl_process_communicator.h:70
void allreduce(const void *sendBuf, void *recBuf, int count, DataType type, ReduceOperation op) const
performs MPI_Allreduce on the processes of the communicator.
Definition pcl_process_communicator.cpp:318
base class for approximation spaces without type of algebra or dof distribution
Definition approximation_space.h:279
Definition function_group.h:52
void add(size_t fct)
adds a function by id to this group
Definition function_group.cpp:79
size_t size() const
number of functions in this group
Definition function_group.h:116
Definition grid_function_util.h:1020
bool bConnViewerOut
Definition grid_function_util.h:1222
ApproximationSpace< TDomain > approximation_space_type
type of approximation space
Definition grid_function_util.h:1035
GridFunctionDebugWriter(SmartPtr< ApproximationSpace< TDomain > > spApproxSpace)
Constructor.
Definition grid_function_util.h:1042
static const int dim
dimension
Definition grid_function_util.h:1022
algebra_type::vector_type vector_type
type of vector
Definition grid_function_util.h:1029
void set_print_consistent(bool b)
sets if data shall be made consistent before printing
Definition grid_function_util.h:1082
virtual void write_matrix(const matrix_type &mat, const char *filename)
write matrix
Definition grid_function_util.h:1101
GridLevel m_glTo
Definition grid_function_util.h:1232
bool bConnViewerIndices
Definition grid_function_util.h:1223
void set_grid_levels(const GridLevel &glFrom, const GridLevel &glTo)
sets the grid level
Definition grid_function_util.h:1059
void set_grid_level(const GridLevel &gridLevel)
sets the grid level
Definition grid_function_util.h:1054
virtual void write_vector(const vector_type &vec, const char *filename)
write vector
Definition grid_function_util.h:1085
GridLevel grid_level() const
returns current grid level
Definition grid_function_util.h:1064
void set_vtk_output(bool b)
sets if writing to vtk
Definition grid_function_util.h:1073
SmartPtr< approximation_space_type > m_spApproxSpace
Definition grid_function_util.h:1219
bool bVTKOut
Definition grid_function_util.h:1226
IDebugWriter< TAlgebra > super
Definition grid_function_util.h:1037
GridLevel m_glFrom
Definition grid_function_util.h:1232
void set_conn_viewer_indices(bool b)
sets if .indices file is written or conn viewer
Definition grid_function_util.h:1079
bool m_printConsistent
Definition grid_function_util.h:1229
virtual ~GridFunctionDebugWriter()
Definition grid_function_util.h:1051
void write_algebra_indices_CV(std::string name)
Definition grid_function_util.h:1154
virtual void write_vector_to_conn_viewer(const vector_type &vec, const char *filename)
write vector
Definition grid_function_util.h:1174
void reset()
sets to toplevel on surface
Definition grid_function_util.h:1067
TAlgebra algebra_type
type of matrix
Definition grid_function_util.h:1026
void set_conn_viewer_output(bool b)
sets if writing to conn viewer
Definition grid_function_util.h:1076
algebra_type::matrix_type matrix_type
type of matrix
Definition grid_function_util.h:1032
virtual void update_positions()
Definition grid_function_util.h:1095
void extract_positions(const GridLevel &gridLevel)
reads the positions
Definition grid_function_util.h:1161
void write_vector_to_vtk(const vector_type &vec, const char *filename)
Definition grid_function_util.h:1199
represents numerical solutions on a grid using an algebraic vector
Definition grid_function.h:121
Definition grid_function_util.h:1241
GridFunctionPositionProvider()
Constructor.
Definition grid_function_util.h:1244
GridFunctionPositionProvider(const TGridFunction &u)
Definition grid_function_util.h:1247
void set_reference_grid_function(const TGridFunction &u)
Definition grid_function_util.h:1250
virtual bool get_positions(std::vector< MathVector< TGridFunction::domain_type::dim > > &vec)
Definition grid_function_util.h:1254
const TGridFunction * m_pGridFunc
Definition grid_function_util.h:1263
Definition grid_function_util.h:1359
TGridFunction::domain_type domain_type
Definition grid_function_util.h:1361
algebra_type::vector_type vector_type
Definition grid_function_util.h:1366
GridFunctionVectorWriterDirichlet0()
Constructor.
Definition grid_function_util.h:1371
vector_type::value_type value_type
Definition grid_function_util.h:1367
virtual bool update(vector_type &vec)
Definition grid_function_util.h:1389
void set_level(size_t level)
Definition grid_function_util.h:1375
TGridFunction::approximation_space_type approximation_space_type
Definition grid_function_util.h:1363
size_t m_level
Definition grid_function_util.h:1415
SmartPtr< IConstraint< algebra_type > > m_spPostProcess
Definition grid_function_util.h:1414
TGridFunction::algebra_type algebra_type
Definition grid_function_util.h:1365
approximation_space_type * m_pApproxSpace
Definition grid_function_util.h:1413
void init(SmartPtr< IConstraint< algebra_type > > pp, approximation_space_type &approxSpace)
Definition grid_function_util.h:1379
Definition grid_function_util.h:1271
void set_user_data(SmartPtr< UserData< number, domain_type::dim > > userData)
Definition grid_function_util.h:1283
virtual bool update(vector_type &vec)
write vector
Definition grid_function_util.h:1295
GridFunctionVectorWriter()
Constructor.
Definition grid_function_util.h:1279
void set_reference_grid_function(const TGridFunction &u)
Definition grid_function_util.h:1287
TVector vector_type
Definition grid_function_util.h:1275
const TGridFunction * m_pGridFunc
Definition grid_function_util.h:1349
TGridFunction::domain_type domain_type
Definition grid_function_util.h:1274
SmartPtr< UserData< number, domain_type::dim > > m_userData
Definition grid_function_util.h:1350
TVector::value_type value_type
Definition grid_function_util.h:1273
Definition grid_level.h:42
@ TOP
Definition grid_level.h:45
@ SURFACE
Definition grid_level.h:48
@ LEVEL
Definition grid_level.h:48
interface for adjustment of constraints
Definition constraint_interface.h:63
base class for all debug writer
Definition debug_writer.h:244
Interface for providing vertex positions.
Definition debug_writer.h:46
base class for all vector debug writer
Definition debug_writer.h:118
std::string get_base_dir()
Definition debug_writer.h:192
void compose_file_path(std::string &path)
composes the path for the files and creates the intermediate directories (up to the base one):
Definition debug_writer.h:210
Interface for modifying a vector (e.g, setting Dirichlet values, ...)
Definition vector_writer.h:42
a mathematical Vector with N entries.
Definition math_vector.h:97
OpenMode
Specifies how file names pointing to non-existing files should be handeld.
Definition matrix_io.h:129
@ EXISTING
Only existing files are valid files (i.e. non-existing file result in error)
Definition matrix_io.h:131
@ NEW
Non-existing files are created with the specified file name.
Definition matrix_io.h:133
Provides I/O functionality for MatrixMarket exchange file format.
Definition matrix_io_mtx.h:84
void write_from(matrix_type &matrix, std::string comment="%Generated with ug4.")
Writes a ug matrix into the associated MatrixMarket exchange file.
Definition matrix_io_mtx.h:287
Definition matrix_operator.h:49
virtual M & get_matrix()
Definition matrix_operator.h:74
Definition periodic_boundary_manager.h:99
bool is_slave(TElem *) const
Definition periodic_boundary_manager_impl.hpp:498
Definition progress.h:50
Group of subsets.
Definition subset_group.h:51
size_t size() const
number of subsets in this group
Definition subset_group.h:122
void add(int si)
adds a subset by number to this group
Definition subset_group.cpp:64
@ ALL
Definition surface_view.h:102
Type based UserData.
Definition user_data.h:144
output writer to the VTK file format
Definition vtkoutput.h:150
void print(const char *filename, TFunction &u, int step, number time, bool makeConsistent)
Definition vtkoutput_impl.h:184
Base-class for all vertex-types.
Definition grid_base_objects.h:231
File utility functions.
std::string ElementDebugInfo(const Grid &grid, GridObject *e)
Returns a string containing information on the given element.
Definition debug_util.cpp:991
#define PCL_RO_SUM
Definition pcl_methods.h:63
int ProcRank()
returns the rank of the process
Definition pcl_base.cpp:83
int NumProcs()
returns the number of processes
Definition pcl_base.cpp:91
#define PCL_RO_BAND
Definition pcl_methods.h:66
UG_API bool FileExists(const char *filename)
!!! Serial i/o version !!!
Definition file_util.cpp:53
bool FileTypeIs(const char *filename, const char *extension)
!!! Serial i/o version !!!
Definition file_util.cpp:86
#define UG_LOG_ALL_PROCS(msg)
Definition log.h:371
#define UG_ASSERT(expr, msg)
Definition assert.h:70
#define UG_CATCH_THROW(msg)
Definition error.h:64
#define UG_THROW(msg)
Definition error.h:57
#define UG_LOG(msg)
Definition log.h:367
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition error.h:61
double number
Definition types.h:124
void WriteVectorPar(std::string filename, const Vector_type &b, const postype *positions, int dimensions, const Vector_type *compareVec=NULL)
Definition connection_viewer_output.h:425
void WriteMatrixPar(std::string name, const Matrix_type &A, const postype *positions, int dimensions)
Definition connection_viewer_output.h:153
string GetParallelName(string name, const pcl::ProcessCommunicator &pc, bool bWriteHeader)
Definition connection_viewer_output.cpp:51
the ug namespace
bool CheckGFforNaN(const TGridFunction *u, size_t fct)
Definition grid_function_util.h:464
bool ReadVector(std::string filename, vector_type &vec, int dim)
Definition grid_function_util.h:859
@ CT_DIRICHLET
Definition ass_tuner.h:59
number SumGFValuesAt(TGridFunction *u, size_t fct)
Definition grid_function_util.h:306
void SaveMatrixForConnectionViewer(TGridFunction &u, MatrixOperator< typename TGridFunction::algebra_type::matrix_type, typename TGridFunction::vector_type > &A, const char *filename)
Definition grid_function_util.h:741
void ScaleGF(SmartPtr< TGridFunction > scaledVecOut, ConstSmartPtr< TGridFunction > vecIn, const std::vector< number > &scalingFactors)
Scales all functions contained in a grid function.
Definition grid_function_util.h:122
void SaveVectorForConnectionViewer(TGridFunction &b, const char *filename)
Definition grid_function_util.h:827
void ExtractPositions(ConstSmartPtr< TDomain > domain, ConstSmartPtr< DoFDistribution > dd, std::vector< MathVector< TDomain::dim > > &vPos)
Definition dof_position_util.cpp:424
void TokenizeTrimString(const string &str, vector< string > &vToken, const char delimiter)
Definition string_util.cpp:83
void SaveMatrixToMTX(const char *filename, MatrixOperator< CPUAlgebra::matrix_type, CPUAlgebra::vector_type > &A, std::string comment="%Generated with ug4.")
Save the assembled matrix of a matrix operator to MatrixMarket format.
Definition grid_function_util.h:761
void WriteVectorCSV(const char *filename, const Vector_type &b, postype *positions, int dimensions)
writes to a file in somewhat SparseMatrix-market format (for connection viewer)
Definition csv_gnuplot_output.h:59
void TokenizeString(const string &str, vector< string > &vToken, const char delimiter)
Definition string_util.cpp:56
void WriteAlgebraIndices(std::string name, ConstSmartPtr< TDomain > domain, ConstSmartPtr< DoFDistribution > dd)
Definition grid_function_util.h:681
void SaveVectorDiffForConnectionViewer(TGridFunction &b, TGridFunction &bCompare, const char *filename)
Definition grid_function_util.h:832
void LoadVector(TGridFunction &u, const char *filename)
Definition grid_function_util.h:917
void SubtractValueFromComponent(SmartPtr< TGridFunction > spGF, size_t fct, number sub)
Definition grid_function_util.h:170
void WriteVectorToConnectionViewer(const char *filename, const typename TFunction::algebra_type::vector_type &b, const TFunction &u, const typename TFunction::algebra_type::vector_type *pCompareVec=NULL)
Definition grid_function_util.h:781
double & BlockRef(T &vec, size_t i)
Definition blocks.h:66
number AverageFunctionDifference(SmartPtr< GridFunction< TDomain, TAlgebra > > spGridFct, std::string subset, std::string fct1, std::string fct2)
Calculates the average of the pointwise difference of two functions on given subset.
Definition grid_function_util.h:979
void AdjustMeanValue(SmartPtr< TGridFunction > spGF, const std::vector< std::string > &vCmp, number mean)
Definition grid_function_util.h:213
@ VOLUME
Definition grid_base_objects.h:63
@ VERTEX
Definition grid_base_objects.h:60
@ EDGE
Definition grid_base_objects.h:61
@ FACE
Definition grid_base_objects.h:62
void WriteMatrixToConnectionViewer(const char *filename, const typename TFunction::algebra_type::matrix_type &A, const TFunction &u)
Definition grid_function_util.h:714
void SaveVectorCSV(TGridFunction &b, const char *filename)
Definition grid_function_util.h:960
static void ScaleGFOnElems(ConstSmartPtr< DoFDistribution > dd, SmartPtr< TGridFunction > vecOut, ConstSmartPtr< TGridFunction > vecIn, const std::vector< number > &vScale)
Definition grid_function_util.h:80
bool CheckGFValuesWithinBounds(ConstSmartPtr< TGridFunction > u, size_t cmp, number lowerBnd, number upperBnd)
Definition grid_function_util.h:578
size_t GetSize(const T &t)
number Integral(SmartPtr< UserData< number, TGridFunction::dim > > spData, TGridFunction &spGridFct, const char *subsets, number time, int quadOrder, std::string quadType)
Definition integrate.h:855
number & DoFRef(TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
Definition multi_index.h:276
#define PROFILE_FUNC_GROUP(groups)
Definition profiler.h:258
#define PROFILE_FUNC()
Definition profiler.h:257
#define PROGRESS_START(progVarName, dSize, msg)
Definition progress.h:111
#define PROGRESS_UPDATE(progVarName, d)
Definition progress.h:117
SurfaceView::traits< TElem >::const_iterator const_iterator
Definition dof_distribution.h:82