69 std::unique_ptr<TapeWriterInterface<T_Type>>
createWriter(
const std::string& fileName,
70 std::vector<typename T_Type::Identifier>& inputVariables,
71 std::vector<typename T_Type::Identifier>& outputVariables,
73 using Type =
CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
74 using Tape =
typename Type::Tape;
76 std::unique_ptr<TapeWriterInterface<T_Type>> writer =
nullptr;
79 switch (selectedType) {
81 if (IsPrimalValueTape) {
82 writer = make_unique_helper<codi::PrimalTextTapeWriter<Type>>(fileName, inputVariables, outputVariables,
true,
85 writer = make_unique_helper<codi::JacobianTextTapeWriter<Type>>(fileName, inputVariables, outputVariables,
90 case FileType::Binary:
91 if (IsPrimalValueTape) {
92 writer = make_unique_helper<codi::PrimalBinaryTapeWriter<Type>>(fileName, inputVariables, outputVariables);
94 writer = make_unique_helper<codi::JacobianBinaryTapeWriter<Type>>(fileName, inputVariables, outputVariables);
99 if (IsPrimalValueTape) {
100 writer = make_unique_helper<codi::PrimalGraphTapeWriter<Type>>(fileName, inputVariables, outputVariables);
103 make_unique_helper<codi::JacobianGraphTapeWriter<Type>>(fileName, inputVariables, outputVariables,
true);
108 if (IsPrimalValueTape) {
109 writer = make_unique_helper<codi::MathRepWriter<Type>>(fileName, inputVariables, outputVariables);
111 CODI_EXCEPTION(
"The MathRepWriter is not supported for Jacobian tapes.");
116 CODI_EXCEPTION(
"A valid file format was not selected.");
132 std::unique_ptr<TapeReaderInterface<T_Type>>
readTapeFile(std::string
const& fileName) {
136 std::unique_ptr<TapeReaderInterface<T_Type>> reader =
nullptr;
137 std::string fileExtension;
139 size_t dotPosition = fileName.find_last_of(
".");
140 if (dotPosition != std::string::npos) {
141 fileExtension = fileName.substr(dotPosition + 1);
144 if (fileExtension ==
"txt") {
145 reader = make_unique_helper<JacobianTextTapeReader<T_Type>>();
146 }
else if (fileExtension ==
"dat") {
147 reader = make_unique_helper<JacobianBinaryTapeReader<T_Type>>();
149 CODI_EXCEPTION(
"The given file type is not supported.");
151 reader->readFile(fileName);
167 std::string
const& fileName, std::vector<typename T_Type::Tape::EvalHandle>
const& evalHandles) {
171 std::unique_ptr<TapeReaderInterface<T_Type>> reader =
nullptr;
172 std::string fileExtension;
174 size_t dotPosition = fileName.find_last_of(
".");
175 if (dotPosition != std::string::npos) {
176 fileExtension = fileName.substr(dotPosition + 1);
179 if (fileExtension ==
"txt") {
180 reader = make_unique_helper<PrimalTextTapeReader<T_Type>>(evalHandles);
181 }
else if (fileExtension ==
"dat") {
182 reader = make_unique_helper<PrimalBinaryTapeReader<T_Type>>(evalHandles);
184 CODI_EXCEPTION(
"The given file type is not supported.");
187 reader->readFile(fileName);
std::unique_ptr< TapeWriterInterface< T_Type > > createWriter(const std::string &fileName, std::vector< typename T_Type::Identifier > &inputVariables, std::vector< typename T_Type::Identifier > &outputVariables, FileType selectedType)
The createWriter() function is used to generate an automatic writer using the FileType and the TapeTr...
Definition readerWriterHelpers.hpp:69
std::unique_ptr< TapeReaderInterface< T_Type > > readTapeFile(std::string const &fileName)
Uses the fileName to read and restore a Jacobian tape. The file extension is used to determine wether...
Definition readerWriterHelpers.hpp:132
std::unique_ptr< T > make_unique_helper(Args &&... args)
Helper for creating a unique pointer. (std::make_unique is not available in C++11....
Definition readerWriterHelpers.hpp:53