81 void create(
const std::string& gstatControlFile,
82 const std::string& gstatInputFile =
"gstatInput.txt",
83 const std::string& gstatOutputFile =
"permeab.dat",
85 bool createNew =
true)
87 fieldType_ = fieldType;
91 DUNE_THROW(Dune::InvalidStateException,
"Requested data field generation with gstat"
92 <<
" but gstat was not found on your system. Set GSTAT_ROOT to the path where gstat "
93 <<
" is installed and pass it to CMake, e.g. through an opts file.");
95 std::ofstream gstatInput(gstatInputFile);
96 for (
const auto& element : elements(gridView_))
98 gstatInput << element.geometry().center() << std::endl;
103 syscom = GSTAT_EXECUTABLE;
105 syscom += gstatControlFile;
107 if (!gstatInput.good())
109 DUNE_THROW(Dune::IOError,
"Reading the gstat control file: "
110 << gstatControlFile <<
" failed." << std::endl);
113 if (system(syscom.c_str()))
115 DUNE_THROW(Dune::IOError,
"Executing gstat failed.");
120 std::ifstream gstatOutput(gstatOutputFile);
121 if (!gstatOutput.good())
123 DUNE_THROW(Dune::IOError,
"Reading from file: "
124 << gstatOutputFile <<
" failed." << std::endl);
128 std::getline(gstatOutput, line);
130 Scalar trash, dataValue;
131 for (
const auto& element : elements(gridView_))
133 std::getline(gstatOutput, line);
134 std::istringstream curLine(line);
136 curLine >> trash >> dataValue;
138 curLine >> trash >> trash >> dataValue;
140 curLine >> trash >> trash >> trash >> dataValue;
142 DUNE_THROW(Dune::InvalidStateException,
"Invalid dimension " << dim);
144 data_[elementMapper_.index(element)] = dataValue;
151 std::for_each(data_.begin(), data_.end(), [](Scalar& s){ s = pow(10.0, s); });
168 const std::string& dataName =
"data")
const
170 Dune::VTKWriter<GridView> vtkwriter(gridView_);
171 vtkwriter.addCellData(data_, dataName);
178 std::for_each(logPerm.begin(), logPerm.end(), [](Scalar& s){ s = log10(s); });
179 vtkwriter.addCellData(logPerm,
"log10 of " + dataName);
181 vtkwriter.write(vtkName, Dune::VTK::OutputType::ascii);