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

Last change on this file since 12330 was 12330, checked in by Mathieu Morlighem, 13 years ago

merged trunk-jpl and trunk for revision 12326M

File size: 5.4 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 "../Container/Container.h"
14#include "../modules/ModelProcessorx/ModelProcessorx.h"
15#include "../io/io.h"
16#include "./objects.h"
17#include "../include/include.h"
18#include "../EnumDefinitions/EnumDefinitions.h"
19#include "../modules/modules.h"
20
21/*Object constructors and destructor*/
22/*FUNCTION FemModel::constructor {{{1*/
23FemModel::FemModel(char* inputfilename, char* outputfilename, const int in_solution_type,const int* analyses,const int nummodels){
24
25 /*intermediary*/
26 int i;
27 int analysis_type;
28 FILE* IOMODEL;
29 extern int my_rank;
30
31 /*Open input file on cpu 0: */
32 if(my_rank==0) IOMODEL= pfopen(inputfilename ,"rb");
33
34 /*Initialize internal data: */
35 this->nummodels=nummodels;
36 this->solution_type=in_solution_type;
37 this->analysis_counter=nummodels-1; //point to last analysis_type carried out.
38 this->results=new Results(); //not initialized by CreateDataSets
39
40 /*Dynamically allocate whatever is a list of length nummodels: */
41 analysis_type_list=(int*)xmalloc(nummodels*sizeof(int));
42
43 /*Initialize: */
44 for(i=0;i<nummodels;i++)analysis_type_list[i]=analyses[i];
45
46 /*create datasets for all analyses*/
47 ModelProcessorx(&this->elements,&this->nodes,&this->vertices,&this->materials,&this->constraints,&this->loads,&this->parameters,IOMODEL,this->solution_type,nummodels,analyses);
48
49 /*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
50 for(i=0;i<nummodels;i++){
51
52 _printf_(VerboseMProcessor()," Processing finite element model of analysis %s:\n",EnumToStringx(analysis_type_list[i]));
53 analysis_type=analysis_type_list[i];
54 this->SetCurrentConfiguration(analysis_type);
55
56 if(i==0){
57 _printf_(VerboseMProcessor()," creating vertex degrees of freedom\n");
58 VerticesDofx(vertices,parameters); //only call once, we only have one set of vertices
59 }
60
61 _printf_(VerboseMProcessor()," resolving node constraints\n");
62 SpcNodesx(nodes,constraints,parameters,analysis_type);
63
64 _printf_(VerboseMProcessor()," creating nodal degrees of freedom\n");
65 NodesDofx(nodes,parameters,analysis_type);
66
67 _printf_(VerboseMProcessor()," configuring element and loads\n");
68 ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
69 }
70
71 /*Close input file descriptors: */
72 if(my_rank==0) pfclose(IOMODEL,inputfilename);
73
74 /*Add output file name to parameters: */
75 this->parameters->AddObject(new StringParam(OutputfilenameEnum,outputfilename));
76
77}
78
79/*}}}1*/
80/*FUNCTION FemModel::destructor {{{1*/
81FemModel::~FemModel(){
82
83 /*Intermediary*/
84 int i;
85
86 /*Delete all the datasets: */
87 xfree((void**)&analysis_type_list);
88 delete elements;
89 delete nodes;
90 delete vertices;
91 delete constraints;
92 delete loads;
93 delete materials;
94 delete parameters;
95 delete results;
96
97}
98/*}}}1*/
99
100/*Object management*/
101/*FUNCTION FemModel::Echo {{{1*/
102void FemModel::Echo(void){
103
104 printf("FemModel echo: \n");
105 printf(" number of fem models: %i\n",nummodels);
106 printf(" analysis_type_list: \n");
107 for(int i=0;i<nummodels;i++)printf(" %i: %s\n",i,EnumToStringx(analysis_type_list[i]));
108 printf(" current analysis_type: \n");
109 printf(" %i: %s\n",analysis_counter,EnumToStringx(analysis_type_list[analysis_counter]));
110
111}
112/*}}}*/
113
114/*Numerics: */
115/*FUNCTION FemModel::SetCurrentConfiguration(int configuration_type,int analysis_type){{{1*/
116void FemModel::SetCurrentConfiguration(int configuration_type,int analysis_type){
117
118 /*Use configuration_type to setup the analysis counter, the configurations of objects etc ... but use
119 * analysis_type to drive the element numerics. This allows for use of 1 configuration_type for several
120 * analyses. For example: do a SurfaceSlopeX, SurfaceSlopeY, BedSlopeX and BedSlopeY analysis using the
121 * Slope configuration.*/
122
123 int found=-1;
124 for(int i=0;i<nummodels;i++){
125 if (analysis_type_list[i]==configuration_type){
126 found=i;
127 break;
128 }
129 }
130 if(found!=-1) analysis_counter=found;
131 else _error_("Could not find alias for analysis_type %s in list of FemModel analyses",EnumToStringx(configuration_type));
132
133 /*Now, plug analysis_counter and analysis_type inside the parameters: */
134 this->parameters->SetParam(analysis_counter,AnalysisCounterEnum);
135 this->parameters->SetParam(analysis_type,AnalysisTypeEnum);
136 this->parameters->SetParam(configuration_type,ConfigurationTypeEnum);
137
138 /*configure elements, loads and nodes, for this new analysis: */
139 this->elements->SetCurrentConfiguration(elements,loads, nodes,vertices, materials,parameters);
140 this->nodes->SetCurrentConfiguration(elements,loads, nodes,vertices, materials,parameters);
141 this->loads->SetCurrentConfiguration(elements, loads, nodes,vertices, materials,parameters);
142
143 #ifdef _HAVE_PETSC_
144 /*take care of petsc options, that depend on this analysis type (present only after model processor)*/
145 if(this->parameters->Exist(PetscOptionsStringsEnum)){
146 PetscOptionsFromAnalysis(this->parameters,analysis_type);
147 _printf_(VerboseSolver()," petsc Options set for analysis type: %s\n",EnumToStringx(analysis_type));
148 }
149 #endif
150
151}
152/*}}}1*/
153/*FUNCTION FemModel::SetCurrentConfiguration(int configuration_type){{{1*/
154void FemModel::SetCurrentConfiguration(int configuration_type){
155
156 /*overload: analysis_type = configuration_type: */
157 this->SetCurrentConfiguration(configuration_type,configuration_type);
158}
159/*}}}1*/
Note: See TracBrowser for help on using the repository browser.