56 class fieldDescription
66 explicit fieldDescription(
Istream& is)
72 if (type_.ends_with(
"Value"))
74 type_.erase(type_.size()-5);
82 bool consumeUnusedType(
const fieldDescription& fieldDesc,
Istream& is)
91 fieldDesc.type() == fieldType1::typeName
92 || fieldDesc.type() == fieldType2::typeName
104 static bool consumeUnused(
const fieldDescription& fieldDesc,
Istream& is)
108 consumeUnusedType<scalar>(fieldDesc, is)
109 || consumeUnusedType<vector>(fieldDesc, is)
110 || consumeUnusedType<sphericalTensor>(fieldDesc, is)
111 || consumeUnusedType<symmTensor>(fieldDesc, is)
112 || consumeUnusedType<tensor>(fieldDesc, is)
121 bool setCellFieldType
123 const fieldDescription& fieldDesc,
131 if (fieldDesc.type() != fieldType::typeName)
149 bool found = fieldHeader.typeHeaderOk<fieldType>(
true);
161 found = fieldHeader.typeHeaderOk<fieldType>(
true);
167 Info<<
" - set internal values of " 168 << fieldHeader.headerClassName()
169 <<
": " << fieldDesc.name()
170 <<
" = " << fieldValue <<
endl;
172 fieldType
field(fieldHeader,
mesh,
false);
176 field.primitiveFieldRef() = fieldValue;
180 for (
const label celli : selectedCells)
182 field[celli] = fieldValue;
187 for (
auto& pfld :
field.boundaryFieldRef())
189 pfld = pfld.patchInternalField();
193 field.boundaryFieldRef().template evaluateCoupled<coupledFvPatch>();
198 <<
"Failed writing field " <<
field.name() <<
endl;
204 <<
"Field " << fieldDesc.name() <<
" not found" <<
endl;
215 bool setAreaFieldType
217 const fieldDescription& fieldDesc,
225 if (fieldDesc.type() != fieldType::typeName)
243 bool found = fieldHeader.typeHeaderOk<fieldType>(
true);
255 found = fieldHeader.typeHeaderOk<fieldType>(
true);
261 Info<<
" - set internal values of " 262 << fieldHeader.headerClassName()
263 <<
": " << fieldDesc.name()
264 <<
" = " << fieldValue <<
endl;
270 field.primitiveFieldRef() = fieldValue;
274 for (
const label facei : selectedFaces)
276 field[facei] = fieldValue;
281 field.boundaryFieldRef().template evaluateCoupled<coupledFaPatch>();
286 <<
"Failed writing field " <<
field.name() <<
endl;
292 <<
"Field " << fieldDesc.name() <<
" not found" <<
endl;
303 bool setFaceFieldType
305 const fieldDescription& fieldDesc,
313 if (fieldDesc.type() != fieldType::typeName)
331 bool found = fieldHeader.typeHeaderOk<fieldType>(
true);
343 found = fieldHeader.typeHeaderOk<fieldType>(
true);
349 Info<<
" - set boundary values of " 350 << fieldHeader.headerClassName()
351 <<
": " << fieldDesc.name()
352 <<
" = " << fieldValue <<
endl;
363 field.boundaryField()[patchi].size(),
364 field.boundaryField()[patchi].patch().start()
366 ) =
field.boundaryField()[patchi];
370 unsigned hasWarned = 0;
377 for (
const label facei : selectedFaces)
383 if (!(hasWarned & 1))
387 <<
"Ignoring internal face " << facei
388 <<
". Suppressing further warnings." <<
endl;
393 if (!(hasWarned & 2))
397 <<
"Ignoring out-of-range face " << facei
398 <<
". Suppressing further warnings." <<
endl;
405 allBoundaryValues[bFacei] = fieldValue;
412 auto& fieldBf =
field.boundaryFieldRef();
417 if (nChanged[patchi] > 0)
420 <<
field.boundaryField()[patchi].patch().name()
421 <<
" set " << nChanged[patchi] <<
" values" <<
endl;
426 fieldBf[patchi].
size(),
427 fieldBf[patchi].patch().start()
434 field.boundaryFieldRef().template evaluateCoupled<coupledFvPatch>();
439 <<
"Failed writing field " <<
field.name() <<
endl;
445 <<
"Field " << fieldDesc.name() <<
" not found" <<
endl;
461 const fieldDescription& fieldDesc,
469 setCellFieldType<scalar>(fieldDesc, m, selectedCells, is)
470 || setCellFieldType<vector>(fieldDesc, m, selectedCells, is)
471 || setCellFieldType<sphericalTensor>(fieldDesc, m, selectedCells, is)
472 || setCellFieldType<symmTensor>(fieldDesc, m, selectedCells, is)
473 || setCellFieldType<tensor>(fieldDesc, m, selectedCells, is)
487 selected_(selectedCells)
492 const fieldDescription fieldDesc(is);
498 ok = consumeUnused(fieldDesc, is);
503 Info<<
"Skip " << fieldDesc.type()
504 <<
" for finite-volume" <<
nl;
509 <<
"Unsupported field type: " 510 << fieldDesc.type() <<
endl;
529 const fieldDescription& fieldDesc,
537 setFaceFieldType<scalar>(fieldDesc, m, selectedFaces, is)
538 || setFaceFieldType<vector>(fieldDesc, m, selectedFaces, is)
539 || setFaceFieldType<sphericalTensor>(fieldDesc, m, selectedFaces, is)
540 || setFaceFieldType<symmTensor>(fieldDesc, m, selectedFaces, is)
541 || setFaceFieldType<tensor>(fieldDesc, m, selectedFaces, is)
555 selected_(selectedFaces)
560 const fieldDescription fieldDesc(is);
566 ok = consumeUnused(fieldDesc, is);
571 Info<<
"Skip " << fieldDesc.type()
572 <<
" for finite-volume" <<
nl;
577 <<
"Unsupported field type: " 578 << fieldDesc.type() <<
endl;
597 const fieldDescription& fieldDesc,
605 setAreaFieldType<scalar>(fieldDesc, m, selectedFaces, is)
606 || setAreaFieldType<vector>(fieldDesc, m, selectedFaces, is)
607 || setAreaFieldType<sphericalTensor>(fieldDesc, m, selectedFaces, is)
608 || setAreaFieldType<symmTensor>(fieldDesc, m, selectedFaces, is)
609 || setAreaFieldType<tensor>(fieldDesc, m, selectedFaces, is)
623 selected_(selectedFaces)
628 const fieldDescription fieldDesc(is);
634 ok = consumeUnused(fieldDesc, is);
639 Info<<
"Skip " << fieldDesc.type()
640 <<
" for finite-volume" <<
nl;
645 <<
"Unsupported field type: " 646 << fieldDesc.type() <<
endl;
658 int main(
int argc,
char *argv[])
666 "Set values on a selected set of cells/patch-faces via a dictionary" 674 "Suppress handling of finite-area mesh/fields" 697 Info<<
"Detected finite-area mesh" <<
nl;
723 Info<<
"Setting volume field default values" <<
endl;
736 Info<<
"Setting area field default values" <<
endl;
749 Info<<
"Setting field region values" <<
nl <<
endl;
753 for (
const entry& region : regions)
777 ITstream& is = region.dict().lookup(
"fieldValues");
782 setCellField::iNew(
mesh, selectedCells)
798 Info<<
" Selected " << selectedFaces.
size()
801 ITstream& is = region.dict().lookup(
"fieldValues");
806 setFaceField::iNew(
mesh, selectedFaces)
823 if (
subset.test(meshFacei))
825 areaFaces[nUsed] = facei;
835 <<
" area faces" <<
nl;
842 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 noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
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.
static bool setTimeIfPresent(Time &runTime, const argList &args, const bool forceInitial=false)
Set the runTime based on -constant (if present), -time (value), or -latestTime.
Generic GeometricField class.
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 addOptions_singleTime()
Add single-time timeSelector options to argList::validOptions()
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) noexcept
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.
static autoPtr< faMesh > TryNew(const word &meshName, const polyMesh &pMesh)
Read construction from polyMesh if all files are available.
Mesh data needed to do the Finite Volume discretisation.
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...
static const List< label > & null() noexcept
Return a null List (reference to a nullObject). Behaves like an empty List.
bool found(const word &optName) const
Return true if the named option is found.
An input stream of tokens.
virtual void rewind() override
Rewind the stream so that it may be read again. Same as seek(0)
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)
Combines List elements. After completion all processors have the same data.
static constexpr const zero Zero
Global zero (0)