/*---------------------------------------------------------------------------*\ ========= | \\ / 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 . \*---------------------------------------------------------------------------*/ #include "PtrField.H" #include "expressionAssert.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::PtrField::PtrField() : PtrList() {} template Foam::PtrField::PtrField(const label size) : PtrList(size) {} template Foam::PtrField::PtrField(const PtrField& f) : tmp>::refCount(), PtrList(f) {} template Foam::PtrField::PtrField(PtrField&& f) : tmp>::refCount(), PtrList(move(f)) {} template Foam::PtrField::PtrField(const tmp>& tf) : PtrList(const_cast&>(tf()), tf.isTmp()) { tf.clear(); } template template Foam::PtrField::PtrField(const PtrField& f, const Args& ... args) : PtrList(f, args ...) {} template template Foam::PtrField::PtrField(const PtrList& f, const Args& ... args) : PtrList(f, args ...) {} template template Foam::PtrField::PtrField(const Expression& e, const Args& ... args) : PtrList(expression::getFirst(e)) { expression::assertSameAllContainerProperty(e); forAll(*this, i) { PtrList::set ( i, expression::New ( expression::access(e, i), args ... ).ptr() ); } } template Foam::tmp> Foam::PtrField::clone() const { return tmp>(new PtrField(*this)); } template template Foam::tmp> Foam::PtrField::New ( const tmp>& tf, const Args& ... args ) { if (tf.isTmp()) { return tf; } else { const PtrField& f = tf(); tmp> trf ( new PtrField(f.size()) ); PtrField& rf = trf.ref(); forAll(f, i) { rf.set(i, expression::New(f[i], args ...).ptr()); } return trf; } } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template void Foam::PtrField::negate() { forAll(*this, i) { this->operator[](i).negate(); } } template void Foam::PtrField::replace ( const direction d, const PtrField& sf ) { forAll(*this, i) { this->operator[](i).replace(d, sf[i]); } } template template void Foam::PtrField::replace ( const direction d, const Expression& e ) { expression::assertSameAllContainerProperty ( *this, e ); forAll(*this, i) { this->operator[](i).replace(d, expression::access(e, i)); } } template void Foam::PtrField::replace ( const direction d, const cmptType& s ) { forAll(*this, i) { this->operator[](i).replace(d, s); } } template void Foam::PtrField::boundLower ( const typename PtrField::pType& lower ) { forAll(*this, i) { this->operator[](i).boundLower(lower); } } template void Foam::PtrField::boundUpper ( const typename PtrField::pType& upper ) { forAll(*this, i) { this->operator[](i).boundUpper(upper); } } template void Foam::PtrField::bound ( const typename PtrField::pType& lower, const typename PtrField::pType& upper ) { forAll(*this, i) { this->operator[](i).bound(lower, upper); } } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template void Foam::PtrField::operator=(const PtrField& f) { if (this == &f) { FatalErrorInFunction << "attempted assignment to self" << abort(FatalError); } forAll(*this, i) { this->operator[](i) = f[i]; } } template void Foam::PtrField::operator=(PtrField&& f) { if (this == &f) { FatalErrorInFunction << "attempted assignment to self" << abort(FatalError); } PtrList::operator=(move(f)); } template void Foam::PtrField::operator=(const tmp& tf) { if (this == &(tf())) { FatalErrorInFunction << "attempted assignment to self" << abort(FatalError); } PtrField* fieldPtr = tf.ptr(); PtrList::transfer(*fieldPtr); delete fieldPtr; } template template void Foam::PtrField::operator=(const Expression& e) { expression::assertSameAllContainerProperty ( *this, e ); forAll(*this, i) { this->operator[](i) = expression::access(e, i); } } template void Foam::PtrField::operator= ( const typename PtrField::pType& t ) { forAll(*this, i) { this->operator[](i) = t; } } #define COMPUTED_ASSIGNMENT(TYPE, PTYPE, op) \ \ template \ void Foam::PtrField::operator op(const PtrField& f) \ { \ forAll(*this, i) \ { \ this->operator[](i) op f[i]; \ } \ } \ \ template \ void Foam::PtrField::operator op \ ( \ const tmp>& tf \ ) \ { \ operator op(tf()); \ tf.clear(); \ } \ \ template \ template \ void Foam::PtrField::operator op(const Expression& e) \ { \ /* Error if the expression is a different size */ \ expression::assertSameAllContainerProperty \ ( \ *this, \ e \ ); \ \ forAll(*this, i) \ { \ this->operator[](i) op expression::access(e, i); \ } \ } \ \ template \ void Foam::PtrField::operator op(const PTYPE& t) \ { \ forAll(*this, i) \ { \ this->operator[](i) op t; \ } \ } #define pType_ typename PtrField::pType COMPUTED_ASSIGNMENT(Type, pType_, +=) COMPUTED_ASSIGNMENT(Type, pType_, -=) #undef pType_ #define cmptField_ typename PtrField::cmptField #define pCmptType_ typename PtrField::pCmptType COMPUTED_ASSIGNMENT(cmptField_, pCmptType_, *=) COMPUTED_ASSIGNMENT(cmptField_, pCmptType_, /=) #undef pCmptType_ #undef cmptField_ #undef COMPUTED_ASSIGNMENT // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // template Foam::Ostream& Foam::operator<<(Ostream& os, const PtrField& f) { os << static_cast&>(f); return os; } // ************************************************************************* //