Ejemplo n.º 1
0
TBool CX509DomainName::AddSubdomainL(TInt& aPos)
	{
	TBool res = EFalse;
	TInt end = iName->Length();
	if (aPos >= end)
		{
		return res;
		}
	TPtrC whatsLeft(&(iName->operator[] (aPos)), end - aPos);
	TInt subdomainEnd = whatsLeft.FindF(KX509SubdomainSeparator);
	if (subdomainEnd == 0)
		{
		return res;
		}
	if (subdomainEnd == KErrNotFound)
		{
		subdomainEnd = end - aPos;
		}
	TPtrC subdomain(&whatsLeft[0], subdomainEnd);
	if (IsValidString(subdomain))
		{
		REP_APPEND_L(subdomain);
		res = ETrue;
		}
	aPos = aPos + subdomainEnd;
	return res;
	}
Ejemplo n.º 2
0
float EpidemicDataSet::getValue(const std::string &varName, const int &time, const int &nodeId, const std::vector<int> &stratificationValues)
{
    // handle derived variables
    if(derivedVariables_.count(varName) > 0)
    {
        return derivedVariables_[varName](time, nodeId, stratificationValues);
    }

    if(variables_.count(varName) == 0)
    {
        put_flog(LOG_ERROR, "no such variable %s (nodeId = %i)", varName.c_str(), nodeId);
        return 0.;
    }
    else if(nodeId != NODES_ALL && nodeIdToIndex_.count(nodeId) == 0)
    {
        put_flog(LOG_ERROR, "could not map nodeId %i to an index (varName = %s)", nodeId, varName.c_str());
        return 0.;
    }

    // the variable we're getting
    blitz::Array<float, 2+NUM_STRATIFICATION_DIMENSIONS> variable = variables_[varName];

    // the full domain
    blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> lowerBound = variable.lbound();
    blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> upperBound = variable.ubound();

    // make sure this variable is valid for the specified time
    if(time < lowerBound(0) || time > upperBound(0))
    {
        put_flog(LOG_WARN, "variable %s not valid for time %i", varName.c_str(), time);
        return 0.;
    }

    // limit by time
    lowerBound(0) = upperBound(0) = time;

    // limit by node
    if(nodeId != NODES_ALL)
    {
        lowerBound(1) = upperBound(1) = nodeIdToIndex_[nodeId];
    }

    // limit by stratification values
    for(unsigned int i=0; i<stratificationValues.size(); i++)
    {
        if(stratificationValues[i] != STRATIFICATIONS_ALL)
        {
            lowerBound(2+i) = upperBound(2+i) = stratificationValues[i];
        }
    }

    // the subdomain
    blitz::RectDomain<2+NUM_STRATIFICATION_DIMENSIONS> subdomain(lowerBound, upperBound);

    // return the sum of the array over the subdomain
    return blitz::sum(variable(subdomain));
}
Ejemplo n.º 3
0
Archivo: noxref.c Proyecto: mth/noxref
static int no_referer_match(char *host, char *referer) {
	int host_len, referer_len, skip;
	hostname h;

	skip = strcspn(referer, ".:/\r\n");
	if (referer[skip] == '.')
		++skip;
	referer_len = strcspn(referer += skip, ":/\r\n");
	if (!memchr(referer, '.', referer_len)) {
		referer_len += skip;
		referer -= skip;
	}
	host_len = strcspn(host, ":");
	if (subdomain(host, host_len, referer, referer_len))
		return 0; // ok
	for (h = whitelist; h; h = h->next)
		if (subdomain(host, host_len, h->name, h->len))
			return 0;
	return -1; // no match, shouldn't be allowed
}
Ejemplo n.º 4
0
int rfc822_valid_msgid(const unsigned char *x) {
    /* expect "<" */
    if (*x != '<') return 0;
    ++ x;

    /* expect local-part = word *("." word)
     * where
     * word = atom/quoted-string
     * atom = 1*ATOMCHAR
     * quoted-string = <"> *(qtext/quoted-pair) <">
     * qtext = CHAR except ", \, CR
     * quoted-pair = "\" CHAR
     */
    for(;;) {
	if (word(&x) == 0) return 0;
	if (*x == '.') { ++x; continue; }
	if (*x == '@') break;
	return 0;
    }

    /* expect "@" */
    if (*x != '@') return 0;
    ++ x;

    /* expect domain = sub-domain *("." sub-domain)
     * sub-domain = domain-ref/domain-literal
     * domain-ref = atom
     * domain-literal = "[" *(dtext/quoted-pair) "]" */
    for(;;) {
	if (subdomain(&x) == 0) return 0;
	if (*x == '.') { ++x; continue; }
	if (*x == '>') break;
	return 0;
    }

    if (*x != '>') return 0;
    return 1;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
  // Initialize POOMA and output stream, using Tester class

  Pooma::initialize(argc, argv);
  Pooma::Tester tester(argc, argv);
  tester.out() << argv[0] << ": Paws Field send/receive test B" << std::endl;
  tester.out() << "--------------------------------------------" << std::endl;

#if POOMA_PAWS

  // Some scalars to send and receive

  int s1 = 1, origs1 = 1;
  double s2 = 2.5, origs2 = 2.5;
  int iters = 0, citers = 10;

  // Fields to send and receive ... use different layouts in the two
  // test codes.

  Loc<2> blocks(2,1);
  Interval<2> domain(6,2);
  Interval<2> subdomain(3, 2);
  Vector<2,double> origin(2.0);
  Vector<2,double> spacings(0.2);
  RectilinearMesh<2> mesh(domain, origin, spacings);

  // Create the geometry and layout.

  typedef DiscreteGeometry<Vert, RectilinearMesh<2> > Geometry_t;
  Geometry_t geom(mesh);
  GridLayout<2> layout(domain, blocks, ReplicatedTag());

  // Now create the Fields

  Field<Geometry_t, float, Brick> a1(geom);
  Field<Geometry_t, int, MultiPatch<GridTag,Brick> > a2(geom, layout);
  Array<2, float, Brick> a3(subdomain);
  Array<2, float, Brick> ca1(domain);
  Array<2, int, Brick> ca2(domain);
  Array<2, float, Brick> ca3(subdomain);

  // Initialize the arrays to be all zero, and the compare arrays to be
  // what we expect from the sender.

  a1 = 0;
  a2 = 0;
  a3 = 0;
  ca1 = 10 * (iota(domain).comp(1) + 1) + iota(domain).comp(0) + 1;
  ca2 = ca1 + 1000;
  ca3 = ca1(subdomain);

  // Create a Paws connection

  tester.out() << "Creating PawsConnection object ..." << std::endl;
  Connection<Paws> *paws = new Connection<Paws>("test6", argc, argv);
  tester.out() << "Finished creating PawsConnection object." << std::endl;

  // Establish connections for the two scalars

  tester.out() << "Connecting s1 = " << s1 << " for input ..." << std::endl;
  ConnectorBase *s1p = paws->connectScalar("s1", s1, ConnectionBase::in);
  tester.out() << "Connecting s2 = " << s2 << " for output ..." << std::endl;
  ConnectorBase *s2p = paws->connectScalar("s2", s2, ConnectionBase::out);
  tester.out() << "Connecting iters = " << iters << " for input ...";
  tester.out() << std::endl;
  ConnectorBase *iterp=paws->connectScalar("iters", iters, ConnectionBase::in);

  // Establish connections for the two fields; also connect up a view of
  // the first fields

  tester.out() << "Connecting a1 = " << a1 << " for input ..." << std::endl;
  paws->connect("a1", a1, ConnectionBase::in);
  tester.out() << "Connecting a2 = " << a2 << " for input ..." << std::endl;
  paws->connect("a2", a2, ConnectionBase::in);
  tester.out() << "Connecting a3 = " << a3 << " for input ..." << std::endl;
  paws->connect("a1view", a3, ConnectionBase::in);

  // Wait for everything to be ready to proceed

  tester.out() << "Waiting for ready signal ..." << std::endl;
  paws->ready();
  tester.out() << "Ready complete, moving on." << std::endl;

  // Modify s1, and update

  s1 *= 2;
  tester.out() << "Updating current s1 = " << s1 << " and s2 = " << s2;
  tester.out() << " ..." << std::endl;
  paws->update();

  // Report the results

  tester.out() << "Received update.  New values:" << std::endl;
  tester.out() << "  s1 = " << s1 << " (should be " << origs1 << ")\n";
  tester.out() << "  s2 = " << s2 << " (should be " << origs2 << ")\n";
  tester.out() << "  iters = " << iters << " (should be " << citers << ")\n";
  tester.out() << std::endl;
  tester.check("s1 OK", s1 == origs1);
  tester.check("s2 OK", s2 == origs2);
  tester.check("iters OK", iters == citers);

  // Also report Field results

  tester.out() << "Received Fields as well.  New values:" << std::endl;
  tester.out() << "  a1 = " << a1 << std::endl;
  tester.out() << "  a2 = " << a2 << std::endl;
  tester.out() << "  a3 = " << a3 << std::endl;
  tester.check("a1 OK", all(a1.array() == ca1));
  tester.check("a2 OK", all(a2.array() == ca2));
  tester.check("a3 OK", all(a3 == ca3));

  // Disconnect the scalars

  int connections = paws->size();
  tester.out() << "Disconnecting scalars ..." << std::endl;
  paws->disconnect(s1p);
  paws->disconnect(s2p);
  paws->disconnect(iterp);
  tester.check("3 less connections", paws->size() == (connections - 3));

  // Do, in a loop, updates of the receiver. Add one to the arrays each time.

  int runiters =  iters;
  while (runiters-- > 0)
    {
      ca1 += 1;
      ca2 += 1;
      ca3 += 1;
      tester.out() << "Receiving for iters = " << iters << std::endl;
      paws->update();
      tester.out() << "Receive complete." << std::endl;
      tester.check("a1 OK", all(a1.array() == ca1));
      tester.check("a2 OK", all(a2.array() == ca2));
      tester.check("a3 OK", all(a3 == ca3));
    }

  // Delete PAWS connection, disconnecting us from the other code.

  tester.out() << "Deleting Connection<Paws> object ..." << std::endl;
  delete paws;

#else // POOMA_PAWS

  tester.out() << "Please configure with --paws to use this test code!"
	       << std::endl;

#endif // POOMA_PAWS

  // Finish up and report results

  tester.out() << "-------------------------------------------" << std::endl;
  int retval = tester.results("Paws Field send/receive test B");
  Pooma::finalize();
  return retval;
}
Ejemplo n.º 6
0
//c---------------------------------------------------------------------
//c
//c Authors: S. Weeratunga
//c          V. Venkatakrishnan
//c          E. Barszcz
//c          M. Yarrow
//c C-version: Rob Van der Wijngaart, Intel Corporation
//c
//c---------------------------------------------------------------------
// 
// Copyright 2010 Intel Corporation
// 
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
// 
//        http://www.apache.org/licenses/LICENSE-2.0
// 
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
// 
int RCCE_APP(int argc, char **argv){

//c---------------------------------------------------------------------
//c
//c   driver for the performance evaluation of the solver for
//c   five coupled parabolic/elliptic partial differential equations.
//c
//c---------------------------------------------------------------------



      char class;
      double mflops;
      int ierr, i, j, k, mm, iverified;

//c---------------------------------------------------------------------
//c   initialize communications
//c---------------------------------------------------------------------
       init_comm(&argc, &argv);
//       RCCE_debug_set(RCCE_DEBUG_SYNCH);
//c---------------------------------------------------------------------
//c   read input data
//c---------------------------------------------------------------------
       read_input();

//c---------------------------------------------------------------------
//c   set up processor grid
//c---------------------------------------------------------------------
       proc_grid();

//c---------------------------------------------------------------------
//c   determine the neighbors
//c---------------------------------------------------------------------
       neighbors();

//c---------------------------------------------------------------------
//c   set up sub-domain sizes
//c---------------------------------------------------------------------
       subdomain();

//c---------------------------------------------------------------------
//c   set up coefficients
//c---------------------------------------------------------------------
       setcoeff();

//c---------------------------------------------------------------------
//c   set the boundary values for dependent variables
//c---------------------------------------------------------------------

       setbv();

//c---------------------------------------------------------------------
//c   set the initial values for dependent variables
//c---------------------------------------------------------------------

       setiv();

//c---------------------------------------------------------------------
//c   compute the forcing term based on prescribed exact solution
//c---------------------------------------------------------------------
       erhs();

////c---------------------------------------------------------------------
////c   perform one SSOR iteration to touch all data and program pages 
////c---------------------------------------------------------------------
       ssor(1);

//
////c---------------------------------------------------------------------
////c   reset the boundary and initial values
////c---------------------------------------------------------------------
       setbv();
       setiv();
//
////c---------------------------------------------------------------------
////c   perform the SSOR iterations
////c---------------------------------------------------------------------
       ssor(itmax);

////c---------------------------------------------------------------------
////c   compute the solution error
////c---------------------------------------------------------------------
        error();

////c---------------------------------------------------------------------
////c   compute the surface integral
////c---------------------------------------------------------------------
      pintgr();
//
////c---------------------------------------------------------------------
////c   verification test
////c---------------------------------------------------------------------

      if (id ==0) {
        verify( rsdnm, errnm, &frc, &class );
         mflops = (double)(itmax)*(1984.77*(double)( nx0 )
              *(double)( ny0 )
              *(double)( nz0 )
              -10923.3*((double)( nx0+ny0+nz0 )/3.)*((double)( nx0+ny0+nz0 )/3.)
              +27770.9* (double)( nx0+ny0+nz0 )/3.
              -144010.)
              / (maxtime*1000000.);

          print_results("LU", &class, &nx0,
           &ny0, &nz0, &itmax, &nnodes_compiled,
           &num, &maxtime, &mflops, "          floating point", &iverified, 
           NPBVERSION, COMPILETIME, CS1, CS2, CS3, CS4, CS5, CS6);

//         FILE *perf_file;
//         char name[50] = "/shared/DEMOS/RCCE/NPB_LU/perf."; 
//         char postfix[50]; 
//         sprintf(postfix, "%d", nnodes_compiled); 
//         strcat(name, postfix); 
//         perf_file = fopen(name,"w"); 
//         fprintf(perf_file, "%d", (int)mflops); 
//         fclose(perf_file); 
      }      
Ejemplo n.º 7
0
bool MeshGenerator::writeToHermes()
{
    // edges
    XMLSubdomains::edges_type edges;
    for (int i = 0; i < edgeList.count(); i++)
        if (edgeList[i].isUsed && edgeList[i].marker != -1)
            edges.ed().push_back(XMLSubdomains::ed(edgeList[i].node[0], edgeList[i].node[1],
                    QString::number(edgeList[i].marker).toStdString(), i));

    // curved edges
    XMLMesh::curves_type curves;
    for (int i = 0; i<edgeList.count(); i++)
    {
        if (edgeList[i].marker != -1)
        {
            // curve
            if (Agros2D::scene()->edges->at(edgeList[i].marker)->angle() > 0.0 &&
                    Agros2D::scene()->edges->at(edgeList[i].marker)->isCurvilinear())
            {
                int segments = Agros2D::scene()->edges->at(edgeList[i].marker)->segments();

                // subdivision angle and chord
                double theta = deg2rad(Agros2D::scene()->edges->at(edgeList[i].marker)->angle()) / double(segments);
                double chord = 2 * Agros2D::scene()->edges->at(edgeList[i].marker)->radius() * sin(theta / 2.0);

                // length of short chord
                double chordShort = (nodeList[edgeList[i].node[1]] - nodeList[edgeList[i].node[0]]).magnitude();

                // direction
                Point center = Agros2D::scene()->edges->at(edgeList[i].marker)->center();
                int direction = (((nodeList[edgeList[i].node[0]].x-center.x)*(nodeList[edgeList[i].node[1]].y-center.y) -
                        (nodeList[edgeList[i].node[0]].y-center.y)*(nodeList[edgeList[i].node[1]].x-center.x)) > 0) ? 1 : -1;

                double angle = direction * theta * chordShort / chord;

                curves.arc().push_back(XMLMesh::arc(edgeList[i].node[0], edgeList[i].node[1], rad2deg(angle)));
            }
        }
    }

    // move nodes (arcs)
    for (int i = 0; i<edgeList.count(); i++)
    {
        // assert(edgeList[i].marker >= 0); // markers changed to marker - 1, check...
        if (edgeList[i].marker != -1)
        {
            // curve
            if (Agros2D::scene()->edges->at(edgeList[i].marker)->angle() > 0.0 &&
                    Agros2D::scene()->edges->at(edgeList[i].marker)->isCurvilinear())
            {
                // angle
                Point center = Agros2D::scene()->edges->at(edgeList[i].marker)->center();
                double pointAngle1 = atan2(center.y - nodeList[edgeList[i].node[0]].y,
                        center.x - nodeList[edgeList[i].node[0]].x) - M_PI;

                double pointAngle2 = atan2(center.y - nodeList[edgeList[i].node[1]].y,
                        center.x - nodeList[edgeList[i].node[1]].x) - M_PI;

                nodeList[edgeList[i].node[0]].x = center.x + Agros2D::scene()->edges->at(edgeList[i].marker)->radius() * cos(pointAngle1);
                nodeList[edgeList[i].node[0]].y = center.y + Agros2D::scene()->edges->at(edgeList[i].marker)->radius() * sin(pointAngle1);

                nodeList[edgeList[i].node[1]].x = center.x + Agros2D::scene()->edges->at(edgeList[i].marker)->radius() * cos(pointAngle2);
                nodeList[edgeList[i].node[1]].y = center.y + Agros2D::scene()->edges->at(edgeList[i].marker)->radius() * sin(pointAngle2);
            }
        }
    }

    // vertices
    XMLMesh::vertices_type vertices;
    for (int i = 0; i<nodeList.count(); i++)
        vertices.v().push_back(std::auto_ptr<XMLMesh::v>(new XMLMesh::v(QString::number(nodeList[i].x).toStdString(),
                                                                        QString::number(nodeList[i].y).toStdString(), i)));

    // elements
    XMLSubdomains::elements_type elements;
    for (int i = 0; i<elementList.count(); i++)
        if (elementList[i].isUsed)
            if (elementList[i].isTriangle())
                elements.el().push_back(XMLSubdomains::t_t(elementList[i].node[0], elementList[i].node[1], elementList[i].node[2],
                        QString::number(elementList[i].marker).toStdString(), i));
            else
                elements.el().push_back(XMLSubdomains::q_t(elementList[i].node[0], elementList[i].node[1], elementList[i].node[2],
                        QString::number(elementList[i].marker).toStdString(), i,
                        elementList[i].node[3]));

    // find edge neighbours
    // for each vertex list elements that it belogns to
    QList<QSet<int> > vertexElements;
    vertexElements.reserve(nodeList.count());
    for (int i = 0; i < nodeList.count(); i++)
        vertexElements.push_back(QSet<int>());

    for (int i = 0; i < elementList.count(); i++)
        if (elementList[i].isUsed)
            for(int elemNode = 0; elemNode < (elementList[i].isTriangle() ? 3 : 4); elemNode++)
                vertexElements[elementList[i].node[elemNode]].insert(i);

    for (int i = 0; i < edgeList.count(); i++)
    {
        if (edgeList[i].isUsed && edgeList[i].marker != -1)
        {
            QSet<int> neighbours = vertexElements[edgeList[i].node[0]];
            neighbours.intersect(vertexElements[edgeList[i].node[1]]);
            assert((neighbours.size() > 0) && (neighbours.size() <= 2));
            edgeList[i].neighElem[0] = neighbours.values()[0];
            if(neighbours.size() == 2)
                edgeList[i].neighElem[1] = neighbours.values()[1];
        }
    }

    // subdomains
    XMLSubdomains::subdomains subdomains;

    if (Agros2D::problem()->fieldInfos().isEmpty())
    {
        // one domain
        XMLSubdomains::subdomain subdomain(Agros2D::problem()->fieldInfos().begin().value()->fieldId().toStdString());
        subdomains.subdomain().push_back(subdomain);
    }
    else
    {
        // more subdomains
        foreach (FieldInfo* fieldInfo, Agros2D::problem()->fieldInfos())
        {
            XMLSubdomains::subdomain subdomain(fieldInfo->fieldId().toStdString());
            subdomain.elements().set(XMLSubdomains::subdomain::elements_type());
            subdomain.boundary_edges().set(XMLSubdomains::subdomain::boundary_edges_type());
            subdomain.inner_edges().set(XMLSubdomains::subdomain::inner_edges_type());

            for (int i = 0; i<elementList.count(); i++)
                if (elementList[i].isUsed && (Agros2D::scene()->labels->at(elementList[i].marker)->marker(fieldInfo) != SceneMaterialContainer::getNone(fieldInfo)))
                    subdomain.elements()->i().push_back(i);

            QList<int> unassignedEdges;
            for (int i = 0; i < edgeList.count(); i++)
            {
                if (edgeList[i].isUsed && edgeList[i].marker != -1)
                {
                    int numNeighWithField = 0;
                    for (int neigh_i = 0; neigh_i < 2; neigh_i++)
                    {
                        int neigh = edgeList[i].neighElem[neigh_i];
                        if (neigh != -1)
                        {
                            if (Agros2D::scene()->labels->at(elementList[neigh].marker)->marker(fieldInfo)
                                    != SceneMaterialContainer::getNone(fieldInfo))
                                numNeighWithField++;
                        }
                    }

                    // edge has boundary condition prescribed for this field
                    bool hasFieldBoundaryCondition = (Agros2D::scene()->edges->at(edgeList[i].marker)->hasMarker(fieldInfo)
                                                      && (Agros2D::scene()->edges->at(edgeList[i].marker)->marker(fieldInfo) != SceneBoundaryContainer::getNone(fieldInfo)));

                    if (numNeighWithField == 1)
                    {
                        // edge is on "boundary" of the field, should have boundary condition prescribed

                        if (!hasFieldBoundaryCondition)
                            if (!unassignedEdges.contains(edgeList[i].marker))
                                unassignedEdges.append(edgeList[i].marker);

                        subdomain.boundary_edges()->i().push_back(i);
                    }
                    else if (numNeighWithField == 2)
                    {
                        // todo: we could enforce not to have boundary conditions prescribed inside:
                        // assert(!hasFieldBoundaryCondition);
                        subdomain.inner_edges()->i().push_back(i);
                    }
                }
            }

            // not assigned boundary
            if (unassignedEdges.count() > 0)
            {
                QString list;
                foreach (int index, unassignedEdges)
                    list += QString::number(index) + ", ";

                Agros2D::log()->printError(tr("Mesh generator"), tr("Boundary condition for %1 is not assigned on following edges: %2").arg(fieldInfo->name()).arg(list.left(list.count() - 2)));

                return false;
            }

            subdomains.subdomain().push_back(subdomain);
        }