variableFFT.cc 5.86 KB
Newer Older
Blue Bird's avatar
Blue Bird committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**********************************************************************************
 * Copyright 2010 Christoph Pflaum 
 * 		Department Informatik Lehrstuhl 10 - Systemsimulation
 *		Friedrich-Alexander Universität Erlangen-Nürnberg
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **********************************************************************************/
 
// ------------------------------------------------------------
//
// variableFFT.cc
//
// ------------------------------------------------------------

#include <string>
#include <stdexcept>
#include "../../../program/source/mympi.h"  // von 3D UGBlocks
#include "../abbrevi2D.h"
//#include "../../../linAlgExptemp/source/linAlg.h"
//#include "../parameter.h"
#include "../math_lib/math_lib.h"
#include "../grid/elements2D.h"
#include "../grid/parti2D.h"
#include "../grid/ug2D.h"
#include "../grid/blockgrid2D.h"
#include "../grid/marker2D.h"
//#include "parallel.h"
#include "extemp2D.h"
#include "variable2D.h"
#include "variableFFT.h"
#include "variable2D_cc.h"
#include "update2D.h"
#include "print_var2D_vtk_cc.h"
#include "../grid/examples_ug2D.h"
#include "../../../common_source/mathlib/fouriertransform.h"
#include "../interpol/interpolTwoD.h"

int VariableFFT::powerTwo(int t) {
    int n=1;
    for(int l=0;l<t;++l) n=n*2;
    return n;
}

void VariableFFT::operator=(VariableFFT& v) {
    Variable2D<std::complex<double> >*pv = static_cast<Variable2D<std::complex<double> >* >(&v);
    static_cast<Variable2D<std::complex<double> >* >(this)->operator=(*pv); 
}

Christoph Pflaum's avatar
Christoph Pflaum committed
59
60
61
62
void VariableFFT::operator=(std::complex<double> x) {
    static_cast<Variable2D<std::complex<double> >* >(this)->operator=(x); 
}

Blue Bird's avatar
Blue Bird committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
void VariableFFT::interpolate(Variable2D<std::complex<double> >& v, 
                              std::complex<double> defaultInterpolation) {
     bool createInterpolator = (assignmentBlockgrid==NULL);
     if(createInterpolator==false) {
          if(assignmentBlockgrid->getId() != v.Give_blockgrid()->getId()) {
             delete assignmentInterpolator;
             createInterpolator=true;
          }
     }
     
     if(createInterpolator) {
        assignmentBlockgrid = v.Give_blockgrid();
        assignmentInterpolator 
           = new Interpolate_on_structured_2Dgrid(Nx+1,Ny+1,
				     D2vector(ug->MinimumX(),ug->MinimumY()),
                     D2vector(ug->MaximumX(),ug->MaximumY()),                                                  
                     *assignmentBlockgrid);
     }
     assignmentInterpolator->interpolate(v,data_rectangles[0],defaultInterpolation);
     Update_back(0);       
}

 
Christoph Pflaum's avatar
Christoph Pflaum committed
86
VariableFFT::VariableFFT(int tx, int ty, Rechteck& ugRectangle) :
Blue Bird's avatar
Blue Bird committed
87
88
    Variable2D<std::complex<double> >(
          *(blockgrid = new Blockgrid2D(&ugRectangle,powerTwo(tx)-1,powerTwo(ty)-1))) {
89

Blue Bird's avatar
Blue Bird committed
90
91
    ownBlockGrid = true;    
    init();    
92
93
94

    Hx = ugRectangle.getSizeX() / Nx;
    Hy = ugRectangle.getSizeY() / Ny;
Blue Bird's avatar
Blue Bird committed
95
96
97
98
99
}

VariableFFT::VariableFFT(VariableFFT* other) :
    Variable2D<std::complex<double> >(*(other->Give_blockgrid())) {
    ownBlockGrid = false;
100
101
102
103

    Hx = other->getHx();
    Hy = other->getHy();

Blue Bird's avatar
Blue Bird committed
104
105
106
107
108
109
    init();
}
 
 VariableFFT::VariableFFT(const VariableFFT& other) :
    Variable2D<std::complex<double> >(*(other.Give_blockgrid())) {
    ownBlockGrid = false;
110
111
112
113

    Hx = other.getHx();
    Hy = other.getHy();

Blue Bird's avatar
Blue Bird committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    init();
}
 
void VariableFFT::init() {
    Nx = blockgrid->Give_Nx_rectangle(0);
    Ny = blockgrid->Give_Ny_rectangle(0);       
    
    startValueY = new complex<double>[Ny+1];  

    FourierTransform intF(MAX(Nx+1,Ny+1));
    assignmentInterpolator = NULL;
    assignmentBlockgrid    = NULL;
}

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
void VariableFFT::setDomainStrech(double strechX, double strechY) {
   Blockgrid2D* blockGridFFT = Give_blockgrid(); 
   blockGridFFT->SetDomainStrech(strechX,strechY);        
}

double VariableFFT::getHx() const { 
  return Hx * Give_blockgrid()->getStrechX(); 
}
double VariableFFT::getHy() const { 
  return Hy * Give_blockgrid()->getStrechY(); 
}
double VariableFFT::getNx() { return Nx; }
double VariableFFT::getNy() { return Ny; }
double VariableFFT::getSizeX() { 
  return Hx*Nx * Give_blockgrid()->getStrechX();
}
double VariableFFT::getSizeY() { 
  return Hy*Ny * Give_blockgrid()->getStrechY();
}
Blue Bird's avatar
Blue Bird committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

VariableFFT::~VariableFFT() {
    if(ownBlockGrid) blockgrid;
    delete[] startValueY;    
}

    
void VariableFFT::FFT() {
    Update<rectangleEl>(0);  
    
    for(int j=0;j<=Ny;++j) {
        std::complex<double>* startValue = &(data_rectangles[0][( Nx+1 ) *j]);
        FourierTransform::FFT(startValue,Nx+1);
    }
    
    for(int i=0;i<=Nx;++i) {
        for(int j=0;j<=Ny;++j) {
            startValueY[j] = data_rectangles[0][i + ( Nx+1 ) *j];
        }
        FourierTransform::FFT(startValueY,Ny+1);
        for(int j=0;j<=Ny;++j) {
           data_rectangles[0][i + ( Nx+1 ) *j] = startValueY[j];
        }
    }
    
    Update_back(0);
}
    

void VariableFFT::inversFFT() {    
    Update<rectangleEl>(0);  
    
    for(int i=0;i<=Nx;++i) {
        for(int j=0;j<=Ny;++j) {
            startValueY[j] = data_rectangles[0][i + ( Nx+1 ) *j];
        }
        FourierTransform::iFFT(startValueY,Nx+1);
        for(int j=0;j<=Ny;++j) {
            data_rectangles[0][i + ( Nx+1 ) *j] = startValueY[j];
        }
    }  
    
    for(int j=0;j<=Ny;++j) {
        complex<double>* startValue = &(data_rectangles[0][( Nx+1 ) *j]);
        FourierTransform::iFFT(startValue,Nx+1);
    }    
    
    Update_back(0);    
}