bool SparseOptimizerIncremental::initSolver(int dimension, int batchEveryN)
 {
   //cerr << __PRETTY_FUNCTION__ << endl;
   slamDimension = dimension;
   if (dimension == 3) {
     setAlgorithm(createSolver("fix3_2_cholmod"));
     OptimizationAlgorithmGaussNewton* gaussNewton = dynamic_cast<OptimizationAlgorithmGaussNewton*>(solver());
     assert(gaussNewton);
     BlockSolver<BlockSolverTraits<3, 2> >* bs = dynamic_cast<BlockSolver<BlockSolverTraits<3, 2> >*>(gaussNewton->solver());
     assert(bs && "Unable to get internal block solver");
     LinearSolverCholmodOnline<Matrix3d>* s = dynamic_cast<LinearSolverCholmodOnline<Matrix3d>*>(bs->linearSolver());
     bs->setAdditionalVectorSpace(300);
     bs->setSchur(false);
     _solverInterface = s;
     _underlyingSolver = bs;
   } else {
     setAlgorithm(createSolver("fix6_3_cholmod"));
     OptimizationAlgorithmGaussNewton* gaussNewton = dynamic_cast<OptimizationAlgorithmGaussNewton*>(solver());
     assert(gaussNewton);
     BlockSolver<BlockSolverTraits<6, 3> >* bs = dynamic_cast<BlockSolver<BlockSolverTraits<6, 3> >*>(gaussNewton->solver());
     assert(bs && "Unable to get internal block solver");
     LinearSolverCholmodOnline<Matrix<double, 6, 6> >* s = dynamic_cast<LinearSolverCholmodOnline<Matrix<double, 6, 6> >*>(bs->linearSolver());
     bs->setAdditionalVectorSpace(600);
     bs->setSchur(false);
     _solverInterface = s;
     _underlyingSolver = bs;
   }
   _solverInterface->cmember = &_cmember;
   _solverInterface->batchEveryN = batchEveryN;
   if (! solver()) {
     cerr << "Error allocating solver. Allocating CHOLMOD solver failed!" << endl;
     return false;
   }
   return true;
 }
