[387] | 1 | /*!\file Pengrid.c
|
---|
| 2 | * \brief: implementation of the Pengrid object
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | #ifdef HAVE_CONFIG_H
|
---|
| 7 | #include "config.h"
|
---|
| 8 | #else
|
---|
| 9 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
| 10 | #endif
|
---|
| 11 |
|
---|
| 12 | #include "stdio.h"
|
---|
| 13 | #include "./Pengrid.h"
|
---|
| 14 | #include <string.h>
|
---|
| 15 | #include "../EnumDefinitions/EnumDefinitions.h"
|
---|
| 16 | #include "../shared/shared.h"
|
---|
| 17 | #include "../include/typedefs.h"
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 | Pengrid::Pengrid(){
|
---|
| 21 | return;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | Pengrid::Pengrid(int pengrid_id, int pengrid_node_id,int pengrid_dof, int pengrid_active, double pengrid_penalty_offset,int pengrid_thermal_steadystate){
|
---|
| 25 |
|
---|
| 26 | id=pengrid_id;
|
---|
| 27 | dof=pengrid_dof;
|
---|
| 28 | active=pengrid_active;
|
---|
| 29 | penalty_offset =pengrid_penalty_offset;
|
---|
| 30 | thermal_steadystate=pengrid_thermal_steadystate;
|
---|
| 31 |
|
---|
| 32 | node_id=pengrid_node_id;
|
---|
| 33 | node_offset=UNDEF;
|
---|
| 34 | node=NULL;
|
---|
| 35 |
|
---|
| 36 | return;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | Pengrid::~Pengrid(){
|
---|
| 40 | return;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | void Pengrid::Echo(void){
|
---|
| 44 |
|
---|
| 45 | printf("Pengrid:\n");
|
---|
| 46 | printf(" id: %i\n",id);
|
---|
| 47 | printf(" dof: %i\n",dof);
|
---|
| 48 | printf(" active: %i\n",active);
|
---|
| 49 | printf(" penalty_offset: %g\n",penalty_offset);
|
---|
| 50 | printf(" thermal_steadystate: %i\n",thermal_steadystate);
|
---|
| 51 | printf(" node_id: [%i]\n",node_id);
|
---|
| 52 | printf(" node_offset: [%i]\n",node_offset);
|
---|
| 53 |
|
---|
| 54 | if(node)node->Echo();
|
---|
| 55 | return;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | void Pengrid::Marshall(char** pmarshalled_dataset){
|
---|
| 59 |
|
---|
| 60 | char* marshalled_dataset=NULL;
|
---|
| 61 | int enum_type=0;
|
---|
| 62 |
|
---|
| 63 | /*recover marshalled_dataset: */
|
---|
| 64 | marshalled_dataset=*pmarshalled_dataset;
|
---|
| 65 |
|
---|
| 66 | /*get enum type of Pengrid: */
|
---|
| 67 | enum_type=PengridEnum();
|
---|
| 68 |
|
---|
| 69 | /*marshall enum: */
|
---|
| 70 | memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
|
---|
| 71 |
|
---|
| 72 | /*marshall Pengrid data: */
|
---|
| 73 | memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
|
---|
| 74 | memcpy(marshalled_dataset,&dof,sizeof(dof));marshalled_dataset+=sizeof(dof);
|
---|
| 75 | memcpy(marshalled_dataset,&active,sizeof(active));marshalled_dataset+=sizeof(active);
|
---|
| 76 | memcpy(marshalled_dataset,&penalty_offset,sizeof(penalty_offset));marshalled_dataset+=sizeof(penalty_offset);
|
---|
| 77 | memcpy(marshalled_dataset,&thermal_steadystate,sizeof(thermal_steadystate));marshalled_dataset+=sizeof(thermal_steadystate);
|
---|
| 78 | memcpy(marshalled_dataset,&node_id,sizeof(node_id));marshalled_dataset+=sizeof(node_id);
|
---|
| 79 | memcpy(marshalled_dataset,&node_offset,sizeof(node_offset));marshalled_dataset+=sizeof(node_offset);
|
---|
| 80 |
|
---|
| 81 | *pmarshalled_dataset=marshalled_dataset;
|
---|
| 82 | return;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | int Pengrid::MarshallSize(){
|
---|
| 86 |
|
---|
| 87 | return sizeof(id)+
|
---|
| 88 | sizeof(dof)+
|
---|
| 89 | sizeof(active)+
|
---|
| 90 | sizeof(penalty_offset)+
|
---|
| 91 | sizeof(thermal_steadystate)+
|
---|
| 92 | sizeof(node_id)+
|
---|
| 93 | sizeof(node_offset)+
|
---|
| 94 | sizeof(int); //sizeof(int) for enum type
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | char* Pengrid::GetName(void){
|
---|
| 98 | return "pengrid";
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 |
|
---|
| 102 | void Pengrid::Demarshall(char** pmarshalled_dataset){
|
---|
| 103 |
|
---|
| 104 | char* marshalled_dataset=NULL;
|
---|
| 105 |
|
---|
| 106 | /*recover marshalled_dataset: */
|
---|
| 107 | marshalled_dataset=*pmarshalled_dataset;
|
---|
| 108 |
|
---|
| 109 | /*this time, no need to get enum type, the pointer directly points to the beginning of the
|
---|
| 110 | *object data (thanks to DataSet::Demarshall):*/
|
---|
| 111 |
|
---|
| 112 | memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
|
---|
| 113 | memcpy(&dof,marshalled_dataset,sizeof(dof));marshalled_dataset+=sizeof(dof);
|
---|
| 114 | memcpy(&active,marshalled_dataset,sizeof(active));marshalled_dataset+=sizeof(active);
|
---|
| 115 | memcpy(&penalty_offset,marshalled_dataset,sizeof(penalty_offset));marshalled_dataset+=sizeof(penalty_offset);
|
---|
| 116 | memcpy(&thermal_steadystate,marshalled_dataset,sizeof(thermal_steadystate));marshalled_dataset+=sizeof(thermal_steadystate);
|
---|
| 117 | memcpy(&node_id,marshalled_dataset,sizeof(node_id));marshalled_dataset+=sizeof(node_id);
|
---|
| 118 | memcpy(&node_offset,marshalled_dataset,sizeof(node_offset));marshalled_dataset+=sizeof(node_offset);
|
---|
| 119 |
|
---|
| 120 | node=NULL;
|
---|
| 121 |
|
---|
| 122 | /*return: */
|
---|
| 123 | *pmarshalled_dataset=marshalled_dataset;
|
---|
| 124 | return;
|
---|
| 125 | }
|
---|
| 126 | int Pengrid::Enum(void){
|
---|
| 127 |
|
---|
| 128 | return PengridEnum();
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | int Pengrid::GetId(void){ return id; }
|
---|
| 132 |
|
---|
| 133 | int Pengrid::MyRank(void){
|
---|
| 134 | extern int my_rank;
|
---|
| 135 | return my_rank;
|
---|
| 136 | }
|
---|
[394] | 137 | void Pengrid::DistributeNumDofs(int* numdofpernode,int analysis_type){return;}
|
---|
[387] | 138 |
|
---|
| 139 | #undef __FUNCT__
|
---|
| 140 | #define __FUNCT__ "Pengrid::Configure"
|
---|
| 141 |
|
---|
| 142 | void Pengrid::Configure(void* pelementsin,void* pnodesin,void* pmaterialsin){
|
---|
| 143 |
|
---|
| 144 | DataSet* nodesin=NULL;
|
---|
| 145 |
|
---|
| 146 | /*Recover pointers :*/
|
---|
| 147 | nodesin=(DataSet*)pnodesin;
|
---|
| 148 |
|
---|
| 149 | /*Link this load with its nodes: */
|
---|
| 150 | ResolvePointers((Object**)&node,&node_id,&node_offset,1,nodesin);
|
---|
| 151 |
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 |
|
---|
| 155 | #undef __FUNCT__
|
---|
| 156 | #define __FUNCT__ "Pengrid::CreateKMatrix"
|
---|
| 157 |
|
---|
| 158 | void Pengrid::CreateKMatrix(Mat Kgg,void* inputs,int analysis_type){
|
---|
| 159 |
|
---|
| 160 | /*No loads applied, do nothing: */
|
---|
| 161 | return;
|
---|
| 162 |
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | #undef __FUNCT__
|
---|
| 166 | #define __FUNCT__ "Pengrid::CreatePVector"
|
---|
| 167 | void Pengrid::CreatePVector(Vec pg, void* inputs, int analysis_type){
|
---|
| 168 |
|
---|
| 169 | /*No loads applied, do nothing: */
|
---|
| 170 | return;
|
---|
| 171 |
|
---|
| 172 | }
|
---|
| 173 | #undef __FUNCT__
|
---|
| 174 | #define __FUNCT__ "Pengrid::UpdateFromInputs"
|
---|
| 175 | void Pengrid::UpdateFromInputs(void* inputs){
|
---|
| 176 |
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | #undef __FUNCT__
|
---|
| 180 | #define __FUNCT__ "Pengrid::PenaltyCreateKMatrix"
|
---|
| 181 | void Pengrid::PenaltyCreateKMatrix(Mat Kgg,void* inputs,double kmax,int analysis_type){
|
---|
[394] | 182 |
|
---|
| 183 | if ((analysis_type==DiagnosticStokesAnalysisEnum())){
|
---|
| 184 |
|
---|
| 185 | PenaltyCreateKMatrixDiagnosticStokes( Kgg,inputs,kmax,analysis_type);
|
---|
| 186 |
|
---|
| 187 | }
|
---|
| 188 | else{
|
---|
| 189 | throw ErrorException(__FUNCT__,exprintf("%s%i%s\n","analysis: ",analysis_type," not supported yet"));
|
---|
| 190 | }
|
---|
| 191 |
|
---|
[387] | 192 | }
|
---|
[394] | 193 |
|
---|
[387] | 194 | #undef __FUNCT__
|
---|
[394] | 195 | #define __FUNCT__ "Pengrid::PenaltyCreateKMatrixDiagnosticStokes"
|
---|
| 196 | void Pengrid::PenaltyCreateKMatrixDiagnosticStokes(Mat Kgg,void* vinputs,double kmax,int analysis_type){
|
---|
| 197 |
|
---|
| 198 | const int numgrids=1;
|
---|
| 199 | const int NDOF3=3;
|
---|
| 200 | const int numdof=numgrids*NDOF3;
|
---|
| 201 | int doflist[numdof];
|
---|
| 202 | int numberofdofspernode;
|
---|
| 203 |
|
---|
| 204 | int dofs1=0;
|
---|
| 205 | int dofs2=1;
|
---|
| 206 | double slope[2];
|
---|
| 207 | int found=0;
|
---|
[442] | 208 | double Ke[4][4]={0.0};
|
---|
[394] | 209 |
|
---|
| 210 | ParameterInputs* inputs=NULL;
|
---|
| 211 |
|
---|
| 212 | /*recover pointers: */
|
---|
| 213 | inputs=(ParameterInputs*)vinputs;
|
---|
| 214 |
|
---|
| 215 | /*Get dof list: */
|
---|
| 216 | GetDofList(&doflist[0],&numberofdofspernode);
|
---|
| 217 |
|
---|
| 218 | /*recover slope: */
|
---|
| 219 | found=inputs->Recover("bedslopex",&slope[0],1,&dofs1,numgrids,(void**)&node);
|
---|
| 220 | if(!found)throw ErrorException(__FUNCT__," bedslopex needed in inputs!");
|
---|
| 221 | found=inputs->Recover("bedslopey",&slope[1],1,&dofs2,numgrids,(void**)&node);
|
---|
| 222 | if(!found)throw ErrorException(__FUNCT__," bedslopey needed in inputs!");
|
---|
| 223 |
|
---|
| 224 | //Create elementary matrix: add penalty to contrain wb (wb=ub*db/dx+vb*db/dy)
|
---|
| 225 | Ke[0][0]=-slope[0]*kmax*pow(10.0,penalty_offset);
|
---|
| 226 | Ke[1][1]=-slope[1]*kmax*pow(10.0,penalty_offset);
|
---|
| 227 | Ke[2][2]=kmax*pow(10,penalty_offset);
|
---|
| 228 |
|
---|
| 229 | /*Add Ke to global matrix Kgg: */
|
---|
| 230 | MatSetValues(Kgg,numdof,doflist,numdof,doflist,(const double*)Ke,ADD_VALUES);
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | #undef __FUNCT__
|
---|
[387] | 234 | #define __FUNCT__ "Pengrid::PenaltyCreatePVector"
|
---|
| 235 | void Pengrid::PenaltyCreatePVector(Vec pg,void* inputs,double kmax,int analysis_type){
|
---|
[442] | 236 |
|
---|
| 237 | /*No penalty applied, do nothing: */
|
---|
| 238 | return;
|
---|
| 239 |
|
---|
[387] | 240 | }
|
---|
| 241 |
|
---|
| 242 | Object* Pengrid::copy() {
|
---|
| 243 | return new Pengrid(*this);
|
---|
| 244 | }
|
---|
| 245 |
|
---|
[394] | 246 |
|
---|
| 247 | void Pengrid::GetDofList(int* doflist,int* pnumberofdofspernode){
|
---|
| 248 |
|
---|
| 249 | int j;
|
---|
| 250 | int doflist_per_node[MAXDOFSPERNODE];
|
---|
| 251 | int numberofdofspernode;
|
---|
| 252 |
|
---|
| 253 | node->GetDofList(&doflist_per_node[0],&numberofdofspernode);
|
---|
| 254 | for(j=0;j<numberofdofspernode;j++){
|
---|
| 255 | doflist[j]=doflist_per_node[j];
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | /*Assign output pointers:*/
|
---|
| 259 | *pnumberofdofspernode=numberofdofspernode;
|
---|
| 260 | }
|
---|