4#include <cusp/csr_matrix.h>
26<<<<<<< Updated upstream
31>>>>>>> Stashed changes
45struct DSFieldCylindrical3
48 void operator()(
double t,
const std::array<double,3>&
y,
49 std::array<double,3>& yp)
const {
50 double R =
y[0], Z =
y[1];
51 double vz = m_v.z()(R, Z);
52 yp[0] = m_v.x()(R, Z)/vz;
53 yp[1] = m_v.y()(R, Z)/vz;
60struct DSFieldCylindrical4
63 void operator()(
double t,
const std::array<double,3>& y,
64 std::array<double,3>& yp)
const {
65 double R =
y[0], Z =
y[1];
66 double vx = m_v.x()(R,Z);
67 double vy = m_v.y()(R,Z);
68 double vz = m_v.z()(R,Z);
69 double divvvz = m_v.divvvz()(R,Z);
100 void operator()(
double t,
const std::array<double,3>& y, std::array<double,3>& yp)
const
108 thrust::host_vector<double> dzetadphi_, detadphi_, dvdphi_;
113template<
class real_type>
117 std::array<thrust::host_vector<real_type>,3>& yp,
118 const thrust::host_vector<double>& vol0,
119 thrust::host_vector<real_type>& yp2b,
120 thrust::host_vector<bool>& in_boxp,
121 real_type deltaPhi, real_type eps)
125 std::array<thrust::host_vector<real_type>,3>
y{
132 dg::geo::detail::DSField field;
134 field = dg::geo::detail::DSField( vec, grid_field);
137 dg::geo::detail::DSFieldCylindrical4 cyl_field(vec);
138 const unsigned size = grid_evaluate.
size();
140 "Dormand-Prince-7-4-5", std::array<real_type,3>{0,0,0});
149 for(
unsigned i=0; i<size; i++)
151 std::array<real_type,3> coords{
y[0][i],
y[1][i],
y[2][i]}, coordsP;
153 real_type phi1 = deltaPhi;
154 odeint.
set_dt( deltaPhi/2.);
155 odeint.
integrate( 0, coords, phi1, coordsP);
156 yp[0][i] = coordsP[0], yp[1][i] = coordsP[1], yp[2][i] = coordsP[2];
158 yp2b.assign( grid_evaluate.
size(), deltaPhi);
159 in_boxp.resize( yp2b.size());
161 for(
unsigned i=0; i<size; i++)
163 std::array<real_type,3> coords{
y[0][i],
y[1][i],
y[2][i]}, coordsP;
164 in_boxp[i] = grid_field.
contains( yp[0][i], yp[1][i]) ? true :
false;
165 if(
false == in_boxp[i])
168 real_type phi1 = deltaPhi;
186struct WallFieldlineDistance :
public aCylindricalFunctor<WallFieldlineDistance>
205 double maxPhi,
double eps, std::string type) :
206 m_domain( domain), m_cyl_field(vec),
207 m_deltaPhi( maxPhi), m_eps( eps), m_type(type)
209 if( m_type !=
"phi" && m_type !=
"s")
210 throw std::runtime_error(
"Distance type "+m_type+
" not recognized!\n");
224 std::array<double,3> coords{ R, Z, 0}, coordsP(coords);
226 m_cyl_field( 0., coords, coordsP);
227 double sign = coordsP[2] > 0 ? +1. : -1.;
228 double phi1 = sign*m_deltaPhi;
231 "Dormand-Prince-7-4-5", coords);
238 }
catch (std::exception& e)
242 phi1 = sign*m_deltaPhi;
243 coordsP[2] = 1e6*phi1;
252 dg::geo::detail::DSFieldCylindrical3 m_cyl_field;
253 double m_deltaPhi, m_eps;
269struct WallFieldlineCoordinate :
public aCylindricalFunctor<WallFieldlineCoordinate>
275 double maxPhi,
double eps, std::string type) :
276 m_domain( domain), m_cyl_field(vec),
277 m_deltaPhi( maxPhi), m_eps( eps), m_type(type)
279 if( m_type !=
"phi" && m_type !=
"s")
280 throw std::runtime_error(
"Distance type "+m_type+
" not recognized!\n");
284 double phiP = m_deltaPhi, phiM = -m_deltaPhi;
285 std::array<double,3> coords{ R, Z, 0}, coordsP(coords), coordsM(coords);
287 m_cyl_field( 0., coords, coordsP);
288 double sign = coordsP[2] > 0 ? +1. : -1.;
292 "Dormand-Prince-7-4-5", coords), m_cyl_field,
298 }
catch (std::exception& e)
302 coordsP[2] = 1e6*phiP;
304 coordsM[2] = 1e6*phiM;
307 return sign*(-phiP-phiM)/(phiP-phiM);
308 double sP = coordsP[2], sM = coordsM[2];
309 double value = sign*(-sP-sM)/(sP-sM);
310 if( (phiM <= -m_deltaPhi) && (phiP >= m_deltaPhi))
312 if( (phiM <= -m_deltaPhi))
313 return value*sign > 0 ? value : 0.;
314 if( (phiP >= m_deltaPhi))
315 return value*sign < 0 ? value : 0.;
321 dg::geo::detail::DSFieldCylindrical3 m_cyl_field;
322 double m_deltaPhi, m_eps;
377template<
class ProductGeometry,
class IMatrix,
class container >
386 template <
class Limiter>
388 const ProductGeometry&
grid,
393 unsigned mx=10,
unsigned my=10,
395 std::string interpolation_method =
"dg",
406 template <
class Limiter>
408 const ProductGeometry&
grid,
413 unsigned mx=10,
unsigned my=10,
415 std::string interpolation_method =
"dg",
423 template<
class ...Params>
502 const container&
hbm()
const {
507 const container&
hbp()
const {
542 const container&
bbm()
const {
547 const container&
bbo()
const {
552 const container&
bbp()
const {
556 const ProductGeometry&
grid()
const{
return *m_g;}
612 template<
class BinaryOp,
class UnaryOp>
613 container
evaluate( BinaryOp binary, UnaryOp unary,
614 unsigned p0,
unsigned rounds)
const;
616 std::string
method()
const{
return m_interpolation_method;}
619 void ePlus(
enum whichMatrix which,
const container& in, container& out);
620 void eMinus(
enum whichMatrix which,
const container& in, container& out);
621 void zero(
enum whichMatrix which,
const container& in, container& out);
622 IMatrix m_plus, m_minus, m_plusT, m_minusT;
623<<<<<<< Updated upstream
625 IMatrix m_back, m_forw;
627 IMatrix m_stencil, m_back, m_forw;
628>>>>>>> Stashed changes
629 container m_hbm, m_hbp;
630 container m_G, m_Gm, m_Gp;
631 container m_bphi, m_bphiM, m_bphiP;
632 container m_bbm, m_bbp, m_bbo;
634 container m_left, m_right, m_temp2d;
636 container m_ghostM, m_ghostP;
637 unsigned m_Nz, m_perp_size;
638 dg::bc m_bcx, m_bcy, m_bcz;
639 std::vector<dg::View<const container>> m_f;
640 std::vector<dg::View< container>> m_temp;
644 std::string m_interpolation_method;
646 bool m_have_adjoint =
false;
647 void updateAdjoint( )
651 m_have_adjoint =
true;
658template<
class Geometry,
class IMatrix,
class container>
659template <
class Limiter>
662 const Geometry& grid,
664 unsigned mx,
unsigned my,
double deltaPhi, std::string interpolation_method,
bool benchmark)
667 if( (grid.bcx() ==
PER && bcx !=
PER) || (grid.bcx() !=
PER && bcx ==
PER) )
668 throw(
dg::Error(
dg::Message(_ping_)<<
"Fieldaligned: Got conflicting periodicity in x. The grid says "<<
bc2str(grid.bcx())<<
" while the parameter says "<<
bc2str(bcx)));
669 if( (grid.bcy() ==
PER && bcy !=
PER) || (grid.bcy() !=
PER && bcy ==
PER) )
670 throw(
dg::Error(
dg::Message(_ping_)<<
"Fieldaligned: Got conflicting boundary conditions in y. The grid says "<<
bc2str(grid.bcy())<<
" while the parameter says "<<
bc2str(bcy)));
671 m_Nz=grid.Nz(), m_bcx = bcx, m_bcy = bcy, m_bcz=grid.bcz();
673 if( deltaPhi <=0) deltaPhi = grid.hz();
674<<<<<<< Updated upstream
675 if( interpolation_method ==
"dg-const")
682 if( benchmark) t.
tic();
686 if( interpolation_method ==
"dg-const")
688 grid_transform->set( 1, grid.gx().size(), grid.gy().size());
689 grid_transform3d->set( 1, grid.gx().size(), grid.gy().size(), grid.gz().size());
692 grid_magnetic->set( grid_original->n() < 3 ? 4 : 7, grid_magnetic->Nx(), grid_magnetic->Ny());
694 if( interpolation_method ==
"dg-const" || interpolation_method ==
"dg")
696 grid_fine = grid_original;
697 if( interpolation_method ==
"dg-const")
698 mx *= grid.n(), my *= grid.n();
699 grid_fine->multiplyCellNumbers((
double)mx, (
double)my);
706 tmp.y0(), tmp.y1(), tmp.n(), tmp.Nx(), tmp.Ny(),
707 tmp.bcx(), tmp.bcy());
710 if( interpolation_method ==
"linear")
712 if ( interpolation_method ==
"linear-const")
723 m_perp_size = grid_coarse->size();
726 m_temp2d = m_ghostM = m_ghostP = m_right = m_left;
729 if( benchmark) t.
tic();
730 std::array<thrust::host_vector<double>,3> yp_coarse, ym_coarse, yp, ym;
732 grid_magnetic->set( 7, grid_magnetic->Nx(), grid_magnetic->Ny());
734 grid_fine.set( 1, grid_fine.gx().size(), grid_fine.gy().size());
735 grid_fine.multiplyCellNumbers((
double)mx, (
double)my);
736>>>>>>> Stashed changes
740 std::cout <<
"# DS: High order grid gen took: "<<t.
diff()<<
"\n";
744 std::array<thrust::host_vector<double>,3> yp_trafo, ym_trafo, yp, ym;
745 thrust::host_vector<bool> in_boxp, in_boxm;
746 thrust::host_vector<double> hbp, hbm;
747 thrust::host_vector<double> vol =
dg::tensor::volume(grid_transform3d->metric()), vol2d0;
750<<<<<<< Updated upstream
751 detail::integrate_all_fieldlines2d( vec, *grid_magnetic, *grid_transform,
752 yp_trafo, vol2d0, hbp, in_boxp, deltaPhi, eps);
753 detail::integrate_all_fieldlines2d( vec, *grid_magnetic, *grid_transform,
754 ym_trafo, vol2d0, hbm, in_boxm, -deltaPhi, eps);
759 *grid_original,
dg::NEU,
dg::NEU, grid_original->n() < 3 ?
"cubic" :
"dg");
762 detail::integrate_all_fieldlines2d( vec, *grid_magnetic, *grid_coarse,
763 yp_coarse, vol2d0, hbp, in_boxp, deltaPhi, eps);
764 detail::integrate_all_fieldlines2d( vec, *grid_magnetic, *grid_coarse,
765 ym_coarse, vol2d0, hbm, in_boxm, -deltaPhi, eps);
768 *grid_coarse,
"cubic");
771>>>>>>> Stashed changes
773 for(
int i=0; i<2; i++)
782 std::cout <<
"# DS: Computing all points took: "<<t.
diff()<<
"\n";
787 if( interpolation_method ==
"dg-const" || interpolation_method ==
"dg")
790 *grid_original, bcx, bcy,
"dg");
792 *grid_original, bcx, bcy,
"dg");
797 *grid_transform, bcx, bcy,
"linear");
799 *grid_transform, bcx, bcy,
"linear");
804 if( mx == 1 && my == 1)
811<<<<<<< Updated upstream
813 if( interpolation_method ==
"dg-const" || interpolation_method ==
"dg")
819 std::string method =
"linear";
820 if( interpolation_method ==
"linear-const")
832 grid_project.set( 1, grid_project.gx().size(), grid_project.gy().size());
836>>>>>>> Stashed changes
838 cusp::multiply(
projection, minusFine, minus);
843 std::cout <<
"# DS: Multiplication PI took: "<<t.
diff()<<
"\n";
848 dg::HVec hbphi( yp_trafo[2]), hbphiP(hbphi), hbphiM(hbphi);
853 for(
unsigned i=0; i<hbphiP.size(); i++)
855 hbphiP[i] = vec.
z()(yp_trafo[0][i], yp_trafo[1][i]);
856 hbphiM[i] = vec.
z()(ym_trafo[0][i], ym_trafo[1][i]);
863 for(
unsigned i=0; i<yp_trafo[0].size(); i++)
866 yp_trafo[1][i], *grid_magnetic);
868 ym_trafo[1][i], *grid_magnetic);
883 m_f =
dg::split( (
const container&)m_hbm, grid);
890 thrust::host_vector<double> bbm( in_boxp.size(),0.), bbo(bbm), bbp(bbm);
891 for(
unsigned i=0; i<in_boxp.size(); i++)
893 if( !in_boxp[i] && !in_boxm[i])
895 else if( !in_boxp[i] && in_boxm[i])
897 else if( in_boxp[i] && !in_boxm[i])
905 m_deltaPhi = deltaPhi;
907 m_interpolation_method = interpolation_method;
910 m_perp_size = grid_transform->size();
913 m_temp2d = m_ghostM = m_ghostP = m_right = m_left;
917template<
class G,
class I,
class container>
919 const G& grid,
const container& in)
924 assert( m_g->Nz() % grid.Nz() == 0);
925 unsigned Nz_coarse = grid.Nz(), Nz = m_g->Nz();
926 unsigned cphi = Nz / Nz_coarse;
931 std::vector<dg::View< container>> out_split =
dg::split( out, *m_g);
932 std::vector<dg::View< const container>> in_split =
dg::split( in, grid);
933 for (
int i=0; i<(int)Nz_coarse; i++)
941 for (
int i=0; i<(int)Nz_coarse; i++)
943 for(
int j=1; j<(int)cphi; j++)
948 dg::blas2::symv( m_plus, m_temp[(i*cphi+cphi+1-j)%Nz], m_temp[i*cphi+cphi-j]);
952 for(
int i=0; i<(int)Nz_coarse; i++)
953 for(
int j=1; j<(int)cphi; j++)
955 double alpha = (double)(cphi-j)/(double)cphi;
956 double beta = (double)j/(
double)cphi;
957 dg::blas1::axpby( alpha, out_split[i*cphi+j], beta, m_temp[i*cphi+j], out_split[i*cphi+j]);
961template<
class G,
class I,
class container>
964 assert( m_g->Nz() % grid.Nz() == 0);
965 unsigned Nz_coarse = grid.Nz(), Nz = m_g->Nz();
966 unsigned cphi = Nz / Nz_coarse;
969 container helperP( in), helperM(in), tempP(in), tempM(in);
972 for(
int j=1; j<(int)cphi; j++)
986template<
class G,
class I,
class container>
992<<<<<<< Updated upstream
995 if( (m_interpolation_method ==
"linear" || m_interpolation_method ==
"linear-const") && which !=
zeroForw && which !=
zeroBack)
1002>>>>>>> Stashed changes
1005template<
class G,
class I,
class container>
1006void Fieldaligned<G, I, container>::zero(
enum whichMatrix which,
1007 const container& f, container& f0)
1012 for(
unsigned i0=0; i0<m_Nz; i0++)
1020 if( ! m_have_adjoint) updateAdjoint( );
1025 if( ! m_have_adjoint) updateAdjoint( );
1028 else if( which == zeroZero)
1037 if( m_interpolation_method ==
"dg-const")
1050 if( m_interpolation_method ==
"dg-const")
1062template<
class G,
class I,
class container>
1063void Fieldaligned<G, I, container>::ePlus(
enum whichMatrix which,
1064 const container& f, container& fpe)
1069 for(
unsigned i0=0; i0<m_Nz; i0++)
1071 unsigned ip = (i0==m_Nz-1) ? 0:i0+1;
1076 if( ! m_have_adjoint) updateAdjoint( );
1094template<
class G,
class I,
class container>
1095void Fieldaligned<G, I, container>::eMinus(
enum whichMatrix which,
1096 const container& f, container& fme)
1101 for(
unsigned i0=0; i0<m_Nz; i0++)
1103 unsigned im = (i0==0) ? m_Nz-1:i0-1;
1106 if( ! m_have_adjoint) updateAdjoint( );
1126template<
class G,
class I,
class container>
1127template<
class BinaryOp,
class UnaryOp>
1129 UnaryOp unary,
unsigned p0,
unsigned rounds)
const
1133 assert( p0 < m_g->Nz());
1138 container temp(init2d), tempP(init2d), tempM(init2d);
1140 std::vector<container> plus2d(m_Nz, zero2d), minus2d(plus2d), result(plus2d);
1141 unsigned turns = rounds;
1142 if( turns ==0) turns++;
1144 for(
unsigned r=0; r<turns; r++)
1145 for(
unsigned i0=0; i0<m_Nz; i0++)
1149 unsigned rep = r*m_Nz + i0;
1150 for(
unsigned k=0; k<rep; k++)
1167 for(
unsigned i0=0; i0<m_Nz; i0++)
1169 int idx = (int)i0 - (
int)p0;
1171 result[i0] = plus2d[idx];
1173 result[i0] = minus2d[abs(idx)];
1174 thrust::copy( result[i0].begin(), result[i0].end(), vec3d.begin() + i0*m_perp_size);
1179 for(
unsigned i0=0; i0<m_Nz; i0++)
1181 unsigned revi0 = (m_Nz - i0)%m_Nz;
1186 for(
unsigned i0=0; i0<m_Nz; i0++)
1188 int idx = ((int)i0 -(
int)p0 + m_Nz)%m_Nz;
1189 thrust::copy( result[idx].begin(), result[idx].end(), vec3d.begin() + i0*m_perp_size);
1229template<
class BinaryOp,
class UnaryOp>
1232 const CylindricalVectorLvl0& vec,
1233 const BinaryOp& binary,
1234 const UnaryOp& unary,
1239 unsigned Nz = grid.
Nz();
1243 std::vector<dg::HVec> plus2d(Nz, tempP), minus2d(plus2d), result(plus2d);
1246 std::array<dg::HVec,3> yy0{
1250 dg::geo::detail::DSFieldCylindrical3 cyl_field(vec);
1251 double deltaPhi = grid.
hz();
1252 double phiM0 = 0., phiP0 = 0.;
1253 unsigned turns = rounds;
1254 if( turns == 0) turns++;
1255 for(
unsigned r=0; r<turns; r++)
1256 for(
unsigned i0=0; i0<Nz; i0++)
1258 unsigned rep = r*Nz + i0;
1260 tempM = tempP = init2d;
1264 "Dormand-Prince-7-4-5", std::array<double,3>{0,0,0});
1268 for(
unsigned i=0; i<g2d->size(); i++)
1271 double phiM1 = phiM0 + deltaPhi;
1272 std::array<double,3>
1273 coords0{yy0[0][i],yy0[1][i],yy0[2][i]}, coords1;
1275 deltaPhi, *g2d, eps);
1276 yy1[0][i] = coords1[0], yy1[1][i] = coords1[1], yy1[2][i] =
1278 tempM[i] = binary( yy1[0][i], yy1[1][i]);
1281 double phiP1 = phiP0 - deltaPhi;
1282 coords0 = std::array<double,3>{xx0[0][i],xx0[1][i],xx0[2][i]};
1284 -deltaPhi, *g2d, eps);
1285 xx1[0][i] = coords1[0], xx1[1][i] = coords1[1], xx1[2][i] =
1287 tempP[i] = binary( xx1[0][i], xx1[1][i]);
1289 std::swap( yy0, yy1);
1290 std::swap( xx0, xx1);
1302 for(
unsigned i0=0; i0<Nz; i0++)
1304 int idx = (int)i0 - (
int)p0;
1306 result[i0] = plus2d[idx];
1308 result[i0] = minus2d[abs(idx)];
1309 thrust::copy( result[i0].begin(), result[i0].end(), vec3d.begin() +
1315 for(
unsigned i0=0; i0<Nz; i0++)
1317 unsigned revi0 = (Nz - i0)%Nz;
1322 for(
unsigned i0=0; i0<Nz; i0++)
1324 int idx = ((int)i0 -(
int)p0 + Nz)%Nz;
1325 thrust::copy( result[idx].begin(), result[idx].end(), vec3d.begin()
void assign(const from_ContainerType &from, ContainerType &to, Params &&... ps)
static DG_DEVICE double cooY2d(double x, double y)
static DG_DEVICE double zero(double x)
static DG_DEVICE double cooX2d(double x, double y)
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
void plus(ContainerType &x, get_value_type< ContainerType > alpha)
void axpby(get_value_type< ContainerType > alpha, const ContainerType1 &x, get_value_type< ContainerType > beta, ContainerType &y)
void scal(ContainerType &x, get_value_type< ContainerType > alpha)
void pointwiseDivide(get_value_type< ContainerType > alpha, const ContainerType1 &x1, const ContainerType2 &x2, get_value_type< ContainerType > beta, ContainerType &y)
void pointwiseDot(get_value_type< ContainerType > alpha, const ContainerType1 &x1, const ContainerType2 &x2, get_value_type< ContainerType > beta, ContainerType &y)
void transfer(const MatrixType &x, AnotherMatrixType &y)
void symv(MatrixType &&M, const ContainerType1 &x, ContainerType2 &y)
void stencil(FunctorType f, MatrixType &&M, const ContainerType1 &x, ContainerType2 &y)
static std::string bc2str(bc bcx)
thrust::host_vector< real_type > evaluate(UnaryOp f, const RealGrid1d< real_type > &g)
thrust::host_vector< real_type > fem_inv_weights(const RealGrid1d< real_type > &g)
dg::InverseKroneckerTriDiagonal2d< dg::HVec_t< real_type > > inv_fem_mass2d(const aRealTopology3d< real_type > &g)
dg::InverseKroneckerTriDiagonal2d< dg::HVec_t< real_type > > inv_fem_linear2const2d(const aRealTopology3d< real_type > &g)
whichMatrix
Enum for the use in Fieldaligned.
Definition: fieldaligned.h:17
ZERO NoLimiter
No Limiter.
Definition: fieldaligned.h:35
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:1204
ONE FullLimiter
Full Limiter means there is a limiter everywhere.
Definition: fieldaligned.h:31
@ zeroBack
from transfomred back to dg coordinates
Definition: fieldaligned_coarse.h:27
@ zeroPlusT
transposed plus interpolation in the current plane
Definition: fieldaligned.h:24
@ einsMinus
minus interpolation in previous plane
Definition: fieldaligned.h:20
@ einsMinusT
transposed minus interpolation in next plane
Definition: fieldaligned.h:21
@ zeroMinusT
transposed minus interpolation in the current plane
Definition: fieldaligned.h:25
@ einsPlusT
transposed plus interpolation in previous plane
Definition: fieldaligned.h:19
@ zeroForw
from dg to transformed coordinates
Definition: fieldaligned.h:26
@ zeroMinus
minus interpolation in the current plane
Definition: fieldaligned.h:23
@ zeroPlus
plus interpolation in the current plane
Definition: fieldaligned.h:22
@ einsPlus
plus interpolation in next plane
Definition: fieldaligned.h:18
MPI_Vector< thrust::host_vector< real_type > > weights(const aRealMPITopology2d< real_type > &g)
cusp::coo_matrix< int, real_type, cusp::host_memory > diagonal(const thrust::host_vector< real_type > &diagonal)
cusp::coo_matrix< int, real_type, cusp::host_memory > interpolation(const thrust::host_vector< real_type > &x, const RealGrid1d< real_type > &g, dg::bc bcx=dg::NEU, std::string method="dg")
cusp::coo_matrix< int, real_type, cusp::host_memory > transformation(const aRealTopology3d< real_type > &g_new, const aRealTopology3d< real_type > &g_old)
real_type interpolate(dg::space sp, const thrust::host_vector< real_type > &v, real_type x, const RealGrid1d< real_type > &g, dg::bc bcx=dg::NEU)
dg::MIHMatrix_t< real_type > projection(const aRealMPITopology2d< real_type > &g_new, const aRealMPITopology2d< real_type > &g_old, std::string method="dg")
CylindricalVectorLvl1 createBHat(const TokamakMagneticField &mag)
Contravariant components of the magnetic unit vector field and its Divergence and derivative in cylin...
Definition: magnetic_field.h:931
get_host_vector< Geometry > volume(const Geometry &g)
thrust::host_vector< real_type > forward_transform(const thrust::host_vector< real_type > &in, const aRealTopology2d< real_type > &g)
void transpose(unsigned nx, unsigned ny, const ContainerType &in, ContainerType &out)
thrust::host_vector< real_type > pullback(const Functor &f, const aRealGeometryX2d< real_type > &g)
void pushForwardPerp(const Functor1 &vR, const Functor2 &vZ, container &vx, container &vy, const Geometry &g)
void assign3dfrom2d(const thrust::host_vector< real_type > &in2d, Container &out, const aRealTopology3d< real_type > &grid)
dg::IHMatrix_t< real_type > backproject(const RealGrid1d< real_type > &g)
dg::IHMatrix_t< real_type > inv_backproject(const RealGrid1d< real_type > &g)
void split(SharedContainer &in, std::vector< View< SharedContainer > > &out, const aRealTopology3d< real_type > &grid)
dg::IHMatrix_t< real_type > backscatter(const RealGrid1d< real_type > &g)
dg::IHMatrix_t< real_type > inv_backscatter(const RealGrid1d< real_type > &g)
dg::IHMatrix_t< real_type > window_stencil(unsigned window_size, const RealGrid1d< real_type > &g, dg::bc bcx)
ContainerType volume(const SparseTensor< ContainerType > &t)
IHMatrix_t< double > IHMatrix
thrust::host_vector< double > HVec
void set_dt(value_type dt)
void integrate_in_domain(value_type t0, const ContainerType &u0, value_type &t1, ContainerType &u1, value_type dt, Domain &&domain, value_type eps_root)
aRealGeometry2d< real_type > * perp_grid() const
bool contains(real_type x, real_type y) const
void integrate(value_type t0, const ContainerType &u0, value_type t1, ContainerType &u1)
Definition: fluxfunctions.h:412
This struct bundles a vector field and its divergence.
Definition: fluxfunctions.h:440
const CylindricalFunctor & y() const
y-component of the vector
Definition: fluxfunctions.h:468
const CylindricalFunctor & x() const
x-component of the vector
Definition: fluxfunctions.h:466
const CylindricalFunctor & divvvz() const
Definition: fluxfunctions.h:474
const CylindricalFunctor & z() const
z-component of the vector
Definition: fluxfunctions.h:470
Create and manage interpolation matrices from fieldline integration.
Definition: fieldaligned.h:433
dg::bc bcx() const
Definition: fieldaligned.h:484
const container & hbp() const
Distance between the planes .
Definition: fieldaligned_coarse.h:507
const container & bphi() const
bphi
Definition: fieldaligned_coarse.h:527
container interpolate_from_coarse_grid(const ProductGeometry &grid_coarse, const container &coarse)
Interpolate along fieldlines from a coarse to a fine grid in phi.
void integrate_between_coarse_grid(const ProductGeometry &grid_coarse, const container &coarse, container &out)
Integrate a 2d function on the fine grid.
const container & bbp() const
Mask plus, 1 if fieldline intersects wall in plus direction but not in minus direction,...
Definition: fieldaligned_coarse.h:552
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_coarse.h:512
void operator()(enum whichMatrix which, const container &in, container &out)
Apply the interpolation to three-dimensional vectors.
const container & sqrtGm() const
Volume form on minus plane (including weights) .
Definition: fieldaligned_coarse.h:517
void set_boundaries(dg::bc bcz, double left, double right)
Set boundary conditions in the limiter region.
Definition: fieldaligned_coarse.h:447
std::string method() const
Definition: fieldaligned_coarse.h:616
const container & hbm() const
Distance between the planes and the boundary .
Definition: fieldaligned_coarse.h:502
void set_boundaries(dg::bc bcz, const container &global, double scal_left, double scal_right)
Set boundary conditions in the limiter region.
Definition: fieldaligned_coarse.h:481
const container & bphiM() const
bphi on minus plane
Definition: fieldaligned_coarse.h:532
dg::bc bcy() const
Definition: fieldaligned.h:487
double deltaPhi() const
Definition: fieldaligned.h:553
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=10, unsigned my=10, double deltaPhi=-1, std::string interpolation_method="dg", bool benchmark=true)
Construct from a magnetic field and a grid.
Definition: fieldaligned_coarse.h:387
Fieldaligned()
do not allocate memory; no member call except construct is valid
Definition: fieldaligned_coarse.h:382
void construct(Params &&...ps)
Perfect forward parameters to one of the constructors.
Definition: fieldaligned_coarse.h:424
const container & bbo() const
Mask both, 1 if fieldline intersects wall in plus direction and in minus direction,...
Definition: fieldaligned_coarse.h:547
const container & bbm() const
Mask minus, 1 if fieldline intersects wall in minus direction but not in plus direction,...
Definition: fieldaligned_coarse.h:542
const container & sqrtGp() const
Volume form on plus plane (including weights) .
Definition: fieldaligned_coarse.h:522
const container & bphiP() const
bphi on plus plane
Definition: fieldaligned_coarse.h:537
const ProductGeometry & grid() const
Grid used for construction.
Definition: fieldaligned.h:610
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=10, unsigned my=10, double deltaPhi=-1, std::string interpolation_method="dg", bool benchmark=true)
Construct from a vector field and a grid.
void set_boundaries(dg::bc bcz, const container &left, const container &right)
Set boundary conditions in the limiter region.
Definition: fieldaligned_coarse.h:464
A tokamak field as given by R0, Psi and Ipol plus Meta-data like shape and equilibrium.
Definition: magnetic_field.h:162
WallFieldlineCoordinate(const dg::geo::CylindricalVectorLvl0 &vec, const dg::aRealTopology2d< double > &domain, double maxPhi, double eps, std::string type)
Construct with vector field, domain.
Definition: fieldaligned_coarse.h:272
double do_compute(double R, double Z) const
Definition: fieldaligned_coarse.h:282
WallFieldlineDistance(const dg::geo::CylindricalVectorLvl0 &vec, const dg::aRealTopology2d< double > &domain, double maxPhi, double eps, std::string type)
Construct with vector field, domain.
Definition: fieldaligned_coarse.h:202
double do_compute(double R, double Z) const
Integrate fieldline until wall is reached.
Definition: fieldaligned_coarse.h:222