Example #1
0
      void
      processRequest(const IMC::PlanControl* pc)
      {
        m_reply.setDestination(pc->getSource());
        m_reply.setDestinationEntity(pc->getSourceEntity());
        m_reply.request_id = pc->request_id;
        m_reply.op = pc->op;
        m_reply.plan_id = pc->plan_id;

        inf(DTR("request -- %s (%s)"),
            DTR(c_op_desc[m_reply.op]),
            m_reply.plan_id.c_str());

        if (getEntityState() != IMC::EntityState::ESTA_NORMAL)
        {
          onFailure(DTR("engine not ready: entity state not normal"));
          return;
        }

        switch (pc->op)
        {
          case IMC::PlanControl::PC_START:
            if (!startPlan(pc->plan_id, pc->arg.isNull() ? 0 : pc->arg.get(), pc->flags))
              vehicleRequest(IMC::VehicleCommand::VC_STOP_MANEUVER);
            break;
          case IMC::PlanControl::PC_STOP:
            stopPlan();
            break;
          case IMC::PlanControl::PC_LOAD:
            loadPlan(pc->plan_id, pc->arg.isNull() ? 0 : pc->arg.get(), false);
            break;
          case IMC::PlanControl::PC_GET:
            getPlan();
            break;
          default:
            onFailure(DTR("plan control operation not supported"));
            break;
        }
      }
