Commit Graph

91 Commits

Author SHA1 Message Date
Andrew Heather
a2014242cf RELEASE: Updated headers for v2112 2021-12-20 14:18:01 +00:00
Mark Olesen
1804d3fed5 ENH: additional #word and #message dictionary directives (#2276)
- use `#word` to concatenate, expand content with the resulting string
  being treated as a word token. Can be used in dictionary or
  primitive context.

  In dictionary context, it fills the gap for constructing dictionary
  names on-the-fly. For example,

  ```
  #word "some_prefix_solverInfo_${application}"
  {
      type    solverInfo;
      libs    (utilityFunctionObjects);
      ...
  }
  ```

  The '#word' directive will automatically squeeze out non-word
  characters. In the block content form, it will also strip out
  comments. This means that this type of content should also work:

  ```
  #word {
     some_prefix_solverInfo
     /* Appended with application name (if defined) */
     ${application:+_}  // Use '_' separator
     ${application}     // The application
  }
  {
      type    solverInfo;
      libs    (utilityFunctionObjects);
      ...
  }
  ```
  This is admittedly quite ugly, but illustrates its capabilities.

- use `#message` to report expanded string content to stderr.
  For example,

  ```
  T
  {
     solver          PBiCG;
     preconditioner  DILU;
     tolerance       1e-10;
     relTol          0;
     #message "using solver: $solver"
  }
  ```
  Only reports on the master node.
2021-11-25 17:05:37 +01:00
Andrew Heather
e3796745ed CONFIG: Updated headers to v2106
Minor clean-up
2021-06-28 09:14:42 +01:00
Mark Olesen
efd1ac4b5f ENH: adjust token in preparation for separate expression tokenization
- minor simplification of #if/#endif handling

