Changeset 13513


Ignore:
Timestamp:
10/03/12 07:41:55 (12 years ago)
Author:
utke
Message:

NEW fov_reverse driver

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/c/modules/AutodiffDriversx/AutodiffDriversx.cpp ΒΆ

    r13507 r13513  
    199199                                xDelete(aWeightVector);
    200200                        }
    201                         else if (strcmp(driver,"fov_reverse")==0) {
     201                        else if ((strcmp(driver,"fov_reverse")==0) || (strcmp(driver,"fov_reverse_all")==0)){
     202
     203                                int* depIndices=NULL;
     204                                int weightNum;
     205                                int dummy;
     206                                double **weightsTimesJac=NULL;
     207                                double **weights=NULL;
     208                                std::set<unsigned int> anIndexSet;
     209
     210
     211                                /*retrieve directions:*/
     212                                if (strcmp(driver,"fov_reverse_all")==0){
     213                                        weightNum=num_dependents;
     214                                        depIndices=xNewZeroInit<int>(weightNum);
     215                                        for(i=0;i<num_dependents;i++)depIndices[i]=1;
     216                                }
     217                                else{
     218                                        parameters->FindParam(&depIndices,&weightNum,&dummy,AutodiffFovForwardIndicesEnum);
     219                                }
     220
     221                                /*Some checks: */
     222                                if (weightNum<1 || weightNum>num_dependents) _error_("tangentDirNum should be in [1,num_dependents]");
     223
     224                                /* full Jacobian or Jacobian projection:*/
     225                                weightsTimesJac=xNew<double>(weightNum,num_independents);
     226
     227                                /*set the forward method function pointers: */
     228                                anEDF_for_solverx_p->fov_reverse=EDF_fov_reverse_for_solverx;
     229
    202230                                /*allocate the space for the parameters to invoke the EDF fos_reverse :*/
    203                                 anEDF_for_solverx_p->dpp_U=xNew<double>(num_dependents,anEDF_for_solverx_p->max_m);
    204                                 anEDF_for_solverx_p->dpp_Z=xNew<double>(num_dependents,anEDF_for_solverx_p->max_n);
    205                                 _error_("driver: " << driver << " not yet supported!");
     231                                anEDF_for_solverx_p->dpp_U=xNew<double>(weightNum,anEDF_for_solverx_p->max_m);
     232                                anEDF_for_solverx_p->dpp_Z=xNew<double>(weightNum,anEDF_for_solverx_p->max_n);
     233
     234                                /*seed matrix: */
     235                                weights=xNewZeroInit<double>(weightNum,num_dependents);
     236
     237                                /*collect indices in a set to prevent accidental duplicates as long as we don't do compression:*/
     238                                for (int i=0; i<weightNum; ++i) {
     239                                        /* make sure the index is in range*/
     240                                        if (depIndices[i]>num_dependents) {
     241                                                _error_("depIndices values must be in [0,num_dependents-1]");
     242                                        }
     243                                        if (anIndexSet.find(depIndices[i])!=anIndexSet.end()) {
     244                                                _error_("duplicate depIndices values are not allowed until we implement Jacobian decompression");
     245                                        }
     246                                        anIndexSet.insert(depIndices[i]);
     247                                        /* now populate the seed matrix from the set of independent indices;
     248                                         * simple setup with a single 1.0 per column and at most a single 1.0 per row*/
     249                                        weights[depIndices[i]][i]=1.0;
     250                                }
     251
     252                                /*call driver: */
     253                                fov_reverse(1,num_dependents,num_independents, weightNum, weights, weightsTimesJac );
     254
     255                                /*add to results: */
     256                                results->AddObject(new GenericExternalResult<IssmPDouble*>(results->Size()+1,AutodiffJacobianEnum,*weightsTimesJac,weightNum*num_independents,1,1,0.0));
     257
     258                                /*Free resources: */
     259                                xDelete(weights);
     260                                xDelete(weightsTimesJac);
     261                                xDelete(depIndices);
    206262                        }
    207263                        else _error_("driver: " << driver << " not yet supported!");
Note: See TracChangeset for help on using the changeset viewer.