LILAC
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rhs_CNLS.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2014, Sam Schetterer, Nathan Kutz, University of Washington
3 Authors: Sam Schetterer
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 
10 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11 
12 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 
16 */
17 #include "rhs_CNLS.h"
18 #include "comp_funcs.hpp"
19 #include "utils/ptr_passer.hpp"
20 #include "types/type_register.hpp"
21 
22 template class type_register<rhs_CNLS>;
27 
28 int rhs_CNLS::dxdt(ptr_passer x, ptr_passer _dx, double t){
29  comp* restr dx = _dx;
30  uf1= x;
32  //take the inverse fourier transform
33  ifft(uf1, u1, NUM_TIME_STEPS);
34  ifft(uf2, u2, NUM_TIME_STEPS);
35  //Inform compiler of alignment, if supported
36  ALIGNED(uf1);
37  ALIGNED(uf2);
38  ALIGNED(u1);
39  ALIGNED(u2);
40  ALIGNED(sq1);
41  ALIGNED(sq2);
42  ALIGNED(comp_in_r);
43  ALIGNED(comp_in);
44  ALIGNED(comp_out);
45  ALIGNED(comp_out_r);
46  ALIGNED(k);
47  ALIGNED(ksq);
48 
49  for(size_t i = 0; i < NUM_TIME_STEPS; i++){
50  sq1[i] = _sqabs(u1[i]);
51  sq2[i] = _sqabs(u2[i]);
52  comp_in_r[i] = sq1[i] + sq2[i];
53  }
54  comp expr1 = Id*(2.0*g0/(1.0+trap(comp_in_r, NUM_TIME_STEPS)*dt/e0));
55  //calculate the ffts for the rhs
56 
57  for(size_t i = 0; i < NUM_TIME_STEPS; i++){
58  comp_in_r[i] = (sq1[i] + A*sq2[i])*u1[i];
59  comp_in[i] = u2[i] * u2[i] * _conj(u1[i]);
60  }
61  //fourier transform forwards nonlinear equations
62  fft(comp_in, comp_out, NUM_TIME_STEPS);
63  fft(comp_in_r, comp_out_r, NUM_TIME_STEPS);
64 
65  for(size_t i = 0; i < NUM_TIME_STEPS; i++){
66  dx[i] = (((D/2) * ksq[i] + K) * uf1[i] - comp_out_r[i]
67  - B*comp_out[i] + expr1*uf1[i]*(1-tau*ksq[i]) - Gamma*uf1[i])/Id;
68  }
69  //Do the fft work for the other half of the calculations
70 
71  for(size_t i = 0; i < NUM_TIME_STEPS; i++){
72  comp_in_r[i] = (A*sq1[i] + sq2[i])*u2[i];
73  comp_in[i] = u1[i] * u1[i] * _conj(u2[i]);
74  }
75  fft(comp_in, comp_out, NUM_TIME_STEPS);
76  fft(comp_in_r, comp_out_r, NUM_TIME_STEPS);
77 
78  for(size_t i = 0; i < NUM_TIME_STEPS; i++){
79  dx[i+NUM_TIME_STEPS] = (((D/2) * ksq[i] - K) * uf2[i] - comp_out_r[i]
80  - B*comp_out[i] + expr1*(uf2[i]-tau*ksq[i]*uf2[i]) - Gamma*uf2[i])/Id;
81  }
82  return 0;
83 }
84 
85 std::vector<std::string> rhs_CNLS::dependencies() const{
86  std::string deps[] = {"g0", "e0", "t_int"};
87  return make_append(deps, rhs::dependencies());
88 }
89 
91  return "CNLS";
92 }
97  rhs::postprocess(dat);
99  if(NUM_TIME_STEPS*2 != dimension){
100  err("dimension not even, which is required for rhs_CNLS",
101  "rhs_CNLS::postprocess", "rhs/rhs_CNLS.cpp", FATAL_ERROR);
102  }
103  dat.retrieve(LENGTH_T, "t_int", this);
104  if(LENGTH_T <= 0){
105  std::string errmess = "t_int is invalid, must be >= 0";
106  err(errmess, "rhs_CNLS::postprocess", "rhs/rhs_CNLS.cpp",
107  dat["t_int"], FATAL_ERROR);
108  }
110  dat.retrieve(g0, "g0", this);
111  dat.retrieve(e0, "e0", this);
113  //create k values
114  double mulval=(2.0*PI/LENGTH_T)*(NUM_TIME_STEPS/2.0);
115  for(size_t i=0; i<NUM_TIME_STEPS/2; i++){
116  k[i] = mulval * (2.0*i/(1.0*NUM_TIME_STEPS));
117  ksq[i] = k[i]*k[i];
118  }
119  for(size_t i=NUM_TIME_STEPS/2; i<NUM_TIME_STEPS; i++){
120  k[i] = mulval * 2.0*((int)i-(int)NUM_TIME_STEPS)/(NUM_TIME_STEPS*1.0);
121  ksq[i] = k[i]*k[i];
122  }
123 
124 }