コード例 #1
0
ファイル: FlightPhaseDetector.hpp プロジェクト: Advi42/XCSoar
 PhaseTotals() {
   total_circstats.Clear();
   left_circstats.Clear();
   right_circstats.Clear();
   mixed_circstats.Clear();
   total_cruisestats.Clear();
 }
コード例 #2
0
ファイル: entry.cpp プロジェクト: layeredqueuing/V5
void Entry::connectCalls()
{
    for ( std::map<unsigned, Phase*>::const_iterator next_phase = _phases.begin(); next_phase != _phases.end(); ++next_phase ) {
	Phase * phase = next_phase->second;
	phase->connectCalls( _src_arcs );
    }
}
コード例 #3
0
ファイル: Base.cpp プロジェクト: BoostedColliderAnalysis/BoCA
std::string Base::FileName(Phase const& phase) const
{
    INFO0;
    switch (phase.Tag()) {
    case Tag::signal : return SignalFileName(phase.Stage());
    case Tag::background : return BackgroundFileName(phase.Stage());
        DEFAULT(boca::Name(phase.Tag()), "");
    }
}
コード例 #4
0
ファイル: FlightPhaseJSON.cpp プロジェクト: CnZoom/XcSoarPull
static void
WriteCruiseStats(TextWriter &writer, const Phase &stats)
{
  JSON::ObjectWriter object(writer);
  object.WriteElement("alt_diff", JSON::WriteInteger, (int)stats.alt_diff);
  object.WriteElement("duration", JSON::WriteInteger, (int)stats.duration);
  object.WriteElement("fraction", JSON::WriteFixed, stats.fraction);
  object.WriteElement("distance", JSON::WriteInteger, (int)stats.distance);
  object.WriteElement("speed", JSON::WriteFixed, stats.GetSpeed());
  object.WriteElement("vario", JSON::WriteFixed, stats.GetVario());
  object.WriteElement("glide_rate", JSON::WriteFixed, stats.GetGlideRate());
  object.WriteElement("count", JSON::WriteInteger, stats.merges);
}
コード例 #5
0
void WriteRestartFile::call(size_t timestep)
{
  Phase *phase = M_PHASE;

  m_step++;

  if (m_step == m_write_every) {
    MSG_DEBUG("WriteRestartFile::call", "Outputting restart file.");

    phase->writeRestartFile(make_filename(m_file_name, m_file_no));
    
    m_file_no++;
    m_step = 0;
  }
}
コード例 #6
0
ファイル: ThermoFactory.cpp プロジェクト: arghdos/cantera
void installElements(Phase& th, const XML_Node& phaseNode)
{
    // get the declared element names
    if (!phaseNode.hasChild("elementArray")) {
        throw CanteraError("installElements",
                           "phase XML node doesn't have \"elementArray\" XML Node");
    }
    XML_Node& elements = phaseNode.child("elementArray");
    vector<string> enames;
    getStringArray(elements, enames);

    // // element database defaults to elements.xml
    string element_database = "elements.xml";
    if (elements.hasAttrib("datasrc")) {
        element_database = elements["datasrc"];
    }

    XML_Node* doc = get_XML_File(element_database);
    XML_Node* dbe = &doc->child("elementData");

    XML_Node& root = phaseNode.root();
    XML_Node* local_db = 0;
    if (root.hasChild("elementData")) {
        local_db = &root.child("elementData");
    }

    for (size_t i = 0; i < enames.size(); i++) {
        // Find the element data
        XML_Node* e = 0;
        if (local_db) {
            e = local_db->findByAttr("name",enames[i]);
        }
        if (!e) {
            e = dbe->findByAttr("name",enames[i]);
        }
        if (!e) {
            throw CanteraError("addElementsFromXML","no data for element "
                               +enames[i]);
        }

        // Add the element
        doublereal weight = 0.0;
        if (e->hasAttrib("atomicWt")) {
            weight = fpValue(e->attrib("atomicWt"));
        }
        int anum = 0;
        if (e->hasAttrib("atomicNumber")) {
            anum = intValue(e->attrib("atomicNumber"));
        }
        string symbol = e->attrib("name");
        doublereal entropy298 = ENTROPY298_UNKNOWN;
        if (e->hasChild("entropy298")) {
            XML_Node& e298Node = e->child("entropy298");
            if (e298Node.hasAttrib("value")) {
                entropy298 = fpValueCheck(e298Node["value"]);
            }
        }
        th.addElement(symbol, weight, anum, entropy298);
    }
}
コード例 #7
0
ファイル: FlightPhaseJSON.cpp プロジェクト: CnZoom/XcSoarPull
static void
WriteCirclingStats(TextWriter &writer, const Phase &stats)
{
  JSON::ObjectWriter object(writer);
  object.WriteElement("alt_diff", JSON::WriteInteger, (int)stats.alt_diff);
  object.WriteElement("duration", JSON::WriteInteger, (int)stats.duration);
  object.WriteElement("fraction", JSON::WriteFixed, stats.fraction);
  object.WriteElement("vario", JSON::WriteFixed, stats.GetVario());
  object.WriteElement("count", JSON::WriteInteger, stats.merges);
}
コード例 #8
0
ファイル: FlightPhaseJSON.cpp プロジェクト: CnZoom/XcSoarPull
static void
WritePhase(TextWriter &writer, Phase &phase)
{
  JSON::ObjectWriter object(writer);
  NarrowString<64> buffer;

  FormatISO8601(buffer.buffer(), phase.start_datetime);
  object.WriteElement("start_time", JSON::WriteString, buffer);

  FormatISO8601(buffer.buffer(), phase.end_datetime);
  object.WriteElement("end_time", JSON::WriteString, buffer);

  object.WriteElement("type", JSON::WriteString,
                      FormatPhaseType(phase.phase_type));
  object.WriteElement("duration", JSON::WriteInteger, (int)phase.duration);
  object.WriteElement("circling_direction", JSON::WriteString,
                      FormatCirclingDirection(phase.circling_direction));
  object.WriteElement("alt_diff", JSON::WriteInteger, (int)phase.alt_diff);
  object.WriteElement("distance", JSON::WriteInteger, (int)phase.distance);
  object.WriteElement("speed", JSON::WriteFixed, phase.GetSpeed());
  object.WriteElement("vario", JSON::WriteFixed, phase.GetVario());
  object.WriteElement("glide_rate", JSON::WriteFixed, phase.GetGlideRate());
}
コード例 #9
0
void FParticleVectorMatrix::computeForces(Particle* part, int force_index)
{
  Phase *phase = ((Simulation *) m_parent)->phase();
  
  size_t nOfParts = phase->returnNofPartC(m_colour);

  ParticleList& particles = phase->particles(m_colour);

  // slow (constant for this call) particle-row-index
  size_t p1 = part->mySlot;

  size_t p1Contrib = p1*SPACE_DIMS*nOfParts*SPACE_DIMS;

  // the force to be modified
  point_t force = {0,0,0};

  // outer (slow) cartesian loop
  for(size_t d1 = 0; d1 < SPACE_DIMS; ++d1) {
    size_t d1Contrib = d1*SPACE_DIMS*nOfParts;
    // inner (fast) particle loop
    for(size_t p2 = 0; p2 < nOfParts; ++p2) {
      point_t& vec = particles[p2].tag.pointByOffset(m_invec_offset);
      // inner (fast) cartesian loop
      for(size_t d2 = 0; d2 < SPACE_DIMS; ++d2) {
	size_t slot = d2
	  + p2*SPACE_DIMS
	  + d1Contrib
	  + p1Contrib;
	  force[d1] += -m_mat[slot]*vec[d2];
      }}}

  part->tag.pointByOffset(m_force_offset[force_index]) += force*m_factor;

//MSG_DEBUG("FParticleVectorMatrix::computeForces", "force AFTER = " << part->tag.tensorByOffset(m_force_offset[force_index]));

}
コード例 #10
0
ファイル: Archiver.C プロジェクト: vincentvillani/DSPSR
void dsp::Archiver::set (Pulsar::Archive* archive, const PhaseSeries* phase)
try
{
  if (verbose > 2)
    cerr << "dsp::Archiver::set Pulsar::Archive" << endl;

  if (!archive)
    throw Error (InvalidParam, "dsp::Archiver::set Pulsar::Archive",
        	 "no Archive");

  if (!phase)
    throw Error (InvalidParam, "dsp::Archiver::set Pulsar::Archive",
        	 "no PhaseSeries");

  const unsigned npol  = get_npol (phase);
  const unsigned nchan = phase->get_nchan();
  const unsigned nbin  = phase->get_nbin();
  const unsigned nsub  = 1;

  if (verbose > 2)
    cerr << "dsp::Archiver::set Pulsar::Archive nsub=" << nsub 
         << " npol=" << npol << " nchan=" << nchan 
         << " nbin=" << nbin << " fourth=" << fourth_moments << endl;

  archive-> resize (nsub, npol, nchan, nbin);

  Pulsar::FITSHdrExtension* ext;
  ext = archive->get<Pulsar::FITSHdrExtension>();
  
  if (ext)
  {
    if (verbose > 2)
      cerr << "dsp::Archiver::set Pulsar::Archive FITSHdrExtension" << endl;

    // Make sure the start time is aligned with pulse phase zero
    // as this is what the PSRFITS format expects.

    MJD initial = phase->get_start_time();

    if (phase->has_folding_predictor())
    {
      Phase inphs = phase->get_folding_predictor()->phase(initial);
      double dtime = inphs.fracturns() * phase->get_folding_period();
      initial -= dtime;
    }

    ext->set_start_time (initial);

    // In keeping with tradition, I'll set this to a value that should
    // work in most places for the next 50 years or so ;)

    ext->set_coordmode("J2000");

    // Set the ASCII date stamp from the system clock (in UTC)

    time_t thetime;
    time(&thetime);
    string time_str = asctime(gmtime(&thetime));

    // Cut off the line feed character
    time_str = time_str.substr(0,time_str.length() - 1);

    ext->set_date_str(time_str);
  }

  archive-> set_telescope ( phase->get_telescope() );
  archive-> set_type ( phase->get_type() );

  switch (phase->get_state())
  {
  case Signal::NthPower:
  case Signal::PP_State:
  case Signal::QQ_State:
    archive->set_state (Signal::Intensity);
    break;
  
  case Signal::FourthMoment:
    archive->set_state (Signal::Stokes);
    break;

  default:
    archive-> set_state ( phase->get_state() );
  }

  archive-> set_scale ( Signal::FluxDensity );

  if (verbose > 2)
    cerr << "dsp::Archiver::set Archive source=" << phase->get_source()
         << "\n  coord=" << phase->get_coordinates()
         << "\n  bw=" << phase->get_bandwidth()
         << "\n  freq=" << phase->get_centre_frequency () << endl;

  archive-> set_source ( phase->get_source() );
  archive-> set_coordinates ( phase->get_coordinates() );
  archive-> set_bandwidth ( phase->get_bandwidth() );
  archive-> set_centre_frequency ( phase->get_centre_frequency() );
  archive-> set_dispersion_measure ( phase->get_dispersion_measure() );

  archive-> set_dedispersed( archive_dedispersed );
  archive-> set_faraday_corrected (false);

  /* *********************************************************************
     *********************************************************************

     Set any available extensions

     *********************************************************************
     ********************************************************************* */

  /*
    A valid Backend extension may have already been created; e.g. by
    the OutputArchive extension class.  Therefore, if the Backend extension
    already exists, do not modifiy it.
  */

  Pulsar::Backend* backend = archive -> get<Pulsar::Backend>();
  if (!backend)
  {
    backend = new Pulsar::Backend;

    if (verbose > 2)
      cerr << "dsp::Archiver::set Pulsar::Backend extension" << endl;

    set (backend);

    archive->add_extension( backend );
  }


  // Note, this is now called before the set(Integration,...) call below
  // so that the DigitiserCounts extension gets set up correctly the
  // first time.

  Pulsar::dspReduction* dspR = archive -> getadd<Pulsar::dspReduction>();
  if (dspR)
  {
    if (verbose > 2)
      cerr << "dsp::Archiver::set Pulsar::dspReduction extension" << endl;
    set (dspR);
  }

  for (unsigned isub=0; isub < nsub; isub++)
    set (archive->get_Integration(isub), phase, isub, nsub);

  if (store_dynamic_extensions)
  {
    Pulsar::TwoBitStats* tbc = archive -> getadd<Pulsar::TwoBitStats>();
    if (tbc)
    {
      if (verbose > 2)
        cerr << "dsp::Archiver::set Pulsar::TwoBitStats extension" << endl;
      set (tbc);
    }

    Pulsar::Passband* pband = archive -> getadd<Pulsar::Passband>();
    if (pband)
    {
      if (verbose > 2)
        cerr << "dsp::Archiver::set Pulsar::Passband extension" << endl;
      set (pband);
    }
  }

  Pulsar::Telescope* telescope = archive -> getadd<Pulsar::Telescope>();

  try
  {
    telescope->set_coordinates ( phase -> get_telescope() );
  }
  catch (Error& error)
  {
    if (verbose > 2)
      cerr << "dsp::Archiver WARNING could not set telescope coordinates\n\t"
           << error.get_message() << endl;
  }

  // default Receiver extension
  Pulsar::Receiver* receiver = archive -> getadd<Pulsar::Receiver>();
  receiver->set_name ( phase -> get_receiver() );
  receiver->set_basis ( phase -> get_basis() );

  for (unsigned iext=0; iext < extensions.size(); iext++)
    archive -> add_extension ( extensions[iext] );

  // set_model must be called after the Integration::MJD has been set
  if( phase->has_folding_predictor() )
  {
    if (verbose > 2)
      cerr << "dsp::Archiver::set has predictor" << endl;
    archive-> set_model ( phase->get_folding_predictor(), false );
  }
  else if (verbose > 2)
    cerr << "dsp::Archiver::set PhaseSeries has no predictor" << endl;

  if (phase->has_pulsar_ephemeris())
    archive-> set_ephemeris( phase->get_pulsar_ephemeris(), false );

  archive-> set_filename (get_filename (phase));

  if (verbose > 2) cerr << "dsp::Archiver set archive filename to '"
        	    << archive->get_filename() << "'" << endl;
}
catch (Error& error)
{
  throw error += "dsp::Archiver::set Pulsar::Archive";
}
コード例 #11
0
ファイル: Base.cpp プロジェクト: BoostedColliderAnalysis/BoCA
std::vector<std::string> Base::TreeNames(Phase const& phase) const
{
    INFO0;
    return TreeNames(phase.Tag());
}
コード例 #12
0
ファイル: interaction.cpp プロジェクト: loczaj/simulbody
void Interaction::calculateRelativeVelocity(const Phase &x) {
	relativeVelocity = x.getBodyVelocity(moon);
	relativeVelocity -= x.getBodyVelocity(earth);
}
コード例 #13
0
float WalkingEngineKick::getValue(Track track, float externValue)
{
  std::vector<Phase>& phases = tracks[track];
  const int phasesSize = int(phases.size());
  int currentPhase = currentPhases[track];

  const bool init = currentPhase < 0;
  if(init)
    currentPhase = currentPhases[track] = 0;

  ASSERT(currentPhase < phasesSize - 1);
  Phase* phase = &phases[currentPhase];
  Phase* nextPhase = &phases[currentPhase + 1];

  if(init)
  {
    const bool precomputedLength = length >= 0.f;
    if(!precomputedLength)
    {
      phase->evaluateLength(0.f);
      nextPhase->evaluateLength(phase->end);
    }
    phase->evaluatePos(externValue);
    nextPhase->evaluatePos(externValue);
    Phase* const nextNextPhase = currentPhase + 2 < phasesSize ? &phases[currentPhase + 2] : 0;
    if(nextNextPhase)
    {
      if(!precomputedLength)
        nextNextPhase->evaluateLength(nextPhase->end);
      nextNextPhase->evaluatePos(externValue);
      nextPhase->velocity = ((nextPhase->pos - phase->pos) / phase->length + (nextNextPhase->pos - nextPhase->pos) / nextPhase->length) * 0.5f;
    }
  }

  while(phase->end <= currentPosition)
  {
    Phase* nextNextPhase = currentPhase + 2 < phasesSize ? &phases[currentPhase + 2] : 0;
    if(!nextNextPhase)
    {
      ASSERT(nextPhase->posValue == 0);
      return externValue;
    }

    currentPhase = ++currentPhases[track];
    phase = nextPhase;
    nextPhase = nextNextPhase;
    if(currentPhase + 2 < phasesSize)
    {
      nextNextPhase = &phases[currentPhase + 2];
      const bool precomputedLength = length >= 0.f;
      if(!precomputedLength)
        nextNextPhase->evaluateLength(nextPhase->end);
      nextNextPhase->evaluatePos(externValue);
      nextPhase->velocity = ((nextPhase->pos - phase->pos) / phase->length + (nextNextPhase->pos - nextPhase->pos) / nextPhase->length) * 0.5f;
    }
  }

  if(!phase->posValue)
    phase->pos = externValue;
  if(!nextPhase->posValue)
    nextPhase->pos = externValue;

  const float nextRatio = (currentPosition - phase->start) / phase->length;
  const float d = phase->pos;
  const float c = phase->velocity;
  const float v2 = nextPhase->velocity;
  const float p2 = nextPhase->pos;
  const float p2mcmd = p2 - c - d;
  const float a = -2.f * p2mcmd + (v2 - c);
  const float b = p2mcmd - a;
  const float x = nextRatio;
  const float xx = x * x;
  return a * xx * x + b * xx + c * x + d;
}
コード例 #14
0
ファイル: Base.cpp プロジェクト: BoostedColliderAnalysis/BoCA
std::string Base::ExportFileName(Phase const& phase) const
{
    INFO0;
    return ExportFileName(phase.Stage(), phase.Tag());
}
コード例 #15
0
ファイル: Contemporaneity.C プロジェクト: SkyTian13/psrchive
double double_cast (const Phase& phase)
{
  return phase.in_turns();
}
コード例 #16
0
ファイル: interaction.cpp プロジェクト: loczaj/simulbody
void Interaction::applyForceOnMoon(Phase &dxdt, const vector3D &force) {
	dxdt.addForceOnBodyInDifferentialPhase(moon, force);
}
コード例 #17
0
ファイル: interaction.cpp プロジェクト: loczaj/simulbody
void Interaction::addVelocityOnEarth(Phase &dxdt, const vector3D &velocity) {
	dxdt.addVelocityOnBodyInDifferentialPhase(earth, velocity);
}
コード例 #18
0
ファイル: interaction.cpp プロジェクト: loczaj/simulbody
void Interaction::addVelocityOnMoon(Phase &dxdt, const vector3D &velocity) {
	dxdt.addVelocityOnBodyInDifferentialPhase(moon, velocity);
}
コード例 #19
0
ファイル: interaction.cpp プロジェクト: loczaj/simulbody
void Interaction::applyForceOnEarth(Phase &dxdt, const vector3D &force) {
	dxdt.addForceOnBodyInDifferentialPhase(earth, force);
}
コード例 #20
0
ファイル: boundary_stl.cpp プロジェクト: hemanth1947/sympler
void BoundarySTL::setup(Simulation* sim, ManagerCell *mgr)
{
    //    BoundaryWithInlet::setup(sim, mgr);
	
    
    /* Cell subdivision */
	
    region_t *inlet, *r;
    bool_point_t periodic = { { { false, false, false } } };

    /* Do we have to construct an inlet??? */
    if (m_inlet_str != "none") {
        int dir;
        double coord;
        ParticleCreatorInlet *pc = NULL;

        MSG_DEBUG("BoundarySTL::setup", "Adding inlet.");

        for(vector<ParticleCreator*>::iterator pcIter = m_pcList.begin();
            pcIter != m_pcList.end(); ++pcIter)
        {
          if(typeid(**pcIter) == typeid(ParticleCreatorInlet))
          {
            if(pc) 
              throw gError("BoundarySTL::setup", "Please define only one ParticleCreatorInlet");
            pc = (ParticleCreatorInlet*) (*pcIter);
          }
        }
        if(!pc) 
          throw gError("BoundarySTL::setup", "Since 'inlet' is not \"none\", you must define a ParticleCreatorInlet.");
        
//         if (typeid(*pcList[0]) != typeid(ParticleCreatorInlet))
//           throw gError
//             ("BoundarySTL::setup"
//              "Please do only use ParticleCreatorInlet with BoundarySTL if you wish to specify an inlet.");
// 
//         pc = (ParticleCreatorInlet*) pcList[0];
// 
// 
//         MSG_DEBUG("BoundarySTL::setup", "Using particle creator: " << pc->className());

        dir = m_inlet_str[0] - 'x';

        m_inlet_normal.assign(0);
        if (m_inlet_pos_str == "bottom") {
            m_inlet_normal[dir] = 1;
            coord = m_container->boundingBox().corner1[dir];
        } else {
            m_inlet_normal[dir] = -1;
            coord = m_container->boundingBox().corner2[dir];
        }

        
        //        MSG_DEBUG("BoundartSTL::setup", "m_inlet_normal = " << m_inlet_normal);

        /* First, delete all walls that might hinder flow through the inlet. */
        list<Wall*> &walls = m_container->walls();
        for (list<Wall*>::iterator i = walls.begin(); i != walls.end(); ) {
            if (((*i)->normal() - m_inlet_normal).abs() < g_geom_eps) {
                /* Fixme!!! Does only work right now. */
                WallTriangle *wt = (WallTriangle*) (*i);
                bool del = true;

                for (int j = 0; j < 3; j++) {
                    //                    MSG_DEBUG("BoundarySTL::setup", "... = " << wt->corner(j)[dir] - coord);
                    if (abs(wt->corner(j)[dir] - coord) >= g_geom_eps)
                        del = false;
                }

                if (del) {
                    list<Wall*>::iterator d = i;
                    int vs[3];
                    i++;

                    //                    MSG_DEBUG("BoundarySTL::setup", "Deleting wall.");

                    for (int j = 0; j < 3; j++) {
                      vs[j] = m_inlet_base_surface.needVertex(wt->corner(j));
                    }

                    m_container->deleteWall(d);

                    m_inlet_base_surface.addWall
                      (new WallTriangle(&m_inlet_base_surface, NULL, vs[0], vs[1], vs[2]));
                } else
                    i++;
            } else
                i++;
        }

        /* Complicated version, add surfaces */

        MSG_DEBUG("BoundarySTL::setup", "Finding pairs.");
        vector< pair<int, int> > pairs;

        point_t middle_point = { { { 0, 0, 0 } } };
        size_t n_points = 0;
        for (list<Wall*>::iterator i = walls.begin(); i != walls.end(); i++) {
            WallTriangle *w = ((WallTriangle*) (*i));
            vector<int> corners;

            for (int j = 0; j < 3; j++) {
                if (abs(w->corner(j)[dir] - coord) < g_geom_eps)
                    corners.push_back(w->cornerVertex(j));
            }

            //            MSG_DEBUG("BoundarySTL::setup", "corners.size() = " << corners.size());
            if (corners.size() == 2) {
                pair<int, int> p;

                p.first = corners[0];
                p.second = corners[1];

                middle_point += m_container->vertex(p.first);
                middle_point += m_container->vertex(p.second);

                n_points += 2;

                pairs.push_back(p);
            } else if (corners.size() == 3)
                throw gError("BoundarySTL::setup", "FATAL: corners.size() = 3 -> should not happpen.");
        }

        middle_point /= n_points;

        MSG_DEBUG("BoundarySTL::setup", "pairs.size() = " << pairs.size());
        MSG_DEBUG("BoundarySTL::setup", "Creating walls.");
        vector<int> partners;
        partners.resize(m_container->vertices().size()+pairs.size(), -1);
        for (vector< pair<int, int> >::iterator i = pairs.begin(); i != pairs.end(); i++) {
            int a, b;
            point_t n1, n2, mv;

            a = i->first;
            b = i->second;

            if (partners[a] == -1) {
                point_t p = m_container->vertex(a);
                p += -m_inlet_length*m_inlet_normal;
                partners[a] = m_container->addVertex(p);
            }
            if (partners[b] == -1) {
                point_t p = m_container->vertex(b);
                p += -m_inlet_length*m_inlet_normal;
                partners[b] = m_container->addVertex(p);
            }

            n1 = (m_container->vertex(b)-m_container->vertex(a)).cross
              (m_container->vertex(partners[a])-m_container->vertex(b));
            n2 = (m_container->vertex(partners[a])-m_container->vertex(b)).cross
              (m_container->vertex(partners[b])-m_container->vertex(partners[a]));
            mv = middle_point-m_container->vertex(b);

            /* Does the vector n1 point towards the middle? */
            if (n1 * mv > 0) {
              m_container->addWall
                (new WallTriangle(m_container, m_container->reflector(),
                                  a, b, partners[a]));
            } else {
              m_container->addWall
                (new WallTriangle(m_container, m_container->reflector(),
                                  b, a, partners[a]));
            }

            /* Does the vector n2 point towards the middle? */
            if (n2 * mv > 0) {
              m_container->addWall
                (new WallTriangle(m_container, m_container->reflector(),
                                  b, partners[a], partners[b]));
            } else {
              m_container->addWall
                (new WallTriangle(m_container, m_container->reflector(),
                                  b, partners[b], partners[a]));
            }
        }

        /* Now, readd the closing surface */
        MSG_DEBUG("BoundarySTL::setup", "Readding closing surface.");

        for (list<Wall*>::iterator i = m_inlet_base_surface.walls().begin(); i != m_inlet_base_surface.walls().end(); ++i) {
          WallTriangle *wall = (WallTriangle*) *i;
          int v1, v2, v3;

          v1 = m_container->findVertex(wall->corner(0) - m_inlet_length * m_inlet_normal, g_geom_eps);
          v2 = m_container->findVertex(wall->corner(1) - m_inlet_length * m_inlet_normal, g_geom_eps);
          v3 = m_container->findVertex(wall->corner(2) - m_inlet_length * m_inlet_normal, g_geom_eps);

          m_container->addWall
            (new WallTriangle(m_container, m_container->reflector(),
                              v1, v2, v3));
        }

        /* Easy version */
/*        vector<point_t> &vertices = m_container->vertices();
        for (vector<point_t>::iterator i = vertices.begin(); i != vertices.end(); i++) {
            if (abs((*i)[dir] - coord) < g_geom_eps) {
                (*i)[dir] -= m_inlet_normal[dir]*m_inlet_length;
            }
            }*/

        m_container->vertexChanged();
        m_container->updateBoundingBox();
    
        m_proposedSize = m_container->boundingBox().corner2;
        
        // next will also call Boundary::setup => this may lead to addition of a frame
        BoundaryWithInlet::setup(sim, mgr);

        point_t inlet_c1, inlet_c2, r_c1, r_c2;

	Phase* phase = (Phase*) m_parent;

        if (m_inlet_pos_str == "bottom") {
            inlet_c1 = m_container->boundingBox().corner1;
            inlet_c2 = m_container->boundingBox().corner2;
            inlet_c2[dir] = inlet_c1[dir] + m_inlet_length;

            r_c1 = m_container->boundingBox().corner1;
//             r_c1[dir] += m_inlet_length;
            r_c2 = m_container->boundingBox().corner2;
            
            // take the frame into account if existent
            if(m_frontFrame[dir]) inlet_c2[dir] += phase->pairCreator()->interactionCutoff();
//             if(m_frontFrame[dir]) inlet_c2[dir] += sim->maxCutoff;

            r_c1[dir] = inlet_c2[dir];
                        
        } else {
            inlet_c1 = m_container->boundingBox().corner1;
            inlet_c2 = m_container->boundingBox().corner2;
            inlet_c1[dir] = inlet_c2[dir] - m_inlet_length;

            r_c1 = m_container->boundingBox().corner1;
            r_c2 = m_container->boundingBox().corner2;
//             r_c2[dir] -= m_inlet_length;
            
            // take the frame into account if existent
            if(m_endFrame[dir]) inlet_c1[dir] -= phase->pairCreator()->interactionCutoff();
//             if(m_endFrame[dir]) inlet_c1[dir] -= sim->maxCutoff;
            
            r_c2[dir] = inlet_c1[dir];
        }

                
        /* *New style* inlets with constant density */
//        periodic[dir] = true;
        periodic[dir] = false;
        inlet = mgr->cellSubdivide(sim->maxCutoff, inlet_c1, inlet_c2, periodic, 1, pc, 
          dir, (int) m_inlet_normal[dir], P_CREATE);

        pc->setRegion(inlet);

//        mgr->setPeriodicity(periodic);

        periodic[dir] = false;
        r = mgr->cellSubdivide(sim->maxCutoff, r_c1, r_c2, periodic, 0, pc, dir, 
          (int) -m_inlet_normal[dir], P_DELETE);
            
        MSG_DEBUG("BoundarySTL::setup", "r->n_cells = " << r->n_cells <<
                  ", inlet->n_cells = " << inlet->n_cells);

//        ManagerCell::connect
//            ((int) m_inlet_normal[dir]*dir-(m_inlet_normal[dir] < 0 ? 1 : 0), inlet, r, periodic, OUTLET);
        ManagerCell::connect
            ((int) m_inlet_normal[dir]*dir-(m_inlet_normal[dir] < 0 ? 1 : 0), inlet, r, periodic, NEIGHBOR);
    } else {
        m_proposedSize = m_container->boundingBox().corner2;
        
        // next could add a frame
        BoundaryWithInlet::setup(sim, mgr);

        r = mgr->cellSubdivide
          (sim->maxCutoff, m_container->boundingBox().corner1, m_container->boundingBox().corner2, periodic, 0);
    }

    mgr->cellSubdivisionFinished();
    
    mgr->assignContainer(m_container);
    
    int counter = 0;

    MSG_DEBUG("BoundarySTL::setup", "Writing geometry information to '" << m_geometry_filename << "'.");
    m_container->toVTK(m_geometry_filename);
}
コード例 #21
0
ファイル: load_Integration.C プロジェクト: lbaehren/lofarsoft
/*! This function assumes that the Integration will have the global
  attributes of the file. */
