38#include "jacobianBaseReaderWriter.hpp"
56 template<
typename T_Type>
59 using Tape =
typename Type::Tape;
61 using Real =
typename Type::Real;
70 std::vector<Identifier>
const& out,
bool ifIO,
bool ifColumnNames)
80 if (printColumnNames) {
81 fprintf(
fileHandleTxt,
"| LHS Index | # of Args | RHS Indices | RHS Jacobian Values |");
96 for (
size_t argCount = 0; argCount < nJacobians; argCount++) {
97 fprintf(
fileHandleTxt,
" %d ", rhsIdentifiers[curJacobianPos + argCount]);
101 for (
size_t argCount = 0; argCount < nJacobians; argCount++) {
102 fprintf(
fileHandleTxt,
" %0.12e ", rhsJacobians[curJacobianPos + argCount]);
129 template<
typename T_Type>
132 using Tape =
typename Type::Tape;
134 using Real =
typename Type::Real;
140 FILE* fileHandleReadTxt =
nullptr;
142 bool isFirstIdentifier =
true;
158 fscanf(fileHandleReadTxt,
"| LHS Index | # of Args | RHS Indices | RHS Jacobian Values |");
161 while (fscanf(fileHandleReadTxt,
"\n%d %hhu [", &lhsIdentifier, &nArgs) == 2) {
167 for (
size_t argumentCount = 0; argumentCount < nArgs; argumentCount++) {
168 fscanf(fileHandleReadTxt,
" %d ", &rhsIdentifiers[argumentCount]);
170 fscanf(fileHandleReadTxt,
"] [");
171 for (
size_t argumentCount = 0; argumentCount < nArgs; argumentCount++) {
172 fscanf(fileHandleReadTxt,
" %lf ", &rhsJacobians[argumentCount]);
175 fscanf(fileHandleReadTxt,
"]");
177 this->
registerStatement(lhsIdentifier, nArgs, rhsIdentifiers, rhsJacobians, lowestIndex, isFirstIdentifier);
184 fclose(fileHandleReadTxt);
#define CODI_Unlikely
Declare unlikely evaluation of an execution path.
Definition config.h:399
#define CODI_Likely
Declare likely evaluation of an execution path.
Definition config.h:397
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
size_t constexpr StatementLowLevelFunctionTag
Statement tag for low level functions.
Definition config.h:126
size_t constexpr MaxArgumentSize
Maximum number of arguments in a statement.
Definition config.h:120
uint8_t ArgumentSize
Type for the number of arguments in statements.
Definition config.h:117
size_t constexpr StatementInputTag
Tag for statements that are inputs. Used in linear index management context.
Definition config.h:123
CoDiPack - Code Differentiation Package.
Definition codi.hpp:91
void restoreIoText()
Constructor.
Definition commonReaderWriterBase.hpp:161
void updateUserIO(Identifier const &linearOffset)
This method is used to remove any offset and to update the largest created index.
Definition commonReaderWriterBase.hpp:209
Tape tape
The newly resorted tape.
Definition commonReaderWriterBase.hpp:153
Identifier largestIndex
The largest index on the stored tape.
Definition commonReaderWriterBase.hpp:155
This class is a common base for all the writers and produces a IO file that contains the input and ou...
Definition commonReaderWriterBase.hpp:84
void printIoText(Tape &tape)
Generate the IO file in a text format.
Definition commonReaderWriterBase.hpp:100
std::string fileName
The base file name provided by the user.
Definition commonReaderWriterBase.hpp:51
void openFile(FILE *&fileHandle, std::string const &name, std::string const &mode)
Definition commonReaderWriterBase.hpp:67
Used to register a statement for a Jacobian tape.
Definition jacobianBaseReaderWriter.hpp:48
void registerStatement(Identifier const &lhsIdentifier, Config::ArgumentSize const &nArgs, std::vector< Identifier > const &rhsIdentifiers, std::vector< Real > const &rhsJacobians, Identifier &lowestIndex, bool &isFirstIdentifier)
Constructor.
Definition jacobianBaseReaderWriter.hpp:57
Reads and restores a text file for a Jacobian tape.
Definition jacobianTextReaderWriter.hpp:130
typename Type::Real Real
See TapeReaderInterface.
Definition jacobianTextReaderWriter.hpp:134
T_Type Type
See TapeReaderInterface.
Definition jacobianTextReaderWriter.hpp:131
typename Type::Identifier Identifier
See TapeReaderInterface.
Definition jacobianTextReaderWriter.hpp:133
typename Type::Tape Tape
See TapeReaderInterface.
Definition jacobianTextReaderWriter.hpp:132
JacobianTextTapeReader()
Constructor.
Definition jacobianTextReaderWriter.hpp:136
void readFile(std::string const &name)
This method uses the the fileName to reproduce a valid tape.
Definition jacobianTextReaderWriter.hpp:139
Writes a Jacobian tape in a text format.
Definition jacobianTextReaderWriter.hpp:57
typename Type::Identifier Identifier
See TapeWriterInterface.
Definition jacobianTextReaderWriter.hpp:60
typename Type::Real Real
See TapeWriterInterface.
Definition jacobianTextReaderWriter.hpp:61
void finish()
After all the statements have been written, the finish method finalizes the writing process.
Definition jacobianTextReaderWriter.hpp:109
bool printIO
Flag to enable the writing of the IO file.
Definition jacobianTextReaderWriter.hpp:65
bool printColumnNames
Flag to enable column names.
Definition jacobianTextReaderWriter.hpp:66
T_Type Type
See TapeWriterInterface.
Definition jacobianTextReaderWriter.hpp:58
typename Type::Tape Tape
See TapeWriterInterface.
Definition jacobianTextReaderWriter.hpp:59
void start(Tape &tape)
Destructor.
Definition jacobianTextReaderWriter.hpp:74
JacobianTextTapeWriter(std::string const &name, std::vector< Identifier > const &in, std::vector< Identifier > const &out, bool ifIO, bool ifColumnNames)
Constructor.
Definition jacobianTextReaderWriter.hpp:69
void writeStatement(Identifier const &curLhsIdentifier, size_t &curJacobianPos, Real const *const rhsJacobians, Identifier const *const rhsIdentifiers, Config::ArgumentSize const &nJacobians)
Called for each statement. The method writes the current statement to the file. This overload is used...
Definition jacobianTextReaderWriter.hpp:89
FILE * fileHandleTxt
File handle.
Definition jacobianTextReaderWriter.hpp:63