Changeset 27244


Ignore:
Timestamp:
08/26/22 21:25:22 (3 years ago)
Author:
Eric.Larour
Message:

CHG making sure we are not spreading a P0 thickness into P1 :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/branches/trunk-larour-SLPS2022/src/c/analyses/MmemasstransportAnalysis.cpp

    r27214 r27244  
    44#include "../classes/classes.h"
    55#include "../classes/Inputs/TransientInput.h"
     6#include "../classes/Inputs/TriaInput.h"
     7#include "../classes/gauss/Gauss.h"
    68#include "../shared/shared.h"
    79#include "../modules/modules.h"
     
    100102void           MmemasstransportAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
    101103
    102         /*retrieve thickness, ice and ocean levelsets from MmemasstransportAnalysis inputs in our element:*/
    103 
    104         IssmDouble height,ice,ocean;
    105         int       *doflist = NULL;
    106 
    107         /*Fetch number of nodes and initialize values*/
    108         int         numnodes = element->GetNumberOfNodes();
    109         int         numdof   = numnodes*3;
    110         IssmDouble* values   = xNew<IssmDouble>(numdof);
    111 
    112         /*Get dof list and inputs */
    113         element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
    114         Input* h_input=element->GetInput(MmemasstransportThicknessEnum); _assert_(h_input);
    115         Input* i_input=element->GetInput(MmemasstransportMaskIceLevelsetEnum); _assert_(i_input);
    116         Input* o_input=element->GetInput(MmemasstransportMaskOceanLevelsetEnum); _assert_(o_input);
    117 
    118         /*Ok, we have the thickness in inputs, fill in solution */
    119         Gauss* gauss=element->NewGauss();
    120         for(int i=0;i<numnodes;i++){
    121                 gauss->GaussVertex(i);
    122                 h_input->GetInputValue(&height,gauss);
    123                 i_input->GetInputValue(&ice,gauss);
    124                 o_input->GetInputValue(&ocean,gauss);
    125                 values[3*i+0]=height;
    126                 values[3*i+1]=ice;
    127                 values[3*i+2]=ocean;
    128         }
    129 
    130         /*Add value to global vector*/
    131         solution->SetValues(numdof,doflist,values,INS_VAL);
    132 
    133         /*Free ressources:*/
    134         delete gauss;
    135         xDelete<int>(doflist);
    136         xDelete<IssmDouble>(values);
     104        /*do nothing:*/
     105        return;
    137106}/*}}}*/
    138107void           MmemasstransportAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element*  element,int control_type,int control_interp,int control_index){/*{{{*/
     
    141110void           MmemasstransportAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
    142111
    143         int         i,domaintype;
    144         int*        doflist=NULL;
     112        /*Fetch number of nodes and dof for this finite element*/
     113        IssmDouble time;
     114        IssmDouble ice[3];
     115        IssmDouble ocean[3];
     116        IssmDouble height;
     117        int numnodes = element->GetNumberOfNodes();
     118       
     119        element->parameters->FindParam(&time,TimeEnum);
    145120
    146         /*Fetch number of nodes and dof for this finite element*/
    147         int numnodes = element->GetNumberOfNodes();
    148         int numdof   = numnodes*3;
     121        TriaInput* h_input=xDynamicCast<TriaInput*>(element->GetInput(MmemasstransportThicknessEnum,time)); _assert_(h_input);
     122        TriaInput* i_input=xDynamicCast<TriaInput*>(element->GetInput(MmemasstransportMaskIceLevelsetEnum,time)); _assert_(i_input);
     123        TriaInput* o_input=xDynamicCast<TriaInput*>(element->GetInput(MmemasstransportMaskOceanLevelsetEnum,time)); _assert_(o_input);
    149124
    150         /*Fetch dof list and allocate solution vectors*/
    151         element->GetDofListLocal(&doflist,NoneApproximationEnum,GsetEnum);
    152         IssmDouble* values    = xNew<IssmDouble>(numdof);
    153         IssmDouble* height        = xNew<IssmDouble>(numnodes);
    154         IssmDouble* ice        = xNew<IssmDouble>(numnodes);
    155         IssmDouble* ocean        = xNew<IssmDouble>(numnodes);
    156 
    157         /*Use the dof list to index into the solution vector: */
    158         for(i=0;i<numdof;i++) values[i]=solution[doflist[i]];
    159 
    160         /*Retrieve h:*/
    161         for(i=0;i<numnodes;i++){
    162                 height[i]=values[3*i+0];
    163                 ice[i]=values[3*i+1];
    164                 ocean[i]=values[3*i+2];
    165 
    166                 /*Check solution*/
    167                 if(xIsNan<IssmDouble>(height[i])) _error_("NaN found in ice thickness solution vector");
    168                 if(xIsInf<IssmDouble>(height[i])) _error_("Inf found in ice thickness solution vector");
    169                 if(xIsNan<IssmDouble>(ice[i])) _error_("NaN found in ice mask solution vector");
    170                 if(xIsInf<IssmDouble>(ice[i])) _error_("Inf found in ice mask solution vector");
    171                 if(xIsNan<IssmDouble>(ocean[i])) _error_("NaN found in ocean mask solution vector");
    172                 if(xIsInf<IssmDouble>(ocean[i])) _error_("Inf found in ocean mask solution vector");
    173 
     125        Gauss* gauss=element->NewGauss();
     126        for(int iv=0;iv<3;iv++){
     127                gauss->GaussVertex(iv);
     128                i_input->GetInputValue(&ice[iv],gauss);
     129                o_input->GetInputValue(&ocean[iv],gauss);
    174130        }
     131        h_input->GetInputAverage(&height);
    175132
    176133        /*Add thickness ice and ocean levelsets as inputs to the tria element: */
    177         element->AddInput(ThicknessEnum,height,P0Enum); //very important, do not change the type of ThicknessEnum to P1 when it should be P0!
     134        element->AddInput(ThicknessEnum,&height,P0Enum); //very important, do not change the type of ThicknessEnum to P1 when it should be P0!
    178135        element->AddInput(MaskIceLevelsetEnum,ice,P1Enum);
    179136        element->AddInput(MaskOceanLevelsetEnum,ocean,P1Enum);
    180 
    181         /*Free ressources:*/
    182         xDelete<IssmDouble>(height);
    183         xDelete<IssmDouble>(ice);
    184         xDelete<IssmDouble>(ocean);
    185         xDelete<IssmDouble>(values);
    186         xDelete<int>(doflist);
    187137
    188138}/*}}}*/
Note: See TracChangeset for help on using the changeset viewer.