Pulsar::Integration* 
Pulsar::FITSArchive::load_Integration (const char* filename, unsigned isubint)
try {

  if (!filename)
    throw Error (InvalidParam, "FITSArchive::load_Integration",
		 "filename unspecified");

  if (search_mode)
    throw Error (InvalidParam, "FITSArchive::load_Integration",
		 "SEARCH mode data -- no Integrations to load");

  Reference::To<Pulsar::Integration> integ = new_Integration();
  init_Integration (integ);

  int row = isubint + 1;
  
  int status = 0;  

  if (verbose > 2)
    cerr << "FITSArchive::load_Integration number " << isubint << endl;
  
  double nulldouble = 0.0;
  float nullfloat = 0.0;
  
  int initflag = 0;
  int colnum = 0;
  
  // Open the file

  fitsfile* fptr = 0;
  
  if (verbose > 2)
    cerr << "FITSArchive::load_Integration"
      " fits_open_file (" << filename << ")" << endl;
  
  fits_open_file (&fptr, filename, READONLY, &status);
  
  if (status != 0)
    throw FITSError (status, "FITSArchive::load_Integration", 
		     "fits_open_file(%s)", filename);
  

  // Move to the SUBINT Header Data Unit
  
  fits_movnam_hdu (fptr, BINARY_TBL, "SUBINT", 0, &status);
  if (status != 0)
    throw FITSError (status, "FITSArchive::load_Integration", 
		     "fits_movnam_hdu SUBINT");


  // Load the convention for the epoch definition
  string epoch_def;
  string default_def = "STT_MJD";
  psrfits_read_key (fptr, "EPOCHS", &epoch_def,
		    default_def, verbose > 2);

  if (verbose > 2)
    cerr << "FITSArchive::load_Integration epochs are " << epoch_def << endl;

  // By default, correct epochs using the phase model
  bool correct_epoch_phase = true;

  // By default, correct epochs such that phase(epoch)=phase(start)
  bool phase_match_start_time = true;

  if (epoch_def == "VALID")
    correct_epoch_phase = phase_match_start_time = false;

  if (epoch_def == "MIDTIME")
    phase_match_start_time = false;

  if (get<Pulsar::IntegrationOrder>())
  {
    colnum = 0;
    fits_get_colnum (fptr, CASEINSEN, "INDEXVAL", &colnum, &status);
    
    double value = 0.0;

    fits_read_col (fptr, TDOUBLE, colnum, row, 1, 1, &nulldouble,
		   &value, &initflag, &status);
    
    if (status != 0)
      throw FITSError (status, "FITSArchive::load_Integration", 
		       "fits_read_col INDEXVAL");
    
    get<Pulsar::IntegrationOrder>()->set_Index(row-1,value);
  }
  
  // Get the reference epoch from the primary header
  const Pulsar::FITSHdrExtension* hdr_ext = get<Pulsar::FITSHdrExtension>();
  
  if (!hdr_ext)
  {
    throw Error (InvalidParam, "FITSArchive::load_Integration",
		 "No FITSHdrExtension found");
  }
  
  // Set the duration of the integration
  
  colnum = 0;
  fits_get_colnum (fptr, CASEINSEN, "TSUBINT", &colnum, &status);
  
  double duration = 0.0;
  
  fits_read_col (fptr, TDOUBLE, colnum, row, 1, 1, &nulldouble,
		 &duration, &initflag, &status);
  
  integ->set_duration (duration);

  // Set the start time of the integration
  
  initflag = 0;
  colnum = 0;
  
  fits_get_colnum (fptr, CASEINSEN, "OFFS_SUB", &colnum, &status);
  
  double time = 0.0;
  fits_read_col (fptr, TDOUBLE, colnum, row, 1, 1, &nulldouble,
		 &time, &initflag, &status);
  
  if (status != 0)
    throw FITSError (status, "FITSArchive::load_Integration", 
		     "fits_read_col OFFS_SUB");


  MJD epoch = hdr_ext->get_start_time() + time;

  if (verbose > 2)
    cerr << "Pulsar::FITSArchive::load_Integration"
      " header epoch=" << hdr_ext->get_start_time().printdays(13) << "\n "
      " offset=" << time << "s epoch=" << epoch.printdays(13) << endl;
  
  // Set a preliminary epoch to avoid problems loading the polyco
  integ->set_epoch (epoch);

  // Set the folding period to 0 until one of three possible methods succeeds
  integ->set_folding_period (0.0);

  /* **********************************************************************

     METHOD 1: folding period defined by a pulse phase model

     ********************************************************************** */

  if (hdr_model)
  {
    // Set the folding period, using the polyco from the file header
    // This was taken out of the condition clause below because period
    // wasn't set when TSUB was 0
    integ->set_folding_period (1.0 / hdr_model->frequency(epoch));

    if (integ->get_folding_period() <= 0.0)
      throw Error( InvalidState, "Pulsar::FITSArchive::load_Integration",
		   "header polyco/predictor corrupted; "
		   "period(epoch=%s)=%lf", epoch.printdays(5).c_str(),
		   integ->get_folding_period() );

    if (integ->get_folding_period() < 1.0e-3)
      warning << "Pulsar::FITSArchive::load_Integration folding_period=" 
	      << integ->get_folding_period() << " is less than 1ms" << endl;

    else if (verbose > 2)
      cerr << "Pulsar::FITSArchive::load_Integration folding_period = "
      	   << integ->get_folding_period () << endl;

    if (duration && correct_epoch_phase)
    {

      if (verbose > 2)
	cerr << "Pulsar::FITSArchive::load_Integration correcting epoch phase"
	     << endl;

      Phase reference_phs = 0.0;

      if (phase_match_start_time)
      {
	// Correct epoch such that its phase equals that of the start time
	if (verbose > 2)
	  cerr << "Pulsar::FITSArchive::load_Integration matching phase(start)"
	       << endl;

	reference_phs = hdr_model->phase(hdr_ext->get_start_time());
      }

      Phase off_phs = hdr_model->phase(epoch);
      Phase dphase  = off_phs - reference_phs;
      
      double dtime = dphase.fracturns() * integ->get_folding_period();
      epoch -= dtime;
      integ->set_epoch (epoch);

      if (verbose > 2)
      {
      	cerr << "Pulsar::FITSArchive::load_Integration row=" << row <<
	  "\n  PRED_PHS=" << predicted_phase;

	if (phase_match_start_time)
	  cerr << "\n  reference epoch=" 
	       << hdr_ext->get_start_time().printdays(13);

	cerr <<
	  "\n  reference phase=" << reference_phs <<
	  "\n      input phase=" << off_phs <<
	  "\n     phase offset=" << dphase << " = " << dtime << "s" 
	  "\n     subint epoch=" << epoch.printdays(13) << 
	  "\n     subint phase=" << hdr_model->phase(epoch) << endl;
      }
    }
  }
  else
  {

    /* *******************************************************************

       METHOD 2: folding period defined by CAL_FREQ in primary header

       ******************************************************************* */

    CalInfoExtension* calinfo = get<CalInfoExtension>();
    if (calinfo && calinfo->cal_frequency > 0.0)
    {
      if (verbose > 2)
        cerr << "FITSArchive::load_Integration CAL_FREQ=" 
	     << calinfo->cal_frequency << endl;
      integ->set_folding_period( 1.0/calinfo->cal_frequency );
    }

    /* *******************************************************************

       METHOD 3: folding period defined by PERIOD column of SUBINT HDU

       ******************************************************************* */

    double period = 0.0;
    status = 0;
    fits_get_colnum (fptr, CASEINSEN, "PERIOD", &colnum, &status);
    fits_read_col (fptr, TDOUBLE, colnum, row, 1, 1, &nulldouble,
                   &period, &initflag, &status);

    if (status == 0 && period > 0.0)
    {
      if (verbose > 2)
	cerr << "FITSArchive::load_Integration PERIOD=" << period << endl;
      integ->set_folding_period (period);
    }

    if (integ->get_folding_period() == 0.0)
      throw FITSError (status, "FITSArchive::load_Integration",
                       "folding period unknown: no model, CAL_FREQ or PERIOD");
  }

  status = 0;

  // Load other useful info

  load_Pointing (fptr,row,integ);
  load_Plasma (fptr,row,integ);

  // Set up the data vector, only Pulsar::Archive base class is friend

  resize_Integration (integ);

  const unsigned nchan = get_nchan();

  if (naux_profile)
    for (unsigned ichan=0; ichan < nchan; ichan++)
    {
      FourthMoments* fourth = new FourthMoments;
      fourth->resize (naux_profile, get_nbin());
      integ->get_Profile(0,ichan)->add_extension (fourth);
    }

  // Load the channel centre frequencies
  
  if (verbose > 2)
    cerr << "Pulsar::FITSArchive::load_Integration reading channel freqs" 
	 << endl;
  
  int counter = 1;
  vector < float >  chan_freqs(get_nchan());
  
  colnum = 0;
  fits_get_colnum (fptr, CASEINSEN, "DAT_FREQ", &colnum, &status);
  
  fits_read_col (fptr, TFLOAT, colnum, row, counter, get_nchan(),
		 &nullfloat, &(chan_freqs[0]), &initflag, &status);

  if (status != 0)
    throw FITSError (status, "FITSArchive::load_Integration",
                     "fits_read_col DAT_FREQ");

  // Set the profile channel centre frequencies
  
  if (verbose > 2)
    cerr << "Pulsar::FITSArchive::load_Integration setting frequencies" 
	 << endl;

  bool all_ones = true;
  for (unsigned j = 0; j < get_nchan(); j++)
    if (chan_freqs[j] != 1)
      all_ones = false;
  
  double chanbw = get_bandwidth() / get_nchan();
  
  if ( all_ones )
  {
    if (verbose > 2)
      cerr << "FITSArchive::load_Integration all frequencies unity - reseting"
	   << endl;
    for (unsigned j = 0; j < get_nchan(); j++)
      integ->set_centre_frequency (j, get_centre_frequency()
				   -0.5*(get_bandwidth()+chanbw)+j*chanbw);
  }
  else
  {
    for (unsigned j = 0; j < get_nchan(); j++)
      integ->set_centre_frequency(j, chan_freqs[j]);
  }
  
  // Load the profile weights

  if (verbose > 2)
    cerr << "Pulsar::FITSArchive::load_Integration reading weights" 
	 << endl;
  
  counter = 1;
  vector < float >  weights(get_nchan());
  
  colnum = 0;
  fits_get_colnum (fptr, CASEINSEN, "DAT_WTS", &colnum, &status);
  
  for (unsigned b = 0; b < get_nchan(); b++) {
    fits_read_col (fptr, TFLOAT, colnum, row, counter, 1, &nullfloat, 
		   &weights[b], &initflag, &status);
    counter ++;
  }

  if (status != 0)
    throw FITSError (status, "FITSArchive::load_Integration",
                     "fits_read_col DAT_WTS");

  // Set the profile weights
  
  if (verbose > 2)
    cerr << "Pulsar::FITSArchive::load_Integration setting weights" 
	 << endl;
  
  for(unsigned j = 0; j < get_nchan(); j++)
    integ->set_weight(j, weights[j]);
  
  // Load the profile offsets
  
  if (!Profile::no_amps)
  {
    vector<Profile*> profiles;

    setup_profiles_dat (integ, profiles);
    setup_dat (fptr, load_dat_io);

    if (verbose > 2)
      cerr << "FITSArchive::load_Integration dat_io=" << load_dat_io.ptr()
           << endl;

    load_dat_io->load (isubint + 1, profiles);

    if (scale_cross_products && integ->get_state() == Signal::Coherence)
      for (unsigned ichan=0; ichan < get_nchan(); ichan++)
      {
	integ->get_Profile(2, ichan)->scale(2.0);
	integ->get_Profile(3, ichan)->scale(2.0);
      }

    if (naux_profile)
    {
      setup_profiles<MoreProfiles> (integ, profiles);
      setup_aux (fptr, load_aux_io, naux_profile);
      load_aux_io->load (isubint + 1, profiles);
    }
  }

  if (verbose > 2)
    cerr << "Pulsar::FITSArchive::load_Integration load complete" << endl;  
  
  // Finished with the file for now
  
  fits_close_file (fptr, &status);

  return integ.release();
}
catch (Error& error)
{
  throw error += "Pulsar::FITSArchive::load_Integration";
}
コード例 #22
0
ファイル: Base.cpp プロジェクト: BoostedColliderAnalysis/BoCA
std::string Base::BranchName(Phase const& phase) const
{
    INFO0;
    return Name(phase.Stage());
}
コード例 #23
0
ファイル: interaction.cpp プロジェクト: loczaj/simulbody
void Interaction::calculateRelativePosition(const Phase &x) {
	relativePosition = x.getBodyPosition(moon);
	relativePosition -= x.getBodyPosition(earth);
}