예제 #2
0
void sLinsysRoot::sync()
{
  //delete children
  deleteChildren();
  //assert(false);

  //delete local stuff
  if( nxupp + nxlow > 0 ) {
    delete dd; 
    delete dq; 
  }
  delete nomegaInv;
  delete rhs;
  if (solver) delete solver;
  if (kkt)    delete kkt;


  //allocate
//  if( nxupp + nxlow > 0 ) {
    //dd      = OoqpVectorHandle(stochNode->newPrimalVector());
    //dq      = OoqpVectorHandle(stochNode->newPrimalVector());
    dd = stochNode->newPrimalVector();
    dq = stochNode->newPrimalVector();
    data->getDiagonalOfQ( *dq );
//  }
  nomegaInv   = stochNode->newDualZVector();
  rhs         = stochNode->newRhs();


  data->getLocalSizes(locnx, locmy, locmz);
  createChildren(data);

  kkt = createKKT(data);
  solver = createSolver(data, kkt);
}
예제 #3
0
sLinsysRootAggregation::sLinsysRootAggregation(sFactory* factory_,
			 sData* prob_,
			 OoqpVector* dd_, 
			 OoqpVector* dq_,
			 OoqpVector* nomegaInv_,
			 OoqpVector* rhs_, OoqpVector* additiveDiag)
  : sLinsysRoot(factory_, prob_, dd_, dq_, nomegaInv_, rhs_,additiveDiag)
{
  n_col = preCond->n_col;  
  n_row = preCond->n_row;

  JNnz = preCond->jac_nnz;
  QNnz = preCond->hes_nnz;

  redDim = n_col + n_row;
  redNnz = JNnz + QNnz + n_col + n_row; // nnz for jac, hes and diag part
  
  redRhs = new SimpleVector(redDim);
  kkt = createKKT(prob_);
  solver = createSolver(prob_, kkt);

  temp_ncol = new SimpleVector(n_col);
  temp_nrow = new SimpleVector(n_row);

  // this is Schur Complement matrix, set it to dummy matrix
  CtDC =  new DenseSymMatrix(0);
}
예제 #4
0
shared_ptr<ISolver> Configuration::createSelectedSolver(IMixedSystem* system)
{
  string solver_name = _global_settings->getSelectedSolver();
  _solver_settings =_settings_factory->createSelectedSolverSettings();
  _simcontroller_settings = shared_ptr<ISimControllerSettings>(new ISimControllerSettings(_global_settings.get()) );
  _solver = createSolver(system, solver_name, _solver_settings);
  return _solver;
}
예제 #5
0
sLinsysRootAug::sLinsysRootAug(sFactory * factory_, sData * prob_)
  : sLinsysRoot(factory_, prob_), CtDC(NULL)
{ 
  prob_->getLocalSizes(locnx, locmy, locmz);
  kkt = createKKT(prob_);
  solver = createSolver(prob_, kkt);
  redRhs = new SimpleVector(locnx+locmy+locmz);
};
QpGenStochLinsysRootAugRedPrecond::
QpGenStochLinsysRootAugRedPrecond(QpGenStoch* factory_,
                                  QpGenStochData* prob,
                                  OoqpVector* dd_,
                                  OoqpVector* dq_,
                                  OoqpVector* nomegaInv_,
                                  OoqpVector* rhs_)
    : QpGenStochLinsysRootAugRed(),
      Pmult(NULL), Amult(NULL), tmpVec1(NULL)
{
    //QpGenStochLinsy
    factory = factory_;

    nx = prob->nx;
    my = prob->my;
    mz = prob->mz;
    ixlow = prob->ixlow;
    ixupp = prob->ixupp;
    iclow = prob->iclow;
    icupp = prob->icupp;

    nxlow = prob->nxlow;
    nxupp = prob->nxupp;
    mclow = prob->mclow;
    mcupp = prob->mcupp;

    if( nxupp + nxlow > 0 ) {
        //dd      = OoqpVectorHandle(dd_);
        dd= dd_;
        //dq      = OoqpVectorHandle(dq_);
        dq = dq_;
    }
    //nomegaInv   = OoqpVectorHandle(nomegaInv_);
    //rhs         = OoqpVectorHandle(rhs_);
    nomegaInv = nomegaInv_;
    rhs = rhs_;

    useRefs=1;
    data = prob;
    stochNode = prob->stochNode;

    //QpGenStochLinsysRoot
    iAmDistrib = 0;

    //QpGenStochLinsyRootAug
    prob->getLocalSizes(locnx, locmy, locmz);
    UtV = NULL;

    //QpGenStochLinsyRootAug
    CtDC=NULL;
    redRhs = new SimpleVector(locnx+locmy+locmz);
    kkt = createKKT(prob);
    solver = createSolver(prob, kkt);

    //intializations related to this class
    me = whoAmI();
    createChildren(prob);
};
QpGenStochLinsysRootAugRedPrecond::
QpGenStochLinsysRootAugRedPrecond(QpGenStoch * factory_,
                                  QpGenStochData * prob)
    : QpGenStochLinsysRootAugRed(),
      Pmult(NULL), Amult(NULL), tmpVec1(NULL)
{
    factory = factory_;
    kkt = NULL;
    solver = NULL;

    nx = prob->nx;
    my = prob->my;
    mz = prob->mz;
    ixlow = prob->ixlow;
    ixupp = prob->ixupp;
    iclow = prob->iclow;
    icupp = prob->icupp;

    nxlow = prob->nxlow;
    nxupp = prob->nxupp;
    mclow = prob->mclow;
    mcupp = prob->mcupp;

    if( nxupp + nxlow > 0 ) {
        dd      = factory_->tree->newPrimalVector();
        dq      = factory_->tree->newPrimalVector();
        prob->getDiagonalOfQ( *dq );
    }
    nomegaInv   = factory_->tree->newDualZVector();
    rhs         = factory_->tree->newRhs();

    useRefs=0;
    data = prob;
    stochNode = prob->stochNode;

    //QpGenStochLinsysRoot
    iAmDistrib = 0;

    //QpGenStochLinsyRootAug
    prob->getLocalSizes(locnx, locmy, locmz);
    UtV = NULL;

    //QpGenStochLinsyRootAug
    CtDC=NULL;
    kkt = createKKT(prob);
    solver = createSolver(prob, kkt);

    //QpGenStochLinsyRootAugRed
    redRhs = new SimpleVector(locnx+locmy+locmz);

    //intializations related to this class
    me = whoAmI();
    createChildren(prob);
};
예제 #8
0
sLinsysRootAggregation::sLinsysRootAggregation(sFactory * factory_, sData * prob_)
  : sLinsysRoot(factory_, prob_)
{
  prob_->getLocalSizes(locnx, locmy, locmz);
  assert(locmz==0);

  n_col = preCond->n_col;  
  n_row = preCond->n_row;

  JNnz  = preCond->jac_nnz;
  QNnz  = preCond->hes_nnz;

  redDim = n_col + n_row;
  redNnz = JNnz + QNnz + n_col + n_row; // nnz for jac, hes and diag part
  
  // vectors for the reduced system
  redRhs 		= new SimpleVector(redDim);
  temp_ncol 	= new SimpleVector(n_col);
  temp_nrow 	= new SimpleVector(n_row);

  temp_ixlow 	= new SimpleVector(n_col);
  temp_ixupp 	= new SimpleVector(n_col);

  temp_x 		= new SimpleVector(n_col);
  temp_y 		= new SimpleVector(n_row);
  temp_gamma 	= new SimpleVector(n_col);
  temp_phi 		= new SimpleVector(n_col);
  temp_v 		= new SimpleVector(n_col);
  temp_w 		= new SimpleVector(n_col);

  rQ 			= new SimpleVector(n_col);
  rA 			= new SimpleVector(n_row);
  rv 			= new SimpleVector(n_col);
  rw 			= new SimpleVector(n_col);
  rgamma 		= new SimpleVector(n_col);
  rphi 			= new SimpleVector(n_col);

  temp_rhs_x 	= new SimpleVector(n_col);
  temp_rhs_y 	= new SimpleVector(n_row); 

  temp_xl 		= new SimpleVector(n_col);
  temp_xu		= new SimpleVector(n_col);


  kkt 	 = createKKT(prob_);
  solver = createSolver(prob_, kkt);

  // this is Schur Complement matrix, set it to dummy matrix
  CtDC =  new DenseSymMatrix(0);

  
  setIX = false;
}
 bool SparseOptimizerIncremental::initSolver(int dimension, int batchEveryN)
 {
   //cerr << __PRETTY_FUNCTION__ << endl;
   slamDimension = dimension;
   if (dimension == 3) {
     setSolver(createSolver(this, "fix3_2_cholmod"));
     BlockSolver<BlockSolverTraits<3, 2> >* bs = dynamic_cast<BlockSolver<BlockSolverTraits<3, 2> >*>(solver());
     LinearSolverCholmodOnline<Matrix3d>* s = dynamic_cast<LinearSolverCholmodOnline<Matrix3d>*>(bs->linearSolver());
     _solverInterface = s;
   } else {
     setSolver(createSolver(this, "fix6_3_cholmod"));
     BlockSolver<BlockSolverTraits<6, 3> >* bs = dynamic_cast<BlockSolver<BlockSolverTraits<6, 3> >*>(solver());
     LinearSolverCholmodOnline<Matrix<double, 6, 6> >* s = dynamic_cast<LinearSolverCholmodOnline<Matrix<double, 6, 6> >*>(bs->linearSolver());
     _solverInterface = s;
   }
   _solverInterface->cmember = &_cmember;
   _solverInterface->batchEveryN = batchEveryN;
   solver()->setSchur(false);
   if (! solver()) {
     cerr << "Error allocating solver. Allocating CHOLMOD solver failed!" << endl;
     return false;
   }
   return true;
 }
