Commit 5bd81cab authored by Mark Olesen's avatar Mark Olesen

STYLE: reorganize subdir names, adjust method catalystCoprocess method name

- was check(), now query()

- emit/suppress information output based on 'log' setting
  (as per other functionObjects)
parent f2c8e739
......@@ -43,19 +43,19 @@ set(LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN}
file(GLOB SOURCE_FILES
catalystCoprocess.C
catalystCloud.C
foamVtkCloudAdaptor.C
cloud/catalystCloud.C
cloud/foamVtkCloudAdaptor.C
catalystFaMesh.C
foamVtkFaMeshAdaptor.C
foamVtkFaMeshAdaptorGeom.C
foamVtkFaMeshAdaptorFields.C
areaMesh/catalystFaMesh.C
areaMesh/foamVtkFaMeshAdaptor.C
areaMesh/foamVtkFaMeshAdaptorGeom.C
areaMesh/foamVtkFaMeshAdaptorFields.C
catalystFvMesh.C
foamVtkFvMeshAdaptor.C
foamVtkFvMeshAdaptorGeom.C
foamVtkFvMeshAdaptorGeomVtu.C
foamVtkFvMeshAdaptorFields.C
volMesh/catalystFvMesh.C
volMesh/foamVtkFvMeshAdaptor.C
volMesh/foamVtkFvMeshAdaptorGeom.C
volMesh/foamVtkFvMeshAdaptorGeomVtu.C
volMesh/foamVtkFvMeshAdaptorFields.C
)
set(OPENFOAM_LIBRARIES
......
......@@ -175,8 +175,6 @@ bool Foam::functionObjects::catalystFaMesh::execute()
return false;
}
const catalystCoprocess::timeQuery when(time_);
// Enforce sanity for backends and adaptor
{
bool updateAdaptor = false;
......@@ -213,36 +211,42 @@ bool Foam::functionObjects::catalystFaMesh::execute()
// Data description for co-processing
vtkNew<vtkCPDataDescription> descrip;
// Form query for catalyst
catalystCoprocess::dataQuery query
// Form data query for catalyst
catalystCoprocess::dataQuery dataq
(
vtk::faMeshAdaptor::channelNames.names(),
when,
time_, // timeQuery
descrip.Get()
);
// Query catalyst
HashTable<wordHashSet> expecting = adaptor_().check(query, allFields);
const HashTable<wordHashSet> expecting(adaptor_().query(dataq, allFields));
if (expecting.empty())
if (catalystCoprocess::debug)
{
Info<< "No data expected for ParaView Catalyst. " << when << endl;
return true;
if (expecting.empty())
{
Info<< type() << ": expecting no data" << nl;
}
else
{
Info<< type() << ": expecting data " << expecting << nl;
}
}
else if (catalystCoprocess::debug)
if (expecting.empty())
{
Info<< type() << " expecting data:" << expecting << endl;
return true;
}
auto output = vtkSmartPointer<vtkMultiBlockDataSet>::New();
// TODO: currently don't rely on the results from expecting much at all
// Store each region in a separate block
// Each region in a separate block
unsigned int regionNo = 0;
for (const word& regionName : regionNames)
{
#if 1
auto pieces = backends_[regionName]->output(selectFields_);
output->SetBlock(regionNo, pieces);
......@@ -252,15 +256,14 @@ bool Foam::functionObjects::catalystFaMesh::execute()
vtkCompositeDataSet::NAME(),
regionName
);
#endif
++regionNo;
}
if (regionNo)
{
Info<< "Send data to ParaView Catalyst. " << when << endl;
Log << type() << ": send data" << nl;
adaptor_().process(query, output);
adaptor_().process(dataq, output);
}
return true;
......
......@@ -50,15 +50,23 @@ Usage
\table
Property | Description | Required | Default
type | catalyst::area | yes |
log | report extra information | no | false
region | | no | region0
regions | wordRe list of regions | no |
fields | wordRe list of fields | yes |
scripts | Python pipeline scripts | yes |
\endtable
Note
The execution frequency can be defined by the functionObject and
by the Catalyst pipeline.
See also
Foam::functionObjects::functionObject
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::timeControl
Foam::catalystCoprocess
Foam::vtk::faMeshAdaptor
SourceFiles
catalystFaMesh.C
......@@ -153,7 +161,7 @@ public:
//- Read the specification
virtual bool read(const dictionary& dict);
//- Execute pipeline
//- Execute catalyst pipelines
virtual bool execute();
//- Write - does nothing
......
......@@ -42,7 +42,7 @@ License
namespace Foam
{
defineTypeNameAndDebug(catalystCoprocess, 0);
defineTypeNameAndDebug(catalystCoprocess, 0);
}
......@@ -121,64 +121,60 @@ Foam::label Foam::catalystCoprocess::expand
template<class DataType>
bool Foam::catalystCoprocess::processImpl
(
const dataQuery& query,
HashTable<vtkSmartPointer<DataType>>& outputs
const dataQuery& dataq,
vtkSmartPointer<DataType>& output
)
{
vtkCPDataDescription* descrip = query.get();
vtkCPDataDescription* descrip = dataq.get();
if (!coproc_->RequestDataDescription(descrip))
{
return false;
}
for (const word& channel : query.channels())
for (const word& chanName : dataq.channels())
{
if (outputs.found(channel))
{
auto* input = descrip->GetInputDescriptionByName(channel.c_str());
auto* input = descrip->GetInputDescriptionByName(chanName.c_str());
if (input && input->GetIfGridIsNecessary())
{
input->SetGrid(outputs[channel]);
}
if (input && input->GetIfGridIsNecessary())
{
input->SetGrid(output);
}
}
coproc_->CoProcess(descrip);
return true;
}
template<class DataType>
bool Foam::catalystCoprocess::process1Impl
bool Foam::catalystCoprocess::processImpl
(
const dataQuery& query,
vtkSmartPointer<DataType>& output
const dataQuery& dataq,
HashTable<vtkSmartPointer<DataType>>& outputs
)
{
vtkCPDataDescription* descrip = query.get();
vtkCPDataDescription* descrip = dataq.get();
if (!coproc_->RequestDataDescription(descrip))
{
return false;
}
for (const word& channel : query.channels())
for (const word& chanName : dataq.channels())
{
auto* input = descrip->GetInputDescriptionByName(channel.c_str());
if (input && input->GetIfGridIsNecessary())
if (outputs.found(chanName))
{
input->SetGrid(output);
}
auto* input = descrip->GetInputDescriptionByName(chanName.c_str());
break;
if (input && input->GetIfGridIsNecessary())
{
input->SetGrid(outputs[chanName]);
}
}
}
coproc_->CoProcess(descrip);
return true;
}
......@@ -256,14 +252,14 @@ void Foam::catalystCoprocess::reset(const UList<string>& scripts)
coproc_->AddPipeline(pipeline.GetPointer());
}
// Do something different with (!nscript) ??
// Do something different with (nscript == 0) ?
}
Foam::HashTable<Foam::wordHashSet>
Foam::catalystCoprocess::check
Foam::catalystCoprocess::query
(
dataQuery& query,
dataQuery& dataq,
const wordHashSet& allFields
)
{
......@@ -276,37 +272,33 @@ Foam::catalystCoprocess::check
return requests;
}
if (query.channels().empty())
if (dataq.channels().empty())
{
// No channels names have been published by the simulation
return requests;
}
vtkCPDataDescription* descrip = query.get();
vtkCPDataDescription* descrip = dataq.get();
descrip->SetTimeData(query.timeValue, query.timeIndex);
descrip->SetForceOutput(query.forced);
descrip->SetTimeData(dataq.timeValue, dataq.timeIndex);
descrip->SetForceOutput(dataq.forced);
// Sort out which channels already exist, are new, or disappeared
{
// The currently defined channels
wordHashSet currentChannels;
wordHashSet currChannels;
const unsigned n = descrip->GetNumberOfInputDescriptions();
for (unsigned i=0; i < n; ++i)
{
currentChannels.insert
currChannels.insert
(
word
(
descrip->GetInputDescriptionName(i),
false // no stripping (ie, accept bad names too)
)
word::validate(descrip->GetInputDescriptionName(i))
);
}
wordHashSet newChannels(query.channels());
wordHashSet oldChannels(currentChannels);
wordHashSet newChannels(dataq.channels());
wordHashSet oldChannels(currChannels);
oldChannels.erase(newChannels);
if (oldChannels.size())
......@@ -315,14 +307,14 @@ Foam::catalystCoprocess::check
}
else
{
newChannels.erase(currentChannels);
newChannels.erase(currChannels);
}
// Add channels
for (const word& channel : newChannels)
for (const word& chanName : newChannels)
{
descrip->AddInput(channel.c_str());
auto* input = descrip->GetInputDescriptionByName(channel.c_str());
descrip->AddInput(chanName.c_str());
auto* input = descrip->GetInputDescriptionByName(chanName.c_str());
for (const word& fieldName : allFields)
{
......@@ -344,13 +336,13 @@ Foam::catalystCoprocess::check
return requests;
}
for (const word& channel : query.channels())
for (const word& chanName : dataq.channels())
{
auto* input = descrip->GetInputDescriptionByName(channel.c_str());
auto* input = descrip->GetInputDescriptionByName(chanName.c_str());
if (input && input->GetIfGridIsNecessary())
{
wordHashSet& fields = requests(channel);
wordHashSet& fields = requests(chanName); // auto-vivify
for (const word& fieldName : allFields)
{
......@@ -368,21 +360,21 @@ Foam::catalystCoprocess::check
bool Foam::catalystCoprocess::process
(
const dataQuery& query,
const dataQuery& dataq,
vtkSmartPointer<vtkMultiBlockDataSet>& output
)
{
return process1Impl(query, output);
return processImpl(dataq, output);
}
bool Foam::catalystCoprocess::process
(
const dataQuery& query,
const dataQuery& dataq,
HashTable<vtkSmartPointer<vtkMultiBlockDataSet>>& outputs
)
{
return processImpl(query, outputs);
return processImpl(dataq, outputs);
}
......
......@@ -28,24 +28,18 @@ Description
Low-level interface between OpenFOAM and ParaView Catalyst.
\code
... initialize catalyst
... initialize catalyst
... define a data query for catalyst
... define a data query for catalyst
// Data description for co-processing
vtkNew<vtkCPDataDescription> descrip;
// Data description for co-processing
vtkNew<vtkCPDataDescription> descrip;
// Form query for catalyst
catalystCoprocess::dataQuery query
(
vtkPVFoam::channelNames.names(),
when,
descrip.Get()
);
// Form data query for catalyst
catalystCoprocess::dataQuery dataq(channelNames, runTime, descrip.Get());
// Query catalyst
HashTable<wordHashSet> expecting = adaptor_().check(query, allFields);
HashTable<wordHashSet> expecting = adaptor_().query(dataq, fields);
\endcode
......@@ -116,9 +110,8 @@ public:
:
public timeQuery
{
//- Catalyst channels to query
//- Catalyst channel names to query
List<word> channels_;
mutable vtkCPDataDescription* descrip_;
public:
......@@ -169,18 +162,20 @@ private:
// Private Member Functions
//- Process single output channel
template<class DataType>
bool processImpl
(
const dataQuery& query,
HashTable<vtkSmartPointer<DataType>>& outputs
vtkSmartPointer<DataType>& outputs
);
//- Process multiple output channels
template<class DataType>
bool process1Impl
bool processImpl
(
const dataQuery& query,
vtkSmartPointer<DataType>& outputs
HashTable<vtkSmartPointer<DataType>>& outputs
);
public:
......@@ -223,36 +218,34 @@ public:
//- Query the coprocess pipelines if they should be executed at this
//- iteration and possibly which fields they require.
//
// \param[in,out] query for catalyst.
// \param[in,out] dataq the data query for catalyst.
// On input it contains the published channel names, the current
// simulation time (index, value) and allocation for the coprocess
// data description.
// On output the data description willbe filled with the field names
// contains the published channel names, the current
// On output the data description will be filled with the field
// names added per channel.
// \param[in] allFields the fields that can be published from the
// simulation.
//
// \return HashTable with fields requested (what Catalyst expects)
// on a per-channel basis.
HashTable<wordHashSet> check
HashTable<wordHashSet> query
(
dataQuery& query,
dataQuery& dataq,
const wordHashSet& allFields
);
//- Single-channel source (eg, "input" or "cloud", ...)
// Uses the currentTime values
bool process
(
const dataQuery& query,
const dataQuery& dataq,
vtkSmartPointer<vtkMultiBlockDataSet>& output
);
//- Multi-channel source (eg, "input", "mesh", "patches")
// Uses the currentTime values
bool process
(
const dataQuery& query,
const dataQuery& dataq,
HashTable<vtkSmartPointer<vtkMultiBlockDataSet>>& outputs
);
......
......@@ -123,8 +123,6 @@ bool Foam::functionObjects::catalystCloud::execute()
return true;
}
const catalystCoprocess::timeQuery when(time_);
// Enforce sanity for backends and adaptor
{
if (!adaptor_.valid())
......@@ -143,30 +141,37 @@ bool Foam::functionObjects::catalystCloud::execute()
// Data description for co-processing
vtkNew<vtkCPDataDescription> descrip;
// Form query for catalyst
catalystCoprocess::dataQuery query
// Form data query for catalyst
catalystCoprocess::dataQuery dataq
(
vtk::cloudAdaptor::channelNames.names(),
when,
time_, // timeQuery
descrip.Get()
);
// Query catalyst
HashTable<wordHashSet> expecting = adaptor_().check(query, allFields);
const HashTable<wordHashSet> expecting(adaptor_().query(dataq, allFields));
if (expecting.empty())
if (catalystCoprocess::debug)
{
Info<< "No data expected for ParaView Catalyst. " << when << endl;
return true;
if (expecting.empty())
{
Info<< type() << ": expecting no data" << nl;
}
else
{
Info<< type() << ": expecting data " << expecting << nl;
}
}
else if (catalystCoprocess::debug)
if (expecting.empty())
{
Info<< type() << " expecting data:" << expecting << endl;
return true;
}
auto output = vtkSmartPointer<vtkMultiBlockDataSet>::New();
// Store each cloud in a separate block
// Each cloud in a separate block.
unsigned int cloudNo = 0;
for (const word& cloudName : cloudNames)
{
......@@ -185,9 +190,9 @@ bool Foam::functionObjects::catalystCloud::execute()
if (cloudNo)
{
Info<< "Send data to ParaView Catalyst. " << when << endl;
Log << type() << ": send data" << nl;
adaptor_().process(query, output);
adaptor_().process(dataq, output);
}
return true;
......
......@@ -51,6 +51,7 @@ Usage
\table
Property | Description | Required | Default value
type | catalyst::cloud | yes |
log | report extra information | no | false
cloud | | no | defaultCloud
clouds | wordRe list of clouds | no |
region | | no | region0
......@@ -59,9 +60,16 @@ Usage
scripts | Python pipeline scripts | yes |
\endtable
Note
The execution frequency can be defined by the functionObject and
by the Catalyst pipeline.
See also
Foam::functionObjects::functionObject
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::timeControl
Foam::catalystCoprocess
Foam::vtk::cloudAdaptor
SourceFiles
catalystCloud.C
......@@ -146,7 +154,7 @@ public:
//- Read the specification
virtual bool read(const dictionary& dict);
//- Execute pipeline
//- Execute catalyst pipelines
virtual bool execute();
//- Write - does nothing
......
......@@ -160,8 +160,6 @@ bool Foam::functionObjects::catalystFvMesh::execute()
return false;
}
const catalystCoprocess::timeQuery when(time_);
// Enforce sanity for backends and adaptor
{
bool updateAdaptor = false;
......@@ -198,40 +196,47 @@ bool Foam::functionObjects::catalystFvMesh::execute()
// Data description for co-processing
vtkNew<vtkCPDataDescription> descrip;
// Form query for catalyst
catalystCoprocess::dataQuery query
// Form data query for catalyst
catalystCoprocess::dataQuery dataq
(
vtk::fvMeshAdaptor::channelNames.names(),
when,
time_, // timeQuery
descrip.Get()
);
// Query catalyst
HashTable<wordHashSet> expecting = adaptor_().check(query, allFields);
const HashTable<wordHashSet> expecting(adaptor_().query(dataq, allFields));
if (expecting.empty())
if (catalystCoprocess::debug)
{
Info<< "No data expected for ParaView Catalyst. " << when << endl;
return true;
if (expecting.empty())
{
Info<< type() << ": expecting no data" << nl;
}
else
{
Info<< type() << ": expecting data " << expecting << nl;
}
}
else if (catalystCoprocess::debug)
if (expecting.empty())
{
Info<< type() << " expecting data:" << expecting << endl;
return true;
}
HashTable<vtkSmartPointer<vtkMultiBlockDataSet>> outputs;