Skip to content

Commit

Permalink
[insitu] WIP implementation of insitu vis.
Browse files Browse the repository at this point in the history
  • Loading branch information
bilke committed Mar 23, 2017
1 parent d43b5d7 commit dbf808f
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Applications/CLI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ if(OGS_USE_PETSC)
target_link_libraries(ogs ${PETSC_LIBRARIES})
endif()

if(OGS_INSITU)
target_link_libraries(ogs InSituLib)
endif()

####################
### Tests ##########
####################
Expand Down
22 changes: 17 additions & 5 deletions Applications/CLI/ogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Applications/ApplicationsLib/LinearSolverLibrarySetup.h"
#include "Applications/ApplicationsLib/LogogSetup.h"
#include "Applications/ApplicationsLib/ProjectData.h"
#include "Applications/InSituLib/Adaptor.h"
#include "ProcessLib/UncoupledProcessesTimeLoop.h"

#include "NumLib/NumericsConfig.h"
Expand Down Expand Up @@ -117,24 +118,35 @@ int main(int argc, char *argv[])
BaseLib::extractPath(project_arg.getValue()),
outdir_arg.getValue());

// Check intermediately that config parsing went fine.
project_config.checkAndInvalidate();
BaseLib::ConfigTree::assertNoSwallowedErrors();

BaseLib::ConfigTree::assertNoSwallowedErrors();
#ifdef USE_INSITU
INFO("Initialize insitu scripts.");
if (auto t = project_config->getConfigSubtreeOptional("insitu"))
InSituLib::Initialize(t->getConfigSubtree("scripts"), BaseLib::extractPath(project_arg.getValue()));
#endif

INFO("Initialize processes.");
for (auto& p : project.getProcesses())
{
p.second->initialize();
}

// Check intermediately that config parsing went fine.
project_config.checkAndInvalidate();
BaseLib::ConfigTree::assertNoSwallowedErrors();

BaseLib::ConfigTree::assertNoSwallowedErrors();

BaseLib::ConfigTree::assertNoSwallowedErrors();

INFO("Solve processes.");

auto& time_loop = project.getTimeLoop();
solver_succeeded = time_loop.loop();

#ifdef USE_INSITU
if (project_config->getConfigSubtreeOptional("insitu"))
InSituLib::Finalize();
#endif
} // This nested scope ensures that everything that could possibly
// possess a ConfigTree is destructed before the final check below is
// done.
Expand Down
4 changes: 4 additions & 0 deletions Applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ endif() # OGS_BUILD_GUI
if(OGS_BUILD_CLI)
add_subdirectory(CLI)
endif() # OGS_BUILD_CLI

if(OGS_INSITU)
add_subdirectory(InSituLib)
endif()
77 changes: 77 additions & 0 deletions Applications/InSituLib/Adaptor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* \copyright
* Copyright (c) 2012-2017, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/

#include "Adaptor.h"

#include <vtkCPDataDescription.h>
#include <vtkCPInputDataDescription.h>
#include <vtkCPProcessor.h>
#include <vtkCPPythonScriptPipeline.h>
#include <vtkNew.h>
#include <vtkUnstructuredGrid.h>

#include "MeshLib/Mesh.h"
#include "MeshLib/Vtk/VtkMappedMeshSource.h"

namespace InSituLib
{
vtkCPProcessor* Processor = NULL;

void Initialize(BaseLib::ConfigTree const & scripts_config, std::string const & path)
{
if (Processor == NULL)
{
Processor = vtkCPProcessor::New();
Processor->Initialize();
}
else
{
Processor->RemoveAllPipelines();
}
for (auto script_config : scripts_config.getConfigSubtreeList("script"))
{
std::stringstream ss;
ss << path << script_config.getConfigParameter<std::string>("name");
vtkNew<vtkCPPythonScriptPipeline> pipeline;
pipeline->Initialize(ss.str().c_str());
Processor->AddPipeline(pipeline.GetPointer());
}
}
void Finalize()
{
if (Processor)
{
Processor->Delete();
Processor = NULL;
}
}
void CoProcess(MeshLib::Mesh const& mesh, double const time,
unsigned int const timeStep, bool const lastTimeStep)
{
vtkNew<vtkCPDataDescription> dataDescription;
dataDescription->AddInput("input");
dataDescription->SetTimeData(time, timeStep);
if (lastTimeStep == true)
{
// assume that we want to all the pipelines to execute if it
// is the last time step.
dataDescription->ForceOutputOn();
}
if (Processor->RequestDataDescription(dataDescription.GetPointer()) != 0)
{
INFO("Start InSitu process.");
vtkNew<MeshLib::VtkMappedMeshSource> vtkSource;
vtkSource->SetMesh(&mesh);
vtkSource->Update();
dataDescription->GetInputDescriptionByName("input")->SetGrid(vtkSource->GetOutput());
Processor->CoProcess(dataDescription.GetPointer());
INFO("End InSitu process.");
}
}
} // namespace
24 changes: 24 additions & 0 deletions Applications/InSituLib/Adaptor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* \copyright
* Copyright (c) 2012-2017, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/

#pragma once

#include "BaseLib/ConfigTree.h"

namespace MeshLib {
class Mesh;
}

namespace InSituLib {

void Initialize(BaseLib::ConfigTree const & scripts_config, std::string const & path);
void Finalize();
void CoProcess( MeshLib::Mesh const & mesh, double const time, unsigned int const timeStep, bool const lastTimeStep);

}
7 changes: 7 additions & 0 deletions Applications/InSituLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Source files
GET_SOURCE_FILES(SOURCES)

# Library
add_library(InSituLib ${SOURCES})

# target_link_libraries(InSituLib )
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ include(VtkModules)
if(OGS_INSITU)
include(ExternalProjectCatalyst)
include("${PARAVIEW_USE_FILE}")
add_definitions(-DUSE_INSITU)
else()
include(ExternalProjectVtk)
endif()
Expand Down
3 changes: 3 additions & 0 deletions ProcessLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ endif()
if(TARGET Boost)
add_dependencies(ProcessLib Boost)
endif()
if(OGS_INSITU)
target_link_libraries(ProcessLib InSituLib)
endif()
6 changes: 6 additions & 0 deletions ProcessLib/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "BaseLib/FileTools.h"
#include "BaseLib/RunTime.h"
#include "Applications/InSituLib/Adaptor.h"

namespace
{
Expand Down Expand Up @@ -124,6 +125,11 @@ void Output::doOutputAlways(Process const& process,

INFO("[time] Output of timestep %d took %g s.", timestep,
time_output.elapsed());

#ifdef USE_INSITU
// TODO: get number of timesteps
InSituLib::CoProcess(process.getMesh(), t, timestep, false);
#endif
}

void Output::doOutput(Process const& process,
Expand Down

0 comments on commit dbf808f

Please sign in to comment.