41 const dictionary& options,
52 label nDesignVars = options.getLabel(
"nDesignVars");
62 MatSetFromOptions(jacMat);
63 MatMPIAIJSetPreallocation(jacMat, nDesignVars, NULL, nDesignVars, NULL);
64 MatSeqAIJSetPreallocation(jacMat, nDesignVars, NULL);
67 MatZeroEntries(jacMat);
68 Info <<
"Partial derivative matrix created. " <<
mesh_.time().elapsedClockTime() <<
" s" << endl;
72 const dictionary& options,
99 label nDesignVars = options.getLabel(
"nDesignVars");
101 word objFuncName, objFuncPart;
102 dictionary objFuncSubDictPart = options.subDict(
"objFuncSubDictPart");
103 options.readEntry<word>(
"objFuncName", objFuncName);
104 options.readEntry<word>(
"objFuncPart", objFuncPart);
106 autoPtr<DAObjFunc> daObjFunc(
119 MatZeroEntries(jacMat);
122 mOptions.set(
"updateState", 1);
123 mOptions.set(
"updateMesh", 1);
124 scalar fRef = daObjFunc->masterFunction(mOptions, xvVec, wVec);
127 scalar rDelta = 1.0 / delta;
130 VecDuplicate(xvVec, &xvVecNew);
131 VecZeroEntries(xvVecNew);
134 for (label i = 0; i < nDesignVars; i++)
136 label eTime =
mesh_.time().elapsedClockTime();
138 if (i % printInterval == 0 or i == nDesignVars - 1)
140 Info <<
modelType_ <<
": " << i <<
" of " << nDesignVars
141 <<
", ExecutionTime: " << eTime <<
" s" << endl;
145 VecZeroEntries(xvVecNew);
147 VecAXPY(xvVecNew, 1.0, xvVec);
150 scalar fNew = daObjFunc->masterFunction(mOptions, xvVecNew, wVec);
154 scalar partDeriv = (fNew - fRef) * rDelta;
155 PetscScalar partDerivValue = 0.0;
158 MatSetValue(jacMat, 0, i, partDerivValue, INSERT_VALUES);
162 fRef = daObjFunc->masterFunction(mOptions, xvVec, wVec);
166 Info << objFuncName <<
": " << fRef << endl;
169 MatAssemblyBegin(jacMat, MAT_FINAL_ASSEMBLY);
170 MatAssemblyEnd(jacMat, MAT_FINAL_ASSEMBLY);