1 | /*
|
---|
2 | * \file Constraints.c
|
---|
3 | * \brief: implementation of the Constraints class, derived from DataSet class
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*Headers: {{{1*/
|
---|
7 | #ifdef HAVE_CONFIG_H
|
---|
8 | #include "config.h"
|
---|
9 | #else
|
---|
10 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
11 | #endif
|
---|
12 |
|
---|
13 | #include <vector>
|
---|
14 | #include <functional>
|
---|
15 | #include <algorithm>
|
---|
16 | #include <iostream>
|
---|
17 |
|
---|
18 | #include "./DataSet.h"
|
---|
19 | #include "../shared/shared.h"
|
---|
20 | #include "../include/include.h"
|
---|
21 | #include "../EnumDefinitions/EnumDefinitions.h"
|
---|
22 |
|
---|
23 | using namespace std;
|
---|
24 | /*}}}*/
|
---|
25 |
|
---|
26 | /*Object constructors and destructor*/
|
---|
27 | /*FUNCTION Constraints::Constraints(){{{1*/
|
---|
28 | Constraints::Constraints(){
|
---|
29 | return;
|
---|
30 | }
|
---|
31 | /*}}}*/
|
---|
32 | /*FUNCTION Constraints::Constraints(int in_enum){{{1*/
|
---|
33 | Constraints::Constraints(int in_enum): DataSet(in_enum){
|
---|
34 | //do nothing;
|
---|
35 | return;
|
---|
36 | }
|
---|
37 | /*}}}*/
|
---|
38 | /*FUNCTION Constraints::~Constraints(){{{1*/
|
---|
39 | Constraints::~Constraints(){
|
---|
40 | return;
|
---|
41 | }
|
---|
42 | /*}}}*/
|
---|
43 |
|
---|
44 | /*Numerics: */
|
---|
45 | /*FUNCTION Constraints::NumberOfConstraints{{{1*/
|
---|
46 | int Constraints::NumberOfConstraints(void){
|
---|
47 |
|
---|
48 | int localconstraints;
|
---|
49 | int numberofconstraints;
|
---|
50 |
|
---|
51 | /*Get number of local constraints*/
|
---|
52 | localconstraints=this->Size();
|
---|
53 |
|
---|
54 | /*figure out total number of constraints combining all the cpus (no clones here)*/
|
---|
55 | #ifdef _PARALLEL_
|
---|
56 | MPI_Reduce(&localconstraints,&numberofconstraints,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
|
---|
57 | MPI_Bcast(&numberofconstraints,1,MPI_INT,0,MPI_COMM_WORLD);
|
---|
58 | #else
|
---|
59 | numberofconstraints=localconstraints;
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | return numberofconstraints;
|
---|
63 | }
|
---|
64 | /*}}}*/
|
---|
65 | /*FUNCTION Constraints::SetupSpcs{{{1*/
|
---|
66 | void Constraints::SetupSpcs(Nodes* nodes,Vec yg,int analysis_type){
|
---|
67 |
|
---|
68 | int i;
|
---|
69 |
|
---|
70 | Node* node=NULL;
|
---|
71 | int nodeid;
|
---|
72 | int dof;
|
---|
73 | double value;
|
---|
74 |
|
---|
75 | for(i=0;i<this->Size();i++){
|
---|
76 |
|
---|
77 | Object* object=(Object*)this->GetObjectByOffset(i);
|
---|
78 |
|
---|
79 | /*Check this is a single point constraint (spc): */
|
---|
80 | if(object->Enum()==SpcEnum){
|
---|
81 |
|
---|
82 | Spc* spc=(Spc*)object;
|
---|
83 |
|
---|
84 | if(spc->InAnalysis(analysis_type)){
|
---|
85 |
|
---|
86 | /*Ok, this object is a constraint. Get the nodeid from the node it applies to: */
|
---|
87 | nodeid=spc->GetNodeId();
|
---|
88 | dof=spc->GetDof();
|
---|
89 | value=spc->GetValue();
|
---|
90 |
|
---|
91 | /*Now, chase through nodes and find the corect node: */
|
---|
92 | node=(Node*)nodes->GetObjectById(NULL,nodeid);
|
---|
93 |
|
---|
94 | /*Apply constraint: */
|
---|
95 | if(node){ //in case the spc is dealing with a node on another cpu
|
---|
96 | node->ApplyConstraint(yg,dof,value);
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | /*Assemble yg: */
|
---|
104 | VecAssemblyBegin(yg);
|
---|
105 | VecAssemblyEnd(yg);
|
---|
106 | }
|
---|
107 | /*}}}*/
|
---|