Beispiel #1
0
void writeInteratomics(Atom *atoms, int numatoms, const double globalCutoff,
  const TypeVec &types, double *spaceSize,
  const SquareSelector<double> &coordCutoffs)
{
  // iterate from numatoms to 1

  BondMap bonds(types);
  CoordinationHistogramData coords(types.size());

  Bond *file;

  size_t *count = new size_t[types.size()];

  for (int i = numatoms - 1; i > 0; --i)
  {
    memset(count, '\0', sizeof(size_t) * types.size());

    // iterate from j-1 to 0
    for (int j = numatoms - 1; j >= 0; --j)
    {
      if (i == j)
      {
        continue;
      }

      double distance = getDistance(atoms[i], atoms[j], spaceSize);

      if (distance <= globalCutoff)
      {
        file = bonds.getFile(atoms[i].type, atoms[j].type);
        file->write(distance);
      }

      if (!coordCutoffs.empty()
        && distance <= coordCutoffs.select(atoms[i].type, atoms[j].type))
      {
        count[atoms[j].type] += 1;
      }
    }

    if (!coordCutoffs.empty())
    {
      for (size_t j = 0; j < types.size(); ++j)
      {
        coords.addValue(atoms[i].type, j, count[j]);
      }
    }
  }

  if (!coordCutoffs.empty())
  {
    writeCoordination(coords, types);
  }

  delete[] count;
}
AST_MATCHER_P(FunctionDecl, throws, internal::Matcher<Type>, InnerMatcher) {
  TypeVec ExceptionList = throwsException(&Node);
  auto NewEnd = llvm::remove_if(
      ExceptionList, [this, Finder, Builder](const Type *Exception) {
        return !InnerMatcher.matches(*Exception, Finder, Builder);
      });
  ExceptionList.erase(NewEnd, ExceptionList.end());
  return ExceptionList.size();
}
Beispiel #3
0
SquareSelector<double> getCoordCutoffs(const TypeVec &types)
{
  vector<string> cutstrs = strsplit(args.getCString("coordinationCutoffs"));

  if (cutstrs.size() != 0)
  {
    if (types.size() == 0)
    {
      cerr << "coordinationCutoffs: species not defined" << endl;
      exit(1);
    }
    if (cutstrs.size() < types.size() * types.size())
    {
      cerr
        << "coordinationCutoffs: too few values. Must be number of species squared"
        << endl;
      exit(1);
    }
    if (cutstrs.size() > types.size() * types.size())
    {
      cerr
        << "coordinationCutoffs: too many values. Must be number of species squared"
        << endl;
      exit(1);
    }

    vector<double> cutoffs(cutstrs.size());
    for (size_t i = 0; i < cutstrs.size(); ++i)
    {
      double value;
      if (convert(cutstrs[i].c_str(), &value))
      {
        cerr << "coordinationCutoffs: invalid double value '"
          << cutstrs[i].c_str() << "'" << endl;
        exit(1);
      }

      cutoffs[i] = value;
    }
    return SquareSelector<double>(cutoffs);
  }

  return SquareSelector<double>(vector<double>());
}
Beispiel #4
0
TypeVec getTypes()
{
  TypeVec types;
  // init types with predefined species (if any)
  vector<string> species = strsplit(args.getCString("species"));
  for (size_t i = 0; i < species.size(); ++i)
  {
    types.push_back(Type(species[i].c_str(), types.size()));
  }

  return types;
}
Beispiel #5
0
void writeCoordination(CoordinationHistogramData &coords, const TypeVec &types)
{
  ofstream coordsfile("coords.txt");

  for (size_t type1 = 0; type1 < types.size(); ++type1)
  {
    for (size_t type2 = 0; type2 < types.size(); ++type2)
    {
      coordsfile << types[type1].name.c_str() << "-"
        << types[type2].name.c_str() << "\t";

      CoordinationHistogramData::Bins bins = coords.data[coords.getIndex(type1,
        type2)];
      for (CoordinationHistogramData::Bins::iterator it = bins.begin();
        it != bins.end(); ++it)
      {
        coordsfile << *it << " ";
      }
      coordsfile << endl;
    }
  }
}
Beispiel #6
0
static void DtoCreateNestedContextType(FuncDeclaration* fd) {
    Logger::println("DtoCreateNestedContextType for %s", fd->toChars());
    LOG_SCOPE

    DtoDeclareFunction(fd);

    if (fd->ir.irFunc->nestedContextCreated)
        return;
    fd->ir.irFunc->nestedContextCreated = true;

    if (fd->nestedVars.empty()) {
        // fill nestedVars
        size_t nnest = fd->closureVars.dim;
        for (size_t i = 0; i < nnest; ++i)
        {
            VarDeclaration* vd = static_cast<VarDeclaration*>(fd->closureVars.data[i]);
            fd->nestedVars.insert(vd);
        }
    }

    // construct nested variables array
    if (!fd->nestedVars.empty())
    {
        Logger::println("has nested frame");
        // start with adding all enclosing parent frames until a static parent is reached

        LLStructType* innerFrameType = NULL;
        unsigned depth = -1;
        if (!fd->isStatic()) {
            if (FuncDeclaration* parfd = getParentFunc(fd, true)) {
                // Make sure the parent has already been analyzed.
                DtoCreateNestedContextType(parfd);

                innerFrameType = parfd->ir.irFunc->frameType;
                if (innerFrameType)
                    depth = parfd->ir.irFunc->depth;
            }
        }
        fd->ir.irFunc->depth = ++depth;

        Logger::cout() << "Function " << fd->toChars() << " has depth " << depth << '\n';

        typedef std::vector<LLType*> TypeVec;
        TypeVec types;
        if (depth != 0) {
            assert(innerFrameType);
            // Add frame pointer types for all but last frame
            if (depth > 1) {
                for (unsigned i = 0; i < (depth - 1); ++i) {
                    types.push_back(innerFrameType->getElementType(i));
                }
            }
            // Add frame pointer type for last frame
            types.push_back(LLPointerType::getUnqual(innerFrameType));
        }

        if (Logger::enabled() && depth != 0) {
            Logger::println("Frame types: ");
            LOG_SCOPE;
            for (TypeVec::iterator i = types.begin(); i != types.end(); ++i)
                Logger::cout() << **i << '\n';
        }

        // Add the direct nested variables of this function, and update their indices to match.
        // TODO: optimize ordering for minimal space usage?
        for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i)
        {
            VarDeclaration* vd = *i;
            if (!vd->ir.irLocal)
                vd->ir.irLocal = new IrLocal(vd);

            vd->ir.irLocal->nestedIndex = types.size();
            vd->ir.irLocal->nestedDepth = depth;
            if (vd->isParameter()) {
                // Parameters will have storage associated with them (to handle byref etc.),
                // so handle those cases specially by storing a pointer instead of a value.
                const IrParameter* irparam = vd->ir.irParam;
                const bool refout = vd->storage_class & (STCref | STCout);
                const bool lazy = vd->storage_class & STClazy;
                const bool byref = irparam->arg->byref;
                const bool isVthisPtr = irparam->isVthis && !byref;
                if (!(refout || (byref && !lazy)) || isVthisPtr) {
                    // This will be copied to the nesting frame.
                    if (lazy)
                        types.push_back(irparam->value->getType()->getContainedType(0));
                    else
                        types.push_back(DtoType(vd->type));
                } else {
                    types.push_back(irparam->value->getType());
                }
            } else if (isSpecialRefVar(vd)) {
                types.push_back(DtoType(vd->type->pointerTo()));
            } else {
                types.push_back(DtoType(vd->type));
            }
            if (Logger::enabled()) {
                Logger::cout() << "Nested var '" << vd->toChars() <<
                    "' of type " << *types.back() << "\n";
            }
        }

        LLStructType* frameType = LLStructType::create(gIR->context(), types,
                                                       std::string("nest.") + fd->toChars());

        Logger::cout() << "frameType = " << *frameType << '\n';

        // Store type in IrFunction
        fd->ir.irFunc->frameType = frameType;
    } else if (FuncDeclaration* parFunc = getParentFunc(fd, true)) {
        // Propagate context arg properties if the context arg is passed on unmodified.
        DtoCreateNestedContextType(parFunc);
        fd->ir.irFunc->frameType = parFunc->ir.irFunc->frameType;
        fd->ir.irFunc->depth = parFunc->ir.irFunc->depth;
    }
}