-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathcrvBezierFields.cc
136 lines (117 loc) · 3.84 KB
/
crvBezierFields.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Copyright 2015 Scientific Computation Research Center
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
*/
#include "crv.h"
#include "crvBezier.h"
#include "crvBezierShapes.h"
#include "crvMath.h"
#include "crvShape.h"
#include "crvTables.h"
#include "crvQuality.h"
#include <apfField.h>
#include <lionPrint.h>
#include <cstdlib>
#include <mth_def.h>
#include <iostream>
#include <pcu_util.h>
namespace crv {
static void convertVectorFieldInterpolationPoints(int n, int ne,
apf::NewArray<apf::Vector3>& nodes,
apf::NewArray<double>& c,
apf::NewArray<apf::Vector3>& newNodes){
for(int i = 0; i < ne; ++i)
newNodes[i].zero();
for( int i = 0; i < ne; ++i)
for( int j = 0; j < n; ++j)
newNodes[i] += nodes[j]*c[i*n+j];
}
static void convertScalarFieldInterpolationPoints(int n, int ne,
apf::NewArray<double>& nodes,
apf::NewArray<double>& c,
apf::NewArray<double>& newNodes)
{
for(int i = 0; i < ne; ++i)
newNodes[i] = 0.;
for( int i = 0; i < ne; ++i)
for( int j = 0; j < n; ++j)
newNodes[i] += nodes[j]*c[i*n+j];
}
void convertInterpolationFieldPoints(apf::MeshEntity* e,
apf::Field* f,
int n, int ne, apf::NewArray<double>& c)
{
apf::NewArray<apf::Vector3> l, b(ne);
apf::NewArray<double> ls, bs(ne);
apf::MeshElement* me =
apf::createMeshElement(f->getMesh(),e);
apf::Element* elem =
apf::createElement(f,me);
if (apf::getValueType(f) == apf::VECTOR) {
apf::getVectorNodes(elem,l);
convertVectorFieldInterpolationPoints(n, ne, l, c, b);
for(int i = 0; i < ne; ++i)
apf::setVector(f, e, i, b[i]);
}
else if (apf::getValueType(f) == apf::SCALAR) {
apf::getScalarNodes(elem, ls);
convertScalarFieldInterpolationPoints(n, ne, ls, c, bs);
for(int i = 0; i < ne; ++i)
apf::setScalar(f, e, i, bs[i]);
}
else
printf("Field type not implemented\n");
apf::destroyElement(elem);
apf::destroyMeshElement(me);
}
void convertInterpolatingFieldToBezier(apf::Mesh2* m_mesh, apf::Field* f)
{
apf::FieldShape * fs = apf::getShape(f);
int order = fs->getOrder();
//apf::Field* fnew = createField(
// m_mesh, "copy_field", apf::getValueType(f), crv::getBezier(order));
//transferFields(m_mesh, f, fnew);
int md = m_mesh->getDimension();
//
int blendingOrder = getBlendingOrder(apf::Mesh::simplexTypes[md]);
//blendingOrder = 0;
// go downward, and convert interpolating to control points
int startDim = md - (blendingOrder > 0);
for(int d = startDim; d >= 1; --d){
if(!fs->hasNodesIn(d)) continue;
int n = fs->getEntityShape(apf::Mesh::simplexTypes[d])->countNodes();
int ne = fs->countNodesOn(apf::Mesh::simplexTypes[d]);
apf::NewArray<double> c;
getBezierTransformationCoefficients(order,
apf::Mesh::simplexTypes[d],c);
apf::MeshEntity* e;
apf::MeshIterator* it = m_mesh->begin(d);
while ((e = m_mesh->iterate(it))){
if(m_mesh->isOwned(e))
convertInterpolationFieldPoints(e,f,n,ne,c);
}
m_mesh->end(it);
}
for( int d = 2; d <= md; ++d){
std::cout<<" blendingorder of dimension "<<d <<" "<<
getBlendingOrder(apf::Mesh::simplexTypes[d])<<std::endl;
if(!fs->hasNodesIn(d) ||
!getBlendingOrder(apf::Mesh::simplexTypes[d])) continue;
int n = fs->getEntityShape(apf::Mesh::simplexTypes[d])->countNodes();
int ne = fs->countNodesOn(apf::Mesh::simplexTypes[d]);
apf::NewArray<double> c;
getInternalBezierTransformationCoefficients(m_mesh,order,1,
apf::Mesh::simplexTypes[d],c);
apf::MeshEntity* e;
apf::MeshIterator* it = m_mesh->begin(d);
while ((e = m_mesh->iterate(it))){
if(!isBoundaryEntity(m_mesh,e) && m_mesh->isOwned(e))
convertInterpolationFieldPoints(e,f,n-ne,ne,c);
}
m_mesh->end(it);
}
apf::synchronize(f);
}
}