5 #include "RSVSmath_automatic.hpp"
12 bool TriFunc::MakeValidField(vector<double> *
TriFunc::*mp)
19 bool fieldReady =
true;
20 if ((this->*mp) == NULL)
26 n = int((this->*mp)->size());
29 for (ii = 0; ii < (nTarg - n); ++ii)
31 (this->*mp)->push_back(0);
36 for (ii = 0; ii < (n - nTarg); ++ii)
38 (this->*mp)->pop_back();
45 bool TriFunc::CheckValid()
52 else if (
int(p0->size()) != nTarg)
60 else if (
int(p1->size()) != nTarg)
68 else if (
int(p2->size()) != nTarg)
76 bool TriFunc::MakeValid()
91 void TriFunc::assign(
const vector<double> &in0,
const vector<double> &in1,
const vector<double> &in2)
100 void TriFunc::assign(
const vector<double> *in0,
const vector<double> *in1,
const vector<double> *in2)
109 void TriFunc::assign(
int pRepI,
const vector<double> &pRep)
128 void TriFunc::PreCalc()
140 cerr <<
"TriFunc cannot be made to match the required paremeters " << endl;
183 bool CoordFunc::CheckValid()
187 for (
int ii = 0; ii < nCoord; ++ii)
189 if (coords[ii] == NULL)
193 else if (
int(coords[ii]->size()) != nDim)
201 bool CoordFunc::MakeValid()
208 for (
int ii = 0; ii < nCoord; ++ii)
210 fieldReady = MakeValidField(coords[ii]);
211 isReady = isReady & fieldReady;
219 if (
int(pRep.size()) == nCoord)
225 ResetNCoord(
int(pRep.size()));
232 void CoordFunc::assign(
int pRepI,
const vector<double> &pRep)
234 if ((pRepI < nCoord) & (pRepI >= 0))
236 coords[pRepI] = &pRep;
272 void CoordFunc::PreCalc()
284 cerr <<
"CoordFunc cannot be made to match the required paremeters " << endl;
288 void CoordFunc::InitialiseArrays()
293 funA.assign(nFun, 1, fun);
295 jac.assign(nFun, nCoord * nDim, fun);
296 hes.assign(nCoord * nDim, nCoord * nDim * nFun, fun);
297 coords.assign(nCoord, NULL);
340 Volume_f(*p0, *p1, *p2, fun);
341 Volume_df(*p0, *p1, *p2, jac);
342 Volume_ddf(*p0, *p1, *p2, hes);
346 void Volume::CalcFD()
372 std::vector<double> v;
373 double fdStep = 1e-6;
376 vector<vector<double>> vecs;
389 for (
int ii = 0; ii < 3; ++ii)
391 for (
int jj = 0; jj < 3; ++jj)
393 vecs[ii][jj] = vecs[ii][jj] + fdStep;
394 Volume_f(vecs[0], vecs[1], vecs[2], tempVal);
395 jac[0][ii * 3 + jj] = (tempVal - this->fun) / fdStep;
396 vecs[ii][jj] = vecs[ii][jj] - fdStep;
431 Area_f(*p0, *p1, *p2, fun);
432 Area_df(*p0, *p1, *p2, jac);
433 Area_ddf(*p0, *p1, *p2, hes);
437 void LengthEdge::Calc()
444 LengthEdge_f(*coords[0], *coords[1], fun);
445 LengthEdge_df(*coords[0], *coords[1], jac);
446 LengthEdge_ddf(*coords[0], *coords[1], hes);
454 void SurfCentroid::CalcFD()
457 auto baseVal = this->funA;
458 std::vector<double> vtemp;
459 double fdStep = 1e-6;
461 this->calcDeriv =
false;
462 this->jac.assign(3, nCoord * 3, 0.0);
464 for (
int i = 0; i < nCoord; ++i)
466 auto saveVec = this->coords[i];
467 this->coords[i] = &vtemp;
468 for (
int j = 0; j < 3; ++j)
470 this->isCalc =
false;
472 vtemp[j] = vtemp[j] + fdStep;
474 for (
int k = 0; k < 3; ++k)
476 this->jac[k][i + nCoord * j] = (this->funA[k][0] - baseVal[k][0]) / fdStep;
479 this->coords[i] = saveVec;
483 void SurfCentroid::Calc()
509 vector<double> x, y, z, centroidTLength;
512 int ii, ii1, ii2, jj, jj2, nR, nC, ind, ind2;
519 centroid.assign(nDim, 0);
521 for (jj = 0; jj < nCoord; ++jj)
524 LengthEdge_f(*coords[jj], *coords[(jj + 1) % nCoord], currEdge);
525 edgeLength += currEdge;
526 for (ii = 0; ii < nDim; ++ii)
528 centroid[ii] += currEdge * ((*(coords[jj]))[ii] + (*(coords[(jj + 1) % nCoord]))[ii]) / 2;
531 if (edgeLength < 0.000000000000001)
533 cout <<
"Warning edgeLength is 0" << endl;
534 for (ii = 0; ii < nDim; ++ii)
536 funA[ii][0] = (*(coords[0]))[ii];
538 edgeLength = 0.0000001;
542 for (ii = 0; ii < nDim; ++ii)
544 funA[ii][0] = centroid[ii] / edgeLength;
547 if (!this->calcDeriv)
561 for (ii = 0; ii < nCoord; ++ii)
563 x.push_back((*coords[ii])[0]);
564 y.push_back((*coords[ii])[1]);
565 z.push_back((*coords[ii])[2]);
572 SurfCentroid4_df(x, y, z, edgeLength, centroid[0], centroid[1], centroid[2], jac);
576 SurfCentroid5_df(x, y, z, edgeLength, centroid[0], centroid[1], centroid[2], jac);
580 SurfCentroid6_df(x, y, z, edgeLength, centroid[0], centroid[1], centroid[2], jac);
594 temp.assign(nDim, nDim, 0);
595 for (jj = 0; jj < nCoord; jj++)
597 for (ii = 0; ii < 3; ++ii)
599 x[ii] = ((*coords[(jj + ii) % nCoord])[0]);
600 y[ii] = ((*coords[(jj + ii) % nCoord])[1]);
601 z[ii] = ((*coords[(jj + ii) % nCoord])[2]);
603 SurfCentroidSelf_df(x, y, z, edgeLength, centroid[0], centroid[1], centroid[2], temp);
604 ind = (jj + 1) % nCoord;
607 for (ii1 = 0; ii1 < nDim; ii1++)
609 for (ii2 = 0; ii2 < nDim; ii2++)
611 jac[ii1][ind + (ii2 * nCoord)] = temp[ii1][ii2];
636 temp.assign(nDim, nDim * nFun, 0);
637 for (jj = 0; jj < nCoord; jj++)
639 for (ii = 0; ii < 3; ++ii)
641 x[ii] = ((*coords[(jj + ii) % nCoord])[0]);
642 y[ii] = ((*coords[(jj + ii) % nCoord])[1]);
643 z[ii] = ((*coords[(jj + ii) % nCoord])[2]);
645 SurfCentroidSelf_ddf(x, y, z, edgeLength, centroid[0], centroid[1], centroid[2], temp);
646 ind = (jj + 1) % nCoord;
649 for (ii1 = 0; ii1 < nDim; ii1++)
651 for (ii2 = 0; ii2 < nDim; ii2++)
653 for (ii = 0; ii < nFun; ii++)
655 hes[ind + (ii1 * nCoord)][ind + (ii2 * nCoord) + (ii * nDim * nCoord)] =
656 temp[ii1][ii2 + (nDim * ii)];
666 temp.assign(nDim * 2, 2 * nDim * nFun, 0);
667 for (jj = 0; jj < nCoord; jj++)
669 jj2 = (jj + 1) % nCoord;
670 for (ii = 0; ii < 4; ++ii)
672 x[ii] = ((*coords[(jj + ii) % nCoord])[0]);
673 y[ii] = ((*coords[(jj + ii) % nCoord])[1]);
674 z[ii] = ((*coords[(jj + ii) % nCoord])[2]);
676 SurfCentroidConnec_ddf(x, y, z, edgeLength, centroid[0], centroid[1], centroid[2], temp);
677 ind = (jj + 1) % nCoord;
678 ind2 = (jj2 + 1) % nCoord;
681 for (ii1 = 0; ii1 < nDim; ii1++)
683 for (ii2 = 0; ii2 < nDim; ii2++)
685 for (ii = 0; ii < nFun; ii++)
687 hes[ind + (ii1 * nCoord)][ind2 + (ii2 * nCoord) + (ii * nDim * nCoord)] =
688 temp[ii1][nDim + ii2 + (nDim * ii)];
689 hes[ind2 + (ii1 * nCoord)][ind + (ii2 * nCoord) + (ii * nDim * nCoord)] =
690 temp[ii1 + nDim][ii2 + (nDim * ii)];
700 temp.assign(nDim * 2, 2 * nDim * nFun, 0);
701 for (jj = 0; jj < nCoord; jj++)
703 for (jj2 = jj + 2; jj2 < nCoord; ++jj2)
705 for (ii = 0; ii < 3; ++ii)
707 x[ii] = ((*coords[(jj + ii) % nCoord])[0]);
708 y[ii] = ((*coords[(jj + ii) % nCoord])[1]);
709 z[ii] = ((*coords[(jj + ii) % nCoord])[2]);
712 for (ii = 0; ii < 3; ++ii)
714 x[ii + 4] = ((*coords[(jj2 + ii) % nCoord])[0]);
715 y[ii + 4] = ((*coords[(jj2 + ii) % nCoord])[1]);
716 z[ii + 4] = ((*coords[(jj2 + ii) % nCoord])[2]);
718 SurfCentroidNoConnec_ddf(x, y, z, edgeLength, centroid[0], centroid[1], centroid[2], temp);
719 ind = (jj + 1) % nCoord;
720 ind2 = (jj2 + 1) % nCoord;
723 for (ii1 = 0; ii1 < nDim; ii1++)
725 for (ii2 = 0; ii2 < nDim; ii2++)
727 for (ii = 0; ii < nFun; ii++)
729 hes[ind + (ii1 * nCoord)][ind2 + (ii2 * nCoord) + (ii * nDim * nCoord)] =
730 temp[ii1][nDim + ii2 + (nDim * ii)];
731 hes[ind2 + (ii1 * nCoord)][ind + (ii2 * nCoord) + (ii * nDim * nCoord)] =
732 temp[ii1 + nDim][ii2 + (nDim * ii)];
741 void SurfCentroid::Disp()
743 for (
int ii = 0; ii < nCoord; ii++)
745 cout <<
"c " << ii <<
" ";
746 DisplayVector(*coords[ii]);
749 cout <<
"edgeLength" << edgeLength << endl <<
"centroid ";
750 DisplayVector(centroid);
761 Volume2_f((*coords[0])[0], (*coords[0])[1], (*coords[0])[2], *coords[1], *coords[2], *coords[3], *coords[4],
762 *coords[5], *coords[6], fun);
763 Volume2_df((*coords[0])[0], (*coords[0])[1], (*coords[0])[2], *coords[1], *coords[2], *coords[3], *coords[4],
764 *coords[5], *coords[6], jac);
765 Volume2_ddf((*coords[0])[0], (*coords[0])[1], (*coords[0])[2], *coords[1], *coords[2], *coords[3], *coords[4],
766 *coords[5], *coords[6], hes);
772 rsvsmath_automatic_eps_edge = rsvsEpsilons.rsvsmath_automatic_eps_edge;
773 rsvsmath_automatic_eps_surf = rsvsEpsilons.rsvsmath_automatic_eps_surf;
774 rsvsmath_automatic_eps_volu = rsvsEpsilons.rsvsmath_automatic_eps_volu;
775 rsvsmath_automatic_eps_centre = rsvsEpsilons.rsvsmath_automatic_eps_centre;
776 rsvsmath_automatic_eps_centre2 = rsvsEpsilons.rsvsmath_automatic_eps_centre2;
Performs Volume and Area calculations for the RSVS process.
Provide std::vector container with hashed index mapping.
bool MakeValidField(std::vector< double > const *mp)
CoordFunc supports the same stuff as tri func but can have any number of points.
\TODO refactor mesh.hpp into mesh and coord headers to allow smaller includes
Class for control of rsvs epsilon.
std::vector< const std::vector< double > * > coordlist
Defines a list of coordinates.
Parameters for the integrated 3DRSVS.
Provides the error and warning system used by the RSVS3D project.
#define RSVS3D_ERROR_ARGUMENT(M)
Throw a invalid_argument.