Ejemplo n.º 1
0
void Foam::expressionToCell::combine(topoSet& set, const bool add) const
{
    fvMesh mesh(set.db());

    FieldValueExpressionDriver driver
        (
            mesh.time().timeName(),
            mesh.time(),
            mesh,
            true, // cache stuff
            true, // search in memory
            true  // search on disc
        );

    if(dict_.valid()) {
        driver.readVariablesAndTables(dict_());
        driver.clearVariables();
    }
    driver.parse(expression_);
    if(!driver.resultIsTyp<volScalarField>(true)) {
        FatalErrorIn("Foam::expressionToCell::combine(topoSet& set, const bool add) const")
            << "Expression " << expression_ << " does not evaluate to a logical expression"
                << endl
                << exit(FatalError);
    }
    const volScalarField &condition=driver.getResult<volScalarField>();

    forAll(condition, cellI)
    {
        if (condition[cellI])
        {
            addOrDelete(set, cellI, add);
        }
    }
}
Ejemplo n.º 2
0
static int DCVertexBufferInit(DCVertexBuffer *self, PyObject *args, PyObject *kwds)
{
	DKObject<DKVertexBuffer> vb = NULL;
	if (self->buffer == NULL)
	{
		PyObject* decls;
		Py_ssize_t size;
		int location;
		int usage;

		char* kwlist[] = { "decls", "size", "location", "usage", NULL };
		if (!PyArg_ParseTupleAndKeywords(args, kwds, "Onii", kwlist,
			&decls, &size, &location, &usage))
			return -1;

		if (!PySequence_Check(decls))
		{
			PyErr_SetString(PyExc_TypeError, "first argument must be sequence object.");
			return -1;
		}
		if (size <= 0)
		{
			PyErr_SetString(PyExc_ValueError, "second argument must be greater than zero.");
			return -1;
		}
		// DKGeometryBuffer::MemoryLocation
		if (location < DKGeometryBuffer::MemoryLocationStatic ||
			location > DKGeometryBuffer::MemoryLocationStream)
		{
			PyErr_SetString(PyExc_ValueError, "thrid argument is invalid. (wrong location)");
			return -1;
		}
		// DKGeometryBuffer::BufferUsage
		if (usage < DKGeometryBuffer::BufferUsageDraw ||
			usage > DKGeometryBuffer::BufferUsageCopy)
		{
			PyErr_SetString(PyExc_ValueError, "fourth argument is invalid. (wrong usage)");
			return -1;
		}
		DKArray<DKVertexBuffer::Decl> declArray;

		PyObject* decl_args = PyTuple_New(0);
		DCObjectRelease decl_args_(decl_args);
		char* decl_kwlist[] = { "id", "name", "type", "normalize", "offset", NULL };

		Py_ssize_t len = PySequence_Size(decls);
		for (int i = 0; i < len; ++i)
		{
			PyObject* dict = PySequence_GetItem(decls, i);
			if (dict == NULL)
			{
				PyErr_SetString(PyExc_TypeError, "first argument must be sequence object.");
				return -1;
			}
			DCObjectRelease dict_(dict);

			if (!PyDict_Check(dict))
			{
				PyErr_SetString(PyExc_TypeError, "decl element must be dictionary object.");
				return -1;
			}

			int stream;
			const char* name;
			int type;
			int normalize;
			Py_ssize_t offset;

			if (!PyArg_ParseTupleAndKeywords(decl_args, dict, "isipn", decl_kwlist,
				&stream, &name, &type, &normalize, &offset))
			{
				PyErr_Clear();
				PyErr_SetString(PyExc_TypeError, "invalid decl data.");
				return -1;
			}

			if (stream <= DKVertexStream::StreamUnknown || stream >= DKVertexStream::StreamMax)
			{
				PyErr_SetString(PyExc_ValueError, "decl['id'] is out of range");
				return -1;
			}
			if (type <= DKVertexStream::TypeUnknown || type >= DKVertexStream::TypeMax)
			{
				PyErr_SetString(PyExc_ValueError, "decl['type'] is out of range");
				return -1;
			}
			if (offset < 0)
			{
				PyErr_SetString(PyExc_ValueError, "decl['offset'] must be greater than zero.");
				return -1;
			}

			DKVertexBuffer::Decl decl;
			decl.id = (DKVertexStream::Stream)stream;
			decl.name = name;
			decl.type = (DKVertexStream::Type)type;
			decl.normalize = normalize != 0;
			decl.offset = offset;

			declArray.Add(decl);
		}

		if (declArray.Count() == 0)
		{
			PyErr_SetString(PyExc_ValueError, "invalid vertex declarations");
			return -1;
		}

		Py_BEGIN_ALLOW_THREADS
		vb = DKVertexBuffer::Create(declArray, declArray.Count(), NULL, size, 0,
			(DKGeometryBuffer::MemoryLocation)location,
			(DKGeometryBuffer::BufferUsage)usage);
		Py_END_ALLOW_THREADS

		if (vb == NULL)
		{
			PyErr_SetString(PyExc_RuntimeError, "failed to create vertex-buffer");
			return -1;
		}
		self->buffer = vb;
		DCObjectSetAddress(self->buffer, (PyObject*)self);
	}