bool NonlinearDriver::solutionNorms (const TimeDomain& time, double zero_tol, std::streamsize outPrec) { if (msgLevel < 0 || solution.empty()) return true; const size_t nsd = model.getNoSpaceDim(); size_t iMax[nsd]; double dMax[nsd]; double normL2 = model.solutionNorms(solution.front(),dMax,iMax); RealArray RF; bool haveReac = model.getCurrentReactions(RF,solution.front()); Vectors gNorm; if (calcEn) { model.setMode(SIM::RECOVERY); model.setQuadratureRule(opt.nGauss[1]); if (!model.solutionNorms(time,solution,gNorm)) gNorm.clear(); } if (myPid > 0) return true; std::streamsize stdPrec = outPrec > 0 ? IFEM::cout.precision(outPrec) : 0; double old_tol = utl::zero_print_tol; utl::zero_print_tol = zero_tol; IFEM::cout <<" Primary solution summary: L2-norm : " << utl::trunc(normL2); for (unsigned char d = 0; d < nsd; d++) if (utl::trunc(dMax[d]) != 0.0) IFEM::cout <<"\n Max "<< char('X'+d) <<"-displacement : "<< dMax[d] <<" node "<< iMax[d]; if (haveReac) { IFEM::cout <<"\n Total reaction forces: Sum(R) ="; for (size_t i = 1; i < RF.size(); i++) IFEM::cout <<" "<< utl::trunc(RF[i]); if (utl::trunc(RF.front()) != 0.0) IFEM::cout <<"\n displacement*reactions: (R,u) = "<< RF.front(); } if (!gNorm.empty()) this->printNorms(gNorm.front(),IFEM::cout); IFEM::cout << std::endl; utl::zero_print_tol = old_tol; if (stdPrec > 0) IFEM::cout.precision(stdPrec); return true; }
static boost::python::list get_identifiers(const Vectors& vec) { boost::python::list l; int nb_vec = vec.get_nb_vector(); for (int v = 0; v < nb_vec; v++) { l.append(vec.get_identifier(v)); } return l; }
// check static bool check(Vectors& v) { StatError error; bool ret = v.check(error); return ret; }
virtual bool assembleSystem(const TimeDomain& time, const Vectors& prevSol, bool newLHSmatrix, bool) { const double M = 10.0; // Mass of the oscillator const double K = 1000.0; // Stiffness of the oscillator const double F = 1.0; // External load (constant) myEqSys->initialize(newLHSmatrix); bool ok; if (myProblem->getMode() == SIM::MASS_ONLY) { ElmMats elm; elm.resize(1,1); elm.redim(1); elm.A[0].fill(M); // Mass Matrix ok = myEqSys->assemble(&elm,1); } else { const double* intPrm = static_cast<Problem*>(myProblem)->getIntPrm(); NewmarkMats elm(intPrm[0],intPrm[1],intPrm[2],intPrm[3]); elm.resize(3,1); elm.redim(1); elm.vec.resize(3); elm.setStepSize(time.dt,0); elm.A[1].fill(M); // Mass matrix elm.A[2].fill(K); // Stiffness matrix elm.b[0] = -K*prevSol.front(); // Elastic forces for (int i = 0; i < 3; i++) elm.vec[i] = prevSol[i]; ok = myEqSys->assemble(&elm,1); } // Add in the external load ok &= mySam->assembleSystem(*myEqSys->getVector(),&F,1); return ok && myEqSys->finalize(newLHSmatrix); }
virtual bool assembleSystem(const TimeDomain& time, const Vectors& prevSol, bool newLHSmatrix, bool) { const double M = 1.0; // Mass of the oscillator const double K = 1000.0; // Stiffness of the oscillator myEqSys->initialize(newLHSmatrix); bool ok; if (myProblem->getMode() == SIM::MASS_ONLY) { ElmMats elm; elm.resize(1,1); elm.redim(2); elm.A[0](1,1) = elm.A[0](2,2) = M; // Mass matrix ok = myEqSys->assemble(&elm,1); } else { const double* intPrm = static_cast<Problem*>(myProblem)->getIntPrm(); NewmarkMats elm(intPrm[0],intPrm[1],intPrm[2],intPrm[3]); elm.resize(3,1); elm.redim(2); elm.vec.resize(3); elm.setStepSize(time.dt,0); elm.A[1](1,1) = elm.A[1](2,2) = M; // Mass Matrix elm.A[2](1,1) = elm.A[2](2,2) = K; // Stiffness matrix elm.A[2](2,1) = elm.A[2](1,2) = -K; elm.b[0] = elm.A[2]*prevSol.front(); // Elastic forces elm.b[0] *= -1.0; for (int i = 0; i < 3; i++) elm.vec[i] = prevSol[i]; ok = myEqSys->assemble(&elm,1); } return ok && myEqSys->finalize(newLHSmatrix); }
GLdouble* NewVector(GLdouble x, GLdouble y) { GLdouble *vert = new GLdouble[3]; vert[0] = x; vert[1] = y; vert[2] = 0; vectors.push_back(vert); return vert; }
int main(){ Vectors<int>* newVector = new Vectors<int>(10,10,0); for (int i=0; i<10; ++i){ for (int j=0; j<10; ++j){ newVector->insert(i, j, 5); } } newVector->print(); for (int i=0; i<10; ++i){ for (int j=0; j<10; ++j){ newVector->remove(i, j); } } newVector->print(); delete newVector; return 0; }
double SIMLinElKL::externalEnergy (const Vectors& psol) const { double energy = this->SIMbase::externalEnergy(psol); // External energy from the nodal point loads for (size_t i = 0; i < myLoads.size(); i++) energy += myLoads[i].pload * psol.front()(myLoads[i].inod); return energy; }
TEST(Vectors, Insert) { Vectors<int>* newInt = new Vectors<int>(10, 10, 0); newInt->insert(4,5,5); EXPECT_EQ(5, newInt->access(4,5)); delete newInt; Vectors<std::string>* newString = new Vectors<std::string>(9, 18, "empty"); newString->insert(4,5,"hello"); EXPECT_EQ("hello", newString->access(4,5)); delete newString; Vectors<double>* newDouble = new Vectors<double>(6, 7, 0.0); newDouble->insert(4,5,5.5); EXPECT_EQ(5.5, newDouble->access(4,5)); delete newDouble; }
static bool select_step(Vectors &input, int variable, double step) { StatError error; bool ret; ret = input.select_step(error, variable, step); if (!ret) stat_tool::wrap_util::throw_error(error); return ret; }
static void file_ascii_data_write(const Vectors& d, const char* path, bool exhaustive) { bool result = true; StatError error; result = d.ascii_data_write(error, path, exhaustive); if (!result) stat_tool::wrap_util::throw_error(error); }
static std::string ascii_data_write(const Vectors& d, bool exhaustive) { std::stringstream s; std::string res; d.ascii_data_write(s, exhaustive); res = s.str(); return res; }
static string rank_correlation_computation(const Vectors& input, int icorrel_type, const string &filename) { StatError error; std::stringstream os; bool ret; correlation_type correl_type = correlation_type(icorrel_type); ret = input.rank_correlation_computation(error, os, correl_type, filename.c_str()); //std::cout << os.str()<<endl; return os.str(); }
double SIMKLShell::externalEnergy (const Vectors& u, const TimeDomain& time) const { double energy = this->SIMbase::externalEnergy(u,time); // External energy from the nodal point loads const int* madof = mySam->getMADOF(); for (const PointLoad& load : myLoads) if (load.ldof.second > 0) { int idof = madof[load.ldof.first-1] + load.ldof.second-1; energy += (*load.p)(time.t) * u.front()(idof); } else if (load.ldof.second < 0) // This is an element point load { Vector v = this->SIMgeneric::getSolution(u.front(),load.xi,0,load.patch); if (-load.ldof.second <= (int)v.size()) energy += (*load.p)(time.t) * v(-load.ldof.second); } return energy; }
TEST(Vectors, Print) { Vectors<std::string>* newVector = new Vectors<std::string>(15,15,"oo"); newVector->insert(1,2,"xx"); newVector->insert(9,8,"xx"); newVector->insert(7,2,"xx"); newVector->insert(6,4,"xx"); newVector->insert(0,8,"xx"); newVector->insert(10,12,"xx"); newVector->insert(3,5,"xx"); newVector->print(); delete newVector; }
static string contingency_table(const Vectors& v, int variable1, int variable2, const string& filename, int iformat) { StatError error; std::stringstream s; bool ret; output_format format = output_format(iformat); ret = v.contingency_table(error, s, variable1, variable2, filename.c_str(), format); if (!ret) stat_tool::wrap_util::throw_error(error); return s.str(); }
static string variance_analysis(const Vectors& v, int class_variable, int response_variable, int response_type, const string& filename, int iformat) { StatError error; std::stringstream s; bool ret; output_format format = output_format(iformat); ret = v.variance_analysis(error, s, class_variable, response_variable, response_type, filename.c_str(), format); if (!ret) stat_tool::wrap_util::throw_error(error); return s.str(); }
bool ASMunstruct::refine (const LR::RefineData& prm, Vectors& sol, const char* fName) { PROFILE2("ASMunstruct::refine()"); if (!geo) return false; else if (shareFE && !prm.refShare) { nnod = geo->nBasisFunctions(); return true; } // to pick up if LR splines get stuck while doing refinement, // print entry and exit point of this function double beta = prm.options.size() > 0 ? prm.options[0]/100.0 : 0.10; int multiplicity = prm.options.size() > 1 ? prm.options[1] : 1; if (multiplicity > 1) for (int d = 0; d < geo->nVariate(); d++) { int p = geo->order(d) - 1; if (multiplicity > p) multiplicity = p; } enum refinementStrategy strat = LR_FULLSPAN; if (prm.options.size() > 2) switch (prm.options[2]) { case 1: strat = LR_MINSPAN; break; case 2: strat = LR_STRUCTURED_MESH; break; } bool linIndepTest = prm.options.size() > 3 ? prm.options[3] != 0 : false; int maxTjoints = prm.options.size() > 4 ? prm.options[4] : -1; int maxAspectRatio = prm.options.size() > 5 ? prm.options[5] : -1; bool closeGaps = prm.options.size() > 6 ? prm.options[6] != 0 : false; char doRefine = 0; if (!prm.errors.empty()) doRefine = 'E'; // Refine based on error indicators else if (!prm.elements.empty()) doRefine = 'I'; // Refine the specified elements if (doRefine) { std::vector<int> nf(sol.size()); for (size_t j = 0; j < sol.size(); j++) if (!(nf[j] = LR::extendControlPoints(geo,sol[j],this->getNoFields(1)))) return false; // set refinement parameters if (maxTjoints > 0) geo->setMaxTjoints(maxTjoints); if (maxAspectRatio > 0) geo->setMaxAspectRatio((double)maxAspectRatio); geo->setCloseGaps(closeGaps); geo->setRefMultiplicity(multiplicity); geo->setRefStrat(strat); // do actual refinement if (doRefine == 'E') geo->refineByDimensionIncrease(prm.errors,beta); else if (strat == LR_STRUCTURED_MESH) geo->refineBasisFunction(prm.elements); else geo->refineElement(prm.elements); geo->generateIDs(); nnod = geo->nBasisFunctions(); for (int i = sol.size()-1; i >= 0; i--) { sol[i].resize(nf[i]*geo->nBasisFunctions()); LR::contractControlPoints(geo,sol[i],nf[i]); } } if (fName) { char fullFileName[256]; strcpy(fullFileName, "lrspline_"); strcat(fullFileName, fName); std::ofstream lrOut(fullFileName); lrOut << *geo; lrOut.close(); LR::LRSplineSurface* lr = dynamic_cast<LR::LRSplineSurface*>(geo); if (lr) { // open files for writing strcpy(fullFileName, "param_"); strcat(fullFileName, fName); std::ofstream paramMeshFile(fullFileName); strcpy(fullFileName, "physical_"); strcat(fullFileName, fName); std::ofstream physicalMeshFile(fullFileName); strcpy(fullFileName, "param_dot_"); strcat(fullFileName, fName); std::ofstream paramDotMeshFile(fullFileName); strcpy(fullFileName, "physical_dot_"); strcat(fullFileName, fName); std::ofstream physicalDotMeshFile(fullFileName); lr->writePostscriptMesh(paramMeshFile); lr->writePostscriptElements(physicalMeshFile); lr->writePostscriptFunctionSpace(paramDotMeshFile); lr->writePostscriptMeshWithControlPoints(physicalDotMeshFile); // close all files paramMeshFile.close(); physicalMeshFile.close(); paramDotMeshFile.close(); physicalDotMeshFile.close(); } } if (doRefine) std::cout <<"Refined mesh: "<< geo->nElements() <<" elements " << geo->nBasisFunctions() <<" nodes."<< std::endl; if (linIndepTest) { std::cout <<"Testing for linear independence by overloading "<< std::endl; bool isLinIndep = geo->isLinearIndepByOverloading(false); if (!isLinIndep) { std::cout <<"Inconclusive..."<< std::endl; #ifdef HAS_BOOST std::cout <<"Testing for linear independence by full tensor expansion "<< std::endl; isLinIndep = geo->isLinearIndepByMappingMatrix(false); #endif } if (isLinIndep) std::cout <<"...Passed."<< std::endl; else { std::cout <<"FAILED!!!"<< std::endl; exit(228); } } return true; }
TEST(Vectors, GetNumCols) { Vectors<int>* newVector = new Vectors<int>(7,8,0); EXPECT_EQ(7, newVector->getNumCols()); delete newVector; }
TEST(Vectors, Access) { Vectors<std::string>* newVector = new Vectors<std::string>(20,20,"null"); EXPECT_EQ("null", newVector->access(10,10)); newVector->insert(15,17,"howdy"); EXPECT_EQ("howdy", newVector->access(15,17)); delete newVector; Vectors<int>* newInt = new Vectors<int>(20,21,0); EXPECT_EQ(0, newInt->access(10,10)); newInt->insert(15,17,90); EXPECT_EQ(90, newInt->access(15,17)); delete newInt; Vectors<double>* newDouble = new Vectors<double>(21,20,0.0); EXPECT_EQ(0.0, newDouble->access(10,10)); newDouble->insert(15,17,4.5); EXPECT_EQ(4.5, newDouble->access(15,17)); delete newDouble; }
TEST(Vectors, Remove) { Vectors<int>* newVector = new Vectors<int>(5,5,0); newVector->insert(2,3,4); newVector->remove(2,3); EXPECT_EQ(0, newVector->access(2,3)); delete newVector; Vectors<double>* newDouble = new Vectors<double>(5,5,0.0); newDouble->insert(2,3,4.4); newDouble->remove(2,3); EXPECT_EQ(0.0, newDouble->access(2,3)); delete newDouble; Vectors<std::string>* newString = new Vectors<std::string>(5,5,"empty"); newString->insert(2,3,"yes"); newString->remove(2,3); EXPECT_EQ("empty", newString->access(2,3)); delete newString; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { Distance_Mode DISTANCE_FCN = EUCLIDEAN; VectorClassNames VECTOR_CLASS; #ifdef DOUBLE char mxIsClassName[] = "double"; #else char mxIsClassName [] = "single"; #endif /* Check for proper number of arguments. */ if (nrhs != 2) { mexErrMsgTxt("Two inputs required."); } int nfields = mxGetNumberOfFields(prhs[0]); if(nfields<5) { mexErrMsgTxt("First input must have at least 5 fields."); } // Get theta const mxArray* tmp=mxGetField(prhs[0],0,fnames_in[0]); if(!mxIsClass(tmp,mxIsClassName)) { mexErrMsgTxt("input.theta must be double\n"); } REAL* ptheta=(REAL*)mxGetData(tmp); theta=*ptheta; bool val=(theta>0.0)&&(theta<1.0); if(!val) { mexErrMsgTxt("Bad theta\n"); } mu=1.0/(1.0-theta); // Get outparams tmp=mxGetField(prhs[0],0,fnames_in[1]); if(!mxIsClass(tmp,"int32")) { mexErrMsgTxt("input.numlevels must be int32\n"); } int* pnumlevels=(int*)mxGetData(tmp); int numlevels=(int)*pnumlevels; // Get minlevel tmp=mxGetField(prhs[0],0,fnames_in[2]); if(!mxIsClass(tmp,"int32")) { mexErrMsgTxt("input.minlevel must be int32\n"); } int* pminlevel=(int*)mxGetData(tmp); int minlevel=(int)*pminlevel; // Get NTHREADS tmp=mxGetField(prhs[0],0,fnames_in[3]); if(!mxIsClass(tmp,"int32")) { mexErrMsgTxt("input.NTHREADS must be int32\n"); } int* pNTHREADS=(int*)mxGetData(tmp); int NTHREADS=(int)*pNTHREADS; // Get BLOCKSIZE tmp=mxGetField(prhs[0],0,fnames_in[4]); if(!mxIsClass(tmp,"int32")) { mexErrMsgTxt("input.BLOCKSIZE must be int32\n"); } int* pBLOCKSIZE=(int*)mxGetData(tmp); int BLOCKSIZE=(int)*pBLOCKSIZE; // Get distancefcn tmp=mxGetField(prhs[0],0,fnames_in[5]); if(tmp==NULL) { DISTANCE_FCN = EUCLIDEAN; } else { if(!mxIsClass(tmp,"int32")) { mexErrMsgTxt("input.distancefcn must be int32\n"); } else { int *pDISTANCE_FCN = (int*)mxGetData(tmp); DISTANCE_FCN = (Distance_Mode)(*pDISTANCE_FCN); } } // Get classname tmp=mxGetField(prhs[0],0,fnames_in[6]); if(tmp==NULL) { DISTANCE_FCN = EUCLIDEAN; } else { if(!mxIsClass(tmp,"int32")) { mexErrMsgTxt("input.classname must be int32\n"); } else { int *pVECTOR_CLASS = (int*)mxGetData(tmp); VECTOR_CLASS = (VectorClassNames)(*pVECTOR_CLASS); } } //mexPrintf("DISTANCE_FCN=%d\n",DISTANCE_FCN); /* Get dimensions of second field of input */ tmp=prhs[1]; mwSize ndims_in=mxGetNumberOfDimensions(tmp); const mwSize* dims_in=mxGetDimensions(tmp); if(!mxIsClass(tmp,mxIsClassName)) { mexErrMsgTxt("Second input must be double\n"); } // mexPrintf("ndims_in=%d\n",ndims_in); int N=dims_in[ndims_in-1]; dim=1; for(int i=0;i<ndims_in-1;i++) { dim*=dims_in[i]; } // mexPrintf("dim=%d N=%d\n",dim,N); // Create Vectors REAL* X=(REAL*)mxGetData(tmp); Vectors *vectors; switch (VECTOR_CLASS) { case VECTORS: vectors = new Vectors(X,N,dim,DISTANCE_FCN); break; default: mexErrMsgTxt("\n Invalid classname for Vectors."); break; } if( N==1 ) { NTHREADS = 0; } ThreadsWithCounter threads(NTHREADS); // Construct covertree SegList<DLPtrListNode<CoverNode> > seglist(1024); const Vector* vector=(vectors->next()); Cover cover(vector,seglist,numlevels,minlevel); EnlargeData enlargedata(&threads,BLOCKSIZE,vectors->getRemaining()); // Timer timer; // timer.on(); cover.enlargeBy(enlargedata,*vectors); // timer.off(); // timer.printOn(cout); /* Create matrix for the return argument. */ plhs[0] = mxCreateStructMatrix(1, 1, 5, fnames_out); mxArray* fout; dims[0]=1; dims[1]=1; #ifdef DOUBLE fout =mxCreateNumericArray(ndims,dims,mxDOUBLE_CLASS,mxREAL); #else fout =mxCreateNumericArray(ndims,dims,mxSINGLE_CLASS,mxREAL); #endif REAL* p=(REAL*)mxGetData(fout); mxSetField(plhs[0],0,fnames_out[0],fout); p[0]=ptheta[0]; dims[0]=1; dims[1]=9; fout = mxCreateNumericArray(ndims,dims,mxINT32_CLASS,mxREAL); int* outparams=(int*)mxGetData(fout); mxSetField(plhs[0],0,fnames_out[1], fout); outparams[0]=vectors->getIndex(cover.getRoot()->getPoint()); outparams[1]=cover.getMinLevel(); outparams[2]=cover.getNumLevels(); outparams[3]=cover.getCount(); outparams[4]=cover.getNumberInserted(); outparams[5]=cover.getNumberDeep(); outparams[6]=cover.getNumberDuplicates(); outparams[7]=DISTANCE_FCN; outparams[8]=VECTOR_CLASS; dims[0]=1; dims[1]=numlevels; #ifdef DOUBLE fout=mxCreateNumericArray(ndims,dims,mxDOUBLE_CLASS,mxREAL); #else fout=mxCreateNumericArray(ndims,dims,mxSINGLE_CLASS,mxREAL); #endif REAL* pradii=(REAL*)mxGetData(fout); pradii[0]=cover.getMaxRadius(); for(int i=1;i<numlevels;i++) { pradii[i]=ptheta[0]*pradii[i-1]; } mxSetField(plhs[0],0,fnames_out[2], fout); dims[0]=N; dims[1]=5; fout =mxCreateNumericArray(ndims,dims,mxINT32_CLASS,mxREAL); int* base=(int*)mxGetData(fout); CoverIndices coverindices(&cover,vectors,base); mxSetField(plhs[0],0,fnames_out[3], fout); dims[0]=1; dims[1]=2; fout =mxCreateNumericArray(ndims,dims,mxINT64_CLASS,mxREAL); long int* pncalls=(long int*)mxGetData(fout); mxSetField(plhs[0],0,fnames_out[4], fout); pncalls[0]=enlargedata.getMergeNCallsToGetDist(); pncalls[1]=enlargedata.getThreadNCallsToGetDist(); // Clean up delete vectors; }
int main(void) { int var, i, j, nb_variable, nb_component; const int nb_vector = 500; double *pweight = NULL; bool *fparam = NULL; int* perm; StatError error; const char * mixpath= "./tmp.mix", * spmixpath= "./tmp_sp.mix"; const char * gnupath = "./tmp_mix", * gnu_datapath = "./tmp_mix_data"; const char * margpath= "./marg_mix", * gnu_tmppath = "./tmp_mix_d"; const char * np_modelpath= "./np_model.mix", * gnu_tmpnppath = "./tmp_mix_d"; const char * entropy_data= "cluster_vectors.vec"; const char * output_path = "tmp_entropy_output.vec"; Distribution *marginal = NULL; DiscreteDistributionData *marginal_histo = NULL; Vectors *vec = NULL; MultivariateMixture *mv1 = NULL, *mv_cp = NULL; MultivariateMixture *mv_np1 = NULL, *mv_np_estim = NULL; MultivariateMixture *mv_estim = NULL; MultivariateMixtureData *mv_data = NULL, *cluster = NULL; DiscreteParametric **dt1 = NULL, **dt2 = NULL; DiscreteParametricProcess **ppcomponent = NULL; // constructors of Mv_Mixture mv1 = new MultivariateMixture(); // destructor of MultivariateMixture delete mv1; mv1= NULL; nb_variable = 2; nb_component = 3; dt1 = new DiscreteParametric*[nb_component]; dt2 = new DiscreteParametric*[nb_component]; pweight = new double[nb_component]; ppcomponent = new DiscreteParametricProcess*[nb_variable]; pweight[0] = 0.1; pweight[1] = 0.2; pweight[2] = 0.7; dt1[0] = new DiscreteParametric(0, BINOMIAL, 2, 12, D_DEFAULT, 0.1); dt1[1] = new DiscreteParametric(0, BINOMIAL, 0, 10, D_DEFAULT, 0.5); dt1[2] = new DiscreteParametric(0, BINOMIAL, 3, 10, D_DEFAULT, 0.8); dt2[0] = new DiscreteParametric(0, POISSON, 2, I_DEFAULT, 8.0, D_DEFAULT); dt2[1] = new DiscreteParametric(0, POISSON, 4, I_DEFAULT, 5.0, D_DEFAULT); dt2[2] = new DiscreteParametric(0, POISSON, 0, I_DEFAULT, 2.0, D_DEFAULT); cout << "Observation distributions for variable 1:" << endl; for (i = 0; i < nb_component; i++) { dt1[i]-> ascii_print(cout); } ppcomponent[0] = new DiscreteParametricProcess(nb_component, dt1); ppcomponent[1] = new DiscreteParametricProcess(nb_component, dt2); for (i = 0; i < nb_component; i++) { delete dt1[i]; dt1[i] = NULL; delete dt2[i]; dt2[i] = NULL; } cout << endl; mv1 = new MultivariateMixture(nb_component, pweight, nb_variable, ppcomponent, NULL); cout << "Mixture of " << nb_component << " components with " << nb_variable << " variables:" << endl; mv1->ascii_write(cout, true); cout << endl; // copy mv_cp = new MultivariateMixture(*mv1); cout << "Copy constructor of MultivariateMixture: " << endl; mv_cp->ascii_write(cout); cout << endl; // destructor of MultivariateMixture delete mv_cp; mv_cp= NULL; delete mv1; mv1= NULL; cout << "MultivariateMixture_building (print into file " << mixpath << "): " << endl; mv1 = multivariate_mixture_building(error , nb_component , nb_variable, pweight, ppcomponent, NULL); if (mv1 == NULL) cout << error; else { mv1->ascii_write(error, mixpath, true); delete mv1; mv1= NULL; } cout << endl; cout << "Read MultivariateMixture from file " << mixpath << ": " << endl; mv1 = multivariate_mixture_ascii_read(error , mixpath); if (mv1 == NULL) { cout << error; return 1; } else { mv1->ascii_write(cout, true); } cout << endl; mv_data = mv1->simulation(error, nb_vector); if (mv_data == NULL) { cout << error; return 1; } else { mv_data->ascii_write(cout, true); } cout << endl; cout << "Gnuplot output for MultivariateMixture ('" << gnupath << "' file)" << endl; mv1->plot_write(error, gnupath, ""); cout << error << endl; cout << "Gnuplot output for MultivariateMixture_data ('" << gnu_datapath << "' file)" << endl; mv_data->plot_write(error, gnu_datapath, ""); cout << error << endl; cout << "Extract marginal distribution for variable 1" << endl; marginal = mv1->extract_distribution(error, 1); marginal_histo = mv_data->extract_marginal(error, 1); if (marginal != NULL) { marginal->ascii_print(cout, false, false, false); delete marginal; } else cout << error; if (marginal_histo != NULL) { cout << "Gnuplot output for marginal ('" << margpath << "' file)" << endl; marginal_histo->plot_write(error, margpath); delete marginal_histo; } else cout << error; cout << "Estimate MultivariateMixture from initial model: " << endl; mv_estim = mv_data->mixture_estimation(error, cout, *mv1); if (mv_estim == NULL) { cout << error; } else { mv_estim->ascii_write(cout, true); mv_estim->plot_write(error, gnu_tmppath, ""); mv_estim->spreadsheet_write(error, spmixpath); cout << error << endl; delete mv_estim; mv_estim = NULL; } cout << endl; fparam = new bool[2]; fparam[0] = true; fparam[1] = false; cout << "Estimate MultivariateMixture from initial nb_component: " << endl; mv_estim = mv_data->mixture_estimation(error, cout, 3, I_DEFAULT, fparam); delete [] fparam; if (mv_estim == NULL) { cout << error; } else { mv_estim->ascii_write(cout, true); mv_estim->plot_write(error, gnu_tmppath, ""); delete mv_estim; mv_estim = NULL; } cout << endl; delete mv1; mv1= NULL; delete mv_data; mv_data = NULL; for (var = 0; var < nb_variable; var++) { delete ppcomponent[var]; ppcomponent[var] = NULL; } cout << "Read non parametric model: " << endl; mv_np1 = multivariate_mixture_ascii_read(error, np_modelpath); if (mv_np1 == NULL) { cout << error; return 1; } else { cout << "Value: " << endl; mv_np1->ascii_write(cout, false); mv_np1->spreadsheet_write(error, spmixpath); cout << error << endl; } // permutation of the states perm = new int[mv_np1->get_nb_component()]; for(j= 0; j < mv_np1->get_nb_component(); j++) perm[mv_np1->get_nb_component()-j -1]=j; mv_np1->state_permutation(error, perm); cout << error; cout << "Permutation of the states: " << endl; mv_np1->ascii_write(cout, false); delete [] perm; perm = NULL; cout << endl; mv_data = mv_np1->simulation(error, nb_vector); if (mv_data == NULL) { cout << error; return 1; } cout << "Extract marginal distribution for variable 2" << endl; marginal = mv_np1->extract_distribution(error, 2); if (marginal != NULL) { marginal->ascii_print(cout, false, false, false); delete marginal; } else cout << error; cout << "Gnuplot output for MultivariateMixture_data ('" << gnu_tmpnppath << "' file)" << endl; mv_data->plot_write(error, gnu_tmpnppath, ""); cout << error << endl; cout << "Estimate MultivariateMixture from initial nb_component: " << endl; mv_estim = mv_data->mixture_estimation(error, cout, 3); if (mv_estim == NULL) { cout << error; return 1; } else { mv_estim->ascii_write(cout, true); mv_estim->plot_write(error, gnu_tmpnppath, ""); } // permutation of the states perm = new int[mv_estim->get_nb_component()]; for(j= 0; j < mv_estim->get_nb_component(); j++) perm[mv_estim->get_nb_component()-j -1]=j; mv_estim->state_permutation(error, perm); cout << error; cout << "Permutation of the states: " << endl; mv_estim->ascii_write(cout, false); delete [] perm; perm = NULL; cout << endl; cout << "Cluster individuals: " << endl; cluster = mv_estim->cluster(error, *mv_data); if (cluster == NULL) { cout << error; } else { cout << "Estimated states: " << endl; for (i = 0; i < 10; i++) cout << cluster->get_int_vector(i, 0) << "\t"; cout << "..." << endl; delete cluster; cluster = NULL; } cout << "State entropy: " << endl; cluster = mv_estim->cluster(error, *mv_data, VITERBI, true); if (cluster == NULL) { cout << error; } else { cout << "State entropies: " << endl; for (i = 0; i < 10; i++) cout << cluster->get_real_vector(i, 3) << "\t"; cout << "..." << endl; delete mv_estim; mv_estim = NULL; delete cluster; cluster = NULL; } // compute state entropies on data cout << "Compute state entropies on data" << endl; vec = vectors_ascii_read(error, entropy_data); if (vec == NULL) { cout << error; return 1; } mv_estim = vec->mixture_estimation(error, cout, 3, 300); if (mv_estim == NULL) { cout << error; return 1; } else mv_estim->ascii_write(cout, true); cluster = mv_estim->cluster(error, *vec, VITERBI, true); if (cluster == NULL) { cout << error; } else { cluster->ascii_write(error, output_path); } delete mv_estim; delete cluster; delete vec; delete mv_data; delete mv_np1; delete [] dt1; delete [] dt2; delete [] pweight; delete [] ppcomponent; return 0; }
void __stdcall ClearVectors() { for (Vectors::size_type i = 0; i < vectors.size(); ++i) delete[] vectors[i]; vectors.clear(); }
static void plot_write(const Vectors &input, const std::string& prefix, const std::string& title) { StatError error; input.plot_write(error, prefix.c_str(), title.c_str()); }
bool Elasticity::evalSol (Vector& s, const Vectors& eV, const FiniteElement& fe, const Vec3& X, bool toLocal, Vec3* pdir) const { if (eV.empty()) { std::cerr <<" *** Elasticity::evalSol: No solutions vector."<< std::endl; return false; } else if (!eV.front().empty() && eV.front().size() != fe.dNdX.rows()*nsd) { std::cerr <<" *** Elasticity::evalSol: Invalid displacement vector." <<"\n size(eV) = "<< eV.front().size() <<" size(dNdX) = " << fe.dNdX.rows() <<","<< fe.dNdX.cols() << std::endl; return false; } // Evaluate the deformation gradient, dUdX, and/or the strain tensor, eps Matrix Bmat; Tensor dUdX(nDF); SymmTensor eps(nsd,axiSymmetry); if (!this->kinematics(eV.front(),fe.N,fe.dNdX,X.x,Bmat,dUdX,eps)) return false; // Add strains due to temperature expansion, if any double epsT = this->getThermalStrain(eV.back(),fe.N,X); if (epsT != 0.0) eps -= epsT; // Calculate the stress tensor through the constitutive relation Matrix Cmat; SymmTensor sigma(nsd, axiSymmetry || material->isPlaneStrain()); double U; if (!material->evaluate(Cmat,sigma,U,fe,X,dUdX,eps)) return false; else if (epsT != 0.0 && nsd == 2 && material->isPlaneStrain()) sigma(3,3) -= material->getStiffness(X)*epsT; Vec3 p; bool havePval = false; if (toLocal && wantPrincipalStress) { // Calculate principal stresses and associated direction vectors if (sigma.size() == 4) { SymmTensor tmp(2); tmp = sigma; // discard the sigma_zz component havePval = pdir ? tmp.principal(p,pdir,2) : tmp.principal(p); } else havePval = pdir ? sigma.principal(p,pdir,2) : sigma.principal(p); // Congruence transformation to local coordinate system at current point if (locSys) sigma.transform(locSys->getTmat(X)); } s = sigma; if (toLocal) s.push_back(sigma.vonMises()); if (havePval) { s.push_back(p.x); s.push_back(p.y); if (sigma.dim() == 3) s.push_back(p.z); } return true; }
void ElasticityNorm::addBoundaryTerms (Vectors& gNorm, double energy) const { gNorm.front()(2) += energy; }
int main() { cout << "---------------------------Matrix 3--------------------------------" << endl; Matrix3 TranslationXY; TranslationXY = Mat3.m_TranslationXY(2, 2); cout << TranslationXY; cout << endl; cout << "--------------------------MATRIX 4 --------------------------------" << endl; Matrix4 RotationX; RotationX = Mat4.m_RotationX(3); cout << RotationX; cout << endl; Matrix4 RotationY; RotationY = Mat4.m_RotationY(2); cout << RotationY; cout << endl; Matrix4 RotationZ; RotationZ = Mat4.m_RotationZ(2); cout << RotationZ; cout << endl; Matrix4 TranslationXYZ; TranslationXYZ = Mat4.m_TranslationXYZ(2, 2, 2); cout << TranslationXYZ; cout << endl; Matrix4 mat; mat = Mat4.m_OrthoProjection(2,2,2,2,2,2); cout << mat; cout << endl; Matrix4 Identity; mat = Mat4.m_CreateIdentity(); cout << Identity; cout <<endl; cout << "---------------------------COMMON MATH--------------------------------" << endl; cout << ComMath.Pow2(2, 2)<< endl; cout << ComMath.m_RadianConvert(360)<< endl; cout << ComMath.m_degreeConvert(6) << endl; Vect3.x = 2; Vect3.y = 2; Vect3.z =2; Vect33.x = 4; Vect33.y = 4; Vect33.z = 4; cout << ComMath.m_Lerp(Vect3, Vect33, 2) << endl; cout << "---------------------------VECTOR 3--------------------------------" << endl; Vect3.x = 2; Vect3.y =2; Vect3.z =2; cout << Vect3.Magnitude()<<endl; Vect3.x = 2; Vect3.y =2; Vect3.z =2; cout << Vect33.Normalise(Vect3)<<endl; Vect3.x = 2; Vect3.y =2; Vect3.z = 2; cout << Vect33.GetNormal(Vect3) << endl; Vect3.x = 2; Vect3.y = 2; Vect3.z =2; cout <<Vect33.DotProduct(Vect3) << endl; Vect3.x = 4; Vect3.y = 4; Vect3.z = 4; Vect33.x =4; Vect33.y = 4; Vect3.z = 4; cout << Vect3.EulerAngle(Vect3, Vect33)<<endl; Vect3.x = 2; Vect3.y = 2; Vect3.z = 2; Vect33.x = 2; Vect33.y =2; Vect33.z = 2; cout << Vect3.CrossProduct(Vect3, Vect33)<<endl; Matrix3 Transform; Transform = Mat3; Vect3.x =2; Vect3.y = 2; Vect3.z = 2; cout << Vect3.m_TransformVector3(Mat3)<<endl; Matrix3 tempM; tempM = Mat3; Vect3.x = 2; Vect3.y = 2; Vect3.z = 2; cout << Vect3.Scale(Mat3); cout << endl; cout << "---------------------------VECTOR 4--------------------------------" << endl; Vect4.x = 2; Vect4.y =2; Vect4.z =2; Vect4.w = 2; cout << Vect4.m_Magnitude()<<endl; Vect4.x = 2; Vect4.y =2; Vect4.z =2; Vect4.w = 2; cout << Vect4.m_GetNormal(Vect4)<<endl; Vect4.x = 2; Vect4.y =2; Vect4.z =2; Vect4.w = 2; cout << Vect4.m_Normalise(Vect4) <<endl; Vect4.x = 2; Vect4.y =2; Vect4.z =2; Vect4.w = 2; cout << Vect4.m_DotProduct(Vect4) << endl; cout << Vect4.m_RGBconverter(0xFFFFFFFF)<<endl; Matrix4 Transform2; Transform2 = Mat4; Vect4.x = 2; Vect4.y =2; Vect4.z =2; Vect4.w = 2; cout << Vect4.m_TransformPoint(Mat4) << endl; Matrix4 Transform3; Transform3 = Mat4; Vect4.x = 2; Vect4.y =2; Vect4.z =2; Vect4.w = 2; cout << Vect4.m_TransformVector4(Vect4, Mat4); cout << endl; Matrix4 mat4; mat4 = Mat4; Vect4.x = 2; Vect4.y = 2; Vect4.z = 2; Vect4.w = 2; cout << Vect4.Scale(Mat4); cout << endl; cout << "---------------------------VECTOR 2--------------------------------" << endl; Vectors Point; Point.x = 2; Point.y =2; cout << V2.pointSubtract(Point, 2) << endl; Vectors Point2; Point2.x = 2; Point2.y =2; cout << V2.pointAdd(Point2, 2)<<endl; Vectors Point3; Point3.x = 2; Point3.y =2; cout << V2.multiplyScalar(Point3, 2) << endl; Vectors Point4; Point4.x = 2; Point4.y =2; cout << V2.getMagnitude(Point4)<<endl; Vectors Point5; Point5.x = 2; Point5.y =2; cout<<V2.getNormal(Point5)<<endl; getchar(); return 0; }