source: issm/trunk/src/c/objects/FemModel.cpp@ 4122

Last change on this file since 4122 was 4122, checked in by Mathieu Morlighem, 15 years ago

Fixed counter problem in diagnostic horiz and updated elements/loads as sub_analysis is not used anymore

File size: 6.1 KB
Line 
1/*!\file FemModel.c
2 * \brief: implementation of the FemModel 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 "../DataSet/DataSet.h"
14#include "../modules/ModelProcessorx/ModelProcessorx.h"
15#include "./objects.h"
16#include "../include/include.h"
17#include "../EnumDefinitions/EnumDefinitions.h"
18#include "../modules/modules.h"
19
20/*Object constructors and destructor*/
21/*FUNCTION FemModel::constructor {{{1*/
22FemModel::FemModel(ConstDataHandle IOMODEL,int in_solution_type,int* analyses, int nummodels){
23
24 /*intermediary*/
25 int i;
26 IoModel* iomodel=NULL;
27 int analysis_type;
28
29 /*Initialize internal data: */
30 this->nummodels=nummodels;
31 this->solution_type=in_solution_type;
32 this->analysis_counter=nummodels-1; //point to last analysis_type carried out.
33 this->results=new DataSet(); //not initialized by CreateDataSets
34
35 /*Dynamically allocate whatever is a list of length nummodels: */
36 analysis_type_list=(int*)xmalloc(nummodels*sizeof(int));
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));
42
43 /*Initialize: */
44 for(i=0;i<nummodels;i++)analysis_type_list[i]=analyses[i];
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;
50
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);
53
54 /*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
55 for(i=0;i<nummodels;i++){
56
57 _printf_(" processing finite element model of analysis %s:\n",EnumAsString(analysis_type_list[i]));
58 analysis_type=analysis_type_list[i];
59 this->SetCurrentAnalysis(analysis_type);
60
61 _printf_(" create degrees of freedom\n");
62 VerticesDofx( &partition,&tpartition,vertices,parameters);
63 NodesDofx(nodes,parameters);
64
65 _printf_(" create single point constraints\n");
66 SpcNodesx( &m_yg[i], nodes,constraints,analysis_type);
67
68 _printf_(" create rigid body constraints\n");
69 MpcNodesx( &m_Rmg[i], nodes,constraints,analysis_type);
70
71 _printf_(" create node sets\n");
72 BuildNodeSetsx(&m_nodesets[i], nodes,analysis_type);
73
74 _printf_(" reducing single point constraints vector\n");
75 Reducevectorgtosx(&m_ys[i], m_yg[i],m_nodesets[i]);
76
77 _printf_(" normalizing rigid body constraints matrix\n");
78 NormalizeConstraintsx(&m_Gmn[i], m_Rmg[i],m_nodesets[i]);
79
80 _printf_(" configuring element and loads\n");
81 ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
82 }
83}
84/*}}}1*/
85/*FUNCTION FemModel::destructor {{{1*/
86FemModel::~FemModel(){
87
88 /*Intermediary*/
89 int i;
90
91 /*Delete all the datasets: */
92 xfree((void**)&analysis_type_list);
93 delete elements;
94 delete nodes;
95 delete vertices;
96 delete constraints;
97 delete loads;
98 delete materials;
99 delete parameters;
100 delete results;
101 delete partition;
102 delete tpartition;
103
104 for(i=0;i<nummodels;i++){
105 Mat temp_Rmg=m_Rmg[i];
106 MatFree(&temp_Rmg);
107 Mat temp_Gmn=m_Gmn[i];
108 MatFree(&temp_Gmn);
109 NodeSets* temp_nodesets=m_nodesets[i];
110 delete temp_nodesets;
111 Vec temp_yg=m_yg[i];
112 VecFree(&temp_yg);
113 Vec temp_ys=m_ys[i];
114 VecFree(&temp_ys);
115 }
116
117 /*Delete dynamically allocated arrays: */
118 delete m_Rmg;
119 delete m_Gmn;
120 delete m_nodesets;
121 delete m_yg;
122 delete m_ys;
123
124}
125/*}}}1*/
126
127/*Object management*/
128/*FUNCTION FemModel::Echo {{{1*/
129void FemModel::Echo(void){
130
131 printf("FemModel echo: \n");
132 printf(" number of fem models: %i\n",nummodels);
133 printf(" analysis_type_list: \n");
134 for(int i=0;i<nummodels;i++)printf(" %i: %s\n",i,EnumAsString(analysis_type_list[i]));
135 printf(" current analysis_type: \n");
136 printf(" %i: %s\n",analysis_counter,EnumAsString(analysis_type_list[analysis_counter]));
137
138
139}
140/*}}}*/
141
142/*Numerics: */
143/*FUNCTION FemModel::GetCurrentAnalysis {{{1*/
144int FemModel::GetCurrentAnalysis(){
145 return analysis_type_list[analysis_counter];
146}
147/*}}}1*/
148/*FUNCTION FemModel::SetCurrentAnalysis {{{1*/
149void FemModel::SetCurrentAnalysis(int analysis_type){
150
151 int found=-1;
152 for(int i=0;i<nummodels;i++){
153 if (analysis_type_list[i]==analysis_type){
154 found=i;
155 break;
156 }
157 }
158 if(found!=-1) analysis_counter=found;
159 else ISSMERROR("Could not find analysis_type %s in list of FemModel analyses",EnumAsString(analysis_type));
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
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);
171}
172/*}}}1*/
173/*FUNCTION FemModel::SetCurrentAnalysisAlias {{{1*/
174void FemModel::SetCurrentAnalysisAlias(int base_analysis_type,int real_analysis_type){
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
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));
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);
200}
201/*}}}1*/
Note: See TracBrowser for help on using the repository browser.