Пример #1
0
bool wxLaunchDefaultApplication(const wxString& document, int flags)
{
    wxUnusedVar(flags);

    wxCFRef<CFMutableStringRef> cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(document)));
    CFStringNormalize(cfMutableString,kCFStringNormalizationFormD);
    wxCFRef<CFURLRef> curl(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false));
    OSStatus err = LSOpenCFURLRef( curl , NULL );

    if (err == noErr)
    {
        return true;
    }
    else
    {
        wxLogDebug(wxT("Default Application Launch error %d"), (int) err);
        return false;
    }
}
Пример #2
0
/*
 * This routine is in charge of the magnetic induction equation.  Virtually all
 * of the terms can be enabled or disabled by parameters read in through the
 * configuration file.  This equation has the form:
 * 
 * dB/dt = curl(u cross B) + Pm/Pr*del^2 B + F_B 
 * 
 * Again we have an incompressible field, so after evaluating the force in 
 * vector notation, we decompose it into poloidal and toroidal scalar fields for
 * the time integration.
 */
void calcMag()
{
    int i,j,k;
    int index;
    debug("Calculating Magnetic forces\n");

    if(magDiff)
    {
        laplacian(B->vec->x->spectral, rhs->x->spectral, 0, Pr/Pm);
        laplacian(B->vec->y->spectral, rhs->y->spectral, 0, Pr/Pm);
        laplacian(B->vec->z->spectral, rhs->z->spectral, 0, Pr/Pm);
    }
    else
    {
        //make sure we don't start with garbage
        memset(rhs->x->spectral, 0, spectralCount * sizeof(complex PRECISION));
        memset(rhs->y->spectral, 0, spectralCount * sizeof(complex PRECISION));
        memset(rhs->z->spectral, 0, spectralCount * sizeof(complex PRECISION));
    }
    
    //Apply hyper diffusion to the boundaries.  Again, this does not currently
    //work!
    if(sanitize)
    {
        killBoundaries(B->vec->x->spatial, rhs->x->spectral, 1, 100*Pr/Pm);
        killBoundaries(B->vec->y->spatial, rhs->y->spectral, 1, 100*Pr/Pm);
        killBoundaries(B->vec->z->spatial, rhs->z->spectral, 1, 100*Pr/Pm);
    }

    //static forcing is currently only in the x direction and a function of y and z
    if(magStaticForcing)
    {
        complex PRECISION * xfield = rhs->x->spectral;
        complex PRECISION * ffield = magForceField->spectral;
        index = 0;
        for(i = 0; i < spectralCount; i++)
        {
            xfield[i] += ffield[i];
        }
    }
    
    //If we are doing the kinematic problem then the velocity field is
    //specified ahead of time.  Note, this conflicts with the momentum equation
    //being enabled.  If both momentum equation and kinematic are enabled, then
    //we will still be doing all the work of both, but right here we will erase
    //any work previously done on the momentum equation, at least insofar as
    //the magnetic field is concerned.
    if(kinematic)
    {
        fillTimeField(u->vec, KINEMATIC);
    }

    //This is really the induction term, not advection, though it does contain
    //advection effects within it.
    if(magAdvect)
    {
        p_vector uxb = temp1;
        p_vector cuxb = temp2;

        crossProduct(u->vec, B->vec, uxb);
        fftForward(uxb->x);
        fftForward(uxb->y);
        fftForward(uxb->z);

        curl(uxb, cuxb);

        plusEq(rhs->x->spectral, cuxb->x->spectral);
        plusEq(rhs->y->spectral, cuxb->y->spectral);
        plusEq(rhs->z->spectral, cuxb->z->spectral);
    }

    if(magTimeForcing)
    {
        fillTimeField(temp1, MAGNETIC);

        plusEq(rhs->x->spectral, temp1->x->spectral);
        plusEq(rhs->y->spectral, temp1->y->spectral);
        plusEq(rhs->z->spectral, temp1->z->spectral);
    }

    //The 1 means we store the result in the force vectors.
    decomposeSolenoidal(B->sol, rhs, 1);
    debug("Magnetic forces done\n");
}
Пример #3
0
bool CPlexClient::ParseSections(PlexSectionParsing parser)
{
  bool rtn = false;
  XFILE::CCurlFile plex;
  plex.SetBufferSize(32768*10);
  plex.SetTimeout(10);

  CURL curl(m_url);
  curl.SetFileName(curl.GetFileName() + "library/sections");
  std::string strResponse;
  if (plex.Get(curl.Get(), strResponse))
  {
#if defined(PLEX_DEBUG_VERBOSE)
    if (parser == PlexSectionParsing::newSection || parser == PlexSectionParsing::checkSection)
      CLog::Log(LOGDEBUG, "CPlexClient::ParseSections %d, %s", parser, strResponse.c_str());
#endif
    if (parser == PlexSectionParsing::updateSection)
    {
      {
        CSingleLock lock(m_criticalMovies);
        m_movieSectionsContents.clear();
      }
      {
        CSingleLock lock(m_criticalTVShow);
        m_showSectionsContents.clear();
      }
      m_needUpdate = false;
    }

    TiXmlDocument xml;
    xml.Parse(strResponse.c_str());

    TiXmlElement* MediaContainer = xml.RootElement();
    if (MediaContainer)
    {
      const TiXmlElement* DirectoryNode = MediaContainer->FirstChildElement("Directory");
      while (DirectoryNode)
      {
        PlexSectionsContent content;
        content.uuid = XMLUtils::GetAttribute(DirectoryNode, "uuid");
        content.path = XMLUtils::GetAttribute(DirectoryNode, "path");
        content.type = XMLUtils::GetAttribute(DirectoryNode, "type");
        content.title = XMLUtils::GetAttribute(DirectoryNode, "title");
        content.updatedAt = XMLUtils::GetAttribute(DirectoryNode, "updatedAt");
        std::string key = XMLUtils::GetAttribute(DirectoryNode, "key");
        content.section = "library/sections/" + key;
        content.thumb = XMLUtils::GetAttribute(DirectoryNode, "composite");
        std::string art = XMLUtils::GetAttribute(DirectoryNode, "art");
        if (m_local)
          content.art = art;
        else
          content.art = content.section + "/resources/" + URIUtils::GetFileName(art);
        if (content.type == "movie")
        {
          if (parser == PlexSectionParsing::checkSection)
          {
            CSingleLock lock(m_criticalMovies);
            for (const auto &contents : m_movieSectionsContents)
            {
              if (contents.uuid == content.uuid)
              {
                if (contents.updatedAt != content.updatedAt)
                {
#if defined(PLEX_DEBUG_VERBOSE)
                  CLog::Log(LOGDEBUG, "CPlexClient::ParseSections need update on %s:%s",
                    m_serverName.c_str(), content.title.c_str());
#endif
                  m_needUpdate = true;
                }
              }
            }
          }
          else
          {
            CSingleLock lock(m_criticalMovies);
            m_movieSectionsContents.push_back(content);
          }
        }
        else if (content.type == "show")
        {
          if (parser == PlexSectionParsing::checkSection)
          {
            CSingleLock lock(m_criticalTVShow);
            for (const auto &contents : m_showSectionsContents)
            {
              if (contents.uuid == content.uuid)
              {
                if (contents.updatedAt != content.updatedAt)
                {
#if defined(PLEX_DEBUG_VERBOSE)
                  CLog::Log(LOGDEBUG, "CPlexClient::ParseSections need update on %s:%s",
                    m_serverName.c_str(), content.title.c_str());
#endif
                  m_needUpdate = true;
                }
              }
            }
          }
          else
          {
            CSingleLock lock(m_criticalTVShow);
            m_showSectionsContents.push_back(content);
          }
        }
        else if (content.type == "artist")
        {
          if (parser == PlexSectionParsing::checkSection)
          {
            CSingleLock lock(m_criticalArtist);
            for (const auto &contents : m_artistSectionsContents)
            {
              if (contents.uuid == content.uuid)
              {
                if (contents.updatedAt != content.updatedAt)
                {
#if defined(PLEX_DEBUG_VERBOSE)
                  CLog::Log(LOGDEBUG, "CPlexClient::ParseSections need update on %s:%s",
                            m_serverName.c_str(), content.title.c_str());
#endif
                  m_needUpdate = true;
                }
              }
            }
          }
          else
          {
            CSingleLock lock(m_criticalArtist);
            m_artistSectionsContents.push_back(content);
          }
        }
        else if (content.type == "photo")
        {
          if (parser == PlexSectionParsing::checkSection)
          {
            CSingleLock lock(m_criticalPhoto);
            for (const auto &contents : m_photoSectionsContents)
            {
              if (contents.uuid == content.uuid)
              {
                if (contents.updatedAt != content.updatedAt)
                {
#if defined(PLEX_DEBUG_VERBOSE)
                  CLog::Log(LOGDEBUG, "CPlexClient::ParseSections need update on %s:%s",
                            m_serverName.c_str(), content.title.c_str());
#endif
                  m_needUpdate = true;
                }
              }
            }
          }
          else
          {
            CSingleLock lock(m_criticalPhoto);
            m_photoSectionsContents.push_back(content);
          }
        }
        else
        {
          CLog::Log(LOGDEBUG, "CPlexClient::ParseSections %s found unhandled content type %s",
            m_serverName.c_str(), content.type.c_str());
        }
        DirectoryNode = DirectoryNode->NextSiblingElement("Directory");
      }

      CLog::Log(LOGDEBUG, "CPlexClient::ParseSections %s found %d movie sections",
        m_serverName.c_str(), (int)m_movieSectionsContents.size());
      CLog::Log(LOGDEBUG, "CPlexClient::ParseSections %s found %d shows sections",
        m_serverName.c_str(), (int)m_showSectionsContents.size());
      CLog::Log(LOGDEBUG, "CPlexClient::ParseSections %s found %d artist sections",
                m_serverName.c_str(), (int)m_artistSectionsContents.size());
      CLog::Log(LOGDEBUG, "CPlexClient::ParseSections %s found %d photo sections",
                m_serverName.c_str(), (int)m_photoSectionsContents.size());

      rtn = true;
    }
    else
    {
      CLog::Log(LOGDEBUG, "CPlexClient::ParseSections no MediaContainer found");
    }
  }
  else
  {
    // 401's are attempts to access a local server that is also in PMS
    // and these require an access token. Only local servers that are
    // not is PMS can be accessed via GDM.
    if (plex.GetResponseCode() != 401)
      CLog::Log(LOGDEBUG, "CPlexClient::ParseSections failed %s", strResponse.c_str());
    rtn = false;
  }

  return rtn;
}
Пример #4
0
/*
 * This routine is in charge of the momentum equation.  Virtually all
 * of the terms can be enabled or disabled by parameters read in through the
 * configuration file.  This equation has the form:
 * 
 * du/dt = div(alpha BB - uu - P) + (Ra T + B^2 / beta) hat z + Pr del^2 u + F_u 
 * 
 * Since the velocity field is incompressible, the pressure term doesn't matter
 * and is eliminated by taking the curl of the right-hand side.  This is then
 * decomposed into poloidal and toroidal components, which are then used in the
 * time integration.
 */