Example #2
0
void executePlan (std::stringstream& plan_to_validate, TypeChecker & tc, const DerivationRules * derivRules, double tolerance, bool lengthDefault, bool giveAdvice)
{
	Ranking rnk;
	Ranking rnkInv;
	vector<string> failed;
	vector<string> queries;

	std::string name = "The master plan";

	plan * the_plan = getPlan (plan_to_validate, tc, failed, name);
	if (the_plan == 0) return;

	plan * copythe_plan = new plan (*the_plan);
	plan * planNoTimedLits = new plan();
	vector<plan_step *> timedInitialLiteralActions = getTimedInitialLiteralActions();
	double deadLine = 101;

	//add timed initial literals to the plan from the problem spec
	for (vector<plan_step *>::iterator ps = timedInitialLiteralActions.begin(); ps != timedInitialLiteralActions.end(); ++ps)
	{
		the_plan->push_back (*ps);
	};

	//add actions that are not to be moved to the timed intitial literals otherwise to the plan to be repaired
	//i.e. pretend these actions are timed initial literals
	for (pc_list<plan_step*>::const_iterator i = copythe_plan->begin(); i != copythe_plan->end(); ++i)
	{
		planNoTimedLits->push_back (*i);
	};

	copythe_plan->clear(); delete copythe_plan;

	PlanRepair pr (timedInitialLiteralActions, deadLine, derivRules, tolerance, tc, an_analysis.the_domain->ops,
	               an_analysis.the_problem->initial_state,
	               the_plan, planNoTimedLits, an_analysis.the_problem->metric, lengthDefault,
	               an_analysis.the_domain->isDurative(), an_analysis.the_problem->the_goal, current_analysis);

	if (Verbose)
		pr.getValidator().displayPlan();



	try
	{

		if (pr.getValidator().execute())
		{
			if (!Silent) cout << "Plan executed successfully - checking goal\n";

			if (pr.getValidator().checkGoal (an_analysis.the_problem->the_goal))

			{
				if (! (pr.getValidator().hasInvariantWarnings()))
				{
					rnk[pr.getValidator().finalValue() ].push_back (name);
					if (!Silent) *report << "Plan valid\n";
					if (!Silent) *report << "Final value: " << pr.getValidator().finalValue() << "\n";
				}
				else
				{
					rnkInv[pr.getValidator().finalValue() ].push_back (name);
					if (!Silent) *report << "Plan valid (subject to further invariant checks)\n";
					if (!Silent) *report << "Final value: " << pr.getValidator().finalValue();
				};
				if (Verbose)
				{
					pr.getValidator().reportViolations();
				};
			}
			else
			{
				failed.push_back (name);
				*report << "Goal not satisfied\n";

				*report << "Plan invalid\n";
				++errorCount;
			};

		}
		else
		{
			failed.push_back (name);
			++errorCount;
			if (ContinueAnyway)
			{
				cout << "\nPlan failed to execute - checking goal\n";

				if (!pr.getValidator().checkGoal (an_analysis.the_problem->the_goal)) *report << "\nGoal not satisfied\n";

			}

			else *report << "\nPlan failed to execute\n";


		};

		if (pr.getValidator().hasInvariantWarnings())
		{
			cout << "\n\n";
			*report << "This plan has the following further condition(s) to check:";
			cout << "\n\n";

			pr.getValidator().displayInvariantWarnings();
		};
	}
	catch (exception & e)
	{
		cout << "Error occurred in validation attempt:\n  " << e.what() << "\n";
		queries.push_back (name);

	};

	//display error report and plan repair advice
	if (giveAdvice && (Verbose || ErrorReport))
	{
		pr.firstPlanAdvice();
	};

	planNoTimedLits->clear(); delete planNoTimedLits;
	delete the_plan;

	if (!rnk.empty())
	{
		if (!Silent) cout << "\nSuccessful plans:";


		if (an_analysis.the_problem->metric &&
		    an_analysis.the_problem->metric->opt == E_MINIMIZE)
		{
			if (!Silent) for_each (rnk.begin(), rnk.end(), showList());

		}
		else
		{
			if (!Silent) for_each (rnk.rbegin(), rnk.rend(), showList());
		};



		*report << "\n";
	};

	if (!rnkInv.empty())
	{
		if (!Silent) cout << "\nSuccessful Plans Subject To Further Invariant Checks:";


		if (an_analysis.the_problem->metric &&
		    an_analysis.the_problem->metric->opt == E_MINIMIZE)
		{
			for_each (rnkInv.begin(), rnkInv.end(), showList());
		}
		else
		{
			for_each (rnkInv.rbegin(), rnkInv.rend(), showList());
		};



		*report << "\n";
	};

	if (!failed.empty())
	{
		cout << "\n\nFailed plans:\n ";
		copy (failed.begin(), failed.end(), ostream_iterator<string> (cout, " "));
		*report << "\n";
	};

	if (!queries.empty())
	{
		cout << "\n\nQueries (validator failed):\n ";
		copy (queries.begin(), queries.end(), ostream_iterator<string> (cout, " "));
		*report << "\n";
	};

};
Albany::PUMIMeshStruct::PUMIMeshStruct(
    const Teuchos::RCP<Teuchos::ParameterList>& params,
    const Teuchos::RCP<const Teuchos_Comm>& commT)
{
  params->validateParameters(
      *(PUMIMeshStruct::getValidDiscretizationParameters()), 0);

  outputFileName = params->get<std::string>("PUMI Output File Name", "");
  outputInterval = params->get<int>("PUMI Write Interval", 1); // write every time step default

  std::string model_file;
  if(params->isParameter("Mesh Model Input File Name"))
    model_file = params->get<std::string>("Mesh Model Input File Name");

#ifdef SCOREC_SIMMODEL
  if (params->isParameter("Acis Model Input File Name"))
    model_file = params->get<std::string>("Parasolid Model Input File Name");

  if(params->isParameter("Parasolid Model Input File Name"))
    model_file = params->get<std::string>("Parasolid Model Input File Name");
#endif

  if (params->isParameter("PUMI Input File Name")) {

    std::string mesh_file = params->get<std::string>("PUMI Input File Name");
    mesh = 0;

    // If we are running in parallel but have a single mesh file, split it and rebalance
    bool useSerialMesh = params->get<bool>("Use Serial Mesh", false);
    if (useSerialMesh && commT->getSize() > 1){ // do the equivalent of the SCOREC "split" utility
       apf::Migration* plan = 0;
       gmi_model* g = 0;
       g = gmi_load(model_file.c_str());
       bool isOriginal = ((PCU_Comm_Self() % commT->getSize()) == 0);
       switchToOriginals(commT->getSize());
       if (isOriginal) {
         mesh = apf::loadMdsMesh(g, mesh_file.c_str());
         plan = getPlan(mesh, commT->getSize());
       }
       switchToAll();
       mesh = repeatMdsMesh(mesh, g, plan, commT->getSize());
    }
    else {
      mesh = apf::loadMdsMesh(model_file.c_str(), mesh_file.c_str());
    }

  } else {
    int nex = params->get<int>("1D Elements", 0);
    int ney = params->get<int>("2D Elements", 0);
    int nez = params->get<int>("3D Elements", 0);
    double wx = params->get<double>("1D Scale", 1);
    double wy = params->get<double>("2D Scale", 1);
    double wz = params->get<double>("3D Scale", 1);
    bool is = ! params->get<bool>("Hexahedral", true);
    buildBoxMesh(nex, ney, nez, wx, wy, wz, is);
  }

  model = mesh->getModel();

  // Tell the mesh that we'll handle deleting the model.
  apf::disownMdsModel(mesh);

  bool isQuadMesh = params->get<bool>("2nd Order Mesh",false);
  if (isQuadMesh)
    apf::changeMeshShape(mesh, apf::getSerendipity(), false);

  // Resize mesh after input if indicated in the input file
  // User has indicated a desired element size in input file
  if(params->isParameter("Resize Input Mesh Element Size")){
    SizeFunction sizeFunction(params->get<double>(
          "Resize Input Mesh Element Size", 0.1));
    int num_iters = params->get<int>(
        "Max Number of Mesh Adapt Iterations", 1);
    ma::Input* input = ma::configure(mesh,&sizeFunction);
    input->maximumIterations = num_iters;
    input->shouldSnap = false;
    ma::adapt(input);
  }

  // get the continuation step to write a restart file
  restartWriteStep = params->get<int>("Write Restart File at Step",0);

  APFMeshStruct::init(params, commT);

  // if we have a restart time, we will want to override some of
  // the default paramaters set by APFMeshStruct::init
  if (params->isParameter("PUMI Restart Time")) {
    hasRestartSolution = true;
    restartDataTime = params->get<double>("PUMI Restart Time", 0.0);
    std::string name = params->get<std::string>("PUMI Input File Name");
    if (!PCU_Comm_Self())
      std::cout << "Restarting from time: " << restartDataTime
        << " from restart file: " << name << std::endl;
  }

  if (params->isParameter("Load FELIX Data"))
    shouldLoadFELIXData = true;

}
Example #4
0
std::vector<double> libmaus2::math::Convolution::convolutionFFTW(
	std::vector<double> const &
		#if defined(LIBMAUS2_HAVE_FFTW)
		RA
		#endif
		,
	std::vector<double> const &
		#if defined(LIBMAUS2_HAVE_FFTW)
		RB
		#endif
)
{
	#if defined(LIBMAUS2_HAVE_FFTW)
	uint64_t const ra = RA.size();
	uint64_t const rb = RB.size();

	if ( ra*rb == 0 )
		return std::vector<double>(0);

	uint64_t const rfftn = (ra+rb-1);
	uint64_t const minsize = 4096;
	uint64_t const fftn = std::max(minsize,libmaus2::math::nextTwoPow(rfftn));

	Transform::shared_ptr_type planA = getPlan(fftn,true);
	Transform::shared_ptr_type planB = getPlan(fftn,true);
	Transform::shared_ptr_type planR = getPlan(fftn,false);

	FFTWConvMemBlock & CCin_A = planA->CCin;
	FFTWConvMemBlock & CCtmp_A = planA->CCout;

	FFTWConvMemBlock & CCin_B = planB->CCin;
	FFTWConvMemBlock & CCtmp_B = planB->CCout;

	FFTWConvMemBlock & CCtmp_C = planR->CCin;
	FFTWConvMemBlock & CCout = planR->CCout;

	for ( uint64_t i = 0; i < RA.size(); ++i )
		CCin_A.A[i][0] = RA[i];
	for ( uint64_t i = 0; i < RB.size(); ++i )
		CCin_B.A[i][0] = RB[i];

	planA->execute();
	planB->execute();

	for ( uint64_t i = 0; i < fftn; ++i )
	{
		std::complex<double> CA(CCtmp_A.A[i][0],CCtmp_A.A[i][1]);
		std::complex<double> CB(CCtmp_B.A[i][0],CCtmp_B.A[i][1]);
		std::complex<double> CC = CA * CB;
		CCtmp_C.A[i][0] = CC.real();
		CCtmp_C.A[i][1] = CC.imag();
	}

	planR->execute();

	std::vector<double> R(rfftn);
	for ( uint64_t i = 0; i < rfftn; ++i )
		R[i] = CCout.A[i][0] / fftn;

	returnPlan(planA);
	returnPlan(planB);
	returnPlan(planR);

	return R;
	#else
	libmaus2::exception::LibMausException lme;
	lme.getStream() << "[E] libmaus2::math::Convolution::convolutionFFTW: libmaus2 is built without fftw support" << std::endl;
	lme.finish();
	throw lme;
	#endif
}