53 class fieldDescription
63 explicit fieldDescription(
Istream& is)
69 if (type_.ends_with(
"Value"))
71 type_.erase(type_.size()-5);
79 bool consumeUnusedType(
const fieldDescription& fieldDesc,
Istream& is)
88 fieldDesc.type() == fieldType1::typeName
89 || fieldDesc.type() == fieldType2::typeName
101 static bool consumeUnused(
const fieldDescription& fieldDesc,
Istream& is)
105 consumeUnusedType<scalar>(fieldDesc, is)
106 || consumeUnusedType<vector>(fieldDesc, is)
107 || consumeUnusedType<sphericalTensor>(fieldDesc, is)
108 || consumeUnusedType<symmTensor>(fieldDesc, is)
109 || consumeUnusedType<tensor>(fieldDesc, is)
118 bool setCellFieldType
120 const fieldDescription& fieldDesc,
128 if (fieldDesc.type() != fieldType::typeName)
146 bool found = fieldHeader.typeHeaderOk<fieldType>(
true);
158 found = fieldHeader.typeHeaderOk<fieldType>(
true);
164 Info<<
" - set internal values of " 165 << fieldHeader.headerClassName()
166 <<
": " << fieldDesc.name()
167 <<
" = " << fieldValue <<
endl;
169 fieldType
field(fieldHeader,
mesh,
false);
173 field.primitiveFieldRef() = fieldValue;
177 for (
const label celli : selectedCells)
179 field[celli] = fieldValue;
184 for (
auto& pfld :
field.boundaryFieldRef())
186 pfld = pfld.patchInternalField();
192 <<
"Failed writing field " <<
field.name() <<
endl;
198 <<
"Field " << fieldDesc.name() <<
" not found" <<
endl;
209 bool setAreaFieldType
211 const fieldDescription& fieldDesc,
219 if (fieldDesc.type() != fieldType::typeName)
237 bool found = fieldHeader.typeHeaderOk<fieldType>(
true);
249 found = fieldHeader.typeHeaderOk<fieldType>(
true);
255 Info<<
" - set internal values of " 256 << fieldHeader.headerClassName()
257 <<
": " << fieldDesc.name()
258 <<
" = " << fieldValue <<
endl;
264 field.primitiveFieldRef() = fieldValue;
268 for (
const label facei : selectedFaces)
270 field[facei] = fieldValue;
277 <<
"Failed writing field " <<
field.name() <<
endl;
283 <<
"Field " << fieldDesc.name() <<
" not found" <<
endl;
294 bool setFaceFieldType
296 const fieldDescription& fieldDesc,
304 if (fieldDesc.type() != fieldType::typeName)
322 bool found = fieldHeader.typeHeaderOk<fieldType>(
true);
334 found = fieldHeader.typeHeaderOk<fieldType>(
true);
340 Info<<
" - set boundary values of " 341 << fieldHeader.headerClassName()
342 <<
": " << fieldDesc.name()
343 <<
" = " << fieldValue <<
endl;
354 field.boundaryField()[patchi].size(),
355 field.boundaryField()[patchi].patch().start()
357 ) =
field.boundaryField()[patchi];
361 unsigned hasWarned = 0;
368 for (
const label facei : selectedFaces)
374 if (!(hasWarned & 1))
378 <<
"Ignoring internal face " << facei
379 <<
". Suppressing further warnings." <<
endl;
384 if (!(hasWarned & 2))
388 <<
"Ignoring out-of-range face " << facei
389 <<
". Suppressing further warnings." <<
endl;
396 allBoundaryValues[bFacei] = fieldValue;
403 auto& fieldBf =
field.boundaryFieldRef();
408 if (nChanged[patchi] > 0)
411 <<
field.boundaryField()[patchi].patch().name()
412 <<
" set " << nChanged[patchi] <<
" values" <<
endl;
417 fieldBf[patchi].
size(),
418 fieldBf[patchi].patch().start()
427 <<
"Failed writing field " <<
field.name() <<
endl;
433 <<
"Field " << fieldDesc.name() <<
" not found" <<
endl;
449 const fieldDescription& fieldDesc,
457 setCellFieldType<scalar>(fieldDesc, m, selectedCells, is)
458 || setCellFieldType<vector>(fieldDesc, m, selectedCells, is)
459 || setCellFieldType<sphericalTensor>(fieldDesc, m, selectedCells, is)
460 || setCellFieldType<symmTensor>(fieldDesc, m, selectedCells, is)
461 || setCellFieldType<tensor>(fieldDesc, m, selectedCells, is)
475 selected_(selectedCells)
480 const fieldDescription fieldDesc(is);
486 ok = consumeUnused(fieldDesc, is);
491 Info<<
"Skip " << fieldDesc.type()
492 <<
" for finite-volume" <<
nl;
497 <<
"Unsupported field type: " 498 << fieldDesc.type() <<
endl;
517 const fieldDescription& fieldDesc,
525 setFaceFieldType<scalar>(fieldDesc, m, selectedFaces, is)
526 || setFaceFieldType<vector>(fieldDesc, m, selectedFaces, is)
527 || setFaceFieldType<sphericalTensor>(fieldDesc, m, selectedFaces, is)
528 || setFaceFieldType<symmTensor>(fieldDesc, m, selectedFaces, is)
529 || setFaceFieldType<tensor>(fieldDesc, m, selectedFaces, is)
543 selected_(selectedFaces)
548 const fieldDescription fieldDesc(is);
554 ok = consumeUnused(fieldDesc, is);
559 Info<<
"Skip " << fieldDesc.type()
560 <<
" for finite-volume" <<
nl;
565 <<
"Unsupported field type: " 566 << fieldDesc.type() <<
endl;
585 const fieldDescription& fieldDesc,
593 setAreaFieldType<scalar>(fieldDesc, m, selectedFaces, is)
594 || setAreaFieldType<vector>(fieldDesc, m, selectedFaces, is)
595 || setAreaFieldType<sphericalTensor>(fieldDesc, m, selectedFaces, is)
596 || setAreaFieldType<symmTensor>(fieldDesc, m, selectedFaces, is)
597 || setAreaFieldType<tensor>(fieldDesc, m, selectedFaces, is)
611 selected_(selectedFaces)
616 const fieldDescription fieldDesc(is);
622 ok = consumeUnused(fieldDesc, is);
627 Info<<
"Skip " << fieldDesc.type()
628 <<
" for finite-volume" <<
nl;
633 <<
"Unsupported field type: " 634 << fieldDesc.type() <<
endl;
646 int main(
int argc,
char *argv[])
650 "Set values on a selected set of cells/patch-faces via a dictionary" 658 "Suppress handling of finite-area mesh/fields" 674 Info<<
"Detected finite-area mesh" <<
nl;
700 Info<<
"Setting volume field default values" <<
endl;
713 Info<<
"Setting area field default values" <<
endl;
726 Info<<
"Setting field region values" <<
nl <<
endl;
730 for (
const entry& region : regions)
754 ITstream& is = region.dict().lookup(
"fieldValues");
759 setCellField::iNew(
mesh, selectedCells)
775 Info<<
" Selected " << selectedFaces.
size()
778 ITstream& is = region.dict().lookup(
"fieldValues");
783 setFaceField::iNew(
mesh, selectedFaces)
798 const label meshFacei = faceLabels[facei];
800 if (
subset.test(meshFacei))
802 areaFaces[nUsed] = facei;
806 areaFaces.resize(nUsed);
812 <<
" area faces" <<
nl;
819 setAreaField::iNew(
areaMesh, areaFaces)
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
static void addNote(const string ¬e)
Add extra notes for the usage information.
void size(const label n)
Older name for setAddressableSize.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const word & name() const noexcept
Return the object name.
Create a new set and ADD elements to it.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
const word dictName("faMeshDefinition")
static void apply(bitSet &selection, const Detail::parcelSelection::actionType action, const Predicate &accept, const UList< Type > &list, const AccessOp &aop)
Ostream & endl(Ostream &os)
Add newline and flush stream.
const labelList & patchID() const
Per boundary face label the patch index.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Generic GeometricField class.
static const List< label > & null()
Return a null List.
SubField is a Field obtained as a section of another Field, without its own allocation. SubField is derived from a SubList rather than a List.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
#define forAll(list, i)
Loop across all elements in list.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Generic templated field type.
A class for handling words, derived from Foam::string.
const Time & time() const noexcept
Return time registry.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
label nInternalFaces() const noexcept
Number of internal faces.
virtual void rewind()
Rewind the stream so that it may be read again.
bool isNull(const T *ptr)
True if ptr is a pointer (of type T) to the nullObject.
static word timeName(const scalar t, const int precision=precision_)
Return time name of given scalar time formatted with the given precision.
const word & constant() const noexcept
Return constant name.
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional 'FOAM Warning' header text...
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const =0
Apply specified action to the topoSet.
#define WarningInFunction
Report a warning using Foam::Warning.
label nCells() const noexcept
Number of mesh cells.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
A collection of cell labels.
Mesh data needed to do the Finite Volume discretisation.
static autoPtr< faMesh > TryNew(const polyMesh &pMesh)
Read construction from polyMesh if all files are available.
Mesh data needed to do the Finite Area discretisation.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
virtual ITstream & stream() const =0
Return token stream, if entry is a primitive entry.
label nBoundaryFaces() const noexcept
Number of boundary faces (== nFaces - nInternalFaces)
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
bool found(const word &optName) const
Return true if the named option is found.
An input stream of tokens.
A keyword and a list of tokens is an 'entry'.
static void listCombineReduce(List< T > &values, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
After completion all processors have the same data.
static constexpr const zero Zero
Global zero (0)