Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nektar
Nektar
Commits
4083fda0
Commit
4083fda0
authored
Jan 12, 2018
by
Kilian Lackhove
Browse files
turn addfieldfromstring into fieldfromstring and enable modifying existing fields
parent
796ba082
Changes
4
Hide whitespace changes
Inline
Side-by-side
docs/user-guide/utilities/fieldconvert.tex
View file @
4083fda0
...
...
@@ -157,7 +157,7 @@ Specifically, FieldConvert has these additional functionalities
\item
\inltt
{
QCriterion
}
: Computes the Q-Criterion for a given output file;
\item
\inltt
{
L2Criterion
}
: Computes the Lambda 2 Criterion for a given output file;
\item
\inltt
{
addcompositeid
}
: Adds the composite ID of an element as an additional field;
\item
\inltt
{
add
fieldfromstring
}
:
A
dds a new field from an expression involving the existing fields;
\item
\inltt
{
fieldfromstring
}
:
Modifies or a
dds a new field from an expression involving the existing fields;
\item
\inltt
{
addFld
}
: Sum two .fld files;
\item
\inltt
{
combineAvg
}
: Combine two
\nekpp
binary output (.chk or .fld) field file containing averages of fields (and
possibly also Reynolds stresses) into single file;
...
...
@@ -286,18 +286,18 @@ obtained through the \nm \inltt{extract} module (see section
%
%
%
\subsection
{
Add new field:
\textit
{
add
fieldfromstring
}
module
}
To create a new field using an expression involving the existing fields, one can
use the
\inltt
{
add
fieldfromstring
}
module of FieldConvert
\subsection
{
Add new field:
\textit
{
fieldfromstring
}
module
}
To
modify or
create a new field using an expression involving the existing fields, one can
use the
\inltt
{
fieldfromstring
}
module of FieldConvert
%
\begin{lstlisting}
[style=BashInputStyle]
FieldConvert -m
add
fieldfromstring:fieldstr="x+y+u":fieldname="result"
\
FieldConvert -m fieldfromstring:fieldstr="x+y+u":fieldname="result"
\
file1.xml file2.fld file3.fld
\end{lstlisting}
%
In this case
\inltt
{
fieldstr
}
is a required parameter describing a function of
the coordinates and the existing variables, and
\inltt
{
fieldname
}
is an optional
parameter defining the name of the new field (the default is newfield).
parameter defining the name of the new
or modified
field (the default is newfield).
\inltt
{
file3.fld
}
is the output containing both the original and the new fields,
and can be processed in a similar way as described
in section
\ref
{
s:utilities:fieldconvert:sub:convert
}
to visualise
...
...
library/FieldUtils/CMakeLists.txt
View file @
4083fda0
...
...
@@ -17,7 +17,7 @@ SET(FieldUtilsHeaders
OutputModules/OutputPts.h
OutputModules/OutputXml.h
ProcessModules/ProcessAddCompositeID.h
ProcessModules/Process
Add
FieldFromString.h
ProcessModules/ProcessFieldFromString.h
ProcessModules/ProcessAddFld.h
ProcessModules/ProcessBoundaryExtract.h
ProcessModules/ProcessCombineAvg.h
...
...
@@ -73,7 +73,7 @@ SET(FieldUtilsSources
OutputModules/OutputPts.cpp
OutputModules/OutputXml.cpp
ProcessModules/ProcessAddCompositeID.cpp
ProcessModules/Process
Add
FieldFromString.cpp
ProcessModules/ProcessFieldFromString.cpp
ProcessModules/ProcessAddFld.cpp
ProcessModules/ProcessBoundaryExtract.cpp
ProcessModules/ProcessCombineAvg.cpp
...
...
library/FieldUtils/ProcessModules/Process
Add
FieldFromString.cpp
→
library/FieldUtils/ProcessModules/ProcessFieldFromString.cpp
View file @
4083fda0
///////////////////////////////////////////////////////////////////////////////
//
// File: Process
Add
FieldFromString.cpp
// File: ProcessFieldFromString.cpp
//
// For more information, please see: http://www.nektar.info/
//
...
...
@@ -29,14 +29,14 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description:
A
dd a new field from a string based on existing variable
// Description:
Modify an existing or a
dd a new field from a string based on existing variable
//
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
using
namespace
std
;
#include "Process
Add
FieldFromString.h"
#include "ProcessFieldFromString.h"
#include <LibUtilities/BasicUtils/ParseUtils.h>
#include <LibUtilities/BasicUtils/SharedArray.hpp>
...
...
@@ -46,28 +46,30 @@ namespace Nektar
namespace
FieldUtils
{
ModuleKey
Process
Add
FieldFromString
::
className
=
ModuleKey
ProcessFieldFromString
::
className
=
GetModuleFactory
().
RegisterCreatorFunction
(
ModuleKey
(
eProcessModule
,
"addfieldfromstring"
),
ProcessAddFieldFromString
::
create
,
"Create a new field from the existing fields as specified by a string"
" using a required argument of the form fieldstr=
\"
x + y + u
\"
"
);
ModuleKey
(
eProcessModule
,
"fieldfromstring"
),
ProcessFieldFromString
::
create
,
"Modify an existing or create a new field from the existing fields as "
"specified by a string using a required argument of the form "
"fieldstr=
\"
x + y + u
\"
"
);
Process
Add
FieldFromString
::
Process
Add
FieldFromString
(
FieldSharedPtr
f
)
ProcessFieldFromString
::
ProcessFieldFromString
(
FieldSharedPtr
f
)
:
ProcessModule
(
f
)
{
m_config
[
"fieldstr"
]
=
ConfigOption
(
false
,
"NotSet"
,
"
string of new field to be added (required)
"
);
false
,
"NotSet"
,
"
Analytic expression
"
);
m_config
[
"fieldname"
]
=
ConfigOption
(
false
,
"newfield"
,
"name for new field, default is newfield (optional)"
);
ConfigOption
(
false
,
"newfield"
,
"name for modified new field, default is
\"
newfield
\"
(optional)"
);
}
Process
Add
FieldFromString
::~
Process
Add
FieldFromString
(
void
)
ProcessFieldFromString
::~
ProcessFieldFromString
(
void
)
{
}
void
Process
Add
FieldFromString
::
Process
(
po
::
variables_map
&
vm
)
void
ProcessFieldFromString
::
Process
(
po
::
variables_map
&
vm
)
{
// Check if required parameter fieldstr was provided
ASSERTL0
(
m_config
[
"fieldstr"
].
m_beenSet
,
"fieldstr must be specified"
);
...
...
@@ -77,7 +79,6 @@ void ProcessAddFieldFromString::Process(po::variables_map &vm)
// Set up new field name
string
fieldName
=
m_config
[
"fieldname"
].
as
<
string
>
();
m_f
->
m_variables
.
push_back
(
fieldName
);
// Skip in case of empty partition
if
(
m_f
->
m_exp
[
0
]
->
GetNumElmts
()
==
0
)
...
...
@@ -91,13 +92,29 @@ void ProcessAddFieldFromString::Process(po::variables_map &vm)
ASSERTL0
(
nstrips
==
1
,
"Routine is currently only setup for non-strip files"
);
// Create new expansion
m_f
->
m_exp
.
resize
(
nfields
+
1
);
m_f
->
m_exp
[
nfields
]
=
m_f
->
AppendExpList
(
m_f
->
m_numHomogeneousDir
);
int
fieldID
;
// check if field exists
auto
it
=
std
::
find
(
m_f
->
m_variables
.
begin
(),
m_f
->
m_variables
.
end
(),
fieldName
);
if
(
it
!=
m_f
->
m_variables
.
end
())
{
// modify existing field
fieldID
=
std
::
distance
(
m_f
->
m_variables
.
begin
(),
it
);
}
else
{
// create new field
m_f
->
m_variables
.
push_back
(
fieldName
);
// Create new expansion
m_f
->
m_exp
.
resize
(
nfields
+
1
);
fieldID
=
nfields
;
m_f
->
m_exp
[
fieldID
]
=
m_f
->
AppendExpList
(
m_f
->
m_numHomogeneousDir
);
}
// Variables for storing names and values for evaluating the function
string
varstr
;
vector
<
Array
<
OneD
,
const
NekDouble
>>
interpfields
;
vector
<
Array
<
OneD
,
const
NekDouble
>
>
interpfields
;
// Add the coordinate values
varstr
+=
"x y z"
;
...
...
@@ -124,11 +141,11 @@ void ProcessAddFieldFromString::Process(po::variables_map &vm)
exprId
=
strEval
.
DefineFunction
(
varstr
.
c_str
(),
fieldstr
);
// Evaluate function
strEval
.
Evaluate
(
exprId
,
interpfields
,
m_f
->
m_exp
[
n
field
s
]
->
UpdatePhys
());
strEval
.
Evaluate
(
exprId
,
interpfields
,
m_f
->
m_exp
[
field
ID
]
->
UpdatePhys
());
// Update coeffs
m_f
->
m_exp
[
n
field
s
]
->
FwdTrans_IterPerExp
(
m_f
->
m_exp
[
n
field
s
]
->
GetPhys
(),
m_f
->
m_exp
[
n
field
s
]
->
UpdateCoeffs
());
m_f
->
m_exp
[
field
ID
]
->
FwdTrans_IterPerExp
(
m_f
->
m_exp
[
field
ID
]
->
GetPhys
(),
m_f
->
m_exp
[
field
ID
]
->
UpdateCoeffs
());
}
}
}
library/FieldUtils/ProcessModules/Process
Add
FieldFromString.h
→
library/FieldUtils/ProcessModules/ProcessFieldFromString.h
View file @
4083fda0
///////////////////////////////////////////////////////////////////////////////
//
// File: Process
Add
FieldFromString.h
// File: ProcessFieldFromString.h
//
// For more information, please see: http://www.nektar.info/
//
...
...
@@ -33,8 +33,8 @@
//
////////////////////////////////////////////////////////////////////////////////
#ifndef FIELDUTILS_PROCESS
ADDNEW
FIELDFROMSTR
#define FIELDUTILS_PROCESS
ADDNEW
FIELDFROMSTR
#ifndef FIELDUTILS_PROCESSFIELDFROMSTR
#define FIELDUTILS_PROCESSFIELDFROMSTR
#include "../Module.h"
...
...
@@ -46,24 +46,24 @@ namespace FieldUtils
/**
* @brief This processing module adds a new field from a string definition
*/
class
Process
Add
FieldFromString
:
public
ProcessModule
class
ProcessFieldFromString
:
public
ProcessModule
{
public:
/// Creates an instance of this class
static
std
::
shared_ptr
<
Module
>
create
(
FieldSharedPtr
f
)
{
return
MemoryManager
<
Process
Add
FieldFromString
>::
AllocateSharedPtr
(
f
);
return
MemoryManager
<
ProcessFieldFromString
>::
AllocateSharedPtr
(
f
);
}
static
ModuleKey
className
;
Process
Add
FieldFromString
(
FieldSharedPtr
f
);
virtual
~
Process
Add
FieldFromString
();
ProcessFieldFromString
(
FieldSharedPtr
f
);
virtual
~
ProcessFieldFromString
();
virtual
void
Process
(
po
::
variables_map
&
vm
);
virtual
std
::
string
GetModuleName
()
{
return
"Process
Add
FieldFromString"
;
return
"ProcessFieldFromString"
;
}
virtual
std
::
string
GetModuleDescription
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment