89 void create(
const std::string& gstatControlFile,
90 const std::string& gstatInputFile =
"gstatInput.txt",
91 const std::string& gstatOutputFile =
"permeab.dat",
93 bool createNew =
true)
95 fieldType_ = fieldType;
99 DUNE_THROW(Dune::InvalidStateException,
"Requested data field generation with gstat"
100 <<
" but gstat was not found on your system. Set GSTAT_ROOT to the path where gstat "
101 <<
" is installed and pass it to CMake, e.g. through an opts file.");
103 std::ofstream gstatInput(gstatInputFile);
104 for (
const auto& element : elements(gridView_))
106 gstatInput << element.geometry().center() << std::endl;
111 syscom = GSTAT_EXECUTABLE;
113 syscom += gstatControlFile;
115 if (!gstatInput.good())
117 DUNE_THROW(Dune::IOError,
"Reading the gstat control file: "
118 << gstatControlFile <<
" failed." << std::endl);
121 if (system(syscom.c_str()))
123 DUNE_THROW(Dune::IOError,
"Executing gstat failed.");
128 std::ifstream gstatOutput(gstatOutputFile);
129 if (!gstatOutput.good())
131 DUNE_THROW(Dune::IOError,
"Reading from file: "
132 << gstatOutputFile <<
" failed." << std::endl);
136 std::getline(gstatOutput,
line);
138 Scalar trash, dataValue;
139 for (
const auto& element : elements(gridView_))
141 std::getline(gstatOutput,
line);
142 std::istringstream curLine(
line);
144 curLine >> trash >> dataValue;
146 curLine >> trash >> trash >> dataValue;
148 curLine >> trash >> trash >> trash >> dataValue;
150 DUNE_THROW(Dune::InvalidStateException,
"Invalid dimension " << dim);
152 data_[elementMapper_.index(element)] = dataValue;
159 std::for_each(data_.begin(), data_.end(), [](Scalar& s){ s = pow(10.0, s); });
176 const std::string& dataName =
"data")
const
178 Dune::VTKWriter<GridView> vtkwriter(gridView_);
179 vtkwriter.addCellData(data_, dataName);
186 std::for_each(logPerm.begin(), logPerm.end(), [](Scalar& s){ s = log10(s); });
187 vtkwriter.addCellData(logPerm,
"log10 of " + dataName);
189 vtkwriter.write(vtkName, Dune::VTK::OutputType::ascii);