WaveBEM: Unsteady Nonlinear Potential Flow Solver for Ship-Wave Interaction.
local_expansion_coeff.cc
Go to the documentation of this file.
1 /*
2  * File: LocalExpansionCoeff.cpp
3  * Author: matteo
4  *
5  * Created on April 3, 2015, 6:05 PM
6  */
7 
9 #include "string.h"
10 #include <iostream>
11 
12 using std::cout;
13 using std::endl;
14 
16 {
17  _p=0;
18  _coeff= NULL;
19 }
20 
22 {
23  _p=p;
24  _coeff= new double[(p+1)*(p+1)*(p+1)*(p+2)/2];
25 }
26 
28 {
29  _p=orig._p;
30  _coeff = new double[(_p+1)*(_p+1)*(_p+1)*(_p+2)/2];
31  memcpy(_coeff, orig._coeff, this->getNumberOfElements());
32 }
33 
35 {
36  delete [] _coeff;
37 }
38 
40 {
41  return (_p+1)*(_p+1)*(_p+1)*(_p+2)/2;
42 }
43 
44 double LocalExpansionCoeff::get(const unsigned int &n, const unsigned int &m, const unsigned int &nn, const unsigned int &mm)
45 {
46 
47  return _coeff[ (mm+nn) +
48  getNNOffset(nn) +
49  getMOffset(m) +
50  getNOffset(n)];
51 }
52 
53 void LocalExpansionCoeff::set(const unsigned int &n, const unsigned int &m, const unsigned int &nn, const unsigned int &mm, const double &value)
54 {
55 
56  _coeff[ (mm+nn) +
57  getNNOffset(nn) +
58  getMOffset(m) +
59  getNOffset(n)]=value;
60 }
61 
62 unsigned int LocalExpansionCoeff::getNNOffset(const unsigned int &nn)
63 {
64  return (nn)*(nn);
65 }
66 
67 unsigned int LocalExpansionCoeff::getMOffset(const unsigned int &m)
68 {
69  return (_p+1)*(_p+1)*m;
70 }
71 
72 unsigned int LocalExpansionCoeff::getNOffset(const unsigned int &n)
73 {
74  return ((_p+1)*(_p+1)*(n+1)*(n))/2;
75 }
76 
77 
78 /*
79  * Debugging and test of indexes
80  */
81 //unsigned int const LocalExpansionCoeff::loopDebugger(const unsigned int & p){
82 // unsigned int count=0;
83 // for(unsigned int n=0; n< p+1; ++n){
84 // for(unsigned int m=0; m < n+1; ++m){
85 // for(int nn=0; nn< p+1; ++nn){
86 // for(int mm=-nn; mm< nn+1; ++mm){
87 // ++count;
88 // }
89 // }
90 // }
91 // }
92 // return count;
93 //}
94 //
95 //void LocalExpansionCoeff::fillCoeffWithIndex(){
96 // unsigned int count=0;
97 // for(unsigned int n=0; n< _p+1; ++n){
98 // for(unsigned int m=0; m < n+1; ++m){
99 // for(int nn=0; nn< _p+1; ++nn){
100 // for(int mm=-nn; mm< nn+1; ++mm){
101 // ++count;
102 // _coeff[count-1]=count;
103 //
104 // }
105 // }
106 // }
107 // }
108 //}
109 //
110 //void LocalExpansionCoeff::printCoeff(){
111 // unsigned int count=0;
112 // for(unsigned int n=0; n< _p+1; ++n){
113 // for(unsigned int m=0; m < n+1; ++m){
114 // for(int nn=0; nn< _p+1; ++nn){
115 // for(int mm=-nn; mm< nn+1; ++mm){
116 // ++count;
117 // cout << "(" << n << " " << m << " " << nn << " " << mm << ")"<< endl;
118 // cout << "_coeff: " << _coeff[count-1]<< endl;
119 // cout << "idx:" << (mm+nn) +
120 // getNNOffset(nn) +
121 // getMOffset(m)+
122 // getNOffset(n) << endl;
123 // cout << "get: " << this->get(n,m,nn,mm) << endl;
124 // cout << endl;
125 //
126 // }
127 // }
128 // }
129 // }
130 //}
131 
unsigned int getNumberOfElements()
void set(const unsigned int &n, const unsigned int &m, const unsigned int &nn, const unsigned int &mm, const double &value)
unsigned int getNNOffset(const unsigned int &nn)
unsigned int getMOffset(const unsigned int &m)
static const bool value
double get(const unsigned int &n, const unsigned int &m, const unsigned int &nn, const unsigned int &mm)
unsigned int getNOffset(const unsigned int &n)