Commit 5621f904 authored by Dave Moxey's avatar Dave Moxey
Browse files

Merge branch 'feature/FCHomogeneousStretch' into 'master'

Create HomogeneousStretch module for FieldConvert

This MR introduces a new module to FieldConvert, which extends the span of a 3DH1D field (only for integer factors). For example, we might want to double the span and obtain the correct duplicated periodic solution. 

This is achieved by moving coefficients between planes so that they are at the correct wave number in the extended domain.

See merge request !609
parents 7036708b f4359695
......@@ -9,6 +9,9 @@ v4.4.0
**NekMesh:**
- Modify curve module to allow for spline input (!628)
**FieldConvert:**
- Add module to stretch homogeneous direction (!609)
v4.3.3
------
**Library**:
......
......@@ -102,6 +102,7 @@ possibly also Reynolds stresses) into single file;
\item \inltt{equispacedoutput}: Write data as equi-spaced output using simplices to represent the data for connecting points;
\item \inltt{extract}: Extract a boundary field;
\item \inltt{homplane}: Extract a plane from 3DH1D expansions;
\item \inltt{homstretch}: Stretch a 3DH1D expansion by an integer factor;
\item \inltt{innerproduct}: take the inner product between one or a series of fields with another field (or series of fields).
\item \inltt{interpfield}: Interpolates one field to another, requires fromxml, fromfld to be defined;
\item \inltt{interppointdatatofld}: Interpolates given discrete data using a finite difference approximation to a fld file given an xml file;
......@@ -327,6 +328,21 @@ The output file \inltt{file-plane.fld} can be processed in a similar
way as described in section \ref{s:utilities:fieldconvert:sub:convert}
to visualise it either in Tecplot or in Paraview.
\subsection{Stretch a 3DH1D expansion: \textit{homstretch} module}
To stretch a 3DH1D expansion in the z-direction, use the command:
\begin{lstlisting}[style=BashInputStyle]
FieldConvert -m homstretch:factor=value file.xml file.fld file-stretch.fld
\end{lstlisting}
The number of modes in the resulting field can be chosen using the command-line
parameter \inltt{output-points-hom-z}. Note that the output for
this module should always be a \inltt{.fld} file and this should not
be used in combination with other modules using a single command.
The output file \inltt{file-stretch.fld} can be processed in a similar
way as described in section \ref{s:utilities:fieldconvert:sub:convert}
to visualise it either in Tecplot or in Paraview.
\subsection{Inner Product of a single or series of fields with respect to a single or series of fields: \textit{innerproduct} module}
You can take the inner product of one field with another field using
......
......@@ -21,6 +21,7 @@ SET(FieldConvertHeaders
ProcessModules/ProcessEquiSpacedOutput.h
ProcessModules/ProcessGrad.h
ProcessModules/ProcessHomogeneousPlane.h
ProcessModules/ProcessHomogeneousStretch.h
ProcessModules/ProcessInnerProduct.h
ProcessModules/ProcessInterpField.h
ProcessModules/ProcessInterpPoints.h
......@@ -66,6 +67,7 @@ SET(FieldConvertSources
ProcessModules/ProcessEquiSpacedOutput.cpp
ProcessModules/ProcessGrad.cpp
ProcessModules/ProcessHomogeneousPlane.cpp
ProcessModules/ProcessHomogeneousStretch.cpp
ProcessModules/ProcessInnerProduct.cpp
ProcessModules/ProcessInterpField.cpp
ProcessModules/ProcessInterpPoints.cpp
......@@ -108,6 +110,7 @@ ADD_NEKTAR_TEST(pointdatatofld)
# ADD_NEKTAR_TEST(chan3D_pts)
ADD_NEKTAR_TEST(chan3DH1D_meanmode)
ADD_NEKTAR_TEST(chan3DH1D_plane)
ADD_NEKTAR_TEST(chan3DH1D_stretch)
ADD_NEKTAR_TEST(chan3D_probe)
ADD_NEKTAR_TEST(cube_prismhex)
ADD_NEKTAR_TEST(outflow_pointdatatofld)
......
////////////////////////////////////////////////////////////////////////////////
//
// File: ProcessHomogeneousStretch.cpp
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Stretch homogeneous direction by an integer factor.
//
////////////////////////////////////////////////////////////////////////////////
#include <string>
#include <iostream>
using namespace std;
#include "ProcessHomogeneousStretch.h"
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/BasicUtils/ParseUtils.hpp>
namespace Nektar
{
namespace Utilities
{
ModuleKey ProcessHomogeneousStretch::className =
GetModuleFactory().RegisterCreatorFunction(
ModuleKey(eProcessModule, "homstretch"),
ProcessHomogeneousStretch::create,
"Stretches homogeneous direction of a 3DH1D expansion, requires factor to be "
"defined. The number of modes in the final expansion can be defined using"
" --output-points-hom-z.");
ProcessHomogeneousStretch::ProcessHomogeneousStretch(FieldSharedPtr f)
: ProcessModule(f)
{
m_config["factor"] = ConfigOption(false, "NotSet", "stretch factor");
}
ProcessHomogeneousStretch::~ProcessHomogeneousStretch()
{
}
void ProcessHomogeneousStretch::Process(po::variables_map &vm)
{
if (m_f->m_verbose)
{
if(m_f->m_comm->GetRank() == 0)
{
cout << "ProcessHomogeneousStretch: Stretching expansion..."
<< endl;
}
}
if ((m_f->m_fielddef[0]->m_numHomogeneousDir) != 1)
{
ASSERTL0(false,
"ProcessHomogeneousStretch only works for Homogeneous1D.");
}
ASSERTL0(m_config["factor"].m_beenSet,
"Missing parameter factor for ProcessHomogeneousStretch");
int factor = m_config["factor"].as<int>();
int nfields = m_f->m_fielddef[0]->m_fields.size();
int nplanes = m_f->m_exp[0]->GetHomogeneousBasis()->
GetZ().num_elements();
ASSERTL0(factor > 1,
"Parameter factor must be greater than 1.");
int nstrips;
m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
for (int s = 0; s < nstrips; ++s)
{
for (int i = 0; i < nfields; ++i)
{
int n = s * nfields + i;
int ncoeffs = m_f->m_exp[n]->GetPlane(0)->GetNcoeffs();
// Loop planes backwards so we can copy in place
for (int p = nplanes-1; p > 1; --p)
{
int newP = 2 * factor * (p/2) + p%2;
if (newP < nplanes)
{
Vmath::Vcopy(ncoeffs,
m_f->m_exp[n]->GetPlane(p)->GetCoeffs(), 1,
m_f->m_exp[n]->GetPlane(newP)->UpdateCoeffs(), 1);
}
Vmath::Zero(ncoeffs,
m_f->m_exp[n]->GetPlane(p)->UpdateCoeffs(), 1);
}
m_f->m_exp[n]->BwdTrans(m_f->m_exp[n]->GetCoeffs(),
m_f->m_exp[n]->UpdatePhys());
}
}
std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
m_f->m_exp[0]->GetFieldDefinitions();
std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
for (int s = 0; s < nstrips; ++s)
{
for (int j = 0; j < nfields; ++j)
{
for (int i = 0; i < FieldDef.size() / nstrips; ++i)
{
int n = s * FieldDef.size() / nstrips + i;
FieldDef[n]->m_fields.push_back(
m_f->m_fielddef[0]->m_fields[j]);
m_f->m_exp[s * nfields + j]->AppendFieldData(FieldDef[n],
FieldData[n]);
}
}
}
for (int i = 0; i < FieldDef.size(); ++i)
{
FieldDef[i]->m_homogeneousLengths[0] = factor *
m_f->m_fielddef[i]->m_homogeneousLengths[0];
}
m_f->m_fielddef = FieldDef;
m_f->m_data = FieldData;
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
// File: ProcessHomogeneousStretch.h
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Stretch homogeneous direction by an integer factor.
//
////////////////////////////////////////////////////////////////////////////////
#ifndef UTILITIES_PREPROCESSING_FIELDCONVERT_PROCESSHOMOGENEOUSSTRETCH
#define UTILITIES_PREPROCESSING_FIELDCONVERT_PROCESSHOMOGENEOUSSTRETCH
#include "../Module.h"
namespace Nektar
{
namespace Utilities
{
/**
* @brief This processing module stretches the homogeneous direction of a
* 3DH1D expansion by an integer factor.
*/
class ProcessHomogeneousStretch : public ProcessModule
{
public:
/// Creates an instance of this class
static boost::shared_ptr<Module> create(FieldSharedPtr f)
{
return MemoryManager<ProcessHomogeneousStretch>::AllocateSharedPtr(f);
}
static ModuleKey className;
ProcessHomogeneousStretch(FieldSharedPtr f);
virtual ~ProcessHomogeneousStretch();
/// Write mesh to output file.
virtual void Process(po::variables_map &vm);
virtual std::string GetModuleName()
{
return "ProcessHomogeneousStretch";
}
};
}
}
#endif
<?xml version="1.0" encoding="utf-8"?>
<test>
<description> Process 3DH1D stretch output </description>
<executable>FieldConvert</executable>
<parameters> --output-points-hom-z 16 -m homstretch:factor=2 -e chan3DH1D.xml chan3DH1D.fld chan3DH1D_stretch.fld</parameters>
<files>
<file description="Session File">chan3DH1D.xml</file>
<file description="Session File">chan3DH1D.fld</file>
</files>
<metrics>
<metric type="L2" id="1">
<value variable="u" tolerance="1e-6">0.129099</value>
<value variable="v" tolerance="1e-6">0</value>
<value variable="w" tolerance="1e-6">0</value>
<value variable="p" tolerance="1e-6">0.816497</value>
</metric>
</metrics>
</test>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment