[1881] | 1 | /*!\file FemModel.c
|
---|
| 2 | * \brief: implementation of the FemModel object
|
---|
| 3 | */
|
---|
| 4 |
|
---|
[3982] | 5 |
|
---|
[1881] | 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"
|
---|
[3982] | 13 | #include "../DataSet/DataSet.h"
|
---|
[4009] | 14 | #include "../modules/ModelProcessorx/ModelProcessorx.h"
|
---|
[3982] | 15 | #include "./objects.h"
|
---|
[3775] | 16 | #include "../include/include.h"
|
---|
[3982] | 17 | #include "../EnumDefinitions/EnumDefinitions.h"
|
---|
| 18 | #include "../modules/modules.h"
|
---|
[1881] | 19 |
|
---|
[3982] | 20 | /*Object constructors and destructor*/
|
---|
| 21 | /*FUNCTION FemModel::constructor {{{1*/
|
---|
[4028] | 22 | FemModel::FemModel(ConstDataHandle IOMODEL,int in_solution_type,int* analyses, int nummodels){
|
---|
[1881] | 23 |
|
---|
[4001] | 24 | /*intermediary*/
|
---|
| 25 | int i;
|
---|
[4004] | 26 | IoModel* iomodel=NULL;
|
---|
| 27 | int analysis_type;
|
---|
[4001] | 28 |
|
---|
[4028] | 29 | /*Initialize internal data: */
|
---|
[4004] | 30 | this->nummodels=nummodels;
|
---|
[4028] | 31 | this->solution_type=in_solution_type;
|
---|
[4063] | 32 | this->analysis_counter=nummodels-1; //point to last analysis_type carried out.
|
---|
[4050] | 33 | this->results=new DataSet(); //not initialized by CreateDataSets
|
---|
[3982] | 34 |
|
---|
| 35 | /*Dynamically allocate whatever is a list of length nummodels: */
|
---|
| 36 | analysis_type_list=(int*)xmalloc(nummodels*sizeof(int));
|
---|
[4055] | 37 | m_Rmg=(Mat*)xmalloc(nummodels*sizeof(Mat));
|
---|
| 38 | m_Gmn=(Mat*)xmalloc(nummodels*sizeof(Mat));
|
---|
| 39 | m_nodesets=(NodeSets**)xmalloc(nummodels*sizeof(NodeSets*));
|
---|
| 40 | m_yg=(Vec*)xmalloc(nummodels*sizeof(Vec));
|
---|
| 41 | m_ys=(Vec*)xmalloc(nummodels*sizeof(Vec));
|
---|
[1881] | 42 |
|
---|
[4004] | 43 | /*Initialize: */
|
---|
| 44 | for(i=0;i<nummodels;i++)analysis_type_list[i]=analyses[i];
|
---|
[4055] | 45 | for(i=0;i<nummodels;i++)m_Rmg[i]=NULL;
|
---|
| 46 | for(i=0;i<nummodels;i++)m_Gmn[i]=NULL;
|
---|
| 47 | for(i=0;i<nummodels;i++)m_nodesets[i]=NULL;
|
---|
| 48 | for(i=0;i<nummodels;i++)m_yg[i]=NULL;
|
---|
| 49 | for(i=0;i<nummodels;i++)m_ys[i]=NULL;
|
---|
[3982] | 50 |
|
---|
[4063] | 51 | /*create datasets for all analyses: */
|
---|
| 52 | ModelProcessorx(&this->elements,&this->nodes,&this->vertices,&this->materials,&this->constraints,&this->loads,&this->parameters,IOMODEL,this->solution_type,nummodels,analyses);
|
---|
[4004] | 53 |
|
---|
[4063] | 54 | /*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
|
---|
[4004] | 55 | for(i=0;i<nummodels;i++){
|
---|
| 56 |
|
---|
[4122] | 57 | _printf_(" processing finite element model of analysis %s:\n",EnumAsString(analysis_type_list[i]));
|
---|
[4004] | 58 | analysis_type=analysis_type_list[i];
|
---|
[4122] | 59 | this->SetCurrentAnalysis(analysis_type);
|
---|
[4004] | 60 |
|
---|
[4117] | 61 | _printf_(" create degrees of freedom\n");
|
---|
[4004] | 62 | VerticesDofx( &partition,&tpartition,vertices,parameters);
|
---|
[4009] | 63 | NodesDofx(nodes,parameters);
|
---|
[4004] | 64 |
|
---|
[4117] | 65 | _printf_(" create single point constraints\n");
|
---|
[4055] | 66 | SpcNodesx( &m_yg[i], nodes,constraints,analysis_type);
|
---|
[4004] | 67 |
|
---|
[4117] | 68 | _printf_(" create rigid body constraints\n");
|
---|
[4055] | 69 | MpcNodesx( &m_Rmg[i], nodes,constraints,analysis_type);
|
---|
[4004] | 70 |
|
---|
[4117] | 71 | _printf_(" create node sets\n");
|
---|
[4055] | 72 | BuildNodeSetsx(&m_nodesets[i], nodes,analysis_type);
|
---|
[4004] | 73 |
|
---|
[4117] | 74 | _printf_(" reducing single point constraints vector\n");
|
---|
[4055] | 75 | Reducevectorgtosx(&m_ys[i], m_yg[i],m_nodesets[i]);
|
---|
[4004] | 76 |
|
---|
[4117] | 77 | _printf_(" normalizing rigid body constraints matrix\n");
|
---|
[4055] | 78 | NormalizeConstraintsx(&m_Gmn[i], m_Rmg[i],m_nodesets[i]);
|
---|
[4004] | 79 |
|
---|
[4117] | 80 | _printf_(" configuring element and loads\n");
|
---|
[4034] | 81 | ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
|
---|
[4004] | 82 | }
|
---|
[1881] | 83 | }
|
---|
[3982] | 84 | /*}}}1*/
|
---|
| 85 | /*FUNCTION FemModel::destructor {{{1*/
|
---|
[1881] | 86 | FemModel::~FemModel(){
|
---|
| 87 |
|
---|
[4001] | 88 | /*Intermediary*/
|
---|
[3982] | 89 | int i;
|
---|
| 90 |
|
---|
| 91 | /*Delete all the datasets: */
|
---|
| 92 | xfree((void**)&analysis_type_list);
|
---|
[1881] | 93 | delete elements;
|
---|
| 94 | delete nodes;
|
---|
[3417] | 95 | delete vertices;
|
---|
[3982] | 96 | delete constraints;
|
---|
[1881] | 97 | delete loads;
|
---|
| 98 | delete materials;
|
---|
| 99 | delete parameters;
|
---|
[4050] | 100 | delete results;
|
---|
[2316] | 101 | delete partition;
|
---|
| 102 | delete tpartition;
|
---|
[3982] | 103 |
|
---|
| 104 | for(i=0;i<nummodels;i++){
|
---|
[4055] | 105 | Mat temp_Rmg=m_Rmg[i];
|
---|
[3982] | 106 | MatFree(&temp_Rmg);
|
---|
[4055] | 107 | Mat temp_Gmn=m_Gmn[i];
|
---|
[3982] | 108 | MatFree(&temp_Gmn);
|
---|
[4055] | 109 | NodeSets* temp_nodesets=m_nodesets[i];
|
---|
| 110 | delete temp_nodesets;
|
---|
| 111 | Vec temp_yg=m_yg[i];
|
---|
[3982] | 112 | VecFree(&temp_yg);
|
---|
[4055] | 113 | Vec temp_ys=m_ys[i];
|
---|
[3982] | 114 | VecFree(&temp_ys);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | /*Delete dynamically allocated arrays: */
|
---|
[4055] | 118 | delete m_Rmg;
|
---|
| 119 | delete m_Gmn;
|
---|
| 120 | delete m_nodesets;
|
---|
| 121 | delete m_yg;
|
---|
| 122 | delete m_ys;
|
---|
[1881] | 123 |
|
---|
| 124 | }
|
---|
[3982] | 125 | /*}}}1*/
|
---|
| 126 |
|
---|
| 127 | /*Object management*/
|
---|
| 128 | /*FUNCTION FemModel::Echo {{{1*/
|
---|
| 129 | void FemModel::Echo(void){
|
---|
| 130 |
|
---|
| 131 | printf("FemModel echo: \n");
|
---|
| 132 | printf(" number of fem models: %i\n",nummodels);
|
---|
| 133 | printf(" analysis_type_list: \n");
|
---|
[4001] | 134 | for(int i=0;i<nummodels;i++)printf(" %i: %s\n",i,EnumAsString(analysis_type_list[i]));
|
---|
[3982] | 135 | printf(" current analysis_type: \n");
|
---|
[4001] | 136 | printf(" %i: %s\n",analysis_counter,EnumAsString(analysis_type_list[analysis_counter]));
|
---|
[3982] | 137 |
|
---|
| 138 |
|
---|
| 139 | }
|
---|
[4001] | 140 | /*}}}*/
|
---|
[3982] | 141 |
|
---|
| 142 | /*Numerics: */
|
---|
| 143 | /*FUNCTION FemModel::GetCurrentAnalysis {{{1*/
|
---|
[4001] | 144 | int FemModel::GetCurrentAnalysis(){
|
---|
[3984] | 145 | return analysis_type_list[analysis_counter];
|
---|
[3982] | 146 | }
|
---|
| 147 | /*}}}1*/
|
---|
| 148 | /*FUNCTION FemModel::SetCurrentAnalysis {{{1*/
|
---|
| 149 | void FemModel::SetCurrentAnalysis(int analysis_type){
|
---|
[4055] | 150 |
|
---|
[3982] | 151 | int found=-1;
|
---|
[4001] | 152 | for(int i=0;i<nummodels;i++){
|
---|
[3982] | 153 | if (analysis_type_list[i]==analysis_type){
|
---|
| 154 | found=i;
|
---|
| 155 | break;
|
---|
| 156 | }
|
---|
| 157 | }
|
---|
[4001] | 158 | if(found!=-1) analysis_counter=found;
|
---|
| 159 | else ISSMERROR("Could not find analysis_type %s in list of FemModel analyses",EnumAsString(analysis_type));
|
---|
[4055] | 160 |
|
---|
| 161 | /*activate matrices/vectors: */
|
---|
| 162 | Rmg=m_Rmg[analysis_counter];
|
---|
| 163 | Gmn=m_Gmn[analysis_counter];
|
---|
| 164 | nodesets=m_nodesets[analysis_counter];
|
---|
| 165 | yg=m_yg[analysis_counter];
|
---|
| 166 | ys=m_ys[analysis_counter];
|
---|
| 167 |
|
---|
[4059] | 168 | /*Now, plug analysis_counter and analysis_type inside the parameters: */
|
---|
| 169 | this->parameters->SetParam(analysis_counter,AnalysisCounterEnum);
|
---|
| 170 | this->parameters->SetParam(analysis_type,AnalysisTypeEnum);
|
---|
[3982] | 171 | }
|
---|
| 172 | /*}}}1*/
|
---|
[4055] | 173 | /*FUNCTION FemModel::SetCurrentAnalysisAlias {{{1*/
|
---|
| 174 | void FemModel::SetCurrentAnalysisAlias(int base_analysis_type,int real_analysis_type){
|
---|
[4059] | 175 |
|
---|
| 176 | /*Use base_analysis_type to setup the analysis counter, but the analysis type of the FemModel will remain
|
---|
| 177 | * real_analysis_type. This means we are using the base_analysis_type settings to run a similar, compatible
|
---|
| 178 | * analysis called real_analysis_type: */
|
---|
| 179 |
|
---|
[4055] | 180 | int found=-1;
|
---|
| 181 | for(int i=0;i<nummodels;i++){
|
---|
| 182 | if (analysis_type_list[i]==base_analysis_type){
|
---|
| 183 | found=i;
|
---|
| 184 | break;
|
---|
| 185 | }
|
---|
| 186 | }
|
---|
| 187 | if(found!=-1) analysis_counter=found;
|
---|
| 188 | else ISSMERROR("Could not find alias for analysis_type %s in list of FemModel analyses",EnumAsString(base_analysis_type));
|
---|
[4059] | 189 |
|
---|
| 190 | /*activate matrices/vectors: */
|
---|
| 191 | Rmg=m_Rmg[analysis_counter];
|
---|
| 192 | Gmn=m_Gmn[analysis_counter];
|
---|
| 193 | nodesets=m_nodesets[analysis_counter];
|
---|
| 194 | yg=m_yg[analysis_counter];
|
---|
| 195 | ys=m_ys[analysis_counter];
|
---|
| 196 |
|
---|
| 197 | /*Now, plug analysis_counter and real_analysis_type inside the parameters: */
|
---|
| 198 | this->parameters->SetParam(analysis_counter,AnalysisCounterEnum);
|
---|
| 199 | this->parameters->SetParam(real_analysis_type,AnalysisTypeEnum);
|
---|
[4055] | 200 | }
|
---|
| 201 | /*}}}1*/
|
---|