void calcMomentum()
{
    debug("Calculating momentum forces\n");

    int i,j,k;
    int index;

    if(viscosity)
    {
        //First argument is the field we take the laplacian of.
        //Second argument is where the result is stored.
        //The 0 in the third argument means we overwrite the destination array
        //Pr is the coefficient for this diffusion term.
        laplacian(u->vec->x->spectral, rhs->x->spectral, 0, Pr);
        laplacian(u->vec->y->spectral, rhs->y->spectral, 0, Pr);
        laplacian(u->vec->z->spectral, rhs->z->spectral, 0, Pr);
    }
    else
    {
        //make sure we don't start with garbage
        memset(rhs->x->spectral, 0, spectralCount * sizeof(complex PRECISION));
        memset(rhs->y->spectral, 0, spectralCount * sizeof(complex PRECISION));
        memset(rhs->z->spectral, 0, spectralCount * sizeof(complex PRECISION));
    }
    
    //Apply hyper diffusion to the boundaries
    //This does not currently work and is disabled by default!
    if(sanitize)
    {
        killBoundaries(u->vec->x->spatial, rhs->x->spectral, 1, 100*Pr);
        killBoundaries(u->vec->y->spatial, rhs->y->spectral, 1, 100*Pr);
        killBoundaries(u->vec->z->spatial, rhs->z->spectral, 1, 100*Pr);
    }

    //static forcing is read in from a file and currently only in the u 
    //direction as a function of y and z (to remove nonlinear advection)
    if(momStaticForcing)
    {
        complex PRECISION * xfield = rhs->x->spectral;
        complex PRECISION * ffield = forceField->spectral;
        index = 0;
        for(i = 0; i < spectralCount; i++)
        {
            xfield[i] += ffield[i];
        }
    }

    //
    if(momTimeForcing)
    {
        //Evaluate the force function at the current time.
        fillTimeField(temp1, MOMENTUM);

        plusEq(rhs->x->spectral, temp1->x->spectral);
        plusEq(rhs->y->spectral, temp1->y->spectral);
        plusEq(rhs->z->spectral, temp1->z->spectral);
    }

    
    if(momAdvection)
    {
        p_field tense = temp1->x;

	    //Note here, because I already forgot once.  a 2 as the third
	    //parameter makes things behave as a -= operation!
        multiply(u->vec->x->spatial, u->vec->x->spatial, tense->spatial);
        fftForward(tense);
        partialX(tense->spectral, rhs->x->spectral, 2);

        multiply(u->vec->y->spatial, u->vec->y->spatial, tense->spatial);
        fftForward(tense);
        partialY(tense->spectral, rhs->y->spectral, 2);

        multiply(u->vec->z->spatial, u->vec->z->spatial, tense->spatial);
        fftForward(tense);
        partialZ(tense->spectral, rhs->z->spectral, 2);

        multiply(u->vec->x->spatial, u->vec->y->spatial, tense->spatial);
        fftForward(tense);
        partialY(tense->spectral, rhs->x->spectral, 2);
        partialX(tense->spectral, rhs->y->spectral, 2);

        multiply(u->vec->x->spatial, u->vec->z->spatial, tense->spatial);
        fftForward(tense);
        partialZ(tense->spectral, rhs->x->spectral, 2);
        partialX(tense->spectral, rhs->z->spectral, 2);

        multiply(u->vec->y->spatial, u->vec->z->spatial, tense->spatial);
        fftForward(tense);
        partialZ(tense->spectral, rhs->y->spectral, 2);
        partialY(tense->spectral, rhs->z->spectral, 2);      
    }


    if(lorentz)
    {
        p_field tense = temp1->x;
        p_vector lor = temp2;

        //The third parameter as a 0 means we overwrite the destination array.
        //The third parameter as a 1 means it behaves as a += operation.
        
        multiply(B->vec->x->spatial, B->vec->x->spatial, tense->spatial);
        fftForward(tense);
        partialX(tense->spectral, lor->x->spectral, 0);

        multiply(B->vec->y->spatial, B->vec->y->spatial, tense->spatial);
        fftForward(tense);
        partialY(tense->spectral, lor->y->spectral, 0);

        multiply(B->vec->z->spatial, B->vec->z->spatial, tense->spatial);
        fftForward(tense);
        partialZ(tense->spectral, lor->z->spectral, 0);

        multiply(B->vec->x->spatial, B->vec->y->spatial, tense->spatial);
        fftForward(tense);
        partialY(tense->spectral, lor->x->spectral, 1);
        partialX(tense->spectral, lor->y->spectral, 1);

        multiply(B->vec->x->spatial, B->vec->z->spatial, tense->spatial);
        fftForward(tense);
        partialZ(tense->spectral, lor->x->spectral, 1);
        partialX(tense->spectral, lor->z->spectral, 1);

        multiply(B->vec->y->spatial, B->vec->z->spatial, tense->spatial);
        fftForward(tense);
        partialZ(tense->spectral, lor->y->spectral, 1);
        partialY(tense->spectral, lor->z->spectral, 1);

        //TODO: Find a routine to change to include this factor
        complex PRECISION * px = lor->x->spectral;
        complex PRECISION * py = lor->y->spectral;
        complex PRECISION * pz = lor->z->spectral;
        int i;
        for(i = 0; i < spectralCount; i++)
        {
            px[i] *= alpha;
            py[i] *= alpha;
            pz[i] *= alpha;
        }

        plusEq(rhs->x->spectral, px);
        plusEq(rhs->y->spectral, py);
        plusEq(rhs->z->spectral, pz);
    }
    
    if(magBuoy)
    {
        p_field B2 = temp1->x;
        dotProduct(B->vec,B->vec,B2);
        fftForward(B2);
        for(i = 0; i < spectralCount; i++)
        {
            B2->spectral[i] *= magBuoyScale;
        }
        plusEq(rhs->z->spectral, B2->spectral);
    }

    if(buoyancy)
    {
        complex PRECISION * zfield = rhs->z->spectral;
        complex PRECISION * tfield = T->spectral;

        PRECISION factor =  Ra * Pr;
        index = 0;
        for(i = 0; i < spectralCount; i++)
        {
            zfield[i] += factor * tfield[i];
        }
    }
    
    //curl it so we can avoid dealing with the pressure term
    curl(rhs, temp1);

    //The third parameter as a 1 means we store the result in the force
    //arrays for u->sol.
    decomposeCurlSolenoidal(u->sol, temp1, 1);
    debug("Momentum forces done\n");
}
Пример #5
0
void loop(){
   WiServer.server_task();
   wag();
   curl();
}
Пример #6
0
int main(int __unused argc, char* argv[])
{
  char* url = argv[1];
  char* filename;
  char** target_url;
  char** filename_parts;
  int* n_filename_parts;
  int* n_matches;

  blob_t blob;
  blob.memory = malloc(1); /* will be grown as needed by the realloc above */
  blob.size = 0;

  // request the whole page content
  curl(url, write_memory_callback, &blob);

  // extract iframe url
  extract_str(blob.memory, "<iframe src=['\"]([^']+)['\"].*tumblr_video_iframe[^>]+>", &target_url, &n_matches);

  // reset the blob
  free(blob.memory);
  blob.memory = malloc(1); /* will be grown as needed by the realloc above */
  blob.size = 0;

  // request the iframe content
  curl(target_url[1], write_memory_callback, &blob);

  // free iframe url data
  for (int i=0; i < *n_matches; i++) free(target_url[i]);
  free(target_url);
  free(n_matches);

  // extract filename from original post url
  extract_str(url, "^https?://([^/]+)/post/([0-9]+).*$", &filename_parts, &n_filename_parts);
  asprintf(&filename, "%s-%s.mp4", filename_parts[1], filename_parts[2]);

  // free filename extraction data
  for (int i=0; i < *n_filename_parts; i++) free(filename_parts[i]);
  free(filename_parts);
  free(n_filename_parts);

  // extract video url from iframe content
  extract_str(blob.memory, "<source src=['\"]([^\"]+)['\"][^>]+>", &target_url, &n_matches);

  // free iframe data
  free(blob.memory);

  // create a file to write the video
  FILE* file = fopen(filename, "wb");

  // free video filename data
  free(filename);

  // write the video to a file
  curl(target_url[1], write_file_callback, file);
  fclose(file);

  // free video url data
  for (int i=0; i < *n_matches; i++) free(target_url[i]);
  free(target_url);
  free(n_matches);

  return 0;
}
Пример #7
0
//------------------------------------------------------------------------------
// private:
//------------------------------------------------------------------------------
void
Score::_updateScore()
{
    Config & config( Engine::instance()->getConfig() );

    if ( ! config.leaderboard )
    {
        _updateScoreDB();
        return;
    }

    hgeFont * font( Engine::rm()->GetFont( "menu" ) );
    CURL * curl( curl_easy_init() );

    if ( curl == 0 )
    {
        _updateScoreDB();
        return;
    }

    char buffer[65536];
    buffer[0] = '\0';

#ifdef _DEBUG
    m_error = m_error || 0 != curl_easy_setopt( curl, CURLOPT_URL,
              "http://gamejam.org/teams/KranzkySoftware/scores/" );
#else
    m_error = m_error || 0 != curl_easy_setopt( curl, CURLOPT_URL,
              "http://gamejam.org/teams/BrownCloud/scores/" );
#endif
    m_error = m_error || 0 != curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION,
              writer );
    m_error = m_error || 0 != curl_easy_setopt( curl, CURLOPT_WRITEDATA, buffer );
    m_error = m_error || 0 != curl_easy_perform( curl );

    curl_easy_cleanup( curl );

    if ( m_error )
    {
        _updateScoreDB();
        return;
    }

    m_high_score.clear();

    std::stringstream stream( buffer );
    char line[256];
    while ( stream.getline( line, 255 ) )
    {
        char name[16];
        int value( 0 );
        char timestamp[64];
        sscanf_s( line, "%[a-zA-Z0-9]:%d:%[^:]", name, 16, & value,
                  timestamp, 64 );
        ScoreData data;
        data.name = name;
        data.value = value;
        data.timestamp = timestamp;
        data.clipped = false;
        m_high_score.push_back( data );
    }
}
Пример #8
0
//------------------------------------------------------------------------------
void
Score::_insertScore( const char * name, int value )
{
    Config & config( Engine::instance()->getConfig() );

    if ( ! config.leaderboard )
    {
        _insertScoreDB( name, value );
        return;
    }

    CURL * curl( curl_easy_init() );

    if ( curl == 0 )
    {
        _insertScoreDB( name, value );
        return;
    }

    struct curl_httppost * form( 0 );
    struct curl_httppost * last( 0 );
    char stringValue[64];

    sprintf_s( stringValue, 63, "%d", value );

    m_error = m_error || 0 != curl_formadd( & form, & last, CURLFORM_COPYNAME,
                                            "tag", CURLFORM_COPYCONTENTS, name,
                                            CURLFORM_END );
    m_error = m_error || 0 != curl_formadd( & form, & last, CURLFORM_COPYNAME,
                                            "value", CURLFORM_COPYCONTENTS,
                                            stringValue, CURLFORM_END );
#ifdef _DEBUG
    m_error = m_error || 0 != curl_formadd( & form, & last, CURLFORM_COPYNAME,
                                            "key", CURLFORM_COPYCONTENTS,
                                            "5ddc27012824dadf705049e39386f1c9",
                                            CURLFORM_END );
    m_error = m_error || 0 != curl_easy_setopt( curl, CURLOPT_URL,
              "http://gamejam.org/teams/KranzkySoftware/setscore/" );
#else
    m_error = m_error || 0 != curl_formadd( & form, & last, CURLFORM_COPYNAME,
                                            "key", CURLFORM_COPYCONTENTS,
                                            "79df3c86a699f13c35177e2ce82b8284",
                                            CURLFORM_END );
    m_error = m_error || 0 != curl_easy_setopt( curl, CURLOPT_URL,
              "http://gamejam.org/teams/BrownCloud/setscore/" );
#endif

    m_error = m_error || 0 != curl_easy_setopt( curl, CURLOPT_HTTPPOST, form );
    m_error = m_error || 0 != curl_easy_perform( curl );

    if ( form != 0 )
    {
        curl_formfree( form );
    }
    curl_easy_cleanup( curl );

    if ( m_error )
    {
        _insertScoreDB( name, value );
    }
}
void VortexConfinement2D::applyImpl(SimObject::Ptr so, float dt)
{
	timer.start();

	if (m_vortField == 0)
	{
		qCritical() << "vortex confinement: no field set!";
		return;
	}

	qDebug() << "apply: vortex confinement";

	vel_x = so->getSubData<VectorField>(m_vortField)->getScalarField(0);
	vel_y = so->getSubData<VectorField>(m_vortField)->getScalarField(1);
	vel_z = so->getSubData<VectorField>(m_vortField)->getScalarField(2);


	CloudData::Ptr cd = std::dynamic_pointer_cast<CloudData>(so);

	math::V3i res = vel_x->getResolution();
	res = math::V3i(res.x-1,res.y,res.z);


	// TODO:
	//Scalar Field to Vector if Vort in 3D

	// create vorticity field
	ScalarField::Ptr vorticity;

	ScalarField::Ptr vortForce_x = std::make_shared<ScalarField>();
	vortForce_x->resize(res);
	ScalarField::Ptr vortForce_y = std::make_shared<ScalarField>();
	vortForce_y->resize(res);

	if(so->hasSubData("vorticity") )
	{
		vorticity = so->getSubData<ScalarField>( "vorticity" );
		//vortForce_x = so->getSubData<VectorField>("vortForce_x");
		//vortForce_y = so->getSubData<VectorField>("vortForce_y");
	}
	else
	{
		vorticity =std::make_shared<ScalarField>();
		vorticity->resize(res);
		so->addSubData( "vorticity", vorticity );


		//so->addSubData( "vortForce", vortForce);
	}



	float nab_nx, nab_ny, mag_n, nx, ny;
	int k = 0;

	//Calculate vorticity magnitude field = n
	for (int i=0; i<res.x; i++)
		for (int j=0; j<res.y; j++){
			vorticity->lvalue(i,j,k)= curl(i,j,k);
		}


	//Calculate vorticity Gradient N = (nabla n) / ||n||
	//for( int k=2;k<res.z-3;++k )
		for( int j=1;j<res.y-1;++j )
			for( int i=1;i<res.x-1;++i )
			{

/*
				// vorticity gradient X face ---
				// back diff
				nX_x = abs(vorticity->lvalue(i,j,k)) - abs(vorticity->lvalue(i-1,j,k));
				//nX_y = ((abs(vorticity->lvalue(i-1,j+1,k))+abs(vorticity->lvalue(i,j+1,k))+abs(vorticity->lvalue(i-1,j,k))+abs(vorticity->lvalue(i,j,k)))/4-
				//		(abs(vorticity->lvalue(i,j-1,k))+abs(vorticity->lvalue(i-1,j-1,k))+abs(vorticity->lvalue(i-1,j,k))+abs(vorticity->lvalue(i,j,k)))/4);
				nX_y = abs(vorticity->evaluate(math::V3f(i,j+1,k)))-abs(vorticity->evaluate(math::V3f(i,j,k)));

				//if (nX_y != nX_y2 && abs(nX_y - nX_y2 )> 0.00001f )
				//	qCritical() << i << j << "diff: " << abs(nX_y - nX_y2 );


				float mag_nX = (float) sqrt(nX_x*nX_x + nX_y*nX_y);
				if(mag_nX > 0.00001f)
				{
					ny = nX_y / mag_nX;
					vel_x->lvalue(i,j,k) +=	-	ny * ( vorticity->lvalue(i,j,k) + vorticity->lvalue(i-1,j,k) ) * 0.5f * m_strenght * dt;
				}


				// vorticity gradient Y face ---
				// back diff
				nY_y = abs(vorticity->lvalue(i,j,k)) - abs(vorticity->lvalue(i,j-1,k));
				//nY_x = ((abs(vorticity->lvalue(i+1,j,k))+abs(vorticity->lvalue(i+1,j+1,k))+abs(vorticity->lvalue(i,j+1,k))+abs(vorticity->lvalue(i,j,k)))/4-
				//		(abs(vorticity->lvalue(i-1,j,k))+abs(vorticity->lvalue(i-1,j+1,k))+abs(vorticity->lvalue(i,j+1,k))+abs(vorticity->lvalue(i,j,k)))/4);
				nY_x = abs(vorticity->evaluate(math::V3f(i+1,j,k)))-abs(vorticity->evaluate(math::V3f(i,j,k)));

				float mag_nY = (float) sqrt(nY_y*nY_y + nY_x*nY_x);
				if(mag_nY > 0.00001f)
				{
					nx = nY_x / mag_nY;
					vel_y->lvalue(i,j,k) +=		nx * ( vorticity->lvalue(i,j,k) + vorticity->lvalue(i,j-1,k) ) * 0.5f * m_strenght * dt;
				}
*/

				//calc nabla n for x and y by central difference
				nab_nx = (abs(vorticity->lvalue(i+1,j,k)) - abs(vorticity->lvalue(i-1,j,k)));
				nab_ny = (abs(vorticity->lvalue(i,j+1,k)) - abs(vorticity->lvalue(i,j-1,k)));

				//calculate magnitude of the vector (nab_nx , nab_ny)
				//add small value to prevent divide by zero
				mag_n = (float) sqrt(nab_nx*nab_nx + nab_ny*nab_ny) + 0.00000001f;

				// normalize vector ->  N = (nabla n) / ||n||
				nx = nab_nx / mag_n;
				ny = nab_ny / mag_n;

				vortForce_x->lvalue(i,j,k) = -	ny * vorticity->lvalue(i,j,k);
				vortForce_y->lvalue(i,j,k) =	nx * vorticity->lvalue(i,j,k);
			}

		for( int j=2;j<res.y-2;++j )
			for( int i=2;i<res.x-2;++i )
			{
				if( !m_onCloudOnly || cd->getSubData<ScalarField>("qc")->lvalue(i,j,k)>0.000001f)
				{
					vel_x->lvalue(i,j,k) +=		0.5*(vortForce_x->lvalue(i,j,k) + vortForce_x->lvalue(i-1,j,k) ) * m_strength * dt;
					vel_y->lvalue(i,j,k) +=		0.5*(vortForce_y->lvalue(i,j,k) + vortForce_y->lvalue(i,j-1,k) ) * m_strength * dt;

				}
			}

		cd->setBounds2D(1,vel_x);
		cd->setBounds2D(2,vel_y);


		timer.stop();
		qCritical() << "VortexConfine:" << core::getVariable("$F").toString() << ":" << timer.elapsedSeconds();

}
Пример #10
0
void HttpConnection::sendAsyncHttpRequestWithoutBodyWithoutVerify(std::shared_ptr<const HttpRequest> pRequest, std::shared_ptr<HttpResponse> pResponse, std::shared_ptr<std::string> pError)
{
    std::shared_ptr<CURL> curl( curl_easy_init() , curl_easy_cleanup );
    
    assert(pRequest);
    assert(pResponse);
    assert(pError);
    
    if( NULL == curl.get() )
    {
        pError->assign(curl_easy_strerror(CURLE_FAILED_INIT));
        
        return ;
    }
    
    //#ifdef DEBUG
    //    curl_easy_setopt(curl.get() , CURLOPT_VERBOSE , 1L);
    //#endif
    
    curl_easy_setopt(curl.get(), CURLOPT_URL , pRequest->m_url.c_str() );
    curl_easy_setopt(curl.get(), CURLOPT_READFUNCTION , NULL );
    
//    curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION , WriteResponseCallbackFunction );
//    curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA , (void *)&response );
    curl_easy_setopt(curl.get() , CURLOPT_WRITEFUNCTION , EmptyWriteResponseCallbackFunction );
    curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA , NULL );
    
