5#include "dg/algorithm.h"
38template<
class Container>
39struct Container2EllSparseBlockMat;
42template<
class real_type,
class ... Args,
template <
class...>
class Vector>
43struct Container2EllSparseBlockMat<Vector<real_type, Args...>>
48static inline void parse_method( std::string method, std::string& i, std::string& p, std::string& f)
51 if( method ==
"dg") i =
"dg", p =
"dg";
52 else if( method ==
"linear") i =
"linear", p =
"dg";
53 else if( method ==
"cubic") i =
"cubic", p =
"dg";
54 else if( method ==
"nearest") i =
"nearest", p =
"dg";
55 else if( method ==
"dg-nearest") i =
"dg", p =
"nearest";
56 else if( method ==
"linear-nearest") i =
"linear", p =
"nearest";
57 else if( method ==
"cubic-nearest") i =
"cubic", p =
"nearest";
58 else if( method ==
"nearest-nearest") i =
"nearest", p =
"nearest";
59 else if( method ==
"dg-linear") i =
"dg", p =
"linear";
60 else if( method ==
"linear-linear") i =
"linear", p =
"linear";
61 else if( method ==
"cubic-linear") i =
"cubic", p =
"linear";
62 else if( method ==
"nearest-linear") i =
"nearest", p =
"linear";
63 else if( method ==
"dg-equi") i =
"dg", p =
"dg", f =
"equi";
64 else if( method ==
"linear-equi") i =
"linear", p =
"dg", f =
"equi";
65 else if( method ==
"cubic-equi") i =
"cubic", p =
"dg", f =
"equi";
66 else if( method ==
"nearest-equi") i =
"nearest", p =
"dg", f =
"equi";
67 else if( method ==
"dg-equi-nearest") i =
"dg", p =
"nearest", f =
"equi";
68 else if( method ==
"linear-equi-nearest") i =
"linear", p =
"nearest", f =
"equi";
69 else if( method ==
"cubic-equi-nearest") i =
"cubic", p =
"nearest", f =
"equi";
70 else if( method ==
"nearest-equi-nearest") i =
"nearest", p =
"nearest", f =
"equi";
71 else if( method ==
"dg-equi-linear") i =
"dg", p =
"linear", f =
"equi";
72 else if( method ==
"linear-equi-linear") i =
"linear", p =
"linear", f =
"equi";
73 else if( method ==
"cubic-equi-linear") i =
"cubic", p =
"linear", f =
"equi";
74 else if( method ==
"nearest-equi-linear") i =
"nearest", p =
"linear", f =
"equi";
79struct DSFieldCylindrical3
82 void operator()(
double,
const std::array<double,3>&
y,
83 std::array<double,3>& yp)
const {
84 double R =
y[0], Z =
y[1];
85 double vz = m_v.z()(R, Z);
86 yp[0] = m_v.x()(R, Z)/vz;
87 yp[1] = m_v.y()(R, Z)/vz;
94struct DSFieldCylindrical4
97 void operator()(
double,
const std::array<double,3>&
y,
98 std::array<double,3>& yp)
const {
99 double R =
y[0], Z =
y[1];
100 double vx = m_v.x()(R,Z);
101 double vy = m_v.y()(R,Z);
102 double vz = m_v.z()(R,Z);
103 double divvvz = m_v.divvvz()(R,Z);
134 void operator()(
double,
const std::array<double,3>&
y, std::array<double,3>& yp)
const
142 thrust::host_vector<double> dzetadphi_, detadphi_, dvdphi_;
147template<
class real_type>
151 std::array<thrust::host_vector<real_type>,3>& yp,
152 const thrust::host_vector<double>& vol0,
153 thrust::host_vector<real_type>& yp2b,
154 thrust::host_vector<bool>& in_boxp,
155 real_type deltaPhi, real_type eps)
159 std::array<thrust::host_vector<real_type>,3>
y{
166 dg::geo::detail::DSField field;
168 field = dg::geo::detail::DSField( vec, grid_field);
171 dg::geo::detail::DSFieldCylindrical4 cyl_field(vec);
172 const unsigned size = grid_evaluate.
size();
174 "Dormand-Prince-7-4-5", std::array<real_type,3>{0,0,0});
183 for(
unsigned i=0; i<size; i++)
185 std::array<real_type,3> coords{
y[0][i],
y[1][i],
y[2][i]}, coordsP;
187 real_type phi1 = deltaPhi;
188 odeint.set_dt( deltaPhi/2.);
189 odeint.integrate( 0, coords, phi1, coordsP);
190 yp[0][i] = coordsP[0], yp[1][i] = coordsP[1], yp[2][i] = coordsP[2];
192 yp2b.assign( grid_evaluate.
size(), deltaPhi);
193 in_boxp.resize( yp2b.size());
195 for(
unsigned i=0; i<size; i++)
197 std::array<real_type,3> coords{
y[0][i],
y[1][i],
y[2][i]}, coordsP;
198 in_boxp[i] = grid_field.
contains( std::array{yp[0][i], yp[1][i]}) ?
true :
false;
199 if(
false == in_boxp[i])
202 real_type phi1 = deltaPhi;
203 odeint.integrate_in_domain( 0., coords, phi1, coordsP, 0., (
const
211template<
class real_type>
226template<
class real_type>
231 else if( method !=
"linear")
232 add_rowwise_from_sub( mat, sub);
310template<
class ProductGeometry,
class IMatrix,
class container >
319 template <
class Limiter>
321 const ProductGeometry&
grid,
326 unsigned mx=12,
unsigned my=12,
328 std::string interpolation_method =
"linear-nearest",
339 template <
class Limiter>
341 const ProductGeometry&
grid,
346 unsigned mx=12,
unsigned my=12,
348 std::string interpolation_method =
"linear-nearest",
356 template<
class ...Params>
435 const container&
hbm()
const {
440 const container&
hbp()
const {
475 const container&
bbm()
const {
480 const container&
bbo()
const {
485 const container&
bbp()
const {
489 const ProductGeometry&
grid()
const{
return *m_g;}
545 template<
class BinaryOp,
class UnaryOp>
546 container
evaluate( BinaryOp binary, UnaryOp unary,
547 unsigned p0,
unsigned rounds)
const;
550 std::string
method()
const{
return m_interpolation_method;}
553 void ePlus(
enum whichMatrix which,
const container& in, container& out)
const;
554 void eMinus(
enum whichMatrix which,
const container& in, container& out)
const;
555 void zero(
enum whichMatrix which,
const container& in, container& out)
const;
556 IMatrix m_plus, m_zero, m_minus;
557 mutable IMatrix m_plusT, m_minusT;
559 typename detail::Container2EllSparseBlockMat<container>::type m_bx, m_by, m_inv_bx, m_inv_by;
560 bool apply_backproject =
false, apply_inv_backproject =
false;
561 mutable container m_temp0, m_temp1;
563 container m_hbm, m_hbp;
564 container m_G, m_Gm, m_Gp;
565 container m_bphi, m_bphiM, m_bphiP;
566 container m_bbm, m_bbp, m_bbo;
568 container m_left, m_right;
570 mutable container m_ghostM, m_ghostP;
571 unsigned m_Nz, m_perp_size;
572 dg::bc m_bcx, m_bcy, m_bcz;
573 mutable std::vector<dg::View<const container>> m_split_in;
574 mutable std::vector<dg::View< container>> m_split_out;
578 std::string m_interpolation_method;
580 mutable bool m_have_adjoint =
false;
581 void updateAdjoint( ) const
583 m_plusT = m_plus.transpose();
584 m_minusT = m_minus.transpose();
585 m_have_adjoint =
true;
592template<
class Geometry,
class IMatrix,
class container>
593template <
class Limiter>
596 const Geometry& grid,
598 unsigned mx,
unsigned my,
double deltaPhi, std::string interpolation_method,
bool benchmark) :
600 m_interpolation_method(interpolation_method)
603 std::string inter_m, project_m, fine_m;
604 detail::parse_method( interpolation_method, inter_m, project_m, fine_m);
606 if( project_m !=
"dg" && fine_m ==
"dg")
608 unsigned rx = mx %
grid.nx(), ry = my %
grid.ny();
609 if( 0 != rx || 0 != ry)
611 std::cerr <<
"#Warning: for projection method \"const\" mx and my "
612 <<mx<<
" "<<my<<
" must be multiples of nx and ny "
613 <<
grid.nx()<<
" "<<
grid.ny()<<
" ! Rounding up for you ...\n";
614 mx = mx +
grid.nx() - rx;
615 my = my +
grid.ny() - ry;
619 std::cout <<
"# Interpolation method: \""<<inter_m
620 <<
"\" projection method: \""<<project_m
621 <<
"\" fine grid \""<<fine_m<<
"\"\n";
632 if( benchmark) t.
tic();
635 std::array<thrust::host_vector<double>,3> yp_trafo, ym_trafo;
636 thrust::host_vector<bool> in_boxp, in_boxm;
637 thrust::host_vector<double>
hbp,
hbm;
643 grid_magnetic->set( grid_transform->n() < 3 ? 4 : 7, grid_magnetic->Nx(), grid_magnetic->Ny());
644 detail::integrate_all_fieldlines2d( vec, *grid_magnetic, *grid_transform,
646 detail::integrate_all_fieldlines2d( vec, *grid_magnetic, *grid_transform,
651 std::cout <<
"# DS: Fieldline integration took: "<<t.
diff()<<
"\n";
660 for(
unsigned sub = 0; sub < grid_transform->Ny(); sub++)
663 grid_transform->x0(),
664 grid_transform->x1(),
665 grid_transform->y0() + sub*grid_transform->hy(),
667 sub == grid_transform->Ny()-1 ? grid_transform->y1() :
668 grid_transform->y0() + (sub+1)*grid_transform->hy(),
669 grid_transform->n(), grid_transform->Nx(), 1,
670 grid_transform->bcx(), grid_transform->bcy());
673 grid_equidist.set( 1, grid_transform->shape(0), grid_transform->shape(1));
674 if( fine_m ==
"equi")
675 grid_fine_sub.set( 1, grid_fine_sub.shape(0), grid_fine_sub.shape(1));
676 grid_fine_sub.multiplyCellNumbers((
double)mx, (
double)my);
677 std::array<thrust::host_vector<double>,3> yp, ym;
681 unsigned shift = grid_transform->shape(0) * grid_transform->n();
682 if( sub <= 1 || sub >= grid_transform->Ny() - 2 || grid_transform->n() < 3)
685 *grid_transform,
dg::NEU,
dg::NEU, grid_transform->n() < 3 ?
"cubic" :
"dg");
688 grid_equidist,
bcx,
bcy, inter_m);
697 for(
int i=0; i<2; i++)
703 if( sub <= 1 || sub >= grid_transform->Ny() -2 )
705 if( project_m ==
"dg")
713 grid_fine_sub, project_m);
724 std::array<dg::HVec*,3> xcomp{ &yp[0], &Xf, &ym[0]};
725 std::array<dg::HVec*,3> ycomp{ &yp[1], &Yf, &ym[1]};
726 std::array<dg::IHMatrix*,3> result{ &
plus, &
zero, &minus};
729 for(
unsigned u=0; u<3; u++)
736 grid_equidist,
bcx,
bcy, inter_m);
737 detail::add_from_sub( *result[u], subresult, project_m);
749 if( project_m !=
"dg")
751 apply_inv_backproject =
true;
753 dg::invert(dg::create::detail::square_backproject(
grid.grid(0))),
756 dg::invert(dg::create::detail::square_backproject(
grid.grid(1))),
761 apply_backproject =
true;
763 dg::create::detail::square_backproject(
grid.grid(0)),
766 dg::create::detail::square_backproject(
grid.grid(1)),
772 m_have_adjoint =
false;
777 std::cout <<
"# DS: Assembly of matrices took: "<<t.
diff()<<
"\n";
778 std::streamsize ss = std::cout.precision();
779 std::cout << std::setprecision(1) << std::fixed;
780 std::cout <<
"# DS: Average nnz per row (plus | zero | minus): "
782 <<(double)
plus.num_nnz()/(double)
plus.num_rows()<<
" | "
783 <<(double)
zero.num_nnz()/(double)
zero.num_rows()<<
" | "
785 std::cout << std::defaultfloat << std::setprecision(ss);
788 dg::HVec hbphi( yp_trafo[2]), hbphiP(hbphi), hbphiM(hbphi);
793 for(
unsigned i=0; i<hbphiP.size(); i++)
795 hbphiP[i] = vec.
z()(yp_trafo[0][i], yp_trafo[1][i]);
796 hbphiM[i] = vec.
z()(ym_trafo[0][i], ym_trafo[1][i]);
803 for(
unsigned i=0; i<yp_trafo[0].size(); i++)
806 yp_trafo[1][i], *grid_magnetic);
808 ym_trafo[1][i], *grid_magnetic);
832 m_temp0 = m_temp1 = m_hbm;
835 thrust::host_vector<double>
bbm( in_boxp.size(),0.),
bbo(
bbm),
bbp(
bbm);
836 for(
unsigned i=0; i<in_boxp.size(); i++)
838 if( !in_boxp[i] && !in_boxm[i])
840 else if( !in_boxp[i] && in_boxm[i])
842 else if( in_boxp[i] && !in_boxm[i])
853 m_perp_size = grid_transform->size();
856 m_ghostM = m_ghostP = m_right = m_left;
860template<
class G,
class I,
class container>
862 const G& grid,
const container& in)
const
867 assert( m_g->Nz() % grid.Nz() == 0);
868 unsigned Nz_coarse = grid.Nz(), Nz = m_g->Nz();
869 unsigned cphi = Nz / Nz_coarse;
874 std::vector<dg::View< container>> out_split =
dg::split( out, *m_g);
875 std::vector<dg::View< const container>> in_split =
dg::split( in, grid);
876 if( apply_backproject)
882 for (
int i=0; i<(int)Nz_coarse; i++)
890 for (
int i=0; i<(int)Nz_coarse; i++)
892 for(
int j=1; j<(int)cphi; j++)
897 dg::blas2::symv( m_plus, m_split_out[(i*cphi+cphi+1-j)%Nz], m_split_out[i*cphi+cphi-j]);
901 for(
int i=0; i<(int)Nz_coarse; i++)
902 for(
int j=1; j<(int)cphi; j++)
904 double alpha = (double)(cphi-j)/(double)cphi;
905 double beta = (double)j/(
double)cphi;
906 dg::blas1::axpby( alpha, out_split[i*cphi+j], beta, m_split_out[i*cphi+j], out_split[i*cphi+j]);
908 if( apply_inv_backproject)
915template<
class G,
class I,
class container>
919 assert( m_g->Nz() % grid.Nz() == 0);
920 unsigned Nz_coarse = grid.Nz(), Nz = m_g->Nz();
921 unsigned cphi = Nz / Nz_coarse;
924 container helperP( in), helperM(in), tempP(in), tempM(in);
925 typename detail::Container2EllSparseBlockMat<container>::type bx, by, inv_bx, inv_by;
926 if( apply_backproject)
929 dg::create::detail::square_backproject( grid.grid(0)),
932 dg::create::detail::square_backproject( grid.grid(1)),
935 if( apply_inv_backproject)
938 dg::invert(dg::create::detail::square_backproject( grid.grid(0))),
941 dg::invert(dg::create::detail::square_backproject( grid.grid(1))),
946 for(
int j=1; j<(int)cphi; j++)
948 if( apply_backproject)
957 if( apply_inv_backproject)
966 if( apply_inv_backproject)
977template<
class G,
class I,
class container>
987template<
class G,
class I,
class container>
988void Fieldaligned<G, I, container>::zero(
enum whichMatrix which,
989 const container& f, container& f0)
const
993 if( apply_backproject)
997 dg::split( (
const container&)m_temp1, m_split_in, *m_g);
1000 for(
unsigned i0=0; i0<m_Nz; i0++)
1008 if( ! m_have_adjoint) updateAdjoint( );
1013 if( ! m_have_adjoint) updateAdjoint( );
1018 if ( m_interpolation_method !=
"dg" )
1026 if( apply_inv_backproject)
1032template<
class G,
class I,
class container>
1033void Fieldaligned<G, I, container>::ePlus(
enum whichMatrix which,
1034 const container& f, container& fpe)
const
1038 if( apply_backproject)
1042 dg::split( (
const container&)m_temp1, m_split_in, *m_g);
1045 for(
unsigned i0=0; i0<m_Nz; i0++)
1047 unsigned ip = (i0==m_Nz-1) ? 0:i0+1;
1052 if( ! m_have_adjoint) updateAdjoint( );
1056 if( apply_inv_backproject)
1076template<
class G,
class I,
class container>
1077void Fieldaligned<G, I, container>::eMinus(
enum whichMatrix which,
1078 const container& f, container& fme)
const
1082 if( apply_backproject)
1086 dg::split( (
const container&)m_temp1, m_split_in, *m_g);
1089 for(
unsigned i0=0; i0<m_Nz; i0++)
1091 unsigned im = (i0==0) ? m_Nz-1:i0-1;
1094 if( ! m_have_adjoint) updateAdjoint( );
1100 if( apply_inv_backproject)
1119template<
class G,
class I,
class container>
1120template<
class BinaryOp,
class UnaryOp>
1122 UnaryOp unary,
unsigned p0,
unsigned rounds)
const
1126 assert( p0 < m_g->Nz());
1130 typename detail::Container2EllSparseBlockMat<container>::type bx, by, inv_bx, inv_by;
1131 if( apply_backproject)
1134 dg::create::detail::square_backproject( g2d->grid(0)),
1137 dg::create::detail::square_backproject( g2d->grid(1)),
1140 if( apply_inv_backproject)
1143 dg::invert(dg::create::detail::square_backproject( g2d->grid(0))),
1146 dg::invert(dg::create::detail::square_backproject( g2d->grid(1))),
1150 container temp(init2d), tempP(init2d), tempM(init2d);
1152 std::vector<container> plus2d(m_Nz, zero2d), minus2d(plus2d), result(plus2d);
1153 unsigned turns = rounds;
1154 if( turns ==0) turns++;
1156 for(
unsigned r=0; r<turns; r++)
1157 for(
unsigned i0=0; i0<m_Nz; i0++)
1161 unsigned rep = r*m_Nz + i0;
1162 for(
unsigned k=0; k<rep; k++)
1164 if( apply_backproject)
1173 if( apply_inv_backproject)
1181 if( apply_inv_backproject)
1196 for(
unsigned i0=0; i0<m_Nz; i0++)
1198 int idx = (int)i0 - (
int)p0;
1200 result[i0] = plus2d[idx];
1202 result[i0] = minus2d[abs(idx)];
1203 thrust::copy( result[i0].begin(), result[i0].end(), vec3d.begin() + i0*m_perp_size);
1208 for(
unsigned i0=0; i0<m_Nz; i0++)
1210 unsigned revi0 = (m_Nz - i0)%m_Nz;
1215 for(
unsigned i0=0; i0<m_Nz; i0++)
1217 int idx = ((int)i0 -(int)p0 + m_Nz)%m_Nz;
1218 thrust::copy( result[idx].begin(), result[idx].end(), vec3d.begin() + i0*m_perp_size);
1258template<
class BinaryOp,
class UnaryOp>
1262 const BinaryOp& binary,
1263 const UnaryOp& unary,
1268 unsigned Nz = grid.
Nz();
1272 std::vector<dg::HVec> plus2d(Nz, tempP), minus2d(plus2d), result(plus2d);
1275 std::array<dg::HVec,3> yy0{
1279 dg::geo::detail::DSFieldCylindrical3 cyl_field(vec);
1280 double deltaPhi = grid.
hz();
1281 double phiM0 = 0., phiP0 = 0.;
1282 unsigned turns = rounds;
1283 if( turns == 0) turns++;
1284 for(
unsigned r=0; r<turns; r++)
1285 for(
unsigned i0=0; i0<Nz; i0++)
1287 unsigned rep = r*Nz + i0;
1289 tempM = tempP = init2d;
1293 "Dormand-Prince-7-4-5", std::array<double,3>{0,0,0});
1297 for(
unsigned i=0; i<g2d->size(); i++)
1300 double phiM1 = phiM0 + deltaPhi;
1301 std::array<double,3>
1302 coords0{yy0[0][i],yy0[1][i],yy0[2][i]}, coords1;
1303 odeint.integrate_in_domain( phiM0, coords0, phiM1, coords1,
1304 deltaPhi, *g2d, eps);
1305 yy1[0][i] = coords1[0], yy1[1][i] = coords1[1], yy1[2][i] =
1307 tempM[i] = binary( yy1[0][i], yy1[1][i]);
1310 double phiP1 = phiP0 - deltaPhi;
1311 coords0 = std::array<double,3>{xx0[0][i],xx0[1][i],xx0[2][i]};
1312 odeint.integrate_in_domain( phiP0, coords0, phiP1, coords1,
1313 -deltaPhi, *g2d, eps);
1314 xx1[0][i] = coords1[0], xx1[1][i] = coords1[1], xx1[2][i] =
1316 tempP[i] = binary( xx1[0][i], xx1[1][i]);
1318 std::swap( yy0, yy1);
1319 std::swap( xx0, xx1);
1331 for(
unsigned i0=0; i0<Nz; i0++)
1333 int idx = (int)i0 - (
int)p0;
1335 result[i0] = plus2d[idx];
1337 result[i0] = minus2d[abs(idx)];
1338 thrust::copy( result[i0].begin(), result[i0].end(), vec3d.begin() +
1344 for(
unsigned i0=0; i0<Nz; i0++)
1346 unsigned revi0 = (Nz - i0)%Nz;
1351 for(
unsigned i0=0; i0<Nz; i0++)
1353 int idx = ((int)i0 -(int)p0 + Nz)%Nz;
1354 thrust::copy( result[idx].begin(), result[idx].end(), vec3d.begin()
DG_DEVICE double cooX2d(double x, double)
DG_DEVICE double cooY2d(double, double y)
DG_DEVICE T zero(T, Ts ...)
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
void axpby(value_type alpha, const ContainerType1 &x, value_type1 beta, ContainerType &y)
void pointwiseDot(value_type alpha, const ContainerType1 &x1, const ContainerType2 &x2, value_type1 beta, ContainerType &y)
void plus(ContainerType &x, value_type alpha)
void assign(const from_ContainerType &from, ContainerType &to, Params &&... ps)
void scal(ContainerType &x, value_type alpha)
void pointwiseDivide(value_type alpha, const ContainerType1 &x1, const ContainerType2 &x2, value_type1 beta, ContainerType &y)
void transfer(const MatrixType &x, AnotherMatrixType &y)
void symv(MatrixType &&M, const ContainerType1 &x, ContainerType2 &y)
std::string bc2str(bc bcx)
auto weights(const Topology &g)
auto evaluate(Functor &&f, const Topology &g)
EllSparseBlockMat< real_type, thrust::host_vector > fast_transform(unsigned coord, const dg::SquareMatrix< real_type > &opx, const aRealTopology< real_type, Nd > &t)
whichMatrix
Enum for the use in Fieldaligned.
Definition fieldaligned.h:16
ZERO NoLimiter
No Limiter.
Definition fieldaligned.h:34
thrust::host_vector< double > fieldaligned_evaluate(const aProductGeometry3d &grid, const CylindricalVectorLvl0 &vec, const BinaryOp &binary, const UnaryOp &unary, unsigned p0, unsigned rounds, double eps=1e-5)
Evaluate a 2d functor and transform to all planes along the fieldlines
Definition fieldaligned.h:1259
ONE FullLimiter
Full Limiter means there is a limiter everywhere.
Definition fieldaligned.h:30
@ einsPlusT
transposed plus interpolation in previous plane
Definition fieldaligned.h:18
@ zeroPlus
plus interpolation in the current plane
Definition fieldaligned.h:21
@ einsPlus
plus interpolation in next plane
Definition fieldaligned.h:17
@ zeroForw
from dg to transformed coordinates
Definition fieldaligned.h:25
@ zeroMinusT
transposed minus interpolation in the current plane
Definition fieldaligned.h:24
@ einsMinus
minus interpolation in previous plane
Definition fieldaligned.h:19
@ zeroPlusT
transposed plus interpolation in the current plane
Definition fieldaligned.h:23
@ einsMinusT
transposed minus interpolation in next plane
Definition fieldaligned.h:20
@ zeroMinus
minus interpolation in the current plane
Definition fieldaligned.h:22
Topology::host_vector forward_transform(const typename Topology::host_vector &in, const Topology &g)
real_type interpolate(dg::space sp, const host_vector &v, real_type x, const RealGrid1d< real_type > &g, dg::bc bcx=dg::NEU)
dg::MIHMatrix_t< typename MPITopology::value_type > projection(const MPITopology &g_new, const MPITopology &g_old, std::string method="dg")
dg::SparseMatrix< int, real_type, thrust::host_vector > interpolation(const RecursiveHostVector &x, const aRealTopology< real_type, Nd > &g, std::array< dg::bc, Nd > bcx, std::string method="dg")
dg::SquareMatrix< T > invert(const dg::SquareMatrix< T > &in)
CylindricalVectorLvl1 createBHat(const TokamakMagneticField &mag)
Contravariant components of the magnetic unit vector field and its Divergence and derivative in cylin...
Definition magnetic_field.h:1154
Geometry::host_vector pullback(const Functor &f, const Geometry &g)
void pushForwardPerp(const Functor1 &vR, const Functor2 &vZ, container &vx, container &vy, const Geometry &g)
void assign3dfrom2d(const host_vector &in2d, Container &out, const Topology &grid)
void split(SharedContainer &in, std::vector< View< SharedContainer > > &out, const aRealTopology3d< real_type > &grid)
ContainerType volume(const SparseTensor< ContainerType > &t)
thrust::host_vector< double > HVec
const Vector< Index > & row_offsets() const
const Vector< Index > & column_indices() const
const Vector< Value > & values() const
aRealGeometry2d< real_type > * perp_grid() const
std::enable_if_t<(Md==1), bool > contains(real_type x) const
Definition fluxfunctions.h:415
This struct bundles a vector field and its divergence.
Definition fluxfunctions.h:443
const CylindricalFunctor & y() const
y-component of the vector
Definition fluxfunctions.h:471
const CylindricalFunctor & x() const
x-component of the vector
Definition fluxfunctions.h:469
const CylindricalFunctor & divvvz() const
Definition fluxfunctions.h:477
const CylindricalFunctor & z() const
z-component of the vector
Definition fluxfunctions.h:473
Create and manage interpolation matrices from fieldline integration.
Definition fieldaligned.h:312
dg::bc bcx() const
Definition fieldaligned.h:363
void integrate_between_coarse_grid(const ProductGeometry &grid_coarse, const container &coarse, container &out) const
Integrate a 2d function on the fine grid.
const container & hbp() const
Distance between the planes .
Definition fieldaligned.h:440
const container & bphi() const
The contravariant phi component (3rd component) of the vector field .
Definition fieldaligned.h:460
Fieldaligned(const dg::geo::TokamakMagneticField &vec, const ProductGeometry &grid, dg::bc bcx=dg::NEU, dg::bc bcy=dg::NEU, Limiter limit=FullLimiter(), double eps=1e-5, unsigned mx=12, unsigned my=12, double deltaPhi=-1, std::string interpolation_method="linear-nearest", bool benchmark=true)
Construct from a magnetic field and a grid.
Definition fieldaligned.h:320
const container & bbp() const
Mask plus, 1 if fieldline intersects wall in plus direction but not in minus direction,...
Definition fieldaligned.h:485
container evaluate(BinaryOp binary, UnaryOp unary, unsigned p0, unsigned rounds) const
Evaluate a 2d functor and transform to all planes along the fieldline
const container & sqrtG() const
Volume form (including weights) .
Definition fieldaligned.h:445
const container & sqrtGm() const
Volume form on minus plane (including weights) .
Definition fieldaligned.h:450
void set_boundaries(dg::bc bcz, double left, double right)
Set boundary conditions in the limiter region.
Definition fieldaligned.h:380
std::string method() const
Return the interpolation_method string given in the constructor.
Definition fieldaligned.h:550
const container & hbm() const
Distance between the planes and the boundary .
Definition fieldaligned.h:435
container interpolate_from_coarse_grid(const ProductGeometry &grid_coarse, const container &coarse) const
Interpolate along fieldlines from a coarse to a fine grid in phi.
void set_boundaries(dg::bc bcz, const container &global, double scal_left, double scal_right)
Set boundary conditions in the limiter region.
Definition fieldaligned.h:414
const container & bphiM() const
bphi on minus plane
Definition fieldaligned.h:465
dg::bc bcy() const
Definition fieldaligned.h:366
double deltaPhi() const
Definition fieldaligned.h:432
Fieldaligned()
do not allocate memory; no member call except construct is valid
Definition fieldaligned.h:315
void construct(Params &&...ps)
Perfect forward parameters to one of the constructors.
Definition fieldaligned.h:357
void operator()(enum whichMatrix which, const container &in, container &out) const
Apply the interpolation to three-dimensional vectors.
const container & bbo() const
Mask both, 1 if fieldline intersects wall in plus direction and in minus direction,...
Definition fieldaligned.h:480
const container & bbm() const
Mask minus, 1 if fieldline intersects wall in minus direction but not in plus direction,...
Definition fieldaligned.h:475
const container & sqrtGp() const
Volume form on plus plane (including weights) .
Definition fieldaligned.h:455
Fieldaligned(const dg::geo::CylindricalVectorLvl1 &vec, const ProductGeometry &grid, dg::bc bcx=dg::NEU, dg::bc bcy=dg::NEU, Limiter limit=FullLimiter(), double eps=1e-5, unsigned mx=12, unsigned my=12, double deltaPhi=-1, std::string interpolation_method="linear-nearest", bool benchmark=true)
Construct from a vector field and a grid.
const container & bphiP() const
bphi on plus plane
Definition fieldaligned.h:470
const ProductGeometry & grid() const
Grid used for construction.
Definition fieldaligned.h:489
void set_boundaries(dg::bc bcz, const container &left, const container &right)
Set boundary conditions in the limiter region.
Definition fieldaligned.h:397
A tokamak field as given by R0, Psi and Ipol plus Meta-data like shape and equilibrium.
Definition magnetic_field.h:172