예제 #10
0
sLinsysRootAug::sLinsysRootAug(sFactory* factory_,
			       sData* prob_,
			       OoqpVector* dd_, 
			       OoqpVector* dq_,
			       OoqpVector* nomegaInv_,
			       OoqpVector* rhs_,
			       OoqpVector* additiveDiag_)
  : sLinsysRoot(factory_, prob_, dd_, dq_, nomegaInv_, rhs_, additiveDiag_), CtDC(NULL)
{ 
  prob_->getLocalSizes(locnx, locmy, locmz);

  kkt = createKKT(prob_);
  solver = createSolver(prob_, kkt);
  redRhs = new SimpleVector(locnx+locmy+locmz);
};
예제 #11
0
int SimulationObject::initializeLbmSimulation(ntlRenderGlobals *glob)
{
	if(! isSimworldOk() ) return 1;
	
	// already inited?
	if(mpLbm) return 0;
	
	mpGlob = glob;
	if(!getVisible()) {
		mpAttrs->setAllUsed();
		return 0;
	}


	mGeoInitId = mpAttrs->readInt("geoinitid", mGeoInitId,"LbmSolverInterface", "mGeoInitId", false);
	//mDimension, mSolverType are deprecated
	string mSolverType(""); 
	mSolverType = mpAttrs->readString("solver", mSolverType, "SimulationObject","mSolverType", false ); 

	mpLbm = createSolver(); 
  /* check lbm pointer */
	if(mpLbm == NULL) {
		errFatal("SimulationObject::initializeLbmSimulation","Unable to init LBM solver! ", SIMWORLD_INITERROR);
		return 2;
	}
	debMsgStd("SimulationObject::initialized",DM_MSG,"IdStr:"<<mpLbm->getIdString() <<" LBM solver! ", 2);

	mpParts = new ParticleTracer();

	// for non-param simulations
	mpLbm->setParametrizer( mpParam );
	mpParam->setAttrList( getAttributeList() );
	// not needed.. done in solver_init: mpParam->setSize ... in solver_interface
	mpParam->parseAttrList();

	mpLbm->setAttrList( getAttributeList() );
	mpLbm->setSwsAttrList( getSwsAttributeList() );
	mpLbm->parseAttrList();
	mpParts->parseAttrList( getAttributeList() );

	if(! isSimworldOk() ) return 3;
	mpParts->setName( getName() + "_part" );
	mpParts->initialize( glob );
	if(! isSimworldOk() ) return 4;
	
	// init material settings
	string matMc("default");
	matMc = mpAttrs->readString("material_surf", matMc, "SimulationObject","matMc", false );
	mShowSurface   = mpAttrs->readInt("showsurface", mShowSurface, "SimulationObject","mShowSurface", false ); 
	mShowParticles = mpAttrs->readInt("showparticles", mShowParticles, "SimulationObject","mShowParticles", false ); 

	checkBoundingBox( mGeoStart, mGeoEnd, "SimulationObject::initializeSimulation" );
	mpLbm->setLbmInitId( mGeoInitId );
	mpLbm->setGeoStart( mGeoStart );
	mpLbm->setGeoEnd( mGeoEnd );
	mpLbm->setRenderGlobals( mpGlob );
	mpLbm->setName( getName() + "_lbm" );
	mpLbm->setParticleTracer( mpParts );
	if(mpElbeemSettings) {
		// set further settings from API struct init
		if(mpElbeemSettings->outputPath) this->mOutFilename = string(mpElbeemSettings->outputPath);
		mpLbm->initDomainTrafo( mpElbeemSettings->surfaceTrafo );
		mpLbm->setSmoothing(1.0 * mpElbeemSettings->surfaceSmoothing, 1.0 * mpElbeemSettings->surfaceSmoothing);
		mpLbm->setIsoSubdivs(mpElbeemSettings->surfaceSubdivs);
		mpLbm->setSizeX(mpElbeemSettings->resolutionxyz);
		mpLbm->setSizeY(mpElbeemSettings->resolutionxyz);
		mpLbm->setSizeZ(mpElbeemSettings->resolutionxyz);
		mpLbm->setPreviewSize(mpElbeemSettings->previewresxyz);
		mpLbm->setRefinementDesired(mpElbeemSettings->maxRefine);
		mpLbm->setGenerateParticles(mpElbeemSettings->generateParticles);
		// set initial particles
		mpParts->setNumInitialParticles(mpElbeemSettings->numTracerParticles);
		
		// surface generation flag
		mpLbm->setSurfGenSettings(mpElbeemSettings->mFsSurfGenSetting);

		string dinitType = string("no");
		if     (mpElbeemSettings->domainobsType==FLUIDSIM_OBSTACLE_PARTSLIP) dinitType = string("part"); 
		else if(mpElbeemSettings->domainobsType==FLUIDSIM_OBSTACLE_FREESLIP) dinitType = string("free"); 
		else /*if(mpElbeemSettings->domainobsType==FLUIDSIM_OBSTACLE_NOSLIP)*/ dinitType = string("no"); 
		mpLbm->setDomainBound(dinitType);
		mpLbm->setDomainPartSlip(mpElbeemSettings->domainobsPartslip);
		mpLbm->setDumpVelocities(mpElbeemSettings->generateVertexVectors);
		mpLbm->setFarFieldSize(mpElbeemSettings->farFieldSize);
		debMsgStd("SimulationObject::initialize",DM_MSG,"Added domain bound: "<<dinitType<<" ps="<<mpElbeemSettings->domainobsPartslip<<" vv"<<mpElbeemSettings->generateVertexVectors<<","<<mpLbm->getDumpVelocities(), 9 );

		debMsgStd("SimulationObject::initialize",DM_MSG,"Set ElbeemSettings values "<<mpLbm->getGenerateParticles(),10);
	}

	if(! mpLbm->initializeSolverMemory()   )         { errMsg("SimulationObject::initialize","initializeSolverMemory failed"); mPanic=true; return 10; }
	if(checkCallerStatus(FLUIDSIM_CBSTATUS_STEP, 0)) { errMsg("SimulationObject::initialize","initializeSolverMemory status"); mPanic=true; return 11; } 
	if(! mpLbm->initializeSolverGrids()    )         { errMsg("SimulationObject::initialize","initializeSolverGrids  failed"); mPanic=true; return 12; }
	if(checkCallerStatus(FLUIDSIM_CBSTATUS_STEP, 0)) { errMsg("SimulationObject::initialize","initializeSolverGrids  status"); mPanic=true; return 13; } 
	if(! mpLbm->initializeSolverPostinit() )         { errMsg("SimulationObject::initialize","initializeSolverPostin failed"); mPanic=true; return 14; }
	if(checkCallerStatus(FLUIDSIM_CBSTATUS_STEP, 0)) { errMsg("SimulationObject::initialize","initializeSolverPostin status"); mPanic=true; return 15; } 

	// print cell type stats
	bool printStats = true;
	if(glob_mpnum>0) printStats=false; // skip in this case
	if(printStats) {
		const int jmax = sizeof(CellFlagType)*8;
		int totalCells = 0;
		int flagCount[jmax];
		for(int j=0; j<jmax ; j++) flagCount[j] = 0;
		int diffInits = 0;
		LbmSolverInterface::CellIdentifier cid = mpLbm->getFirstCell();
		for(; mpLbm->noEndCell( cid );
					mpLbm->advanceCell( cid ) ) {
			int flag = mpLbm->getCellFlag(cid,0);
			int flag2 = mpLbm->getCellFlag(cid,1);
			if(flag != flag2) {
				diffInits++;
			}
			for(int j=0; j<jmax ; j++) {
				if( flag&(1<<j) ) flagCount[j]++;
			}
			totalCells++;
		}
		mpLbm->deleteCellIterator( &cid );

		char charNl = '\n';
		debugOutNnl("SimulationObject::initializeLbmSimulation celltype stats: " <<charNl, 5);
		debugOutNnl("no. of cells = "<<totalCells<<", "<<charNl ,5);
		for(int j=0; j<jmax ; j++) {
			std::ostringstream out;
			if(flagCount[j]>0) {
				out<<"\t" << flagCount[j] <<" x "<< convertCellFlagType2String( (CellFlagType)(1<<j) ) <<", " << charNl;
				debugOutNnl(out.str(), 5);
			}
		}
		// compute dist. of empty/bnd - fluid - if
		// cfEmpty   = (1<<0), cfBnd  = (1<< 2), cfFluid   = (1<<10), cfInter   = (1<<11),
		if(1){
			std::ostringstream out;
			out.precision(2); out.width(4);
			int totNum = flagCount[1]+flagCount[2]+flagCount[7]+flagCount[8];
			double ebFrac = (double)(flagCount[1]+flagCount[2]) / totNum;
			double flFrac = (double)(flagCount[7]) / totNum;
			double ifFrac = (double)(flagCount[8]) / totNum;
			//???
			out<<"\tFractions: [empty/bnd - fluid - interface - ext. if]  =  [" << ebFrac<<" - " << flFrac<<" - " << ifFrac<<"] "<< charNl;

			if(diffInits > 0) {
				debMsgStd("SimulationObject::initializeLbmSimulation",DM_MSG,"celltype Warning: Diffinits="<<diffInits<<"!" , 5);
			}
			debugOutNnl(out.str(), 5);
		}
	} // cellstats

	// might be modified by mpLbm
	//mpParts->setStart( mGeoStart );?  mpParts->setEnd( mGeoEnd );?
	mpParts->setStart( mpLbm->getGeoStart() );
	mpParts->setEnd(   mpLbm->getGeoEnd()   );
	mpParts->setCastShadows( false );
	mpParts->setReceiveShadows( false );
	mpParts->searchMaterial( glob->getMaterials() );

	// this has to be inited here - before, the values might be unknown
	IsoSurface *surf = mpLbm->getSurfaceGeoObj();
	if(surf) {
		surf->setName( "final" ); // final surface mesh 
		// warning - this might cause overwriting effects for multiple sims and geom dump...
		surf->setCastShadows( true );
		surf->setReceiveShadows( false );
		surf->searchMaterial( glob->getMaterials() );
		if(mShowSurface) mObjects.push_back( surf );
	}
	
#ifdef ELBEEM_PLUGIN
	mShowParticles=1; // for e.g. dumping
#endif // ELBEEM_PLUGIN
	if((mpLbm->getGenerateParticles()>0.0)||(mpParts->getNumInitialParticles()>0)) {
		mShowParticles=1;
		mpParts->setDumpParts(true);
	}
		//debMsgStd("SimulationObject::init",DM_NOTIFY,"Using envvar ELBEEM_DUMPPARTICLE to set mShowParticles, DEBUG!",1);
	//}  // DEBUG ENABLE!!!!!!!!!!
	if(mShowParticles) {
		mObjects.push_back(mpParts);
	}

	// add objects to display for debugging (e.g. levelset particles)
	vector<ntlGeometryObject *> debugObjs = mpLbm->getDebugObjects();
	for(size_t i=0;i<debugObjs.size(); i++) {
		debugObjs[i]->setCastShadows( false );
		debugObjs[i]->setReceiveShadows( false );
		debugObjs[i]->searchMaterial( glob->getMaterials() );
		mObjects.push_back( debugObjs[i] );
		debMsgStd("SimulationObject::init",DM_NOTIFY,"Added debug obj "<<debugObjs[i]->getName(), 10 );
	}
	return 0;
}
예제 #12
0
파일: slam2d_linear.cpp 프로젝트: 2maz/g2o
 virtual OptimizationAlgorithm* construct()
 {
   return createSolver(property().name);
 }
예제 #13
0
 virtual Solver* construct(SparseOptimizer* optimizer)
 {
   return createSolver(optimizer, property().name);
 }