86 GetPropType<TypeTag, Properties::EquilGrid>,
87 GetPropType<TypeTag, Properties::GridView>,
88 GetPropType<TypeTag, Properties::ElementMapper>,
89 GetPropType<TypeTag, Properties::Scalar>>
97 using Element =
typename GridView::template Codim<0>::Entity;
106 static void registerParameters()
115 :
BaseType(simulator.vanguard().schedule(),
116 simulator.vanguard().eclState(),
117 simulator.vanguard().summaryConfig(),
118 simulator.vanguard().grid(),
119 ((simulator.vanguard().grid().comm().rank() == 0)
120 ? &simulator.vanguard().equilGrid()
122 simulator.vanguard().gridView(),
123 simulator.vanguard().cartesianIndexMapper(),
124 ((simulator.vanguard().grid().comm().rank() == 0)
125 ? &simulator.vanguard().equilCartesianIndexMapper()
128 , simulator_(simulator)
130 this->damarisUpdate_ =
true ;
132 this->rank_ = this->simulator_.vanguard().grid().comm().rank() ;
133 this->nranks_ = this->simulator_.vanguard().grid().comm().size();
135 this->elements_rank_offsets_.resize(this->nranks_);
145 const auto& gridView = this->simulator_.gridView();
151 if (this->nranks_ > 1) {
152 auto smryCfg = (this->rank_ == 0)
153 ? this->eclIO_->finalSummaryConfig()
156 eclBroadcast(this->simulator_.vanguard().grid().comm(),
smryCfg);
158 this->damarisOutputModule_ = std::make_unique<OutputBlackOilModule<TypeTag>>
159 (simulator,
smryCfg, this->collectOnIORank_);
162 this->damarisOutputModule_ = std::make_unique<OutputBlackOilModule<TypeTag>>
163 (simulator, this->eclIO_->finalSummaryConfig(), this->collectOnIORank_);
166 wanted_vars_set_ = DamarisOutput::getSetOfIncludedVariables();
175 const int reportStepNum = simulator_.episodeIndex() + 1;
176 const auto&
cc = simulator_.vanguard().grid().comm();
180 this->damarisOutputModule_->invalidateLocalData() ;
181 this->prepareLocalCellData(
isSubStep, reportStepNum);
182 this->damarisOutputModule_->outputErrorLog(
cc);
185 auto localWellData = simulator_.problem().wellModel().wellData();
194 this->damarisOutputModule_->addRftDataToWells(
localWellData, reportStepNum,
cc);
197 if (damarisUpdate_ ==
true) {
202 dam_err_ = DamarisOutput::setupWritingPars(
cc, numElements_, elements_rank_offsets_);
205 this->setGlobalIndexForDamaris() ;
209 this->writeDamarisGridOutput() ;
213 this->damarisUpdate_ =
false;
222 const std::string& name =
damVar.first ;
225 if (wanted_vars_set_.count(name) || wanted_vars_set_.empty())
228 OpmLog::debug(fmt::format(
"Name of Damaris Variable : ( rank:{}) name: {} ", rank_, name));
233 dam_err_ = DamarisOutput::setPosition(name.c_str(),
this->elements_rank_offsets_[rank_]);
238 if (
dataCol.data<
double>().size() >=
static_cast<std::vector<double>::size_type
>(
this->numElements_)) {
239 dam_err_ = DamarisOutput::write(name.c_str(),
dataCol.data<
double>().data()) ;
241 OpmLog::info(fmt::format(
"( rank:{}) The variable \"{}\" was found to be of a different size {} (not {}).", rank_, name,
dataCol.data<
double>().size(),
this->numElements_ ));
244 catch (std::bad_variant_access
const&
ex) {
246 if (
dataCol.data<
int>().size() >=
static_cast<std::vector<int>::size_type
>(
this->numElements_)) {
247 dam_err_ = DamarisOutput::write(name.c_str(),
dataCol.data<
int>().data()) ;
249 OpmLog::info(fmt::format(
"( rank:{}) The variable \"{}\" was found to be of a different size {} (not {}).", rank_, name,
dataCol.data<
int>().size(),
this->numElements_ ));
255 DamarisOutput::handleError(dam_err_,
cc,
"setPosition() and write() for available variables");
258 OpmLog::info(fmt::format(
"( rank:{}) No simulation data written to the Damaris server - check --damaris-limit-variables command line option (if used) has valid variable name(s) and that the Damaris XML file contains variable names that are available in your simulation.", rank_));
260 OpmLog::debug(fmt::format(
"( rank:{}) {} Damaris Variables written to the Damaris servers", rank_,
cell_data_written));
276 if (!this->damarisOutputModule_->getFluidPressure().empty())
278 dam_err_ = DamarisOutput::endIteration();
280 DamarisOutput::handleError(dam_err_,
cc,
"endIteration()");
290 std::unordered_set<std::string> wanted_vars_set_ ;
293 std::unique_ptr<OutputBlackOilModule<TypeTag>> damarisOutputModule_;
294 std::vector<unsigned long long> elements_rank_offsets_ ;
295 bool damarisUpdate_ =
false;
297 static bool enableDamarisOutput_()
299 static bool enable = Parameters::Get<Parameters::EnableDamarisOutput>();
303 void setGlobalIndexForDamaris ()
305 const auto&
cc = simulator_.
vanguard().grid().comm();
309 dam_err_ = DamarisOutput::setPosition(
"GLOBAL_CELL_INDEX", elements_rank_offsets_[rank_]);
310 DamarisOutput::handleError(dam_err_,
cc,
"setPosition() for GLOBAL_CELL_INDEX");
316 DamarisVarInt
mpi_rank_var(1, {
"n_elements_local"},
"MPI_RANK", rank_);
321 if (this->collectOnIORank_.isParallel()) {
322 const std::vector<int>& local_to_global =
323 this->collectOnIORank_.localIdxToGlobalIdxMapping();
324 dam_err_ = DamarisOutput::write(
"GLOBAL_CELL_INDEX", local_to_global.data());
331 DamarisOutput::handleError(dam_err_,
cc,
"write() for GLOBAL_CELL_INDEX");
333 mpi_rank_var.setDamarisParameterAndShmem( {this->numElements_ } ) ;
339 const auto& outputDir = simulator_.
vanguard().eclState().cfg().io().getOutputDir();
340 if (outputDir.size() > 0) {
341 dam_err_ = DamarisOutput::setParameter(
"path_string_length", outputDir.size()) ;
342 DamarisOutput::handleError(dam_err_,
cc,
"setParameter() for path_string_length");
343 dam_err_ = DamarisOutput::write(
"OUTPUTDIR", outputDir.c_str());
344 DamarisOutput::handleError(dam_err_,
cc,
"write() for OUTPUTDIR");
348 void writeDamarisGridOutput()
350 const auto& gridView = simulator_.
gridView();
351 GridDataOutput::SimMeshDataAccessor
geomData(gridView, Dune::Partitions::interior) ;
356 OpmLog::error(fmt::format(
"ERORR: rank {} The DUNE geometry grid has polyhedral elements - These elements are currently not supported.", rank_ ));
370 DamarisVarDbl
var_x(1, {
"n_coords_local"},
"coordset/coords/values/x", rank_) ;
374 var_x.setDamarisParameterAndShmem( {
geomData.getNVertices() } ) ;
376 DamarisVarDbl
var_y(1, {
"n_coords_local"},
"coordset/coords/values/y", rank_) ;
377 var_y.setDamarisParameterAndShmem( {
geomData.getNVertices() } ) ;
379 DamarisVarDbl
var_z(1, {
"n_coords_local"},
"coordset/coords/values/z", rank_) ;
380 var_z.setDamarisParameterAndShmem( {
geomData.getNVertices() } ) ;
400 "topologies/topo/elements/connectivity", rank_) ;
402 DamarisVarInt
var_offsets(1, {
"n_offsets_types_ph"},
403 "topologies/topo/elements/offsets", rank_) ;
405 DamarisVarChar
var_types(1, {
"n_offsets_types_ph"},
406 "topologies/topo/elements/types", rank_) ;
411 GridDataOutput::ConnectivityVertexOrder
vtkorder = GridDataOutput::VTK ;
425 catch (std::exception&
e)
427 OpmLog::error(
e.what());
431 void prepareLocalCellData(
const bool isSubStep,
432 const int reportStepNum)
435 if (damarisOutputModule_->localDataValid()) {
439 const auto& gridView = simulator_.
vanguard().gridView();
441 countLocalInteriorCellsGridView(gridView);
442 const bool log = this->collectOnIORank_.isIORank();
444 damarisOutputModule_->allocBuffers(
num_interior, reportStepNum,
447 ElementContext elemCtx(simulator_);
448 OPM_BEGIN_PARALLEL_TRY_CATCH();
451 damarisOutputModule_->setupExtractors(
isSubStep, reportStepNum);
453 elemCtx.updatePrimaryStencil(
elem);
454 elemCtx.updatePrimaryIntensiveQuantities(0);
456 damarisOutputModule_->processElement(elemCtx);
458 damarisOutputModule_->clearExtractors();
463 elemCtx.updatePrimaryStencil(
elem);
464 elemCtx.updatePrimaryIntensiveQuantities(0);
465 damarisOutputModule_->processElementBlockData(elemCtx);
471#pragma omp parallel for
474 const auto& intQuants = *(simulator_.
model().cachedIntensiveQuantities(dofIdx, 0));
476 damarisOutputModule_->updateFluidInPlace(dofIdx, intQuants,
totVolume);
479 damarisOutputModule_->validateLocalData();
480 OPM_END_PARALLEL_TRY_CATCH(
"DamarisWriter::prepareLocalCellData() failed: ", simulator_.
vanguard().grid().comm());