Extension: Geometries
#include "dg/geometries/geometries.h"
refined_curvilinearX.h
Go to the documentation of this file.
1#pragma once
2
4#include "generatorX.h"
5#include "curvilinear.h"
6
7namespace dg
8{
9namespace geo
10{
13
19template<class real_type>
21{
38 real_type fx, real_type fy, unsigned n, unsigned Nx, unsigned Ny, unsigned Nz, bc bcx=dg::DIR, bc bcy=dg::NEU, bc bcz=dg::PER):
39 dg::aRealGeometryX3d<real_type>( generator.zeta0(fx), generator.zeta1(fx), generator.eta0(fy), generator.eta1(fy), 0., 2.*M_PI, ref.fx_new(Nx,fx),ref.fy_new(Ny,fy),n, ref.nx_new(Nx,fx), ref.ny_new(Ny,fy), Nz, bcx, bcy, bcz), map_(3)
40 {
41 handle_ = generator;
42 ref_=ref;
43 constructPerp( fx,fy,n, Nx, Ny);
44 constructParallel(Nz);
45 }
46
47 const aRealGeneratorX2d<real_type> & generator() const{return *handle_;}
48 virtual RealCurvilinearRefinedProductGridX3d* clone()const override final{return new RealCurvilinearRefinedProductGridX3d(*this);}
49 private:
50 //construct phi and lift rest to 3d
51 void constructParallel(unsigned Nz)
52 {
53 map_[2]=dg::evaluate(dg::cooZ3d, *this);
54 unsigned size = this->size();
55 unsigned size2d = this->n()*this->n()*this->Nx()*this->Ny();
56 //resize for 3d values
57 for( unsigned r=0; r<6;r++)
58 jac_.values()[r].resize(size);
59 map_[0].resize(size);
60 map_[1].resize(size);
61 //lift to 3D grid
62 for( unsigned k=1; k<Nz; k++)
63 for( unsigned i=0; i<size2d; i++)
64 {
65 for(unsigned r=0; r<6; r++)
66 jac_.values()[r][k*size2d+i] = jac_.values()[r][(k-1)*size2d+i];
67 map_[0][k*size2d+i] = map_[0][(k-1)*size2d+i];
68 map_[1][k*size2d+i] = map_[1][(k-1)*size2d+i];
69 }
70 }
71 //construct 2d plane
72 void constructPerp( real_type fx, real_type fy, unsigned n, unsigned Nx, unsigned Ny)
73 {
74 std::vector<thrust::host_vector<real_type> > w(2),abs(2);
75 GridX2d g( this->x0(),this->x1(),this->y0(),this->y1(),fx,fy,n,Nx,Ny,this->bcx(),this->bcy());
76 ref_->generate(g,w[0],w[1],abs[0],abs[1]);
77 thrust::host_vector<real_type> x_vec(this->n()*this->Nx()), y_vec(this->n()*this->Ny());
78 for( unsigned i=0; i<x_vec.size(); i++)
79 {
80 x_vec[i] = abs[0][i];
81 //std::cout << abs[0][i] <<"\n";
82 }
83 for( unsigned i=0; i<y_vec.size(); i++)
84 {
85 y_vec[i] = abs[1][i*x_vec.size()];
86 //std::cout << abs[1][i*x_vec.size()] <<"\n";
87 }
88 jac_ = SparseTensor< thrust::host_vector<real_type>>( x_vec);//unit tensor
89 jac_.values().resize( 6);
90 handle_->generate( x_vec, y_vec, this->n()*this->outer_Ny(), this->n()*(this->inner_Ny()+this->outer_Ny()), map_[0], map_[1], jac_.values()[0], jac_.values()[1], jac_.values()[2], jac_.values()[3]);
91 //multiply by weights
92 dg::blas1::pointwiseDot( jac_.values()[0], w[0], jac_.values()[0]);
93 dg::blas1::pointwiseDot( jac_.values()[1], w[0], jac_.values()[1]);
94 dg::blas1::pointwiseDot( jac_.values()[2], w[1], jac_.values()[2]);
95 dg::blas1::pointwiseDot( jac_.values()[3], w[1], jac_.values()[3]);
96 jac_.idx(0,0) = 0, jac_.idx(0,1) = 1, jac_.idx(1,0)=2, jac_.idx(1,1) = 3;
97 }
98 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_jacobian( ) const override final{
99 return jac_;
100 }
101 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_metric( ) const override final
102 {
103 return detail::square( jac_, map_[0], handle_->isOrthogonal());
104 }
105 virtual std::vector<thrust::host_vector<real_type> > do_compute_map()const override final{return map_;}
106 std::vector<thrust::host_vector<real_type> > map_;
107 SparseTensor<thrust::host_vector<real_type> > jac_;
110};
111
115template<class real_type>
117{
130 RealCurvilinearRefinedGridX2d( const aRealRefinementX2d<real_type>& ref, 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::NEU):
131 dg::aRealGeometryX2d<real_type>( generator.zeta0(fx), generator.zeta1(fx), generator.eta0(fy), generator.eta1(fy),ref.fx_new(Nx,fx),ref.fy_new(Ny,fy),n, ref.nx_new(Nx,fx), ref.ny_new(Ny,fy), bcx, bcy)
132 {
133 handle_ = generator;
134 ref_=ref;
135 construct( fx,fy,n,Nx,Ny);
136 }
137
138 const aRealGeneratorX2d<real_type>& generator() const{return *handle_;}
139 virtual RealCurvilinearRefinedGridX2d* clone()const override final{return new RealCurvilinearRefinedGridX2d(*this);}
140 private:
141 void construct(real_type fx, real_type fy, unsigned n, unsigned Nx, unsigned Ny)
142 {
143 RealCurvilinearRefinedProductGridX3d<real_type> g( *ref_, *handle_,fx,fy,n,Nx,Ny,1,this->bcx(), this->bcy());
144 map_=g.map();
145 jac_=g.jacobian();
146 metric_=g.metric();
147 dg::blas1::copy( 1., metric_.values()[3]); //set pp to 1
148 map_.pop_back();
149 }
150 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_jacobian( ) const override final{
151 return jac_;
152 }
153 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_metric( ) const override final{
154 return metric_;
155 }
156 virtual std::vector<thrust::host_vector<real_type> > do_compute_map()const override final{return map_;}
158 std::vector<thrust::host_vector<real_type> > map_;
161};
164
166
167
168} //namespace geo
169} //namespace dg
170
#define M_PI
static DG_DEVICE double cooZ3d(double x, double y, double z)
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
void pointwiseDot(get_value_type< ContainerType > alpha, const ContainerType1 &x1, const ContainerType2 &x2, get_value_type< ContainerType > beta, ContainerType &y)
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 inner_Ny() const
unsigned Ny() const
unsigned Nx() const
unsigned size() const
real_type y0() const
real_type x0() const
unsigned outer_Ny() const
real_type x1() const
real_type fy() const
A two-dimensional grid based on curvilinear coordinates.
Definition: refined_curvilinearX.h:117
const aRealGeneratorX2d< real_type > & generator() const
Definition: refined_curvilinearX.h:138
virtual RealCurvilinearRefinedGridX2d * clone() const override final
Definition: refined_curvilinearX.h:139
RealCurvilinearRefinedGridX2d(const aRealRefinementX2d< real_type > &ref, 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::NEU)
Constructor.
Definition: refined_curvilinearX.h:130
A three-dimensional grid based on curvilinear coordinates.
Definition: refined_curvilinearX.h:21
const aRealGeneratorX2d< real_type > & generator() const
Definition: refined_curvilinearX.h:47
RealCurvilinearRefinedProductGridX3d(const aRealRefinementX2d< real_type > &ref, 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::NEU, bc bcz=dg::PER)
Constructor.
Definition: refined_curvilinearX.h:37
virtual RealCurvilinearRefinedProductGridX3d * clone() const override final
Definition: refined_curvilinearX.h:48
The abstract generator base class.
Definition: generatorX.h:19