11 #ifndef _LSPROBLEMIMPLEM_H_ 12 #define _LSPROBLEMIMPLEM_H_ 14 #if defined(CH_Darwin) && defined(__GNUC__) && ( __GNUC__ == 3 ) 17 #define _GLIBCPP_USE_C99 1 34 #include "NamespaceHeader.H" 39 if (a_r == 0)
return 1;
42 for (
int i = 1; i <= a_r; ++i)
66 for (
int idir = 0; idir <
dim; ++idir)
68 corner[idir] = vertex[idir] - 0.5;
76 Real monoCorner = 1.0;
77 for (
int idir = 0; idir <
dim ; ++idir)
79 monoCorner *= pow(cornerCoord[idir],a_mono[idir]);
82 if (monoCorner > a_maxVal)
84 a_maxVal = monoCorner;
87 if (monoCorner < a_minVal)
89 a_minVal = monoCorner;
97 m_lowerBound.assign(-HUGE);
98 m_upperBound.assign(HUGE);
101 if (m_degreeP == 0 &&
dim == 2)
110 if (m_degreeP == 0 &&
dim == 2)
117 IvDim mono = it->first;
120 monoMaxMin(maxMono,minMono,mono,a_ccm.
m_IFData);
121 Real val = it->second;
124 Real newLoBnd = val/minMono;
125 if (newLoBnd > lobnd)
133 Real newLoBnd = val/maxMono;
134 if (newLoBnd > lobnd)
144 IvDim mono = IvDim::Zero;
147 int variableNdx = ndx;
148 m_lowerBound[variableNdx]=lobnd;
149 m_upperBound[variableNdx]=HUGE;
154 for (
typename PthMomentLoc::const_iterator it = m_monoLocPLess1.begin();
155 it != m_monoLocPLess1.end();++it)
157 IvDim mono = it->first;
160 int ndx = it->second;
161 int variableNdx = ndx + m_numP;
167 momentBounds(lobnd,hibnd,mono, a_ccm.
m_IFData);
171 bool isZeroDegree = (mono.
sum() == 0);
175 Real zeroDegreeLoBnd = 0.0;
186 IvDim mono = it->first;
187 Real val = it->second;
190 monoMaxMin(maxMono,minMono,mono,a_ccm.
m_IFData);
193 Real newLoBnd = val/minMono;
194 if (newLoBnd > zeroDegreeLoBnd)
196 zeroDegreeLoBnd = newLoBnd;
202 Real newLoBnd = val/maxMono;
203 if (newLoBnd > zeroDegreeLoBnd)
205 zeroDegreeLoBnd = newLoBnd;
210 lobnd =
Max(lobnd, zeroDegreeLoBnd);
220 Iv2 bdId = it->first;
223 Real volSide = it->second.getVol(doVol);
224 if (volSide > largestVol[idir])
226 largestVol[idir] = volSide;
234 noUndercutBnd =
Min(noUndercutBnd, vol*normalDx);
236 hibnd =
Min(hibnd, noUndercutBnd);
241 m_lowerBound[variableNdx] = lobnd;
242 m_upperBound[variableNdx] = hibnd;
252 const IvDim & a_mono,
268 for (
int idir = 0; idir <
dim; ++idir)
270 corner[idir] = vertex[idir] - 0.5;
278 Real partialCellMag = 1.0;
279 for (
int idir = 0; idir <
dim ; ++idir)
281 Real pPlus1 =(
Real)( a_mono[idir]+1);
282 partialCellMag *= pow(cornerCoord[idir],pPlus1)/pPlus1;
283 if (cornerCoord[idir] < 0.0) partialCellMag *=-1.0;
285 if (partialCellMag > 0.0) a_hibnd += partialCellMag;
286 if (partialCellMag < 0.0) a_lobnd += partialCellMag;
292 if (m_matrix != NULL)
295 int numRows =
dim*m_numP;
296 int numCols = m_numP + m_numPLess1;
297 freeArray(numRows,numCols,m_matrix);
304 const bool & a_useConstraints)
305 :m_degreeP(a_degreeP),
306 m_numActiveBounds(0),
307 m_useConstraints(a_useConstraints)
318 const int & a_degreeP,
319 const bool & a_useConstraints,
336 if (a_useConstraints)
371 pout() <<
"Singular LS problem. Linearly dependent columns (zero normal?)" << endl;
374 pout() <<
"Conflicting upper/lower bounds in LS problem. Zero or bad normal?" << endl;
379 pout() <<
"BVLS failed to converge properly" << endl;
404 a_residual[2] += ri * ri;
406 a_residual[2] = sqrt(a_residual[2]);
415 if (a_n < 0 || a_m < 0)
419 for (
int i = a_m+1; i <= a_n; ++i)
429 if (a_monoDegree == -1)
437 if (
dim- 1 > a_monoDegree)
440 smaller = a_monoDegree;
445 bigger = a_monoDegree;
447 int numerator =
factorial(
dim - 1 + a_monoDegree,bigger);
451 retval = numerator/denominator;
469 for (
typename PthMomentLoc::const_iterator it =
m_monoLocP.begin();
472 for (
int idir = 0; idir<
dim; ++idir)
475 int row = dim*(it->second) + idir;
476 int pcol = it->second;
481 IvDim mono = it->first;
511 const IvDim & a_mono)
513 if (a_mono[a_idir] > 0)
515 a_coeff = a_mono[a_idir];
517 a_Dmono[a_idir] -= 1;
519 else if (a_mono[a_idir] == 0)
522 for (
int idir = 0; idir <
dim; ++idir)
539 const int & a_degree)
547 for (
int i = 0; i < monomials.
size(); i++)
549 const IvDim & monomial = monomials[i];
551 a_monoLoc[monomial] = i;
552 a_locMono[i] = monomial;
561 a_A =
new Real* [a_rows];
563 for (
int i = 0; i < a_rows; i++)
565 a_A[i] =
new Real [a_cols];
567 Real* scanA = a_A[i];
568 for (
int j = 0; j < a_cols; j++)
579 for (
int i = 0; i < a_rows; i++)
589 a_out <<
"Dim = " <<
dim <<
", degree = " <<
m_degreeP <<
'\n';
590 a_out <<
"m_monoLocP has " <<
m_monoLocP.size() <<
" elements" <<
'\n';
592 for (
typename PthMomentLoc::const_iterator it =
m_monoLocP.begin();
595 a_out <<
"Monomial = " << it->first <<
", Loc = " << it->second <<
'\n';
598 a_out <<
"Dim = " <<
dim <<
'\n';
599 a_out <<
"m_locMonoP has " <<
m_locMonoP.size() <<
" elements" <<
'\n';
601 for (
typename LocPthMoment::const_iterator it =
m_locMonoP.begin();
604 a_out <<
"Loc = " << it->first <<
", Monomial = " << it->second <<
'\n';
607 a_out <<
"m_locMonoPLess1 has " <<
m_locMonoPLess1.size() <<
" elements" <<
'\n';
608 for (
typename PthMomentLoc::const_iterator it =
m_monoLocPLess1.begin();
611 a_out <<
"Monomial = " << it->first <<
", Loc = " << it->second <<
'\n';
614 a_out <<
"m_locMonoPLess1 has " <<
m_locMonoPLess1.size() <<
" elements" <<
'\n';
616 for (
typename LocPthMoment::const_iterator it =
m_locMonoPLess1.begin();
619 a_out <<
"Loc = " << it->first <<
", Monomial = " << it->second <<
'\n';
622 a_out <<
"Matrix and rhs for least squares problem of dim = " << dim << endl;
632 a_lsProblem.
print(a_out);
640 pout() <<
"numRows = " << rows <<
", numCols = " << cols << endl;
642 for (
int i = 0; i < rows; i++)
644 for (
int j = 0; j < cols; j++)
654 pout() <<
"Outputting Rhs" << endl;
657 pout() <<
"m_rhs[" << i <<
"] = " <<
m_rhs[i] << endl;
663 pout() <<
"Outputting Unknowns" << endl;
674 pout() <<
"Outputting Lower/Upper bounds" << endl;
677 pout() <<
"m_lowerBound[" << setw(2) << i <<
"] = " << setw(14) <<
m_lowerBound[i]
678 <<
" m_upperBound[" << setw(2) << i <<
"] = " << setw(14) <<
m_upperBound[i] << endl;
683 pout() <<
"Problem is unconstrained" << endl;
687 #include "NamespaceFooter.H" std::ostream & pout()
Use this in place of std::cout for program output.
void computeBounds(const IndexTM< Real, dim > &a_dx, const CutCellMoments< dim > &a_ccm)
Definition: LSProblemImplem.H:94
BdCutCellMoments m_bdCutCellMoments
Definition: CutCellMoments.H:144
void differentiate(int &a_coeff, IvDim &a_Dmono, int &a_idir, const IvDim &a_mono)
Definition: LSProblemImplem.H:508
map< IvDim, int, LexLT< IvDim > > PthMomentLoc
Definition: LSProblem.H:32
void print(ostream &a_out) const
Definition: LSProblemImplem.H:587
LSResult solveBoundConstrained(Vector< Real > &a_x, Real **a_A, const Vector< Real > &a_rhs, const Vector< Real > &a_lowerBound, const Vector< Real > &a_upperBound)
int m_numP
Definition: LSProblem.H:186
Definition: ConstrainedLS.H:32
#define LARGEREALVAL
Definition: Notation.H:77
bool m_useConstraints
Definition: LSProblem.H:176
#define LARGEINTVAL
Definition: Notation.H:76
int numberActiveConstraints() const
void outputRhs() const
Definition: LSProblemImplem.H:652
EBorVol
Definition: Notation.H:101
void outputMatrix() const
Definition: LSProblemImplem.H:636
Vector< Real > m_rhs
Definition: LSProblem.H:199
void outputBounds() const
Definition: LSProblemImplem.H:670
int numMonomials(const int &a_monoDegree)
Definition: LSProblemImplem.H:426
Definition: ConstrainedLS.H:33
Definition: ComputeCutCellMoments.H:35
void momentBounds(Real &a_lobnd, Real &a_hibnd, const IvDim &a_mono, const IFData< dim > &a_ifData)
Definition: LSProblemImplem.H:250
LSProblem(const int &a_degreeP, const bool &a_useConstraints)
Definition: LSProblemImplem.H:303
Definition: ConstrainedLS.H:35
PthMomentLoc m_monoLocPLess1
Definition: LSProblem.H:189
LSResult
Definition: ConstrainedLS.H:29
void outputUnknowns() const
Definition: LSProblemImplem.H:661
CoordinateSystem< dim > m_localCoord
Definition: IFData.H:58
void resize(unsigned int isize)
Definition: Vector.H:323
Definition: ConstrainedLS.H:31
~LSProblem()
Definition: LSProblemImplem.H:290
T sum() const
Definition: IndexTMI.H:260
void fillMap(PthMomentLoc &a_monoLoc, LocPthMoment &a_locMono, const int &a_degree)
Definition: LSProblemImplem.H:537
int factorial(const int &a_n, const int &a_m=0)
Definition: LSProblemImplem.H:411
map< int, IvDim > LocPthMoment
Definition: LSProblem.H:33
Definition: LSquares.H:22
IFData< dim > m_IFData
Definition: CutCellMoments.H:147
#define BDID_DIR
Definition: Notation.H:88
int nChooseR(int a_n, int a_r)
Definition: LSProblemImplem.H:36
double Real
Definition: REAL.H:33
int invertNormalEq(const Vector< Real > &a_rhs, Vector< Real > &a_residual)
Definition: LSProblemImplem.H:344
T Abs(const T &a_a)
Definition: Misc.H:53
void monoMaxMin(Real &a_maxVal, Real &a_minVal, const IndexTM< int, dim > &a_mono, const IFData< dim > &a_IFData)
Definition: LSProblemImplem.H:50
size_t size() const
Definition: Vector.H:177
PthMomentLoc m_monoLocP
Definition: LSProblem.H:182
void setRhs(const Vector< Real > &a_rhs)
Definition: LSProblemImplem.H:533
static void Error(const char *const a_msg=m_nullString, int m_exitCode=CH_DEFAULT_ERROR_CODE)
Print out message to cerr and exit with the specified exit code.
Definition: Notation.H:104
int m_order
Definition: LSProblem.H:167
CoordinateSystem< dim > m_cellCenterCoord
Definition: IFData.H:56
ostream & operator<<(ostream &a_out, LSProblem< dim > &a_lsProblem)
Definition: LSProblemImplem.H:629
int m_numPLess1
Definition: LSProblem.H:193
PthMoment m_moments
Definition: CutCellMoments.H:138
Real ** m_matrix
Definition: LSProblem.H:197
LocPthMoment m_locMonoP
Definition: LSProblem.H:183
T Min(const T &a_a, const T &a_b)
Definition: Misc.H:26
CornerSigns m_cornerSigns
Definition: IFData.H:51
int m_numActiveBounds
Definition: LSProblem.H:173
int m_degreeP
Definition: LSProblem.H:170
Vector< Real > m_upperBound
Definition: LSProblem.H:202
T Max(const T &a_a, const T &a_b)
Definition: Misc.H:39
PthMoment m_EBmoments
Definition: CutCellMoments.H:141
void allocArray(const int &a_rows, const int &a_cols, Real **&a_A)
Definition: LSProblemImplem.H:557
Definition: ConstrainedLS.H:19
void generateMultiIndices(Vector< IndexTM< int, dim > > &a_indices, const int &a_magnitude)
Definition: MultiIndexImplem.H:18
void LeastSquares(Real **A, Vector< Real > &x, const Vector< Real > &rhs)
void freeArray(const int &a_rows, const int &a_cols, Real **&a_A)
Definition: LSProblemImplem.H:575
int dim
Definition: EBInterface.H:146
void setMatrix()
Definition: LSProblemImplem.H:457
Definition: CutCellMoments.H:32
Definition: ConstrainedLS.H:34
Vector< Real > m_unknowns
Definition: LSProblem.H:198
IndexTM< Real, dim > m_normal
Definition: LSProblem.H:179
Vector< Real > m_lowerBound
Definition: LSProblem.H:201
LocPthMoment m_locMonoPLess1
Definition: LSProblem.H:190
static void Abort(const char *const a_msg=m_nullString)
Print out message to cerr and exit via abort() (if serial) or MPI_Abort() (if parallel).