Ice Sheet System Model  4.18
Code documentation
Loads.cpp
Go to the documentation of this file.
1 /*
2  * \file Loads.cpp
3  * \brief: Implementation of Loads class, derived from DataSet 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 <vector>
14 #include <functional>
15 #include <algorithm>
16 
17 #include "../../shared/io/Comm/IssmComm.h"
18 #include "../../shared/Numerics/recast.h"
19 #include "../../shared/Enum/EnumDefinitions.h"
20 #include "../../shared/Exceptions/exceptions.h"
21 #include "../../shared/MemOps/MemOps.h"
22 #include "../../shared/io/Marshalling/Marshalling.h"
23 #include "./Loads.h"
24 #include "./Load.h"
25 
26 using namespace std;
27 /*}}}*/
28 
29 /*Object constructors and destructor*/
30 Loads::Loads(){/*{{{*/
31  this->enum_type=LoadsEnum;
32  this->numrifts = 0;
33  this->numpenalties = 0;
34  return;
35 }
36 /*}}}*/
37 Loads::~Loads(){/*{{{*/
38  return;
39 }
40 /*}}}*/
41 
42 Loads* Loads::Copy() {/*{{{*/
43 
44  int num_proc = IssmComm::GetSize();
45 
46  /*Copy dataset*/
47  Loads* output=new Loads();
48  output->sorted=this->sorted;
49  output->numsorted=this->numsorted;
50  output->presorted=this->presorted;
51  for(vector<Object*>::iterator obj=this->objects.begin() ; obj < this->objects.end(); obj++ ){
52  output->AddObject((*obj)->copy());
53  }
54 
55  /*Build id_offsets and sorted_ids*/
56  int objsize = this->numsorted;
57  output->id_offsets=NULL;
58  output->sorted_ids=NULL;
59  if(this->sorted && objsize>0 && this->id_offsets){
60  output->id_offsets=xNew<int>(objsize);
61  xMemCpy<int>(output->id_offsets,this->id_offsets,objsize);
62  }
63  if(this->sorted && objsize>0 && this->sorted_ids){
64  output->sorted_ids=xNew<int>(objsize);
65  xMemCpy<int>(output->sorted_ids,this->sorted_ids,objsize);
66  }
67 
68  /*Copy other fields*/
69  output->numrifts = this->numrifts;
70  output->numpenalties = this->numpenalties;
71 
72  return output;
73 }
74 /*}}}*/
75 void Loads::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
76 
77  int num_procs=IssmComm::GetSize();
78  int test = num_procs;
80  MARSHALLING(numrifts);
81  MARSHALLING(numpenalties);
82 
83  DataSet::Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
84 }
85 /*}}}*/
86 
87 /*Numerics:*/
88 void Loads::Configure(Elements* elements,Loads* loads, Nodes* nodes, Vertices* vertices, Materials* materials,Parameters* parameters){/*{{{*/
89 
90  vector<Object*>::iterator object;
91  for(object=objects.begin() ; object < objects.end(); object++){
92  Load* load=xDynamicCast<Load*>(*object);
93  load->Configure(elements,loads,nodes,vertices,materials,parameters);
94  }
95 }
96 /*}}}*/
97 void Loads::Finalize(){/*{{{*/
98 
99  /*Count Rifts and penalties*/
100  int ispenalty=0;
101  int isrift=0;
102  int allcount;
103 
104  /*Now go through all loads, and get how many nodes they own, unless they are clone nodes: */
105  for(int i=0;i<this->Size();i++){
106  Load* load=xDynamicCast<Load*>(this->GetObjectByOffset(i));
107  if(load->IsPenalty()){
108  ispenalty++;
109  }
110  if(load->ObjectEnum()==RiftfrontEnum){
111  isrift++;
112  }
113  }
114 
115  /*Grab sum of all cpus: */
116  ISSM_MPI_Allreduce((void*)&ispenalty,(void*)&allcount,1,ISSM_MPI_INT,ISSM_MPI_SUM,IssmComm::GetComm());
117  this->numpenalties = allcount;
118 
119  ISSM_MPI_Allreduce((void*)&isrift,(void*)&allcount,1,ISSM_MPI_INT,ISSM_MPI_SUM,IssmComm::GetComm());
120  this->numrifts= allcount;
121 
122 }
123 /*}}}*/
124 bool Loads::IsPenalty(){/*{{{*/
125 
126  if(this->numpenalties>0)
127  return true;
128  else
129  return false;
130 }
131 /*}}}*/
132 int Loads::MaxNumNodes(){/*{{{*/
133 
134  int max=0;
135  int allmax;
136 
137  /*Now go through all loads, and get how many nodes they own, unless they are clone nodes: */
138  for(int i=0;i<this->Size();i++){
139  Load* load=xDynamicCast<Load*>(this->GetObjectByOffset(i));
140  int numnodes=load->GetNumberOfNodes();
141  if(numnodes>max)max=numnodes;
142  }
143 
144  /*Grab max of all cpus: */
146  return allmax;
147 }
148 /*}}}*/
149 int Loads::NumberOfLoads(void){/*{{{*/
150 
151  int localloads;
152  int numberofloads;
153 
154  /*Get number of local loads*/
155  localloads=this->Size();
156 
157  /*figure out total number of loads combining all the cpus (no clones here)*/
158  ISSM_MPI_Reduce(&localloads,&numberofloads,1,ISSM_MPI_INT,ISSM_MPI_SUM,0,IssmComm::GetComm() );
159  ISSM_MPI_Bcast(&numberofloads,1,ISSM_MPI_INT,0,IssmComm::GetComm());
160 
161  return numberofloads;
162 }
163 /*}}}*/
164 void Loads::ResetHooks(){/*{{{*/
165 
166  vector<Object*>::iterator object;
167  Load* load=NULL;
168 
169  for ( object=objects.begin() ; object < objects.end(); object++ ){
170 
171  load=xDynamicCast<Load*>((*object));
172  load->ResetHooks();
173 
174  }
175 
176 }
177 /*}}}*/
178 void Loads::SetCurrentConfiguration(Elements* elements,Loads* loads, Nodes* nodes, Vertices* vertices, Materials* materials,Parameters* parameters){/*{{{*/
179 
180  vector<Object*>::iterator object;
181  Load* load=NULL;
182 
183  for ( object=objects.begin() ; object < objects.end(); object++ ){
184  load=xDynamicCast<Load*>(*object);
185  load->SetCurrentConfiguration(elements,loads,nodes,vertices,materials,parameters);
186  }
187 }
188 /*}}}*/
Vertices
Declaration of Vertices class.
Definition: Vertices.h:15
Loads::ResetHooks
void ResetHooks()
Definition: Loads.cpp:164
LoadsEnum
@ LoadsEnum
Definition: EnumDefinitions.h:1145
Nodes
Declaration of Nodes class.
Definition: Nodes.h:19
Loads.h
ISSM_MPI_Allreduce
int ISSM_MPI_Allreduce(void *sendbuf, void *recvbuf, int count, ISSM_MPI_Datatype datatype, ISSM_MPI_Op op, ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:116
DataSet::AddObject
int AddObject(Object *object)
Definition: DataSet.cpp:252
Parameters
Declaration of Parameters class.
Definition: Parameters.h:18
ISSM_MPI_SUM
#define ISSM_MPI_SUM
Definition: issmmpi.h:134
MARSHALLING_ENUM
#define MARSHALLING_ENUM(EN)
Definition: Marshalling.h:14
IssmComm::GetComm
static ISSM_MPI_Comm GetComm(void)
Definition: IssmComm.cpp:30
Elements
Declaration of Elements class.
Definition: Elements.h:17
ISSM_MPI_MAX
#define ISSM_MPI_MAX
Definition: issmmpi.h:131
Load
Definition: Load.h:22
DataSet::sorted_ids
int * sorted_ids
Definition: DataSet.h:28
Loads::MaxNumNodes
int MaxNumNodes()
Definition: Loads.cpp:132
Loads::Copy
Loads * Copy()
Definition: Loads.cpp:42
Loads::numpenalties
int numpenalties
Definition: Loads.h:21
Loads::Loads
Loads()
Definition: Loads.cpp:30
ISSM_MPI_INT
#define ISSM_MPI_INT
Definition: issmmpi.h:127
Materials
Declaration of Materials class.
Definition: Materials.h:16
Load::Configure
virtual void Configure(Elements *elements, Loads *loads, Nodes *nodes, Vertices *vertices, Materials *materials, Parameters *parameters)=0
Load::SetCurrentConfiguration
virtual void SetCurrentConfiguration(Elements *elements, Loads *loads, Nodes *nodes, Vertices *vertices, Materials *materials, Parameters *parameters)=0
DataSet::sorted
int sorted
Definition: DataSet.h:25
Load.h
abstract class for Load object This class is a place holder for the Icefront and the Penpair loads....
IssmComm::GetSize
static int GetSize(void)
Definition: IssmComm.cpp:46
Loads::Configure
void Configure(Elements *elements, Loads *loads, Nodes *nodes, Vertices *vertices, Materials *materials, Parameters *parameters)
Definition: Loads.cpp:88
MARSHALLING
#define MARSHALLING(FIELD)
Definition: Marshalling.h:29
Loads::IsPenalty
bool IsPenalty()
Definition: Loads.cpp:124
Load::GetNumberOfNodes
virtual int GetNumberOfNodes(void)=0
RiftfrontEnum
@ RiftfrontEnum
Definition: EnumDefinitions.h:1240
ISSM_MPI_Bcast
int ISSM_MPI_Bcast(void *buffer, int count, ISSM_MPI_Datatype datatype, int root, ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:162
Object::ObjectEnum
virtual int ObjectEnum()=0
Loads::NumberOfLoads
int NumberOfLoads()
Definition: Loads.cpp:149
Loads::numrifts
int numrifts
Definition: Loads.h:20
Loads
Declaration of Loads class.
Definition: Loads.h:16
Loads::~Loads
~Loads()
Definition: Loads.cpp:37
Loads::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Loads.cpp:75
DataSet::numsorted
int numsorted
Definition: DataSet.h:27
Load::IsPenalty
virtual bool IsPenalty(void)=0
ISSM_MPI_Reduce
int ISSM_MPI_Reduce(void *sendbuf, void *recvbuf, int count, ISSM_MPI_Datatype datatype, ISSM_MPI_Op op, int root, ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:373
max
IssmDouble max(IssmDouble a, IssmDouble b)
Definition: extrema.cpp:24
Loads::Finalize
void Finalize()
Definition: Loads.cpp:97
DataSet::id_offsets
int * id_offsets
Definition: DataSet.h:29
Loads::SetCurrentConfiguration
void SetCurrentConfiguration(Elements *elements, Loads *loads, Nodes *nodes, Vertices *vertices, Materials *materials, Parameters *parameters)
Definition: Loads.cpp:178
Load::ResetHooks
virtual void ResetHooks()=0
DataSet::presorted
int presorted
Definition: DataSet.h:26
DataSet::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: DataSet.cpp:93