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