93 void create(
const std::string& gstatControlFile,
94 const std::string& gstatInputFile =
"gstatInput.txt",
95 const std::string& gstatOutputFile =
"permeab.dat",
97 bool createNew =
true)
99 fieldType_ = fieldType;
103 DUNE_THROW(Dune::InvalidStateException,
"Requested data field generation with gstat"
104 <<
" but gstat was not found on your system. Set GSTAT_ROOT to the path where gstat "
105 <<
" is installed and pass it to CMake, e.g. through an opts file.");
107 std::ofstream gstatInput(gstatInputFile);
108 for (
const auto& element : elements(gridView_))
110 gstatInput << element.geometry().center() << std::endl;
115 syscom = GSTAT_EXECUTABLE;
117 syscom += gstatControlFile;
119 if (!gstatInput.good())
121 DUNE_THROW(Dune::IOError,
"Reading the gstat control file: "
122 << gstatControlFile <<
" failed." << std::endl);
125 if (system(syscom.c_str()))
127 DUNE_THROW(Dune::IOError,
"Executing gstat failed.");
132 std::ifstream gstatOutput(gstatOutputFile);
133 if (!gstatOutput.good())
135 DUNE_THROW(Dune::IOError,
"Reading from file: "
136 << gstatOutputFile <<
" failed." << std::endl);
140 std::getline(gstatOutput, line);
142 Scalar trash, dataValue;
143 for (
const auto& element : elements(gridView_))
145 std::getline(gstatOutput, line);
146 std::istringstream curLine(line);
148 curLine >> trash >> dataValue;
150 curLine >> trash >> trash >> dataValue;
152 curLine >> trash >> trash >> trash >> dataValue;
154 DUNE_THROW(Dune::InvalidStateException,
"Invalid dimension " << dim);
156 data_[elementMapper_.index(element)] = dataValue;
163 std::for_each(data_.begin(), data_.end(), [](Scalar& s){ s = pow(10.0, s); });
180 const std::string& dataName =
"data")
const
182 Dune::VTKWriter<GridView> vtkwriter(gridView_);
183 vtkwriter.addCellData(data_, dataName);
190 std::for_each(logPerm.begin(), logPerm.end(), [](Scalar& s){ s = log10(s); });
191 vtkwriter.addCellData(logPerm,
"log10 of " + dataName);
193 vtkwriter.write(vtkName, Dune::VTK::OutputType::ascii);