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

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

Renamed DuplicateInput to InputDuplicate

File size: 5.9 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 analysis_type=analysis_type_list[i];
58
59 _printf_(" create degrees of freedom: \n");
60 VerticesDofx( &partition,&tpartition,vertices,parameters);
61 NodesDofx(nodes,parameters);
62
63 _printf_(" create single point constraints: \n");
64 SpcNodesx( &m_yg[i], nodes,constraints,analysis_type);
65
66 _printf_(" create rigid body constraints:\n");
67 MpcNodesx( &m_Rmg[i], nodes,constraints,analysis_type);
68
69 _printf_(" create node sets:\n");
70 BuildNodeSetsx(&m_nodesets[i], nodes,analysis_type);
71
72 _printf_(" reducing single point constraints vector:\n");
73 Reducevectorgtosx(&m_ys[i], m_yg[i],m_nodesets[i]);
74
75 _printf_(" normalizing rigid body constraints matrix:\n");
76 NormalizeConstraintsx(&m_Gmn[i], m_Rmg[i],m_nodesets[i]);
77
78 _printf_(" configuring element and loads:\n");
79 ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
80 }
81}
82/*}}}1*/
83/*FUNCTION FemModel::destructor {{{1*/
84FemModel::~FemModel(){
85
86 /*Intermediary*/
87 int i;
88
89 /*Delete all the datasets: */
90 xfree((void**)&analysis_type_list);
91 delete elements;
92 delete nodes;
93 delete vertices;
94 delete constraints;
95 delete loads;
96 delete materials;
97 delete parameters;
98 delete results;
99 delete partition;
100 delete tpartition;
101
102 for(i=0;i<nummodels;i++){
103 Mat temp_Rmg=m_Rmg[i];
104 MatFree(&temp_Rmg);
105 Mat temp_Gmn=m_Gmn[i];
106 MatFree(&temp_Gmn);
107 NodeSets* temp_nodesets=m_nodesets[i];
108 delete temp_nodesets;
109 Vec temp_yg=m_yg[i];
110 VecFree(&temp_yg);
111 Vec temp_ys=m_ys[i];
112 VecFree(&temp_ys);
113 }
114
115 /*Delete dynamically allocated arrays: */
116 delete m_Rmg;
117 delete m_Gmn;
118 delete m_nodesets;
119 delete m_yg;
120 delete m_ys;
121
122}
123/*}}}1*/
124
125/*Object management*/
126/*FUNCTION FemModel::Echo {{{1*/
127void FemModel::Echo(void){
128
129 printf("FemModel echo: \n");
130 printf(" number of fem models: %i\n",nummodels);
131 printf(" analysis_type_list: \n");
132 for(int i=0;i<nummodels;i++)printf(" %i: %s\n",i,EnumAsString(analysis_type_list[i]));
133 printf(" current analysis_type: \n");
134 printf(" %i: %s\n",analysis_counter,EnumAsString(analysis_type_list[analysis_counter]));
135
136
137}
138/*}}}*/
139
140/*Numerics: */
141/*FUNCTION FemModel::GetCurrentAnalysis {{{1*/
142int FemModel::GetCurrentAnalysis(){
143 return analysis_type_list[analysis_counter];
144}
145/*}}}1*/
146/*FUNCTION FemModel::SetCurrentAnalysis {{{1*/
147void FemModel::SetCurrentAnalysis(int analysis_type){
148
149 int found=-1;
150 for(int i=0;i<nummodels;i++){
151 if (analysis_type_list[i]==analysis_type){
152 found=i;
153 break;
154 }
155 }
156 if(found!=-1) analysis_counter=found;
157 else ISSMERROR("Could not find analysis_type %s in list of FemModel analyses",EnumAsString(analysis_type));
158
159 /*activate matrices/vectors: */
160 Rmg=m_Rmg[analysis_counter];
161 Gmn=m_Gmn[analysis_counter];
162 nodesets=m_nodesets[analysis_counter];
163 yg=m_yg[analysis_counter];
164 ys=m_ys[analysis_counter];
165
166 /*Now, plug analysis_counter and analysis_type inside the parameters: */
167 this->parameters->SetParam(analysis_counter,AnalysisCounterEnum);
168 this->parameters->SetParam(analysis_type,AnalysisTypeEnum);
169}
170/*}}}1*/
171/*FUNCTION FemModel::SetCurrentAnalysisAlias {{{1*/
172void FemModel::SetCurrentAnalysisAlias(int base_analysis_type,int real_analysis_type){
173
174 /*Use base_analysis_type to setup the analysis counter, but the analysis type of the FemModel will remain
175 * real_analysis_type. This means we are using the base_analysis_type settings to run a similar, compatible
176 * analysis called real_analysis_type: */
177
178 int found=-1;
179 for(int i=0;i<nummodels;i++){
180 if (analysis_type_list[i]==base_analysis_type){
181 found=i;
182 break;
183 }
184 }
185 if(found!=-1) analysis_counter=found;
186 else ISSMERROR("Could not find alias for analysis_type %s in list of FemModel analyses",EnumAsString(base_analysis_type));
187
188 /*activate matrices/vectors: */
189 Rmg=m_Rmg[analysis_counter];
190 Gmn=m_Gmn[analysis_counter];
191 nodesets=m_nodesets[analysis_counter];
192 yg=m_yg[analysis_counter];
193 ys=m_ys[analysis_counter];
194
195 /*Now, plug analysis_counter and real_analysis_type inside the parameters: */
196 this->parameters->SetParam(analysis_counter,AnalysisCounterEnum);
197 this->parameters->SetParam(real_analysis_type,AnalysisTypeEnum);
198}
199/*}}}1*/
Note: See TracBrowser for help on using the repository browser.