/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2026 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
Namespace
Foam::expression
Description
Functions which check the consistency of the contents of expressions
\*---------------------------------------------------------------------------*/
#ifndef expressionAssert_H
#define expressionAssert_H
#include "expressionContainers.H"
#include "expressionName.H"
#include "error.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace expression
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Assert that all containers in an expression have the same property value
template
void assertSameAllContainerProperty(const Expression& e)
{
typedef AllContainers allContainers;
FixedList ps =
getAll(e);
for (unsigned i = 1; i < allContainers::n; ++ i)
{
if (ps[0] != ps[i])
{
FatalErrorInFunction
<< "expression '" << name(e)
<< "' of type '" << typeName()
<< "' contains containers with different "
<< Property::names() << exit(FatalError);
}
}
}
//- Assert that all containers in an expression have the same property value as
// that of the given container
template
void assertSameAllContainerProperty
(
const Container& c,
const Expression& e
)
{
assertSameAllContainerProperty(e);
typedef AllContainers allContainers;
FixedList ps =
getAll(e);
if (allContainers::n)
{
if (Property::get(c) != ps[0])
{
FatalErrorInFunction
<< "expression '" << name(e)
<< "' of type '" << typeName()
<< "' has a different " << Property::name()
<< " to container '" << name(c)
<< "' of type '" << typeName()
<< "'" << exit(FatalError);
}
}
}
//- Assert that all containers of a type in an expression have the same
// property value
template
void assertSameTypeContainerProperty(const Expression& e)
{
typedef TypeContainers typeContainers;
FixedList ps =
getTypes(e);
for (unsigned i = 1; i < typeContainers::n; ++ i)
{
if (ps[0] != ps[i])
{
FatalErrorInFunction
<< "expression '" << name(e)
<< "' of type '" << typeName()
<< "' contains containers of type '"
<< typeName() << "' with different "
<< Property::names() << exit(FatalError);
}
}
}
//- Assert that all containers of a type in an expression have the same
// property value as that of the given container
template
void assertSameTypeContainerProperty
(
const Container& c,
const Expression& e
)
{
assertSameTypeContainerProperty(e);
typedef TypeContainers typeContainers;
FixedList ps =
getTypes(e);
if (typeContainers::n)
{
if (Property::get(c) != ps[0])
{
FatalErrorInFunction
<< "expression '" << name(e)
<< "' of type '" << typeName()
<< "' has a different " << Property::name()
<< " to container '" << name(c)
<< "' of type '" << typeName()
<< "'" << exit(FatalError);
}
}
}
//- Assert that two containers have the same property value
template
void assertSameTypeContainerProperty
(
const Container& a,
const Container& b
)
{
if (Property::get(a) != Property::get(b))
{
FatalErrorInFunction
<< "containers '" << name(a)
<< "' and '" << name(b)
<< "' of type '" << typeName()
<< "' have different " << Property::names()
<< exit(FatalError);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace expression
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //