void psi_refine_triquadratic(psi_rvec* pos, psi_rvec* vel, psi_real mass, psi_tet_buffer* tetbuf, psi_int lvl) { // TODO: these are different for the 48-tet connectivity! #if PSI_NDIM == 3 // all unique tet edges across the 3x3 unit cube. Order is first, midpoint, second. const static int edges3TQ[19][3] = { { 0 , 1 , 2 }, { 0 , 3 , 6 }, { 0 , 9 , 18 }, { 2 , 4 , 6 }, { 2 , 5 , 8 }, { 2 , 10 , 18 }, { 2 , 11 , 20 }, { 6 , 7 , 8 }, { 6 , 12 , 18 }, { 6 , 15 , 24 }, { 8 , 13 , 18 }, { 8 , 14 , 20 }, { 8 , 16 , 24 }, { 8 , 17 , 26 }, { 18 , 19 , 20 }, { 18 , 21 , 24 }, { 20 , 22 , 24 }, { 20 , 23 , 26 }, { 24 , 25 , 26 } }; const static int nedges3TQ = 19; #elif PSI_NDIM == 2 const static psi_int edges3TQ[5][3] = {{0,1,2}, {0,3,6}, {2,4,6}, {2,5,8}, {6,7,8}}; const static psi_int nedges3TQ = 5; #endif psi_rvec interppos[125]; psi_rvec interpvel[125]; psi_rvec childpos[27]; psi_rvec childvel[27]; psi_int e, i, j, k, ii, jj, kk; psi_real midpt_tet, midpt_quad, err2; // check to see if all of the tet edges are within tolerance if(lvl < tetbuf->max_lvl) for(e = 0; e < nedges3TQ; ++e) { err2 = 0.0; for(i = 0; i < PSI_NDIM; ++i) { midpt_tet = 0.5*(pos[edges3TQ[e][0]].xyz[i] + pos[edges3TQ[e][2]].xyz[i]); midpt_quad = pos[edges3TQ[e][1]].xyz[i]; err2 += (midpt_tet - midpt_quad)*(midpt_tet - midpt_quad); } // if this edge gives too large an error in position, stop and recurse if(err2 > tetbuf->ptol2) { // triquadratic interpolation psi_interp_triquadratic(pos, interppos); psi_interp_triquadratic(vel, interpvel); // TODO: option to use velocity #if PSI_NDIM == 3 // extract sub-cubes from interp for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) for(k = 0; k < 2; ++k) { for(ii = 0; ii < 3; ++ii) for(jj = 0; jj < 3; ++jj) for(kk = 0; kk < 3; ++kk) {// TODO: option to use velocity childpos[ind3(ii,jj,kk)] = interppos[ind5(ii+2*i,jj+2*j,kk+2*k)]; childvel[ind3(ii,jj,kk)] = interpvel[ind5(ii+2*i,jj+2*j,kk+2*k)]; } psi_refine_triquadratic(childpos, childvel, 0.125*mass, tetbuf, lvl+1); } #elif PSI_NDIM == 2 for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) { for(ii = 0; ii < 3; ++ii) for(jj = 0; jj < 3; ++jj) { childpos[ind3(ii,jj)] = interppos[ind5(ii+2*i,jj+2*j)]; childvel[ind3(ii,jj)] = interpvel[ind5(ii+2*i,jj+2*j)]; } psi_refine_triquadratic(childpos, childvel, 0.25*mass, tetbuf, lvl+1); } #endif return; } } // if we have passed the tolerance test, refine the ucube to the buffer psi_tets_from_3cube(pos, vel, mass, tetbuf); }
void psi_interp_triquadratic(psi_rvec* in, psi_rvec* out) { psi_int i, j, k, ax; for(ax = 0; ax < PSI_NDIM; ++ax) { #if PSI_NDIM == 3 for(i = 0; i < 3; ++i) for(j = 0; j < 3; ++j) for(k = 0; k < 3; ++k) out[ind5(2*i, 2*j, 2*k)].xyz[ax] = in[ind3(i, j, k)].xyz[ax]; for(j = 0; j < 5; j += 2) for(k = 0; k < 5; k += 2) { out[ind5(1, j, k)].xyz[ax] = 0.125*(3.0*out[ind5(0, j, k)].xyz[ax] + 6.0*out[ind5(2, j, k)].xyz[ax] - out[ind5(4, j, k)].xyz[ax]); out[ind5(3, j, k)].xyz[ax] = 0.125*(3.0*out[ind5(4, j, k)].xyz[ax] + 6.0*out[ind5(2, j, k)].xyz[ax] - out[ind5(0, j, k)].xyz[ax]); } for(i = 0; i < 5; i += 1) for(k = 0; k < 5; k += 2) { out[ind5(i, 1, k)].xyz[ax] = 0.125*(3.0*out[ind5(i, 0, k)].xyz[ax] + 6.0*out[ind5(i, 2, k)].xyz[ax] - out[ind5(i, 4, k)].xyz[ax]); out[ind5(i, 3, k)].xyz[ax] = 0.125*(3.0*out[ind5(i, 4, k)].xyz[ax] + 6.0*out[ind5(i, 2, k)].xyz[ax] - out[ind5(i, 0, k)].xyz[ax]); } for(i = 0; i < 5; i += 1) for(j = 0; j < 5; j += 1) { out[ind5(i, j, 1)].xyz[ax] = 0.125*(3.0*out[ind5(i, j, 0)].xyz[ax] + 6.0*out[ind5(i, j, 2)].xyz[ax] - out[ind5(i, j, 4)].xyz[ax]); out[ind5(i, j, 3)].xyz[ax] = 0.125*(3.0*out[ind5(i, j, 4)].xyz[ax] + 6.0*out[ind5(i, j, 2)].xyz[ax] - out[ind5(i, j, 0)].xyz[ax]); } #elif PSI_NDIM == 2 for(i = 0; i < 3; ++i) for(j = 0; j < 3; ++j) out[ind5(2*i, 2*j)].xyz[ax] = in[ind3(i, j)].xyz[ax]; for(j = 0; j < 5; j += 2) { out[ind5(1, j)].xyz[ax] = 0.125*(3.0*out[ind5(0, j)].xyz[ax] + 6.0*out[ind5(2, j)].xyz[ax] - out[ind5(4, j)].xyz[ax]); out[ind5(3, j)].xyz[ax] = 0.125*(3.0*out[ind5(4, j)].xyz[ax] + 6.0*out[ind5(2, j)].xyz[ax] - out[ind5(0, j)].xyz[ax]); } for(i = 0; i < 5; i += 1) { out[ind5(i, 1)].xyz[ax] = 0.125*(3.0*out[ind5(i, 0)].xyz[ax] + 6.0*out[ind5(i, 2)].xyz[ax] - out[ind5(i, 4)].xyz[ax]); out[ind5(i, 3)].xyz[ax] = 0.125*(3.0*out[ind5(i, 4)].xyz[ax] + 6.0*out[ind5(i, 2)].xyz[ax] - out[ind5(i, 0)].xyz[ax]); } #endif } }
int main(int argc, char * argv[]) { ProblemDefinitionsSPtr dummy_defs(new ProblemDefinitions(2,2,0,0)); PopulationSPtr myPop(new Population); IndividualSPtr ind1(new Individual(dummy_defs)); std::vector<double> dvs1 {1.0, 0.0}; ind1->setRealDVs(dvs1); ind1->setObjectives(std::vector<double>{1.0, 0.0}); myPop->push_back(ind1); IndividualSPtr ind2(new Individual(dummy_defs)); ind2->setRealDVs(std::vector<double>{0.7, 0.15}); ind2->setObjectives(std::vector<double>{0.49, 0.0225}); myPop->push_back(ind2); IndividualSPtr ind3(new Individual(dummy_defs)); ind3->setRealDVs(std::vector<double>{0.5, 0.26}); ind3->setObjectives(std::vector<double>{0.25, 0.0676}); myPop->push_back(ind3); IndividualSPtr ind4(new Individual(dummy_defs)); ind4->setRealDVs(std::vector<double>{0.44, 0.3}); ind4->setObjectives(std::vector<double>{0.1936, 0.09}); myPop->push_back(ind4); IndividualSPtr ind5(new Individual(dummy_defs)); ind5->setRealDVs(std::vector<double>{0.4, 0.37}); ind5->setObjectives(std::vector<double>{0.16, 0.1369}); myPop->push_back(ind5); IndividualSPtr ind6(new Individual(dummy_defs)); ind6->setRealDVs(std::vector<double>{0.2, 0.7}); ind6->setObjectives(std::vector<double>{0.04, 0.49}); myPop->push_back(ind6); IndividualSPtr ind7(new Individual(dummy_defs)); ind7->setRealDVs(std::vector<double>{0.0, 1.0}); ind7->setObjectives(std::vector<double>{0, 1}); myPop->push_back(ind7); IndividualSPtr ind1_(new Individual(dummy_defs)); ind1_->setRealDVs(std::vector<double> {1.0, 0.0}); ind1_->setObjectives(std::vector<double>{1.2, 0.2}); myPop->push_back(ind1_); IndividualSPtr ind2_(new Individual(dummy_defs)); ind2_->setRealDVs(std::vector<double>{0.7, 0.15}); ind2_->setObjectives(std::vector<double>{0.69, 0.2225}); myPop->push_back(ind2_); IndividualSPtr ind3_(new Individual(dummy_defs)); ind3_->setRealDVs(std::vector<double>{0.5, 0.26}); ind3_->setObjectives(std::vector<double>{0.45, 0.2676}); myPop->push_back(ind3_); IndividualSPtr ind4_(new Individual(dummy_defs)); ind4_->setRealDVs(std::vector<double>{0.44, 0.3}); ind4_->setObjectives(std::vector<double>{0.3936, 0.29}); myPop->push_back(ind4_); IndividualSPtr ind5_(new Individual(dummy_defs)); ind5_->setRealDVs(std::vector<double>{0.4, 0.37}); ind5_->setObjectives(std::vector<double>{0.36, 0.3369}); myPop->push_back(ind5_); IndividualSPtr ind6_(new Individual(dummy_defs)); ind6_->setRealDVs(std::vector<double>{0.2, 0.7}); ind6_->setObjectives(std::vector<double>{0.24, 0.69}); myPop->push_back(ind6_); IndividualSPtr ind7_(new Individual(dummy_defs)); ind7_->setRealDVs(std::vector<double>{0.0, 1.0}); ind7_->setObjectives(std::vector<double>{0.2, 1.2}); myPop->push_back(ind7_); std::vector< std::vector<std::pair<IndividualSPtr, double > > > values1 = DebsCrowdingDistance::calculate(myPop); FrontsSPtr values2 = myPop->getFronts(); // typedef std::pair<IndividualSPtr, double> IndDistPair; // FrontsSPtr values2(new Fronts(values1.size())); // boost::shared_ptr<std::vector<std::vector<IndividualSPtr> > > values2(new std::vector<std::vector<IndividualSPtr> >(values1.size())); // for (int i = 0; i < values2->size(); ++i) // { // BOOST_FOREACH(IndDistPair ind, values1[i]) // { // (*values2)[i].push_back(ind.first); // } // } #ifdef WITH_VTK PlotFrontVTK plot; plot(myPop); #endif }