//    curl_easy_setopt(curl.get(), CURLOPT_HEADERFUNCTION , WriteHeaderCallbackFunction );
//    curl_easy_setopt(curl.get(), CURLOPT_HEADERDATA , (void *)&header );
    curl_easy_setopt(curl.get(), CURLOPT_HEADERFUNCTION , EmptyWriteHeaderCallbackFunction );
    curl_easy_setopt(curl.get(), CURLOPT_HEADERDATA , NULL );
    
    curl_easy_setopt(curl.get(), CURLOPT_NOSIGNAL , 1L );
    curl_easy_setopt(curl.get(), CURLOPT_CONNECTTIMEOUT, 5);
	curl_easy_setopt(curl.get(), CURLOPT_TIMEOUT, 5);
    
    if( pRequest->m_method == HttpRequestMethod::POST )
    {
        curl_easy_setopt(curl.get(), CURLOPT_POST, 1);
        curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDS , pRequest->m_http_body.c_str() );
    }
    
    /// Custom Header
    curl_slist * chunk = NULL ;
    addHeader(curl.get(), *pRequest , chunk);
    
    auto ret = curl_easy_perform(curl.get());
    
    cleanHeader(chunk);
    
    if( ret != CURLE_OK )
    {
        pError->assign( curl_easy_strerror(ret) );
        return ;
    }
    
    curl_easy_getinfo(curl.get(), CURLINFO_RESPONSE_CODE , std::addressof(pResponse->m_status_code) );
    curl_easy_getinfo(curl.get(), CURLINFO_TOTAL_TIME , std::addressof(pResponse->m_total_time) );
    curl_easy_getinfo(curl.get(), CURLINFO_CONNECT_TIME , std::addressof(pResponse->m_conn_time) );
    curl_easy_getinfo(curl.get(), CURLINFO_NAMELOOKUP_TIME , std::addressof(pResponse->m_namelookup_time) );
}
Пример #11
0
void HttpConnection::sendSyncHttpRequestWithoutBodyWithoutVerify(const HttpRequest &httpRequest, HttpResponse &httpResponse, std::string &error, bool verbose)
{
    std::lock_guard<std::mutex> lock( g_send_mutex );
    
    std::shared_ptr<CURL> curl( curl_easy_init() , curl_easy_cleanup );
    
    if( NULL == curl.get() )
    {
        error = curl_easy_strerror(CURLE_FAILED_INIT);
        
        return ;
    }
    
    //#ifdef DEBUG
    //    curl_easy_setopt(curl.get() , CURLOPT_VERBOSE , 1L);
    //#endif
    
    curl_easy_setopt(curl.get(), CURLOPT_URL , httpRequest.m_url.c_str() );
    curl_easy_setopt(curl.get(), CURLOPT_READFUNCTION , NULL );
    
//    curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION , WriteResponseCallbackFunction );
//    curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA , (void *)&response );
    curl_easy_setopt(curl.get() , CURLOPT_WRITEFUNCTION , EmptyWriteResponseCallbackFunction );
    curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA , NULL );
    
