OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
FDScheme.hpp
1/*
2 * FiniteDifferences.hpp
3 *
4 * Created on: Sep 17, 2015
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_FDSCHEME_HPP_
9#define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_FDSCHEME_HPP_
10
11#include "Matrix/SparseMatrix.hpp"
12#include "Vector/Vector.hpp"
13#include "Grid/grid_dist_id.hpp"
14#include "Grid/Iterators/grid_dist_id_iterator_sub.hpp"
15#include "eq.hpp"
16#include "NN/CellList/CellDecomposer.hpp"
17#include "Grid/staggered_dist_grid_util.hpp"
18#include "Grid/grid_dist_id.hpp"
19#include "Vector/Vector_util.hpp"
20#include "Grid/staggered_dist_grid.hpp"
21
22
125template<typename Sys_eqs>
127{
128public:
129
131 typedef grid_dist_id<Sys_eqs::dims,typename Sys_eqs::stype,aggregate<size_t>,typename Sys_eqs::b_grid::decomposition::extended_type> g_map_type;
132
134 typedef Sys_eqs Sys_eqs_typ;
135
138 {
140 typename Sys_eqs::stype scal;
141
147 constant_b(typename Sys_eqs::stype scal)
148 {
149 this->scal = scal;
150 }
151
161 typename Sys_eqs::stype get(grid_dist_key_dx<Sys_eqs::dims> & key)
162 {
163 return scal;
164 }
165 };
166
168 template<typename grid, unsigned int prp>
169 struct grid_b
170 {
173
180 :gr(gr)
181 {}
182
190 auto get(grid_dist_key_dx<Sys_eqs::dims> & key) -> decltype(gr.template get<prp>(key))
191 {
192 return gr.template get<prp>(key);
193 }
194 };
195
196private:
197
200
202 typedef typename Sys_eqs::SparseMatrix_type::triplet_type triplet;
203
205 typename Sys_eqs::Vector_type b;
206
209
211 typename Sys_eqs::stype spacing[Sys_eqs::dims];
212
215
217 size_t row;
218
220 size_t row_b;
221
224
227
232 size_t s_pnt;
233
238 {
241
243 size_t eq;
244 };
245
254 {
255 key_and_eq ke;
256 auto it = g_map.getDomainIterator();
257
258 while (it.isNext())
259 {
260 size_t row_low = g_map.template get<0>(it.get());
261
262 if (row >= row_low * Sys_eqs::nvar && row < row_low * Sys_eqs::nvar + Sys_eqs::nvar)
263 {
264 ke.eq = row - row_low * Sys_eqs::nvar;
265 ke.key = g_map.getGKey(it.get());
266 return ke;
267 }
268
269 ++it;
270 }
271 std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " the row does not map to any position" << "\n";
272
273 return ke;
274 }
275
284 inline const std::vector<size_t> padding( const size_t (& sz)[Sys_eqs::dims], Padding<Sys_eqs::dims> & pd)
285 {
286 std::vector<size_t> g_sz_pad(Sys_eqs::dims);
287
288 for (size_t i = 0 ; i < Sys_eqs::dims ; i++)
289 g_sz_pad[i] = sz[i] + pd.getLow(i) + pd.getHigh(i);
290
291 return g_sz_pad;
292 }
293
298 {
299 openfpm::vector<triplet> & trpl = A.getMatrixTriplets();
300
301 // A and B must have the same rows
302 if (row != row_b)
303 std::cerr << "Error " << __FILE__ << ":" << __LINE__ << "the term B and the Matrix A for Ax=B must contain the same number of rows\n";
304
305 // Indicate all the non zero rows
307 nz_rows.resize(row_b);
308
309 for (size_t i = 0 ; i < trpl.size() ; i++)
310 nz_rows.get(trpl.get(i).row() - s_pnt*Sys_eqs::nvar) = true;
311
312 // Indicate all the non zero colums
313 // This check can be done only on single processor
314
315 Vcluster<> & v_cl = create_vcluster();
316 if (v_cl.getProcessingUnits() == 1)
317 {
319 nz_cols.resize(row_b);
320
321 for (size_t i = 0 ; i < trpl.size() ; i++)
322 nz_cols.get(trpl.get(i).col()) = true;
323
324 // all the rows must have a non zero element
325 for (size_t i = 0 ; i < nz_rows.size() ; i++)
326 {
327 if (nz_rows.get(i) == false)
328 {
330 std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " Ill posed matrix row " << i << " is not filled, position " << ke.key.to_string() << " equation: " << ke.eq << "\n";
331 }
332 }
333
334 // all the colums must have a non zero element
335 for (size_t i = 0 ; i < nz_cols.size() ; i++)
336 {
337 if (nz_cols.get(i) == false)
338 std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " Ill posed matrix colum " << i << " is not filled\n";
339 }
340 }
341 }
342
353 template<typename Vct, typename Grid_dst ,unsigned int ... pos> void copy_staggered(Vct & v, Grid_dst & g_dst, grid_key_dx<Grid_dst::dims> & start_d, grid_key_dx<Grid_dst::dims> & stop_d)
354 {
355 // check that g_dst is staggered
356 if (g_dst.is_staggered() == false)
357 std::cerr << __FILE__ << ":" << __LINE__ << " The destination grid must be staggered " << std::endl;
358
359 // sub-grid iterator over the grid map
360 auto g_map_it = g_map.getSubDomainIterator(start_d,stop_d);
361
362 // Iterator over the destination grid
363 auto g_dst_it = g_dst.getSubDomainIterator(start_d,stop_d);
364
365 while (g_map_it.isNext() == true)
366 {
367 typedef typename to_boost_vmpl<pos...>::type vid;
368 typedef boost::mpl::size<vid> v_size;
369
370 auto key_src = g_map_it.get();
371 size_t lin_id = g_map.template get<0>(key_src);
372
373 // destination point
374 auto key_dst = g_dst_it.get();
375
376 // Transform this id into an id for the Eigen vector
377
378 copy_ele<Sys_eqs_typ, Grid_dst,Vct> cp(key_dst,g_dst,v,lin_id,g_map.size());
379
380 boost::mpl::for_each_ref<boost::mpl::range_c<int,0,v_size::value>>(cp);
381
382 ++g_map_it;
383 ++g_dst_it;
384 }
385 }
386
397 template<typename Vct, typename Grid_dst ,unsigned int ... pos> void copy_normal(Vct & v, Grid_dst & g_dst)
398 {
399 // check that g_dst is staggered
400 if (g_dst.is_staggered() == true)
401 std::cerr << __FILE__ << ":" << __LINE__ << " The destination grid must be normal " << std::endl;
402
405
406 for (size_t i = 0 ; i < Grid_dst::dims ; i++)
407 {
408 start.set_d(i,pd.getLow(i));
409 stop.set_d(i,g_map.size(i) - pd.getHigh(i));
410 }
411
412 // sub-grid iterator over the grid map
413 auto g_map_it = g_map.getSubDomainIterator(start,stop);
414
415 // Iterator over the destination grid
416 auto g_dst_it = g_dst.getDomainIterator();
417
418 while (g_dst_it.isNext() == true)
419 {
420 typedef typename to_boost_vmpl<pos...>::type vid;
421 typedef boost::mpl::size<vid> v_size;
422
423 auto key_src = g_map_it.get();
424 size_t lin_id = g_map.template get<0>(key_src);
425
426 // destination point
427 auto key_dst = g_dst_it.get();
428
429 // Transform this id into an id for the vector
430
431 copy_ele<Sys_eqs_typ, Grid_dst,Vct> cp(key_dst,g_dst,v,lin_id,g_map.size());
432
433 boost::mpl::for_each_ref<boost::mpl::range_c<int,0,v_size::value>>(cp);
434
435 ++g_map_it;
436 ++g_dst_it;
437 }
438 }
439
453 template<typename bop, typename iterator>
454 void impose_dit_b(bop num,
455 long int id ,
456 const iterator & it_d)
457 {
458
459 auto it = it_d;
461
462 // iterate all the grid points
463 while (it.isNext())
464 {
465 // get the position
466 auto key = it.get();
467
468 b(g_map.template get<0>(key)*Sys_eqs::nvar + id) = num.get(key);
469
470 // if SE_CLASS1 is defined check the position
471#ifdef SE_CLASS1
472// T::position(key,gs,s_pos);
473#endif
474
475 ++row_b;
476 ++it;
477 }
478 }
479
495 template<typename T, typename bop, typename iterator> void impose_dit(const T & op,
496 bop num,
497 long int id ,
498 const iterator & it_d)
499 {
500 openfpm::vector<triplet> & trpl = A.getMatrixTriplets();
501
502 auto it = it_d;
504
505 std::unordered_map<long int,typename Sys_eqs::stype> cols;
506
507 // iterate all the grid points
508 while (it.isNext())
509 {
510 // get the position
511 auto key = it.get();
512
513 // Add padding
514 for (size_t i = 0 ; i < Sys_eqs::dims ; i++)
515 key.getKeyRef().set_d(i,key.getKeyRef().get(i) + pd.getLow(i));
516
517 // Calculate the non-zero colums
518 T::value(g_map,key,gs,spacing,cols,1.0);
519
520 // indicate if the diagonal has been set
521 bool is_diag = false;
522
523 // create the triplet
524 for ( auto it = cols.begin(); it != cols.end(); ++it )
525 {
526 trpl.add();
527 trpl.last().row() = g_map.template get<0>(key)*Sys_eqs::nvar + id;
528 trpl.last().col() = it->first;
529 trpl.last().value() = it->second;
530
531 if (trpl.last().row() == trpl.last().col())
532 {is_diag = true;}
533
534 }
535
536 // If does not have a diagonal entry put it to zero
537 if (is_diag == false)
538 {
539 trpl.add();
540 trpl.last().row() = g_map.template get<0>(key)*Sys_eqs::nvar + id;
541 trpl.last().col() = g_map.template get<0>(key)*Sys_eqs::nvar + id;
542 trpl.last().value() = 0.0;
543 }
544
545 b(g_map.template get<0>(key)*Sys_eqs::nvar + id) = num.get(key);
546
547 cols.clear();
548
549 // if SE_CLASS1 is defined check the position
550#ifdef SE_CLASS1
551// T::position(key,gs,s_pos);
552#endif
553
554 ++row;
555 ++row_b;
556 ++it;
557 }
558 }
559
560
561
566 {
567 Vcluster<> & v_cl = create_vcluster();
568
569 // Calculate the size of the local domain
570 size_t sz = g_map.getLocalDomainSize();
571
572 // Get the total size of the local grids on each processors
573 v_cl.allGather(sz,pnt);
574 v_cl.execute();
575 s_pnt = 0;
576
577 // calculate the starting point for this processor
578 for (size_t i = 0 ; i < v_cl.getProcessUnitID() ; i++)
579 s_pnt += pnt.get(i);
580
581 // resize b if needed
582 b.resize(Sys_eqs::nvar * g_map.size(),Sys_eqs::nvar * sz);
583
584 // Calculate the starting point
585
586 // Counter
587 size_t cnt = 0;
588
589 // Create the re-mapping grid
590 auto it = g_map.getDomainIterator();
591
592 while (it.isNext())
593 {
594 auto key = it.get();
595
596 g_map.template get<0>(key) = cnt + s_pnt;
597
598 ++cnt;
599 ++it;
600 }
601
602 // sync the ghost
603 g_map.template ghost_get<0>();
604 }
605
612 {
614
615 // Create a CellDecomposer and calculate the spacing
616
617 size_t sz_g[Sys_eqs::dims];
618 for (size_t i = 0 ; i < Sys_eqs::dims ; i++)
619 {
620 if (Sys_eqs::boundary[i] == NON_PERIODIC)
621 sz_g[i] = gs.getSize()[i] - 1;
622 else
623 sz_g[i] = gs.getSize()[i];
624 }
625
626 CellDecomposer_sm<Sys_eqs::dims,typename Sys_eqs::stype> cd(domain,sz_g,0);
627
628 for (size_t i = 0 ; i < Sys_eqs::dims ; i++)
629 spacing[i] = cd.getCellBox().getHigh(i);
630 }
631
632public:
633
639 void setStagPos(comb<Sys_eqs::dims> (& sp)[Sys_eqs::nvar])
640 {
641 for (size_t i = 0 ; i < Sys_eqs::nvar ; i++)
642 s_pos[i] = sp[i];
643 }
644
653 {
654 typedef typename Sys_eqs::b_grid::value_type prp_type;
655
656 openfpm::vector<comb<Sys_eqs::dims>> c_prp[prp_type::max_prop];
657
659
660 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,prp_type::max_prop> >(ssp);
661 }
662
669 {
670 return pd;
671 }
672
681 {
682 return g_map;
683 }
684
696 const typename Sys_eqs::b_grid & b_g)
697 :pd({0,0,0},{0,0,0}),gs(b_g.getGridInfoVoid()),g_map(b_g,stencil,pd),row(0),row_b(0)
698 {
699 Initialize(domain);
700 }
701
713 const Ghost<Sys_eqs::dims,long int> & stencil,
715 const typename Sys_eqs::b_grid & b_g)
716 :pd(pd),gs(b_g.getGridInfoVoid()),g_map(b_g,stencil,pd),row(0),row_b(0)
717 {
718 Initialize(domain);
719 }
720
738 template<typename T> void impose(const T & op,
739 typename Sys_eqs::stype num,
740 long int id,
741 const long int (& start)[Sys_eqs::dims],
742 const long int (& stop)[Sys_eqs::dims],
743 bool skip_first = false)
744 {
747
748 bool increment = false;
749 if (skip_first == true)
750 {
751 start_k = grid_key_dx<Sys_eqs::dims>(start);
752 stop_k = grid_key_dx<Sys_eqs::dims>(start);
753
754 auto it = g_map.getSubDomainIterator(start_k,stop_k);
755
756 if (it.isNext() == true)
757 increment = true;
758 }
759
760 // add padding to start and stop
761 start_k = grid_key_dx<Sys_eqs::dims>(start);
762 stop_k = grid_key_dx<Sys_eqs::dims>(stop);
763
764 auto it = g_map.getSubDomainIterator(start_k,stop_k);
765
766 if (increment == true)
767 {++it;}
768
769 constant_b b(num);
770
771 impose_git_gmap(op,b,id,it);
772
773 }
774
778 void new_b()
779 {row_b = 0;}
780
785 void new_A()
786 {row = 0;}
787
803 template<unsigned int prp, typename b_term, typename iterator>
804 void impose_dit_b(b_term & b_t,
805 const iterator & it_d,
806 long int id = 0)
807 {
809
810 impose_dit_b(b,id,it_d);
811 }
812
828 template<typename T> void impose_dit(const T & op ,
829 typename Sys_eqs::stype num,
830 long int id ,
832 {
833 constant_b b(num);
834
835 impose_dit(op,b,id,it_d);
836 }
837
853 template<typename T, typename bop, typename iterator> void impose_git_gmap(const T & op ,
854 bop num,
855 long int id ,
856 iterator & it)
857 {
858 openfpm::vector<triplet> & trpl = A.getMatrixTriplets();
859
861
862 std::unordered_map<long int,float> cols;
863
864 // iterate all the grid points
865 while (it.isNext())
866 {
867 // get the position
868 auto key = it.get();
869
870 // Calculate the non-zero colums
871 T::value(g_map,key,gs,spacing,cols,1.0);
872
873 // indicate if the diagonal has been set
874 bool is_diag = false;
875
876 // create the triplet
877 for ( auto it = cols.begin(); it != cols.end(); ++it )
878 {
879 trpl.add();
880 trpl.last().row() = g_map.template get<0>(key)*Sys_eqs::nvar + id;
881 trpl.last().col() = it->first;
882 trpl.last().value() = it->second;
883
884 if (trpl.last().row() == trpl.last().col())
885 is_diag = true;
886
887// std::cout << "(" << trpl.last().row() << "," << trpl.last().col() << "," << trpl.last().value() << ")" << "\n";
888 }
889
890 // If does not have a diagonal entry put it to zero
891 if (is_diag == false)
892 {
893 trpl.add();
894 trpl.last().row() = g_map.template get<0>(key)*Sys_eqs::nvar + id;
895 trpl.last().col() = g_map.template get<0>(key)*Sys_eqs::nvar + id;
896 trpl.last().value() = 0.0;
897 }
898
899 b(g_map.template get<0>(key)*Sys_eqs::nvar + id) = num.get(key);
900
901 cols.clear();
902
903 // if SE_CLASS1 is defined check the position
904#ifdef SE_CLASS1
905// T::position(key,gs,s_pos);
906#endif
907
908 ++row;
909 ++row_b;
910 ++it;
911 }
912 }
913
929 template<typename T, typename bop, typename iterator> void impose_git(const T & op ,
930 bop num,
931 long int id ,
932 const iterator & it_d,
933 bool skip_first = false)
934 {
935 openfpm::vector<triplet> & trpl = A.getMatrixTriplets();
936
937 auto start = it_d.getStart();
938 auto stop = it_d.getStop();
939
940 auto itg = g_map.getSubDomainIterator(start,stop);
941
942 auto it = it_d;
943
944 if (skip_first == true)
945 {++it;}
946
948
949 std::unordered_map<long int,float> cols;
950
951 // iterate all the grid points
952 while (it.isNext())
953 {
954 // get the position
955 auto key = it.get();
956 auto keyg = itg.get();
957
958 // Calculate the non-zero colums
959 T::value(g_map,keyg,gs,spacing,cols,1.0);
960
961 // indicate if the diagonal has been set
962 bool is_diag = false;
963
964 // create the triplet
965 for ( auto it = cols.begin(); it != cols.end(); ++it )
966 {
967 trpl.add();
968 trpl.last().row() = g_map.template get<0>(keyg)*Sys_eqs::nvar + id;
969 trpl.last().col() = it->first;
970 trpl.last().value() = it->second;
971
972 if (trpl.last().row() == trpl.last().col())
973 is_diag = true;
974
975// std::cout << "(" << trpl.last().row() << "," << trpl.last().col() << "," << trpl.last().value() << ")" << "\n";
976 }
977
978 // If does not have a diagonal entry put it to zero
979 if (is_diag == false)
980 {
981 trpl.add();
982 trpl.last().row() = g_map.template get<0>(keyg)*Sys_eqs::nvar + id;
983 trpl.last().col() = g_map.template get<0>(keyg)*Sys_eqs::nvar + id;
984 trpl.last().value() = 0.0;
985 }
986
987 b(g_map.template get<0>(keyg)*Sys_eqs::nvar + id) = num.get(key);
988
989 cols.clear();
990
991 // if SE_CLASS1 is defined check the position
992#ifdef SE_CLASS1
993// T::position(key,gs,s_pos);
994#endif
995
996 ++row;
997 ++row_b;
998 ++it;
999 ++itg;
1000 }
1001 }
1002
1018 template<unsigned int prp, typename T, typename b_term, typename iterator> void impose_dit(const T & op ,
1019 b_term & b_t,
1020 const iterator & it_d,
1021 long int id = 0)
1022 {
1023 grid_b<b_term,prp> b(b_t);
1024
1025 impose_dit(op,b,id,it_d);
1026 }
1027
1029 typename Sys_eqs::SparseMatrix_type A;
1030
1036 typename Sys_eqs::SparseMatrix_type & getA()
1037 {
1038#ifdef SE_CLASS1
1039 consistency();
1040#endif
1041 A.resize(g_map.size()*Sys_eqs::nvar,g_map.size()*Sys_eqs::nvar,
1042 g_map.getLocalDomainSize()*Sys_eqs::nvar,
1043 g_map.getLocalDomainSize()*Sys_eqs::nvar);
1044
1045 return A;
1046
1047 }
1048
1054 typename Sys_eqs::Vector_type & getB()
1055 {
1056#ifdef SE_CLASS1
1057 consistency();
1058#endif
1059
1060 return b;
1061 }
1062
1078 template<unsigned int ... pos, typename Vct, typename Grid_dst>
1079 void copy(Vct & v,const long int (& start)[Sys_eqs_typ::dims], const long int (& stop)[Sys_eqs_typ::dims], Grid_dst & g_dst)
1080 {
1082 {
1083 if (g_dst.is_staggered() == true)
1084 {
1087 copy_staggered<Vct,Grid_dst,pos...>(v,g_dst,sr,st);
1088 }
1089 else
1090 {
1091 // Create a temporal staggered grid and copy the data there
1092 auto & g_map = this->getMap();
1093
1094 // Convert the ghost in grid units
1095
1097 for (size_t i = 0 ; i < Grid_dst::dims ; i++)
1098 {
1099 g_int.setLow(i,g_map.getDecomposition().getGhost().getLow(i) / g_map.spacing(i));
1100 g_int.setHigh(i,g_map.getDecomposition().getGhost().getHigh(i) / g_map.spacing(i));
1101 }
1102
1105
1108
1109 for (int i = 0 ; i < Grid_dst::dims ; i++)
1110 {
1111 sr.set_d(i,-1);
1112 st.set_d(i,stop[i]);
1113 }
1114
1115 copy_staggered<Vct,decltype(stg),pos...>(v,stg,sr,st);
1116
1117 // sync the ghost and interpolate to the normal grid
1118 stg.template ghost_get<pos...>();
1119 stg.template to_normal<Grid_dst,pos...>(g_dst,this->getPadding(),start,stop);
1120 }
1121 }
1122 else
1123 {
1124 copy_normal<Vct,Grid_dst,pos...>(v,g_dst);
1125 }
1126 }
1127
1141 template<unsigned int ... pos, typename Vct, typename Grid_dst> void copy(Vct & v, Grid_dst & g_dst)
1142 {
1143 long int start[Sys_eqs_typ::dims];
1144 long int stop[Sys_eqs_typ::dims];
1145
1146 for (size_t i = 0 ; i < Sys_eqs_typ::dims ; i++)
1147 {
1148 start[i] = 0;
1149 stop[i] = g_dst.size(i);
1150 }
1151
1152 this->copy<pos...>(v,start,stop,g_dst);
1153 }
1154};
1155
1156#define EQS_FIELDS 0
1157#define EQS_SPACE 1
1158
1159
1160#endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_FDSCHEME_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition Box.hpp:556
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Definition Box.hpp:567
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition Box.hpp:544
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition Box.hpp:533
Finite Differences.
Definition FDScheme.hpp:127
void impose_dit(const T &op, bop num, long int id, const iterator &it_d)
Impose an operator.
Definition FDScheme.hpp:495
void construct_gmap()
Construct the gmap structure.
Definition FDScheme.hpp:565
const std::vector< size_t > padding(const size_t(&sz)[Sys_eqs::dims], Padding< Sys_eqs::dims > &pd)
calculate the mapping grid size with padding
Definition FDScheme.hpp:284
void consistency()
Check if the Matrix is consistent.
Definition FDScheme.hpp:297
Padding< Sys_eqs::dims > pd
Padding.
Definition FDScheme.hpp:199
const grid_sm< Sys_eqs::dims, void > & gs
Domain Grid informations.
Definition FDScheme.hpp:208
void impose_git_gmap(const T &op, bop num, long int id, iterator &it)
Impose an operator.
Definition FDScheme.hpp:853
void impose_git(const T &op, bop num, long int id, const iterator &it_d, bool skip_first=false)
Impose an operator.
Definition FDScheme.hpp:929
void setStagPos(comb< Sys_eqs::dims >(&sp)[Sys_eqs::nvar])
set the staggered position for each property
Definition FDScheme.hpp:639
size_t s_pnt
Definition FDScheme.hpp:232
void impose_dit(const T &op, b_term &b_t, const iterator &it_d, long int id=0)
Impose an operator.
const g_map_type & getMap()
Return the map between the grid index position and the position in the distributed vector.
Definition FDScheme.hpp:680
void copy_normal(Vct &v, Grid_dst &g_dst)
Copy a given solution vector in a normal grid.
Definition FDScheme.hpp:397
Sys_eqs::Vector_type b
Vector b.
Definition FDScheme.hpp:205
Sys_eqs::Vector_type & getB()
produce the B vector
Sys_eqs Sys_eqs_typ
Type that specify the properties of the system of equations.
Definition FDScheme.hpp:134
void copy(Vct &v, const long int(&start)[Sys_eqs_typ::dims], const long int(&stop)[Sys_eqs_typ::dims], Grid_dst &g_dst)
Copy the vector into the grid.
Sys_eqs::SparseMatrix_type & getA()
produce the Matrix
openfpm::vector< size_t > pnt
Grid points that has each processor.
Definition FDScheme.hpp:223
void new_A()
In case we want to impose a new A re-using FDScheme we have to call This function.
Definition FDScheme.hpp:785
void copy_staggered(Vct &v, Grid_dst &g_dst, grid_key_dx< Grid_dst::dims > &start_d, grid_key_dx< Grid_dst::dims > &stop_d)
Copy a given solution vector in a staggered grid.
Definition FDScheme.hpp:353
size_t row_b
row on b
Definition FDScheme.hpp:220
void impose_dit_b(b_term &b_t, const iterator &it_d, long int id=0)
Impose an operator.
Definition FDScheme.hpp:804
FDScheme(Padding< Sys_eqs::dims > &pd, const Ghost< Sys_eqs::dims, long int > &stencil, const Box< Sys_eqs::dims, typename Sys_eqs::stype > &domain, const typename Sys_eqs::b_grid &b_g)
Constructor.
Definition FDScheme.hpp:712
comb< Sys_eqs::dims > s_pos[Sys_eqs::nvar]
Staggered position for each property.
Definition FDScheme.hpp:226
void impose_dit(const T &op, typename Sys_eqs::stype num, long int id, grid_dist_iterator_sub< Sys_eqs::dims, typename g_map_type::d_grid > it_d)
Impose an operator.
Definition FDScheme.hpp:828
void copy(Vct &v, Grid_dst &g_dst)
Copy the vector into the grid.
void new_b()
In case we want to impose a new b re-using FDScheme we have to call This function.
Definition FDScheme.hpp:778
FDScheme(const Ghost< Sys_eqs::dims, long int > &stencil, const Box< Sys_eqs::dims, typename Sys_eqs::stype > &domain, const typename Sys_eqs::b_grid &b_g)
Constructor.
Definition FDScheme.hpp:694
g_map_type g_map
mapping grid
Definition FDScheme.hpp:214
Sys_eqs::stype spacing[Sys_eqs::dims]
Get the grid spacing.
Definition FDScheme.hpp:211
void impose_dit_b(bop num, long int id, const iterator &it_d)
Impose an operator.
Definition FDScheme.hpp:454
key_and_eq from_row_to_key(size_t row)
From the row Matrix position to the spatial position.
Definition FDScheme.hpp:253
void Initialize(const Box< Sys_eqs::dims, typename Sys_eqs::stype > &domain)
Definition FDScheme.hpp:611
Sys_eqs::SparseMatrix_type A
type of the sparse matrix
grid_dist_id< Sys_eqs::dims, typename Sys_eqs::stype, aggregate< size_t >, typename Sys_eqs::b_grid::decomposition::extended_type > g_map_type
Distributed grid map.
Definition FDScheme.hpp:131
size_t row
row of the matrix
Definition FDScheme.hpp:217
const Padding< Sys_eqs::dims > & getPadding()
Get the specified padding.
Definition FDScheme.hpp:668
void computeStag()
compute the staggered position for each property
Definition FDScheme.hpp:652
void impose(const T &op, typename Sys_eqs::stype num, long int id, const long int(&start)[Sys_eqs::dims], const long int(&stop)[Sys_eqs::dims], bool skip_first=false)
Impose an operator.
Definition FDScheme.hpp:738
Sys_eqs::SparseMatrix_type::triplet_type triplet
Sparse matrix triplet type.
Definition FDScheme.hpp:202
Class that contain Padding information on each direction positive and Negative direction.
Definition Ghost.hpp:127
void execute()
Execute all the requests.
size_t getProcessUnitID()
Get the process unit id.
size_t getProcessingUnits()
Get the total number of processors.
bool allGather(T &send, openfpm::vector< T, Mem, gr > &v)
Gather the data from all processors.
Implementation of VCluster class.
Definition VCluster.hpp:59
This is a distributed grid.
const grid_sm< dim, void > & getGridInfoVoid() const
Get an object containing the grid informations without type.
Decomposition & getDecomposition()
Get the object that store the information about the decomposition.
size_t getLocalDomainSize() const
Get the total number of grid points for the calling processor.
grid_key_dx< dim > getGKey(const grid_dist_key_dx< dim > &k) const
Convert a g_dist_key_dx into a global key.
grid_dist_iterator_sub< dim, device_grid > getSubDomainIterator(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop) const
It return an iterator that span the grid domain only in the specified part.
size_t size() const
Return the total number of points in the grid.
St spacing(size_t i) const
Get the spacing of the grid in direction i.
grid_dist_iterator< dim, device_grid, decltype(device_grid::type_of_subiterator()), FREE > getDomainIterator() const
It return an iterator that span the full grid domain (each processor span its local domain)
Distributed grid iterator.
Grid key for a distributed grid.
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
Definition grid_key.hpp:516
std::string to_string() const
convert the information into a string
Definition grid_key.hpp:444
Declaration grid_sm.
Definition grid_sm.hpp:167
__device__ __host__ const size_t(& getSize() const)[N]
Return the size of the grid as an array.
Definition grid_sm.hpp:760
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
this class is a functor for "for_each" algorithm
Implementation of the staggered grid.
void setDefaultStagPosition()
It set all the properties defined to be staggered on the default location.
Encapsulation of the b term as constant.
Definition FDScheme.hpp:138
Sys_eqs::stype get(grid_dist_key_dx< Sys_eqs::dims > &key)
Get the b term on a grid point.
Definition FDScheme.hpp:161
Sys_eqs::stype scal
scalar
Definition FDScheme.hpp:140
constant_b(typename Sys_eqs::stype scal)
Constrictor from a scalar.
Definition FDScheme.hpp:147
Encapsulation of the b term as grid.
Definition FDScheme.hpp:170
grid & gr
b term fo the grid
Definition FDScheme.hpp:172
grid_b(grid &gr)
gr grid that encapsulate
Definition FDScheme.hpp:179
auto get(grid_dist_key_dx< Sys_eqs::dims > &key) -> decltype(gr.template get< prp >(key))
Get the value of the b term on a grid point.
Definition FDScheme.hpp:190
Equation id + space position.
Definition FDScheme.hpp:238
size_t eq
equation id
Definition FDScheme.hpp:243
grid_key_dx< Sys_eqs::dims > key
space position
Definition FDScheme.hpp:240
Position of the element of dimension d in the hyper-cube of dimension dim.
Definition comb.hpp:35
this class is a functor for "for_each" algorithm
is_grid_staggered analyse T if it has a property grid_type defined and indicate that the grid is stag...
Definition common.hpp:45