55 class fieldDescription
65 explicit fieldDescription(
Istream& is)
71 if (type_.ends_with(
"Value"))
73 type_.erase(type_.size()-5);
81 bool consumeUnusedType(
const fieldDescription& fieldDesc,
Istream& is)
90 fieldDesc.type() == fieldType1::typeName
91 || fieldDesc.type() == fieldType2::typeName
103 static bool consumeUnused(
const fieldDescription& fieldDesc,
Istream& is)
107 consumeUnusedType<scalar>(fieldDesc, is)
108 || consumeUnusedType<vector>(fieldDesc, is)
109 || consumeUnusedType<sphericalTensor>(fieldDesc, is)
110 || consumeUnusedType<symmTensor>(fieldDesc, is)
111 || consumeUnusedType<tensor>(fieldDesc, is)
120 bool setCellFieldType
122 const fieldDescription& fieldDesc,
130 if (fieldDesc.type() != fieldType::typeName)
148 bool found = fieldHeader.typeHeaderOk<fieldType>(
true);
160 found = fieldHeader.typeHeaderOk<fieldType>(
true);
166 Info<<
" - set internal values of " 167 << fieldHeader.headerClassName()
168 <<
": " << fieldDesc.name()
169 <<
" = " << fieldValue <<
endl;
171 fieldType
field(fieldHeader,
mesh,
false);
175 field.primitiveFieldRef() = fieldValue;
179 for (
const label celli : selectedCells)
181 field[celli] = fieldValue;
186 for (
auto& pfld :
field.boundaryFieldRef())
188 pfld = pfld.patchInternalField();
192 field.boundaryFieldRef().template evaluateCoupled<coupledFvPatch>();
197 <<
"Failed writing field " <<
field.name() <<
endl;
203 <<
"Field " << fieldDesc.name() <<
" not found" <<
endl;
214 bool setAreaFieldType
216 const fieldDescription& fieldDesc,
224 if (fieldDesc.type() != fieldType::typeName)
242 bool found = fieldHeader.typeHeaderOk<fieldType>(
true);
254 found = fieldHeader.typeHeaderOk<fieldType>(
true);
260 Info<<
" - set internal values of " 261 << fieldHeader.headerClassName()
262 <<
": " << fieldDesc.name()
263 <<
" = " << fieldValue <<
endl;
269 field.primitiveFieldRef() = fieldValue;
273 for (
const label facei : selectedFaces)
275 field[facei] = fieldValue;
280 field.boundaryFieldRef().template evaluateCoupled<coupledFaPatch>();
285 <<
"Failed writing field " <<
field.name() <<
endl;
291 <<
"Field " << fieldDesc.name() <<
" not found" <<
endl;
302 bool setFaceFieldType
304 const fieldDescription& fieldDesc,
312 if (fieldDesc.type() != fieldType::typeName)
330 bool found = fieldHeader.typeHeaderOk<fieldType>(
true);
342 found = fieldHeader.typeHeaderOk<fieldType>(
true);
348 Info<<
" - set boundary values of " 349 << fieldHeader.headerClassName()
350 <<
": " << fieldDesc.name()
351 <<
" = " << fieldValue <<
endl;
362 field.boundaryField()[patchi].size(),
363 field.boundaryField()[patchi].patch().start()
365 ) =
field.boundaryField()[patchi];
369 unsigned hasWarned = 0;
376 for (
const label facei : selectedFaces)
382 if (!(hasWarned & 1))
386 <<
"Ignoring internal face " << facei
387 <<
". Suppressing further warnings." <<
endl;
392 if (!(hasWarned & 2))
396 <<
"Ignoring out-of-range face " << facei
397 <<
". Suppressing further warnings." <<
endl;
404 allBoundaryValues[bFacei] = fieldValue;
411 auto& fieldBf =
field.boundaryFieldRef();
416 if (nChanged[patchi] > 0)
419 <<
field.boundaryField()[patchi].patch().name()
420 <<
" set " << nChanged[patchi] <<
" values" <<
endl;
425 fieldBf[patchi].
size(),
426 fieldBf[patchi].patch().start()
433 field.boundaryFieldRef().template evaluateCoupled<coupledFvPatch>();
438 <<
"Failed writing field " <<
field.name() <<
endl;
444 <<
"Field " << fieldDesc.name() <<
" not found" <<
endl;
460 const fieldDescription& fieldDesc,
468 setCellFieldType<scalar>(fieldDesc, m, selectedCells, is)
469 || setCellFieldType<vector>(fieldDesc, m, selectedCells, is)
470 || setCellFieldType<sphericalTensor>(fieldDesc, m, selectedCells, is)
471 || setCellFieldType<symmTensor>(fieldDesc, m, selectedCells, is)
472 || setCellFieldType<tensor>(fieldDesc, m, selectedCells, is)
486 selected_(selectedCells)
491 const fieldDescription fieldDesc(is);
497 ok = consumeUnused(fieldDesc, is);
502 Info<<
"Skip " << fieldDesc.type()
503 <<
" for finite-volume" <<
nl;
508 <<
"Unsupported field type: " 509 << fieldDesc.type() <<
endl;
528 const fieldDescription& fieldDesc,
536 setFaceFieldType<scalar>(fieldDesc, m, selectedFaces, is)
537 || setFaceFieldType<vector>(fieldDesc, m, selectedFaces, is)
538 || setFaceFieldType<sphericalTensor>(fieldDesc, m, selectedFaces, is)
539 || setFaceFieldType<symmTensor>(fieldDesc, m, selectedFaces, is)
540 || setFaceFieldType<tensor>(fieldDesc, m, selectedFaces, is)
554 selected_(selectedFaces)
559 const fieldDescription fieldDesc(is);
565 ok = consumeUnused(fieldDesc, is);
570 Info<<
"Skip " << fieldDesc.type()
571 <<
" for finite-volume" <<
nl;
576 <<
"Unsupported field type: " 577 << fieldDesc.type() <<
endl;
596 const fieldDescription& fieldDesc,
604 setAreaFieldType<scalar>(fieldDesc, m, selectedFaces, is)
605 || setAreaFieldType<vector>(fieldDesc, m, selectedFaces, is)
606 || setAreaFieldType<sphericalTensor>(fieldDesc, m, selectedFaces, is)
607 || setAreaFieldType<symmTensor>(fieldDesc, m, selectedFaces, is)
608 || setAreaFieldType<tensor>(fieldDesc, m, selectedFaces, is)
622 selected_(selectedFaces)
627 const fieldDescription fieldDesc(is);
633 ok = consumeUnused(fieldDesc, is);
638 Info<<
"Skip " << fieldDesc.type()
639 <<
" for finite-volume" <<
nl;
644 <<
"Unsupported field type: " 645 << fieldDesc.type() <<
endl;
657 int main(
int argc,
char *argv[])
661 "Set values on a selected set of cells/patch-faces via a dictionary" 669 "Suppress handling of finite-area mesh/fields" 685 Info<<
"Detected finite-area mesh" <<
nl;
711 Info<<
"Setting volume field default values" <<
endl;
724 Info<<
"Setting area field default values" <<
endl;
737 Info<<
"Setting field region values" <<
nl <<
endl;
741 for (
const entry& region : regions)
765 ITstream& is = region.dict().lookup(
"fieldValues");
770 setCellField::iNew(
mesh, selectedCells)
786 Info<<
" Selected " << selectedFaces.
size()
789 ITstream& is = region.dict().lookup(
"fieldValues");
794 setFaceField::iNew(
mesh, selectedFaces)
811 if (
subset.test(meshFacei))
813 areaFaces[nUsed] = facei;
823 <<
" area faces" <<
nl;
830 setAreaField::iNew(
areaMesh, areaFaces)
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.
void resize(const label len)
Adjust allocated size of list.
#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.
labelList faceLabels(nFaceLabels)
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 expressions::valueTypeCode::INVALID.
Generic templated field type.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
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.
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 a time name for the given scalar time value 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 void rewind() override
Rewind the stream so that it may be read again. Same as seek(0)
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)