Extension: Geometries
#include "dg/geometries/geometries.h"
curvilinearX.h
Go to the documentation of this file.
1#pragma once
2
3#include "dg/algorithm.h"
4#include "generatorX.h"
5#include "curvilinear.h"
6
7namespace dg
8{
9namespace geo
10{
13
19template<class real_type>
21{
37 real_type fx, real_type fy, unsigned n, unsigned Nx, unsigned Ny, unsigned Nz, bc bcx=dg::DIR, bc bcy=dg::PER, bc bcz=dg::PER):
38 dg::aRealGeometryX3d<real_type>( generator.zeta0(fx), generator.zeta1(fx), generator.eta0(fy), generator.eta1(fy), 0., 2.*M_PI, fx,fy,n, Nx, Ny, Nz, bcx, bcy, bcz)
39 {
40 map_.resize(3);
41 handle_ = generator;
42 constructPerp( n, Nx, Ny);
43 constructParallel(Nz);
44 }
45
46 const aRealGeneratorX2d<real_type> & generator() const{return *handle_;}
47 virtual RealCurvilinearProductGridX3d* clone()const override final{return new RealCurvilinearProductGridX3d(*this);}
48 private:
49 //construct phi and lift rest to 3d
50 void constructParallel(unsigned Nz)
51 {
52 map_[2]=dg::evaluate(dg::cooZ3d, *this);
53 unsigned size = this->size();
54 unsigned size2d = this->n()*this->n()*this->Nx()*this->Ny();
55 //resize for 3d values
56 for( unsigned r=0; r<6;r++)
57 jac_.values()[r].resize(size);
58 map_[0].resize(size);
59 map_[1].resize(size);
60 //lift to 3D grid
61 for( unsigned k=1; k<Nz; k++)
62 for( unsigned i=0; i<size2d; i++)
63 {
64 for(unsigned r=0; r<6; r++)
65 jac_.values()[r][k*size2d+i] = jac_.values()[r][(k-1)*size2d+i];
66 map_[0][k*size2d+i] = map_[0][(k-1)*size2d+i];
67 map_[1][k*size2d+i] = map_[1][(k-1)*size2d+i];
68 }
69 }
70 //construct 2d plane
71 void constructPerp( unsigned n, unsigned Nx, unsigned Ny)
72 {
73 dg::Grid1d gX1d( this->x0(), this->x1(), n, Nx);
74 dg::GridX1d gY1d( this->y0(), this->y1(), this->fy(), n, Ny);
75 thrust::host_vector<real_type> x_vec = dg::evaluate( dg::cooX1d, gX1d);
76 thrust::host_vector<real_type> y_vec = dg::evaluate( dg::cooX1d, gY1d);
77 jac_ = SparseTensor< thrust::host_vector<real_type>>( x_vec);//unit tensor
78 jac_.values().resize( 6);
79 handle_->generate( x_vec, y_vec, gY1d.n()*gY1d.outer_N(), gY1d.n()*(gY1d.inner_N()+gY1d.outer_N()), map_[0], map_[1], jac_.values()[2], jac_.values()[3], jac_.values()[4], jac_.values()[5]);
80 jac_.idx(0,0) = 2, jac_.idx(0,1) = 3, jac_.idx(1,0)=4, jac_.idx(1,1) = 5;
81 }
82 virtual SparseTensor<thrust::host_vector<real_type>> do_compute_jacobian( ) const override final{
83 return jac_;
84 }
85 virtual SparseTensor<thrust::host_vector<real_type>> do_compute_metric( ) const override final
86 {
87 return detail::square( jac_, map_[0], handle_->isOrthogonal());
88 }
89 virtual std::vector<thrust::host_vector<real_type>> do_compute_map()const override final{return map_;}
90 std::vector<thrust::host_vector<real_type>> map_;
91 SparseTensor<thrust::host_vector<real_type>> jac_;
93};
94
98template<class real_type>
100{
112 RealCurvilinearGridX2d( const aRealGeneratorX2d<real_type>& generator, real_type fx, real_type fy, unsigned n, unsigned Nx, unsigned Ny, dg::bc bcx=dg::DIR, bc bcy=dg::PER):
113 dg::aRealGeometryX2d<real_type>( generator.zeta0(fx), generator.zeta1(fx), generator.eta0(fy), generator.eta1(fy),fx,fy, n, Nx, Ny, bcx, bcy), handle_(generator)
114 {
115 construct(fx,fy, n,Nx,Ny);
116 }
117
118 const aRealGeneratorX2d<real_type>& generator() const{return *handle_;}
119 virtual RealCurvilinearGridX2d* clone()const override final{return new RealCurvilinearGridX2d(*this);}
120 private:
121 void construct( real_type fx, real_type fy, unsigned n, unsigned Nx, unsigned Ny)
122 {
123 RealCurvilinearProductGridX3d<real_type> g( *handle_,fx,fy,n,Nx,Ny,1,this->bcx());
124 map_=g.map();
125 jac_=g.jacobian();
126 metric_=g.metric();
127 dg::blas1::copy( 1., metric_.values()[3]); //set pp to 1
128 map_.pop_back();
129 }
130 virtual SparseTensor<thrust::host_vector<real_type>> do_compute_jacobian( ) const override final{
131 return jac_;
132 }
133 virtual SparseTensor<thrust::host_vector<real_type>> do_compute_metric( ) const override final{
134 return metric_;
135 }
136 virtual std::vector<thrust::host_vector<real_type>> do_compute_map()const override final{return map_;}
138 std::vector<thrust::host_vector<real_type>> map_;
140};
141
142
145
147
148} //namespace geo
149} //namespace dg
#define M_PI
static DG_DEVICE double cooX1d(double x)
static DG_DEVICE double cooZ3d(double x, double y, double z)
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
thrust::host_vector< real_type > evaluate(UnaryOp f, const RealGrid1d< real_type > &g)
int idx(unsigned i, unsigned j) const
std::vector< container > & values()
unsigned Nx() const
real_type fx() const
unsigned Ny() const
real_type fy() const
unsigned n() const
unsigned n() const
real_type y1() const
real_type fx() const
unsigned Nz() const
unsigned Ny() const
unsigned Nx() const
unsigned size() const
real_type y0() const
real_type x0() const
real_type x1() const
real_type fy() const
A two-dimensional grid based on curvilinear coordinates.
Definition: curvilinearX.h:100
RealCurvilinearGridX2d(const aRealGeneratorX2d< real_type > &generator, real_type fx, real_type fy, unsigned n, unsigned Nx, unsigned Ny, dg::bc bcx=dg::DIR, bc bcy=dg::PER)
Constructor.
Definition: curvilinearX.h:112
const aRealGeneratorX2d< real_type > & generator() const
Definition: curvilinearX.h:118
virtual RealCurvilinearGridX2d * clone() const override final
Definition: curvilinearX.h:119
A three-dimensional grid based on curvilinear coordinates.
Definition: curvilinearX.h:21
RealCurvilinearProductGridX3d(const aRealGeneratorX2d< real_type > &generator, real_type fx, real_type fy, unsigned n, unsigned Nx, unsigned Ny, unsigned Nz, bc bcx=dg::DIR, bc bcy=dg::PER, bc bcz=dg::PER)
Constructor.
Definition: curvilinearX.h:36
virtual RealCurvilinearProductGridX3d * clone() const override final
Definition: curvilinearX.h:47
const aRealGeneratorX2d< real_type > & generator() const
Definition: curvilinearX.h:46
The abstract generator base class.
Definition: generatorX.h:19