vtf-logo

Interpolation.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2002 Ralf Deiterding
00004 // Brandenburgische Universitaet Cottbus
00005 //
00006 // Copyright (C) 2003-2007 California Institute of Technology
00007 // Ralf Deiterding, ralf@amroc.net
00008 
00009 #ifndef AMROC_INTERPOLATION_H
00010 #define AMROC_INTERPOLATION_H
00011 
00019 #include "numerical/grid_interp_extrap.h"
00020 
00027 template <class VectorType, int dim>
00028 class Interpolation {
00029   typedef typename VectorType::InternalDataType DataType;
00030 public:
00031   typedef GridData<VectorType,dim> vec_grid_data_type;  
00032   typedef GridData<DataType,dim> grid_data_type;  
00033   typedef Vector<DataType,dim> point_type;
00034   typedef GridData<bool,dim> bool_grid_data_type;
00035 
00036   Interpolation() : _Equations(VectorType::Length()) {}
00037 
00038   virtual ~Interpolation() {}
00039 
00040   virtual void Interpolate(GridHierarchy& GH, vec_grid_data_type& gdu, const int& nc, 
00041                            const point_type* xc, VectorType* uv, const DataType& ErrorValue) {
00042 
00043     grid_data_type phihelp(grow(gdu.bbox(),2));
00044     phihelp.equals(static_cast<DataType>(-1.0));
00045     phihelp.equals(static_cast<DataType>(1.0),gdu.bbox());
00046 
00047     Coords ex = phihelp.extents();
00048     DCoords dxh2(GH.worldStep(phihelp.stepsize())); dxh2 *= static_cast<DataType>(0.5);
00049     DCoords lbcorner = GH.worldCoords(phihelp.lower(), phihelp.stepsize()) + dxh2;
00050     DCoords ubcorner = GH.worldCoords(phihelp.upper(), phihelp.stepsize()) + dxh2;
00051       
00052     DataType domain[2*dim];
00053     for (register int n=0; n<dim; n++) {
00054       domain[n] = lbcorner(n); domain[dim+n] = ubcorner(n);
00055     }
00056 
00057     const DataType default_values[1] = { ErrorValue };
00058     DataType* values = new DataType[nc];
00059     register int cnt;
00060     for (int neq=0; neq<NEquations(); neq++) {
00061       grid_data_type field(grow(gdu.bbox(),2));
00062       equals_from(field,gdu.bbox(),gdu,gdu.bbox(),neq);
00063       const DataType* fields[1] = { field.data() };
00064       for (cnt=0; cnt<nc; cnt++) values[cnt] = ErrorValue;
00065 
00066       numerical::grid_interp_extrap<dim,1,DataType>( nc, values, xc[0].data(), 
00067                                                      default_values, ex(), domain, 
00068                                                      phihelp.data(), fields );  
00069       for (cnt = 0; cnt<nc; cnt++) 
00070         if (values[cnt] != ErrorValue)
00071           uv[cnt](neq) = values[cnt];
00072     }
00073     delete [] values;
00074   }
00075 
00076   virtual void Interpolate(GridHierarchy& GH, vec_grid_data_type& gdu, 
00077                            grid_data_type& gdphi, const int& nc, const point_type* xc, 
00078                            VectorType* uv, const DataType& ErrorValue) {
00079 
00080     grid_data_type phihelp(grow(gdphi.bbox(),2));
00081     phihelp.equals(static_cast<DataType>(-1.0));
00082     phihelp.equals(gdphi,gdphi.bbox());
00083 
00084     Coords ex = phihelp.extents();
00085     DCoords dxh2(GH.worldStep(phihelp.stepsize())); dxh2 *= static_cast<DataType>(0.5);
00086     DCoords lbcorner = GH.worldCoords(phihelp.lower(), phihelp.stepsize()) + dxh2;
00087     DCoords ubcorner = GH.worldCoords(phihelp.upper(), phihelp.stepsize()) + dxh2;
00088       
00089     DataType domain[2*dim];
00090     for (register int n=0; n<dim; n++) {
00091       domain[n] = lbcorner(n); domain[dim+n] = ubcorner(n);
00092     }
00093 
00094     const DataType default_values[1] = { ErrorValue };
00095     DataType* values = new DataType[nc];
00096     register int cnt;
00097     for (int neq=0; neq<NEquations(); neq++) {
00098       grid_data_type field(grow(gdu.bbox(),2));
00099       equals_from(field,gdu.bbox(),gdu,gdu.bbox(),neq);
00100       const DataType* fields[1] = { field.data() };
00101       for (cnt=0; cnt<nc; cnt++) values[cnt] = ErrorValue;
00102 
00103       numerical::grid_interp_extrap<dim,1,DataType>( nc, values, xc[0].data(), 
00104                                                      default_values, ex(), domain, 
00105                                                      phihelp.data(), fields );  
00106       for (cnt = 0; cnt<nc; cnt++) 
00107         if (values[cnt] != ErrorValue)
00108           uv[cnt](neq) = values[cnt];
00109     }
00110     delete [] values;
00111   }
00112 
00113   virtual void Interpolate(GridHierarchy& GH, vec_grid_data_type& gdu, 
00114                            bool_grid_data_type& gdflg, const int& nc, const point_type* xc, 
00115                            VectorType* uv, const DataType& ErrorValue) {
00116 
00117     grid_data_type phihelp(grow(gdflg.bbox(),2));
00118     SetPhiFromBool(phihelp,gdflg);
00119 
00120     Coords ex = phihelp.extents();
00121     DCoords dxh2(GH.worldStep(phihelp.stepsize())); dxh2 *= static_cast<DataType>(0.5);
00122     DCoords lbcorner = GH.worldCoords(phihelp.lower(), phihelp.stepsize()) + dxh2;
00123     DCoords ubcorner = GH.worldCoords(phihelp.upper(), phihelp.stepsize()) + dxh2;
00124       
00125     DataType domain[2*dim];
00126     for (register int n=0; n<dim; n++) {
00127       domain[n] = lbcorner(n); domain[dim+n] = ubcorner(n);
00128     }
00129 
00130     const DataType default_values[1] = { ErrorValue };
00131     DataType* values = new DataType[nc];
00132     register int cnt;
00133     for (int neq=0; neq<NEquations(); neq++) {
00134       grid_data_type field(grow(gdu.bbox(),2));
00135       equals_from(field,gdu.bbox(),gdu,gdu.bbox(),neq);
00136       const DataType* fields[1] = { field.data() };
00137       for (cnt=0; cnt<nc; cnt++) values[cnt] = ErrorValue;
00138 
00139       numerical::grid_interp_extrap<dim,1,DataType>( nc, values, xc[0].data(), 
00140                                                      default_values, ex(), domain, 
00141                                                      phihelp.data(), fields );  
00142       for (cnt = 0; cnt<nc; cnt++) 
00143         if (values[cnt] != ErrorValue)
00144           uv[cnt](neq) = values[cnt];
00145     }
00146     delete [] values;
00147   }
00148 
00149   virtual void Interpolate(GridHierarchy& GH, grid_data_type& gd, const int& nc, 
00150                            const point_type* xc, DataType* u, const DataType& ErrorValue) {
00151 
00152     grid_data_type phihelp(grow(gd.bbox(),2));
00153     phihelp.equals(static_cast<DataType>(-1.0));
00154     phihelp.equals(static_cast<DataType>(1.0),gd.bbox());
00155 
00156     Coords ex = phihelp.extents();
00157     DCoords dxh2(GH.worldStep(phihelp.stepsize())); dxh2 *= static_cast<DataType>(0.5);
00158     DCoords lbcorner = GH.worldCoords(phihelp.lower(), phihelp.stepsize()) + dxh2;
00159     DCoords ubcorner = GH.worldCoords(phihelp.upper(), phihelp.stepsize()) + dxh2;
00160       
00161     DataType domain[2*dim];
00162     for (register int n=0; n<dim; n++) {
00163       domain[n] = lbcorner(n); domain[dim+n] = ubcorner(n);
00164     }
00165 
00166     const DataType default_values[1] = { ErrorValue };
00167     grid_data_type field(grow(gd.bbox(),2));
00168     field.equals(gd,gd.bbox());
00169     const DataType* fields[1] = { field.data() };
00170 
00171     numerical::grid_interp_extrap<dim,1,DataType>( nc, u, xc[0].data(), 
00172                                                    default_values, ex(), domain, 
00173                                                    phihelp.data(), fields );
00174   }
00175 
00176   virtual void Interpolate(GridHierarchy& GH, grid_data_type& gd, 
00177                            grid_data_type& gdphi, const int& nc, const point_type* xc, 
00178                            DataType* u, const DataType& ErrorValue) {
00179 
00180     grid_data_type phihelp(grow(gdphi.bbox(),2));
00181     phihelp.equals(static_cast<DataType>(-1.0));
00182     phihelp.equals(gdphi,gdphi.bbox());
00183 
00184     Coords ex = phihelp.extents();
00185     DCoords dxh2(GH.worldStep(phihelp.stepsize())); dxh2 *= static_cast<DataType>(0.5);
00186     DCoords lbcorner = GH.worldCoords(phihelp.lower(), phihelp.stepsize()) + dxh2;
00187     DCoords ubcorner = GH.worldCoords(phihelp.upper(), phihelp.stepsize()) + dxh2;
00188       
00189     DataType domain[2*dim];
00190     for (register int n=0; n<dim; n++) {
00191       domain[n] = lbcorner(n); domain[dim+n] = ubcorner(n);
00192     }
00193 
00194     const DataType default_values[1] = { ErrorValue };
00195     grid_data_type field(grow(gd.bbox(),2));
00196     field.equals(gd,gd.bbox());
00197     const DataType* fields[1] = { field.data() };
00198 
00199     numerical::grid_interp_extrap<dim,1,DataType>( nc, u, xc[0].data(), 
00200                                                    default_values, ex(), domain, 
00201                                                    phihelp.data(), fields );
00202   }
00203 
00204   virtual void Interpolate(GridHierarchy& GH, grid_data_type& gd, 
00205                            bool_grid_data_type& gdflg, const int& nc, const point_type* xc, 
00206                            DataType* u, const DataType& ErrorValue) {
00207 
00208     grid_data_type phihelp(grow(gdflg.bbox(),2));
00209     SetPhiFromBool(phihelp,gdflg);
00210 
00211     Coords ex = phihelp.extents();
00212     DCoords dxh2(GH.worldStep(phihelp.stepsize())); dxh2 *= static_cast<DataType>(0.5);
00213     DCoords lbcorner = GH.worldCoords(phihelp.lower(), phihelp.stepsize()) + dxh2;
00214     DCoords ubcorner = GH.worldCoords(phihelp.upper(), phihelp.stepsize()) + dxh2;
00215       
00216     DataType domain[2*dim];
00217     for (register int n=0; n<dim; n++) {
00218       domain[n] = lbcorner(n); domain[dim+n] = ubcorner(n);
00219     }
00220 
00221     const DataType default_values[1] = { ErrorValue };
00222     grid_data_type field(grow(gd.bbox(),2));
00223     field.equals(gd,gd.bbox());
00224     const DataType* fields[1] = { field.data() };
00225 
00226     numerical::grid_interp_extrap<dim,1,DataType>( nc, u, xc[0].data(), 
00227                                                    default_values, ex(), domain, 
00228                                                    phihelp.data(), fields );
00229   }
00230 
00231   const int& NEquations() const { return _Equations; }
00232 
00233 protected:
00234   void SetPhiFromBool(grid_data_type& gdphi, bool_grid_data_type& gdflg) {
00235     gdphi.equals(static_cast<DataType>(-1.0));
00236     if (dim == 1) {
00237       BeginFastIndex1(phi, gdphi.bbox(), gdphi.data(), DataType);
00238       BeginFastIndex1(flg, gdflg.bbox(), gdflg.data(), bool);
00239       for_1 (n, gdflg.bbox(), gdflg.bbox().stepsize())
00240         if (!FastIndex1(flg,n)) 
00241           FastIndex1(phi,n) = static_cast<DataType>(1.0);
00242       end_for
00243       EndFastIndex1(phi);
00244       EndFastIndex1(flg);
00245     }      
00246     else if (dim == 2) {
00247       BeginFastIndex2(phi, gdphi.bbox(), gdphi.data(), DataType);
00248       BeginFastIndex2(flg, gdflg.bbox(), gdflg.data(), bool);
00249       for_2 (n, m, gdflg.bbox(), gdflg.bbox().stepsize())
00250         if (!FastIndex2(flg,n,m)) 
00251           FastIndex2(phi,n,m) = static_cast<DataType>(1.0);
00252       end_for
00253       EndFastIndex2(phi);
00254       EndFastIndex2(flg);
00255     }
00256     else if (dim == 3) {
00257       BeginFastIndex3(phi, gdphi.bbox(), gdphi.data(), DataType);
00258       BeginFastIndex3(flg, gdflg.bbox(), gdflg.data(), bool);
00259       for_3 (n, m, l, gdflg.bbox(), gdflg.bbox().stepsize())
00260         if (!FastIndex3(flg,n,m,l)) 
00261           FastIndex3(phi,n,m,l) = static_cast<DataType>(1.0);
00262       end_for
00263       EndFastIndex3(phi);
00264       EndFastIndex3(flg);
00265     }
00266   }
00267     
00268 protected:
00269   int _Equations;
00270 };
00271 
00272 #endif

Generated on Fri Aug 24 13:00:51 2007 for AMROC Fluid-solver Framework - by  doxygen 1.4.7