00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _GENLEVELOPIMPLEM_H_
00029 #define _GENLEVELOPIMPLEM_H_
00030
00031 #include "DataIterator.H"
00032
00033 template <class T>
00034 void GenLevelOp<T>::setToZero(LevelData<T>& a_one)
00035 {
00036 DataIterator dit = a_one.dataIterator();
00037
00038 for (dit.reset(); dit.ok(); ++dit)
00039 {
00040 a_one[dit()].setVal(0.0);
00041 }
00042 }
00043
00044 template <class T>
00045 void GenLevelOp<T>::copy(LevelData<T>& a_one,
00046 const LevelData<T>& a_two)
00047 {
00048 DataIterator dit = a_two.dataIterator();
00049 Interval comps(0,a_two.nComp());
00050
00051 for (dit.reset(); dit.ok(); ++dit)
00052 {
00053 Box box = a_one[dit()].box();
00054
00055 a_one[dit()].copy(box,comps,box,a_two[dit()],comps);
00056 }
00057 }
00058
00059 template <class T>
00060 void GenLevelOp<T>::scalarMul(LevelData<T>& a_one,
00061 const Real a_scalar)
00062 {
00063 DataIterator dit = a_one.dataIterator();
00064
00065 for (dit.reset(); dit.ok(); ++dit)
00066 {
00067 a_one[dit()] *= a_scalar;
00068 }
00069 }
00070
00071 template <class T>
00072 void GenLevelOp<T>::negate(LevelData<T>& a_one)
00073 {
00074 DataIterator dit = a_one.dataIterator();
00075
00076 for (dit.reset(); dit.ok(); ++dit)
00077 {
00078 a_one[dit()].negate();
00079 }
00080 }
00081
00082 template <class T>
00083 void GenLevelOp<T>::sum(LevelData<T>& a_one,
00084 const LevelData<T>& a_two)
00085 {
00086 DataIterator dit = a_two.dataIterator();
00087
00088 for (dit.reset(); dit.ok(); ++dit)
00089 {
00090 a_one[dit()] += a_two[dit()];
00091 }
00092 }
00093
00094 template <class T>
00095 void GenLevelOp<T>::diff(LevelData<T>& a_one,
00096 const LevelData<T>& a_two)
00097 {
00098 DataIterator dit = a_two.dataIterator();
00099
00100 for (dit.reset(); dit.ok(); ++dit)
00101 {
00102 a_one[dit()] -= a_two[dit()];
00103 }
00104 }
00105
00106 template <class T>
00107 Real GenLevelOp<T>::dotProduct(const LevelData<T>& a_one,
00108 const LevelData<T>& a_two)
00109 {
00110 DataIterator dit = a_two.dataIterator();
00111 Real dotProduct = 0.0;
00112
00113 for (dit.reset(); dit.ok(); ++dit)
00114 {
00115 dotProduct += a_one[dit()].dotProduct(a_two[dit()]);
00116 }
00117
00118 #ifdef MPI
00119 Real recv;
00120 int result = MPI_Allreduce(&dotProduct, &recv, 1, MPI_CH_REAL,
00121 MPI_SUM, Chombo_MPI::comm);
00122
00123 if (result != MPI_SUCCESS)
00124 {
00125 MayDay::Error("Error in MPI_Allreduce to sum dot products");
00126 }
00127
00128 dotProduct = recv;
00129 #endif
00130
00131 return dotProduct;
00132 }
00133
00134 template <class T>
00135 Real GenLevelOp<T>::norm(const LevelData<T>& a_one,
00136 const int a_power)
00137 {
00138 const DisjointBoxLayout& boxes = a_one.disjointBoxLayout();
00139 Real norm = 0.0;
00140 int startComp = 0;
00141 int numComp = a_one.nComp();
00142
00143 assert(a_power >= 0);
00144
00145 DataIterator dit = a_one.dataIterator();
00146
00147 if (a_power == 0)
00148 {
00149 for (dit.reset(); dit.ok(); ++dit)
00150 {
00151 norm = Max(norm, a_one[dit()].norm(boxes[dit()], a_power,
00152 startComp, numComp));
00153 }
00154
00155 #ifdef MPI
00156 Real recv;
00157 int result = MPI_Allreduce(&norm, &recv, 1, MPI_CH_REAL,
00158 MPI_MAX, Chombo_MPI::comm);
00159
00160 if (result != MPI_SUCCESS)
00161 {
00162 MayDay::Error("Error in MPI_Allreduce to sum norms");
00163 }
00164
00165 norm = recv;
00166 #endif
00167 }
00168 else if (a_power == 1)
00169 {
00170 for (dit.reset(); dit.ok(); ++dit)
00171 {
00172 norm += a_one[dit()].norm(boxes[dit()], a_power,
00173 startComp, numComp);
00174 }
00175
00176 #ifdef MPI
00177 Real recv;
00178 int result = MPI_Allreduce(&norm, &recv, 1, MPI_CH_REAL,
00179 MPI_SUM, Chombo_MPI::comm);
00180
00181 if (result != MPI_SUCCESS)
00182 {
00183 MayDay::Error("Error in MPI_Allreduce to sum norms");
00184 }
00185
00186 norm = recv;
00187 #endif
00188 }
00189 else
00190 {
00191 for (dit.reset(); dit.ok(); ++dit)
00192 {
00193 norm += a_one[dit()].sumPow(boxes[dit()], a_power,
00194 startComp, numComp);
00195 }
00196
00197 #ifdef MPI
00198 Real recv;
00199 int result = MPI_Allreduce(&norm, &recv, 1, MPI_CH_REAL,
00200 MPI_SUM, Chombo_MPI::comm);
00201
00202 if (result != MPI_SUCCESS)
00203 {
00204 MayDay::Error("Error in MPI_Allreduce to sum norms");
00205 }
00206
00207 norm = recv;
00208 #endif
00209
00210 norm = pow(norm, 1.0/a_power);
00211 }
00212
00213 return norm;
00214 }
00215
00216 template <class T>
00217 void GenLevelOp<T>::defineOpData(LevelData<T>& a_data)
00218 {
00219 #if FIXIT
00220 #endif
00221 }
00222
00223 template <class T>
00224 void GenLevelOp<T>::defineData(LevelData<T>& a_data)
00225 {
00226 #if FIXIT
00227 #endif
00228 }
00229
00230 #endif