source: issm/branches/trunk-larour-SLPS2022/src/c/classes/GrdLoads.cpp@ 27104

Last change on this file since 27104 was 27104, checked in by Eric.Larour, 3 years ago

CHG: fixed all memory leaks.

File size: 4.1 KB
RevLine 
[26227]1/*
2 * \file GrdLoads.cpp
3 * \brief: Implementation of GrdLoads class
4 */
5
6/*Headers: {{{*/
7#ifdef HAVE_CONFIG_H
8 #include <config.h>
9#else
10#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
11#endif
12
13#include "./GrdLoads.h"
14#include "./SealevelGeometry.h"
15using namespace std;
16/*}}}*/
17
18/*Object constructors and destructor*/
19GrdLoads::GrdLoads(int nel,SealevelGeometry* slgeom){ /*{{{*/
20
[27104]21 /*allocate:*/
[26227]22 vloads=new Vector<IssmDouble>(nel);
23 for (int i=0;i<SLGEOM_NUMLOADS;i++) vsubloads[i]=new Vector<IssmDouble>(slgeom->nbar[i]);
24
25 vsealevelloads=new Vector<IssmDouble>(nel);
26 vsealevelloads->Set(0);vsealevelloads->Assemble();
27
28 vsubsealevelloads=new Vector<IssmDouble>(slgeom->nbar[SLGEOM_OCEAN]);
29
[27104]30 /*make sure all pointers that are not allocated are NULL:*/
31 loads=NULL;
32 for (int i=0;i<SLGEOM_NUMLOADS;i++)subloads[i]=NULL;
33 sealevelloads=NULL;
34 subsealevelloads=NULL;
35
36
[26227]37}; /*}}}*/
38GrdLoads::~GrdLoads(){ /*{{{*/
39
40 delete vloads;
41 xDelete<IssmDouble>(loads);
42 for(int i=0;i<SLGEOM_NUMLOADS;i++){
43 delete vsubloads[i];
44 xDelete<IssmDouble>(subloads[i]);
45 }
46 delete vsealevelloads;
47 xDelete<IssmDouble>(sealevelloads);
48 delete vsubsealevelloads;
49 xDelete<IssmDouble>(subsealevelloads);
50}; /*}}}*/
51
52void GrdLoads::BroadcastLoads(void){ /*{{{*/
53
54 /*Initialize barycentre vectors, now that we know their size: */
55 vloads->Assemble();
56 for (int i=0;i<SLGEOM_NUMLOADS;i++){
57 vsubloads[i]->Assemble();
58 }
[26468]59
[27104]60 /*Avoid leaks:*/
61 if(loads)xDelete<IssmDouble>(loads);
62 for (int i=0;i<SLGEOM_NUMLOADS;i++){
63 if(subloads[i])xDelete<IssmDouble>(subloads[i]);
64 }
65
66 /*Serialize:*/
[26227]67 loads=vloads->ToMPISerial();
68 for (int i=0;i<SLGEOM_NUMLOADS;i++){
69 subloads[i]=vsubloads[i]->ToMPISerial();
70 }
71
72} /*}}}*/
73void GrdLoads::AssembleSealevelLoads(void){ /*{{{*/
74
75 vsealevelloads->Assemble();
76 vsubsealevelloads->Assemble();
77
78} /*}}}*/
79void GrdLoads::BroadcastSealevelLoads(void){ /*{{{*/
[26468]80
[27104]81 /*Avoid leakds:*/
82 if(sealevelloads)xDelete<IssmDouble>(sealevelloads);
83 if(subsealevelloads)xDelete<IssmDouble>(subsealevelloads);
84
85 /*Serialize:*/
[26227]86 sealevelloads=vsealevelloads->ToMPISerial();
87 subsealevelloads=vsubsealevelloads->ToMPISerial();
88
89} /*}}}*/
[27104]90void GrdLoads::SHDegree2Coefficients(IssmDouble* deg2coeff, FemModel* femmodel, SealevelGeometry* slgeom){ /*{{{*/
[26800]91
92 IssmDouble area,re, S;
93 int ylmindex, intj;
94 IssmDouble deg2coeff_local[5];
95
96 femmodel->parameters->FindParam(&re,SolidearthPlanetRadiusEnum);
97
98 for (int c=0;c<5;c++) deg2coeff_local[c]=0;
99
100 for(Object* & object : femmodel->elements->objects){
101 Element* element = xDynamicCast<Element*>(object);
102 //first, loads on centroids
103 S=0;
104 S+=loads[element->Sid()];
105
106 if(sealevelloads) S+=sealevelloads[element->Sid()];
107 if(S!=0){
108 element->Element::GetInputValue(&area,AreaEnum);
109
110 for (int c=0;c<5;c++){ //degree l=2 has 2*l+1=5 coefficients: 2,0; 2,1cos; 2,1sin; 2,2cos; 2,2sin
111 ylmindex=(4+c)*slgeom->localnel+element->lid; // starting at index=l^2
112 deg2coeff_local[c] += S*area/re/re*slgeom->Ylm[ylmindex];
113 }
114 }
115 //add loads on subelement barycenters
116 for (int i=0;i<SLGEOM_NUMLOADS;i++){
117 if (slgeom->issubelement[i][element->lid]){
118 intj=slgeom->subelementmapping[i][element->lid];
119 S=0;
120 S+=subloads[i][intj];
121 if(i==SLGEOM_OCEAN && sealevelloads) S+=subsealevelloads[intj];
122 if(S!=0){
123 area=slgeom->area_subel[i][intj];
124 for (int c=0;c<5;c++){ //degree l=2 has 2*l+1=5 coefficients
125 ylmindex=(4+c)*slgeom->localnel+element->lid; // starting at index=l^2
126 deg2coeff_local[c] += S*area/re/re*slgeom->Ylm_subel[i][ylmindex];
127 }
128 }
129 }
130 }
131 }
132
133 //sum each degree 2 coefficient across all cpus to get global total
134 ISSM_MPI_Reduce (&deg2coeff_local[0],&deg2coeff[0],1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
135 ISSM_MPI_Bcast(&deg2coeff[0],1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
136 ISSM_MPI_Reduce (&deg2coeff_local[1],&deg2coeff[1],1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
137 ISSM_MPI_Bcast(&deg2coeff[1],1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
138 ISSM_MPI_Reduce (&deg2coeff_local[2],&deg2coeff[2],1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
139 ISSM_MPI_Bcast(&deg2coeff[2],1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
140
[27104]141} /*}}}*/
Note: See TracBrowser for help on using the repository browser.