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