Skip to content

Commit

Permalink
More work on FEM code
Browse files Browse the repository at this point in the history
Now I'm ready to write the 3D Q1 element code.
  • Loading branch information
ckhroulev committed Oct 14, 2020
1 parent 859054c commit bf3cc68
Show file tree
Hide file tree
Showing 11 changed files with 330 additions and 176 deletions.
2 changes: 1 addition & 1 deletion src/inverse/functional/IPGroundedIceH1NormFunctional.cc
Expand Up @@ -202,7 +202,7 @@ void IPGroundedIceH1NormFunctional2S::gradientAt(IceModelVec2S &x, IceModelVec2S
m_cH1*(dxdx_qq*m_element.chi(q, k).dx + dxdy_qq*m_element.chi(q, k).dy));
} // k
} // q
m_element.add_contribution(gradient_e, gradient);
m_element.add_contribution(gradient_e, gradient.array());
} // j
} // i
}
Expand Down
2 changes: 1 addition & 1 deletion src/inverse/functional/IPTotalVariationFunctional.cc
Expand Up @@ -126,7 +126,7 @@ void IPTotalVariationFunctional2S::gradientAt(IceModelVec2S &x, IceModelVec2S &g
*(dxdx_qq*m_element.chi(q, k).dx + dxdy_qq*m_element.chi(q, k).dy);
} // k
} // q
m_element.add_contribution(gradient_e, gradient);
m_element.add_contribution(gradient_e, gradient.array());
} // j
} // i
}
Expand Down
2 changes: 1 addition & 1 deletion src/inverse/functional/IP_H1NormFunctional.cc
Expand Up @@ -174,7 +174,7 @@ void IP_H1NormFunctional2S::gradientAt(IceModelVec2S &x, IceModelVec2S &gradient
m_cH1*(dxdx_qq*m_element.chi(q, k).dx + dxdy_qq*m_element.chi(q, k).dy));
} // k
} // q
m_element.add_contribution(gradient_e, gradient);
m_element.add_contribution(gradient_e, gradient.array());
} // j
} // i
}
Expand Down
4 changes: 2 additions & 2 deletions src/inverse/functional/IP_L2NormFunctional.cc
Expand Up @@ -147,7 +147,7 @@ void IP_L2NormFunctional2S::gradientAt(IceModelVec2S &x, IceModelVec2S &gradient
gradient_e[k] += 2*W*x_qq*m_element.chi(q, k).val;
} // k
} // q
m_element.add_contribution(gradient_e, gradient);
m_element.add_contribution(gradient_e, gradient.array());
} // j
} // i
}
Expand Down Expand Up @@ -279,7 +279,7 @@ void IP_L2NormFunctional2V::gradientAt(IceModelVec2V &x, IceModelVec2V &gradient
gradient_e[k].v += gcommon*x_qq.v;
} // k
} // q
m_element.add_contribution(gradient_e, gradient);
m_element.add_contribution(gradient_e, gradient.array());
} // j
} // i
}
Expand Down
8 changes: 4 additions & 4 deletions src/stressbalance/ssa/SSAFEM.cc
Expand Up @@ -616,7 +616,7 @@ void SSAFEM::cache_residual_cfbc(const Inputs &inputs) {
int node_type[Nk];
m_q1_element.nodal_values(m_node_type, node_type);

fem::Element *E = nullptr;
fem::Element2 *E = nullptr;
{
auto type = fem::element_type(node_type);

Expand Down Expand Up @@ -708,7 +708,7 @@ void SSAFEM::cache_residual_cfbc(const Inputs &inputs) {

} // loop over element sides

E->add_contribution(I.data(), m_boundary_integral);
E->add_contribution(I.data(), m_boundary_integral.array());

} // i-loop
} // j-loop
Expand Down Expand Up @@ -773,7 +773,7 @@ void SSAFEM::compute_local_function(Vector2 const *const *const velocity_global,
for (int j = ys; j < ys + ym; j++) {
for (int i = xs; i < xs + xm; i++) {

fem::Element *E = nullptr;
fem::Element2 *E = nullptr;
{
m_q1_element.reset(i, j);

Expand Down Expand Up @@ -987,7 +987,7 @@ void SSAFEM::compute_local_jacobian(Vector2 const *const *const velocity_global,
for (int j = ys; j < ys + ym; j++) {
for (int i = xs; i < xs + xm; i++) {

fem::Element *E = nullptr;
fem::Element2 *E = nullptr;
{
m_q1_element.reset(i, j);

Expand Down
15 changes: 7 additions & 8 deletions src/util/fem/DirichletData.cc
Expand Up @@ -74,7 +74,7 @@ void DirichletData::finish(const IceModelVec *values) {
}

//! @brief Constrain `element`, i.e. ensure that quadratures do not contribute to Dirichlet nodes by marking corresponding rows and columns as "invalid".
void DirichletData::constrain(Element &element) {
void DirichletData::constrain(Element2 &element) {
element.nodal_values(m_indices->array(), m_indices_e);
auto n_chi = element.n_chi();
for (int k = 0; k < n_chi; k++) {
Expand All @@ -95,7 +95,7 @@ DirichletData_Scalar::DirichletData_Scalar(const IceModelVec2Int *indices,
init(indices, m_values, weight);
}

void DirichletData_Scalar::enforce(const Element &element, double* x_nodal) {
void DirichletData_Scalar::enforce(const Element2 &element, double* x_nodal) {
assert(m_values != NULL);

element.nodal_values(m_indices->array(), m_indices_e);
Expand All @@ -108,11 +108,11 @@ void DirichletData_Scalar::enforce(const Element &element, double* x_nodal) {
}
}

void DirichletData_Scalar::enforce_homogeneous(const Element &element, double* x_nodal) {
void DirichletData_Scalar::enforce_homogeneous(const Element2 &element, double* x_nodal) {
element.nodal_values(m_indices->array(), m_indices_e);
for (int k = 0; k < element.n_chi(); k++) {
if (m_indices_e[k] > 0.5) { // Dirichlet node
x_nodal[k] = 0.;
x_nodal[k] = 0.0;
}
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ DirichletData_Vector::DirichletData_Vector(const IceModelVec2Int *indices,
init(indices, m_values, weight);
}

void DirichletData_Vector::enforce(const Element &element, Vector2* x_nodal) {
void DirichletData_Vector::enforce(const Element2 &element, Vector2* x_nodal) {
assert(m_values != NULL);

element.nodal_values(m_indices->array(), m_indices_e);
Expand All @@ -204,12 +204,11 @@ void DirichletData_Vector::enforce(const Element &element, Vector2* x_nodal) {
}
}

void DirichletData_Vector::enforce_homogeneous(const Element &element, Vector2* x_nodal) {
void DirichletData_Vector::enforce_homogeneous(const Element2 &element, Vector2* x_nodal) {
element.nodal_values(m_indices->array(), m_indices_e);
for (int k = 0; k < element.n_chi(); k++) {
if (m_indices_e[k] > 0.5) { // Dirichlet node
x_nodal[k].u = 0.0;
x_nodal[k].v = 0.0;
x_nodal[k] = 0.0;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/util/fem/DirichletData.hh
Expand Up @@ -32,12 +32,12 @@ class IceModelVec2V;

namespace fem {

class Element;
class Element2;

//* Parts shared by scalar and 2D vector Dirichlet data classes.
class DirichletData {
public:
void constrain(Element &element);
void constrain(Element2 &element);
operator bool() {
return m_indices != NULL;
}
Expand All @@ -59,8 +59,8 @@ public:
double weight = 1.0);
~DirichletData_Scalar();

void enforce(const Element &element, double* x_e);
void enforce_homogeneous(const Element &element, double* x_e);
void enforce(const Element2 &element, double* x_e);
void enforce_homogeneous(const Element2 &element, double* x_e);
void fix_residual(double const *const *const x_global, double **r_global);
void fix_residual_homogeneous(double **r_global);
void fix_jacobian(Mat J);
Expand All @@ -74,8 +74,8 @@ public:
double weight);
~DirichletData_Vector();

void enforce(const Element &element, Vector2* x_e);
void enforce_homogeneous(const Element &element, Vector2* x_e);
void enforce(const Element2 &element, Vector2* x_e);
void enforce_homogeneous(const Element2 &element, Vector2* x_e);
void fix_residual(Vector2 const *const *const x_global, Vector2 **r_global);
void fix_residual_homogeneous(Vector2 **r);
void fix_jacobian(Mat J);
Expand Down

0 comments on commit bf3cc68

Please sign in to comment.