//    curl_easy_setopt(curl.get(), CURLOPT_HEADERFUNCTION , WriteHeaderCallbackFunction );
//    curl_easy_setopt(curl.get(), CURLOPT_HEADERDATA , (void *)&header );
    curl_easy_setopt(curl.get(), CURLOPT_HEADERFUNCTION , EmptyWriteHeaderCallbackFunction );
    curl_easy_setopt(curl.get(), CURLOPT_HEADERDATA , NULL );
    
    curl_easy_setopt(curl.get(), CURLOPT_NOSIGNAL , 1L );
    curl_easy_setopt(curl.get(), CURLOPT_CONNECTTIMEOUT, 5);
	curl_easy_setopt(curl.get(), CURLOPT_TIMEOUT, 5);
    
    if(verbose)
    {
        curl_easy_setopt(curl.get(), CURLOPT_VERBOSE , 1L);
    }
    
    if( httpRequest.m_method == HttpRequestMethod::POST )
    {
        curl_easy_setopt(curl.get(), CURLOPT_POST, 1);
        curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDS , httpRequest.m_http_body.c_str() );
    }
    
    /// Custom Header
    curl_slist * chunk = NULL ;
    addHeader(curl.get(), httpRequest , chunk);
    
    auto ret = curl_easy_perform(curl.get());
    
    cleanHeader(chunk);
    
    if( ret != CURLE_OK )
    {
        error = curl_easy_strerror(ret);
        return ;
    }
    
    curl_easy_getinfo(curl.get(), CURLINFO_RESPONSE_CODE , &httpResponse.m_status_code );
    curl_easy_getinfo(curl.get(), CURLINFO_TOTAL_TIME , &httpResponse.m_total_time );
    curl_easy_getinfo(curl.get(), CURLINFO_CONNECT_TIME , &httpResponse.m_conn_time );
    curl_easy_getinfo(curl.get(), CURLINFO_NAMELOOKUP_TIME , &httpResponse.m_namelookup_time);
}
Пример #12
0
int
main (int argc,
      char **argv)
{
  const char *options("hs:u:v");
  bool qVerbose(false);
  std::string saveFilename;

  typedef std::vector<std::string> tStrings;
  tStrings urls;

  for (int c; (c = getopt(argc, argv, options)) != EOF;) {
    switch (c) {
      case 's': saveFilename = optarg; break;
      case 'u': urls.push_back(optarg); break;
      case 'v': qVerbose = !qVerbose; break;
      default:
        std::cerr << "Unrecognized option (" << ((char) optopt) << ")" << std::endl;
      case 'h':
        return usage(argv[0], options);
    }
  }

  if (optind < argc) {
    std::cerr << "Unprocessed command line arguments:";
    for (int i(optind); i < argc; ++i) {
      std::cerr << " '" << argv[i] << "'";
    }
    std::cerr << std::endl;
    return usage(argv[0], options);
  }

  if (urls.empty()) { // Build from database
    std::cerr << "urls from database not currently implemented!" << std::endl;
    return 1;
  }

  for (tStrings::const_iterator it(urls.begin()), et(urls.end()); it != et; ++it) {
    const std::string::size_type j(it->find(':'));
    if (j == it->npos) {
      std::cerr << "Malformed parser:URL field(" << *it << ")" << std::endl;
      return 1;
    }
    const std::string parser(it->substr(0,j));
    const std::string url(it->substr(j+1));
    Curl curl(url, qVerbose); // Load the file
    if (!curl) {
      std::cerr << "Error fetching '" << url << "', " << curl.errmsg() << std::endl;
      continue;
    }
    if (curl.responseCode() != 200) {
      std::cerr << "Error fetching '" << url 
                << "', response code " << curl.responseCode()
                << ", " << HTTP::statusMsg(curl.responseCode())
                << std::endl;
      continue;
    }

    if (!saveFilename.empty()) {
      std::ofstream os(saveFilename);
      if (!os) {
         std::cerr << "Error opening '" << saveFilename << "', " << strerror(errno) << std::endl;
         return 1;
      }
      os << curl.str();
    }

    if (parser == "USGS0") {
      ParserUSGS0 a(url, curl.str(), qVerbose);
    } else if (parser == "USGS1") {
      ParserUSGS1 a(url, curl.str(), qVerbose);
    } else if (parser == "NOAA0") {
      ParserNOAA0 a(url, curl.str(), qVerbose);
    } else {
      std::cerr << "Unrecongized parser '" << parser << "'" << std::endl;
      continue;
    }
  }

  return 0;
}
void ossimPlanetYahooGeocoder::getLocationFromAddress(std::vector<osg::ref_ptr<ossimPlanetGeocoderLocation> >& result,
                                                      const ossimString& location)const
{
   ossimString url = theUrl + "appid=" + theAppId +"&location="+location.substitute(" ", "+", true);
   wmsCurlMemoryStream curl(url);

   if(curl.download())
   {
      ossimXmlDocument xml;
      ossimString buffer = curl.getStream()->getBufferAsString();
      std::istringstream in(buffer);
      if(xml.read(in))
      {
         std::vector<ossimRefPtr<ossimXmlNode> > nodes;
         xml.findNodes("/ResultSet/Result",
                       nodes);
         if(nodes.size())
         {
            osg::ref_ptr<ossimPlanetGeocoderLocation> location = new ossimPlanetGeocoderLocation;
            ossim_uint32 idx = 0;
            for(idx = 0; idx < nodes.size(); ++idx)
            {
               ossimRefPtr<ossimXmlNode> lat     = nodes[idx]->findFirstNode("Latitude");
               ossimRefPtr<ossimXmlNode> lon     = nodes[idx]->findFirstNode("Longitude");
               ossimRefPtr<ossimXmlNode> zip     = nodes[idx]->findFirstNode("Zip");
               ossimRefPtr<ossimXmlNode> city    = nodes[idx]->findFirstNode("City");
               ossimRefPtr<ossimXmlNode> state   = nodes[idx]->findFirstNode("State");
               ossimRefPtr<ossimXmlNode> address = nodes[idx]->findFirstNode("Address");
               ossimRefPtr<ossimXmlNode> country = nodes[idx]->findFirstNode("Country");
               if(lat.valid()&&lon.valid())
               {
                  ossimGpt gpt(lat->getText().toDouble(),
                               lon->getText().toDouble());
                  location->setLocation(gpt);
                  ossimString name;

                  if(address.valid())
                  {
                     name = address->getText().trim();
                  }
                  if(city.valid())
                  {
                     if(!name.empty())
                     {
                        name += ", ";
                     }
                     name += city->getText().trim();
                  }
                  if(state.valid())
                  {
                     if(!name.empty())
                     {
                        name += ", ";
                     }
                     name += state->getText().trim();
                  }
                  if(zip.valid())
                  {
                     if(!name.empty())
                     {
                        name += ", ";
                     }
                     name += zip->getText().trim();
                  }
                  if(country.valid())
                  {
                     if(!name.empty())
                     {
                        name += ", ";
                     }
                     name += country->getText().trim();
                  }
                  location->setName(name);
                  
                  result.push_back(location);
               }
            }
         }
      }
   }
}