ENH: improve input robustness with negative-prefixed expansions (#2095)

- especially in blockMeshDict it is useful to negate an value directly.
  Eg,
  ```
     xmax  100;
     xmin  -$xmax;
  ```
  However, this fails since the dictionary expansion is a two-step
  process of tokenization followed by expansion. After the expansion
  the given input would now be the following:
  ```
     xmax  100;
     xmin  - 100;
  ```
  and retrieving a scalar value for 'xmin' fails.

  Counteract this by being more generous on tokenized input when
  attempting to retrieve a label or scalar value.
  If a '-' is found where a number is expected, use it to negate the
  subsequent value.

  The previous solution was to invoke an 'eval':
  ```
     xmax  100;
     xmin  #eval{-$xmax};
  ```
  which adds additional clutter.
2021-05-18 15:30:00 +02:00
Mark Olesen
b060378dca ENH: improve consistency of fileName handling windows/non-windows (#2057)
- wrap command-line retrieval of fileName with an implicit validate.

  Instead of this:
      fileName input(args[1]);
      fileName other(args["someopt"]);

  Now use this:
      auto input = args.get<fileName>(1);
      auto other = args.get<fileName>("someopt");

  which adds a fileName::validate on the inputs

  Because of how it is implemented, it will automatically also apply
  to argList getOrDefault<fileName>, readIfPresent<fileName> etc.

- adjust fileName::validate and clean to handle backslash conversion.
  This makes it easier to ensure that path names arising from MS-Windows
  are consistently handled internally.

- dictionarySearch: now check for initial '/' directly instead of
  relying on fileName isAbsolute(), which now does more things

BREAKING: remove fileName::clean() const method

- relying on const/non-const to control the behaviour (inplace change
  or return a copy) is too fragile and the const version was
  almost never used.

  Replace:
      fileName sanitized = constPath.clean();

  With:
      fileName sanitized(constPath);
      sanitized.clean());

STYLE: test empty() instead of comparing with fileName::null
2021-04-19 16:33:42 +00:00
Mark Olesen
21720bea12 ENH: support field width for #eval expressions
For example,
```
entry #eval 10 { vector(rand(), 0, 0) };
```

ENH: be more generous and ignore trailing ';' in expressions

STYLE: adjust parse token name for tensor::I
2021-03-29 16:00:11 +02:00
Mark Olesen
d4ac96cdf3 ENH: support use of 'vector' in #calc directive (fixes #2039) 2021-03-29 16:00:11 +02:00
Andrew Heather
79e353b84e RELEASE: Updated version to v2012 2020-12-23 10:01:39 +01:00
Andrew Heather
538d749220 REL: Updated headers to version v2006 2020-06-29 17:27:54 +01:00
Andrew Heather
ae2ab06312 REL: Release preparations 2019-12-23 09:49:23 +00:00
Mark Olesen
1cf795a40f ENH: use exprString expansions for #eval
- follows the principle of least surprise if the expansion behaviour
  for #eval and expressions (eg, exprFixedValue) are the same.  This
  is possible now that we harness the regular stringOps::expand()
  within exprString::expand()
2019-12-17 09:47:51 +01:00
Mark Olesen
c2123452b1 ENH: generalize string expression evaluation
- replace stringOps::toScalar with a more generic stringOps::evaluate
  method that handles scalars, vectors etc.

- improve #eval to handle various mathematical operations.
  Previously only handled scalars. Now produce vectors, tensors etc
  for the entries. These tokens are streamed directly into the entry.
2019-12-09 19:44:23 +01:00
Mark Olesen
9e6683f7bc ENH: add conditionals to #eval (string to scalar)
Example,

     ($radius > 10) ? sin(degToRad(45)) : cos(degToRad(30))

- protect division and modulo against zero-divide.

- add scanner/parser debugging switches in the namespace,
  selectable as "stringToScalar". For example,

    debug parser:  foamDictionary -debug-switch stringToScalar=2
    debug scanner: foamDictionary -debug-switch stringToScalar=4
    debug both:    foamDictionary -debug-switch stringToScalar=6
2019-11-19 14:22:03 +01:00
Andrew Heather
fdf8d10ab4 Merge commit 'e9219558d7' into develop-v1906 2019-12-05 11:47:19 +00:00
OpenFOAM bot
e9219558d7 GIT: Header file updates 2019-10-31 14:48:44 +00:00
Mark Olesen
177f4b79fe ENH: use direct scanning mode when lexing #eval expressions 2019-11-01 19:13:50 +01:00
Mark Olesen
6b5492e3bd ENH: code simplification, improvements for reading dictionary variables
- Now accept '/' when reading variables without requiring
  a surrounding '{}'

- fix some degenerate parsing cases when the first character is
  already bad.

  Eg, $"abc" would have previously parsed as a <$"> variable, even
  although a double quote is not a valid variable character.

  Now emits a warning and parses as a '$' token and a string token.
2019-10-08 18:43:38 +02:00
Mark Olesen
46225279c0 ENH: improvements to stringOps::expand operations
- add toScalar evaluation, embedded as "${{EXPR}}".

  For example,

    "repeat ${{5 * 7}} times or ${{ pow(3, 10) }}"

- use direct string concatenation if primitive entry is only a string
  type. This prevents spurious quotes from appearing in the expansion.

     radius  "(2+4)";
     angle   "3*15";
     #eval   "$radius*sin(degToRad($angle))";

     We want to have
         '(2+4)*sin(degToRad(3*15))'
     and not
         '"(2+4)"*sin(degToRad("3*15"))'

ENH: code refactoring

- refactored expansion code with low-level service routines now
  belonging to file-scope. All expansion routines use a common
  multi-parameter backend to handle with/without dictionary etc.
  This removes a large amount of code duplication.
2019-10-07 08:27:19 +02:00
Mark Olesen
bd35981feb ENH: stringOps::toScalar improvements
- add floor/ceil/round methods
- support evaluation of sub-strings

STYLE: add blockMeshDict1.calc, blockMeshDict1.eval test dictionaries

- useful for testing and simple demonstration of equivalence
2019-10-04 17:50:55 +02:00
Mark Olesen
836d3a849f ENH: add stringOps::toScalar and dictionary #eval directive
- the #eval directive is similar to the #calc directive, but for evaluating
  string expressions into scalar values. It uses an internal parser for
  the evaluation instead of dynamic code compilation. This can make it
  more suitable for 'quick' evaluations.

  The evaluation supports the following:
    - operations:  - + * /
    - functions:  exp, log, log10, pow, sqrt, cbrt, sqr, mag, magSqr
    - trigonometric:  sin, cos, tan, asin, acos, atan, atan2, hypot
    - hyperbolic:  sinh, cosh, tanh
    - conversions:  degToRad, radToDeg
    - constants:  pi()
    - misc: rand(), rand(seed)
2019-09-30 16:40:32 +02:00
Mark Olesen
b5342c166c ENH: handle keyType type (literal/regex) as enum instead of bool
- makes its use somewhat clearer and allows more future options
2019-08-20 13:48:05 +02:00
Andrew Heather
be44dcaf1f RELEASE: Version clean-up for release 2019-06-25 11:51:19 +01:00
OpenFOAM bot
154029ddd0 BOT: Cleaned up header files 2019-02-06 12:28:23 +00:00
Mark Olesen
22b659d7c0 ENH: export FOAM_API in dictionary (issue #1158)
- uses the value of foamVersion::api, which should be reliable.
2019-01-07 19:04:50 +01:00
Andrew Heather
9231534efa STYLE: Updating version to v1812 2018-12-19 18:07:52 +00:00
Mark Olesen
c6520033c9 ENH: rationalize dictionary access methods
- use keyType::option enum to consolidate searching options.
  These enumeration names should be more intuitive to use
  and improve code readability.

    Eg,   lookupEntry(key, keyType::REGEX);
    vs    lookupEntry(key, false, true);

  or

    Eg,   lookupEntry(key, keyType::LITERAL_RECURSIVE);
    vs    lookupEntry(key, true, false);

- new findEntry(), findDict(), findScoped() methods with consolidated
  search options for shorter naming and access names more closely
  aligned with other components. Behave simliarly to the
  methods lookupEntryPtr(), subDictPtr(), lookupScopedEntryPtr(),
  respectively. Default search parameters consistent with lookupEntry().

    Eg, const entry* e = dict.findEntry(key);
    vs  const entry* e = dict.lookupEntryPtr(key, false, true);

- added '*' and '->' dereference operators to dictionary searchers.
2018-10-15 16:16:12 +02:00
Andrew Heather
6e35bcda70 ENH: Updated config for release v1806 2018-06-28 12:56:00 +01:00
Mark Olesen
d318a630b6 ENH: add directive '#sinclude' (or '#includeIfPresent' as long name)
- consistency with make and more succinct.

- reduce code duplication in findEtcFiles.
2018-05-28 13:38:03 +02:00
Mark Olesen
2fde6c3ab0 ENH: improve handling of mismatched brackets, forgotten ';' (issue #762)
- flags the following type of problems:

  * mismatches:

        keyword  mismatch ( set of { brackets ) in the } entry;

  * underflow (too many closing brackets:

        keyword  too many ( set of ) brackets ) in ) entry;

- a missing semi-colon

        dict
        {
           keyword  entry with missing semi-colon
        }

  will be flagged as 'underflow', since it parses through the '}' but
  did not open with it.

Max monitoring depth is 60 levels of nesting, to avoid incurring any
memory allocation.
2018-04-25 09:55:00 +02:00
Mark Olesen
3d608bf06a ENH: remove reliance on the Xfer class (issue #639)
This class is largely a pre-C++11 holdover. It is now possible to
simply use move construct/assignment directly.

In a few rare cases (eg, polyMesh::resetPrimitives) it has been
replaced by an autoPtr.
2018-03-05 13:28:53 +01:00
Mark Olesen
f2ba618c19 STYLE: consistency in using argList::addArgument, argList::addOption 2017-11-22 12:54:28 +01:00
Mark Olesen
61534989df ENH: simplify primitiveEntry parsing code, move append new tokens
- simplify string output code
2017-11-05 22:07:17 +01:00
Mark Olesen
4e48beffd4 ENH: support "one-shot" changes to the dictionary inputMode (issue #429)
- Instead of relying on #inputMode to effect a global change it is now
  possible (and recommended) to a temporary change in the inputMode
  for the following entry.

     #default   : provide default value if entry is not already defined
     #overwrite : silently remove a previously existing entry
     #warn      : warn about duplicate entries
     #error     : error if any duplicate entries occur
     #merge     : merge sub-dictionaries when possible (the default mode)

  This is generally less cumbersome than the switching the global
  inputMode. For example to provide a set of fallback values.

      #includeIfPresent "user-files"
      ...
      #default value uniform 10;

  vs.

      #includeIfPresent "user-files"
      #inputMode protect
      ...
      value uniform 10;
      #inputMode merge    // _Assuming_ we actually had this before

  These directives can also be used to suppress the normal dictionary
  merge semantics:

     #overwrite dict { entry val; ... }
2017-07-29 17:44:22 +02:00
Mark Olesen
2fdc6b161a ENH: support full-scoping for keywords as lvalue (issue #429)
- patterns only supported for the final element.

  To create an element as a pattern instead of a word, an embedded
  string quote (single or double) is used for that element.
  Any of the following examples:

      "/top/sub/dict/'(p|U).*"     100;
      "/top/sub/dict/'(p|U).*'"    100;
      "/top/sub/dict/\"(p|U).*"    100;
      "/top/sub/dict/\"(p|U).*\""  100;

  are equivalent to the longer form:

      top
      {
          sub
          {
              dict
              {
                  "(p|U).*"     100;
              }
          }
      }

  It is not currently possible to auto-vivify intermediate
  dictionaries with patterns.

    NOK   "/nonexistent.*/value"   100;
    OK    "/existing.*/value"      100;

- full scoping also works for the #remove directive

        #remove "/dict1/subdict2/entry1"
2017-07-20 10:58:05 +02:00
Mark Olesen
5148e4f860 STYLE: manage dictionary inputMode directly within entry class
- The logic for switching input-mode was previously completely
  encapsulated within the #inputMode directive, but without any
  programming equivalent. Furthermore, the encapsulation in inputMode
  made the logic less clear in other places.

  Exposing the inputMode as an enum with direct access from entry
  simplifies things a fair bit.

- eliminate one level of else/if nesting in entryIO.C for clearer logic

- for dictionary function entries, simply use
  addNamedToMemberFunctionSelectionTable() and avoid defining a type()
  as a static. For most function entries the information is only used
  to get a name for the selection table lookup anyhow.
2017-08-03 07:14:17 +02:00
Mark Olesen
cc290b7c02 ENH: improve dictionary parsing behaviour for ill-formed entries (closes #510)
- mostly associated with forgotten quotes around "(abd|def)" ...

- Address different potential problems:

      (key) { key1   entry1; }
      (key) { key1   entry1; };    // <- Note trailing ';'
      (key) entry2;
2017-07-19 11:00:44 +02:00
Mark Olesen
84e47f2d2a ENH: cleanup dictionary code
- use typedefs and new features/methods
- file-scope template to avoid code duplication.
2017-07-06 12:58:04 +02:00
Mark Olesen
ffe3e0e425 ENH: allow '^' as anchor for dictionary scoping (issue #429)
- The existing ':' anchor works for rvalue substitutions
  (Eg, ${:subdict.name}), but fails for lvalues, since it is
  a punctuation token and parse stops there.
2017-04-25 11:57:21 +02:00
Mark Olesen
f05be160e2 BUG: dictionary entries not being properly merged/overwritten (closes #418)
STYLE: update dictionary documentation
2017-03-03 11:36:24 +01:00
Mark Olesen
6d5db96ad9 ENH: subdict output with leading name (issue #255)
- Introduce dictionary::writeEntries for better code-reuse.

  Before
  ======
      os << nl << indent << "name";
      dict.write(os);

  After
  =====
      dict.write(os, "name");
2016-06-09 18:33:56 +01:00
Andrew Heather
f0c3e8d599 STYLE: Updated version to 'plus' 2015-12-22 23:14:17 +00:00
Andrew Heather
8837a89237 STYLE: Updated links from openfoam.org to openfoam.com 2015-12-09 15:03:05 +00:00
OpenFOAM-admin
9fb26d59d3 GIT: Repo update 2014-12-11 08:35:10 +00:00
OpenFOAM-admin
fbb3ddf2c4 Updated for release 2.3.0 2014-02-17 10:21:46 +00:00
mattijs
7da6784897 ENH: testDict: key substitution 2013-05-08 14:11:13 +01:00
mattijs
6dc4de7d3f ENH: dictionary: recursive variable expansion 2012-10-15 16:00:03 +01:00
mattijs
78a7cdf7f3 ENH: Test-dictionary: test dictionary variable expansion 2012-10-12 17:52:52 +01:00
mattijs
87bab77daf ENH:dictionary: allow scoped variable lookup (using '.') 2012-09-12 09:14:43 +01:00
Henry
c2dd153a14 Copyright transfered to the OpenFOAM Foundation 2011-08-14 12:17:30 +01:00
OpenFOAM-admin
c720299876 ENH: Reverted back to version dev 2011-06-17 10:08:20 +01:00