41 const dictionary& options,
52 label nDesignVars = options.getLabel(
"nDesignVars");
65 MatSetFromOptions(jacMat);
66 MatMPIAIJSetPreallocation(jacMat, nDesignVars, NULL, nDesignVars, NULL);
67 MatSeqAIJSetPreallocation(jacMat, nDesignVars, NULL);
70 MatZeroEntries(jacMat);
71 Info <<
"Partial derivative matrix created. " <<
mesh_.time().elapsedClockTime() <<
" s" << endl;
75 const dictionary& options,
98 label nDesignVars = options.getLabel(
"nDesignVars");
103 MatZeroEntries(jacMat);
106 Vec resVecRef, resVec;
107 VecDuplicate(wVec, &resVec);
108 VecDuplicate(wVec, &resVecRef);
109 VecZeroEntries(resVec);
110 VecZeroEntries(resVecRef);
113 mOptions.set(
"updateState", 1);
114 mOptions.set(
"updateMesh", 1);
115 mOptions.set(
"setResVec", 1);
116 mOptions.set(
"isPC", options.getLabel(
"isPC"));
120 scalar rDelta = 1.0 / delta;
121 PetscScalar rDeltaValue = 0.0;
125 VecDuplicate(xvVec, &xvVecNew);
126 VecZeroEntries(xvVecNew);
129 for (label i = 0; i < nDesignVars; i++)
131 label eTime =
mesh_.time().elapsedClockTime();
133 if (i % printInterval == 0 or i == nDesignVars - 1)
135 Info <<
modelType_ <<
": " << i <<
" of " << nDesignVars
136 <<
", ExecutionTime: " << eTime <<
" s" << endl;
140 VecZeroEntries(xvVecNew);
142 VecAXPY(xvVecNew, 1.0, xvVec);
150 VecAXPY(resVec, -1.0, resVecRef);
151 VecScale(resVec, rDeltaValue);
154 PetscInt Istart, Iend;
155 VecGetOwnershipRange(resVec, &Istart, &Iend);
157 const PetscScalar* resVecArray;
158 VecGetArrayRead(resVec, &resVecArray);
159 for (label j = Istart; j < Iend; j++)
161 label relIdx = j - Istart;
162 PetscScalar val = resVecArray[relIdx];
163 MatSetValue(jacMat, j, i, val, INSERT_VALUES);
165 VecRestoreArrayRead(resVec, &resVecArray);
171 MatAssemblyBegin(jacMat, MAT_FINAL_ASSEMBLY);
172 MatAssemblyEnd(jacMat, MAT_FINAL_ASSEMBLY);