64 const word&
type() const noexcept {
return type_; }
65 const word&
name() const noexcept {
return name_; }
67 explicit fieldDescription(Istream& is)
73 if (type_.ends_with(
"Value"))
75 type_.erase(type_.size()-5);
83bool consumeUnusedType(
const fieldDescription& fieldDesc,
Istream& is)
90 const bool isExpectedType
92 fieldDesc.type() == fieldType1::typeName
93 || fieldDesc.type() == fieldType2::typeName
101 return isExpectedType;
106static bool consumeUnused(
const fieldDescription& fieldDesc,
Istream& is)
110 consumeUnusedType<scalar>(fieldDesc, is)
111 || consumeUnusedType<vector>(fieldDesc, is)
112 || consumeUnusedType<sphericalTensor>(fieldDesc, is)
113 || consumeUnusedType<symmTensor>(fieldDesc, is)
114 || consumeUnusedType<tensor>(fieldDesc, is)
125 const fieldDescription& fieldDesc,
133 const bool isExpectedType
135 fieldDesc.type() == fieldType::typeName
151 mesh.thisDb().time().timeName(),
158 bool found = fieldHeader.typeHeaderOk<fieldType>(
true);
163 fieldHeader.resetHeader();
164 fieldHeader.instance() =
mesh.thisDb().time().constant();
165 found = fieldHeader.typeHeaderOk<fieldType>(
true);
171 Info<<
" - set internal values of "
172 << fieldHeader.headerClassName()
173 <<
": " << fieldDesc.name()
174 <<
" = " << fieldValue <<
endl;
176 fieldType
field(fieldHeader,
mesh,
false);
180 field.primitiveFieldRef() = fieldValue;
184 for (
const label celli : selectedCells)
186 field[celli] = fieldValue;
191 for (
auto& pfld :
field.boundaryFieldRef())
193 pfld = pfld.patchInternalField();
197 field.boundaryFieldRef().template evaluateCoupled<coupledFvPatch>();
202 <<
"Failed writing field " <<
field.name() <<
endl;
208 <<
"Field " << fieldDesc.name() <<
" not found" <<
endl;
211 return isExpectedType;
221 const fieldDescription& fieldDesc,
229 const bool isExpectedType
231 fieldDesc.type() == fieldType::typeName
247 mesh.thisDb().time().timeName(),
254 bool found = fieldHeader.typeHeaderOk<fieldType>(
true);
259 fieldHeader.resetHeader();
260 fieldHeader.instance() =
mesh.thisDb().time().constant(),
261 found = fieldHeader.typeHeaderOk<fieldType>(
true);
267 Info<<
" - set internal values of "
268 << fieldHeader.headerClassName()
269 <<
": " << fieldDesc.name()
270 <<
" = " << fieldValue <<
endl;
276 field.primitiveFieldRef() = fieldValue;
280 for (
const label facei : selectedFaces)
282 field[facei] = fieldValue;
287 field.boundaryFieldRef().template evaluateCoupled<coupledFaPatch>();
292 <<
"Failed writing field " <<
field.name() <<
endl;
298 <<
"Field " << fieldDesc.name() <<
" not found" <<
endl;
301 return isExpectedType;
311 const fieldDescription& fieldDesc,
319 const bool isExpectedType
321 fieldDesc.type() == fieldType::typeName
337 mesh.thisDb().time().timeName(),
344 bool found = fieldHeader.typeHeaderOk<fieldType>(
true);
349 fieldHeader.resetHeader();
350 fieldHeader.instance() =
mesh.thisDb().time().constant();
351 found = fieldHeader.typeHeaderOk<fieldType>(
true);
357 Info<<
" - set boundary values of "
358 << fieldHeader.headerClassName()
359 <<
": " << fieldDesc.name()
360 <<
" = " << fieldValue <<
endl;
366 for (
const auto& pfld :
field.boundaryField())
372 pfld.patch().offset()
377 unsigned hasWarned = 0;
384 for (
const label facei : selectedFaces)
386 const label bFacei = facei-
mesh.nInternalFaces();
390 if (!(hasWarned & 1))
394 <<
"Ignoring internal face " << facei
395 <<
". Suppressing further warnings." <<
endl;
398 else if (bFacei >=
mesh.nBoundaryFaces())
400 if (!(hasWarned & 2))
404 <<
"Ignoring out-of-range face " << facei
405 <<
". Suppressing further warnings." <<
endl;
410 const label patchi =
mesh.boundaryMesh().patchID()[bFacei];
412 allBoundaryValues[bFacei] = fieldValue;
419 auto& fieldBf =
field.boundaryFieldRef();
424 if (nChanged[patchi] > 0)
427 <<
field.boundaryField()[patchi].patch().name()
428 <<
" set " << nChanged[patchi] <<
" values" <<
endl;
433 fieldBf[patchi].size(),
434 fieldBf[patchi].
patch().offset()
440 field.boundaryFieldRef().template evaluateCoupled<coupledFvPatch>();
445 <<
"Failed writing field " <<
field.name() <<
endl;
451 <<
"Field " << fieldDesc.name() <<
" not found" <<
endl;
454 return isExpectedType;
463 autoPtr<setCellField> clone()
const {
return nullptr; }
467 const fieldDescription& fieldDesc,
469 const labelUList& selectedCells,
475 setCellFieldType<scalar>(fieldDesc, m, selectedCells, is)
476 || setCellFieldType<vector>(fieldDesc, m, selectedCells, is)
477 || setCellFieldType<sphericalTensor>(fieldDesc, m, selectedCells, is)
478 || setCellFieldType<symmTensor>(fieldDesc, m, selectedCells, is)
479 || setCellFieldType<tensor>(fieldDesc, m, selectedCells, is)
490 iNew(
const fvMesh&
mesh,
const labelUList& selectedCells)
noexcept
493 selected_(selectedCells)
496 autoPtr<setCellField> operator()(Istream& is)
const
498 const fieldDescription fieldDesc(is);
500 bool ok = setCellField::apply(fieldDesc, mesh_, selected_, is);
504 ok = consumeUnused(fieldDesc, is);
509 Info<<
"Skip " << fieldDesc.type()
510 <<
" for finite-volume" <<
nl;
515 <<
"Unsupported field type: "
516 << fieldDesc.type() <<
endl;
531 autoPtr<setFaceField> clone()
const {
return nullptr; }
535 const fieldDescription& fieldDesc,
537 const labelUList& selectedFaces,
543 setFaceFieldType<scalar>(fieldDesc, m, selectedFaces, is)
544 || setFaceFieldType<vector>(fieldDesc, m, selectedFaces, is)
545 || setFaceFieldType<sphericalTensor>(fieldDesc, m, selectedFaces, is)
546 || setFaceFieldType<symmTensor>(fieldDesc, m, selectedFaces, is)
547 || setFaceFieldType<tensor>(fieldDesc, m, selectedFaces, is)
558 iNew(
const fvMesh&
mesh,
const labelUList& selectedFaces)
noexcept
561 selected_(selectedFaces)
564 autoPtr<setFaceField> operator()(Istream& is)
const
566 const fieldDescription fieldDesc(is);
568 bool ok = setFaceField::apply(fieldDesc, mesh_, selected_, is);
572 ok = consumeUnused(fieldDesc, is);
577 Info<<
"Skip " << fieldDesc.type()
578 <<
" for finite-volume" <<
nl;
583 <<
"Unsupported field type: "
584 << fieldDesc.type() <<
endl;
599 autoPtr<setAreaField> clone()
const {
return nullptr; }
603 const fieldDescription& fieldDesc,
605 const labelUList& selectedFaces,
611 setAreaFieldType<scalar>(fieldDesc, m, selectedFaces, is)
612 || setAreaFieldType<vector>(fieldDesc, m, selectedFaces, is)
613 || setAreaFieldType<sphericalTensor>(fieldDesc, m, selectedFaces, is)
614 || setAreaFieldType<symmTensor>(fieldDesc, m, selectedFaces, is)
615 || setAreaFieldType<tensor>(fieldDesc, m, selectedFaces, is)
626 iNew(
const faMesh&
mesh,
const labelUList& selectedFaces)
noexcept
629 selected_(selectedFaces)
632 autoPtr<setAreaField> operator()(Istream& is)
const
634 const fieldDescription fieldDesc(is);
636 bool ok = setAreaField::apply(fieldDesc, mesh_, selected_, is);
640 ok = consumeUnused(fieldDesc, is);
645 Info<<
"Skip " << fieldDesc.type()
646 <<
" for finite-volume" <<
nl;
651 <<
"Unsupported field type: "
652 << fieldDesc.type() <<
endl;
664int main(
int argc,
char *argv[])
672 "Set values on a selected set of cells/patch-faces via a dictionary"
680 "Suppress handling of finite-area mesh/fields"
699 if (
args.found(
"no-finite-area"))
713 label nGoodRegions(0);
721 faMeshes.
set(nGoodRegions++, std::move(faMeshPtr));
725 faMeshes.
resize(nGoodRegions);
728 if (faMeshes.
size() == 1)
730 Info<<
"Using finite-area mesh";
741 else if (faMeshes.
size() > 1)
743 Info<<
"Detected finite-area meshes:";
774 Info<<
"Setting volume field default values" <<
endl;
784 Info<<
"Setting area field default values";
808 Info<<
"Setting field region values" <<
nl <<
endl;
812 for (
const entry& region : regions)
832 stats[0] = selectedCells.
size();
833 stats[1] =
mesh.nCells();
836 Info<<
" Selected " << stats[0] <<
'/' << stats[1]
840 ITstream& is = region.dict().lookup(
"fieldValues");
845 setCellField::iNew(
mesh, selectedCells)
854 mesh.nBoundaryFaces()/10+1
861 Info<<
" Selected " << selectedFaces.
size()
864 ITstream& is = region.dict().lookup(
"fieldValues");
869 setFaceField::iNew(
mesh, selectedFaces)
884 if (
subset.test(meshFacei))
886 areaFaces[nUsed] = facei;
890 areaFaces.resize(nUsed);
894 stats[0] = areaFaces.
size();
898 Info<<
" Selected " << stats[0] <<
'/' << stats[1]
907 setAreaField::iNew(
areaMesh, areaFaces)
labelList faceLabels(nFaceLabels)
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
A 1D vector of objects of type <T> with a fixed length <N>.
static constexpr label size() noexcept
Return the number of elements in the FixedList.
Generic GeometricField class.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
@ NO_REGISTER
Do not request registration (bool: false).
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
An input stream of tokens.
virtual void rewind() override
Rewind the stream so that it may be read again. Same as seek(0).
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
static const List< label > & null() noexcept
static void listReduce(UList< T > &values, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce list elements (list must be equal size on all ranks), applying bop to each list element.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie,...
void resize(const label newLen)
Adjust size of PtrList.
SubField is a Field obtained as a section of another Field, without its own allocation....
void size(const label n)
Older name for setAddressableSize.
label size() const noexcept
The number of entries in the list.
Mesh data needed to do the Finite Area discretisation.
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
static void addNote(const string ¬e)
Add extra notes for the usage information.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A collection of cell labels.
A keyword and a list of tokens is an 'entry'.
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
static autoPtr< faMesh > TryNew(const word &areaName, const polyMesh &pMesh)
Read construction from polyMesh if all files are available.
Mesh data needed to do the Finite Volume discretisation.
A traits class, which is primarily used for primitives and vector-space.
static const word & regionName(const word ®ion)
The mesh region name or word::null if polyMesh::defaultRegion.
static void addOptions_singleTime()
Add single-time timeSelector options to argList::validOptions().
static bool setTimeIfPresent(Time &runTime, const argList &args, const bool forceInitial=false)
Set the runTime based on -constant (if present), -time (value), or -latestTime.
@ FACESET_SOURCE
Faces as set.
@ CELLSET_SOURCE
Cells as set.
@ NEW
Create a new set and ADD elements to it.
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
A class for handling words, derived from Foam::string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const word dictName("faMeshDefinition")
return returnReduce(nRefine-oldNRefine, sumOp< label >())
#define WarningInFunction
Report a warning using Foam::Warning.
const std::string patch
OpenFOAM patch number as a std::string.
List< label > labelList
A List of labels.
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
static constexpr const zero Zero
Global zero (0).
UList< label > labelUList
A UList of labels.
bool isNull(const T *ptr) noexcept
True if ptr is a pointer (of type T) to the nullObject.
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional 'FOAM Warning' header text.
constexpr char nl
The newline '\n' character (0x0a).
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.